[#2328] Remove UpdatableTable marker interface, pulling up methods
to Table
This commit is contained in:
parent
e7b46589a1
commit
8e8915c008
@ -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()) ||
|
||||
|
||||
@ -9059,7 +9059,7 @@ create.insertInto(com.example.generated.Tables.MY_TABLE)
|
||||
Every table in your database will generate a <reference class="org.jooq.Table"/> implementation that looks like this:
|
||||
</p>
|
||||
|
||||
<java><![CDATA[public class Book extends UpdatableTableImpl<BookRecord> {
|
||||
<java><![CDATA[public class Book extends TableImpl<BookRecord> {
|
||||
|
||||
// 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:
|
||||
</p>
|
||||
|
||||
<java><![CDATA[public class TAuthor extends UpdatableTableImpl<TAuthorRecord> {
|
||||
<java><![CDATA[public class TAuthor extends TableImpl<TAuthorRecord> {
|
||||
|
||||
// [...]
|
||||
public final TableField<TAuthorRecord, GregorianCalendar> DATE_OF_BIRTH = // [...]
|
||||
@ -10297,7 +10297,8 @@ Condition condition3 = BOOK.TITLE.isNotDistinctFrom(possiblyNull);]]></java>
|
||||
<li>The code generation configuration can no longer be loaded from .properties files. Only XML configurations are supported.</li>
|
||||
<li>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.</li>
|
||||
<li>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</li>
|
||||
<li>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.</li>
|
||||
<li>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.</li>
|
||||
<li>The UpdatableTable type has been removed. While adding significant complexity to the type hierarchy, this type adds not much value over a simple <code>Table.getPrimaryKey() != null</code> check.</li>
|
||||
</ul>
|
||||
</content>
|
||||
</section>
|
||||
|
||||
@ -76,8 +76,8 @@ public interface InsertOnDuplicateStep<R extends Record> extends InsertFinalStep
|
||||
* simulate this clause using a <code>MERGE</code> statement on some other
|
||||
* databases. The conditions for a RDBMS to simulate this clause are:
|
||||
* <ul>
|
||||
* <li>The <code>INSERT</code> statement's table is an
|
||||
* {@link UpdatableTable}</li>
|
||||
* <li>The <code>INSERT</code> statement's table is a
|
||||
* {@link Table} with a {@link Table#getPrimaryKey()}</li>
|
||||
* <li>The RDBMS supports the <code>MERGE</code> clause (see
|
||||
* {@link Executor#mergeInto(Table)}).</li>
|
||||
* </ul>
|
||||
|
||||
@ -166,13 +166,70 @@ public interface Table<R extends Record> extends TableLike<R> {
|
||||
* <code>null</code>, if no such information is available.
|
||||
*/
|
||||
Identity<R, ? extends Number> getIdentity();
|
||||
/**
|
||||
* Retrieve the table's primary key
|
||||
*
|
||||
* @return The primary key. This is never <code>null</code> for an updatable
|
||||
* table.
|
||||
*/
|
||||
UniqueKey<R> getPrimaryKey();
|
||||
|
||||
/**
|
||||
* A "version" field holding record version information used for optimistic
|
||||
* locking
|
||||
* <p>
|
||||
* 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 <code>UPDATE</code> or
|
||||
* <code>DELETE</code> statement if tables provide a "version" or
|
||||
* "timestamp" field, or in two steps using an additional
|
||||
* <code>SELECT .. FOR UPDATE</code> statement otherwise.
|
||||
* <p>
|
||||
* 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 <code>null</code>, if this table has no
|
||||
* "version" field.
|
||||
* @see #getRecordTimestamp()
|
||||
* @see UpdatableRecord#store()
|
||||
* @see UpdatableRecord#delete()
|
||||
* @see Settings#isExecuteWithOptimisticLocking()
|
||||
*/
|
||||
TableField<R, ? extends Number> getRecordVersion();
|
||||
|
||||
/**
|
||||
* A "timestamp" field holding record timestamp information used for
|
||||
* optimistic locking
|
||||
* <p>
|
||||
* 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 <code>UPDATE</code> or
|
||||
* <code>DELETE</code> statement if tables provide a "version" or
|
||||
* "timestamp" field, or in two steps using an additional
|
||||
* <code>SELECT .. FOR UPDATE</code> statement otherwise.
|
||||
* <p>
|
||||
* 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 <code>null</code>, if this table has no
|
||||
* "timestamp" field.
|
||||
* @see #getRecordVersion()
|
||||
* @see UpdatableRecord#store()
|
||||
* @see UpdatableRecord#delete()
|
||||
* @see Settings#isExecuteWithOptimisticLocking()
|
||||
*/
|
||||
TableField<R, ? extends java.util.Date> getRecordTimestamp();
|
||||
|
||||
/**
|
||||
* Retrieve all of the table's unique keys.
|
||||
*
|
||||
* @return All keys. This is never <code>null</code>. 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<UniqueKey<R>> getKeys();
|
||||
|
||||
|
||||
@ -78,13 +78,7 @@ import org.jooq.impl.Executor;
|
||||
public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableRecord<R> {
|
||||
|
||||
/**
|
||||
* The table from which this record was read
|
||||
*/
|
||||
@Override
|
||||
UpdatableTable<R> getTable();
|
||||
|
||||
/**
|
||||
* A view holding values for the {@link UpdatableTable#getPrimaryKey()}
|
||||
* A view holding values for the {@link Table#getPrimaryKey()}
|
||||
* <p>
|
||||
* 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<R extends UpdatableRecord<R>> 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 <code>INSERT</code> or <code>UPDATE</code> 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<R extends UpdatableRecord<R>> extends TableReco
|
||||
* <p>
|
||||
* 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
|
||||
* <code>WHERE</code> clause of the executed <code>DELETE</code> statement.</li>
|
||||
* <li><strong>Without any specific column configurations</strong>
|
||||
@ -266,8 +260,8 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
|
||||
* <p>
|
||||
* 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
|
||||
* <code>WHERE</code> clause of the executed <code>DELETE</code> statement.</li>
|
||||
* <li><strong>Without any specific column configurations</strong>
|
||||
|
||||
@ -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 <R> The record type of the table
|
||||
* @see UpdatableRecord
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface UpdatableTable<R extends Record> extends Table<R> {
|
||||
|
||||
/**
|
||||
* Retrieve the table's primary key
|
||||
*
|
||||
* @return The primary key. This is never <code>null</code> for an updatable
|
||||
* table.
|
||||
*/
|
||||
UniqueKey<R> getPrimaryKey();
|
||||
|
||||
/**
|
||||
* A "version" field holding record version information used for optimistic
|
||||
* locking
|
||||
* <p>
|
||||
* 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 <code>UPDATE</code> or
|
||||
* <code>DELETE</code> statement if tables provide a "version" or
|
||||
* "timestamp" field, or in two steps using an additional
|
||||
* <code>SELECT .. FOR UPDATE</code> statement otherwise.
|
||||
* <p>
|
||||
* 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 <code>null</code>, if this table has no
|
||||
* "version" field.
|
||||
* @see #getRecordTimestamp()
|
||||
* @see UpdatableRecord#store()
|
||||
* @see UpdatableRecord#delete()
|
||||
* @see Settings#isExecuteWithOptimisticLocking()
|
||||
*/
|
||||
TableField<R, ? extends Number> getRecordVersion();
|
||||
|
||||
/**
|
||||
* A "timestamp" field holding record timestamp information used for
|
||||
* optimistic locking
|
||||
* <p>
|
||||
* 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 <code>UPDATE</code> or
|
||||
* <code>DELETE</code> statement if tables provide a "version" or
|
||||
* "timestamp" field, or in two steps using an additional
|
||||
* <code>SELECT .. FOR UPDATE</code> statement otherwise.
|
||||
* <p>
|
||||
* 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 <code>null</code>, if this table has no
|
||||
* "timestamp" field.
|
||||
* @see #getRecordVersion()
|
||||
* @see UpdatableRecord#store()
|
||||
* @see UpdatableRecord#delete()
|
||||
* @see Settings#isExecuteWithOptimisticLocking()
|
||||
*/
|
||||
TableField<R, ? extends java.util.Date> getRecordTimestamp();
|
||||
|
||||
}
|
||||
@ -163,6 +163,36 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Subclasses may override this method
|
||||
*/
|
||||
@Override
|
||||
public UniqueKey<R> getPrimaryKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Subclasses may override this method
|
||||
*/
|
||||
@Override
|
||||
public TableField<R, ? extends Number> getRecordVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Subclasses may override this method
|
||||
*/
|
||||
@Override
|
||||
public TableField<R, ? extends java.util.Date> getRecordTimestamp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
|
||||
@ -70,13 +70,4 @@ public abstract class CustomRecord<R extends TableRecord<R>> extends TableRecord
|
||||
protected CustomRecord(Table<R> table) {
|
||||
super(table);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// No further overrides allowed
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Table<R> getTable() {
|
||||
return super.getTable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<R extends UpdatableRecord<R>, 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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<R extends Record> extends AbstractStoreQuery<R> implements
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final Merge<R> toMerge(Configuration configuration) {
|
||||
if (getInto() instanceof UpdatableTable) {
|
||||
UpdatableTable<R> into = (UpdatableTable<R>) getInto();
|
||||
Table<R> into = getInto();
|
||||
|
||||
if (into.getPrimaryKey() != null) {
|
||||
Condition condition = null;
|
||||
List<Field<?>> key = new ArrayList<Field<?>>();
|
||||
|
||||
|
||||
@ -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<R extends TableRecord<R>> implements
|
||||
|
||||
// Configuration data
|
||||
// ------------------
|
||||
private final Executor create;
|
||||
private final Executor create;
|
||||
private final Table<R> table;
|
||||
private final UpdatableTable<R> 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<R extends TableRecord<R>> implements
|
||||
this.create = create;
|
||||
this.table = table;
|
||||
this.errors = new ArrayList<LoaderError>();
|
||||
|
||||
if (table instanceof UpdatableTable) {
|
||||
this.updatable = (UpdatableTable<R>) table;
|
||||
}
|
||||
else {
|
||||
this.updatable = null;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -150,8 +141,8 @@ class LoaderImpl<R extends TableRecord<R>> implements
|
||||
|
||||
@Override
|
||||
public final LoaderImpl<R> 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<R extends TableRecord<R>> implements
|
||||
|
||||
@Override
|
||||
public final LoaderImpl<R> 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<R extends TableRecord<R>> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Field<?>> onFields = new HashSet<Field<?>>();
|
||||
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++) {
|
||||
|
||||
@ -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<Record> 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<Record> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -4555457095396846609L;
|
||||
|
||||
MetaUpdatableTable(String name, Schema schema, Result<Record> columns) {
|
||||
super(name, schema, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final UniqueKey<Record> getPrimaryKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TableField<Record, ? extends Number> getRecordVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TableField<Record, ? extends Date> getRecordTimestamp() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,11 +62,8 @@ public class TableRecordImpl<R extends TableRecord<R>> extends AbstractRecord im
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/*
|
||||
* Subclasses may override this method
|
||||
*/
|
||||
@Override
|
||||
public Table<R> getTable() {
|
||||
public final Table<R> getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
@ -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<R extends UpdatableRecord<R>> extends TableReco
|
||||
*/
|
||||
private static final long serialVersionUID = -1012420583600561579L;
|
||||
|
||||
public UpdatableRecordImpl(UpdatableTable<R> table) {
|
||||
public UpdatableRecordImpl(Table<R> table) {
|
||||
super(table);
|
||||
}
|
||||
|
||||
@ -105,11 +105,6 @@ public class UpdatableRecordImpl<R extends UpdatableRecord<R>> extends TableReco
|
||||
return key.fetchChildren((R) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final UpdatableTable<R> getTable() {
|
||||
return (UpdatableTable<R>) super.getTable();
|
||||
}
|
||||
|
||||
@Override
|
||||
final UniqueKey<R> getPrimaryKey() {
|
||||
return getTable().getPrimaryKey();
|
||||
@ -423,9 +418,7 @@ public class UpdatableRecordImpl<R extends UpdatableRecord<R>> extends TableReco
|
||||
}
|
||||
|
||||
private final boolean isTimestampOrVersionAvailable() {
|
||||
UpdatableTable<R> table = getTable();
|
||||
|
||||
return table.getRecordTimestamp() != null || table.getRecordVersion() != null;
|
||||
return getTable().getRecordTimestamp() != null || getTable().getRecordVersion() != 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
|
||||
* <p>
|
||||
* This type is for JOOQ INTERNAL USE only. Do not reference directly
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class UpdatableTableImpl<R extends Record> extends TableImpl<R> implements UpdatableTable<R> {
|
||||
|
||||
/**
|
||||
* 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<R> aliased) {
|
||||
super(name, schema, aliased);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Subclasses should override this method
|
||||
*/
|
||||
@Override
|
||||
public UniqueKey<R> getPrimaryKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Subclasses may override this method
|
||||
*/
|
||||
@Override
|
||||
public TableField<R, ? extends Number> getRecordVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Subclasses may override this method
|
||||
*/
|
||||
@Override
|
||||
public TableField<R, ? extends java.util.Date> getRecordTimestamp() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user