[jOOQ/jOOQ#9627] Add Settings.metaIncludeSystemIndexes
This commit is contained in:
parent
292b179241
commit
07c28ad1d8
@ -230,6 +230,8 @@ public class Settings
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean interpreterDelayForeignKeyDeclarations = false;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean metaIncludeSystemIndexes = false;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean migrationAllowsUndo = false;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean migrationRevertUntracked = false;
|
||||
@ -2044,6 +2046,30 @@ public class Settings
|
||||
this.interpreterDelayForeignKeyDeclarations = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link org.jooq.Meta} implementation that is backed by {@link java.sql.DatabaseMetaData} does not produce system generated indexes on constraints, by default.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public Boolean isMetaIncludeSystemIndexes() {
|
||||
return metaIncludeSystemIndexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the metaIncludeSystemIndexes property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public void setMetaIncludeSystemIndexes(Boolean value) {
|
||||
this.metaIncludeSystemIndexes = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether migrations are allowed to be executed in inverse order.<p><strong>This is a potentially destructive feature, which should not be turned on in production</strong>. It is useful mostly to quickly switch between branches in a development environment. This feature is available only in commercial distributions.
|
||||
*
|
||||
@ -3070,6 +3096,11 @@ public class Settings
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withMetaIncludeSystemIndexes(Boolean value) {
|
||||
setMetaIncludeSystemIndexes(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withMigrationAllowsUndo(Boolean value) {
|
||||
setMigrationAllowsUndo(value);
|
||||
return this;
|
||||
@ -3341,6 +3372,7 @@ public class Settings
|
||||
builder.append("interpreterNameLookupCaseSensitivity", interpreterNameLookupCaseSensitivity);
|
||||
builder.append("interpreterLocale", interpreterLocale);
|
||||
builder.append("interpreterDelayForeignKeyDeclarations", interpreterDelayForeignKeyDeclarations);
|
||||
builder.append("metaIncludeSystemIndexes", metaIncludeSystemIndexes);
|
||||
builder.append("migrationAllowsUndo", migrationAllowsUndo);
|
||||
builder.append("migrationRevertUntracked", migrationRevertUntracked);
|
||||
builder.append("migrationAutoBaseline", migrationAutoBaseline);
|
||||
@ -4103,6 +4135,15 @@ public class Settings
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (metaIncludeSystemIndexes == null) {
|
||||
if (other.metaIncludeSystemIndexes!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!metaIncludeSystemIndexes.equals(other.metaIncludeSystemIndexes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (migrationAllowsUndo == null) {
|
||||
if (other.migrationAllowsUndo!= null) {
|
||||
return false;
|
||||
@ -4379,6 +4420,7 @@ public class Settings
|
||||
result = ((prime*result)+((interpreterNameLookupCaseSensitivity == null)? 0 :interpreterNameLookupCaseSensitivity.hashCode()));
|
||||
result = ((prime*result)+((interpreterLocale == null)? 0 :interpreterLocale.hashCode()));
|
||||
result = ((prime*result)+((interpreterDelayForeignKeyDeclarations == null)? 0 :interpreterDelayForeignKeyDeclarations.hashCode()));
|
||||
result = ((prime*result)+((metaIncludeSystemIndexes == null)? 0 :metaIncludeSystemIndexes.hashCode()));
|
||||
result = ((prime*result)+((migrationAllowsUndo == null)? 0 :migrationAllowsUndo.hashCode()));
|
||||
result = ((prime*result)+((migrationRevertUntracked == null)? 0 :migrationRevertUntracked.hashCode()));
|
||||
result = ((prime*result)+((migrationAutoBaseline == null)? 0 :migrationAutoBaseline.hashCode()));
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
@ -65,6 +66,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -566,7 +568,7 @@ final class MetaImpl extends AbstractMeta {
|
||||
@Override
|
||||
public final List<Index> getIndexes() {
|
||||
final String schema = getSchema() == null ? null : getSchema().getName();
|
||||
Result<Record> result = meta(new MetaFunction() {
|
||||
Result<Record> result = removeSystemIndexes(meta(new MetaFunction() {
|
||||
@Override
|
||||
public Result<Record> run(DatabaseMetaData meta) throws SQLException {
|
||||
ResultSet rs;
|
||||
@ -601,13 +603,40 @@ final class MetaImpl extends AbstractMeta {
|
||||
String.class // FILTER_CONDITION
|
||||
);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Sort by INDEX_NAME (5), ORDINAL_POSITION (7)
|
||||
result.sortAsc(7).sortAsc(5);
|
||||
return createIndexes(result);
|
||||
}
|
||||
|
||||
private final Result<Record> removeSystemIndexes(Result<Record> result) {
|
||||
if (TRUE.equals(settings().isMetaIncludeSystemIndexes()))
|
||||
return result;
|
||||
|
||||
// [#8655] [#9627] TODO Re-use more precise, dialect-specific logic from jOOQ-meta's Database::getIncludeSystemReferences
|
||||
Set<String> constraints = new HashSet<>();
|
||||
for (UniqueKey<?> key : getKeys())
|
||||
constraints.add(key.getName());
|
||||
for (ForeignKey<?, ?> key : getReferences())
|
||||
constraints.add(key.getName());
|
||||
|
||||
Iterator<Record> it = result.iterator();
|
||||
while (it.hasNext()) {
|
||||
String indexName = it.next().get(5, String.class);
|
||||
|
||||
// It's generally a good heuristic to assume an index that shares the name of the constraint is system generated
|
||||
if (constraints.contains(indexName))
|
||||
it.remove();
|
||||
|
||||
// In H2, system indexes are called PRIMARY_KEY_xx_y
|
||||
else if (family() == H2 && indexName.startsWith("PRIMARY_KEY_"))
|
||||
it.remove();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<UniqueKey<Record>> getKeys() {
|
||||
UniqueKey<Record> pk = getPrimaryKey();
|
||||
@ -870,7 +899,9 @@ final class MetaImpl extends AbstractMeta {
|
||||
DataType type = null;
|
||||
try {
|
||||
type = DefaultDataType.getDataType(family(), typeName, precision, scale);
|
||||
type = type.getSQLDataType();
|
||||
|
||||
if (type.getSQLDataType() != null)
|
||||
type = type.getSQLDataType();
|
||||
|
||||
// JDBC doesn't distinguish between precision and length
|
||||
if (type.hasPrecision() && type.hasScale())
|
||||
|
||||
@ -501,6 +501,10 @@ jOOQ queries, for which no specific fetchSize value was specified.]]></jxb:javad
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Using this flag, the interpreter will be able to delay the addition of foreign key declarations until the end of the interpretation run.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="metaIncludeSystemIndexes" type="boolean" minOccurs="0" maxOccurs="1" default="false">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The {@link org.jooq.Meta} implementation that is backed by {@link java.sql.DatabaseMetaData} does not produce system generated indexes on constraints, by default.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="migrationSchemata" type="jooq-runtime:MigrationSchemata" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The database objects that are included in the migration.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user