io.vertx.sqlclient.SqlResult Java Examples
The following examples show how to use
io.vertx.sqlclient.SqlResult.
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: MySQLClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void collector01Example(SqlClient client) { // Create a collector projecting a row set to a map Collector<Row, ?, Map<Long, String>> collector = Collectors.toMap( row -> row.getLong("id"), row -> row.getString("last_name")); // Run the query with the collector client.query("SELECT * FROM users").collecting(collector).execute(ar -> { if (ar.succeeded()) { SqlResult<Map<Long, String>> result = ar.result(); // Get the map created by the collector Map<Long, String> map = result.value(); System.out.println("Got " + map); } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
Example #2
Source File: PgClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void collector01Example(SqlClient client) { // Create a collector projecting a row set to a map Collector<Row, ?, Map<Long, String>> collector = Collectors.toMap( row -> row.getLong("id"), row -> row.getString("last_name")); // Run the query with the collector client.query("SELECT * FROM users") .collecting(collector) .execute(ar -> { if (ar.succeeded()) { SqlResult<Map<Long, String>> result = ar.result(); // Get the map created by the collector Map<Long, String> map = result.value(); System.out.println("Got " + map); } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
Example #3
Source File: PgClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void collector02Example(SqlClient client) { // Create a collector projecting a row set to a (last_name_1,last_name_2,...) Collector<Row, ?, String> collector = Collectors.mapping( row -> row.getString("last_name"), Collectors.joining(",", "(", ")") ); // Run the query with the collector client.query("SELECT * FROM users").collecting(collector).execute(ar -> { if (ar.succeeded()) { SqlResult<String> result = ar.result(); // Get the string created by the collector String list = result.value(); System.out.println("Got " + list); } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
Example #4
Source File: PgPoolTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testPool(TestContext ctx) { int num = 5000; Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { pool.getConnection(ctx.asyncAssertSuccess(conn -> { conn.query("SELECT id, randomnumber from WORLD").execute(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(10000, result.size()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); } conn.close(); async.countDown(); }); })); } }
Example #5
Source File: PgPoolTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testQuery(TestContext ctx) { int num = 1000; Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { pool.query("SELECT id, randomnumber from WORLD").execute(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(10000, result.size()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); } async.countDown(); }); } }
Example #6
Source File: PgPoolTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
private void testQueryWithParams(TestContext ctx, PgConnectOptions options) { int num = 2; Async async = ctx.async(num); PgPool pool = createPool(options, 1); for (int i = 0;i < num;i++) { pool.preparedQuery("SELECT id, randomnumber from WORLD where id=$1").execute(Tuple.of(i + 1), ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(1, result.size()); } else { ar.cause().printStackTrace(); ctx.assertEquals("closed", ar.cause().getMessage()); } async.countDown(); }); } }
Example #7
Source File: PgPoolTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testUpdate(TestContext ctx) { int num = 1000; Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { pool.query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9").execute(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(1, result.rowCount()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); } async.countDown(); }); } }
Example #8
Source File: PgPoolTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testUpdateWithParams(TestContext ctx) { int num = 1000; Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { pool.preparedQuery("UPDATE Fortune SET message = 'Whatever' WHERE id = $1").execute(Tuple.of(9), ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(1, result.rowCount()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); } async.countDown(); }); } }
Example #9
Source File: PgConnectionTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testQueueQueries(TestContext ctx) { int num = 1000; Async async = ctx.async(num + 1); connector.accept(ctx.asyncAssertSuccess(conn -> { for (int i = 0;i < num;i++) { conn .query("SELECT id, randomnumber from WORLD") .execute(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(10000, result.size()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); } async.countDown(); }); } conn.closeHandler(v -> { ctx.assertEquals(1, async.count()); async.countDown(); }); conn.close(); })); }
Example #10
Source File: DB2ClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void collector01Example(SqlClient client) { // Create a collector projecting a row set to a map Collector<Row, ?, Map<Long, String>> collector = Collectors.toMap( row -> row.getLong("id"), row -> row.getString("last_name")); // Run the query with the collector client.query("SELECT * FROM users") .collecting(collector) .execute(ar -> { if (ar.succeeded()) { SqlResult<Map<Long, String>> result = ar.result(); // Get the map created by the collector Map<Long, String> map = result.value(); System.out.println("Got " + map); } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
Example #11
Source File: DB2ClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void collector02Example(SqlClient client) { // Create a collector projecting a row set to a (last_name_1,last_name_2,...) Collector<Row, ?, String> collector = Collectors.mapping( row -> row.getString("last_name"), Collectors.joining(",", "(", ")") ); // Run the query with the collector client.query("SELECT * FROM users").collecting(collector).execute(ar -> { if (ar.succeeded()) { SqlResult<String> result = ar.result(); // Get the string created by the collector String list = result.value(); System.out.println("Got " + list); } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
Example #12
Source File: MySQLClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void collector02Example(SqlClient client) { // Create a collector projecting a row set to a (last_name_1,last_name_2,...) Collector<Row, ?, String> collector = Collectors.mapping( row -> row.getString("last_name"), Collectors.joining(",", "(", ")") ); // Run the query with the collector client.query("SELECT * FROM users").collecting(collector).execute(ar -> { if (ar.succeeded()) { SqlResult<String> result = ar.result(); // Get the string created by the collector String list = result.value(); System.out.println("Got " + list); } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
Example #13
Source File: PreparedStatementImpl.java From vertx-sql-client with Apache License 2.0 | 6 votes |
<R, F extends SqlResult<R>> void execute(Tuple args, int fetch, String cursorId, boolean suspended, QueryExecutor<R, ?, F> builder, Promise<F> p) { if (context == Vertx.currentContext()) { builder.executeExtendedQuery( conn, ps, autoCommit, args, fetch, cursorId, suspended, p); } else { context.runOnContext(v -> execute(args, fetch, cursorId, suspended, builder, p)); } }
Example #14
Source File: PostgresClientTest.java From raml-module-builder with Apache License 2.0 | 5 votes |
@Override public Query<RowSet<Row>> query(String s) { return new Query<RowSet<Row>>() { @Override public void execute(Handler<AsyncResult<RowSet<Row>>> handler) { if (s.startsWith("EXPLAIN") && failExplain) { handler.handle(Future.failedFuture("failExplain")); } else if (s.startsWith("COUNT ") && asyncResult.succeeded()) { List<String> columnNames = new LinkedList<>(); columnNames.add("COUNT"); RowDesc rowDesc = new RowDesc(columnNames); Row row = new RowImpl(rowDesc); row.addInteger(asyncResult.result().size()); List<Row> rows = new LinkedList<>(); rows.add(row); RowSet rowSet = new LocalRowSet(asyncResult.result().size()).withColumns(columnNames).withRows(rows); handler.handle(Future.succeededFuture(rowSet)); } else { handler.handle(asyncResult); } } @Override public <R> Query<SqlResult<R>> collecting(Collector<Row, ?, R> collector) { return null; } @Override public <U> Query<RowSet<U>> mapping(Function<Row, U> function) { return null; } }; }
Example #15
Source File: PreparedStatementImpl.java From vertx-sql-client with Apache License 2.0 | 5 votes |
<R, F extends SqlResult<R>> void executeBatch(List<Tuple> argsList, QueryExecutor<R, ?, F> builder, Promise<F> p) { if (context == Vertx.currentContext()) { builder.executeBatchQuery(conn, ps, autoCommit, argsList, p); } else { context.runOnContext(v -> executeBatch(argsList, builder, p)); } }
Example #16
Source File: PgClientTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test public void testLocalDateTimeWithCodegenCollector(TestContext ctx) { SqlTemplate<Map<String, Object>, SqlResult<List<LocalDateTimeDataObject>>> template = SqlTemplate .forQuery(connection, "SELECT #{value} :: TIMESTAMP WITHOUT TIME ZONE \"localDateTime\"") .collecting(LocalDateTimeDataObjectRowMapper.COLLECTOR); LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); template.execute(Collections.singletonMap("value", ldt), ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(ldt, result.value().get(0).getLocalDateTime()); })); }
Example #17
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> Future<SqlResult<R>> query(String string, Collector<Row, ?, R> clctr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #18
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> SqlConnection preparedBatch(String string, List<Tuple> list, Collector<Row, ?, R> clctr, Handler<AsyncResult<SqlResult<R>>> hndlr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #19
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> SqlConnection preparedQuery(String string, Tuple tuple, Collector<Row, ?, R> clctr, Handler<AsyncResult<SqlResult<R>>> hndlr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #20
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> SqlConnection query(String string, Collector<Row, ?, R> clctr, Handler<AsyncResult<SqlResult<R>>> hndlr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #21
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> SqlConnection preparedQuery(String string, Collector<Row, ?, R> clctr, Handler<AsyncResult<SqlResult<R>>> hndlr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #22
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> Future<SqlResult<R>> preparedQuery(String string, Collector<Row, ?, R> clctr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #23
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> Future<SqlResult<R>> preparedQuery(String string, Tuple tuple, Collector<Row, ?, R> clctr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #24
Source File: PostgresQueryTest.java From okapi with Apache License 2.0 | 4 votes |
@Override public <R> Future<SqlResult<R>> preparedBatch(String string, List<Tuple> list, Collector<Row, ?, R> clctr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
Example #25
Source File: SqlClientBase.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override protected <T2, R2 extends SqlResult<T2>> QueryBase<T2, R2> copy(QueryExecutor<T2, ?, R2> builder) { return new QueryImpl<>(autoCommit, singleton, sql, builder); }
Example #26
Source File: SqlResultBase.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override public SqlResult<T> next() { return next; }
Example #27
Source File: PreparedStatementImpl.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override public <U> PreparedQuery<SqlResult<U>> collecting(Collector<Row, ?, U> collector) { return (PreparedQuery<SqlResult<U>>) super.collecting(collector); }
Example #28
Source File: PreparedStatementImpl.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override protected <T2, R2 extends SqlResult<T2>> QueryBase<T2, R2> copy(QueryExecutor<T2, ?, R2> builder) { return new PreparedStatementQuery<>(builder); }
Example #29
Source File: SqlClientBase.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override protected <T2, R2 extends SqlResult<T2>> QueryBase<T2, R2> copy(QueryExecutor<T2, ?, R2> builder) { return new PreparedQueryImpl<>(autoCommit, singleton, sql, builder); }
Example #30
Source File: SqlClientBase.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override public <U> PreparedQuery<SqlResult<U>> collecting(Collector<Row, ?, U> collector) { return (PreparedQuery<SqlResult<U>>) super.collecting(collector); }