From 8e8915c008a2ffab0d8e092504e5bf3f0b607039 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sun, 24 Mar 2013 11:45:40 +0100 Subject: [PATCH] [#2328] Remove UpdatableTable marker interface, pulling up methods to Table --- .../java/org/jooq/util/JavaGenerator.java | 15 +-- .../src/main/resources/manual-3.0.xml | 7 +- .../java/org/jooq/InsertOnDuplicateStep.java | 4 +- jOOQ/src/main/java/org/jooq/Table.java | 61 +++++++++- .../main/java/org/jooq/UpdatableRecord.java | 20 ++-- .../main/java/org/jooq/UpdatableTable.java | 108 ------------------ .../java/org/jooq/impl/AbstractTable.java | 30 +++++ .../main/java/org/jooq/impl/CustomRecord.java | 9 -- jOOQ/src/main/java/org/jooq/impl/DAOImpl.java | 6 +- .../org/jooq/impl/DefaultBindContext.java | 1 - .../java/org/jooq/impl/InsertQueryImpl.java | 5 +- .../main/java/org/jooq/impl/LoaderImpl.java | 23 ++-- .../main/java/org/jooq/impl/MergeImpl.java | 6 +- .../src/main/java/org/jooq/impl/MetaImpl.java | 39 +------ .../java/org/jooq/impl/TableRecordImpl.java | 5 +- .../org/jooq/impl/UpdatableRecordImpl.java | 13 +-- .../org/jooq/impl/UpdatableTableImpl.java | 100 ---------------- jOOQ/src/main/java/org/jooq/impl/Utils.java | 1 - 18 files changed, 125 insertions(+), 328 deletions(-) delete mode 100644 jOOQ/src/main/java/org/jooq/UpdatableTable.java delete mode 100644 jOOQ/src/main/java/org/jooq/impl/UpdatableTableImpl.java diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java index f23e80b253..2c523e29bc 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java @@ -77,7 +77,6 @@ import org.jooq.impl.TableRecordImpl; import org.jooq.impl.UDTImpl; import org.jooq.impl.UDTRecordImpl; import org.jooq.impl.UpdatableRecordImpl; -import org.jooq.impl.UpdatableTableImpl; import org.jooq.tools.JooqLogger; import org.jooq.tools.StopWatch; import org.jooq.tools.StringUtils; @@ -1347,6 +1346,7 @@ public class JavaGenerator extends AbstractGenerator { protected void generateTable(SchemaDefinition schema, TableDefinition table) { UniqueKeyDefinition primaryKey = table.getPrimaryKey(); + final boolean updatable = generateRelations() && primaryKey != null; final String className = getStrategy().getJavaClassName(table); final String fullClassName = getStrategy().getFullJavaClassName(table); final String fullTableId = getStrategy().getFullJavaIdentifier(table); @@ -1363,14 +1363,7 @@ public class JavaGenerator extends AbstractGenerator { printPackage(out, table); printClassJavadoc(out, table); - Class baseClass; - if (generateRelations() && primaryKey != null) { - baseClass = UpdatableTableImpl.class; - } else { - baseClass = TableImpl.class; - } - - out.println("public class %s extends %s<%s>[[before= implements ][%s]] {", className, baseClass, recordType, interfaces); + out.println("public class %s extends %s<%s>[[before= implements ][%s]] {", className, TableImpl.class, recordType, interfaces); out.printSerial(); printSingletonInstance(out, table); printRecordTypeMethod(out, table); @@ -1465,9 +1458,9 @@ public class JavaGenerator extends AbstractGenerator { } } - // [#1596] UpdatableTables can provide fields for optimistic locking + // [#1596] Updatable tables can provide fields for optimistic locking // if properly configured - if (baseClass == UpdatableTableImpl.class) { + if (updatable) { patternLoop: for (String pattern : database.getRecordVersionFields()) { for (ColumnDefinition column : table.getColumns()) { if ((column.getName().matches(pattern.trim()) || diff --git a/jOOQ-website/src/main/resources/manual-3.0.xml b/jOOQ-website/src/main/resources/manual-3.0.xml index d4f7f77387..e055fabd1d 100644 --- a/jOOQ-website/src/main/resources/manual-3.0.xml +++ b/jOOQ-website/src/main/resources/manual-3.0.xml @@ -9059,7 +9059,7 @@ create.insertInto(com.example.generated.Tables.MY_TABLE) Every table in your database will generate a implementation that looks like this:

- { + { // The singleton instance public static final Book BOOK = new Book(); @@ -9458,7 +9458,7 @@ public class Book implements java.io.Serializable The above configuration will lead to AUTHOR.DATE_OF_BIRTH being generated like this:

- { + { // [...] public final TableField DATE_OF_BIRTH = // [...] @@ -10297,7 +10297,8 @@ Condition condition3 = BOOK.TITLE.isNotDistinctFrom(possiblyNull);]]>
  • The code generation configuration can no longer be loaded from .properties files. Only XML configurations are supported.
  • The master data type feature is no longer supported. This feature was unlikely to behave exactly as users expected. It is better if users write their own code generators to generate master enum data types from their database tables. jOOQ's enum mapping and converter features sufficiently cover interacting with such user-defined types.
  • The Factory subtypes are no longer instanciable. As Factory now only contains static methods, subclassing is no longer useful. There are still dialect-specific Factories providing static methods for dialect-specific functions. But the code-generator no longer generates a schema-specific Factory
  • -
  • The concept of a "main key" is no longer supported. The code generator produces UpdatableTables and UpdatableRecords only if the underlying table has a PRIMARY KEY. The reason for this removal is the fact that "main keys" are not reliable enough. They were chosen arbitrarily among UNIQUE KEYs.
  • +
  • The concept of a "main key" is no longer supported. The code generator produces UpdatableRecords only if the underlying table has a PRIMARY KEY. The reason for this removal is the fact that "main keys" are not reliable enough. They were chosen arbitrarily among UNIQUE KEYs.
  • +
  • The UpdatableTable type has been removed. While adding significant complexity to the type hierarchy, this type adds not much value over a simple Table.getPrimaryKey() != null check.
  • diff --git a/jOOQ/src/main/java/org/jooq/InsertOnDuplicateStep.java b/jOOQ/src/main/java/org/jooq/InsertOnDuplicateStep.java index 3edc4333fe..6406d54bc2 100644 --- a/jOOQ/src/main/java/org/jooq/InsertOnDuplicateStep.java +++ b/jOOQ/src/main/java/org/jooq/InsertOnDuplicateStep.java @@ -76,8 +76,8 @@ public interface InsertOnDuplicateStep extends InsertFinalStep * simulate this clause using a MERGE statement on some other * databases. The conditions for a RDBMS to simulate this clause are: *
      - *
    • The INSERT statement's table is an - * {@link UpdatableTable}
    • + *
    • The INSERT statement's table is a + * {@link Table} with a {@link Table#getPrimaryKey()}
    • *
    • The RDBMS supports the MERGE clause (see * {@link Executor#mergeInto(Table)}).
    • *
    diff --git a/jOOQ/src/main/java/org/jooq/Table.java b/jOOQ/src/main/java/org/jooq/Table.java index 25fe1c64c3..593f619ce8 100644 --- a/jOOQ/src/main/java/org/jooq/Table.java +++ b/jOOQ/src/main/java/org/jooq/Table.java @@ -166,13 +166,70 @@ public interface Table extends TableLike { * null, if no such information is available. */ Identity getIdentity(); + /** + * Retrieve the table's primary key + * + * @return The primary key. This is never null for an updatable + * table. + */ + UniqueKey getPrimaryKey(); + + /** + * A "version" field holding record version information used for optimistic + * locking + *

    + * jOOQ supports optimistic locking in {@link UpdatableRecord#store()} and + * {@link UpdatableRecord#delete()} if + * {@link Settings#isExecuteWithOptimisticLocking()} is enabled. Optimistic + * locking is performed in a single UPDATE or + * DELETE statement if tables provide a "version" or + * "timestamp" field, or in two steps using an additional + * SELECT .. FOR UPDATE statement otherwise. + *

    + * This method is overridden in generated subclasses if their corresponding + * tables have been configured accordingly. A table may have both a + * "version" and a "timestamp" field. + * + * @return The "version" field, or null, if this table has no + * "version" field. + * @see #getRecordTimestamp() + * @see UpdatableRecord#store() + * @see UpdatableRecord#delete() + * @see Settings#isExecuteWithOptimisticLocking() + */ + TableField getRecordVersion(); + + /** + * A "timestamp" field holding record timestamp information used for + * optimistic locking + *

    + * jOOQ supports optimistic locking in {@link UpdatableRecord#store()} and + * {@link UpdatableRecord#delete()} if + * {@link Settings#isExecuteWithOptimisticLocking()} is enabled. Optimistic + * locking is performed in a single UPDATE or + * DELETE statement if tables provide a "version" or + * "timestamp" field, or in two steps using an additional + * SELECT .. FOR UPDATE statement otherwise. + *

    + * This method is overridden in generated subclasses if their corresponding + * tables have been configured accordingly. A table may have both a + * "version" and a "timestamp" field. + * + * @return The "timestamp" field, or null, if this table has no + * "timestamp" field. + * @see #getRecordVersion() + * @see UpdatableRecord#store() + * @see UpdatableRecord#delete() + * @see Settings#isExecuteWithOptimisticLocking() + */ + TableField getRecordTimestamp(); /** * Retrieve all of the table's unique keys. * * @return All keys. This is never null. This is never empty - * for {@link UpdatableTable}s because an updatable table always has - * at least a primary key. This method returns an unmodifiable list. + * for a {@link Table} with a {@link Table#getPrimaryKey()}. This + * method returns an unmodifiable list. */ List> getKeys(); diff --git a/jOOQ/src/main/java/org/jooq/UpdatableRecord.java b/jOOQ/src/main/java/org/jooq/UpdatableRecord.java index 43e3fbb521..03d3f5b04b 100644 --- a/jOOQ/src/main/java/org/jooq/UpdatableRecord.java +++ b/jOOQ/src/main/java/org/jooq/UpdatableRecord.java @@ -78,13 +78,7 @@ import org.jooq.impl.Executor; public interface UpdatableRecord> extends TableRecord { /** - * The table from which this record was read - */ - @Override - UpdatableTable getTable(); - - /** - * A view holding values for the {@link UpdatableTable#getPrimaryKey()} + * A view holding values for the {@link Table#getPrimaryKey()} *

    * This method returns a "view" of this record itself. Modifications to the * returned record will affect values in this record. @@ -145,8 +139,8 @@ public interface UpdatableRecord> extends TableReco * jOOQ can auto-generate "version" and "timestamp" values that can be used * for optimistic locking. If this is an {@link UpdatableRecord} and if this * record returns fields for either - * {@link UpdatableTable#getRecordVersion()} or - * {@link UpdatableTable#getRecordTimestamp()}, then these values are set + * {@link Table#getRecordVersion()} or + * {@link Table#getRecordTimestamp()}, then these values are set * onto the INSERT or UPDATE statement being * executed. On execution success, the generated values are set to this * record. Use the code-generation configuration to specify naming patterns @@ -170,8 +164,8 @@ public interface UpdatableRecord> extends TableReco *

    * This is the preferred way of using optimistic locking in jOOQ. If this is * an {@link UpdatableRecord} and if this record returns fields for either - * {@link UpdatableTable#getRecordVersion()} or - * {@link UpdatableTable#getRecordTimestamp()}, then these values are + * {@link Table#getRecordVersion()} or + * {@link Table#getRecordTimestamp()}, then these values are * compared to the corresponding value in the database in the * WHERE clause of the executed DELETE statement. *

  • Without any specific column configurations @@ -266,8 +260,8 @@ public interface UpdatableRecord> extends TableReco *

    * This is the preferred way of using optimistic locking in jOOQ. If this is * an {@link UpdatableRecord} and if this record returns fields for either - * {@link UpdatableTable#getRecordVersion()} or - * {@link UpdatableTable#getRecordTimestamp()}, then these values are + * {@link Table#getRecordVersion()} or + * {@link Table#getRecordTimestamp()}, then these values are * compared to the corresponding value in the database in the * WHERE clause of the executed DELETE statement.

  • *
  • Without any specific column configurations diff --git a/jOOQ/src/main/java/org/jooq/UpdatableTable.java b/jOOQ/src/main/java/org/jooq/UpdatableTable.java deleted file mode 100644 index 62124bf1e4..0000000000 --- a/jOOQ/src/main/java/org/jooq/UpdatableTable.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (c) 2009-2013, 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; - -import org.jooq.conf.Settings; - -/** - * A common interface for tables whose records can be stored back to the - * database again. - * - * @param The record type of the table - * @see UpdatableRecord - * @author Lukas Eder - */ -public interface UpdatableTable extends Table { - - /** - * Retrieve the table's primary key - * - * @return The primary key. This is never null for an updatable - * table. - */ - UniqueKey getPrimaryKey(); - - /** - * A "version" field holding record version information used for optimistic - * locking - *

    - * jOOQ supports optimistic locking in {@link UpdatableRecord#store()} and - * {@link UpdatableRecord#delete()} if - * {@link Settings#isExecuteWithOptimisticLocking()} is enabled. Optimistic - * locking is performed in a single UPDATE or - * DELETE statement if tables provide a "version" or - * "timestamp" field, or in two steps using an additional - * SELECT .. FOR UPDATE statement otherwise. - *

    - * This method is overridden in generated subclasses if their corresponding - * tables have been configured accordingly. A table may have both a - * "version" and a "timestamp" field. - * - * @return The "version" field, or null, if this table has no - * "version" field. - * @see #getRecordTimestamp() - * @see UpdatableRecord#store() - * @see UpdatableRecord#delete() - * @see Settings#isExecuteWithOptimisticLocking() - */ - TableField getRecordVersion(); - - /** - * A "timestamp" field holding record timestamp information used for - * optimistic locking - *

    - * jOOQ supports optimistic locking in {@link UpdatableRecord#store()} and - * {@link UpdatableRecord#delete()} if - * {@link Settings#isExecuteWithOptimisticLocking()} is enabled. Optimistic - * locking is performed in a single UPDATE or - * DELETE statement if tables provide a "version" or - * "timestamp" field, or in two steps using an additional - * SELECT .. FOR UPDATE statement otherwise. - *

    - * This method is overridden in generated subclasses if their corresponding - * tables have been configured accordingly. A table may have both a - * "version" and a "timestamp" field. - * - * @return The "timestamp" field, or null, if this table has no - * "timestamp" field. - * @see #getRecordVersion() - * @see UpdatableRecord#store() - * @see UpdatableRecord#delete() - * @see Settings#isExecuteWithOptimisticLocking() - */ - TableField getRecordTimestamp(); - -} diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java index 682c3ba6c9..32269fbfb0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java @@ -163,6 +163,36 @@ abstract class AbstractTable extends AbstractQueryPart impleme return null; } + /** + * {@inheritDoc} + *

    + * Subclasses may override this method + */ + @Override + public UniqueKey getPrimaryKey() { + return null; + } + + /** + * {@inheritDoc} + *

    + * Subclasses may override this method + */ + @Override + public TableField getRecordVersion() { + return null; + } + + /** + * {@inheritDoc} + *

    + * Subclasses may override this method + */ + @Override + public TableField getRecordTimestamp() { + return null; + } + /** * {@inheritDoc} *

    diff --git a/jOOQ/src/main/java/org/jooq/impl/CustomRecord.java b/jOOQ/src/main/java/org/jooq/impl/CustomRecord.java index e733fd1c2b..b015752c58 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CustomRecord.java +++ b/jOOQ/src/main/java/org/jooq/impl/CustomRecord.java @@ -70,13 +70,4 @@ public abstract class CustomRecord> extends TableRecord protected CustomRecord(Table table) { super(table); } - - // ------------------------------------------------------------------------- - // No further overrides allowed - // ------------------------------------------------------------------------- - - @Override - public final Table getTable() { - return super.getTable(); - } } diff --git a/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java b/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java index 5b89f1c645..067f824968 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java @@ -49,7 +49,6 @@ import org.jooq.RecordMapper; import org.jooq.Table; import org.jooq.UniqueKey; import org.jooq.UpdatableRecord; -import org.jooq.UpdatableTable; /** * A common base implementation for generated DAO's. @@ -266,10 +265,9 @@ public abstract class DAOImpl, P, T> implements DAO } private final Field pk() { - if (table instanceof UpdatableTable) { - UpdatableTable updatable = (UpdatableTable) table; - UniqueKey key = updatable.getPrimaryKey(); + UniqueKey key = table.getPrimaryKey(); + if (key != null) { if (key.getFields().size() == 1) { return key.getFields().get(0); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java index 6085ee9e85..54edb21b2b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java @@ -50,7 +50,6 @@ import java.math.BigInteger; import java.sql.Array; import java.sql.Blob; import java.sql.Clob; -import java.sql.Connection; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.SQLException; diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java index 63b11f310e..d29b9d465f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java @@ -53,7 +53,6 @@ import org.jooq.MergeOnConditionStep; import org.jooq.Record; import org.jooq.RenderContext; import org.jooq.Table; -import org.jooq.UpdatableTable; import org.jooq.exception.SQLDialectNotSupportedException; /** @@ -330,9 +329,9 @@ class InsertQueryImpl extends AbstractStoreQuery implements @SuppressWarnings("unchecked") private final Merge toMerge(Configuration configuration) { - if (getInto() instanceof UpdatableTable) { - UpdatableTable into = (UpdatableTable) getInto(); + Table into = getInto(); + if (into.getPrimaryKey() != null) { Condition condition = null; List> key = new ArrayList>(); diff --git a/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java b/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java index 54faf8c99b..0f3ed5bb20 100644 --- a/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java @@ -61,7 +61,6 @@ import org.jooq.LoaderXMLStep; import org.jooq.SelectQuery; import org.jooq.Table; import org.jooq.TableRecord; -import org.jooq.UpdatableTable; import org.jooq.exception.DataAccessException; import org.jooq.tools.StringUtils; import org.jooq.tools.csv.CSVParser; @@ -99,9 +98,8 @@ class LoaderImpl> implements // Configuration data // ------------------ - private final Executor create; + private final Executor create; private final Table table; - private final UpdatableTable updatable; private int onDuplicate = ON_DUPLICATE_KEY_ERROR; private int onError = ON_ERROR_ABORT; private int commit = COMMIT_NONE; @@ -129,13 +127,6 @@ class LoaderImpl> implements this.create = create; this.table = table; this.errors = new ArrayList(); - - if (table instanceof UpdatableTable) { - this.updatable = (UpdatableTable) table; - } - else { - this.updatable = null; - } } // ------------------------------------------------------------------------- @@ -150,8 +141,8 @@ class LoaderImpl> implements @Override public final LoaderImpl onDuplicateKeyIgnore() { - if (updatable == null) { - throw new IllegalStateException("ON DUPLICATE KEY IGNORE only works on UpdatableTable. Table is not updatable : " + table); + if (table.getPrimaryKey() == null) { + throw new IllegalStateException("ON DUPLICATE KEY IGNORE only works on tables with explicit primary keys. Table is not updatable : " + table); } onDuplicate = ON_DUPLICATE_KEY_IGNORE; @@ -160,8 +151,8 @@ class LoaderImpl> implements @Override public final LoaderImpl onDuplicateKeyUpdate() { - if (updatable == null) { - throw new IllegalStateException("ON DUPLICATE KEY UPDATE only works on UpdatableTable. Table is not updatable : " + table); + if (table.getPrimaryKey() == null) { + throw new IllegalStateException("ON DUPLICATE KEY UPDATE only works on tables with explicit primary keys. Table is not updatable : " + table); } onDuplicate = ON_DUPLICATE_KEY_UPDATE; @@ -272,10 +263,10 @@ class LoaderImpl> implements this.fields = f; this.primaryKey = new boolean[f.length]; - if (updatable != null) { + if (table.getPrimaryKey() != null) { for (int i = 0; i < fields.length; i++) { if (fields[i] != null) { - if (updatable.getPrimaryKey().getFields().contains(fields[i])) { + if (table.getPrimaryKey().getFields().contains(fields[i])) { primaryKey[i] = true; } } diff --git a/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java b/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java index 0271169a27..23c1bf6bbd 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java @@ -116,7 +116,6 @@ import org.jooq.Select; import org.jooq.Table; import org.jooq.TableLike; import org.jooq.UniqueKey; -import org.jooq.UpdatableTable; import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.tools.StringUtils; @@ -923,8 +922,9 @@ implements Set> onFields = new HashSet>(); Condition condition = null; if (getH2Keys().isEmpty()) { - if (table instanceof UpdatableTable) { - UniqueKey key = ((UpdatableTable) table).getPrimaryKey(); + UniqueKey key = table.getPrimaryKey(); + + if (key != null) { onFields.addAll(key.getFields()); for (int i = 0; i < key.getFields().size(); i++) { diff --git a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java index 1058a36617..7338d2f7b7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java @@ -43,7 +43,6 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Map; @@ -55,9 +54,6 @@ import org.jooq.Record; import org.jooq.Result; import org.jooq.Schema; import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.UpdatableTable; import org.jooq.exception.DataAccessException; import org.jooq.exception.SQLDialectNotSupportedException; @@ -216,12 +212,7 @@ class MetaImpl implements Meta, Serializable { // Result pkColumns = executor.fetch(meta().getPrimaryKeys(catalog, schema, name)) // .sortAsc("KEY_SEQ"); // -// if (pkColumns.size() == 0) { -// result.add(new MetaTable(name, this, columnCache.get(name))); -// } -// else { -// result.add(new MetaUpdatableTable(name, this, columnCache.get(name))); -// } +// result.add(new MetaTable(name, this, columnCache.get(name))); } return result; @@ -317,32 +308,4 @@ class MetaImpl implements Meta, Serializable { } } } - - @SuppressWarnings("unused") - private class MetaUpdatableTable extends MetaTable implements UpdatableTable { - - /** - * Generated UID - */ - private static final long serialVersionUID = -4555457095396846609L; - - MetaUpdatableTable(String name, Schema schema, Result columns) { - super(name, schema, columns); - } - - @Override - public final UniqueKey getPrimaryKey() { - return null; - } - - @Override - public final TableField getRecordVersion() { - return null; - } - - @Override - public final TableField getRecordTimestamp() { - return null; - } - } } diff --git a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java index 1cfa73792a..47df0b2df6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java @@ -62,11 +62,8 @@ public class TableRecordImpl> extends AbstractRecord im this.table = table; } - /* - * Subclasses may override this method - */ @Override - public Table getTable() { + public final Table getTable() { return table; } diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java index ce5f04e584..fda216ec40 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java @@ -54,11 +54,11 @@ import org.jooq.Result; import org.jooq.SQLDialect; import org.jooq.SelectQuery; import org.jooq.StoreQuery; +import org.jooq.Table; import org.jooq.TableField; import org.jooq.TableRecord; import org.jooq.UniqueKey; import org.jooq.UpdatableRecord; -import org.jooq.UpdatableTable; import org.jooq.UpdateQuery; import org.jooq.exception.DataChangedException; import org.jooq.exception.InvalidResultException; @@ -78,7 +78,7 @@ public class UpdatableRecordImpl> extends TableReco */ private static final long serialVersionUID = -1012420583600561579L; - public UpdatableRecordImpl(UpdatableTable table) { + public UpdatableRecordImpl(Table table) { super(table); } @@ -105,11 +105,6 @@ public class UpdatableRecordImpl> extends TableReco return key.fetchChildren((R) this); } - @Override - public final UpdatableTable getTable() { - return (UpdatableTable) super.getTable(); - } - @Override final UniqueKey getPrimaryKey() { return getTable().getPrimaryKey(); @@ -423,9 +418,7 @@ public class UpdatableRecordImpl> extends TableReco } private final boolean isTimestampOrVersionAvailable() { - UpdatableTable table = getTable(); - - return table.getRecordTimestamp() != null || table.getRecordVersion() != null; + return getTable().getRecordTimestamp() != null || getTable().getRecordVersion() != null; } /** diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdatableTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdatableTableImpl.java deleted file mode 100644 index 0e2b5a42f9..0000000000 --- a/jOOQ/src/main/java/org/jooq/impl/UpdatableTableImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2009-2013, 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 org.jooq.Record; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.UpdatableTable; - -/** - * A table implementation for a table holding a primary key - *

    - * This type is for JOOQ INTERNAL USE only. Do not reference directly - * - * @author Lukas Eder - */ -public class UpdatableTableImpl extends TableImpl implements UpdatableTable { - - /** - * Generated UID - */ - private static final long serialVersionUID = 8214807990871116060L; - - public UpdatableTableImpl(String name) { - super(name, null, null); - } - - public UpdatableTableImpl(String name, Schema schema) { - super(name, schema, null); - } - - public UpdatableTableImpl(String name, Schema schema, Table aliased) { - super(name, schema, aliased); - } - - /** - * {@inheritDoc} - *

    - * Subclasses should override this method - */ - @Override - public UniqueKey getPrimaryKey() { - return null; - } - - /** - * {@inheritDoc} - *

    - * Subclasses may override this method - */ - @Override - public TableField getRecordVersion() { - return null; - } - - /** - * {@inheritDoc} - *

    - * Subclasses may override this method - */ - @Override - public TableField getRecordTimestamp() { - return null; - } -} diff --git a/jOOQ/src/main/java/org/jooq/impl/Utils.java b/jOOQ/src/main/java/org/jooq/impl/Utils.java index b81bf9c32c..4a92923a01 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Utils.java +++ b/jOOQ/src/main/java/org/jooq/impl/Utils.java @@ -56,7 +56,6 @@ import java.sql.Array; import java.sql.Blob; import java.sql.CallableStatement; import java.sql.Clob; -import java.sql.Connection; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException;