connection.queryStream("select * from test", stream -> { if (stream.succeeded()) { SQLRowStream sqlRowStream = stream.result();
/** * Executes the given SQL <code>SELECT</code> statement which returns the results of the query as a read stream. * @param sql the SQL to execute. For example <code>SELECT * FROM table ...</code>. * @param handler the handler which is called once the operation completes. It will return a <code>SQLRowStream</code>. * @return */ public io.vertx.rxjava.ext.sql.SQLConnection queryStream(String sql, Handler<AsyncResult<io.vertx.rxjava.ext.sql.SQLRowStream>> handler) { delegate.queryStream(sql, new Handler<AsyncResult<io.vertx.ext.sql.SQLRowStream>>() { public void handle(AsyncResult<io.vertx.ext.sql.SQLRowStream> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.sql.SQLRowStream.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
/** * Executes the given SQL <code>SELECT</code> statement which returns the results of the query as a read stream. * @param sql the SQL to execute. For example <code>SELECT * FROM table ...</code>. * @param handler the handler which is called once the operation completes. It will return a <code>SQLRowStream</code>. * @return */ public io.vertx.rxjava.ext.sql.SQLConnection queryStream(String sql, Handler<AsyncResult<io.vertx.rxjava.ext.sql.SQLRowStream>> handler) { delegate.queryStream(sql, new Handler<AsyncResult<io.vertx.ext.sql.SQLRowStream>>() { public void handle(AsyncResult<io.vertx.ext.sql.SQLRowStream> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.sql.SQLRowStream.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
@Override public SQLConnection queryStream(String sql, Handler<AsyncResult<SQLRowStream>> handler) { delegate.queryStream(sql, handler); return this; }
} else { final SQLConnection conn = getConnection.result(); conn.queryStream(sql, query -> { if (query.failed()) { conn.close(close -> {
@Test public void testUnhandledExceptionInHandlerRowStream(TestContext testContext) { this.<SQLRowStream>testUnhandledExceptionInHandler(testContext, (sqlConnection, handler) -> { sqlConnection.queryStream("SELECT name FROM test_table", handler); }); }
@Test public void testUnhandledExceptionInHandlerRowStream(TestContext testContext) { this.<SQLRowStream>testUnhandledExceptionInHandler(testContext, (sqlConnection, handler) -> { sqlConnection.queryStream("SELECT name FROM test_table", handler); }); }
@Test public void testUnhandledExceptionInHandlerRowStream(TestContext testContext) { this.<SQLRowStream>testUnhandledExceptionInHandler(testContext, (sqlConnection, handler) -> { sqlConnection.queryStream("SELECT name FROM test_table", handler); }); }
public void testStreamFlowControl(Handler<SQLRowStream> initHandler, Handler<SQLRowStream> dataHandler) { String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID"; final AtomicInteger cnt = new AtomicInteger(0); final long[] t = {0, 0}; connection().queryStream(sql, onSuccess(res -> { res.handler(row -> { t[cnt.getAndIncrement()] = System.currentTimeMillis(); dataHandler.handle(res); }).endHandler(v -> { assertEquals(2, cnt.get()); assertTrue(t[1] - t[0] >= 1000); testComplete(); }).exceptionHandler(t0 -> { fail(t0); }); initHandler.handle(res); })); await(); }
setupSimpleTable(conn, ar2 -> { conn.queryStream("SELECT name, id FROM test_table ORDER BY name ASC", ar3 -> { if (ar3.failed()) { context.fail(ar3.cause());
setupSimpleTable(conn, ar2 -> { conn.queryStream("SELECT name, id FROM test_table ORDER BY name ASC", ar3 -> { if (ar3.failed()) { context.fail(ar3.cause());
setupSimpleTable(conn, ar2 -> { conn.queryStream("SELECT name, id FROM test_table ORDER BY name ASC", ar3 -> { if (ar3.failed()) { context.fail(ar3.cause());
@Test public void testStreamGetColumns() { String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID"; connection().queryStream(sql, onSuccess(res -> { assertEquals(Arrays.asList("ID", "FNAME", "LNAME"), res.columns()); // assert the collection is immutable try { res.columns().add("durp!"); fail(); } catch (RuntimeException e) { // expected! } testComplete(); })); await(); }
conn.queryStream("SELECT name, id FROM test_table ORDER BY name ASC", ar3 -> { if (ar3.failed()) { context.fail(ar3.cause());
conn.queryStream("SELECT name, id FROM test_table ORDER BY name ASC", ar3 -> { if (ar3.failed()) { context.fail(ar3.cause());
@Test public void testStreamColumnResolution() { String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID"; final AtomicInteger cnt = new AtomicInteger(0); connection().queryStream(sql, onSuccess(res -> { res.handler(row -> { assertEquals("doe", row.getString(res.column("lname"))); cnt.incrementAndGet(); }).endHandler(v -> { assertEquals(2, cnt.get()); testComplete(); }).exceptionHandler(t -> { fail(t); }); })); await(); }
@Test public void testBigStream() { String sql = "SELECT * FROM big_table"; final AtomicInteger cnt = new AtomicInteger(0); connection().queryStream(sql, onSuccess(res -> { res.resultSetClosedHandler(v -> { res.moreResults(); }).handler(row -> { cnt.incrementAndGet(); }).endHandler(v -> { assertEquals(200, cnt.get()); testComplete(); }).exceptionHandler(t -> { fail(t); }); })); await(); }
@Test public void testStream() { String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID"; final AtomicInteger cnt = new AtomicInteger(0); connection().queryStream(sql, onSuccess(res -> { res.resultSetClosedHandler(v -> { res.moreResults(); }).handler(row -> { cnt.incrementAndGet(); }).endHandler(v -> { assertEquals(2, cnt.get()); testComplete(); }).exceptionHandler(t -> { fail(t); }); })); await(); }
@Test public void testStreamOnClosedConnection() { String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID"; final AtomicInteger cnt = new AtomicInteger(0); final SQLConnection conn = connection(); conn.queryStream(sql, onSuccess(res -> { conn.close(); res.resultSetClosedHandler(v -> { fail("Should not happen"); }).handler(row -> { fail("Should not happen"); }).endHandler(v -> { fail("Should not happen"); }).exceptionHandler(t -> { testComplete(); }); })); await(); }
@Test public void testStreamAbort() { String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID"; connection().queryStream(sql, onSuccess(res -> { res.handler(row -> { res.close(close -> { testComplete(); }); }).endHandler(v -> { fail("Should not be called"); }).exceptionHandler(t -> { fail(t); }); })); await(); }