Example usage for io.vertx.sqlclient RowStream endHandler

List of usage examples for io.vertx.sqlclient RowStream endHandler

Introduction

In this page you can find the example usage for io.vertx.sqlclient RowStream endHandler.

Prototype

@Override
    RowStream<T> endHandler(Handler<Void> endHandler);

Source Link

Usage

From source file:examples.SqlClientExamples.java

License:Apache License

public void usingCursors03(SqlConnection connection) {
    connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar1 -> {
        if (ar1.succeeded()) {
            PreparedQuery pq = ar1.result();

            // Streams require to run within a transaction
            Transaction tx = connection.begin();

            // Fetch 50 rows at a time
            RowStream<Row> stream = pq.createStream(50, Tuple.of("julien"));

            // Use the stream
            stream.exceptionHandler(err -> {
                System.out.println("Error: " + err.getMessage());
            });/*from   w  w  w .  ja  v a  2  s.c o  m*/
            stream.endHandler(v -> {
                tx.commit();
                System.out.println("End of stream");
            });
            stream.handler(row -> {
                System.out.println("User: " + row.getString("last_name"));
            });
        }
    });
}

From source file:examples.SqlClientExamples.java

License:Apache License

public void usingCursors03(SqlConnection connection) {
    connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> {
        if (ar1.succeeded()) {
            PreparedQuery pq = ar1.result();

            // Fetch 50 rows at a time
            RowStream<Row> stream = pq.createStream(50, Tuple.of(18));

            // Use the stream
            stream.exceptionHandler(err -> {
                System.out.println("Error: " + err.getMessage());
            });//from www  . j a v  a 2 s . co m
            stream.endHandler(v -> {
                System.out.println("End of stream");
            });
            stream.handler(row -> {
                System.out.println("User: " + row.getString("last_name"));
            });
        }
    });
}