當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultTransactionDefinition.setPropagationBehaviorName方法代碼示例

本文整理匯總了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();
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:21,代碼來源:MyBatisSpringTest.java

示例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();
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:18,代碼來源:MyBatisSpringTest.java

示例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();
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:18,代碼來源:MyBatisSpringTest.java

示例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();
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:18,代碼來源:MyBatisSpringTest.java

示例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();
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:25,代碼來源:MyBatisSpringTest.java

示例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);
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:24,代碼來源:MyBatisSpringTest.java

示例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);
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:21,代碼來源:MyBatisSpringTest.java

示例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);
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:17,代碼來源:SpringTransactionManagerTest.java

示例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);
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:24,代碼來源:DbConnectorComponentFactory.java

示例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;
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:20,代碼來源:DbConnectorFactoryBean.java

示例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;
  }
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:32,代碼來源:MyBatisSpringTest.java

示例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();
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:15,代碼來源:SqlSessionTemplateTest.java

示例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;
  }
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:47,代碼來源:MyBatisSpringTest.java

示例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;
  }
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:52,代碼來源:MyBatisSpringTest.java

示例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;
  }
}
 
開發者ID:zyong2004,項目名稱:mybatis-spring,代碼行數:47,代碼來源:MyBatisSpringTest.java


注:本文中的org.springframework.transaction.support.DefaultTransactionDefinition.setPropagationBehaviorName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。