org.jooq.Query.getSQL()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(172)

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

Query.getSQL介绍

[英]Retrieve the SQL code rendered by this Query.

Use this method, when you want to use jOOQ for object oriented query creation, but execute the query with some other technology, such as

  • JDBC
  • Spring Templates
  • JPA native queries
  • etc...

Note, this is the same as calling #getSQL(boolean). The boolean parameter will depend on your DSLContext's Settings:
StatementTypeboolean parametereffectStatementType#PREPARED_STATEMENTfalse (default)This will render bind variables to be used with a JDBC PreparedStatement. You can extract bind values from this Query using #getBindValues()StatementType#STATIC_STATEMENTtrueThis will inline all bind variables in a statement to be used with a JDBC Statement

[#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use the Settings to decide whether to render bind values.
[中]检索此查询呈现的SQL代码。
如果希望使用jOOQ创建面向对象的查询,但需要使用其他技术执行查询,例如
*JDBC
*Spring模板
*JPA本机查询
*等等。。。
注意,这与调用#getSQL(布尔)相同。布尔参数将取决于您的DSLContext设置:
StatementTypeboolean parametereffectStatementType#PREPARED_语句false(默认值)这将呈现要与JDBC PreparedStatement一起使用的绑定变量。您可以使用#getBindValues()语句类型#STATIC_语句true从这个Query中提取绑定值。这将把所有绑定变量内联到一个要与JDBC语句一起使用的语句中
[#1520]请注意,实际执行的查询可能不包含任何绑定变量,以防绑定变量的数量超过SQL方言支持的绑定变量的最大数量。此方法不会反映这一点,它将仅使用设置来决定是否渲染绑定值。

代码示例

代码示例来源:origin: org.jooq/jooq

@Override
public final String getSQL(ParamType paramType) {
  return delegate.getSQL(paramType);
}

代码示例来源:origin: org.jooq/jooq

@Override
@Deprecated
public final String getSQL(boolean inline) {
  return delegate.getSQL(inline);
}

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

protected String toPreparedQuery(Query query){
    String namedQuery = query.getSQL(ParamType.NAMED);
    return namedQuery.replaceAll(pattern, "\\$");
  }
}

代码示例来源:origin: stackoverflow.com

Query query = ctx.insertInto(...).values(...);
ctx.execute(
  query.getSQL().replace("insert into", "insert /*+APPEND*/ into"), 
  query.getBindValues().toArray()
);

代码示例来源:origin: org.jooq/jooq

private final int[] executeStatic() {
    List<Query> queries = new ArrayList<Query>(allBindValues.size());

    for (Object[] bindValues : allBindValues) {
      for (int i = 0; i < bindValues.length; i++)
        query.bind(i + 1, bindValues[i]);

      queries.add(create.query(query.getSQL(INLINED)));
    }

    return create.batch(queries).execute();
  }
}

代码示例来源: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: io.github.jklingsporn/vertx-jooq-async-rx

@Override
public <P> Single<List<P>> fetch(Query query, java.util.function.Function<JsonObject, P> mapper){
  return getConnection().flatMap(executeAndClose(sqlConnection ->
      sqlConnection.rxQueryWithParams(query.getSQL(), getBindValues(query)).map(rs ->
              rs.getRows().stream().map(mapper).collect(Collectors.toList())
      )));
}

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

@Override
public <P> Single<P> fetchOne(Query query, Function<JsonObject, P> mapper){
  return getConnection().flatMap(executeAndClose(sqlConnection ->
    sqlConnection.rxQueryWithParams(query.getSQL(), getBindValues(query)).map(rs -> {
      Optional<P> optional = rs.getRows().stream().findFirst().map(mapper);
      return optional.orElseGet(() -> null);
    })));
}

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

@Override
public <P> Single<List<P>> fetch(Query query, java.util.function.Function<JsonObject, P> mapper){
  return getConnection().flatMap(executeAndClose(sqlConnection ->
      sqlConnection.rxQueryWithParams(query.getSQL(), getBindValues(query)).map(rs ->
              rs.getRows().stream().map(mapper).collect(Collectors.toList())
      )));
}

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

@Override
public <P> Single<P> fetchOne(Query query, Function<JsonObject, P> mapper){
  return getConnection().flatMap(executeAndClose(sqlConnection ->
    sqlConnection.rxQueryWithParams(query.getSQL(), getBindValues(query)).map(rs -> {
      Optional<P> optional = rs.getRows().stream().findFirst().map(mapper);
      return optional.orElseGet(() -> null);
    })));
}

代码示例来源: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: 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<Long> insertReturning(Query query) {
  return getConnection().thenCompose(sqlConnection -> {
    CompletableFuture<Long> cf = new VertxCompletableFuture<>(vertx);
    sqlConnection.update(query.getSQL(ParamType.INLINED), executeAndClose(updateResult->updateResult.getKeys().getLong(0), sqlConnection, cf));
    return cf;
  });
}

代码示例来源: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: com.orientechnologies/spring-data-orientdb-commons

/**
 * Creates the query for the given {@link OrientSource} and {@link org.springframework.data.domain.Sort}.
 *
 * @param source the source
 * @param sort the sort
 * @return the query
 */
private OSQLQuery<T> getQuery(String source, Sort sort) {
  Query query = DSL.using(SQLDialect.MYSQL).select().from(source).orderBy(QueryUtils.toOrders(sort));
  return new OSQLSynchQuery<T>(query.getSQL(ParamType.INLINED));
}

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

@Override
public Single<Integer> execute(Query query){
  return getConnection()
      .flatMap(executeAndClose(sqlConnection ->
          sqlConnection
              .rxUpdateWithParams(query.getSQL(), getBindValues(query))
              .map(UpdateResult::getUpdated))
      );
}

代码示例来源:origin: orientechnologies/spring-data-orientdb

/**
 * Creates the query for the given {@link OrientSource} and {@link org.springframework.data.domain.Sort}.
 *
 * @param source the source
 * @param sort the sort
 * @return the query
 */
private OSQLQuery<T> getQuery(String source, Sort sort) {
  Query query = DSL.using(SQLDialect.MYSQL).select().from(source).orderBy(QueryUtils.toOrders(sort));
  return new OSQLSynchQuery<>(query.getSQL(ParamType.INLINED));
}

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

@Override
public Single<Integer> execute(Query query){
  return getConnection()
      .flatMap(executeAndClose(sqlConnection ->
          sqlConnection
              .rxUpdateWithParams(query.getSQL(), getBindValues(query))
              .map(UpdateResult::getUpdated))
      );
}

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

@Override
public Single<Long> insertReturning(Query query) {
  return getConnection()
      .flatMap(executeAndClose(sqlConnection ->
              sqlConnection
                  .rxUpdateWithParams(query.getSQL(), getBindValues(query))
                  .map(updateResult -> updateResult.getKeys().getLong(0)))
      );
}

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

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

相关文章