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);
}
});
}
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);
}
}
}
Aggregations