Java Code Examples for io.vertx.ext.sql.SQLConnection#setAutoCommit()

The following examples show how to use io.vertx.ext.sql.SQLConnection#setAutoCommit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDBCCustomTypesTest.java    From vertx-jdbc-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomInsert() {
  String sql = "INSERT INTO t (u, t, d, ts) VALUES (?, ?, ?, ?)";
  final String uuid = UUID.randomUUID().toString();

  final SQLConnection conn = connection();

  conn.setAutoCommit(false, tx -> {
    if (tx.succeeded()) {
      conn.updateWithParams(sql, new JsonArray().add(uuid).add("09:00:00").add("2015-03-16").add(Instant.now()), onSuccess(resultSet -> {
        testComplete();
      }));
    }
  });

  await();
}
 
Example 2
Source File: JDBCEventStore.java    From enode with MIT License 5 votes vote down vote up
private void resetAutoCommitAndCloseConnection(SQLConnection conn) {
    conn.setAutoCommit(true, commit -> {
        if (commit.failed()) {
            logger.error("jdbc driver set autocommit true failed", commit.cause());
        }
        // close will put the connection into pool
        conn.close();
    });
}
 
Example 3
Source File: SQL.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public static Future<SQLConnection> setAutoCommit(final Tracer tracer, final SpanContext context, final SQLConnection connection, boolean state) {
    final Span span = startSqlSpan(tracer, context, "set autocommit", builder -> {
        builder.withTag("db.autocommit", state);
    });
    final Promise<Void> promise = Promise.promise();
    connection.setAutoCommit(state, promise);
    return finishSpan(promise.future().map(connection), span, null);
}
 
Example 4
Source File: SQLExamples.java    From vertx-jdbc-client with Apache License 2.0 5 votes vote down vote up
public void example1(SQLConnection connection) {
  connection.setAutoCommit(false, res -> {
    if (res.succeeded()) {
      // OK!
    } else {
      // Failed!
    }
  });
}
 
Example 5
Source File: SQL.java    From hono with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Enable auto-commit.
 *
 * @param tracer The tracer.
 * @param context The span.
 * @param connection The database connection to change.
 * @param state The auto-commit state.
 * @return A future for tracking the outcome.
 */
public static Future<SQLConnection> setAutoCommit(final Tracer tracer, final SpanContext context, final SQLConnection connection, final boolean state) {
    final Span span = startSqlSpan(tracer, context, "set autocommit", builder -> {
        builder.withTag("db.autocommit", state);
    });
    final Promise<Void> promise = Promise.promise();
    connection.setAutoCommit(state, promise);
    return finishSpan(promise.future().map(connection), span, null);
}