本文整理汇总了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();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:OpenSessionInViewTests.java
示例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 );
}
开发者ID:PavlidisLab,项目名称:modinvreg,代码行数:18,代码来源:UserDaoImpl.java
示例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");
}
}
开发者ID:kider,项目名称:jbpm4ssh,代码行数:12,代码来源:AbstractDaoSupport.java
注:本文中的org.springframework.orm.hibernate3.HibernateAccessor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论