[jOOQ/jOOQ#10898] Add Settings.metaIncludeSystemSequences
This commit is contained in:
parent
6d0c56e422
commit
2d66eae6f2
@ -56,7 +56,7 @@ import org.jooq.ResultQuery;
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@Internal
|
||||
public interface ResultQueryDatabase {
|
||||
public interface ResultQueryDatabase extends Database {
|
||||
|
||||
/**
|
||||
* A query that produces primary keys for a set of input schemas.
|
||||
|
||||
@ -637,7 +637,7 @@ public class PostgresDatabase extends AbstractDatabase implements ResultQueryDat
|
||||
select(COLUMNS.TABLE_SCHEMA, COLUMNS.TABLE_NAME.concat(inline("_")).concat(COLUMNS.COLUMN_NAME).concat(inline("_seq")))
|
||||
.from(COLUMNS)
|
||||
.where(COLUMNS.COLUMN_DEFAULT.eq(
|
||||
inline("nextval('").concat(COLUMNS.TABLE_NAME.concat(inline("_")).concat(COLUMNS.COLUMN_NAME).concat(inline("_seq"))).concat(inline("_seq'::regclass)"))
|
||||
inline("nextval('").concat(COLUMNS.TABLE_NAME.concat(inline("_")).concat(COLUMNS.COLUMN_NAME)).concat(inline("_seq'::regclass)"))
|
||||
))
|
||||
)
|
||||
: noCondition())
|
||||
|
||||
@ -232,6 +232,8 @@ public class Settings
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean metaIncludeSystemIndexes = false;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean metaIncludeSystemSequences = false;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean migrationAllowsUndo = false;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean migrationRevertUntracked = false;
|
||||
@ -2070,6 +2072,30 @@ public class Settings
|
||||
this.metaIncludeSystemIndexes = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link org.jooq.Meta} implementation that is backed by {@link java.sql.DatabaseMetaData} does not produce system generated sequences, by default.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public Boolean isMetaIncludeSystemSequences() {
|
||||
return metaIncludeSystemSequences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the metaIncludeSystemSequences property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public void setMetaIncludeSystemSequences(Boolean value) {
|
||||
this.metaIncludeSystemSequences = 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.
|
||||
*
|
||||
@ -3101,6 +3127,11 @@ public class Settings
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withMetaIncludeSystemSequences(Boolean value) {
|
||||
setMetaIncludeSystemSequences(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withMigrationAllowsUndo(Boolean value) {
|
||||
setMigrationAllowsUndo(value);
|
||||
return this;
|
||||
@ -3373,6 +3404,7 @@ public class Settings
|
||||
builder.append("interpreterLocale", interpreterLocale);
|
||||
builder.append("interpreterDelayForeignKeyDeclarations", interpreterDelayForeignKeyDeclarations);
|
||||
builder.append("metaIncludeSystemIndexes", metaIncludeSystemIndexes);
|
||||
builder.append("metaIncludeSystemSequences", metaIncludeSystemSequences);
|
||||
builder.append("migrationAllowsUndo", migrationAllowsUndo);
|
||||
builder.append("migrationRevertUntracked", migrationRevertUntracked);
|
||||
builder.append("migrationAutoBaseline", migrationAutoBaseline);
|
||||
@ -4144,6 +4176,15 @@ public class Settings
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (metaIncludeSystemSequences == null) {
|
||||
if (other.metaIncludeSystemSequences!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!metaIncludeSystemSequences.equals(other.metaIncludeSystemSequences)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (migrationAllowsUndo == null) {
|
||||
if (other.migrationAllowsUndo!= null) {
|
||||
return false;
|
||||
@ -4421,6 +4462,7 @@ public class Settings
|
||||
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)+((metaIncludeSystemSequences == null)? 0 :metaIncludeSystemSequences.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()));
|
||||
|
||||
@ -59,6 +59,7 @@ import static org.jooq.impl.AbstractNamed.findIgnoreCase;
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.MetaSQL.M_SEQUENCES;
|
||||
import static org.jooq.impl.MetaSQL.M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES;
|
||||
import static org.jooq.impl.MetaSQL.M_UNIQUE_KEYS;
|
||||
import static org.jooq.impl.Tools.EMPTY_OBJECT;
|
||||
import static org.jooq.impl.Tools.EMPTY_SORTFIELD;
|
||||
@ -573,7 +574,9 @@ final class MetaImpl extends AbstractMeta {
|
||||
|
||||
private final Result<Record> getSequences0() {
|
||||
if (sequenceCache == null) {
|
||||
final String sql = M_SEQUENCES.get(family());
|
||||
final String sql = TRUE.equals(settings().isMetaIncludeSystemSequences())
|
||||
? M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES.get(family())
|
||||
: M_SEQUENCES.get(family());
|
||||
|
||||
if (sql != null) {
|
||||
Result<Record> result = meta(new MetaFunction() {
|
||||
|
||||
@ -10,6 +10,7 @@ import org.jooq.SQLDialect;
|
||||
final class MetaSQL {
|
||||
static final EnumMap<SQLDialect, String> M_UNIQUE_KEYS = new EnumMap<>(SQLDialect.class);
|
||||
static final EnumMap<SQLDialect, String> M_SEQUENCES = new EnumMap<>(SQLDialect.class);
|
||||
static final EnumMap<SQLDialect, String> M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES = new EnumMap<>(SQLDialect.class);
|
||||
|
||||
static {
|
||||
|
||||
@ -33,7 +34,20 @@ final class MetaSQL {
|
||||
M_SEQUENCES.put(FIREBIRD, "select null catalog, null schema, trim(RDB$GENERATORS.RDB$GENERATOR_NAME) RDB$GENERATOR_NAME, 'BIGINT' type_name, null numeric_precision, null numeric_scale, 0 RDB$INITIAL_VALUE, 1 RDB$GENERATOR_INCREMENT, null min_value, null max_value, null cycle, null cache from RDB$GENERATORS order by RDB$GENERATORS.RDB$GENERATOR_NAME");
|
||||
M_SEQUENCES.put(H2, "select null catalog, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME, 'BIGINT' type_name, null precision, null scale, null start_value, nullif(INFORMATION_SCHEMA.SEQUENCES.INCREMENT, 1) INCREMENT, nullif(INFORMATION_SCHEMA.SEQUENCES.MIN_VALUE, 1) MIN_VALUE, nullif(INFORMATION_SCHEMA.SEQUENCES.MAX_VALUE, 9223372036854775807) MAX_VALUE, INFORMATION_SCHEMA.SEQUENCES.IS_CYCLE, nullif(INFORMATION_SCHEMA.SEQUENCES.CACHE, 32) CACHE from INFORMATION_SCHEMA.SEQUENCES where (INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA in (cast(? as varchar(2147483647))) and upper(INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME) not like 'SYSTEM!_SEQUENCE!_%' escape '!') order by INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME");
|
||||
M_SEQUENCES.put(HSQLDB, "select null as catalog, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME, INFORMATION_SCHEMA.SEQUENCES.DATA_TYPE, INFORMATION_SCHEMA.SEQUENCES.NUMERIC_PRECISION, INFORMATION_SCHEMA.SEQUENCES.NUMERIC_SCALE, INFORMATION_SCHEMA.SEQUENCES.START_WITH, INFORMATION_SCHEMA.SEQUENCES.INCREMENT, INFORMATION_SCHEMA.SEQUENCES.MINIMUM_VALUE, INFORMATION_SCHEMA.SEQUENCES.MAXIMUM_VALUE, case when INFORMATION_SCHEMA.SEQUENCES.CYCLE_OPTION is not distinct from 'YES' then true else false end as CYCLE_OPTION, null as cache from INFORMATION_SCHEMA.SEQUENCES where INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA in (cast(? as varchar(128))) order by INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME");
|
||||
M_SEQUENCES.put(POSTGRES, "select null as catalog, information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name, information_schema.sequences.data_type, information_schema.sequences.numeric_precision, information_schema.sequences.numeric_scale, nullif(cast(information_schema.sequences.start_value as bigint), 1) as start_value, nullif(cast(information_schema.sequences.increment as bigint), 1) as increment, nullif(cast(information_schema.sequences.minimum_value as bigint), 1) as minimum_value, nullif(cast(information_schema.sequences.maximum_value as decimal), (power(cast(2 as decimal), cast((information_schema.sequences.numeric_precision - 1) as decimal)) - 1)) as maximum_value, cast(information_schema.sequences.cycle_option as boolean) as cycle_option, null as cache from information_schema.sequences where (information_schema.sequences.sequence_schema in (?) and (information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name) not in (select information_schema.columns.table_schema, (((information_schema.columns.table_name || '_') || information_schema.columns.column_name) || '_seq') from information_schema.columns where information_schema.columns.column_default = (('nextval(''' || (((information_schema.columns.table_name || '_') || information_schema.columns.column_name) || '_seq')) || '_seq''::regclass)'))) order by information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name");
|
||||
M_SEQUENCES.put(POSTGRES, "select null as catalog, information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name, information_schema.sequences.data_type, information_schema.sequences.numeric_precision, information_schema.sequences.numeric_scale, nullif(cast(information_schema.sequences.start_value as bigint), 1) as start_value, nullif(cast(information_schema.sequences.increment as bigint), 1) as increment, nullif(cast(information_schema.sequences.minimum_value as bigint), 1) as minimum_value, nullif(cast(information_schema.sequences.maximum_value as decimal), (power(cast(2 as decimal), cast((information_schema.sequences.numeric_precision - 1) as decimal)) - 1)) as maximum_value, cast(information_schema.sequences.cycle_option as boolean) as cycle_option, null as cache from information_schema.sequences where (information_schema.sequences.sequence_schema in (?) and (information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name) not in (select information_schema.columns.table_schema, (((information_schema.columns.table_name || '_') || information_schema.columns.column_name) || '_seq') from information_schema.columns where information_schema.columns.column_default = (('nextval(''' || ((information_schema.columns.table_name || '_') || information_schema.columns.column_name)) || '_seq''::regclass)'))) order by information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES.put(DERBY, "select cast(null as varchar(32672)) as catalog, alias_8805161.SCHEMANAME, SYS.SYSSEQUENCES.SEQUENCENAME, SYS.SYSSEQUENCES.SEQUENCEDATATYPE, cast(null as int) as numeric_precision, cast(null as int) as numeric_scale, nullif(SYS.SYSSEQUENCES.STARTVALUE, 1) as STARTVALUE, nullif(SYS.SYSSEQUENCES.INCREMENT, 1) as INCREMENT, nullif(SYS.SYSSEQUENCES.MINIMUMVALUE, case when cast(SYS.SYSSEQUENCES.SEQUENCEDATATYPE as varchar(32672)) = 'SMALLINT' then -32768 when cast(SYS.SYSSEQUENCES.SEQUENCEDATATYPE as varchar(32672)) = 'INTEGER' then -2147483648 when cast(SYS.SYSSEQUENCES.SEQUENCEDATATYPE as varchar(32672)) = 'BIGINT' then -9223372036854775808 end) as MINIMUMVALUE, nullif(SYS.SYSSEQUENCES.MAXIMUMVALUE, case when cast(SYS.SYSSEQUENCES.SEQUENCEDATATYPE as varchar(32672)) = 'SMALLINT' then 32767 when cast(SYS.SYSSEQUENCES.SEQUENCEDATATYPE as varchar(32672)) = 'INTEGER' then 2147483647 when cast(SYS.SYSSEQUENCES.SEQUENCEDATATYPE as varchar(32672)) = 'BIGINT' then 9223372036854775807 end) as MAXIMUMVALUE, SYS.SYSSEQUENCES.CYCLEOPTION, cast(null as bigint) as cache from (SYS.SYSSEQUENCES join SYS.SYSSCHEMAS as alias_8805161 on SYS.SYSSEQUENCES.SCHEMAID = alias_8805161.SCHEMAID) where cast(alias_8805161.SCHEMANAME as varchar(32672)) in (cast(? as varchar(32672))) order by alias_8805161.SCHEMANAME, SYS.SYSSEQUENCES.SEQUENCENAME");
|
||||
M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES.put(FIREBIRD, "select null catalog, null schema, trim(RDB$GENERATORS.RDB$GENERATOR_NAME) RDB$GENERATOR_NAME, 'BIGINT' type_name, null numeric_precision, null numeric_scale, 0 RDB$INITIAL_VALUE, 1 RDB$GENERATOR_INCREMENT, null min_value, null max_value, null cycle, null cache from RDB$GENERATORS order by RDB$GENERATORS.RDB$GENERATOR_NAME");
|
||||
M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES.put(H2, "select null catalog, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME, 'BIGINT' type_name, null precision, null scale, null start_value, nullif(INFORMATION_SCHEMA.SEQUENCES.INCREMENT, 1) INCREMENT, nullif(INFORMATION_SCHEMA.SEQUENCES.MIN_VALUE, 1) MIN_VALUE, nullif(INFORMATION_SCHEMA.SEQUENCES.MAX_VALUE, 9223372036854775807) MAX_VALUE, INFORMATION_SCHEMA.SEQUENCES.IS_CYCLE, nullif(INFORMATION_SCHEMA.SEQUENCES.CACHE, 32) CACHE from INFORMATION_SCHEMA.SEQUENCES where INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA in (cast(? as varchar(2147483647))) order by INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME");
|
||||
M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES.put(HSQLDB, "select null as catalog, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME, INFORMATION_SCHEMA.SEQUENCES.DATA_TYPE, INFORMATION_SCHEMA.SEQUENCES.NUMERIC_PRECISION, INFORMATION_SCHEMA.SEQUENCES.NUMERIC_SCALE, INFORMATION_SCHEMA.SEQUENCES.START_WITH, INFORMATION_SCHEMA.SEQUENCES.INCREMENT, INFORMATION_SCHEMA.SEQUENCES.MINIMUM_VALUE, INFORMATION_SCHEMA.SEQUENCES.MAXIMUM_VALUE, case when INFORMATION_SCHEMA.SEQUENCES.CYCLE_OPTION is not distinct from 'YES' then true else false end as CYCLE_OPTION, null as cache from INFORMATION_SCHEMA.SEQUENCES where INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA in (cast(? as varchar(128))) order by INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_SCHEMA, INFORMATION_SCHEMA.SEQUENCES.SEQUENCE_NAME");
|
||||
M_SEQUENCES_INCLUDING_SYSTEM_SEQUENCES.put(POSTGRES, "select null as catalog, information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name, information_schema.sequences.data_type, information_schema.sequences.numeric_precision, information_schema.sequences.numeric_scale, nullif(cast(information_schema.sequences.start_value as bigint), 1) as start_value, nullif(cast(information_schema.sequences.increment as bigint), 1) as increment, nullif(cast(information_schema.sequences.minimum_value as bigint), 1) as minimum_value, nullif(cast(information_schema.sequences.maximum_value as decimal), (power(cast(2 as decimal), cast((information_schema.sequences.numeric_precision - 1) as decimal)) - 1)) as maximum_value, cast(information_schema.sequences.cycle_option as boolean) as cycle_option, null as cache from information_schema.sequences where information_schema.sequences.sequence_schema in (?) order by information_schema.sequences.sequence_schema, information_schema.sequences.sequence_name");
|
||||
|
||||
|
||||
|
||||
|
||||
@ -505,6 +505,10 @@ jOOQ queries, for which no specific fetchSize value was specified.]]></jxb:javad
|
||||
<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="metaIncludeSystemSequences" 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 sequences, 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