本文整理汇总了Java中org.springframework.orm.hibernate3.HibernateAccessor类的典型用法代码示例。如果您正苦于以下问题:Java HibernateAccessor类的具体用法?Java HibernateAccessor怎么用?Java HibernateAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HibernateAccessor类属于org.springframework.orm.hibernate3包,在下文中一共展示了HibernateAccessor类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOpenSessionInViewInterceptorWithSingleSessionAndFlush
import org.springframework.orm.hibernate3.HibernateAccessor; //导入依赖的package包/类
@Test
public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws Exception {
SessionFactory sf = mock(SessionFactory.class);
Session session = mock(Session.class);
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
interceptor.setSessionFactory(sf);
interceptor.setFlushMode(HibernateAccessor.FLUSH_AUTO);
given(sf.openSession()).willReturn(session);
given(session.getSessionFactory()).willReturn(sf);
interceptor.preHandle(this.webRequest);
assertTrue(TransactionSynchronizationManager.hasResource(sf));
interceptor.postHandle(this.webRequest, null);
assertTrue(TransactionSynchronizationManager.hasResource(sf));
interceptor.afterCompletion(this.webRequest, null);
assertFalse(TransactionSynchronizationManager.hasResource(sf));
verify(session).flush();
verify(session).close();
}
示例2: findByUserName
import org.springframework.orm.hibernate3.HibernateAccessor; //导入依赖的package包/类
@Override
public User findByUserName( final String userName ) {
// we make this method safer to call in a transaction, as it really is a
// read-only method that should be
// accessing information that is already committed.
HibernateTemplate t = new HibernateTemplate( this.getSessionFactory() );
t.setAlwaysUseNewSession( true );
t.setFlushMode( HibernateAccessor.FLUSH_NEVER );
List<?> r = t.findByNamedParam( "from User u where u.userName=:userName", "userName", userName );
if ( r.isEmpty() ) {
return null;
} else if ( r.size() > 1 ) {
throw new IllegalStateException( "Multiple users with name=" + userName );
}
return ( User ) r.get( 0 );
}
示例3: checkWriteOperationAllowed
import org.springframework.orm.hibernate3.HibernateAccessor; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected void checkWriteOperationAllowed(Session session)
throws InvalidDataAccessApiUsageException {
if (getHibernateTemplate().isCheckWriteOperations()
&& getHibernateTemplate().getFlushMode() != HibernateAccessor.FLUSH_EAGER
&& FlushMode.NEVER.equals(session.getFlushMode())) {
throw new InvalidDataAccessApiUsageException(
"Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session "
+ "into FlushMode.AUTO or remove 'readOnly' marker from transaction definition");
}
}