Beispiel #1
0
  public static void main(String[] args) throws Exception {
    ConnectionManager mysqlCM =
        ConnectionManagerProvider.createConnectionManager(
            "adbcj:mysqlnetty://localhost/adbcjtck", "adbcjtck", "adbcjtck");
    ConnectionManager pgCM =
        ConnectionManagerProvider.createConnectionManager(
            "adbcj:postgresql-netty://localhost/adbcjtck", "adbcjtck", "adbcjtck");

    Connection mysql = mysqlCM.connect().getUninterruptably();
    Connection pg = pgCM.connect().getUninterruptably();

    final String insertTemplate = "INSERT INTO large (a, b, c) VALUES ('%s', '%s', '%s')";
    for (int i = 0; i < 998; i++) {
      String a = randString();
      String b = randString();
      String c = randString();
      final String insert = String.format(insertTemplate, a, b, c);
      mysql.executeUpdate(insert).get();
      pg.executeUpdate(insert).get();
    }
    //		mysql.close(false).get();
    //		pg.close(false).get();
    //		mysqlCM.close(true);
    //		pgCM.close(true);
  }
  @Test
  public void closesPreparedStatements() throws InterruptedException {
    final ConnectionManager connectionManager =
        ConnectionManagerProvider.createConnectionManager(
            "adbcj:pooled:mock:database", "sa", "pwd");

    final MockConnectionManager mockFactory =
        MockConnectionFactory.lastInstanceRequestedOnThisThread();

    final Connection connection = connectionManager.connect().get();

    connection.beginTransaction();

    final MockConnection mockConnection = mockFactory.lastInstanceRequestedOnThisThread();
    mockConnection.assertTransactionState(TransactionState.ACTIVE);

    connection.close();

    mockConnection.assertTransactionState(TransactionState.ROLLED_BACK);
  }