List of usage examples for org.springframework.transaction.jta JtaTransactionManager setAllowCustomIsolationLevels
public void setAllowCustomIsolationLevels(boolean allowCustomIsolationLevels)
From source file:org.hsweb.web.datasource.dynamic.DynamicDataSourceAutoConfiguration.java
@Bean public JtaTransactionManager transactionManager(UserTransactionManager userTransactionManager, UserTransactionImp userTransaction) throws SystemException { JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(); jtaTransactionManager.setTransactionManager(userTransactionManager); jtaTransactionManager.setUserTransaction(userTransaction); jtaTransactionManager.setAllowCustomIsolationLevels(true); return jtaTransactionManager; }
From source file:com._4dconcept.springframework.data.marklogic.datasource.DatabaseConnectorJtaTransactionTest.java
@Test public void testJtaTransactionWithIsolationLevelContentSourceAdapter() throws Exception { given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE); final IsolationLevelContentSourceAdapter dsToUse = new IsolationLevelContentSourceAdapter(); dsToUse.setTargetContentSource(contentSource); dsToUse.afterPropertiesSet();/*from w w w . j a va 2 s.c om*/ JtaTransactionManager ptm = new JtaTransactionManager(userTransaction); ptm.setAllowCustomIsolationLevels(true); TransactionTemplate tt = new TransactionTemplate(ptm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException { Session c = ContentSourceUtils.getSession(dsToUse); assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse)); assertSame(session, c); ContentSourceUtils.releaseSession(c, dsToUse); } }); tt.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ); tt.setReadOnly(true); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException { Session c = ContentSourceUtils.getSession(dsToUse); assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse)); assertSame(session, c); ContentSourceUtils.releaseSession(c, dsToUse); } }); verify(userTransaction, times(2)).begin(); verify(userTransaction, times(2)).commit(); verify(session).setTransactionMode(Session.TransactionMode.QUERY); verify(session, times(2)).close(); }
From source file:com._4dconcept.springframework.data.marklogic.datasource.DatabaseConnectorJtaTransactionTest.java
private void doTestJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception { given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE); final ContentSource contentSource1 = mock(ContentSource.class); final Session session1 = mock(Session.class); given(contentSource1.newSession()).willReturn(session1); final ContentSource contentSource2 = mock(ContentSource.class); final Session session2 = mock(Session.class); given(contentSource2.newSession()).willReturn(session2); final IsolationLevelContentSourceRouter dsToUse = new IsolationLevelContentSourceRouter(); Map<Object, Object> targetContentSources = new HashMap<Object, Object>(); targetContentSources.put("ISOLATION_REPEATABLE_READ", contentSource2); dsToUse.setDefaultTargetContentSource(contentSource1); dsToUse.setTargetContentSources(targetContentSources); dsToUse.afterPropertiesSet();/* ww w.ja v a 2s . c o m*/ JtaTransactionManager ptm = new JtaTransactionManager(userTransaction); ptm.setAllowCustomIsolationLevels(true); TransactionTemplate tt = new TransactionTemplate(ptm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException { Session c = ContentSourceUtils.getSession(dsToUse); assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse)); assertSame(session1, c); ContentSourceUtils.releaseSession(c, dsToUse); } }); tt.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException { Session c = ContentSourceUtils.getSession(dsToUse); assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse)); assertSame(session2, c); ContentSourceUtils.releaseSession(c, dsToUse); } }); verify(userTransaction, times(2)).begin(); verify(userTransaction, times(2)).commit(); verify(session1).close(); verify(session2).close(); }