[jOOQ/jOOQ#9601] Add <includeSystemIndexes/>

This commit is contained in:
Lukas Eder 2019-12-03 09:39:00 +01:00
parent 8e1cfbcb4b
commit 53f7cc0c79
10 changed files with 98 additions and 0 deletions

View File

@ -514,6 +514,7 @@ public class GenerationTool {
database.setIncludePackageConstants(!FALSE.equals(d.isIncludePackageConstants()));
database.setIncludeIndexes(!FALSE.equals(d.isIncludeIndexes()));
database.setIncludeCheckConstraints(!FALSE.equals(d.isIncludeCheckConstraints()));
database.setIncludeSystemIndexes(TRUE.equals(d.isIncludeSystemIndexes()));
database.setIncludeSystemCheckConstraints(TRUE.equals(d.isIncludeSystemCheckConstraints()));
database.setIncludeInvisibleColumns(!FALSE.equals(d.isIncludeInvisibleColumns()));
database.setIncludePrimaryKeys(!FALSE.equals(d.isIncludePrimaryKeys()));

View File

@ -136,6 +136,7 @@ public abstract class AbstractDatabase implements Database {
private boolean includeSequences = true;
private boolean includeIndexes = true;
private boolean includeCheckConstraints = true;
private boolean includeSystemIndexes = false;
private boolean includeSystemCheckConstraints = false;
private boolean includePrimaryKeys = true;
private boolean includeUniqueKeys = true;
@ -1000,6 +1001,16 @@ public abstract class AbstractDatabase implements Database {
return includeCheckConstraints;
}
@Override
public final void setIncludeSystemIndexes(boolean includeSystemIndexes) {
this.includeSystemIndexes = includeSystemIndexes;
}
@Override
public final boolean getIncludeSystemIndexes() {
return includeSystemIndexes;
}
@Override
public final void setIncludeSystemCheckConstraints(boolean includeSystemCheckConstraints) {
this.includeSystemCheckConstraints = includeSystemCheckConstraints;

View File

@ -438,6 +438,16 @@ public interface Database extends AutoCloseable {
*/
boolean getIncludeCheckConstraints();
/**
* whether system generated indexes should be included.
*/
void setIncludeSystemIndexes(boolean systemIndexes);
/**
* whether system generated indexes should be included.
*/
boolean getIncludeSystemIndexes();
/**
* whether system generated check constraints should be included.
*/

View File

@ -37,10 +37,13 @@
*/
package org.jooq.meta.h2;
import static org.jooq.impl.DSL.condition;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.not;
import static org.jooq.impl.DSL.nullif;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.select;
@ -146,6 +149,9 @@ public class H2Database extends AbstractDatabase {
Indexes.ASC_OR_DESC)
.from(INDEXES)
.where(Indexes.TABLE_SCHEMA.in(getInputSchemata()))
.and(getIncludeSystemIndexes()
? noCondition()
: not(condition(Indexes.IS_GENERATED)))
.orderBy(
Indexes.TABLE_SCHEMA,
Indexes.TABLE_NAME,

View File

@ -123,6 +123,9 @@ public class HSQLDBDatabase extends AbstractDatabase {
SYSTEM_INDEXINFO.ASC_OR_DESC)
.from(SYSTEM_INDEXINFO)
.where(SYSTEM_INDEXINFO.TABLE_SCHEM.in(getInputSchemata()))
.and(getIncludeSystemIndexes()
? noCondition()
: SYSTEM_INDEXINFO.INDEX_NAME.notLike("SYS!_IDX!_%", '!'))
.orderBy(
SYSTEM_INDEXINFO.TABLE_SCHEM,
SYSTEM_INDEXINFO.TABLE_NAME,

View File

@ -82,6 +82,8 @@ public class Database implements Serializable, XMLAppendable
@XmlElement(defaultValue = "true")
protected Boolean includeCheckConstraints = true;
@XmlElement(defaultValue = "false")
protected Boolean includeSystemIndexes = false;
@XmlElement(defaultValue = "false")
protected Boolean includeSystemCheckConstraints = false;
@XmlElement(defaultValue = "true")
protected Boolean includeInvisibleColumns = true;
@ -779,6 +781,30 @@ public class Database implements Serializable, XMLAppendable
this.includeCheckConstraints = value;
}
/**
* This flag indicates whether system generated indexes should be included in output produced by this database
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isIncludeSystemIndexes() {
return includeSystemIndexes;
}
/**
* Sets the value of the includeSystemIndexes property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setIncludeSystemIndexes(Boolean value) {
this.includeSystemIndexes = value;
}
/**
* This flag indicates whether system generated check constraints should be included in output produced by this database
*
@ -1733,6 +1759,11 @@ public class Database implements Serializable, XMLAppendable
return this;
}
public Database withIncludeSystemIndexes(Boolean value) {
setIncludeSystemIndexes(value);
return this;
}
public Database withIncludeSystemCheckConstraints(Boolean value) {
setIncludeSystemCheckConstraints(value);
return this;
@ -2163,6 +2194,7 @@ public class Database implements Serializable, XMLAppendable
builder.append("includeUniqueKeys", includeUniqueKeys);
builder.append("includeForeignKeys", includeForeignKeys);
builder.append("includeCheckConstraints", includeCheckConstraints);
builder.append("includeSystemIndexes", includeSystemIndexes);
builder.append("includeSystemCheckConstraints", includeSystemCheckConstraints);
builder.append("includeInvisibleColumns", includeInvisibleColumns);
builder.append("recordVersionFields", recordVersionFields);
@ -2413,6 +2445,15 @@ public class Database implements Serializable, XMLAppendable
return false;
}
}
if (includeSystemIndexes == null) {
if (other.includeSystemIndexes!= null) {
return false;
}
} else {
if (!includeSystemIndexes.equals(other.includeSystemIndexes)) {
return false;
}
}
if (includeSystemCheckConstraints == null) {
if (other.includeSystemCheckConstraints!= null) {
return false;
@ -2721,6 +2762,7 @@ public class Database implements Serializable, XMLAppendable
result = ((prime*result)+((includeUniqueKeys == null)? 0 :includeUniqueKeys.hashCode()));
result = ((prime*result)+((includeForeignKeys == null)? 0 :includeForeignKeys.hashCode()));
result = ((prime*result)+((includeCheckConstraints == null)? 0 :includeCheckConstraints.hashCode()));
result = ((prime*result)+((includeSystemIndexes == null)? 0 :includeSystemIndexes.hashCode()));
result = ((prime*result)+((includeSystemCheckConstraints == null)? 0 :includeSystemCheckConstraints.hashCode()));
result = ((prime*result)+((includeInvisibleColumns == null)? 0 :includeInvisibleColumns.hashCode()));
result = ((prime*result)+((recordVersionFields == null)? 0 :recordVersionFields.hashCode()));

View File

@ -40,6 +40,9 @@ package org.jooq.meta.mysql;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
import static org.jooq.meta.mysql.information_schema.Tables.CHECK_CONSTRAINTS;
import static org.jooq.meta.mysql.information_schema.Tables.COLUMNS;
import static org.jooq.meta.mysql.information_schema.Tables.KEY_COLUMN_USAGE;
@ -130,6 +133,13 @@ public class MySQLDatabase extends AbstractDatabase {
getInputSchemata().size() == 1
? Statistics.TABLE_SCHEMA.in(getInputSchemata())
: falseCondition()))
.and(getIncludeSystemIndexes()
? noCondition()
: row(Statistics.INDEX_SCHEMA, Statistics.INDEX_NAME).notIn(
select(TableConstraints.CONSTRAINT_SCHEMA, TableConstraints.CONSTRAINT_NAME)
.from(TABLE_CONSTRAINTS)
)
)
.orderBy(
Statistics.TABLE_SCHEMA,
Statistics.TABLE_NAME,

View File

@ -191,6 +191,12 @@ public class PostgresDatabase extends AbstractDatabase {
.join(trel).on(oid(trel).eq(i.INDRELID))
.join(tnsp).on(oid(tnsp).eq(trel.RELNAMESPACE))
.where(tnsp.NSPNAME.in(getInputSchemata()))
.and(getIncludeSystemIndexes()
? noCondition()
: row(tnsp.NSPNAME, irel.RELNAME).notIn(
select(TABLE_CONSTRAINTS.CONSTRAINT_SCHEMA, TABLE_CONSTRAINTS.CONSTRAINT_NAME)
.from(TABLE_CONSTRAINTS)
))
.orderBy(1, 2, 3)) {
final SchemaDefinition tableSchema = getSchema(record.get(tnsp.NSPNAME));

View File

@ -39,8 +39,10 @@ package org.jooq.meta.sqlite;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.meta.sqlite.sqlite_master.SQLiteMaster.SQLITE_MASTER;
import java.sql.SQLException;
@ -122,6 +124,9 @@ public class SQLiteDatabase extends AbstractDatabase {
table("pragma_index_list({0})", SQLiteMaster.NAME).as("il"),
table("pragma_index_info(il.name)").as("ii"))
.where(SQLiteMaster.TYPE.eq(inline("table")))
.and(getIncludeSystemIndexes()
? noCondition()
: field("il.origin", VARCHAR).notIn(inline("pk"), inline("u")))
.orderBy(1, 2, 4)
.fetchGroups(
new Field[] {

View File

@ -559,6 +559,10 @@ Excludes match before includes, i.e. excludes have a higher priority.]]></jxb:ja
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This flag indicates whether check constraints should be included in output produced by this database]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="includeSystemIndexes" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This flag indicates whether system generated indexes should be included in output produced by this database]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="includeSystemCheckConstraints" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This flag indicates whether system generated check constraints should be included in output produced by this database]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>