This commit is contained in:
parent
ce1b91b716
commit
2cc51949ea
@ -52,7 +52,6 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import static java.util.Collections.singletonList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -121,8 +120,8 @@ public abstract class AbstractDatabase implements Database {
|
||||
private String[] recordVersionFields;
|
||||
private String[] recordTimestampFields;
|
||||
private String[] syntheticPrimaryKeys;
|
||||
private String[] syntheticIdentities;
|
||||
private String[] overridePrimaryKeys;
|
||||
private String[] syntheticIdentities;
|
||||
private boolean supportsUnsignedTypes;
|
||||
private boolean ignoreProcedureReturnValues;
|
||||
private boolean dateAsTimestamp;
|
||||
@ -690,21 +689,6 @@ public abstract class AbstractDatabase implements Database {
|
||||
return syntheticPrimaryKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSyntheticIdentities(String[] syntheticIdentities) {
|
||||
if (syntheticIdentities.length > 0 && !syntheticIdentities[0].isEmpty()) {
|
||||
this.syntheticIdentities = syntheticIdentities;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isSyntheticIdentity(ColumnDefinition columnDefinition) {
|
||||
if (syntheticIdentities == null) {
|
||||
return false;
|
||||
}
|
||||
return !filterExcludeInclude(singletonList(columnDefinition), null, syntheticIdentities, filters).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverridePrimaryKeys(String[] overridePrimaryKeys) {
|
||||
this.overridePrimaryKeys = overridePrimaryKeys;
|
||||
@ -719,6 +703,19 @@ public abstract class AbstractDatabase implements Database {
|
||||
return overridePrimaryKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSyntheticIdentities(String[] syntheticIdentities) {
|
||||
this.syntheticIdentities = syntheticIdentities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String[] getSyntheticIdentities() {
|
||||
if (syntheticIdentities == null) {
|
||||
syntheticIdentities = new String[0];
|
||||
}
|
||||
return syntheticIdentities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setConfiguredEnumTypes(List<EnumType> configuredEnumTypes) {
|
||||
this.configuredEnumTypes = configuredEnumTypes;
|
||||
|
||||
@ -50,7 +50,6 @@ import java.util.List;
|
||||
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
|
||||
/**
|
||||
* A base implementation for table definitions.
|
||||
@ -61,8 +60,6 @@ public abstract class AbstractTableDefinition
|
||||
extends AbstractElementContainerDefinition<ColumnDefinition>
|
||||
implements TableDefinition {
|
||||
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractTableDefinition.class);
|
||||
|
||||
private List<ParameterDefinition> parameters;
|
||||
private TableDefinition parentTable;
|
||||
private List<TableDefinition> childTables;
|
||||
@ -178,18 +175,4 @@ implements TableDefinition {
|
||||
protected List<ParameterDefinition> getParameters0() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected ColumnDefinition applySyntheticIdentities(ColumnDefinition columnDefinition) {
|
||||
if (!columnDefinition.isIdentity() && getDatabase().isSyntheticIdentity(columnDefinition)) {
|
||||
log.info("Synthetic Identity: " + columnDefinition.getQualifiedName());
|
||||
return new DefaultColumnDefinition(
|
||||
columnDefinition.getContainer(),
|
||||
columnDefinition.getName(),
|
||||
columnDefinition.getPosition(),
|
||||
columnDefinition.getType(),
|
||||
true,
|
||||
columnDefinition.getComment());
|
||||
}
|
||||
return columnDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,18 +424,6 @@ public interface Database {
|
||||
*/
|
||||
String[] getSyntheticPrimaryKeys();
|
||||
|
||||
/**
|
||||
* Columns matching these regular expressions will be considered as identity
|
||||
* columns in generated code.
|
||||
*/
|
||||
void setSyntheticIdentities(String[] syntheticIdentityPattern);
|
||||
|
||||
/**
|
||||
* Returns true if the given column is considered a synthetic identity column
|
||||
* as defined by the pattern(s) passed to setSyntheticIdentities [#5360]
|
||||
*/
|
||||
boolean isSyntheticIdentity(ColumnDefinition columnDefinition);
|
||||
|
||||
/**
|
||||
* Unique keys matching these regular expressions will be considered as
|
||||
* primary keys in generated code.
|
||||
@ -448,6 +436,18 @@ public interface Database {
|
||||
*/
|
||||
String[] getOverridePrimaryKeys();
|
||||
|
||||
/**
|
||||
* Columns matching these regular expressions will be considered as identity
|
||||
* columns in generated code.
|
||||
*/
|
||||
void setSyntheticIdentities(String[] syntheticIdentities);
|
||||
|
||||
/**
|
||||
* Columns matching these regular expressions will be considered as identity
|
||||
* columns in generated code.
|
||||
*/
|
||||
String[] getSyntheticIdentities();
|
||||
|
||||
/**
|
||||
* Database objects matching any of these field names will be generated as
|
||||
* custom types.
|
||||
|
||||
@ -41,6 +41,8 @@
|
||||
|
||||
package org.jooq.util;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -61,7 +63,13 @@ public class DefaultColumnDefinition
|
||||
super(table, name, position, type, comment);
|
||||
|
||||
this.position = position;
|
||||
this.isIdentity = isIdentity;
|
||||
this.isIdentity = isIdentity || isSyntheticIdentity(this);
|
||||
}
|
||||
|
||||
private static boolean isSyntheticIdentity(DefaultColumnDefinition column) {
|
||||
AbstractDatabase db = (AbstractDatabase) column.getDatabase();
|
||||
String[] syntheticIdentities = db.getSyntheticIdentities();
|
||||
return !db.filterExcludeInclude(singletonList(column), null, syntheticIdentities, db.getFilters()).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -110,7 +110,7 @@ public class CUBRIDTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -110,7 +110,7 @@ public class DerbyTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -112,7 +112,7 @@ public class H2TableDefinition extends AbstractTableDefinition {
|
||||
|| defaultString(record.get(Columns.COLUMN_DEFAULT)).trim().toLowerCase().startsWith("nextval"),
|
||||
record.get(Columns.REMARKS));
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -118,7 +118,7 @@ public class HSQLDBTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -122,7 +122,7 @@ public class MySQLTableDefinition extends AbstractTableDefinition {
|
||||
record.get(Columns.COLUMN_COMMENT)
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -187,7 +187,7 @@ public class PostgresMaterializedViewDefinition extends AbstractTableDefinition
|
||||
record.get(PG_DESCRIPTION.DESCRIPTION)
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -126,7 +126,7 @@ public class PostgresTableDefinition extends AbstractTableDefinition {
|
||||
record.get(PG_DESCRIPTION.DESCRIPTION)
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -198,8 +198,8 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(applySyntheticIdentities(column));
|
||||
result.add(column);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -438,12 +438,6 @@
|
||||
-->
|
||||
<element name="recordTimestampFields" type="string" default="" minOccurs="0" maxOccurs="1" />
|
||||
|
||||
<!--
|
||||
A regular expression matching all columns that represent identities
|
||||
To be used if columns are not detected as automatically as identities
|
||||
-->
|
||||
<element name="syntheticIdentities" type="string" default="" minOccurs="0" maxOccurs="1"/>
|
||||
|
||||
<!--
|
||||
A regular expression matching all columns that participate in "synthetic" primary keys,
|
||||
which should be placed on generated UpdatableRecords, to be used with
|
||||
@ -472,6 +466,12 @@
|
||||
-->
|
||||
<element name="overridePrimaryKeys" type="string" default="" minOccurs="0" maxOccurs="1" />
|
||||
|
||||
<!--
|
||||
A regular expression matching all columns that represent identities
|
||||
To be used if columns are not detected as automatically as identities.
|
||||
-->
|
||||
<element name="syntheticIdentities" type="string" default="" minOccurs="0" maxOccurs="1"/>
|
||||
|
||||
<!--
|
||||
Generate java.sql.Timestamp fields for DATE columns. This is
|
||||
particularly useful for Oracle databases
|
||||
|
||||
Loading…
Reference in New Issue
Block a user