Exemplo n.º 1
0
 private TransactionFactory transactionManagerElement(XNode context) throws Exception {
   if (context != null) {
     String type = context.getStringAttribute("type");
     Properties props = context.getChildrenAsProperties();
     TransactionFactory factory = (TransactionFactory) resolveClass(type).newInstance();
     factory.setProperties(props);
     return factory;
   }
   throw new BuilderException("Environment declaration requires a TransactionFactory.");
 }
 @Test
 public void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnections()
     throws Exception {
   TransactionFactory tf = new ManagedTransactionFactory();
   tf.setProperties(new Properties());
   Transaction tx = tf.newTransaction(conn);
   assertEquals(conn, tx.getConnection());
   tx.commit();
   tx.rollback();
   tx.close();
   verify(conn).close();
 }
Exemplo n.º 3
0
 private Executor newExecutor() throws SQLException {
   final Environment environment = configuration.getEnvironment();
   if (environment == null)
     throw new ExecutorException(
         "ResultLoader could not load lazily.  Environment was not configured.");
   final DataSource ds = environment.getDataSource();
   if (ds == null)
     throw new ExecutorException(
         "ResultLoader could not load lazily.  DataSource was not configured.");
   final TransactionFactory transactionFactory = environment.getTransactionFactory();
   final Transaction tx = transactionFactory.newTransaction(ds, null, false);
   return configuration.newExecutor(tx, ExecutorType.SIMPLE);
 }
 @Test
 public void
     shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnectionsAndDoesNotCloseConnection()
         throws Exception {
   TransactionFactory tf = new ManagedTransactionFactory();
   Properties props = new Properties();
   props.setProperty("closeConnection", "false");
   tf.setProperties(props);
   Transaction tx = tf.newTransaction(conn);
   assertEquals(conn, tx.getConnection());
   tx.commit();
   tx.rollback();
   tx.close();
   verifyNoMoreInteractions(conn);
 }
Exemplo n.º 5
0
  private SqlSession openSessionFromDataSource(
      ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
    Transaction tx = null;
    try {
      DataSource ds = ShardMapperProxy.getCurrentDs();
      final Environment environment = configuration.getEnvironment();
      final TransactionFactory transactionFactory =
          getTransactionFactoryFromEnvironment(environment);

      tx = transactionFactory.newTransaction(ds, level, autoCommit);

      final Executor executor = configuration.newExecutor(tx, execType);
      return new DefaultSqlSession(configuration, executor);
    } catch (Exception e) {
      closeTransaction(tx); // may have fetched a connection so lets call close()
      throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
      ErrorContext.instance().reset();
    }
  }