本文整理汇总了Java中org.springframework.transaction.support.DefaultTransactionDefinition.setPropagationBehaviorName方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTransactionDefinition.setPropagationBehaviorName方法的具体用法?Java DefaultTransactionDefinition.setPropagationBehaviorName怎么用?Java DefaultTransactionDefinition.setPropagationBehaviorName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.transaction.support.DefaultTransactionDefinition
的用法示例。
在下文中一共展示了DefaultTransactionDefinition.setPropagationBehaviorName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithJtaTxManager
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testWithJtaTxManager() {
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = jtaManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
jtaManager.commit(status);
// assume a real JTA tx would enlist and commit the JDBC connection
assertNoCommitJdbc();
assertCommitSession();
assertSingleConnection();
}
示例2: testWithTxSupports
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testWithTxSupports() {
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_SUPPORTS");
TransactionStatus status = txManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.commit(status);
// SUPPORTS should just activate tx synchronization but not commits
assertNoCommit();
assertSingleConnection();
}
示例3: testRollbackWithTxSupports
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testRollbackWithTxSupports() {
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_SUPPORTS");
TransactionStatus status = txManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.rollback(status);
// SUPPORTS should just activate tx synchronization but not commits
assertNoCommit();
assertSingleConnection();
}
示例4: testWithTxRequired
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testWithTxRequired() {
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = txManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.commit(status);
assertCommit();
assertCommitSession();
assertSingleConnection();
}
示例5: testSqlSessionCommitWithTx
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testSqlSessionCommitWithTx() {
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = txManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
// commit should no-op since there is an active transaction
session.commit(true);
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.commit(status);
// Connection should be committed once, but we explicitly called commit on the SqlSession,
// so it should be committed twice
assertEquals("should call commit on Connection", 1, connection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, connection.getNumberRollbacks());
assertEquals("should call commit on SqlSession", 2, executorInterceptor.getCommitCount());
assertEquals("should not call rollback on SqlSession", 0, executorInterceptor.getRollbackCount());
assertSingleConnection();
}
示例6: testBatchInTx
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testBatchInTx() {
setupBatchStatements();
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = txManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory, ExecutorType.BATCH, exceptionTranslator);
session.getMapper(TestMapper.class).insertTest("test1");
session.getMapper(TestMapper.class).insertTest("test2");
session.getMapper(TestMapper.class).insertTest("test3");
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.commit(status);
assertCommit();
assertSingleConnection();
assertExecuteCount(3);
}
示例7: testBatchInTxWithError
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test(expected = DataAccessException.class)
public void testBatchInTxWithError() {
setupBatchStatements();
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = txManager.getTransaction(txDef);
session = SqlSessionUtils.getSqlSession(sqlSessionFactory, ExecutorType.BATCH, exceptionTranslator);
session.getMapper(TestMapper.class).insertTest("test1");
session.getMapper(TestMapper.class).insertTest("test2");
session.update("org.mybatis.spring.TestMapper.insertFail");
session.getMapper(TestMapper.class).insertTest("test3");
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.commit(status);
}
示例8: shouldNoOpWithTx
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void shouldNoOpWithTx() throws Exception {
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = txManager.getTransaction(txDef);
SpringManagedTransactionFactory transactionFactory = new SpringManagedTransactionFactory();
SpringManagedTransaction transaction = (SpringManagedTransaction) transactionFactory.newTransaction(dataSource, null, false);
transaction.getConnection();
transaction.commit();
transaction.close();
assertEquals("should not call commit on Connection", 0, connection.getNumberCommits());
assertFalse("should not close the Connection", connection.isClosed());
txManager.commit(status);
}
示例9: createTransactionTemplate
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
/**
* Creates the transaction template.
* <p>
* This is Hibernate aware if Hibernate is available.
*
* @param repo the component repository, only used to register secondary items like lifecycle, not null
* @param hibernateSessionFactory the session factory, not null
* @return the template, not null
*/
protected TransactionTemplate createTransactionTemplate(ComponentRepository repo, SessionFactory hibernateSessionFactory) {
DefaultTransactionDefinition transactionDef = new DefaultTransactionDefinition();
transactionDef.setName(getName());
if (getTransactionIsolationLevel() != null) {
transactionDef.setIsolationLevelName(getTransactionIsolationLevel());
}
if (getTransactionPropagationBehavior() != null) {
transactionDef.setPropagationBehaviorName(getTransactionPropagationBehavior());
}
if (getTransactionTimeout() != 0) {
transactionDef.setTimeout(getTransactionTimeout());
}
return new TransactionTemplate(createTransactionManager(repo, hibernateSessionFactory), transactionDef);
}
示例10: createTransactionDefinition
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
/**
* Creates the transaction definition.
*
* @return the transaction definition, not null
*/
protected DefaultTransactionDefinition createTransactionDefinition() {
DefaultTransactionDefinition transDefn = new DefaultTransactionDefinition();
transDefn.setName(getName());
if (getTransactionIsolationLevelName() != null) {
transDefn.setIsolationLevelName(getTransactionIsolationLevelName());
}
if (getTransactionPropagationBehaviorName() != null) {
transDefn.setPropagationBehaviorName(getTransactionPropagationBehaviorName());
}
if (getTransactionTimeout() != 0) {
transDefn.setTimeout(getTransactionTimeout());
}
return transDefn;
}
示例11: testChangeExecutorTypeInTxRequiresNew
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testChangeExecutorTypeInTxRequiresNew() throws Exception {
try {
txManager.setDataSource(dataSource);
TransactionStatus status = txManager.getTransaction(new DefaultTransactionDefinition());
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
// start a new tx while the other is in progress
DefaultTransactionDefinition txRequiresNew = new DefaultTransactionDefinition();
txRequiresNew.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
TransactionStatus status2 = txManager.getTransaction(txRequiresNew);
SqlSession session2 = SqlSessionUtils.getSqlSession(sqlSessionFactory, ExecutorType.BATCH, exceptionTranslator);
SqlSessionUtils.closeSqlSession(session2, sqlSessionFactory);
txManager.rollback(status2);
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.rollback(status);
} finally {
// reset the txManager; keep other tests from potentially failing
txManager.setDataSource(dataSource);
// null the connection since it was not used
// this avoids failing in validateConnectionClosed()
connection = null;
}
}
示例12: testWithTxRequired
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testWithTxRequired() {
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = txManager.getTransaction(txDef);
sqlSessionTemplate.getMapper(TestMapper.class).findTest();
txManager.commit(status);
assertCommit();
assertSingleConnection();
}
示例13: testWithJtaTxManagerAndNonSpringTxManager
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
MockDataSource mockDataSource = new MockDataSource();
mockDataSource.setupConnection(createMockConnection());
Environment nonSpring = new Environment("non-spring", new ManagedTransactionFactory(), mockDataSource,null);
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = jtaManager.getTransaction(txDef);
try {
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
// Spring is not managing SqlSession, so commit is needed
session.commit(true);
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
jtaManager.commit(status);
// assume a real JTA tx would enlist and commit the JDBC connection
assertNoCommitJdbc();
assertCommitSession();
MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
assertEquals("should call commit on Connection", 0, mockConnection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());
assertEquals("should not call DataSource.getConnection()", 0, dataSource.getConnectionCount());
} finally {
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
sqlSessionFactory.getConfiguration().setEnvironment(original);
// null the connection since it was not used
// this avoids failing in validateConnectionClosed()
connection = null;
}
}
示例14: testSuspendAndResume
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testSuspendAndResume() throws Exception {
try {
txManager.setDataSource(dataSource);
TransactionStatus status = txManager.getTransaction(new DefaultTransactionDefinition());
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
// start a new tx while the other is in progress
DefaultTransactionDefinition txRequiresNew = new DefaultTransactionDefinition();
txRequiresNew.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
TransactionStatus status2 = txManager.getTransaction(txRequiresNew);
SqlSession session2 = SqlSessionUtils.getSqlSession(sqlSessionFactory);
assertNotSame("getSqlSession() should not return suspended SqlSession", session, session2);
SqlSessionUtils.closeSqlSession(session2, sqlSessionFactory);
txManager.commit(status2);
// first tx should be resumed now and this should succeed
session.getMapper(TestMapper.class).findTest();
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
txManager.commit(status);
// two transactions should have completed, each using their own Connection
assertEquals("should call DataSource.getConnection() twice", 2, dataSource.getConnectionCount());
// both connections and should be committed
assertEquals("should call commit on Connection 1", 1, connection.getNumberCommits());
assertEquals("should not call rollback on Connection 1", 0, connection.getNumberRollbacks());
assertEquals("should call commit on Connection 2", 1, connectionTwo.getNumberCommits());
assertEquals("should not call rollback on Connection 2", 0, connectionTwo.getNumberRollbacks());
// the SqlSession should have also committed twice
assertEquals("should call commit on SqlSession", 2, executorInterceptor.getCommitCount());
assertEquals("should call rollback on SqlSession", 0, executorInterceptor.getRollbackCount());
assertConnectionClosed(connection);
assertConnectionClosed(connectionTwo);
} finally {
// reset the txManager; keep other tests from potentially failing
txManager.setDataSource(dataSource);
// null the connection since it was not used
// this avoids failing in validateConnectionClosed()
connection = null;
}
}
示例15: testWithJtaTxManagerAndNonSpringTxManager
import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
MockDataSource mockDataSource = new MockDataSource();
mockDataSource.setupConnection(createMockConnection());
Environment nonSpring = new Environment("non-spring", new ManagedTransactionFactory(), mockDataSource);
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = jtaManager.getTransaction(txDef);
try {
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
// Spring is not managing SqlSession, so commit is needed
session.commit(true);
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
jtaManager.commit(status);
// assume a real JTA tx would enlist and commit the JDBC connection
assertNoCommitJdbc();
assertCommitSession();
MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
assertEquals("should call commit on Connection", 0, mockConnection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());
assertEquals("should not call DataSource.getConnection()", 0, dataSource.getConnectionCount());
} finally {
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
sqlSessionFactory.getConfiguration().setEnvironment(original);
// null the connection since it was not used
// this avoids failing in validateConnectionClosed()
connection = null;
}
}