[#1544] Remove Attachable interface from QueryPart hierarchy - removed
obsolete AttachableImpl
This commit is contained in:
parent
8a4c6cf07d
commit
9bf4f75cbf
@ -61,10 +61,10 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
private static final long serialVersionUID = -8046199737354507547L;
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractQuery.class);
|
||||
|
||||
private final AttachableImpl attachable;
|
||||
private Configuration configuration;
|
||||
|
||||
AbstractQuery(Configuration configuration) {
|
||||
this.attachable = new AttachableImpl(this, configuration);
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -72,13 +72,13 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void attach(Configuration configuration) {
|
||||
attachable.attach(configuration);
|
||||
public final void attach(Configuration c) {
|
||||
configuration = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Configuration getConfiguration() {
|
||||
return attachable.getConfiguration();
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,18 +136,18 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
if (isExecutable()) {
|
||||
|
||||
// Let listeners provide a configuration to this query
|
||||
Configuration configuration = org.jooq.ConfigurationRegistry.provideFor(getConfiguration());
|
||||
if (configuration == null) {
|
||||
configuration = getConfiguration();
|
||||
Configuration c = org.jooq.ConfigurationRegistry.provideFor(getConfiguration());
|
||||
if (c == null) {
|
||||
c = getConfiguration();
|
||||
}
|
||||
|
||||
// [#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(configuration, this);
|
||||
ExecuteContext ctx = new DefaultExecuteContext(c, this);
|
||||
ExecuteListener listener = new ExecuteListeners(ctx);
|
||||
|
||||
Connection connection = configuration.getConnection();
|
||||
Connection connection = c.getConnection();
|
||||
if (connection == null) {
|
||||
throw new DetachedException("Cannot execute query. No Connection configured");
|
||||
}
|
||||
@ -163,9 +163,9 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
listener.prepareEnd(ctx);
|
||||
|
||||
// [#1145] Bind variables only for true prepared statements
|
||||
if (executePreparedStatements(getConfiguration().getSettings())) {
|
||||
if (executePreparedStatements(c.getSettings())) {
|
||||
listener.bindStart(ctx);
|
||||
create(configuration).bind(this, ctx.statement());
|
||||
create(c).bind(this, ctx.statement());
|
||||
listener.bindEnd(ctx);
|
||||
}
|
||||
|
||||
|
||||
@ -221,13 +221,6 @@ abstract class AbstractQueryPart implements QueryPartInternal {
|
||||
return Factory.getNewFactory(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal convenience method
|
||||
*/
|
||||
final Factory create(AttachableImpl a) {
|
||||
return create(a.getConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal convenience method
|
||||
*
|
||||
|
||||
@ -105,7 +105,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
private final Set<Parameter<?>> inValuesNonDefaulted;
|
||||
private transient Field<T> function;
|
||||
|
||||
private final AttachableImpl attachable;
|
||||
private Configuration configuration;
|
||||
private final Map<Parameter<?>, Object> results;
|
||||
private final Map<Parameter<?>, Integer> parameterIndexes;
|
||||
|
||||
@ -164,7 +164,6 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
protected AbstractRoutine(String name, Schema schema, Package pkg, DataType<T> type) {
|
||||
super(name, schema);
|
||||
|
||||
this.attachable = new AttachableImpl(this);
|
||||
this.parameterIndexes = new HashMap<Parameter<?>, Integer>();
|
||||
|
||||
this.pkg = pkg;
|
||||
@ -214,8 +213,8 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void attach(Configuration configuration) {
|
||||
attachable.attach(configuration);
|
||||
public final void attach(Configuration c) {
|
||||
configuration = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -225,14 +224,14 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
|
||||
@Override
|
||||
public final Configuration getConfiguration() {
|
||||
return attachable.getConfiguration();
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int execute(Configuration configuration) {
|
||||
public final int execute(Configuration c) {
|
||||
|
||||
// Ensure that all depending Attachables are attached
|
||||
attach(configuration);
|
||||
attach(c);
|
||||
return execute();
|
||||
}
|
||||
|
||||
@ -243,7 +242,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
return executeCallableStatement();
|
||||
}
|
||||
else {
|
||||
switch (attachable.getConfiguration().getDialect()) {
|
||||
switch (configuration.getDialect()) {
|
||||
|
||||
// [#852] Some RDBMS don't allow for using JDBC procedure escape
|
||||
// syntax for functions. Select functions from DUAL instead
|
||||
@ -276,7 +275,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
}
|
||||
|
||||
private final int executeSelectFrom() {
|
||||
Factory create = create(attachable);
|
||||
Factory create = create(configuration);
|
||||
Result<?> result = create.selectFrom(table(asField())).fetch();
|
||||
results.put(returnParameter, result);
|
||||
return 0;
|
||||
@ -284,12 +283,11 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
|
||||
private final int executeSelect() {
|
||||
final Field<T> field = asField();
|
||||
results.put(returnParameter, create(attachable).select(field).fetchOne(field));
|
||||
results.put(returnParameter, create(configuration).select(field).fetchOne(field));
|
||||
return 0;
|
||||
}
|
||||
|
||||
private final int executeCallableStatement() {
|
||||
Configuration configuration = attachable.getConfiguration();
|
||||
ExecuteContext ctx = new DefaultExecuteContext(configuration, this);
|
||||
ExecuteListener listener = new ExecuteListeners(ctx);
|
||||
|
||||
@ -529,7 +527,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final void registerOutParameters(Configuration configuration, CallableStatement statement) throws SQLException {
|
||||
private final void registerOutParameters(Configuration c, CallableStatement statement) throws SQLException {
|
||||
|
||||
// Register all out / inout parameters according to their position
|
||||
// Note that some RDBMS do not support binding by name very well
|
||||
@ -538,9 +536,9 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
getOutParameters().contains(parameter)) {
|
||||
|
||||
int index = parameterIndexes.get(parameter);
|
||||
int sqlType = parameter.getDataType().getDataType(configuration).getSQLType();
|
||||
int sqlType = parameter.getDataType().getDataType(c).getSQLType();
|
||||
|
||||
switch (configuration.getDialect()) {
|
||||
switch (c.getDialect()) {
|
||||
|
||||
// For some user defined types Oracle needs to bind
|
||||
// also the type name
|
||||
@ -552,7 +550,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
|
||||
else if (sqlType == Types.ARRAY) {
|
||||
ArrayRecord<?> record = Util.newArrayRecord(
|
||||
(Class<? extends ArrayRecord<?>>) parameter.getType(), configuration);
|
||||
(Class<? extends ArrayRecord<?>>) parameter.getType(), c);
|
||||
statement.registerOutParameter(index, Types.ARRAY, record.getName());
|
||||
}
|
||||
|
||||
@ -712,8 +710,8 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
}
|
||||
|
||||
@Override
|
||||
final Field<T> getFunction0(Configuration configuration) {
|
||||
RenderContext local = create(configuration).renderContext();
|
||||
final Field<T> getFunction0(Configuration c) {
|
||||
RenderContext local = create(c).renderContext();
|
||||
toSQLQualifiedName(local);
|
||||
|
||||
Field<?>[] array = new Field<?>[getInParameters().size()];
|
||||
@ -722,7 +720,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
for (Parameter<?> p : getInParameters()) {
|
||||
|
||||
// Disambiguate overloaded function signatures
|
||||
if (SQLDialect.POSTGRES == configuration.getDialect() && isOverloaded()) {
|
||||
if (SQLDialect.POSTGRES == c.getDialect() && isOverloaded()) {
|
||||
array[i] = getInValues().get(p).cast(p.getType());
|
||||
}
|
||||
else {
|
||||
|
||||
@ -42,6 +42,7 @@ import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jooq.Attachable;
|
||||
import org.jooq.AttachableInternal;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Store;
|
||||
@ -55,16 +56,16 @@ abstract class AbstractStore<T> implements Store<T>, AttachableInternal {
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -2989496800221194411L;
|
||||
private static final long serialVersionUID = -2989496800221194411L;
|
||||
|
||||
private final AttachableImpl attachable;
|
||||
private Configuration configuration;
|
||||
|
||||
AbstractStore() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
AbstractStore(Configuration configuration) {
|
||||
this.attachable = new AttachableImpl(this, configuration);
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -77,13 +78,17 @@ abstract class AbstractStore<T> implements Store<T>, AttachableInternal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void attach(Configuration configuration) {
|
||||
attachable.attach(configuration);
|
||||
public final void attach(Configuration c) {
|
||||
configuration = c;
|
||||
|
||||
for (Attachable attachable : getAttachables()) {
|
||||
attachable.attach(c);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Configuration getConfiguration() {
|
||||
return attachable.getConfiguration();
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,137 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed to you under the Apache License, Version 2.0
|
||||
* (the "License"); You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* . Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* . Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* . Neither the name "jOOQ" nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Factory.isStaticFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Attachable;
|
||||
import org.jooq.AttachableInternal;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Store;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
|
||||
/**
|
||||
* A default implementation for mixin of the {@link Attachable} interface
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
class AttachableImpl implements AttachableInternal {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 8769475224067827057L;
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AttachableImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
private final AttachableInternal delegate;
|
||||
|
||||
AttachableImpl(AttachableInternal delegate) {
|
||||
this(delegate, null);
|
||||
}
|
||||
|
||||
AttachableImpl(AttachableInternal delegate, Configuration configuration) {
|
||||
this.delegate = delegate;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <I> I internalAPI(Class<I> internalType) throws ClassCastException {
|
||||
return internalType.cast(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void attach(Configuration c) {
|
||||
|
||||
// Static factories or default configurations in QueryParts
|
||||
// shouldn't be attached
|
||||
if (!isStaticFactory(configuration)
|
||||
|
||||
// On the other hand, Stores (e.g. UDTRecord, ArrayRecord) should
|
||||
// always be attached
|
||||
|| delegate instanceof Store) {
|
||||
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Attaching", delegate.getClass().getSimpleName() + " [ " + delegate + " ]");
|
||||
}
|
||||
|
||||
configuration = c;
|
||||
}
|
||||
|
||||
for (Attachable attachable : getAttachables()) {
|
||||
if (attachable != null) {
|
||||
attachable.attach(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
final SQLDialect getDialect() {
|
||||
return getConfiguration().getDialect();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
final org.jooq.SchemaMapping getSchemaMapping() {
|
||||
return getConfiguration().getSchemaMapping();
|
||||
}
|
||||
|
||||
final Settings getSettings() {
|
||||
return getConfiguration().getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Attachable> getAttachables() {
|
||||
return delegate.getAttachables();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (configuration == null) {
|
||||
return "[ detached ]";
|
||||
}
|
||||
else {
|
||||
return configuration.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,14 +93,14 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
|
||||
*/
|
||||
private static final long serialVersionUID = 6416154375799578362L;
|
||||
|
||||
private final FieldProvider fields;
|
||||
private final List<R> records;
|
||||
private final AttachableImpl attachable;
|
||||
private final FieldProvider fields;
|
||||
private final List<R> records;
|
||||
private Configuration configuration;
|
||||
|
||||
ResultImpl(Configuration configuration, FieldProvider fields) {
|
||||
this.fields = fields;
|
||||
this.records = new ArrayList<R>();
|
||||
this.attachable = new AttachableImpl(this, configuration);
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -113,8 +113,12 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void attach(Configuration configuration) {
|
||||
attachable.attach(configuration);
|
||||
public final void attach(Configuration c) {
|
||||
this.configuration = c;
|
||||
|
||||
for (Attachable attachable : getAttachables()) {
|
||||
attachable.attach(c);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -132,7 +136,7 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
|
||||
|
||||
@Override
|
||||
public final Configuration getConfiguration() {
|
||||
return attachable.getConfiguration();
|
||||
return configuration;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user