Search in sources :

Example 16 with PgConnection

use of io.vertx.pgclient.PgConnection in project raml-module-builder by folio-org.

the class PostgresClient method removePersistentCacheResult.

private void removePersistentCacheResult(AsyncResult<SQLConnection> conn, String cacheName, Handler<AsyncResult<Integer>> replyHandler) {
    try {
        if (conn.failed()) {
            replyHandler.handle(Future.failedFuture(conn.cause()));
            return;
        }
        long start = System.nanoTime();
        PgConnection connection = conn.result().conn;
        connection.query("DROP TABLE " + schemaName + DOT + cacheName).execute(query -> {
            statsTracker("removePersistentCacheResult", "DROP TABLE " + cacheName, start);
            if (query.failed()) {
                replyHandler.handle(Future.failedFuture(query.cause()));
            } else {
                replyHandler.handle(Future.succeededFuture(query.result().rowCount()));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        replyHandler.handle(Future.failedFuture(e));
    }
}
Also used : PgConnection(io.vertx.pgclient.PgConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) TemplateException(freemarker.template.TemplateException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 17 with PgConnection

use of io.vertx.pgclient.PgConnection in project raml-module-builder by folio-org.

the class PostgresClient method persistentlyCacheResult.

private void persistentlyCacheResult(AsyncResult<SQLConnection> conn, String cacheName, String sql2cache, Handler<AsyncResult<Integer>> replyHandler) {
    try {
        if (conn.failed()) {
            replyHandler.handle(Future.failedFuture(conn.cause()));
            return;
        }
        long start = System.nanoTime();
        PgConnection connection = conn.result().conn;
        String q = "CREATE UNLOGGED TABLE IF NOT EXISTS " + schemaName + DOT + cacheName + " AS " + sql2cache;
        log.info(q);
        connection.query(q).execute(query -> {
            statsTracker("persistentlyCacheResult", "CREATE TABLE AS", start);
            if (query.failed()) {
                replyHandler.handle(Future.failedFuture(query.cause()));
            } else {
                replyHandler.handle(Future.succeededFuture(query.result().rowCount()));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        replyHandler.handle(Future.failedFuture(e));
    }
}
Also used : PgConnection(io.vertx.pgclient.PgConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) TemplateException(freemarker.template.TemplateException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

PgConnection (io.vertx.pgclient.PgConnection)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 RowSet (io.vertx.sqlclient.RowSet)9 IOException (java.io.IOException)8 Handler (io.vertx.core.Handler)7 PgPool (io.vertx.pgclient.PgPool)7 Row (io.vertx.sqlclient.Row)7 SqlConnection (io.vertx.sqlclient.SqlConnection)7 PreparedStatement (io.vertx.sqlclient.PreparedStatement)6 Transaction (io.vertx.sqlclient.Transaction)6 TemplateException (freemarker.template.TemplateException)5 Tuple (io.vertx.sqlclient.Tuple)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArrayList (java.util.ArrayList)5 Function (java.util.function.Function)5 QueryHelper (org.folio.rest.persist.PostgresClient.QueryHelper)5 FacetField (org.folio.rest.persist.facets.FacetField)5 Test (org.junit.Test)5 AsyncResult (io.vertx.core.AsyncResult)4 Future (io.vertx.core.Future)4