Exemple #1
0
 private final String getSQL0(ExecuteContext ctx) {
   if (executePreparedStatements(configuration().settings())) {
     try {
       RenderContext render = new DefaultRenderContext(configuration);
       render.data(DATA_COUNT_BIND_VALUES, true);
       return render.render(this);
     } catch (DefaultRenderContext.ForceInlineSignal e) {
       ctx.data(DATA_FORCE_STATIC_STATEMENT, true);
       return getSQL(INLINED);
     }
   } else {
     return getSQL(INLINED);
   }
 }
Exemple #2
0
  private final Rendered getSQL0(ExecuteContext ctx) {
    Rendered result;

    // [#3542] [#4977] Some dialects do not support bind values in DDL statements
    if (ctx.type() == DDL) {
      ctx.data(DATA_FORCE_STATIC_STATEMENT, true);
      result = new Rendered(getSQL(INLINED));
    } else if (executePreparedStatements(configuration().settings())) {
      try {
        DefaultRenderContext render = new DefaultRenderContext(configuration);
        render.data(DATA_COUNT_BIND_VALUES, true);
        render.visit(this);
        result = new Rendered(render.render(), render.bindValues());
      } catch (DefaultRenderContext.ForceInlineSignal e) {
        ctx.data(DATA_FORCE_STATIC_STATEMENT, true);
        result = new Rendered(getSQL(INLINED));
      }
    } else {
      result = new Rendered(getSQL(INLINED));
    }

    return result;
  }
Exemple #3
0
  @Override
  public final int execute() {
    if (isExecutable()) {

      // Get the attached configuration of this query
      Configuration c = configuration();

      // [#1191] The following triggers a start event on all listeners.
      //         This may be used to provide jOOQ with a JDBC connection,
      //         in case this Query / Configuration was previously
      //         deserialised
      ExecuteContext ctx = new DefaultExecuteContext(c, this);
      ExecuteListener listener = new ExecuteListeners(ctx);

      int result = 0;
      try {
        if (ctx.connection() == null) {
          throw new DetachedException("Cannot execute query. No Connection configured");
        }

        // [#385] If a statement was previously kept open
        if (keepStatement() && statement != null) {
          ctx.sql(sql);
          ctx.statement(statement);
        }

        // [#385] First time statement preparing
        else {
          listener.renderStart(ctx);
          ctx.sql(getSQL0(ctx));
          listener.renderEnd(ctx);

          sql = ctx.sql();

          listener.prepareStart(ctx);
          prepare(ctx);
          listener.prepareEnd(ctx);

          statement = ctx.statement();
        }

        // [#1856] Set the query timeout onto the Statement
        if (timeout != 0) {
          ctx.statement().setQueryTimeout(timeout);
        }

        if (

        // [#1145] Bind variables only for true prepared statements
        // [#2414] Even if parameters are inlined here, child
        //         QueryParts may override this behaviour!
        executePreparedStatements(c.settings())
            &&

            // [#1520] Renderers may enforce static statements, too
            !Boolean.TRUE.equals(ctx.data(DATA_FORCE_STATIC_STATEMENT))) {

          listener.bindStart(ctx);
          using(c).bindContext(ctx.statement()).visit(this);
          listener.bindEnd(ctx);
        }

        result = execute(ctx, listener);
        return result;
      } catch (SQLException e) {
        ctx.sqlException(e);
        listener.exception(ctx);
        throw ctx.exception();
      } finally {

        // [#2385] Successful fetchLazy() needs to keep open resources
        if (!keepResultSet() || ctx.exception() != null) {
          Utils.safeClose(listener, ctx, keepStatement());
        }

        if (!keepStatement()) {
          statement = null;
          sql = null;
        }
      }
    } else {
      if (log.isDebugEnabled()) {
        log.debug("Query is not executable", this);
      }

      return 0;
    }
  }