[jOOQ/jOOQ#14155] Support transforming BatchMultiple
This commit is contained in:
parent
3821ba5b4e
commit
5ca35f80b0
@ -167,6 +167,8 @@ public interface ExecuteContext extends Scope {
|
||||
* <code>Query</code>
|
||||
* <p>
|
||||
* Refer to {@link #batchMode()} to decide how to interpret this content.
|
||||
* <p>
|
||||
* This corresponds to {@link #transformedBatchQueries()}.
|
||||
*
|
||||
* @see #query()
|
||||
* @see #routine()
|
||||
@ -176,6 +178,44 @@ public interface ExecuteContext extends Scope {
|
||||
@NotNull
|
||||
Query @NotNull [] batchQueries();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The jOOQ {@link Routine} that is being executed or <code>null</code> if
|
||||
* the query is unknown or if there was no jOOQ <code>Routine</code>.
|
||||
|
||||
@ -284,7 +284,7 @@ abstract class AbstractQuery<R extends Record> extends AbstractAttachableQueryPa
|
||||
|
||||
// [#385] First time statement preparing
|
||||
else {
|
||||
ctx.transformQuery(listener);
|
||||
ctx.transformQueries(listener);
|
||||
|
||||
listener.renderStart(ctx);
|
||||
rendered = getSQL0(ctx);
|
||||
|
||||
@ -89,8 +89,8 @@ final class BatchMultiple extends AbstractBatch {
|
||||
return execute(configuration, queries);
|
||||
}
|
||||
|
||||
static int[] execute(final Configuration configuration, final Query[] queries) {
|
||||
ExecuteContext ctx = new DefaultExecuteContext(configuration, BatchMode.MULTIPLE, queries);
|
||||
static int[] execute(Configuration configuration, Query[] queries) {
|
||||
DefaultExecuteContext ctx = new DefaultExecuteContext(configuration, BatchMode.MULTIPLE, queries);
|
||||
ExecuteListener listener = ExecuteListeners.get(ctx);
|
||||
Connection connection = ctx.connection();
|
||||
|
||||
@ -98,20 +98,21 @@ final class BatchMultiple extends AbstractBatch {
|
||||
|
||||
// [#8968] Keep start() event inside of lifecycle management
|
||||
listener.start(ctx);
|
||||
ctx.transformQueries(listener);
|
||||
|
||||
if (ctx.statement() == null)
|
||||
ctx.statement(new SettingsEnabledPreparedStatement(connection));
|
||||
|
||||
String[] batchSQL = ctx.batchSQL();
|
||||
for (int i = 0; i < queries.length; i++) {
|
||||
for (int i = 0; i < ctx.batchQueries().length; i++) {
|
||||
ctx.sql(null);
|
||||
listener.renderStart(ctx);
|
||||
batchSQL[i] = DSL.using(configuration).renderInlined(queries[i]);
|
||||
batchSQL[i] = DSL.using(configuration).renderInlined(ctx.batchQueries()[i]);
|
||||
ctx.sql(batchSQL[i]);
|
||||
listener.renderEnd(ctx);
|
||||
}
|
||||
|
||||
for (int i = 0; i < queries.length; i++) {
|
||||
for (int i = 0; i < ctx.batchQueries().length; i++) {
|
||||
ctx.sql(batchSQL[i]);
|
||||
listener.prepareStart(ctx);
|
||||
ctx.statement().addBatch(batchSQL[i]);
|
||||
|
||||
@ -196,7 +196,7 @@ final class BatchSingle extends AbstractBatch implements BatchBindStep {
|
||||
try {
|
||||
// [#8968] Keep start() event inside of lifecycle management
|
||||
listener.start(ctx);
|
||||
ctx.transformQuery(listener);
|
||||
ctx.transformQueries(listener);
|
||||
|
||||
listener.renderStart(ctx);
|
||||
// [#1520] TODO: Should the number of bind values be checked, here?
|
||||
|
||||
@ -107,14 +107,16 @@ class DefaultExecuteContext implements ExecuteContext {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Query query;
|
||||
private final Routine<?> routine;
|
||||
private String sql;
|
||||
|
||||
private final BatchMode batchMode;
|
||||
private final Query[] batchQueries;
|
||||
private final String[] batchSQL;
|
||||
private final int[] batchRows;
|
||||
private Query[] batchQueries;
|
||||
private String[] batchSQL;
|
||||
private int[] batchRows;
|
||||
|
||||
ConnectionProvider connectionProvider;
|
||||
private Connection connection;
|
||||
@ -347,32 +349,11 @@ class DefaultExecuteContext implements ExecuteContext {
|
||||
|
||||
|
||||
|
||||
|
||||
this.routine = routine;
|
||||
this.converterContext = new DefaultConverterContext(derivedConfiguration, data);
|
||||
|
||||
if (routine != null) {
|
||||
this.batchQueries = null;
|
||||
this.batchRows = null;
|
||||
this.batchSQL = null;
|
||||
}
|
||||
else if (batchQueries != null) {
|
||||
this.batchQueries = batchQueries;
|
||||
this.batchRows = new int[batchQueries.length];
|
||||
this.batchSQL = new String[batchQueries.length];
|
||||
|
||||
Arrays.fill(this.batchRows, -1);
|
||||
}
|
||||
else if (query == null) {
|
||||
this.batchQueries = null;
|
||||
this.batchRows = null;
|
||||
this.batchSQL = null;
|
||||
}
|
||||
else {
|
||||
this.batchQueries = null;
|
||||
this.batchRows = null;
|
||||
this.batchSQL = null;
|
||||
}
|
||||
|
||||
batchQueries(batchQueries);
|
||||
clean();
|
||||
}
|
||||
|
||||
@ -504,6 +485,36 @@ class DefaultExecuteContext implements ExecuteContext {
|
||||
: EMPTY_QUERY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public final Routine<?> routine() {
|
||||
return routine;
|
||||
@ -763,7 +774,7 @@ class DefaultExecuteContext implements ExecuteContext {
|
||||
}
|
||||
|
||||
|
||||
final void transformQuery(ExecuteListener listener) {
|
||||
final void transformQueries(ExecuteListener listener) {
|
||||
|
||||
|
||||
|
||||
|
||||
@ -116,6 +116,25 @@ final class SimpleExecuteContext extends AbstractScope implements ExecuteContext
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public final Routine<?> routine() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user