[jOOQ/jOOQ#11530] Add Configuration.setAppending() and Configuration.deriveAppending() methods to create derived configurations by appending listeners

This commit is contained in:
Lukas Eder 2021-02-25 17:14:41 +01:00
parent b73dd6e65c
commit 7cfaeea9c3
10 changed files with 730 additions and 202 deletions

View File

@ -78,6 +78,7 @@ import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.DSLContext;
import org.jooq.ExecuteContext;
import org.jooq.ExecuteListener;
import org.jooq.ExecuteListenerProvider;
import org.jooq.Field;
import org.jooq.Log;
@ -345,10 +346,7 @@ public abstract class AbstractDatabase implements Database {
}
else {
final Settings newSettings = SettingsTools.clone(configuration.settings()).withRenderFormatted(true);
final ExecuteListenerProvider[] oldProviders = configuration.executeListenerProviders();
final ExecuteListenerProvider[] newProviders = new ExecuteListenerProvider[oldProviders.length + 1];
System.arraycopy(oldProviders, 0, newProviders, 0, oldProviders.length);
newProviders[oldProviders.length] = new DefaultExecuteListenerProvider(new DefaultExecuteListener() {
final ExecuteListener newListener = new DefaultExecuteListener() {
class SQLPerformanceWarning extends Exception {}
@ -449,8 +447,8 @@ public abstract class AbstractDatabase implements Database {
private String formatted(Query query) {
return DSL.using(configuration.derive(newSettings)).renderInlined(query);
}
});
return DSL.using(configuration.derive(newProviders));
};
return DSL.using(configuration.deriveAppending(newListener));
}
}

View File

@ -743,7 +743,7 @@ public interface Configuration extends Serializable {
Configuration set(RecordUnmapperProvider newRecordUnmapperProvider);
/**
* Change this configuration to hold a new record listeners.
* Change this configuration to hold new record listeners.
* <p>
* This will wrap the argument {@link RecordListener} in a
* {@link DefaultRecordListenerProvider} for convenience.
@ -759,7 +759,23 @@ public interface Configuration extends Serializable {
Configuration set(RecordListener... newRecordListeners);
/**
* Change this configuration to hold a new record listener providers.
* Change this configuration by appending new record listeners.
* <p>
* This will wrap the argument {@link RecordListener} in a
* {@link DefaultRecordListenerProvider} for convenience.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newRecordListeners The appended record listener to be contained in
* the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(RecordListener... newRecordListeners);
/**
* Change this configuration to hold new record listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
@ -772,7 +788,20 @@ public interface Configuration extends Serializable {
Configuration set(RecordListenerProvider... newRecordListenerProviders);
/**
* Change this configuration to hold a new execute listeners.
* Change this configuration by appending new record listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newRecordListenerProviders The appended record listener providers
* to be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(RecordListenerProvider... newRecordListenerProviders);
/**
* Change this configuration to hold new execute listeners.
* <p>
* This will wrap the argument {@link ExecuteListener} in a
* {@link DefaultExecuteListenerProvider} for convenience.
@ -788,7 +817,23 @@ public interface Configuration extends Serializable {
Configuration set(ExecuteListener... newExecuteListeners);
/**
* Change this configuration to hold a new execute listener providers.
* Change this configuration by appending new execute listeners.
* <p>
* This will wrap the argument {@link ExecuteListener} in a
* {@link DefaultExecuteListenerProvider} for convenience.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newExecuteListeners The appended execute listeners to be contained
* in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(ExecuteListener... newExecuteListeners);
/**
* Change this configuration to hold new execute listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
@ -801,7 +846,20 @@ public interface Configuration extends Serializable {
Configuration set(ExecuteListenerProvider... newExecuteListenerProviders);
/**
* Change this configuration to hold a new migration listeners.
* Change this configuration by appending new execute listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newExecuteListenerProviders The appended execute listener
* providers to be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(ExecuteListenerProvider... newExecuteListenerProviders);
/**
* Change this configuration to hold new migration listeners.
* <p>
* This will wrap the argument {@link MigrationListener} in a
* {@link DefaultMigrationListenerProvider} for convenience.
@ -817,18 +875,48 @@ public interface Configuration extends Serializable {
Configuration set(MigrationListener... newMigrationListeners);
/**
* Change this configuration to hold a new migration listener providers.
* Change this configuration by appending new migration listeners.
* <p>
* This will wrap the argument {@link MigrationListener} in a
* {@link DefaultMigrationListenerProvider} for convenience.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newMigrationListenerProviders The new migration listener providers to
* be contained in the changed configuration.
* @param newMigrationListeners The appended migration listeners to be
* contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(MigrationListener... newMigrationListeners);
/**
* Change this configuration to hold new migration listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newMigrationListenerProviders The new migration listener providers
* to be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration set(MigrationListenerProvider... newMigrationListenerProviders);
/**
* Change this configuration to hold by appending new migration listener
* providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newMigrationListenerProviders The appended migration listener
* providers to be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(MigrationListenerProvider... newMigrationListenerProviders);
/**
* Change this configuration to hold a new visit listeners.
* <p>
@ -846,20 +934,49 @@ public interface Configuration extends Serializable {
Configuration set(VisitListener... newVisitListeners);
/**
* Change this configuration to hold a new visit listener providers.
* Change this configuration to hold new visit listeners.
* <p>
* This will wrap the argument {@link VisitListener} in a
* {@link DefaultVisitListenerProvider} for convenience.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newVisitListenerProviders The new visit listener providers to
* be contained in the changed configuration.
* @param newVisitListeners The new visit listeners to be contained in the
* changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(VisitListener... newVisitListeners);
/**
* Change this configuration to hold new visit listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newVisitListenerProviders The new visit listener providers to be
* contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration set(VisitListenerProvider... newVisitListenerProviders);
/**
* Change this configuration to hold a new transaction listeners.
* Change this configuration by appending new visit listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newVisitListenerProviders The appended visit listener providers to
* be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(VisitListenerProvider... newVisitListenerProviders);
/**
* Change this configuration to hold new transaction listeners.
* <p>
* This will wrap the argument {@link TransactionListener} in a
* {@link DefaultTransactionListenerProvider} for convenience.
@ -875,7 +992,23 @@ public interface Configuration extends Serializable {
Configuration set(TransactionListener... newTransactionListeners);
/**
* Change this configuration to hold a new transaction listener providers.
* Change this configuration by appending new transaction listeners.
* <p>
* This will wrap the argument {@link TransactionListener} in a
* {@link DefaultTransactionListenerProvider} for convenience.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newTransactionListeners The appended transaction listeners to be
* contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(TransactionListener... newTransactionListeners);
/**
* Change this configuration to hold new transaction listener providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
@ -888,7 +1021,21 @@ public interface Configuration extends Serializable {
Configuration set(TransactionListenerProvider... newTransactionListenerProviders);
/**
* Change this configuration to hold a new diagnostics listeners.
* Change this configuration by appending new transaction listener
* providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newTransactionListenerProviders The appended transaction listener
* providers to be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(TransactionListenerProvider... newTransactionListenerProviders);
/**
* Change this configuration to hold new diagnostics listeners.
* <p>
* This will wrap the argument {@link DiagnosticsListener} in a
* {@link DefaultDiagnosticsListenerProvider} for convenience.
@ -903,6 +1050,22 @@ public interface Configuration extends Serializable {
@NotNull
Configuration set(DiagnosticsListener... newDiagnosticsListeners);
/**
* Change this configuration by appending new diagnostics listeners.
* <p>
* This will wrap the argument {@link DiagnosticsListener} in a
* {@link DefaultDiagnosticsListenerProvider} for convenience.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newDiagnosticsListeners The new diagnostics listeners to be
* contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(DiagnosticsListener... newDiagnosticsListeners);
/**
* Change this configuration to hold new diagnostics listener providers.
* <p>
@ -916,6 +1079,20 @@ public interface Configuration extends Serializable {
@NotNull
Configuration set(DiagnosticsListenerProvider... newDiagnosticsListenerProviders);
/**
* Change this configuration by appending new diagnostics listener
* providers.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newDiagnosticsListenerProviders The new diagnostics listener
* providers to be contained in the changed configuration.
* @return The changed configuration.
*/
@NotNull
Configuration setAppending(DiagnosticsListenerProvider... newDiagnosticsListenerProviders);
/**
* Change this configuration to hold a new unwrapper.
* <p>
@ -982,6 +1159,37 @@ public interface Configuration extends Serializable {
@ -1201,17 +1409,42 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(RecordListener... newRecordListeners);
/**
* Create a derived configuration from this one, with appended record
* listeners.
* <p>
* This will wrap the argument {@link RecordListener} in a
* {@link DefaultRecordListenerProvider} for convenience.
*
* @param newRecordListeners The appended record listeners to be contained
* in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(RecordListener... newRecordListeners);
/**
* Create a derived configuration from this one, with new record listener
* providers.
*
* @param newRecordListenerProviders The new record listener providers to
* be contained in the derived configuration.
* @param newRecordListenerProviders The new record listener providers to be
* contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration derive(RecordListenerProvider... newRecordListenerProviders);
/**
* Create a derived configuration from this one, with appended record
* listener providers.
*
* @param newRecordListenerProviders The appended record listener providers
* to be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(RecordListenerProvider... newRecordListenerProviders);
/**
* Create a derived configuration from this one, with new execute listeners.
* <p>
@ -1225,6 +1458,20 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(ExecuteListener... newExecuteListeners);
/**
* Create a derived configuration from this one, with appended execute
* listeners.
* <p>
* This will wrap the argument {@link ExecuteListener} in a
* {@link DefaultExecuteListenerProvider} for convenience.
*
* @param newExecuteListeners The appended execute listener to be contained
* in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(ExecuteListener... newExecuteListeners);
/**
* Create a derived configuration from this one, with new execute listener
* providers.
@ -1237,29 +1484,66 @@ public interface Configuration extends Serializable {
Configuration derive(ExecuteListenerProvider... newExecuteListenerProviders);
/**
* Create a derived configuration from this one, with new migration listeners.
* Create a derived configuration from this one, with appended execute
* listener providers.
*
* @param newExecuteListenerProviders The appended execute listener
* providers to be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(ExecuteListenerProvider... newExecuteListenerProviders);
/**
* Create a derived configuration from this one, with new migration
* listeners.
* <p>
* This will wrap the argument {@link MigrationListener} in a
* {@link DefaultMigrationListenerProvider} for convenience.
*
* @param newMigrationListeners The new migration listener to be contained in
* the derived configuration.
* @param newMigrationListeners The new migration listener to be contained
* in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration derive(MigrationListener... newMigrationListeners);
/**
* Create a derived configuration from this one, with appended migration
* listeners.
* <p>
* This will wrap the argument {@link MigrationListener} in a
* {@link DefaultMigrationListenerProvider} for convenience.
*
* @param newMigrationListeners The appended migration listener to be
* contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(MigrationListener... newMigrationListeners);
/**
* Create a derived configuration from this one, with new migration listener
* providers.
*
* @param newMigrationListenerProviders The new migration listener providers to
* be contained in the derived configuration.
* @param newMigrationListenerProviders The new migration listener providers
* to be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration derive(MigrationListenerProvider... newMigrationListenerProviders);
/**
* Create a derived configuration from this one, with appended migration
* listener providers.
*
* @param newMigrationListenerProviders The appended migration listener
* providers to be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(MigrationListenerProvider... newMigrationListenerProviders);
/**
* Create a derived configuration from this one, with new visit listeners.
* <p>
@ -1273,6 +1557,20 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(VisitListener... newVisitListeners);
/**
* Create a derived configuration from this one, with appended visit
* listeners.
* <p>
* This will wrap the argument {@link VisitListener} in a
* {@link DefaultVisitListenerProvider} for convenience.
*
* @param newVisitListeners The appended visit listeners to be contained in
* the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(VisitListener... newVisitListeners);
/**
* Create a derived configuration from this one, with new visit listener
* providers.
@ -1284,6 +1582,17 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(VisitListenerProvider... newVisitListenerProviders);
/**
* Create a derived configuration from this one, with appended visit
* listener providers.
*
* @param newVisitListenerProviders The appended visit listener providers to
* be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(VisitListenerProvider... newVisitListenerProviders);
/**
* Create a derived configuration from this one, with new transaction
* listeners.
@ -1298,6 +1607,20 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(TransactionListener... newTransactionListeners);
/**
* Create a derived configuration from this one, with appended transaction
* listeners.
* <p>
* This will wrap the argument {@link TransactionListener} in a
* {@link DefaultTransactionListenerProvider} for convenience.
*
* @param newTransactionListeners The appended transaction listeners to be
* contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(TransactionListener... newTransactionListeners);
/**
* Create a derived configuration from this one, with new transaction
* listener providers.
@ -1309,6 +1632,17 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(TransactionListenerProvider... newTransactionListenerProviders);
/**
* Create a derived configuration from this one, with appended transaction
* listener providers.
*
* @param newTransactionListenerProviders The appended transaction listener
* providers to be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(TransactionListenerProvider... newTransactionListenerProviders);
/**
* Create a derived configuration from this one, with new diagnostics
* listeners.
@ -1320,6 +1654,17 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(DiagnosticsListener... newDiagnosticsListeners);
/**
* Create a derived configuration from this one, with appended diagnostics
* listeners.
*
* @param newDiagnosticsListeners The appended diagnostics listeners to be
* contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(DiagnosticsListener... newDiagnosticsListeners);
/**
* Create a derived configuration from this one, with new diagnostics
* listener providers.
@ -1331,6 +1676,17 @@ public interface Configuration extends Serializable {
@NotNull
Configuration derive(DiagnosticsListenerProvider... newDiagnosticsListenerProviders);
/**
* Create a derived configuration from this one, with appended diagnostics
* listener providers.
*
* @param newDiagnosticsListenerProviders The appended diagnostics listener
* providers to be contained in the derived configuration.
* @return The derived configuration.
*/
@NotNull
Configuration deriveAppending(DiagnosticsListenerProvider... newDiagnosticsListenerProviders);
/**
* Create a derived configuration from this one, with a new unwrapper.
*
@ -1393,6 +1749,30 @@ public interface Configuration extends Serializable {

View File

@ -0,0 +1,296 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import static org.jooq.impl.Tools.combine;
import org.jooq.Configuration;
import org.jooq.DiagnosticsListener;
import org.jooq.DiagnosticsListenerProvider;
import org.jooq.ExecuteListener;
import org.jooq.ExecuteListenerProvider;
import org.jooq.MigrationListener;
import org.jooq.MigrationListenerProvider;
// ...
// ...
// ...
import org.jooq.RecordListener;
import org.jooq.RecordListenerProvider;
import org.jooq.TransactionListener;
import org.jooq.TransactionListenerProvider;
import org.jooq.VisitListener;
import org.jooq.VisitListenerProvider;
/**
* A base implementation for {@link Configuration} classes, implementing the
* usual convenience API.
*
* @author Lukas Eder
*/
public abstract class AbstractConfiguration implements Configuration {
/**
* Generated UID
*/
private static final long serialVersionUID = 4192586780235493065L;
@Override
public final Configuration set(RecordListener... newRecordListeners) {
return set(DefaultRecordListenerProvider.providers(newRecordListeners));
}
@Override
public final Configuration setAppending(RecordListener... newRecordListeners) {
return setAppending(DefaultRecordListenerProvider.providers(newRecordListeners));
}
@Override
public final Configuration setAppending(RecordListenerProvider... newRecordListenerProviders) {
return set(combine(recordListenerProviders(), newRecordListenerProviders));
}
@Override
public final Configuration set(ExecuteListener... newExecuteListeners) {
return set(DefaultExecuteListenerProvider.providers(newExecuteListeners));
}
@Override
public final Configuration setAppending(ExecuteListener... newExecuteListeners) {
return setAppending(DefaultExecuteListenerProvider.providers(newExecuteListeners));
}
@Override
public final Configuration setAppending(ExecuteListenerProvider... newExecuteListenerProviders) {
return set(combine(executeListenerProviders(), newExecuteListenerProviders));
}
@Override
public final Configuration set(MigrationListener... newMigrationListeners) {
return set(DefaultMigrationListenerProvider.providers(newMigrationListeners));
}
@Override
public final Configuration setAppending(MigrationListener... newMigrationListeners) {
return setAppending(DefaultMigrationListenerProvider.providers(newMigrationListeners));
}
@Override
public final Configuration setAppending(MigrationListenerProvider... newMigrationListenerProviders) {
return set(combine(migrationListenerProviders(), newMigrationListenerProviders));
}
@Override
public final Configuration set(VisitListener... newVisitListeners) {
return set(DefaultVisitListenerProvider.providers(newVisitListeners));
}
@Override
public final Configuration setAppending(VisitListener... newVisitListeners) {
return setAppending(DefaultVisitListenerProvider.providers(newVisitListeners));
}
@Override
public final Configuration setAppending(VisitListenerProvider... newVisitListenerProviders) {
return set(combine(visitListenerProviders(), newVisitListenerProviders));
}
@Override
public final Configuration set(TransactionListener... newTransactionListeners) {
return set(DefaultTransactionListenerProvider.providers(newTransactionListeners));
}
@Override
public final Configuration setAppending(TransactionListener... newTransactionListeners) {
return setAppending(DefaultTransactionListenerProvider.providers(newTransactionListeners));
}
@Override
public final Configuration setAppending(TransactionListenerProvider... newTransactionListenerProviders) {
return set(combine(transactionListenerProviders(), newTransactionListenerProviders));
}
@Override
public final Configuration set(DiagnosticsListener... newDiagnosticsListeners) {
return set(DefaultDiagnosticsListenerProvider.providers(newDiagnosticsListeners));
}
@Override
public final Configuration setAppending(DiagnosticsListener... newDiagnosticsListeners) {
return setAppending(DefaultDiagnosticsListenerProvider.providers(newDiagnosticsListeners));
}
@Override
public final Configuration setAppending(DiagnosticsListenerProvider... newDiagnosticsListenerProviders) {
return set(combine(diagnosticsListenerProviders(), newDiagnosticsListenerProviders));
}
@Override
public final Configuration derive(RecordListener... newRecordListeners) {
return derive(DefaultRecordListenerProvider.providers(newRecordListeners));
}
@Override
public final Configuration deriveAppending(RecordListener... newRecordListeners) {
return deriveAppending(DefaultRecordListenerProvider.providers(newRecordListeners));
}
@Override
public final Configuration deriveAppending(RecordListenerProvider... newRecordListenerProviders) {
return derive(combine(recordListenerProviders(), newRecordListenerProviders));
}
@Override
public final Configuration derive(ExecuteListener... newExecuteListeners) {
return derive(DefaultExecuteListenerProvider.providers(newExecuteListeners));
}
@Override
public final Configuration deriveAppending(ExecuteListener... newExecuteListeners) {
return deriveAppending(DefaultExecuteListenerProvider.providers(newExecuteListeners));
}
@Override
public final Configuration deriveAppending(ExecuteListenerProvider... newExecuteListenerProviders) {
return derive(combine(executeListenerProviders(), newExecuteListenerProviders));
}
@Override
public final Configuration derive(MigrationListener... newMigrationListeners) {
return derive(DefaultMigrationListenerProvider.providers(newMigrationListeners));
}
@Override
public final Configuration deriveAppending(MigrationListener... newMigrationListeners) {
return deriveAppending(DefaultMigrationListenerProvider.providers(newMigrationListeners));
}
@Override
public final Configuration deriveAppending(MigrationListenerProvider... newMigrationListenerProviders) {
return derive(combine(migrationListenerProviders(), newMigrationListenerProviders));
}
@Override
public final Configuration derive(VisitListener... newVisitListeners) {
return derive(DefaultVisitListenerProvider.providers(newVisitListeners));
}
@Override
public final Configuration deriveAppending(VisitListener... newVisitListeners) {
return deriveAppending(DefaultVisitListenerProvider.providers(newVisitListeners));
}
@Override
public final Configuration deriveAppending(VisitListenerProvider... newVisitListenerProviders) {
return derive(combine(visitListenerProviders(), newVisitListenerProviders));
}
@Override
public final Configuration derive(TransactionListener... newTransactionListeners) {
return derive(DefaultTransactionListenerProvider.providers(newTransactionListeners));
}
@Override
public final Configuration deriveAppending(TransactionListener... newTransactionListeners) {
return deriveAppending(DefaultTransactionListenerProvider.providers(newTransactionListeners));
}
@Override
public final Configuration deriveAppending(TransactionListenerProvider... newTransactionListenerProviders) {
return derive(combine(transactionListenerProviders(), newTransactionListenerProviders));
}
@Override
public final Configuration derive(DiagnosticsListener... newDiagnosticsListeners) {
return derive(DefaultDiagnosticsListenerProvider.providers(newDiagnosticsListeners));
}
@Override
public final Configuration deriveAppending(DiagnosticsListener... newDiagnosticsListeners) {
return deriveAppending(DefaultDiagnosticsListenerProvider.providers(newDiagnosticsListeners));
}
@Override
public final Configuration deriveAppending(DiagnosticsListenerProvider... newDiagnosticsListenerProviders) {
return derive(combine(diagnosticsListenerProviders(), newDiagnosticsListenerProviders));
}
}

View File

@ -96,10 +96,7 @@ final class BatchCRUD extends AbstractBatch {
QueryCollector collector = new QueryCollector();
// Add the QueryCollector to intercept query execution after rendering
Configuration local = configuration.derive(Tools.combine(
configuration.executeListenerProviders(),
new DefaultExecuteListenerProvider(collector)
));
Configuration local = configuration.deriveAppending(collector);
// [#1537] Communicate with UpdatableRecordImpl
local.data(DATA_OMIT_RETURNING_CLAUSE, true);
@ -153,11 +150,7 @@ final class BatchCRUD extends AbstractBatch {
private final int[] executeStatic() {
List<Query> queries = new ArrayList<>();
QueryCollector collector = new QueryCollector();
Configuration local = configuration.derive(Tools.combine(
configuration.executeListenerProviders(),
new DefaultExecuteListenerProvider(collector)
));
Configuration local = configuration.derive(collector);
for (int i = 0; i < records.length; i++) {
Configuration previous = records[i].configuration();

View File

@ -448,13 +448,25 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
// [#7731] Create a Record -> POJO mapping to allow for reusing the below
// derived Configuration for improved reflection caching.
IdentityHashMap<R, Object> mapping = null;
IdentityHashMap<R, Object> mapping = !FALSE.equals(settings().isReturnRecordToPojo()) ? new IdentityHashMap<>() : null;
// [#2536] Upon store(), insert(), update(), delete(), returned values in the record
// are copied back to the relevant POJO using the RecordListener SPI
if (!FALSE.equals(settings().isReturnRecordToPojo())) {
mapping = new IdentityHashMap<>();
ctx = configuration().derive(providers(configuration().recordListenerProviders(), mapping)).dsl();
if (mapping != null) {
Consumer<? super RecordContext> end = c -> {
Record record = c.record();
// TODO: [#2536] Use mapper()
if (record != null)
record.into(mapping.get(record));
};
ctx = configuration().deriveAppending(
onStoreEnd(end)
.onInsertEnd(end)
.onUpdateEnd(end)
.onDeleteEnd(end)
).dsl();
}
else
ctx = ctx();

View File

@ -65,7 +65,6 @@ import org.jooq.ExecuteListener;
import org.jooq.ExecuteListenerProvider;
import org.jooq.ExecutorProvider;
import org.jooq.MetaProvider;
import org.jooq.MigrationListener;
import org.jooq.MigrationListenerProvider;
// ...
// ...
@ -101,7 +100,7 @@ import org.jooq.migrations.xml.jaxb.MigrationsType;
*
* @author Lukas Eder
*/
public class DefaultConfiguration implements Configuration {
public class DefaultConfiguration extends AbstractConfiguration {
/**
* Serial version UID
@ -563,11 +562,6 @@ public class DefaultConfiguration implements Configuration {
);
}
@Override
public final Configuration derive(RecordListener... newRecordListeners) {
return derive(DefaultRecordListenerProvider.providers(newRecordListeners));
}
@Override
public final Configuration derive(RecordListenerProvider... newRecordListenerProviders) {
return new DefaultConfiguration(
@ -599,11 +593,6 @@ public class DefaultConfiguration implements Configuration {
);
}
@Override
public final Configuration derive(ExecuteListener... newExecuteListeners) {
return derive(DefaultExecuteListenerProvider.providers(newExecuteListeners));
}
@Override
public final Configuration derive(ExecuteListenerProvider... newExecuteListenerProviders) {
return new DefaultConfiguration(
@ -635,11 +624,6 @@ public class DefaultConfiguration implements Configuration {
);
}
@Override
public final Configuration derive(MigrationListener... newMigrationListeners) {
return derive(DefaultMigrationListenerProvider.providers(newMigrationListeners));
}
@Override
public final Configuration derive(MigrationListenerProvider... newMigrationListenerProviders) {
return new DefaultConfiguration(
@ -671,11 +655,6 @@ public class DefaultConfiguration implements Configuration {
);
}
@Override
public final Configuration derive(VisitListener... newVisitListeners) {
return derive(DefaultVisitListenerProvider.providers(newVisitListeners));
}
@Override
public final Configuration derive(VisitListenerProvider... newVisitListenerProviders) {
return new DefaultConfiguration(
@ -707,11 +686,6 @@ public class DefaultConfiguration implements Configuration {
);
}
@Override
public final Configuration derive(TransactionListener... newTransactionListeners) {
return derive(DefaultTransactionListenerProvider.providers(newTransactionListeners));
}
@Override
public final Configuration derive(TransactionListenerProvider... newTransactionListenerProviders) {
return new DefaultConfiguration(
@ -743,11 +717,6 @@ public class DefaultConfiguration implements Configuration {
);
}
@Override
public final Configuration derive(DiagnosticsListener... newDiagnosticsListeners) {
return derive(DefaultDiagnosticsListenerProvider.providers(newDiagnosticsListeners));
}
@Override
public final Configuration derive(DiagnosticsListenerProvider... newDiagnosticsListenerProviders) {
return new DefaultConfiguration(
@ -904,12 +873,6 @@ public class DefaultConfiguration implements Configuration {
@ -1102,11 +1065,6 @@ public class DefaultConfiguration implements Configuration {
return this;
}
@Override
public final Configuration set(RecordListener... newRecordListeners) {
return set(DefaultRecordListenerProvider.providers(newRecordListeners));
}
@Override
public final Configuration set(RecordListenerProvider... newRecordListenerProviders) {
this.recordListenerProviders = newRecordListenerProviders != null
@ -1116,11 +1074,6 @@ public class DefaultConfiguration implements Configuration {
return this;
}
@Override
public final Configuration set(ExecuteListener... newExecuteListeners) {
return set(DefaultExecuteListenerProvider.providers(newExecuteListeners));
}
@Override
public final Configuration set(ExecuteListenerProvider... newExecuteListenerProviders) {
this.executeListenerProviders = newExecuteListenerProviders != null
@ -1130,11 +1083,6 @@ public class DefaultConfiguration implements Configuration {
return this;
}
@Override
public final Configuration set(MigrationListener... newMigrationListeners) {
return set(DefaultMigrationListenerProvider.providers(newMigrationListeners));
}
@Override
public final Configuration set(MigrationListenerProvider... newMigrationListenerProviders) {
this.migrationListenerProviders = newMigrationListenerProviders != null
@ -1144,11 +1092,6 @@ public class DefaultConfiguration implements Configuration {
return this;
}
@Override
public final Configuration set(VisitListener... newVisitListeners) {
return set(DefaultVisitListenerProvider.providers(newVisitListeners));
}
@Override
public final Configuration set(VisitListenerProvider... newVisitListenerProviders) {
this.visitListenerProviders = newVisitListenerProviders != null
@ -1158,11 +1101,6 @@ public class DefaultConfiguration implements Configuration {
return this;
}
@Override
public final Configuration set(TransactionListener... newTransactionListeners) {
return set(DefaultTransactionListenerProvider.providers(newTransactionListeners));
}
@Override
public final Configuration set(TransactionListenerProvider... newTransactionListenerProviders) {
this.transactionListenerProviders = newTransactionListenerProviders != null
@ -1172,11 +1110,6 @@ public class DefaultConfiguration implements Configuration {
return this;
}
@Override
public final Configuration set(DiagnosticsListener... newDiagnosticsListeners) {
return set(DefaultDiagnosticsListenerProvider.providers(newDiagnosticsListeners));
}
@Override
public final Configuration set(DiagnosticsListenerProvider... newDiagnosticsListenerProviders) {
this.diagnosticsListenerProviders = newDiagnosticsListenerProviders != null
@ -1225,10 +1158,6 @@ public class DefaultConfiguration implements Configuration {
@Override
public final Configuration set(Clock newClock) {

View File

@ -13394,7 +13394,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
// [#8722] TODO Replace this by a public SPI
// [#11054] Use a VisitListener to find actual Params in the expression tree,
// which may have more refined DataTypes attached to them, from context
dsl.configuration().derive(onVisitStart(ctx -> {
dsl.configuration().deriveAppending(onVisitStart(ctx -> {
if (ctx.queryPart() instanceof Param) {
Param<?> p = (Param<?>) ctx.queryPart();

View File

@ -2804,6 +2804,12 @@ final class Tools {
return result;
}
static final <T> T[] combine(T[] a1, T[] a2) {
T[] result = Arrays.copyOf(a1, a1.length + a2.length);
System.arraycopy(a2, 0, result, a1.length, a2.length);
return result;
}
/**
* Combine a field with an array of fields
*/

View File

@ -60,12 +60,9 @@ import org.jooq.Record;
import org.jooq.Routine;
import org.jooq.TXTFormat;
import org.jooq.VisitContext;
import org.jooq.VisitListener;
import org.jooq.VisitListenerProvider;
import org.jooq.impl.DSL;
import org.jooq.impl.DefaultExecuteListener;
import org.jooq.impl.DefaultVisitListener;
import org.jooq.impl.DefaultVisitListenerProvider;
/**
* A default {@link ExecuteListener} that just logs events to java.util.logging,
@ -90,7 +87,7 @@ public class LoggerListener extends DefaultExecuteListener {
// [#2939] Prevent excessive logging of bind variables only in DEBUG mode, not in TRACE mode.
if (!log.isTraceEnabled())
configuration = abbreviateBindVariables(configuration);
configuration = configuration.deriveAppending(new BindValueAbbreviator());
String[] batchSQL = ctx.batchSQL();
if (ctx.query() != null) {
@ -216,18 +213,6 @@ public class LoggerListener extends DefaultExecuteListener {
private static final int maxLength = 2000;
/**
* Add a {@link VisitListener} that transforms all bind variables by abbreviating them.
*/
private final Configuration abbreviateBindVariables(Configuration configuration) {
VisitListenerProvider[] oldProviders = configuration.visitListenerProviders();
VisitListenerProvider[] newProviders = new VisitListenerProvider[oldProviders.length + 1];
System.arraycopy(oldProviders, 0, newProviders, 0, oldProviders.length);
newProviders[newProviders.length - 1] = new DefaultVisitListenerProvider(new BindValueAbbreviator());
return configuration.derive(newProviders);
}
private static class BindValueAbbreviator extends DefaultVisitListener {
private boolean anyAbbreviations = false;

View File

@ -76,6 +76,7 @@ import org.jooq.UnwrapperProvider;
import org.jooq.VisitListener;
import org.jooq.VisitListenerProvider;
import org.jooq.conf.Settings;
import org.jooq.impl.AbstractConfiguration;
/**
* A mock configuration.
@ -87,7 +88,7 @@ import org.jooq.conf.Settings;
* @author Lukas Eder
*/
@SuppressWarnings("deprecation")
public class MockConfiguration implements Configuration {
public class MockConfiguration extends AbstractConfiguration {
/**
* Generated UID
@ -312,61 +313,31 @@ public class MockConfiguration implements Configuration {
return delegate.set(newRecordUnmapperProvider);
}
@Override
public Configuration set(RecordListener... newRecordListeners) {
return delegate.set(newRecordListeners);
}
@Override
public Configuration set(RecordListenerProvider... newRecordListenerProviders) {
return delegate.set(newRecordListenerProviders);
}
@Override
public Configuration set(ExecuteListener... newExecuteListeners) {
return delegate.set(newExecuteListeners);
}
@Override
public Configuration set(ExecuteListenerProvider... newExecuteListenerProviders) {
return delegate.set(newExecuteListenerProviders);
}
@Override
public Configuration set(MigrationListener... newMigrationListeners) {
return delegate.set(newMigrationListeners);
}
@Override
public Configuration set(MigrationListenerProvider... newMigrationListenerProviders) {
return delegate.set(newMigrationListenerProviders);
}
@Override
public Configuration set(VisitListener... newVisitListeners) {
return delegate.set(newVisitListeners);
}
@Override
public Configuration set(VisitListenerProvider... newVisitListenerProviders) {
return delegate.set(newVisitListenerProviders);
}
@Override
public Configuration set(TransactionListener... newTransactionListeners) {
return delegate.set(newTransactionListeners);
}
@Override
public Configuration set(TransactionListenerProvider... newTransactionListenerProviders) {
return delegate.set(newTransactionListenerProviders);
}
@Override
public Configuration set(DiagnosticsListener... newDiagnosticsListeners) {
return delegate.set(newDiagnosticsListeners);
}
@Override
public Configuration set(DiagnosticsListenerProvider... newDiagnosticsListenerProviders) {
return delegate.set(newDiagnosticsListenerProviders);
@ -382,12 +353,6 @@ public class MockConfiguration implements Configuration {
@Override
public Configuration set(Unwrapper newUnwrapper) {
return delegate.set(newUnwrapper);
@ -488,61 +453,31 @@ public class MockConfiguration implements Configuration {
return delegate.derive(newRecordUnmapperProvider);
}
@Override
public Configuration derive(RecordListener... newRecordListeners) {
return delegate.derive(newRecordListeners);
}
@Override
public Configuration derive(RecordListenerProvider... newRecordListenerProviders) {
return delegate.derive(newRecordListenerProviders);
}
@Override
public Configuration derive(ExecuteListener... newExecuteListeners) {
return delegate.derive(newExecuteListeners);
}
@Override
public Configuration derive(ExecuteListenerProvider... newExecuteListenerProviders) {
return delegate.derive(newExecuteListenerProviders);
}
@Override
public Configuration derive(MigrationListener... newMigrationListeners) {
return delegate.derive(newMigrationListeners);
}
@Override
public Configuration derive(MigrationListenerProvider... newMigrationListenerProviders) {
return delegate.derive(newMigrationListenerProviders);
}
@Override
public Configuration derive(VisitListener... newVisitListeners) {
return delegate.derive(newVisitListeners);
}
@Override
public Configuration derive(VisitListenerProvider... newVisitListenerProviders) {
return delegate.derive(newVisitListenerProviders);
}
@Override
public Configuration derive(TransactionListener... newTransactionListeners) {
return delegate.derive(newTransactionListeners);
}
@Override
public Configuration derive(TransactionListenerProvider... newTransactionListenerProviders) {
return delegate.derive(newTransactionListenerProviders);
}
@Override
public Configuration derive(DiagnosticsListener... newDiagnosticsListeners) {
return delegate.derive(newDiagnosticsListeners);
}
@Override
public Configuration derive(DiagnosticsListenerProvider... newDiagnosticsListenerProviders) {
return delegate.derive(newDiagnosticsListenerProviders);
@ -558,12 +493,6 @@ public class MockConfiguration implements Configuration {
@Override
public Configuration derive(Unwrapper newUnwrapper) {
return delegate.derive(newUnwrapper);