当前位置: 首页>>代码示例>>Java>>正文


Java SessionFactoryUtils.getSession方法代码示例

本文整理汇总了Java中org.springframework.orm.hibernate3.SessionFactoryUtils.getSession方法的典型用法代码示例。如果您正苦于以下问题:Java SessionFactoryUtils.getSession方法的具体用法?Java SessionFactoryUtils.getSession怎么用?Java SessionFactoryUtils.getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.orm.hibernate3.SessionFactoryUtils的用法示例。


在下文中一共展示了SessionFactoryUtils.getSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lock

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Override
public void lock(final Account... accounts) throws LockingException {
    if (ArrayUtils.isEmpty(accounts)) {
        return;
    }
    Long[] ids = EntityHelper.toIds(accounts);
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    try {
        session
                .createQuery("select l.id from AccountLock l where l.id in (:ids)")
                .setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE))
                .setParameterList("ids", ids)
                .list();
    } catch (JDBCException e) {
        handleException(e);
    }
}
 
开发者ID:crypto-coder,项目名称:open-cyclos,代码行数:18,代码来源:DirectLockHandlerFactory.java

示例2: preHandle

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:OpenSessionInViewInterceptor.java

示例3: testOpenSessionInViewInterceptorAndDeferredClose

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Test
public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception {
	SessionFactory sf = mock(SessionFactory.class);
	Session session = mock(Session.class);

	OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
	interceptor.setSessionFactory(sf);
	interceptor.setSingleSession(false);

	given(sf.openSession()).willReturn(session);
	given(session.getSessionFactory()).willReturn(sf);

	interceptor.preHandle(this.webRequest);
	org.hibernate.Session sess = SessionFactoryUtils.getSession(sf, true);
	SessionFactoryUtils.releaseSession(sess, sf);

	// check that further invocations simply participate
	interceptor.preHandle(this.webRequest);

	interceptor.preHandle(this.webRequest);
	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	interceptor.preHandle(this.webRequest);
	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:37,代码来源:OpenSessionInViewTests.java

示例4: testClobStringTypeWithSynchronizedSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Test
public void testClobStringTypeWithSynchronizedSession() throws Exception {
	SessionFactory sf = mock(SessionFactory.class);
	Session session = mock(Session.class);
	given(sf.openSession()).willReturn(session);
	given(session.getSessionFactory()).willReturn(sf);
	given(lobHandler.getClobAsString(rs, "column")).willReturn("content");

	ClobStringType type = new ClobStringType(lobHandler, null);
	assertEquals(1, type.sqlTypes().length);
	assertEquals(Types.CLOB, type.sqlTypes()[0]);
	assertEquals(String.class, type.returnedClass());
	assertTrue(type.equals("content", "content"));
	assertEquals("content", type.deepCopy("content"));
	assertFalse(type.isMutable());

	assertEquals("content", type.nullSafeGet(rs, new String[] {"column"}, null));
	TransactionSynchronizationManager.initSynchronization();
	try {
		SessionFactoryUtils.getSession(sf, true);
		type.nullSafeSet(ps, "content", 1);
		List synchs = TransactionSynchronizationManager.getSynchronizations();
		assertEquals(2, synchs.size());
		assertTrue(synchs.get(0).getClass().getName().endsWith("SpringLobCreatorSynchronization"));
		((TransactionSynchronization) synchs.get(0)).beforeCompletion();
		((TransactionSynchronization) synchs.get(0)).afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
		((TransactionSynchronization) synchs.get(1)).beforeCompletion();
		((TransactionSynchronization) synchs.get(1)).afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
	}
	finally {
		TransactionSynchronizationManager.clearSynchronization();
	}

	verify(session).close();
	verify(lobCreator).setClobAsString(ps, 1, "content");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:37,代码来源:LobTypeTests.java

示例5: getSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
 * ��ȡSession����
 * @return
 */
protected Session getSession(){
	return (!this.template.isAllowCreate() ?
	    SessionFactoryUtils.getSession(this.template.getSessionFactory(), false) :
			SessionFactoryUtils.getSession(
					this.template.getSessionFactory(),
					this.template.getEntityInterceptor(),
					this.template.getJdbcExceptionTranslator()));
}
 
开发者ID:java-scott,项目名称:java-project,代码行数:13,代码来源:DaoSupport.java

示例6: getSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Override
protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
 Session session = SessionFactoryUtils.getSession(sessionFactory, true);
 //set the FlushMode to auto in order to save objects.
 session.setFlushMode(FlushMode.AUTO);
 return session;
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:8,代码来源:HibernateFilter.java

示例7: openSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public static boolean openSession(SessionFactory sessionFactory) {
boolean participate = TransactionSynchronizationManager.hasResource(sessionFactory);
if (!participate) {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(org.hibernate.FlushMode.ALWAYS);
    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
}
return participate;
   }
 
开发者ID:EsupPortail,项目名称:esup-smsu,代码行数:10,代码来源:HibernateUtils.java

示例8: getSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public static Session getSession(boolean allowCreate)
        throws DataAccessResourceFailureException, IllegalStateException {

    return (!allowCreate ?
            SessionFactoryUtils.getSession(getSessionFactory(), false) :
            SessionFactoryUtils.getSession(
                    getSessionFactory(),
                    hibernateTemplate.getEntityInterceptor(),
                    hibernateTemplate.getJdbcExceptionTranslator()));
}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:11,代码来源:HibernateUtil.java

示例9: openSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Before
public void openSession()  throws Exception {
    session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(FlushMode.MANUAL);//MANUAL
    TransactionSynchronizationManager.bindResource(sessionFactory,new SessionHolder(session));
   

}
 
开发者ID:VonChange,项目名称:haloDao-Hibernate3,代码行数:9,代码来源:BaseServiceTestCase.java

示例10: preHandle

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:45,代码来源:OpenSessionInViewInterceptor.java

示例11: bindSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
private boolean bindSession() {
    if (sessionFactory == null) {
        throw new IllegalStateException("No sessionFactory property provided");
    }
    final Object inStorage = TransactionSynchronizationManager.getResource(sessionFactory);
    if (inStorage != null) {
        ((SessionHolder) inStorage).getSession().flush();
        return false;
    } else {
        Session session = SessionFactoryUtils.getSession(sessionFactory, true);
        session.setFlushMode(FlushMode.AUTO);
        TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
        return true;
    }
}
 
开发者ID:psramkumar,项目名称:grails-jsf2-plugin,代码行数:16,代码来源:GrailsHibernatePhaseListener.java

示例12: getSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
 * @return Returns the existing session attached to the thread.
 *      A new session will <b>not</b> be created.
 */
protected Session getSession()
{
    return SessionFactoryUtils.getSession(sessionFactory, true);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:9,代码来源:BaseSpringTest.java

示例13: doGetPersistenceContext

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Override
   protected Session doGetPersistenceContext(Object testObject) {
	return SessionFactoryUtils.getSession(getPersistenceUnit(testObject), true);
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:5,代码来源:HibernateModule.java

示例14: getSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public Session getSession() {
    return SessionFactoryUtils.getSession(this.sessionFactory, true);
}
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:4,代码来源:HibernateDao.java

示例15: getSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
protected Session getSession() {
    return SessionFactoryUtils.getSession(sessionFactory, true);
}
 
开发者ID:crypto-coder,项目名称:open-cyclos,代码行数:4,代码来源:AbstractDocumentMapper.java


注:本文中的org.springframework.orm.hibernate3.SessionFactoryUtils.getSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。