From 9bf4f75cbf9f2c439c2126a7b85e813d21337dd0 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 27 Jul 2012 20:11:13 +0200 Subject: [PATCH] [#1544] Remove Attachable interface from QueryPart hierarchy - removed obsolete AttachableImpl --- .../java/org/jooq/impl/AbstractQuery.java | 24 +-- .../java/org/jooq/impl/AbstractQueryPart.java | 7 - .../java/org/jooq/impl/AbstractRoutine.java | 34 ++--- .../java/org/jooq/impl/AbstractStore.java | 17 ++- .../java/org/jooq/impl/AttachableImpl.java | 137 ------------------ .../main/java/org/jooq/impl/ResultImpl.java | 18 ++- 6 files changed, 50 insertions(+), 187 deletions(-) delete mode 100644 jOOQ/src/main/java/org/jooq/impl/AttachableImpl.java diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java index 1b3f0aab0a..176a0519ae 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java @@ -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); } diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractQueryPart.java b/jOOQ/src/main/java/org/jooq/impl/AbstractQueryPart.java index 910ea5cf9d..bf31ba987b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractQueryPart.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractQueryPart.java @@ -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 * diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java index af1d15224b..1a9675c917 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java @@ -105,7 +105,7 @@ public abstract class AbstractRoutine extends AbstractSchemaProviderQueryPart private final Set> inValuesNonDefaulted; private transient Field function; - private final AttachableImpl attachable; + private Configuration configuration; private final Map, Object> results; private final Map, Integer> parameterIndexes; @@ -164,7 +164,6 @@ public abstract class AbstractRoutine extends AbstractSchemaProviderQueryPart protected AbstractRoutine(String name, Schema schema, Package pkg, DataType type) { super(name, schema); - this.attachable = new AttachableImpl(this); this.parameterIndexes = new HashMap, Integer>(); this.pkg = pkg; @@ -214,8 +213,8 @@ public abstract class AbstractRoutine 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 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 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 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 extends AbstractSchemaProviderQueryPart private final int executeSelect() { final Field 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 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 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 extends AbstractSchemaProviderQueryPart else if (sqlType == Types.ARRAY) { ArrayRecord record = Util.newArrayRecord( - (Class>) parameter.getType(), configuration); + (Class>) parameter.getType(), c); statement.registerOutParameter(index, Types.ARRAY, record.getName()); } @@ -712,8 +710,8 @@ public abstract class AbstractRoutine extends AbstractSchemaProviderQueryPart } @Override - final Field getFunction0(Configuration configuration) { - RenderContext local = create(configuration).renderContext(); + final Field getFunction0(Configuration c) { + RenderContext local = create(c).renderContext(); toSQLQualifiedName(local); Field[] array = new Field[getInParameters().size()]; @@ -722,7 +720,7 @@ public abstract class AbstractRoutine 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 { diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractStore.java b/jOOQ/src/main/java/org/jooq/impl/AbstractStore.java index 9236c50a8f..0793d9cc34 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractStore.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractStore.java @@ -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 implements Store, 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 implements Store, 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; } /** diff --git a/jOOQ/src/main/java/org/jooq/impl/AttachableImpl.java b/jOOQ/src/main/java/org/jooq/impl/AttachableImpl.java deleted file mode 100644 index 4e9928a384..0000000000 --- a/jOOQ/src/main/java/org/jooq/impl/AttachableImpl.java +++ /dev/null @@ -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 internalAPI(Class 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 getAttachables() { - return delegate.getAttachables(); - } - - @Override - public String toString() { - if (configuration == null) { - return "[ detached ]"; - } - else { - return configuration.toString(); - } - } -} diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java index 083f9dc958..6e6e6443b5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java @@ -93,14 +93,14 @@ class ResultImpl implements Result, AttachableInternal { */ private static final long serialVersionUID = 6416154375799578362L; - private final FieldProvider fields; - private final List records; - private final AttachableImpl attachable; + private final FieldProvider fields; + private final List records; + private Configuration configuration; ResultImpl(Configuration configuration, FieldProvider fields) { this.fields = fields; this.records = new ArrayList(); - this.attachable = new AttachableImpl(this, configuration); + this.configuration = configuration; } // ------------------------------------------------------------------------- @@ -113,8 +113,12 @@ class ResultImpl implements Result, 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 implements Result, AttachableInternal { @Override public final Configuration getConfiguration() { - return attachable.getConfiguration(); + return configuration; } // -------------------------------------------------------------------------