/** * Provide delegate listeners from an <code>ExecuteContext</code> */ private static List<ExecuteListener> listeners(ExecuteContext ctx) { List<ExecuteListener> result = new ArrayList<ExecuteListener>(); if (!FALSE.equals(ctx.configuration().settings().isExecuteLogging())) { result.add(new LoggerListener()); result.add(new StopWatchListener()); } for (ExecuteListenerProvider provider : ctx.configuration().executeListenerProviders()) { // Could be null after deserialisation if (provider != null) { result.add(provider.provide()); } } return result; }
private final <U> void fetchOutParameter(ExecuteContext ctx, Parameter<U> parameter) throws SQLException { { DefaultBindingGetStatementContext<U> out = new DefaultBindingGetStatementContext<U>( ctx.configuration(), ctx.data(), (CallableStatement) ctx.statement(), resultIndexes.get(parameter) ); parameter.getBinding().get(out); outValues.put(parameter, out.value()); } }
CursorImpl(ExecuteContext ctx, ExecuteListener listener, Field<?>[] fields, int[] internIndexes, boolean keepStatement, boolean keepResultSet, Class<? extends R> type, int maxRows) { super(ctx.configuration(), new Fields<R>(fields)); this.ctx = ctx; this.listener = (listener != null ? listener : ExecuteListeners.get(ctx)); this.cursorFields = fields; this.factory = recordFactory(type, fields); this.keepStatement = keepStatement; this.keepResultSet = keepResultSet; this.rs = new CursorResultSet(); this.rsContext = new DefaultBindingGetResultSetContext<Object>(ctx.configuration(), ctx.data(), rs, 0); this.maxRows = maxRows; this.lockRowsForUpdate = TRUE.equals(ctx.data(DATA_LOCK_ROWS_FOR_UPDATE)); if (internIndexes != null) { this.intern = new boolean[fields.length]; for (int i : internIndexes) intern[i] = true; } else this.intern = null; }
private final void registerOutParameters(ExecuteContext ctx) throws SQLException { Configuration c = ctx.configuration(); Map<Object, Object> data = ctx.data(); CallableStatement statement = (CallableStatement) ctx.statement(); // Register all out / inout parameters according to their position // Note that some RDBMS do not support binding by name very well for (Parameter<?> parameter : getParameters()) if (resultParameter(parameter)) registerOutParameter(c, data, statement, parameter); }
/** * Default implementation for query execution using a prepared statement. * Subclasses may override this method. */ protected int execute(ExecuteContext ctx, ExecuteListener listener) throws SQLException { int result = 0; PreparedStatement stmt = ctx.statement(); try { listener.executeStart(ctx); // [#1829] Statement.execute() is preferred over Statement.executeUpdate(), as // we might be executing plain SQL and returning results. if (!stmt.execute()) { result = stmt.getUpdateCount(); ctx.rows(result); } listener.executeEnd(ctx); return result; } // [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any catch (SQLException e) { consumeExceptions(ctx.configuration(), stmt, e); if (ctx.settings().getThrowExceptions() != THROW_NONE) throw e; else return stmt.getUpdateCount(); } }
/** * [#5666] Handle the complexity of each dialect's understanding of * correctly calling {@link Statement#execute()}. */ static final SQLException executeStatementAndGetFirstResultSet(ExecuteContext ctx, int skipUpdateCounts) throws SQLException { PreparedStatement stmt = ctx.statement(); try { if (stmt.execute()) { ctx.resultSet(stmt.getResultSet()); } else { ctx.resultSet(null); ctx.rows(stmt.getUpdateCount()); } return null; } // [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any catch (SQLException e) { if (ctx.settings().getThrowExceptions() != THROW_NONE) { consumeExceptions(ctx.configuration(), ctx.statement(), e); throw e; } else { return e; } } }
/** * Provide delegate listeners from an <code>ExecuteContext</code> */ private static final ExecuteListener[] listeners(ExecuteContext ctx) { List<ExecuteListener> result = null; // jOOQ-internal listeners are added first, so their results are available to user-defined listeners // ------------------------------------------------------------------------------------------------- // [#6580] Fetching server output may require some pre / post actions around the actual statement if (SettingsTools.getFetchServerOutputSize(0, ctx.settings()) > 0) (result = init(result)).add(new FetchServerOutputListener()); // [#6051] The previously used StopWatchListener is no longer included by default if (!FALSE.equals(ctx.settings().isExecuteLogging())) { // [#6747] Avoid allocating the listener (and by consequence, the ExecuteListeners) if // we do not DEBUG log anyway. if (LOGGER_LISTENER_LOGGER.isDebugEnabled()) (result = init(result)).add(new LoggerListener()); } for (ExecuteListenerProvider provider : ctx.configuration().executeListenerProviders()) // Could be null after deserialisation if (provider != null) (result = init(result)).add(provider.provide()); return result == null ? null : result.toArray(EMPTY_EXECUTE_LISTENER); }
@Override public void outEnd(ExecuteContext ctx) { if (ctx.routine() != null) if (log.isDebugEnabled()) logMultiline("Fetched OUT parameters", "" + StringUtils.defaultIfNull(record(ctx.configuration(), ctx.routine()), "N/A"), Level.FINE); }
@Override public final Result<R> fetch(int number) { // [#1157] This invokes listener.fetchStart(ctx), which has to be called // Before listener.resultStart(ctx) iterator(); ResultImpl<R> result = new ResultImpl<R>(ctx.configuration(), fields); R record = null; ctx.result(result); listener.resultStart(ctx); for (int i = 0; i < number && ((record = iterator().next()) != null); i++) { result.addRecord(record); } ctx.result(result); listener.resultEnd(ctx); return result; }
if (ctx.routine() != null) { log.debug( DSL.using(ctx.configuration()) .renderInlined(ctx.routine()) );
switch (ctx.configuration().dialect().family()) {
if (ctx.configuration().dialect() == POSTGRES) { Object object = stmt.getObject(index); return (T) (object == null ? null : PostgresUtils.toYearToMonth(object)); if (ctx.configuration().dialect() == POSTGRES) { Object object = stmt.getObject(index); return (T) (object == null ? null : PostgresUtils.toDayToSecond(object)); switch (ctx.configuration().dialect().family()) { switch (ctx.configuration().dialect()) { case POSTGRES: return (T) pgNewUDTRecord(type, stmt.getObject(index)); return (T) DSL.using(ctx.configuration()).fetch(nested);
else if (isForUpdate() && asList(CUBRID).contains(ctx.configuration().dialect().family())) { ctx.data(DATA_LOCK_ROWS_FOR_UPDATE, true); ctx.statement(ctx.connection().prepareStatement(ctx.sql(), TYPE_SCROLL_SENSITIVE, CONCUR_UPDATABLE));
int result = 1; ResultSet rs; switch (ctx.configuration().dialect().family()) { listener.executeEnd(ctx); DSLContext create = DSL.using(ctx.configuration()); returned = create.select(returning) listener.executeEnd(ctx); selectReturning(ctx.configuration(), create(ctx.configuration()).lastID()); return result; selectReturning(ctx.configuration(), list.toArray()); return result; ExecuteContext ctx2 = new DefaultExecuteContext(ctx.configuration()); ExecuteListener listener2 = new ExecuteListeners(ctx2);
result = new ResultImpl<R>(ctx.configuration()); anyResults = true; Field<?>[] fields = new MetaDataFieldProvider(ctx.configuration(), ctx.resultSet().getMetaData()).getFields(); Cursor<Record> c = new CursorImpl<Record>(ctx, listener, fields, internIndexes(fields), true, false); results.add(c.fetch());
DSLContext dsl = DSL.using(ctx.configuration()); Field<Integer> c = field(name("UPDATE_COUNT"), int.class); Result<Record1<Integer>> r = dsl.newResult(c); results = new ResultsImpl(ctx.configuration()); consumeResultSets(ctx, listener, results, intern, e);
ctx.configuration(), ctx.dsl().lastID() ); ctx.configuration(), list.toArray() );
anyResults = true; Field<?>[] fields = new MetaDataFieldProvider(ctx.configuration(), ctx.resultSet().getMetaData()).getFields(); Cursor<Record> c = new CursorImpl<Record>(ctx, listener, fields, intern != null ? intern.internIndexes(fields) : null, true, false); results.resultsOrRows().add(new ResultOrRowsImpl(c.fetch())); consumeExceptions(ctx.configuration(), ctx.statement(), e); throw e;
@Override public void renderEnd(ExecuteContext ctx) { if (log.isDebugEnabled()) { Configuration configuration = ctx.configuration(); String newline = TRUE.equals(configuration.settings().isRenderFormatted()) ? "\n" : "";
@Override public void renderEnd(ExecuteContext ctx) { if (log.isDebugEnabled()) { Configuration configuration = ctx.configuration();