org.hibernate.SessionBuilder Java Examples
The following examples show how to use
org.hibernate.SessionBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCurrentSessionContext.java From lams with GNU General Public License v2.0 | 5 votes |
protected SessionBuilder baseSessionBuilder() { final SessionBuilder builder = factory.withOptions(); final CurrentTenantIdentifierResolver resolver = factory.getCurrentTenantIdentifierResolver(); if ( resolver != null ) { builder.tenantIdentifier( resolver.resolveCurrentTenantIdentifier() ); } return builder; }
Example #2
Source File: HibernateTransactionManagerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testTransactionCommitWithEntityInterceptor() throws Exception { Interceptor entityInterceptor = mock(Interceptor.class); Connection con = mock(Connection.class); final SessionFactory sf = mock(SessionFactory.class); ImplementingSession session = mock(ImplementingSession.class); SessionBuilder options = mock(SessionBuilder.class); Transaction tx = mock(Transaction.class); given(sf.withOptions()).willReturn(options); given(options.interceptor(entityInterceptor)).willReturn(options); given(options.openSession()).willReturn(session); given(session.beginTransaction()).willReturn(tx); given(session.isOpen()).willReturn(true); given(session.isConnected()).willReturn(true); given(session.connection()).willReturn(con); HibernateTransactionManager tm = new HibernateTransactionManager(sf); tm.setEntityInterceptor(entityInterceptor); tm.setAllowResultAccessAfterCompletion(true); TransactionTemplate tt = new TransactionTemplate(tm); tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf)); assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive()); tt.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf)); } }); assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf)); assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive()); verify(session).close(); verify(tx).commit(); }
Example #3
Source File: LegacySessionFactory.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public SessionBuilder withOptions() { return null; }
Example #4
Source File: AbstractDelegatingSessionBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
public AbstractDelegatingSessionBuilder(SessionBuilder delegate) { this.delegate = delegate; }
Example #5
Source File: AbstractDelegatingSessionBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
protected SessionBuilder delegate() { return delegate; }
Example #6
Source File: HibernateTransactionManagerTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void testTransactionCommitWithEntityInterceptorBeanName() throws Exception { Interceptor entityInterceptor = mock(Interceptor.class); Interceptor entityInterceptor2 = mock(Interceptor.class); Connection con = mock(Connection.class); final SessionFactory sf = mock(SessionFactory.class); ImplementingSession session = mock(ImplementingSession.class); SessionBuilder options = mock(SessionBuilder.class); Transaction tx = mock(Transaction.class); given(sf.withOptions()).willReturn(options); given(options.interceptor(entityInterceptor)).willReturn(options); given(options.interceptor(entityInterceptor2)).willReturn(options); given(options.openSession()).willReturn(session); given(session.beginTransaction()).willReturn(tx); given(session.isOpen()).willReturn(true); given(session.isConnected()).willReturn(true); given(session.connection()).willReturn(con); BeanFactory beanFactory = mock(BeanFactory.class); given(beanFactory.getBean("entityInterceptor", Interceptor.class)).willReturn( entityInterceptor, entityInterceptor2); HibernateTransactionManager tm = new HibernateTransactionManager(sf); tm.setEntityInterceptorBeanName("entityInterceptor"); tm.setBeanFactory(beanFactory); TransactionTemplate tt = new TransactionTemplate(tm); tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf)); assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive()); for (int i = 0; i < 2; i++) { tt.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf)); } }); } assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf)); assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive()); verify(session, times(2)).close(); verify(tx, times(2)).commit(); }
Example #7
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SessionBuilder withOptions() { return null; }
Example #8
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SessionBuilder withOptions() { return null; }
Example #9
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SessionBuilder withOptions() { return null; }