io.vertx.ext.sql.SQLConnection.queryWithParams()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中io.vertx.ext.sql.SQLConnection.queryWithParams()方法的一些代码示例,展示了SQLConnection.queryWithParams()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLConnection.queryWithParams()方法的具体详情如下:
包路径:io.vertx.ext.sql.SQLConnection
类名称:SQLConnection
方法名:queryWithParams

SQLConnection.queryWithParams介绍

暂无

代码示例

代码示例来源:origin: vert-x3/vertx-examples

connection.queryWithParams("select * from test where id = ?", new JsonArray().add(2), rs -> {
 if (rs.failed()) {
  System.err.println("Cannot retrieve the data from the database");

代码示例来源:origin: vert-x3/vertx-examples

private void handleGetProduct(RoutingContext routingContext) {
 String productID = routingContext.request().getParam("productID");
 HttpServerResponse response = routingContext.response();
 if (productID == null) {
  sendError(400, response);
 } else {
  SQLConnection conn = routingContext.get("conn");
  conn.queryWithParams("SELECT id, name, price, weight FROM products where id = ?", new JsonArray().add(Integer.parseInt(productID)), query -> {
   if (query.failed()) {
    sendError(500, response);
   } else {
    if (query.result().getNumRows() == 0) {
     sendError(404, response);
    } else {
     response.putHeader("content-type", "application/json").end(query.result().getRows().get(0).encode());
    }
   }
  });
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Executes the given SQL <code>SELECT</code> prepared statement which returns the results of the query.
 * @param sql the SQL to execute. For example <code>SELECT * FROM table ...</code>.
 * @param params these are the parameters to fill the statement.
 * @param resultHandler the handler which is called once the operation completes. It will return a <code>ResultSet</code>.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection queryWithParams(String sql, JsonArray params, Handler<AsyncResult<ResultSet>> resultHandler) { 
 delegate.queryWithParams(sql, params, resultHandler);
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Executes the given SQL <code>SELECT</code> prepared statement which returns the results of the query.
 * @param sql the SQL to execute. For example <code>SELECT * FROM table ...</code>.
 * @param params these are the parameters to fill the statement.
 * @param resultHandler the handler which is called once the operation completes. It will return a <code>ResultSet</code>.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection queryWithParams(String sql, JsonArray params, Handler<AsyncResult<ResultSet>> resultHandler) { 
 delegate.queryWithParams(sql, params, resultHandler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-jdbc-client

@Override
public SQLConnection queryWithParams(String sql, JsonArray params, Handler<AsyncResult<ResultSet>> resultHandler) {
 delegate.queryWithParams(sql, params, resultHandler);
 return this;
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
public void retrievePaymentRecord(String payId, Handler<AsyncResult<Payment>> resultHandler) {
 jdbc.getConnection(connHandler(resultHandler, connection -> {
  connection.queryWithParams(FETCH_STATEMENT, new JsonArray().add(payId), r -> {
   if (r.succeeded()) {
    List<JsonObject> resList = r.result().getRows();
    if (resList == null || resList.isEmpty()) {
     resultHandler.handle(Future.succeededFuture());
    } else {
     resultHandler.handle(Future.succeededFuture(new Payment(resList.get(0))));
    }
   } else {
    resultHandler.handle(Future.failedFuture(r.cause()));
   }
   connection.close();
  });
 }));
}

代码示例来源:origin: io.vertx/vertx-lang-groovy

public static io.vertx.ext.sql.SQLConnection queryWithParams(io.vertx.ext.sql.SQLConnection j_receiver, java.lang.String sql, java.util.List<Object> params, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
 io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.queryWithParams(sql,
  params != null ? io.vertx.core.impl.ConversionHelper.toJsonArray(params) : null,
  resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.sql.ResultSet>>() {
  public void handle(io.vertx.core.AsyncResult<io.vertx.ext.sql.ResultSet> ar) {
   resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null));
  }
 } : null));
 return j_receiver;
}
public static io.vertx.ext.sql.SQLConnection queryStreamWithParams(io.vertx.ext.sql.SQLConnection j_receiver, java.lang.String sql, java.util.List<Object> params, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.sql.SQLRowStream>> handler) {

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

protected Future<List<JsonObject>> retrieveMany(JsonArray param, String sql) {
 return getConnection().compose(connection -> {
  Future<List<JsonObject>> future = Future.future();
  connection.queryWithParams(sql, param, r -> {
   if (r.succeeded()) {
    future.complete(r.result().getRows());
   } else {
    future.fail(r.cause());
   }
   connection.close();
  });
  return future;
 });
}

代码示例来源:origin: io.github.jklingsporn/vertx-jooq-async-future

@Override
public <P> CompletableFuture<P> fetchOne(Query query, Function<JsonObject, P> mapper){
  return getConnection().thenCompose(sqlConnection -> {
    CompletableFuture<P> cf = new VertxCompletableFuture<P>(vertx);
    sqlConnection.queryWithParams(query.getSQL(), getBindValues(query), executeAndClose(rs -> {
      Optional<P> optional = rs.getRows().stream().findFirst().map(mapper);
      return optional.orElseGet(() -> null);
    }, sqlConnection, cf));
    return cf;
  });
}

代码示例来源:origin: jklingsporn/vertx-jooq-async

@Override
public <P> void fetch(Query query, Function<JsonObject, P> mapper, Handler<AsyncResult<List<P>>> resultHandler) {
  getConnection().setHandler(sqlConnectionResult->{
    if(sqlConnectionResult.succeeded()){
      log("Fetch", ()-> query.getSQL(ParamType.INLINED));
      sqlConnectionResult.result().queryWithParams(
          query.getSQL(),
          getBindValues(query),
          executeAndClose(rs -> rs.getRows().stream().map(mapper).collect(Collectors.toList()), sqlConnectionResult.result(), resultHandler)
      );
    }else{
      resultHandler.handle(Future.failedFuture(sqlConnectionResult.cause()));
    }
  });
}

代码示例来源:origin: jklingsporn/vertx-jooq-async

@Override
public <P> CompletableFuture<P> fetchOne(Query query, Function<JsonObject, P> mapper){
  return getConnection().thenCompose(sqlConnection -> {
    CompletableFuture<P> cf = new VertxCompletableFuture<P>(vertx);
    sqlConnection.queryWithParams(query.getSQL(), getBindValues(query), executeAndClose(rs -> {
      Optional<P> optional = rs.getRows().stream().findFirst().map(mapper);
      return optional.orElseGet(() -> null);
    }, sqlConnection, cf));
    return cf;
  });
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

protected Future<List<JsonObject>> retrieveByPage(int page, int limit, String sql) {
 JsonArray params = new JsonArray().add(calcPage(page, limit)).add(limit);
 return getConnection().compose(connection -> {
  Future<List<JsonObject>> future = Future.future();
  connection.queryWithParams(sql, params, r -> {
   if (r.succeeded()) {
    future.complete(r.result().getRows());
   } else {
    future.fail(r.cause());
   }
   connection.close();
  });
  return future;
 });
}

代码示例来源:origin: apiman/apiman

/**
 * @see io.apiman.gateway.engine.components.jdbc.IJdbcConnection#query(io.apiman.gateway.engine.async.IAsyncResultHandler, java.lang.String, java.lang.Object[])
 */
@Override
public void query(IAsyncResultHandler<IJdbcResultSet> handler, String sql, Object... params) {
  connection.queryWithParams(sql, toJsonArray(params), result -> {
    if (result.succeeded()) {
      VertxJdbcResultSet jdbcResultSet = new VertxJdbcResultSet(result.result());
      handler.handle(AsyncResultImpl.create(jdbcResultSet));
    } else {
      handler.handle(AsyncResultImpl.create(result.cause()));
    }
  });
}

代码示例来源:origin: jklingsporn/vertx-jooq

@Override
public <R extends Record> CompletableFuture<QueryResult> query(Function<DSLContext, ? extends ResultQuery<R>> queryFunction) {
  return getConnection().thenCompose(safeExecute(sqlConnection -> {
    Query query = createQuery(queryFunction);
    log(query);
    CompletableFuture<QueryResult> cf = new VertxCompletableFuture<>(vertx);
    sqlConnection.queryWithParams(
        query.getSQL(),
        getBindValues(query),
        executeAndClose(AsyncQueryResult::new,sqlConnection,cf)
    );
    return cf;
  }));
}

代码示例来源:origin: jklingsporn/vertx-jooq

@Override
public <Q extends Record> CompletableFuture<List<JsonObject>> findManyJson(Function<DSLContext, ? extends ResultQuery<Q>> queryFunction) {
  return getConnection().thenCompose(safeExecute(sqlConnection -> {
    Query query = createQuery(queryFunction);
    log(query);
    CompletableFuture<List<JsonObject>> cf = new VertxCompletableFuture<>(vertx);
    sqlConnection.queryWithParams(
        query.getSQL(),
        getBindValues(query),
        executeAndClose(ResultSet::getRows,
            sqlConnection,
            cf)
    );
    return cf;
  }));
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

protected void checkConsistency(TestContext context, Async async, SQLConnection conn, long id1, String name1, long id2, String name2) {
 conn.queryWithParams("SELECT name FROM test_table WHERE id = ?", new JsonArray().add(id1), ar5 -> {
  ensureSuccess(context, ar5);
  ResultSet resultSet1 = ar5.result();
  context.assertEquals(name1, resultSet1.getResults().get(0).getString(0));
  conn.queryWithParams("SELECT name FROM test_table WHERE id = ?", new JsonArray().add(id2), ar6 -> {
   ensureSuccess(context, ar6);
   ResultSet resultSet2 = ar6.result();
   context.assertNotEquals(id1, id2);
   context.assertEquals(name2, resultSet2.getResults().get(0).getString(0));
   async.complete();
  });
 });
}

代码示例来源:origin: io.github.jklingsporn/vertx-jooq-classic-async

@Override
public <Q extends Record> Future<List<JsonObject>> findManyJson(Function<DSLContext, ? extends ResultQuery<Q>> queryFunction) {
  return getConnection().compose(safeExecute(sqlConnection -> {
    Query query = createQuery(queryFunction);
    log(query);
    Future<List<JsonObject>> future = Future.future();
    sqlConnection.queryWithParams(
        query.getSQL(),
        getBindValues(query),
        this.<ResultSet,List<JsonObject>>executeAndClose(ResultSet::getRows, sqlConnection, future)
    );
    return future;
  }));
}

代码示例来源:origin: io.github.jklingsporn/vertx-jooq-classic-async

@Override
  public <R extends Record> Future<QueryResult> query(Function<DSLContext, ? extends ResultQuery<R>> queryFunction) {
    return getConnection().compose(safeExecute(sqlConnection -> {
      Query query = createQuery(queryFunction);
      log(query);
      Future<QueryResult> future = Future.future();
      sqlConnection.queryWithParams(
          query.getSQL(),
          getBindValues(query),
          this.executeAndClose(AsyncQueryResult::new,sqlConnection,future)
      );
      return future;
    }));
  }
}

代码示例来源:origin: jklingsporn/vertx-jooq

@Override
public <Q extends Record> Future<List<JsonObject>> findManyJson(Function<DSLContext, ? extends ResultQuery<Q>> queryFunction) {
  return getConnection().compose(safeExecute(sqlConnection -> {
    Query query = createQuery(queryFunction);
    log(query);
    Future<List<JsonObject>> future = Future.future();
    sqlConnection.queryWithParams(
        query.getSQL(),
        getBindValues(query),
        this.<ResultSet,List<JsonObject>>executeAndClose(ResultSet::getRows, sqlConnection, future)
    );
    return future;
  }));
}

代码示例来源:origin: jklingsporn/vertx-jooq

@Override
  public <R extends Record> Future<QueryResult> query(Function<DSLContext, ? extends ResultQuery<R>> queryFunction) {
    return getConnection().compose(safeExecute(sqlConnection -> {
      Query query = createQuery(queryFunction);
      log(query);
      Future<QueryResult> future = Future.future();
      sqlConnection.queryWithParams(
          query.getSQL(),
          getBindValues(query),
          this.executeAndClose(AsyncQueryResult::new,sqlConnection,future)
      );
      return future;
    }));
  }
}

相关文章