Example usage for io.vertx.sqlclient Cursor read

List of usage examples for io.vertx.sqlclient Cursor read

Introduction

In this page you can find the example usage for io.vertx.sqlclient Cursor read.

Prototype

void read(int count, Handler<AsyncResult<RowSet<Row>>> handler);

Source Link

Document

Read rows from the cursor, the result is provided asynchronously to the handler .

Usage

From source file:examples.SqlClientExamples.java

License:Apache License

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

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

            // Create a cursor
            Cursor cursor = pq.cursor(Tuple.of("julien"));

            // Read 50 rows
            cursor.read(50, ar2 -> {
                if (ar2.succeeded()) {
                    RowSet<Row> rows = ar2.result();

                    // Check for more ?
                    if (cursor.hasMore()) {
                        // Repeat the process...
                    } else {
                        // No more rows - commit the transaction
                        tx.commit();//from  ww  w. j  av a  2 s  . c  o  m
                    }
                }
            });
        }
    });
}

From source file:examples.SqlClientExamples.java

License:Apache License

public void usingCursors02(Cursor cursor) {
    cursor.read(50, ar2 -> {
        if (ar2.succeeded()) {
            // Close the cursor
            cursor.close();//from  www.ja v a  2s  .c  o m
        }
    });
}

From source file:examples.SqlClientExamples.java

License:Apache License

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

            // Create a cursor
            Cursor cursor = pq.cursor(Tuple.of(18));

            // Read 50 rows
            cursor.read(50, ar2 -> {
                if (ar2.succeeded()) {
                    RowSet<Row> rows = ar2.result();

                    // Check for more ?
                    if (cursor.hasMore()) {
                        // Repeat the process...
                    } else {
                        // No more rows - close the cursor
                        cursor.close();/*  w  ww.  j a  va2s. c o  m*/
                    }
                }
            });
        }
    });
}