Search in sources :

Example 21 with Row

use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.

the class PostgresClient method queryAndAnalyze.

static void queryAndAnalyze(PgConnection conn, String sql, String statMethod, Handler<AsyncResult<RowSet<Row>>> replyHandler) {
    long start = System.nanoTime();
    conn.query(sql).execute(res -> {
        long queryTime = (System.nanoTime() - start);
        if (res.failed()) {
            log.error("queryAndAnalyze: " + res.cause().getMessage() + " - " + sql, res.cause());
            replyHandler.handle(Future.failedFuture(res.cause()));
            return;
        }
        if (queryTime >= explainQueryThreshold * 1000000) {
            final String explainQuery = "EXPLAIN ANALYZE " + sql;
            conn.query(explainQuery).execute(explain -> {
                // not before, so we have conn if it gets closed
                replyHandler.handle(res);
                if (explain.failed()) {
                    log.warn(explainQuery + ": ", explain.cause().getMessage(), explain.cause());
                    return;
                }
                StringBuilder e = new StringBuilder(explainQuery);
                RowIterator<Row> iterator = explain.result().iterator();
                while (iterator.hasNext()) {
                    Row row = iterator.next();
                    e.append('\n').append(row.getValue(0));
                }
                log.warn(e.toString());
            });
        } else {
            replyHandler.handle(res);
        }
    });
}
Also used : Row(io.vertx.sqlclient.Row)

Example 22 with Row

use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.

the class PostgresClient method deserializeResults.

/**
 * @param resultsHelper
 */
<T> void deserializeResults(ResultsHelper<T> resultsHelper) {
    if (resultsHelper.resultSet == null) {
        return;
    }
    boolean isAuditFlavored = isAuditFlavored(resultsHelper.clazz);
    Map<String, Method> externalColumnSetters = new HashMap<>();
    collectExternalColumnSetters(resultsHelper.resultSet.columnsNames(), resultsHelper.clazz, isAuditFlavored, externalColumnSetters);
    RowIterator<Row> iterator = resultsHelper.resultSet.iterator();
    while (iterator.hasNext()) {
        Row row = iterator.next();
        try {
            T objRow = (T) deserializeRow(resultsHelper, externalColumnSetters, isAuditFlavored, row);
            if (!resultsHelper.facet) {
                resultsHelper.list.add(objRow);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            resultsHelper.list.add(null);
        }
    }
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) Row(io.vertx.sqlclient.Row) InvocationTargetException(java.lang.reflect.InvocationTargetException) TemplateException(freemarker.template.TemplateException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

Row (io.vertx.sqlclient.Row)22 PgPool (io.vertx.pgclient.PgPool)12 ArrayList (java.util.ArrayList)11 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)10 IOException (java.io.IOException)10 PgConnection (io.vertx.pgclient.PgConnection)9 RowSet (io.vertx.sqlclient.RowSet)9 SqlConnection (io.vertx.sqlclient.SqlConnection)9 Transaction (io.vertx.sqlclient.Transaction)9 LinkedList (java.util.LinkedList)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Handler (io.vertx.core.Handler)8 RowImpl (io.vertx.pgclient.impl.RowImpl)8 PreparedStatement (io.vertx.sqlclient.PreparedStatement)8 Tuple (io.vertx.sqlclient.Tuple)8 RowDesc (io.vertx.sqlclient.impl.RowDesc)8 LocalRowSet (org.folio.rest.persist.helpers.LocalRowSet)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 AsyncResult (io.vertx.core.AsyncResult)7 Future (io.vertx.core.Future)7