本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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");
}
示例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);
}
}
示例6: closeSession
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@After
public void closeSession() throws Exception {
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.releaseSession(session, sessionFactory);
}
示例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());
}