use of io.vertx.sqlclient.Transaction in project raml-module-builder by folio-org.
the class PostgresClientIT method postgresClientConnectionThrowsException.
/**
* @return a PostgresClient where invoking SQLConnection::update(...) or SQLConnection::updateWithParams
* throws an RuntimeException.
*/
private PostgresClient postgresClientConnectionThrowsException() {
PgConnection pgConnection = new PgConnection() {
@Override
public PgConnection notificationHandler(Handler<PgNotification> handler) {
throw new RuntimeException();
}
@Override
public PgConnection cancelRequest(Handler<AsyncResult<Void>> handler) {
throw new RuntimeException();
}
@Override
public int processId() {
throw new RuntimeException();
}
@Override
public int secretKey() {
throw new RuntimeException();
}
@Override
public PgConnection prepare(String s, Handler<AsyncResult<PreparedStatement>> handler) {
throw new RuntimeException();
}
@Override
public Future<PreparedStatement> prepare(String s) {
return null;
}
@Override
public SqlConnection prepare(String sql, PrepareOptions options, Handler<AsyncResult<PreparedStatement>> handler) {
return null;
}
@Override
public Future<PreparedStatement> prepare(String s, PrepareOptions prepareOptions) {
return null;
}
@Override
public PgConnection exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public PgConnection closeHandler(Handler<Void> handler) {
return null;
}
@Override
public void begin(Handler<AsyncResult<Transaction>> handler) {
}
@Override
public Future<Transaction> begin() {
return null;
}
@Override
public boolean isSSL() {
return false;
}
@Override
public void close(Handler<AsyncResult<Void>> handler) {
close().onComplete(handler);
}
@Override
public Future<Void> close() {
return Future.succeededFuture();
}
@Override
public Query<RowSet<Row>> query(String s) {
throw new RuntimeException();
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String s, PrepareOptions options) {
throw new RuntimeException();
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String s) {
throw new RuntimeException();
}
@Override
public DatabaseMetadata databaseMetadata() {
throw new RuntimeException();
}
};
PgPool client = new PgPoolBase() {
@Override
public Future<SqlConnection> getConnection() {
return Future.succeededFuture(pgConnection);
}
};
try {
PostgresClient postgresClient = new PostgresClient(vertx, TENANT);
postgresClient.setClient(client);
return postgresClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.vertx.sqlclient.Transaction in project raml-module-builder by folio-org.
the class PostgresClientIT method streamGetResultException.
@Test
public void streamGetResultException(TestContext context) {
createTableWithPoLines(context);
ResultInfo resultInfo = new ResultInfo();
context.assertNotNull(vertx);
RowStream<Row> sqlRowStream = new MySQLRowStream();
StringBuilder events = new StringBuilder();
Async async = context.async();
PostgresClientStreamResult<Object> streamResult = new PostgresClientStreamResult(resultInfo);
Transaction transaction = null;
postgresClient.doStreamRowResults(sqlRowStream, Object.class, transaction, new QueryHelper("table_name"), streamResult, context.asyncAssertSuccess(sr -> {
sr.handler(streamHandler -> {
events.append("[handler]");
});
sr.endHandler(x -> {
events.append("[endHandler]");
throw new NullPointerException("null");
});
sr.exceptionHandler(x -> {
events.append("[exception]");
context.assertEquals("SQLRowStream exception", x.getMessage());
async.complete();
});
}));
async.await(1000);
context.assertEquals("[exception]", events.toString());
}
use of io.vertx.sqlclient.Transaction in project raml-module-builder by folio-org.
the class PostgresClientIT method postgresClientQueryReturnBadResults.
/**
* @return a PostgresClient where invoking SQLConnection::queryWithParams will return null ResultSet
*/
private PostgresClient postgresClientQueryReturnBadResults() {
PgConnection pgConnection = new PgConnection() {
@Override
public PgConnection notificationHandler(Handler<PgNotification> handler) {
return null;
}
@Override
public PgConnection cancelRequest(Handler<AsyncResult<Void>> handler) {
return this;
}
@Override
public int processId() {
return 0;
}
@Override
public int secretKey() {
return 0;
}
@Override
public PgConnection prepare(String s, Handler<AsyncResult<PreparedStatement>> handler) {
return null;
}
@Override
public Future<PreparedStatement> prepare(String s) {
return null;
}
@Override
public SqlConnection prepare(String sql, PrepareOptions options, Handler<AsyncResult<PreparedStatement>> handler) {
return null;
}
@Override
public Future<PreparedStatement> prepare(String sql, PrepareOptions options) {
return null;
}
@Override
public PgConnection exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public PgConnection closeHandler(Handler<Void> handler) {
return null;
}
@Override
public void begin(Handler<AsyncResult<Transaction>> handler) {
}
@Override
public Future<Transaction> begin() {
return null;
}
@Override
public boolean isSSL() {
return false;
}
@Override
public void close(Handler<AsyncResult<Void>> handler) {
}
@Override
public Query<RowSet<Row>> query(String s) {
return null;
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String s) {
return null;
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String sql, PrepareOptions options) {
return preparedQuery(sql);
}
@Override
public Future<Void> close() {
return null;
}
@Override
public DatabaseMetadata databaseMetadata() {
return null;
}
};
PgPool client = new PgPoolBase() {
@Override
public Future<SqlConnection> getConnection() {
return Future.succeededFuture(pgConnection);
}
};
try {
PostgresClient postgresClient = new PostgresClient(vertx, TENANT);
postgresClient.setClient(client);
return postgresClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.vertx.sqlclient.Transaction in project vertx-examples by vert-x3.
the class SqlClientExample method start.
@Override
public void start() {
Pool pool = PgPool.pool(vertx, new PgConnectOptions().setPort(5432).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret"), new PoolOptions().setMaxSize(4));
// Uncomment for MySQL
// Pool pool = MySQLPool.pool(vertx, new MySQLConnectOptions()
// .setPort(5432)
// .setHost("the-host")
// .setDatabase("the-db")
// .setUser("user")
// .setPassword("secret"), new PoolOptions().setMaxSize(4));
pool.begin(res1 -> {
if (res1.failed()) {
System.err.println(res1.cause().getMessage());
return;
}
Transaction tx = res1.result();
// create a test table
tx.query("create table test(id int primary key, name varchar(255))").execute(res2 -> {
if (res2.failed()) {
tx.close();
System.err.println("Cannot create the table");
res2.cause().printStackTrace();
return;
}
// insert some test data
tx.query("insert into test values (1, 'Hello'), (2, 'World')").execute(res3 -> {
// rollback transaction
tx.rollback(res4 -> {
// query some data with arguments
pool.query("select * from test").execute(rs -> {
if (rs.failed()) {
System.err.println("Cannot retrieve the data from the database");
rs.cause().printStackTrace();
return;
}
for (Row line : rs.result()) {
System.out.println("" + line);
}
});
});
});
});
});
}
use of io.vertx.sqlclient.Transaction in project vertx-examples by vert-x3.
the class SqlClientExample method start.
@Override
public void start() {
Pool pool = PgPool.pool(vertx, new PgConnectOptions().setPort(5432).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret"), new PoolOptions().setMaxSize(4));
// Uncomment for MySQL
// Pool pool = MySQLPool.pool(vertx, new MySQLConnectOptions()
// .setPort(5432)
// .setHost("the-host")
// .setDatabase("the-db")
// .setUser("user")
// .setPassword("secret"), new PoolOptions().setMaxSize(4));
pool.begin(res1 -> {
if (res1.failed()) {
System.err.println(res1.cause().getMessage());
return;
}
Transaction tx = res1.result();
// create a test table
tx.query("create table test(id int primary key, name varchar(255))").execute(res2 -> {
if (res2.failed()) {
tx.close();
System.err.println("Cannot create the table");
res2.cause().printStackTrace();
return;
}
// insert some test data
tx.query("insert into test values (1, 'Hello'), (2, 'World')").execute(res3 -> {
// query some data with arguments
tx.query("select * from test").execute(rs -> {
if (rs.failed()) {
System.err.println("Cannot retrieve the data from the database");
rs.cause().printStackTrace();
return;
}
for (Row line : rs.result()) {
System.out.println("" + line);
}
// and close the connection
tx.commit();
});
});
});
});
}
Aggregations