[jOOQ/jOOQ#9442] Sequence flag generation for PostgreSQL

Note: Cache information is not available from PostgreSQL's
`INFORMATION_SCHEMA.SEQUENCES`.
This commit is contained in:
Knut Wannheden 2019-11-27 16:49:17 +01:00
parent c5a35289fa
commit c09ddd9c8c
2 changed files with 25 additions and 4 deletions

View File

@ -54,7 +54,6 @@ import static org.jooq.meta.h2.information_schema.tables.Tables.TABLES;
import static org.jooq.meta.h2.information_schema.tables.TypeInfo.TYPE_INFO;
import java.io.StringReader;
import java.math.BigInteger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@ -112,7 +111,7 @@ import org.jooq.util.h2.H2DataType;
*/
public class H2Database extends AbstractDatabase {
private static final BigInteger DEFAULT_SEQUENCE_MAXVALUE = new BigInteger("9223372036854775807");
private static final long DEFAULT_SEQUENCE_MAXVALUE = Long.MAX_VALUE;
@Override
protected DSLContext create0() {

View File

@ -49,12 +49,17 @@ import static org.jooq.impl.DSL.max;
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.partitionBy;
import static org.jooq.impl.DSL.power;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.rowNumber;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.when;
import static org.jooq.impl.SQLDataType.BIGINT;
import static org.jooq.impl.SQLDataType.BOOLEAN;
import static org.jooq.impl.SQLDataType.NUMERIC;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.meta.postgres.information_schema.Tables.ATTRIBUTES;
import static org.jooq.meta.postgres.information_schema.Tables.CHECK_CONSTRAINTS;
@ -552,7 +557,13 @@ public class PostgresDatabase extends AbstractDatabase {
SEQUENCES.SEQUENCE_NAME,
SEQUENCES.DATA_TYPE,
SEQUENCES.NUMERIC_PRECISION,
SEQUENCES.NUMERIC_SCALE)
SEQUENCES.NUMERIC_SCALE,
SEQUENCES.START_VALUE.cast(BIGINT).as(SEQUENCES.START_VALUE),
SEQUENCES.INCREMENT.cast(BIGINT).as(SEQUENCES.INCREMENT),
SEQUENCES.MINIMUM_VALUE.cast(BIGINT).as(SEQUENCES.MINIMUM_VALUE),
nullif(SEQUENCES.MAXIMUM_VALUE.cast(NUMERIC),
power(inline(2, NUMERIC), SEQUENCES.NUMERIC_PRECISION.minus(1)).minus(1)).as(SEQUENCES.MAXIMUM_VALUE),
SEQUENCES.CYCLE_OPTION.cast(BOOLEAN).as(SEQUENCES.CYCLE_OPTION))
.from(SEQUENCES)
.where(SEQUENCES.SEQUENCE_SCHEMA.in(getInputSchemata()))
.orderBy(
@ -572,7 +583,18 @@ public class PostgresDatabase extends AbstractDatabase {
(String) null
);
result.add(new DefaultSequenceDefinition(schema, record.get(SEQUENCES.SEQUENCE_NAME), type));
result.add(new DefaultSequenceDefinition(
schema,
record.get(SEQUENCES.SEQUENCE_NAME),
type,
null,
record.get(SEQUENCES.START_VALUE, Long.class),
record.get(SEQUENCES.INCREMENT, Long.class),
record.get(SEQUENCES.MINIMUM_VALUE, Long.class),
record.get(SEQUENCES.MAXIMUM_VALUE, Long.class),
record.get(SEQUENCES.CYCLE_OPTION, Boolean.class),
null
));
}
return result;