Skip to content

Commit

Permalink
[#7569] Regression in UpdatableRecord.store() and update() methods wh…
Browse files Browse the repository at this point in the history
…en used with connection pools
  • Loading branch information
lukaseder committed Jun 26, 2018
1 parent dc59407 commit b2a9d1f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
38 changes: 29 additions & 9 deletions jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java
Expand Up @@ -37,6 +37,7 @@
*/
package org.jooq.impl;

// ...
// ...
// ...
import static org.jooq.SQLDialect.HSQLDB;
Expand Down Expand Up @@ -629,13 +630,14 @@ protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws
ctx.rows(result);
listener.executeEnd(ctx);

DSLContext create = DSL.using(ctx.configuration());
DSLContext create = ctx.dsl();
returnedResult =
create.select(returning)
.from(table)
.where(rowid().equal(rowid().getDataType().convert(create.lastID())))
.fetch();

returnedResult.attach(((DefaultExecuteContext) ctx).originalConfiguration());
return result;
}

Expand All @@ -655,7 +657,12 @@ protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws
ctx.rows(result);
listener.executeEnd(ctx);

selectReturning(ctx.configuration(), ctx.dsl().lastID());
selectReturning(
((DefaultExecuteContext) ctx).originalConfiguration(),
ctx.configuration(),
ctx.dsl().lastID()
);

return result;
}

Expand Down Expand Up @@ -691,7 +698,12 @@ protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws
while (rs.next())
list.add(rs.getObject(1));

selectReturning(ctx.configuration(), list.toArray());
selectReturning(
((DefaultExecuteContext) ctx).originalConfiguration(),
ctx.configuration(),
list.toArray()
);

return result;
}
finally {
Expand Down Expand Up @@ -793,6 +805,7 @@ protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws






case HSQLDB:
Expand Down Expand Up @@ -830,7 +843,11 @@ protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws
* arbitrary fields from JDBC's {@link Statement#getGeneratedKeys()} method.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private final void selectReturning(Configuration configuration, Object... values) {
private final void selectReturning(
Configuration originalConfiguration,
Configuration derivedConfiguration,
Object... values
) {
if (values != null && values.length > 0) {

// This shouldn't be null, as relevant dialects should
Expand All @@ -846,7 +863,7 @@ private final void selectReturning(Configuration configuration, Object... values
if (returningResolvedAsterisks.size() == 1 && new Fields<Record>(returningResolvedAsterisks).field(field) != null) {
for (final Object id : ids) {
((Result) getResult()).add(
Tools.newRecord(true, table, configuration)
Tools.newRecord(true, table, originalConfiguration)
.operate(new RecordOperation<R, RuntimeException>() {

@Override
Expand All @@ -865,10 +882,13 @@ public R operate(R record) throws RuntimeException {
// Other values are requested, too. Run another query
else {
returnedResult =
configuration.dsl().select(returning)
.from(table)
.where(field.in(ids))
.fetch();
derivedConfiguration.dsl()
.select(returning)
.from(table)
.where(field.in(ids))
.fetch();

returnedResult.attach(originalConfiguration);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions jOOQ/src/main/java/org/jooq/impl/CursorImpl.java
Expand Up @@ -399,7 +399,7 @@ public final Result<R> fetchNext(int number) {
// Before listener.resultStart(ctx)
iterator();

ResultImpl<R> result = new ResultImpl<R>(ctx.configuration(), cursorFields);
ResultImpl<R> result = new ResultImpl<R>(((DefaultExecuteContext) ctx).originalConfiguration(), cursorFields);

ctx.result(result);
listener.resultStart(ctx);
Expand Down Expand Up @@ -1614,7 +1614,7 @@ private final R fetchNext() {
rs.updateRow();
}

record = Tools.newRecord(true, (RecordFactory<AbstractRecord>) factory, ctx.configuration())
record = Tools.newRecord(true, (RecordFactory<AbstractRecord>) factory, ((DefaultExecuteContext) ctx).originalConfiguration())
.operate(new CursorRecordInitialiser(cursorFields, 0));

rows++;
Expand Down Expand Up @@ -1710,7 +1710,7 @@ private final <T> void setValue(AbstractRecord record, Field<T> field, int index
if (field instanceof RowField) {
Field<?>[] emulatedFields = ((RowField<?, ?>) field).emulatedFields();

value = (T) Tools.newRecord(true, RecordImpl.class, emulatedFields, ctx.configuration())
value = (T) Tools.newRecord(true, RecordImpl.class, emulatedFields, ((DefaultExecuteContext) ctx).originalConfiguration())
.operate(new CursorRecordInitialiser(emulatedFields, offset + index));

offset += emulatedFields.length - 1;
Expand Down
17 changes: 13 additions & 4 deletions jOOQ/src/main/java/org/jooq/impl/DefaultExecuteContext.java
Expand Up @@ -89,7 +89,8 @@ class DefaultExecuteContext implements ExecuteContext {
private static final JooqLogger log = JooqLogger.getLogger(DefaultExecuteContext.class);

// Persistent attributes (repeatable)
private final Configuration configuration;
private final Configuration originalConfiguration;
private final Configuration derivedConfiguration;
private final Map<Object, Object> data;
private final Query query;
private final Routine<?> routine;
Expand Down Expand Up @@ -468,8 +469,10 @@ private DefaultExecuteContext(Configuration configuration, Query query, Query[]

// [#4277] The ExecuteContext's Configuration will always return the same Connection,
// e.g. when running statements from sub-ExecuteContexts
// [#7569] The original configuration is attached to Record and Result instances
this.connectionProvider = configuration.connectionProvider();
this.configuration = configuration.derive(new ExecuteContextConnectionProvider());
this.originalConfiguration = configuration;
this.derivedConfiguration = configuration.derive(new ExecuteContextConnectionProvider());
this.data = new DataMap();
this.query = query;
this.routine = routine;
Expand Down Expand Up @@ -656,7 +659,13 @@ public final ResultSet resultSet() {

@Override
public final Configuration configuration() {
return configuration;
return derivedConfiguration;
}

// [#4277] [#7569] The original configuration that was used to create the
// derived configuration in this ExecuteContext
final Configuration originalConfiguration() {
return originalConfiguration;
}

@Override
Expand Down Expand Up @@ -712,7 +721,7 @@ final void connection(ConnectionProvider provider, Connection c) {
}

private final SettingsEnabledConnection wrapConnection(ConnectionProvider provider, Connection c) {
return new SettingsEnabledConnection(new ProviderEnabledConnection(provider, c), configuration.settings());
return new SettingsEnabledConnection(new ProviderEnabledConnection(provider, c), derivedConfiguration.settings());
}

final void incrementStatementExecutionCount() {
Expand Down

0 comments on commit b2a9d1f

Please sign in to comment.