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


Java SessionFactoryUtils.releaseSession方法代码示例

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


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

示例1: 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

示例2: tearDown

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public void tearDown()
	throws Exception
{
	SessionFactory sf = (SessionFactory) this.context.getBean("sessionFactory");
	SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
	Session s = holder.getSession(); 
	s.flush();
	TransactionSynchronizationManager.unbindResource(sf);
	//SessionFactoryUtils.closeSessionIfNecessary(s, sf);
	SessionFactoryUtils.releaseSession(s, sf);
}
 
开发者ID:iwethey,项目名称:iwethey,代码行数:12,代码来源:HibernateTestHarness.java

示例3: closeSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
private void closeSession()
{
    SessionFactory sessionFactory = getSessionFactory();
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
    sessionHolder.getSession().flush();
    sessionHolder.getSession().close();
    SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:9,代码来源:PersonDaoTest.java

示例4: main

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	System.out.println("Converting Old Quotes to New LERPADISMS!");
	context = new ClassPathXmlApplicationContext("test-context.xml");
	System.out.println("1");
	SessionFactory sf = (SessionFactory) context.getBean("sessionFactory");
	System.out.println("2");
	Session s = sf.openSession();
	System.out.println("3");
	TransactionSynchronizationManager.bindResource(sf, new SessionHolder(s));
	System.out.println("4");

	adminManager = (AdminManager) context.getBean("adminManager");
	System.out.println("5");
	userManager = (UserManager) context.getBean("userManager");
	System.out.println("5.5");

	List<OldQuote> oldQuotes = adminManager.getAllOldLRPDs();
	System.out.println("6");

	System.out.println("# Old Quotes = [" + oldQuotes.size() + "]");

	for (OldQuote oq : oldQuotes)
	{
		System.out.println("Working on Quote = [" + oq.getQuote() + "]");
		Quote q = new Quote();

		q.setBoard(oq.getBoard());
		q.setQuote(oq.getQuote());
		q.setCreated(oq.getCreated());
		q.setApproved(true);
		q.setApprovedBy(userManager.getUserById(1));
		q.setApprovedDate(new Date());
		q.setCreatedBy(userManager.getUserByNickname(oq.getCreatedBy()));


		System.out.println("Saving New Quote = [" + q.getQuote() + "]");
		adminManager.saveQuote(q);
		System.out.println("-----------------------------");
	}
	System.out.println("7");

	s.flush();
	System.out.println("8");
	TransactionSynchronizationManager.unbindResource(sf);
	System.out.println("9");
	SessionFactoryUtils.releaseSession(s, sf);
	System.out.println("10");
}
 
开发者ID:iwethey,项目名称:iwethey,代码行数:49,代码来源:ConvertQuote.java

示例5: closeSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public static void closeSession(SessionFactory sessionFactory, boolean participate) {
if (!participate) {
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
    SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
}
   }
 
开发者ID:EsupPortail,项目名称:esup-smsu,代码行数:7,代码来源:HibernateUtils.java

示例6: closeSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@After
public void closeSession()  throws Exception {
    TransactionSynchronizationManager.unbindResource(sessionFactory);     
    SessionFactoryUtils.releaseSession(session, sessionFactory);
}
 
开发者ID:VonChange,项目名称:haloDao-Hibernate3,代码行数:6,代码来源:BaseServiceTestCase.java

示例7: releaseSession

import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
 * Close the given Hibernate Session, created via this DAO's SessionFactory,
 * if it isn't bound to the thread (i.e. isn't a transactional Session).
 * <p>Typically used in plain Hibernate code, in combination with
 * {@link #getSession} and {@link #convertHibernateAccessException}.
 * @param session the Session to close
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#releaseSession
 * @deprecated as of Spring 3.2.7, in favor of {@link HibernateTemplate} usage
 */
@Deprecated
protected final void releaseSession(Session session) {
	SessionFactoryUtils.releaseSession(session, getSessionFactory());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:HibernateDaoSupport.java


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