本文整理汇总了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);
}
}
示例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());
}
}
}
示例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();
}
示例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");
}
示例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()));
}
示例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;
}
示例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;
}
示例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()));
}
示例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));
}
示例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());
}
}
}
示例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;
}
}
示例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);
}
示例13: doGetPersistenceContext
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Override
protected Session doGetPersistenceContext(Object testObject) {
return SessionFactoryUtils.getSession(getPersistenceUnit(testObject), true);
}
示例14: getSession
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public Session getSession() {
return SessionFactoryUtils.getSession(this.sessionFactory, true);
}
示例15: getSession
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
protected Session getSession() {
return SessionFactoryUtils.getSession(sessionFactory, true);
}