src/main/java/me/zzp/ar/DB.java
public void batch(Runnable transaction) {
    // TODO: 不支持嵌套事务
    try (Connection c = pool.getConnection()) {
      boolean commit = c.getAutoCommit();
      try {
        c.setAutoCommit(false);
      } catch (SQLException e) {
        throw new TransactionException("transaction setAutoCommit(false)", e);
      }
      base.set(c);

      try {
        transaction.run();
      } catch (RuntimeException e) {
        try {
          c.rollback();
          c.setAutoCommit(commit);
        } catch (SQLException ex) {
          throw new TransactionException("transaction rollback: " + ex.getMessage(), e);
        }
        throw e;
      }

      try {
        c.commit();
      } catch (SQLException e) {
        throw new TransactionException("transaction commit", e);
      }
      c.setAutoCommit(commit);
    } catch (SQLException e) {
      throw new DBOpenException(e);
    } finally {
      base.set(null);
    }
  }
public void batch(Runnable transaction) {
    // TODO: 不支持嵌套事务
    try (Connection c = pool.getConnection()) {
      boolean commit = c.getAutoCommit();
      try {
        c.setAutoCommit(false);
      } catch (SQLException e) {
        throw new TransactionException("transaction setAutoCommit(false)", e);
      }
      base.set(c);

      try {
        transaction.run();
      } catch (RuntimeException e) {
        try {
          c.rollback();
          c.setAutoCommit(commit);
        } catch (SQLException ex) {
          throw new TransactionException("transaction rollback: " + ex.getMessage(), e);
        }
        throw e;
      }

      try {
        c.commit();
      } catch (SQLException e) {
        throw new TransactionException("transaction commit", e);
      }
      c.setAutoCommit(commit);
    } catch (SQLException e) {
      throw new DBOpenException(e);
    } finally {
      base.set(null);
    }
  }
public void batch ( Runnable transaction ) { // TODO: 不支持嵌套事务 try ( Connection c = pool . getConnection ( ) ) { boolean commit = c . getAutoCommit ( ) ; try { c . setAutoCommit ( false ) ; } catch ( SQLException e ) { throw new TransactionException ( "transaction setAutoCommit(false)" , e ) ; } base . set ( c ) ; try { transaction . run ( ) ; } catch ( RuntimeException e ) { try { c . rollback ( ) ; c . setAutoCommit ( commit ) ; } catch ( SQLException ex ) { throw new TransactionException ( "transaction rollback: " + ex . getMessage ( ) , e ) ; } throw e ; } try { c . commit ( ) ; } catch ( SQLException e ) { throw new TransactionException ( "transaction commit" , e ) ; } c . setAutoCommit ( commit ) ; } catch ( SQLException e ) { throw new DBOpenException ( e ) ; } finally { base . set ( null ) ; } }
/* Transaction
/ * Transaction