io.vertx.ext.sql.SQLConnection.setAutoCommit()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中io.vertx.ext.sql.SQLConnection.setAutoCommit()方法的一些代码示例,展示了SQLConnection.setAutoCommit()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLConnection.setAutoCommit()方法的具体详情如下:
包路径:io.vertx.ext.sql.SQLConnection
类名称:SQLConnection
方法名:setAutoCommit

SQLConnection.setAutoCommit介绍

[英]Sets the auto commit flag for this connection. True by default.
[中]设置此连接的自动提交标志。默认情况下为True。

代码示例

代码示例来源:origin: vert-x3/vertx-examples

private void startTx(SQLConnection conn, Handler<ResultSet> done) {
 conn.setAutoCommit(false, res -> {
  if (res.failed()) {
   throw new RuntimeException(res.cause());
  }
  done.handle(null);
 });
}

代码示例来源:origin: vert-x3/vertx-examples

private void startTx(SQLConnection conn, Handler<ResultSet> done) {
 conn.setAutoCommit(false, res -> {
  if (res.failed()) {
   throw new RuntimeException(res.cause());
  }
  done.handle(null);
 });
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Sets the auto commit flag for this connection. True by default.
 * @param autoCommit the autoCommit flag, true by default.
 * @param resultHandler the handler which is called once this operation completes.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection setAutoCommit(boolean autoCommit, Handler<AsyncResult<Void>> resultHandler) { 
 delegate.setAutoCommit(autoCommit, resultHandler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Sets the auto commit flag for this connection. True by default.
 * @param autoCommit the autoCommit flag, true by default.
 * @param resultHandler the handler which is called once this operation completes.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection setAutoCommit(boolean autoCommit, Handler<AsyncResult<Void>> resultHandler) { 
 delegate.setAutoCommit(autoCommit, resultHandler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-jdbc-client

@Override
public SQLConnection setAutoCommit(boolean autoCommit, Handler<AsyncResult<Void>> resultHandler) {
 delegate.setAutoCommit(autoCommit, resultHandler);
 return this;
}

代码示例来源:origin: apiman/apiman

@Override
public void setAutoCommit(boolean autoCommit, IAsyncResultHandler<Void> handler) {
  connection.setAutoCommit(autoCommit, translateVoidHandlers(handler));
}

代码示例来源:origin: com.jporm/jpo-rx-vertx3

@Override
public CompletableFuture<AsyncConnection> getConnection(final boolean autoCommit) {
  CompletableFuture<AsyncConnection> connection = new CompletableFuture<>();
  jdbcService.getConnection(handler -> {
    if (handler.succeeded()) {
      handler.result().setAutoCommit(true, autoCommitHandler -> {
        if (autoCommitHandler.succeeded()) {
          connection.complete(new Vertx3AsyncConnection(handler.result()));
        } else {
          connection.completeExceptionally(handler.cause());
        }
      });
    } else {
      connection.completeExceptionally(handler.cause());
    }
  });
  return connection;
}

代码示例来源:origin: io.vertx/vertx-jdbc-client

@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();
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Test
public void testEmptyTransactions(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.setAutoCommit(false, ar2 -> {
   ensureSuccess(context, ar2);
   conn.rollback(ar3 -> {
    ensureSuccess(context, ar3);
    conn.commit(ar4 -> {
     ensureSuccess(context, ar4);
     conn.setAutoCommit(true, ar5 -> {
      ensureSuccess(context, ar5);
      async.complete();
     });
    });
   });
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testEmptyTransactions(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.setAutoCommit(false, ar2 -> {
   ensureSuccess(context, ar2);
   conn.rollback(ar3 -> {
    ensureSuccess(context, ar3);
    conn.commit(ar4 -> {
     ensureSuccess(context, ar4);
     conn.setAutoCommit(true, ar5 -> {
      ensureSuccess(context, ar5);
      async.complete();
     });
    });
   });
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testRollingBackWhenNotInTransaction(TestContext context) {
 int id = 0;
 String name = "adele";
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  setupSimpleTable(conn, ar2 -> {
   ensureSuccess(context, ar2);
   conn.setAutoCommit(false, ar3 -> {
    ensureSuccess(context, ar3);
    conn.updateWithParams("UPDATE test_table SET name=? WHERE id=?",
     new JsonArray().add(name).add(id), ar4 -> {
      ensureSuccess(context, ar4);
      conn.setAutoCommit(true, ar5 -> {
       ensureSuccess(context, ar5);
       conn.rollback(ar6 -> {
        context.assertTrue(ar6.failed());
        async.complete();
       });
      });
     });
   });
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testTwoTransactionsAfterEachOther(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.setAutoCommit(false, ar2 -> {
   ensureSuccess(context, ar2);
   conn.query("SELECT 1", ar3 -> {
    ensureSuccess(context, ar3);
    conn.commit(ar4 -> {
     ensureSuccess(context, ar4);
     conn.query("SELECT 2", ar5 -> {
      ensureSuccess(context, ar5);
      conn.commit(ar6 -> {
       ensureSuccess(context, ar6);
       conn.setAutoCommit(true, ar7 -> {
        ensureSuccess(context, ar7);
        async.complete();
       });
      });
     });
    });
   });
  });
 });
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Test
public void testRollingBackWhenNotInTransaction(TestContext context) {
 int id = 0;
 String name = "adele";
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  setupSimpleTable(conn, ar2 -> {
   ensureSuccess(context, ar2);
   conn.setAutoCommit(false, ar3 -> {
    ensureSuccess(context, ar3);
    conn.updateWithParams("UPDATE test_table SET name=? WHERE id=?",
     new JsonArray().add(name).add(id), ar4 -> {
      ensureSuccess(context, ar4);
      conn.setAutoCommit(true, ar5 -> {
       ensureSuccess(context, ar5);
       conn.rollback(ar6 -> {
        context.assertTrue(ar6.failed());
        async.complete();
       });
      });
     });
   });
  });
 });
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Test
public void testCommitWhenNotInTransaction(TestContext context) {
 int id = 0;
 String name = "adele";
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  setupSimpleTable(conn, ar2 -> {
   ensureSuccess(context, ar2);
   conn.setAutoCommit(false, ar3 -> {
    ensureSuccess(context, ar3);
    conn.updateWithParams("UPDATE test_table SET name=? WHERE id=?",
     new JsonArray().add(name).add(id), ar4 -> {
      ensureSuccess(context, ar4);
      conn.setAutoCommit(true, ar5 -> {
       ensureSuccess(context, ar5);
       conn.commit(ar6 -> {
        context.assertTrue(ar6.failed());
        async.complete();
       });
      });
     });
   });
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testCommitWhenNotInTransaction(TestContext context) {
 int id = 0;
 String name = "adele";
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  setupSimpleTable(conn, ar2 -> {
   ensureSuccess(context, ar2);
   conn.setAutoCommit(false, ar3 -> {
    ensureSuccess(context, ar3);
    conn.updateWithParams("UPDATE test_table SET name=? WHERE id=?",
     new JsonArray().add(name).add(id), ar4 -> {
      ensureSuccess(context, ar4);
      conn.setAutoCommit(true, ar5 -> {
       ensureSuccess(context, ar5);
       conn.commit(ar6 -> {
        context.assertTrue(ar6.failed());
        async.complete();
       });
      });
     });
   });
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testRollingBackWhenNotInTransaction(TestContext context) {
 int id = 0;
 String name = "adele";
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  setupSimpleTable(conn, ar2 -> {
   ensureSuccess(context, ar2);
   conn.setAutoCommit(false, ar3 -> {
    ensureSuccess(context, ar3);
    conn.updateWithParams("UPDATE test_table SET name=? WHERE id=?",
     new JsonArray().add(name).add(id), ar4 -> {
      ensureSuccess(context, ar4);
      conn.setAutoCommit(true, ar5 -> {
       ensureSuccess(context, ar5);
       conn.rollback(ar6 -> {
        context.assertTrue(ar6.failed());
        async.complete();
       });
      });
     });
   });
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testCommitWhenNotInTransaction(TestContext context) {
 int id = 0;
 String name = "adele";
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  setupSimpleTable(conn, ar2 -> {
   ensureSuccess(context, ar2);
   conn.setAutoCommit(false, ar3 -> {
    ensureSuccess(context, ar3);
    conn.updateWithParams("UPDATE test_table SET name=? WHERE id=?",
     new JsonArray().add(name).add(id), ar4 -> {
      ensureSuccess(context, ar4);
      conn.setAutoCommit(true, ar5 -> {
       ensureSuccess(context, ar5);
       conn.commit(ar6 -> {
        context.assertTrue(ar6.failed());
        async.complete();
       });
      });
     });
   });
  });
 });
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Test
public void testTwoTransactionsAfterEachOther(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.setAutoCommit(false, ar2 -> {
   ensureSuccess(context, ar2);
   conn.query("SELECT 1", ar3 -> {
    ensureSuccess(context, ar3);
    conn.commit(ar4 -> {
     ensureSuccess(context, ar4);
     conn.query("SELECT 2", ar5 -> {
      ensureSuccess(context, ar5);
      conn.commit(ar6 -> {
       ensureSuccess(context, ar6);
       conn.setAutoCommit(true, ar7 -> {
        ensureSuccess(context, ar7);
        async.complete();
       });
      });
     });
    });
   });
  });
 });
}

代码示例来源:origin: io.vertx/vertx-jdbc-client

@Test
public void testWorkerPerConnection() {
 int numConns = 4;
 ArrayList<SQLConnection> conns = new ArrayList<>();
 for (int i = 0; i < numConns; i++) {
  conns.add(connection());
 }
 AtomicInteger count = new AtomicInteger();
 Context context = vertx.getOrCreateContext();
 context.runOnContext(v -> {
  for (SQLConnection conn : conns) {
   conn.setAutoCommit(false, onSuccess(ar1 -> {
    conn.execute("LOCK TABLE insert_table WRITE", onSuccess(ar2 -> {
     String sql = "INSERT INTO insert_table VALUES (null, 'doe', 'john', '2001-01-01');";
     conn.update(sql, onSuccess(res3 -> {
      conn.commit(onSuccess(committed -> {
       conn.close(onSuccess(closed -> {
        if (count.incrementAndGet() == numConns) {
         testComplete();
        }
       }));
      }));
     }));
    }));
   }));
  }
 });
 await();
}

代码示例来源:origin: io.vertx/vertx-jdbc-client

@Test
public void testSelectTx() {
 String sql = "INSERT INTO insert_table VALUES (?, ?, ?, ?);";
 JsonArray params = new JsonArray().addNull().add("smith").add("john").add("2003-03-03");
 client.getConnection(onSuccess(conn -> {
  assertNotNull(conn);
  conn.setAutoCommit(false, onSuccess(v -> {
   conn
    .setOptions(new SQLOptions().setAutoGeneratedKeys(true))
    .updateWithParams(sql, params, onSuccess((UpdateResult updateResult) -> {
     assertUpdate(updateResult, 1);
     int id = updateResult.getKeys().getInteger(0);
     // Explicit typing of resultset is not really necessary but without it IntelliJ reports
     // syntax error :(
     conn.queryWithParams("SELECT LNAME FROM insert_table WHERE id = ?", new JsonArray().add(id), onSuccess((ResultSet resultSet) -> {
      assertFalse(resultSet.getResults().isEmpty());
      assertEquals("smith", resultSet.getResults().get(0).getString(0));
      testComplete();
     }));
    }));
  }));
 }));
 await();
}

相关文章