[#5360] Add <syntheticIdentities> regular expression to code generator configuration
This commit is contained in:
parent
1940ed4ff8
commit
453f3f0d73
@ -373,6 +373,7 @@ public class GenerationTool {
|
||||
database.setRecordTimestampFields(new String[] { defaultString(d.getRecordTimestampFields()) });
|
||||
database.setSyntheticPrimaryKeys(new String[] { defaultString(d.getSyntheticPrimaryKeys()) });
|
||||
database.setOverridePrimaryKeys(new String[] { defaultString(d.getOverridePrimaryKeys()) });
|
||||
database.setSyntheticIdentities(new String[] { defaultString(d.getSyntheticIdentities()) });
|
||||
database.setConfiguredCustomTypes(d.getCustomTypes());
|
||||
database.setConfiguredEnumTypes(d.getEnumTypes());
|
||||
database.setConfiguredForcedTypes(d.getForcedTypes());
|
||||
|
||||
@ -52,6 +52,7 @@ 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;
|
||||
@ -120,6 +121,7 @@ public abstract class AbstractDatabase implements Database {
|
||||
private String[] recordVersionFields;
|
||||
private String[] recordTimestampFields;
|
||||
private String[] syntheticPrimaryKeys;
|
||||
private String[] syntheticIdentities;
|
||||
private String[] overridePrimaryKeys;
|
||||
private boolean supportsUnsignedTypes;
|
||||
private boolean ignoreProcedureReturnValues;
|
||||
@ -688,6 +690,21 @@ 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;
|
||||
|
||||
@ -50,6 +50,7 @@ import java.util.List;
|
||||
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
|
||||
/**
|
||||
* A base implementation for table definitions.
|
||||
@ -60,6 +61,8 @@ 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;
|
||||
@ -175,4 +178,18 @@ 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,6 +424,18 @@ 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.
|
||||
|
||||
@ -110,7 +110,7 @@ public class CUBRIDTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -110,7 +110,7 @@ public class DerbyTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(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(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -118,7 +118,7 @@ public class HSQLDBTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -122,7 +122,7 @@ public class MySQLTableDefinition extends AbstractTableDefinition {
|
||||
record.get(Columns.COLUMN_COMMENT)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -187,7 +187,7 @@ public class PostgresMaterializedViewDefinition extends AbstractTableDefinition
|
||||
record.get(PG_DESCRIPTION.DESCRIPTION)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -126,7 +126,7 @@ public class PostgresTableDefinition extends AbstractTableDefinition {
|
||||
record.get(PG_DESCRIPTION.DESCRIPTION)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -198,8 +198,8 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
}
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(applySyntheticIdentities(column));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -438,6 +438,12 @@
|
||||
-->
|
||||
<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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user