[jOOQ/jOOQ#10588] Deprecate <syntheticIdentities/>

This commit is contained in:
Lukas Eder 2020-09-04 10:50:00 +02:00
parent 19ce35ce7b
commit 7d53551114
3 changed files with 64 additions and 26 deletions

View File

@ -162,7 +162,6 @@ public abstract class AbstractDatabase implements Database {
private boolean forceIntegerTypesOnZeroScaleDecimals = true;
private String[] recordVersionFields;
private String[] recordTimestampFields;
private String[] syntheticIdentities;
private boolean embeddablePrimaryKeys = false;
private boolean embeddableUniqueKeys = false;
private boolean embeddableDomains = false;
@ -1173,9 +1172,8 @@ public abstract class AbstractDatabase implements Database {
@Override
public String[] getRecordVersionFields() {
if (recordVersionFields == null) {
if (recordVersionFields == null)
recordVersionFields = new String[0];
}
return recordVersionFields;
}
@ -1187,24 +1185,27 @@ public abstract class AbstractDatabase implements Database {
@Override
public String[] getRecordTimestampFields() {
if (recordTimestampFields == null) {
if (recordTimestampFields == null)
recordTimestampFields = new String[0];
}
return recordTimestampFields;
}
@Override
@Deprecated
public void setSyntheticPrimaryKeys(String[] syntheticPrimaryKeys) {
if (syntheticPrimaryKeys != null) {
for (String syntheticPrimaryKey : syntheticPrimaryKeys) {
log.warn("DEPRECATION", "The <syntheticPrimaryKeys/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
getConfiguredSyntheticPrimaryKeys().add(new SyntheticPrimaryKeyType().withKeyFields(syntheticPrimaryKey));
if (!StringUtils.isBlank(syntheticPrimaryKey)) {
log.warn("DEPRECATION", "The <syntheticPrimaryKeys/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
getConfiguredSyntheticPrimaryKeys().add(new SyntheticPrimaryKeyType().withKeyFields(syntheticPrimaryKey));
}
}
}
}
@Override
@Deprecated
public String[] getSyntheticPrimaryKeys() {
log.warn("DEPRECATION", "The <syntheticPrimaryKeys/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
return new String[0];
@ -1215,29 +1216,39 @@ public abstract class AbstractDatabase implements Database {
public void setOverridePrimaryKeys(String[] overridePrimaryKeys) {
if (overridePrimaryKeys != null) {
for (String overridePrimaryKey : overridePrimaryKeys) {
log.warn("DEPRECATION", "The <overridePrimaryKeys/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
getConfiguredSyntheticPrimaryKeys().add(new SyntheticPrimaryKeyType().withKey(overridePrimaryKey));
if (!StringUtils.isBlank(overridePrimaryKey)) {
log.warn("DEPRECATION", "The <overridePrimaryKeys/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
getConfiguredSyntheticPrimaryKeys().add(new SyntheticPrimaryKeyType().withKey(overridePrimaryKey));
}
}
}
}
@Override
@Deprecated
public String[] getOverridePrimaryKeys() {
log.warn("DEPRECATION", "The <overridePrimaryKeys/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
return new String[0];
}
@Override
@Deprecated
public void setSyntheticIdentities(String[] syntheticIdentities) {
this.syntheticIdentities = syntheticIdentities;
if (syntheticIdentities != null) {
for (String syntheticIdentity : syntheticIdentities) {
if (!StringUtils.isBlank(syntheticIdentity)) {
log.warn("DEPRECATION", "The <syntheticIdentities/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
getConfiguredSyntheticIdentities().add(new SyntheticIdentityType().withKeyFields(syntheticIdentity));
}
}
}
}
@Override
@Deprecated
public final String[] getSyntheticIdentities() {
if (syntheticIdentities == null)
syntheticIdentities = new String[0];
return syntheticIdentities;
log.warn("DEPRECATION", "The <syntheticIdentities/> configuration element has been deprecated in jOOQ 3.14. Use <syntheticKeys/> only, instead.");
return new String[0];
}
@Override
@ -2588,8 +2599,12 @@ public abstract class AbstractDatabase implements Database {
return Collections.unmodifiableList(all);
}
protected final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions, String e, String i, List<Filter> f) {
return filterExcludeInclude(definitions, new String[] { e }, new String[] { i }, f);
protected final <T extends Definition> List<T> filter(List<T> definitions, String include) {
return filterExcludeInclude(definitions, null, include);
}
protected final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions, String e, String i) {
return filterExcludeInclude(definitions, new String[] { e }, new String[] { i != null ? i : ".*" }, Collections.emptyList());
}
protected final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions, String[] e, String[] i, List<Filter> f) {
@ -2859,8 +2874,8 @@ public abstract class AbstractDatabase implements Database {
if (key.getKey() == null)
continue keyLoop;
for (TableDefinition table : filterExcludeInclude(getTables(), null, key.getKeyTables() != null ? key.getKeyTables() : ".*", Collections.emptyList())) {
for (UniqueKeyDefinition uk : filterExcludeInclude(table.getUniqueKeys(), null, key.getKey(), Collections.emptyList())) {
for (TableDefinition table : filter(getTables(), key.getKeyTables())) {
for (UniqueKeyDefinition uk : filter(table.getUniqueKeys(), key.getKey())) {
log.info("Overriding primary key", "" + uk);
r.overridePrimaryKey(uk);
markUsed(key);
@ -2876,10 +2891,10 @@ public abstract class AbstractDatabase implements Database {
if (key.getKey() != null)
continue keyLoop;
for (TableDefinition table : filterExcludeInclude(getTables(), null, key.getKeyTables() != null ? key.getKeyTables() : ".*", Collections.emptyList())) {
for (TableDefinition table : filter(getTables(), key.getKeyTables())) {
String keyName = key.getName() != null ? key.getName() : "SYNTHETIC_PK_" + table.getName();
List<ColumnDefinition> columns = filterExcludeInclude(table.getColumns(), null, key.getKeyFields(), Collections.emptyList());
List<ColumnDefinition> columns = filter(table.getColumns(), key.getKeyFields());
if (!columns.isEmpty()) {
markUsed(key);
@ -2945,7 +2960,6 @@ public abstract class AbstractDatabase implements Database {
@Override

View File

@ -752,13 +752,22 @@ public interface Database extends AutoCloseable {
/**
* Columns matching these regular expressions will be considered as members
* of synthetic primary keys in generated code.
*
* @deprecated - 3.14.0 - [#10588] - Use
* {@link #setConfiguredSyntheticKeys(SyntheticKeysType)}
* instead.
*/
@Deprecated
void setSyntheticPrimaryKeys(String[] primaryKeys);
/**
* Columns matching these regular expressions will be considered as members
* of synthetic primary keys in generated code.
*
* @deprecated - 3.14.0 - [#10588] - Use
* {@link #getConfiguredSyntheticPrimaryKeys()} instead.
*/
@Deprecated
String[] getSyntheticPrimaryKeys();
/**
@ -785,13 +794,22 @@ public interface Database extends AutoCloseable {
/**
* Columns matching these regular expressions will be considered as identity
* columns in generated code.
*
* @deprecated - 3.14.0 - [#10588] - Use
* {@link #setConfiguredSyntheticKeys(SyntheticKeysType)}
* instead.
*/
@Deprecated
void setSyntheticIdentities(String[] syntheticIdentities);
/**
* Columns matching these regular expressions will be considered as identity
* columns in generated code.
*
* @deprecated - 3.14.0 - [#10588] - Use
* {@link #getConfiguredSyntheticIdentities()} instead.
*/
@Deprecated
String[] getSyntheticIdentities();
/**

View File

@ -43,6 +43,7 @@ import static java.util.Collections.singletonList;
import java.util.ArrayList;
import java.util.List;
import org.jooq.meta.jaxb.SyntheticIdentityType;
import org.jooq.tools.JooqLogger;
/**
@ -72,15 +73,20 @@ public class DefaultColumnDefinition
((DefaultDataTypeDefinition) type).identity(this.isIdentity);
}
@SuppressWarnings("unused")
private static boolean isSyntheticIdentity(DefaultColumnDefinition column) {
AbstractDatabase db = (AbstractDatabase) column.getDatabase();
String[] syntheticIdentities = db.getSyntheticIdentities();
boolean match = !db.filterExcludeInclude(singletonList(column), null, syntheticIdentities, db.getFilters()).isEmpty();
if (match)
log.info("Synthetic Identity: " + column.getQualifiedName());
for (SyntheticIdentityType id : db.getConfiguredSyntheticIdentities()) {
for (TableDefinition t : db.filter(singletonList(column.getContainer()), id.getKeyTables())) {
for (ColumnDefinition c : db.filter(singletonList(column), id.getKeyFields())) {
log.info("Synthetic identity", column.getQualifiedName());
return true;
}
}
}
return match;
return false;
}
@Override