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

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

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

SQLConnection.updateWithParams介绍

暂无

代码示例

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

private void handleAddProduct(RoutingContext routingContext) {
 HttpServerResponse response = routingContext.response();
 SQLConnection conn = routingContext.get("conn");
 JsonObject product = routingContext.getBodyAsJson();
 conn.updateWithParams("INSERT INTO products (name, price, weight) VALUES (?, ?, ?)",
  new JsonArray().add(product.getString("name")).add(product.getFloat("price")).add(product.getInteger("weight")), query -> {
   if (query.failed()) {
    sendError(500, response);
   } else {
    response.end();
   }
  });
}

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

/**
 * Executes the given prepared statement which may be an <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code>
 * statement with the given parameters
 * @param sql the SQL to execute. For example <code>INSERT INTO table ...</code>
 * @param params these are the parameters to fill the statement.
 * @param resultHandler the handler which is called once the operation completes.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection updateWithParams(String sql, JsonArray params, Handler<AsyncResult<UpdateResult>> resultHandler) { 
 delegate.updateWithParams(sql, params, resultHandler);
 return this;
}

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

/**
 * Executes the given prepared statement which may be an <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code>
 * statement with the given parameters
 * @param sql the SQL to execute. For example <code>INSERT INTO table ...</code>
 * @param params these are the parameters to fill the statement.
 * @param resultHandler the handler which is called once the operation completes.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection updateWithParams(String sql, JsonArray params, Handler<AsyncResult<UpdateResult>> resultHandler) { 
 delegate.updateWithParams(sql, params, resultHandler);
 return this;
}

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

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

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

protected <R> void execute(JsonArray params, String sql, R ret, Handler<AsyncResult<R>> resultHandler) {
 client.getConnection(connHandler(resultHandler, connection -> {
  connection.updateWithParams(sql, params, r -> {
   if (r.succeeded()) {
    resultHandler.handle(Future.succeededFuture(ret));
   } else {
    resultHandler.handle(Future.failedFuture(r.cause()));
   }
   connection.close();
  });
 }));
}

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

protected <K> void removeOne(K id, String sql, Handler<AsyncResult<Void>> resultHandler) {
 client.getConnection(connHandler(resultHandler, connection -> {
  JsonArray params = new JsonArray().add(id);
  connection.updateWithParams(sql, params, r -> {
   if (r.succeeded()) {
    resultHandler.handle(Future.succeededFuture());
   } else {
    resultHandler.handle(Future.failedFuture(r.cause()));
   }
   connection.close();
  });
 }));
}

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

public static io.vertx.ext.sql.SQLConnection updateWithParams(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.updateWithParams(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.UpdateResult>>() {
  public void handle(io.vertx.core.AsyncResult<io.vertx.ext.sql.UpdateResult> 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 call(io.vertx.ext.sql.SQLConnection j_receiver, java.lang.String sql, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {

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

/**
 * Suitable for `add`, `exists` operation.
 *
 * @param params        query params
 * @param sql           sql
 * @param resultHandler async result handler
 */
protected void executeNoResult(JsonArray params, String sql, Handler<AsyncResult<Void>> resultHandler) {
 client.getConnection(connHandler(resultHandler, connection -> {
  connection.updateWithParams(sql, params, r -> {
   if (r.succeeded()) {
    resultHandler.handle(Future.succeededFuture());
   } else {
    resultHandler.handle(Future.failedFuture(r.cause()));
   }
   connection.close();
  });
 }));
}

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

/**
 * @see io.apiman.gateway.engine.components.jdbc.IJdbcConnection#execute(io.apiman.gateway.engine.async.IAsyncResultHandler, java.lang.String, java.lang.Object[])
 */
@Override
public void execute(IAsyncResultHandler<Void> handler, String sql, Object... params) {
  connection.updateWithParams(sql, toJsonArray(params), translateVoidHandlers(handler));
}

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

@Override
public CompletableFuture<Integer> execute(Query query){
  return getConnection().thenCompose(sqlConnection -> {
    CompletableFuture<Integer> cf = new VertxCompletableFuture<>(vertx);
    JsonArray bindValues = getBindValues(query);
    sqlConnection.updateWithParams(query.getSQL(), bindValues, executeAndClose(UpdateResult::getUpdated,sqlConnection,cf));
    return cf;
  });
}

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

@Override
public CompletableFuture<Integer> execute(Query query){
  return getConnection().thenCompose(sqlConnection -> {
    CompletableFuture<Integer> cf = new VertxCompletableFuture<>(vertx);
    JsonArray bindValues = getBindValues(query);
    sqlConnection.updateWithParams(query.getSQL(), bindValues, executeAndClose(UpdateResult::getUpdated,sqlConnection,cf));
    return cf;
  });
}

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

@Override
public void addPaymentRecord(Payment payment, Handler<AsyncResult<Void>> resultHandler) {
 jdbc.getConnection(connHandler(resultHandler, connection -> {
  connection.updateWithParams(INSERT_STATEMENT, new JsonArray().add(payment.getPayId())
   .add(payment.getPayAmount())
   .add(payment.getPaySource())
   .add(payment.getPaymentTime()), r -> {
   if (r.succeeded()) {
    resultHandler.handle(Future.succeededFuture());
   } else {
    resultHandler.handle(Future.failedFuture(r.cause()));
   }
   connection.close();
  });
 }));
}

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

@Override
public CompletableFuture<Integer> execute(Function<DSLContext, ? extends Query> queryFunction) {
  return getConnection().thenCompose(safeExecute(sqlConnection -> {
    Query query = createQuery(queryFunction);
    log(query);
    CompletableFuture<Integer> cf = new VertxCompletableFuture<>(vertx);
    JsonArray bindValues = getBindValues(query);
    sqlConnection.updateWithParams(query.getSQL(), bindValues, executeAndClose(UpdateResult::getUpdated,sqlConnection,cf));
    return cf;
  }));
}

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

@Test
public void testInvalidInsertStatement(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  conn.updateWithParams("INVALID INSERT", new JsonArray(), ar2 -> {
   if (ar2.failed() && ar2.cause() instanceof com.github.jasync.sql.db.exceptions.DatabaseException) {
    async.complete();
   } else {
    context.fail("Should receive an exception of type DatabaseException.");
   }
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testInvalidInsertStatement(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  conn.updateWithParams("INVALID INSERT", new JsonArray(), ar2 -> {
   if (ar2.failed() && ar2.cause() instanceof com.github.mauricio.async.db.exceptions.DatabaseException) {
    async.complete();
   } else {
    context.fail("Should receive an exception of type DatabaseException.");
   }
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testInvalidInsertStatement(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  ensureSuccess(context, ar);
  conn = ar.result();
  conn.updateWithParams("INVALID INSERT", new JsonArray(), ar2 -> {
   if (ar2.failed() && ar2.cause() instanceof com.github.jasync.sql.db.exceptions.DatabaseException) {
    async.complete();
   } else {
    context.fail("Should receive an exception of type DatabaseException.");
   }
  });
 });
}

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

@Test
public void testCustomInsert() {
 String sql = "INSERT INTO t (u, t, d, ts) VALUES (?, ?, ?, ?)";
 final String uuid = UUID.randomUUID().toString();
 final SQLConnection conn = connection();
 conn.setAutoCommit(false, tx -> {
  if (tx.succeeded()) {
   conn.updateWithParams(sql, new JsonArray().add(uuid).add("09:00:00").add("2015-03-16").add(Instant.now()), onSuccess(resultSet -> {
    testComplete();
   }));
  }
 });
 await();
}

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

@Override
public Future<Integer> execute(Function<DSLContext, ? extends Query> queryFunction) {
  return getConnection().compose(safeExecute(sqlConnection -> {
      Query query = createQuery(queryFunction);
      log(query);
      Future<Integer> future = Future.future();
      sqlConnection.updateWithParams(
          query.getSQL(),
          getBindValues(query),
          this.<UpdateResult,Integer>executeAndClose(UpdateResult::getUpdated,
              sqlConnection,
              future)
      );
      return future;
  }));
}

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

@Override
public Future<Integer> execute(Function<DSLContext, ? extends Query> queryFunction) {
  return getConnection().compose(safeExecute(sqlConnection -> {
      Query query = createQuery(queryFunction);
      log(query);
      Future<Integer> future = Future.future();
      sqlConnection.updateWithParams(
          query.getSQL(),
          getBindValues(query),
          this.<UpdateResult,Integer>executeAndClose(UpdateResult::getUpdated,
              sqlConnection,
              future)
      );
      return future;
  }));
}

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

@Test
public void testDeleteWithParams() {
 String sql = "DELETE FROM delete_table WHERE id = ?;";
 JsonArray params = new JsonArray().add(2);
 connection().updateWithParams(sql, params, onSuccess(result -> {
  assertNotNull(result);
  assertEquals(1, result.getUpdated());
  testComplete();
 }));
 await();
}

相关文章