[#718] Sequences should be mapped to appropriate type (e.g. SMALLINT, INT, BIGINT, etc)
This commit is contained in:
parent
35f7a6f065
commit
de67521fb4
@ -300,10 +300,16 @@ public class DefaultGenerator implements Generator {
|
||||
|
||||
out.print("\tpublic static final ");
|
||||
out.print(Sequence.class);
|
||||
out.print("<");
|
||||
out.print(getJavaType(sequence.getType()));
|
||||
out.print(">");
|
||||
out.print(" ");
|
||||
out.print(strategy.getJavaIdentifierUC(sequence));
|
||||
out.print(" = new ");
|
||||
out.print(SequenceImpl.class);
|
||||
out.print("<");
|
||||
out.print(getJavaType(sequence.getType()));
|
||||
out.print(">");
|
||||
out.print("(\"");
|
||||
out.print(sequence.getName());
|
||||
out.print("\"");
|
||||
@ -315,6 +321,9 @@ public class DefaultGenerator implements Generator {
|
||||
out.print(", null");
|
||||
}
|
||||
|
||||
out.print(", ");
|
||||
out.print(getJavaTypeReference(sequence.getDatabase(), sequence.getType()));
|
||||
|
||||
out.println(");");
|
||||
}
|
||||
|
||||
@ -322,7 +331,7 @@ public class DefaultGenerator implements Generator {
|
||||
out.println("}");
|
||||
out.close();
|
||||
|
||||
registerInSchema(outS, database.getSequences(), Sequence.class, false);
|
||||
registerInSchema(outS, database.getSequences(), Sequence.class, true);
|
||||
watch.splitInfo("Sequences generated");
|
||||
}
|
||||
|
||||
|
||||
@ -38,9 +38,11 @@ package org.jooq.util;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class DefaultSequenceDefinition extends AbstractDefinition implements SequenceDefinition {
|
||||
public class DefaultSequenceDefinition
|
||||
extends AbstractTypedElementDefinition<SchemaDefinition>
|
||||
implements SequenceDefinition {
|
||||
|
||||
public DefaultSequenceDefinition(Database database, String name) {
|
||||
super(database, name, null);
|
||||
public DefaultSequenceDefinition(SchemaDefinition schema, String name, DataTypeDefinition type) {
|
||||
super(schema, name, -1, type, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,6 @@ package org.jooq.util;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface SequenceDefinition extends Definition {
|
||||
public interface SequenceDefinition extends TypedElementDefinition<SchemaDefinition> {
|
||||
|
||||
}
|
||||
|
||||
@ -59,6 +59,8 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
import org.jooq.util.EnumDefinition;
|
||||
@ -171,13 +173,25 @@ public class DB2Database extends AbstractDatabase {
|
||||
protected List<SequenceDefinition> getSequences0() throws SQLException {
|
||||
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
|
||||
|
||||
for (String name : create().select(Sequences.SEQNAME)
|
||||
.from(SEQUENCES)
|
||||
.where(Sequences.SEQSCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQNAME)
|
||||
.fetch(Sequences.SEQNAME)) {
|
||||
for (Record record : create().select(
|
||||
Sequences.SEQNAME,
|
||||
Sequences.SEQTYPE,
|
||||
Datatypes.TYPENAME,
|
||||
Sequences.PRECISION)
|
||||
.from(SEQUENCES)
|
||||
.join(DATATYPES)
|
||||
.on(Sequences.DATATYPEID.equal(Datatypes.TYPEID.cast(Integer.class)))
|
||||
.where(Sequences.SEQSCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQNAME)
|
||||
.fetch()) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
record.getValue(Datatypes.TYPENAME),
|
||||
record.getValue(Sequences.PRECISION),
|
||||
0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(getSchema(),
|
||||
record.getValue(Sequences.SEQNAME), type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -56,6 +56,8 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
import org.jooq.util.EnumDefinition;
|
||||
@ -193,15 +195,22 @@ public class DerbyDatabase extends AbstractDatabase {
|
||||
protected List<SequenceDefinition> getSequences0() throws SQLException {
|
||||
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
|
||||
|
||||
for (String name : create().select(Syssequences.SEQUENCENAME)
|
||||
.from(SYSSEQUENCES)
|
||||
.join(SYSSCHEMAS)
|
||||
.on(Sysschemas.SCHEMAID.equal(Syssequences.SCHEMAID))
|
||||
.where(Sysschemas.SCHEMANAME.equal(getSchemaName()))
|
||||
.orderBy(Syssequences.SEQUENCENAME)
|
||||
.fetch(Syssequences.SEQUENCENAME)) {
|
||||
for (Record record : create().select(
|
||||
Syssequences.SEQUENCENAME,
|
||||
Syssequences.SEQUENCEDATATYPE)
|
||||
.from(SYSSEQUENCES)
|
||||
.join(SYSSCHEMAS)
|
||||
.on(Sysschemas.SCHEMAID.equal(Syssequences.SCHEMAID))
|
||||
.where(Sysschemas.SCHEMANAME.equal(getSchemaName()))
|
||||
.orderBy(Syssequences.SEQUENCENAME)
|
||||
.fetch()) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
record.getValue(Syssequences.SEQUENCEDATATYPE),
|
||||
0, 0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(
|
||||
getSchema(), record.getValueAsString(Syssequences.SEQUENCENAME), type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -51,6 +51,7 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
import org.jooq.util.EnumDefinition;
|
||||
@ -163,12 +164,15 @@ public class H2Database extends AbstractDatabase {
|
||||
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
|
||||
|
||||
for (String name : create().select(Sequences.SEQUENCE_NAME)
|
||||
.from(SEQUENCES)
|
||||
.where(Sequences.SEQUENCE_SCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQUENCE_NAME)
|
||||
.fetch(Sequences.SEQUENCE_NAME)) {
|
||||
.from(SEQUENCES)
|
||||
.where(Sequences.SEQUENCE_SCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQUENCE_NAME)
|
||||
.fetch(Sequences.SEQUENCE_NAME)) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
H2DataType.BIGINT.getTypeName(), 0, 0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(getSchema(), name, type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -54,6 +54,8 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
import org.jooq.util.EnumDefinition;
|
||||
@ -174,14 +176,20 @@ public class HSQLDBDatabase extends AbstractDatabase {
|
||||
protected List<SequenceDefinition> getSequences0() throws SQLException {
|
||||
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
|
||||
|
||||
for (String name : create()
|
||||
.select(Sequences.SEQUENCE_NAME)
|
||||
for (Record record : create()
|
||||
.select(
|
||||
Sequences.SEQUENCE_NAME,
|
||||
Sequences.DATA_TYPE)
|
||||
.from(SEQUENCES)
|
||||
.where(Sequences.SEQUENCE_SCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQUENCE_NAME)
|
||||
.fetch(Sequences.SEQUENCE_NAME)) {
|
||||
.fetch()) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
record.getValue(Sequences.DATA_TYPE), 0, 0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(
|
||||
getSchema(), record.getValue(Sequences.SEQUENCE_NAME), type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -53,6 +53,8 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
import org.jooq.util.EnumDefinition;
|
||||
@ -180,13 +182,19 @@ public class IngresDatabase extends AbstractDatabase {
|
||||
protected List<SequenceDefinition> getSequences0() throws SQLException {
|
||||
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
|
||||
|
||||
for (Record record : create().select(Iisequences.SEQ_NAME.trim())
|
||||
for (Record record : create().select(
|
||||
Iisequences.SEQ_NAME.trim(),
|
||||
Iisequences.DATA_TYPE.trim())
|
||||
.from(IISEQUENCES)
|
||||
.where(Iisequences.SEQ_OWNER.equal(getSchemaName()))
|
||||
.orderBy(Iisequences.SEQ_NAME)
|
||||
.fetch()) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, record.getValue(Iisequences.SEQ_NAME.trim())));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
record.getValue(Iisequences.DATA_TYPE.trim()), 0, 0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(
|
||||
getSchema(), record.getValue(Iisequences.SEQ_NAME.trim()), type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -59,6 +59,7 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultArrayDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
@ -181,7 +182,10 @@ public class OracleDatabase extends AbstractDatabase {
|
||||
.orderBy(SEQUENCE_NAME)
|
||||
.fetch(SEQUENCE_NAME)) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
OracleDataType.NUMBER.getTypeName(), 38, 0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(getSchema(), name, type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -64,6 +64,8 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultEnumDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
@ -195,13 +197,24 @@ public class PostgresDatabase extends AbstractDatabase {
|
||||
protected List<SequenceDefinition> getSequences0() throws SQLException {
|
||||
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
|
||||
|
||||
for (String name : create().select(Sequences.SEQUENCE_NAME)
|
||||
.from(SEQUENCES)
|
||||
.where(Sequences.SEQUENCE_SCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQUENCE_NAME)
|
||||
.fetch(Sequences.SEQUENCE_NAME)) {
|
||||
for (Record record : create()
|
||||
.select(
|
||||
Sequences.SEQUENCE_NAME,
|
||||
Sequences.DATA_TYPE,
|
||||
Sequences.NUMERIC_PRECISION,
|
||||
Sequences.NUMERIC_SCALE)
|
||||
.from(SEQUENCES)
|
||||
.where(Sequences.SEQUENCE_SCHEMA.equal(getSchemaName()))
|
||||
.orderBy(Sequences.SEQUENCE_NAME)
|
||||
.fetch()) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
record.getValue(Sequences.DATA_TYPE),
|
||||
record.getValue(Sequences.NUMERIC_PRECISION),
|
||||
record.getValue(Sequences.NUMERIC_SCALE));
|
||||
|
||||
result.add(new DefaultSequenceDefinition(
|
||||
getSchema(), record.getValue(Sequences.SEQUENCE_NAME), type));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -47,6 +47,8 @@ import org.jooq.impl.Factory;
|
||||
import org.jooq.util.AbstractDatabase;
|
||||
import org.jooq.util.ArrayDefinition;
|
||||
import org.jooq.util.ColumnDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultRelations;
|
||||
import org.jooq.util.DefaultSequenceDefinition;
|
||||
import org.jooq.util.EnumDefinition;
|
||||
@ -203,8 +205,12 @@ public class SybaseDatabase extends AbstractDatabase {
|
||||
.orderBy(Syssequence.SEQUENCE_NAME)
|
||||
.fetch(Syssequence.SEQUENCE_NAME)) {
|
||||
|
||||
result.add(new DefaultSequenceDefinition(this, name));
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(this,
|
||||
SybaseDataType.NUMERIC.getTypeName(), 38, 0);
|
||||
|
||||
result.add(new DefaultSequenceDefinition(getSchema(), name, type));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.db2.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Lukas extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = 2041409044;
|
||||
private static final long serialVersionUID = 1225381834;
|
||||
|
||||
/**
|
||||
* The singleton instance of LUKAS
|
||||
@ -25,8 +25,8 @@ public class Lukas extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(
|
||||
org.jooq.test.db2.generatedclasses.Sequences.S_AUTHOR_ID,
|
||||
org.jooq.test.db2.generatedclasses.Sequences.S_TRIGGER_ID);
|
||||
}
|
||||
|
||||
@ -13,14 +13,14 @@ package org.jooq.test.db2.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence S_AUTHOR_ID
|
||||
* The sequence LUKAS.LUKAS.S_AUTHOR_ID
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("S_AUTHOR_ID", org.jooq.test.db2.generatedclasses.Lukas.LUKAS);
|
||||
public static final org.jooq.Sequence<java.lang.Integer> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Integer>("S_AUTHOR_ID", org.jooq.test.db2.generatedclasses.Lukas.LUKAS, org.jooq.impl.SQLDataType.INTEGER);
|
||||
|
||||
/**
|
||||
* The sequence S_TRIGGER_ID
|
||||
* The sequence LUKAS.LUKAS.S_TRIGGER_ID
|
||||
*/
|
||||
public static final org.jooq.Sequence S_TRIGGER_ID = new org.jooq.impl.SequenceImpl("S_TRIGGER_ID", org.jooq.test.db2.generatedclasses.Lukas.LUKAS);
|
||||
public static final org.jooq.Sequence<java.lang.Integer> S_TRIGGER_ID = new org.jooq.impl.SequenceImpl<java.lang.Integer>("S_TRIGGER_ID", org.jooq.test.db2.generatedclasses.Lukas.LUKAS, org.jooq.impl.SQLDataType.INTEGER);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -13,9 +13,9 @@ package org.jooq.test.derby.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence S_AUTHOR_ID
|
||||
* The sequence TEST.TEST.S_AUTHOR_ID
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("S_AUTHOR_ID", org.jooq.test.derby.generatedclasses.Test.TEST);
|
||||
public static final org.jooq.Sequence<java.lang.Integer> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Integer>("S_AUTHOR_ID", org.jooq.test.derby.generatedclasses.Test.TEST, org.jooq.impl.SQLDataType.INTEGER);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.derby.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Test extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -2119002270;
|
||||
private static final long serialVersionUID = 561937048;
|
||||
|
||||
/**
|
||||
* The singleton instance of TEST
|
||||
@ -25,8 +25,8 @@ public class Test extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(org.jooq.test.derby.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(org.jooq.test.derby.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.h2.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Public extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -1780021047;
|
||||
private static final long serialVersionUID = 131264191;
|
||||
|
||||
/**
|
||||
* The singleton instance of PUBLIC
|
||||
@ -25,8 +25,8 @@ public class Public extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(
|
||||
org.jooq.test.h2.generatedclasses.Sequences.S_AUTHOR_ID,
|
||||
org.jooq.test.h2.generatedclasses.Sequences.S_TRIGGERS_SEQUENCE);
|
||||
}
|
||||
|
||||
@ -13,14 +13,14 @@ package org.jooq.test.h2.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence S_AUTHOR_ID
|
||||
* The sequence PUBLIC.PUBLIC.S_AUTHOR_ID
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("S_AUTHOR_ID", org.jooq.test.h2.generatedclasses.Public.PUBLIC);
|
||||
public static final org.jooq.Sequence<java.lang.Long> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Long>("S_AUTHOR_ID", org.jooq.test.h2.generatedclasses.Public.PUBLIC, org.jooq.impl.SQLDataType.BIGINT);
|
||||
|
||||
/**
|
||||
* The sequence S_TRIGGERS_SEQUENCE
|
||||
* The sequence PUBLIC.PUBLIC.S_TRIGGERS_SEQUENCE
|
||||
*/
|
||||
public static final org.jooq.Sequence S_TRIGGERS_SEQUENCE = new org.jooq.impl.SequenceImpl("S_TRIGGERS_SEQUENCE", org.jooq.test.h2.generatedclasses.Public.PUBLIC);
|
||||
public static final org.jooq.Sequence<java.lang.Long> S_TRIGGERS_SEQUENCE = new org.jooq.impl.SequenceImpl<java.lang.Long>("S_TRIGGERS_SEQUENCE", org.jooq.test.h2.generatedclasses.Public.PUBLIC, org.jooq.impl.SQLDataType.BIGINT);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.hsqldb.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Public extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -701266683;
|
||||
private static final long serialVersionUID = 1798190159;
|
||||
|
||||
/**
|
||||
* The singleton instance of PUBLIC
|
||||
@ -25,8 +25,8 @@ public class Public extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(org.jooq.test.hsqldb.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(org.jooq.test.hsqldb.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,9 +13,9 @@ package org.jooq.test.hsqldb.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence S_AUTHOR_ID
|
||||
* The sequence PUBLIC.PUBLIC.S_AUTHOR_ID
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("S_AUTHOR_ID", org.jooq.test.hsqldb.generatedclasses.Public.PUBLIC);
|
||||
public static final org.jooq.Sequence<java.lang.Integer> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Integer>("S_AUTHOR_ID", org.jooq.test.hsqldb.generatedclasses.Public.PUBLIC, org.jooq.impl.SQLDataType.INTEGER);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -13,9 +13,9 @@ package org.jooq.test.ingres.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence s_author_id
|
||||
* The sequence test.test.s_author_id
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("s_author_id", org.jooq.test.ingres.generatedclasses.Test.TEST);
|
||||
public static final org.jooq.Sequence<java.lang.Long> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Long>("s_author_id", org.jooq.test.ingres.generatedclasses.Test.TEST, org.jooq.impl.SQLDataType.BIGINT);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.ingres.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Test extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -1015067730;
|
||||
private static final long serialVersionUID = 1311361976;
|
||||
|
||||
/**
|
||||
* The singleton instance of test
|
||||
@ -25,8 +25,8 @@ public class Test extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(org.jooq.test.ingres.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(org.jooq.test.ingres.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -2117,9 +2117,10 @@ public abstract class jOOQAbstractTest<
|
||||
|
||||
reset = false;
|
||||
|
||||
Sequence sequence = (Sequence) cSequences().getField("S_AUTHOR_ID").get(cSequences());
|
||||
Field<BigInteger> nextval = sequence.nextval();
|
||||
Field<BigInteger> currval = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
Sequence<? extends Number> sequence = (Sequence<? extends Number>) cSequences().getField("S_AUTHOR_ID").get(cSequences());
|
||||
Field<? extends Number> nextval = sequence.nextval();
|
||||
Field<? extends Number> currval = null;
|
||||
|
||||
assertEquals("3", "" + create().select(nextval).fetchOne(nextval));
|
||||
assertEquals("4", "" + create().select(nextval).fetchOne(nextval));
|
||||
@ -2142,15 +2143,15 @@ public abstract class jOOQAbstractTest<
|
||||
assertEquals("5", "" + create().select(currval).fetchOne(currval));
|
||||
assertEquals("5", "" + create().select(currval).fetchOne(currval));
|
||||
|
||||
assertEquals(new BigInteger("5"), create().currval(sequence));
|
||||
assertEquals(new BigInteger("5"), create().currval(sequence));
|
||||
assertEquals(5, create().currval(sequence).intValue());
|
||||
assertEquals(5, create().currval(sequence).intValue());
|
||||
}
|
||||
|
||||
assertEquals("6", "" + create().select(nextval).fetchOne(nextval));
|
||||
|
||||
// Test convenience syntax
|
||||
assertEquals(new BigInteger("7"), create().nextval(sequence));
|
||||
assertEquals(new BigInteger("8"), create().nextval(sequence));
|
||||
assertEquals(7, create().nextval(sequence).intValue());
|
||||
assertEquals(8, create().nextval(sequence).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -13,9 +13,9 @@ package org.jooq.test.oracle.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence S_AUTHOR_ID
|
||||
* The sequence TEST.TEST.S_AUTHOR_ID
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("S_AUTHOR_ID", org.jooq.test.oracle.generatedclasses.Test.TEST);
|
||||
public static final org.jooq.Sequence<java.math.BigInteger> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.math.BigInteger>("S_AUTHOR_ID", org.jooq.test.oracle.generatedclasses.Test.TEST, org.jooq.impl.SQLDataType.DECIMAL_INTEGER);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.oracle.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Test extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -1777958162;
|
||||
private static final long serialVersionUID = 1485629092;
|
||||
|
||||
/**
|
||||
* The singleton instance of TEST
|
||||
@ -36,8 +36,8 @@ public class Test extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(org.jooq.test.oracle.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(org.jooq.test.oracle.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.postgres.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Public extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -2116922621;
|
||||
private static final long serialVersionUID = -810150023;
|
||||
|
||||
/**
|
||||
* The singleton instance of public
|
||||
@ -33,8 +33,8 @@ public class Public extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(org.jooq.test.postgres.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(org.jooq.test.postgres.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,9 +13,9 @@ package org.jooq.test.postgres.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence s_author_id
|
||||
* The sequence public.public.s_author_id
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("s_author_id", org.jooq.test.postgres.generatedclasses.Public.PUBLIC);
|
||||
public static final org.jooq.Sequence<java.lang.Long> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.lang.Long>("s_author_id", org.jooq.test.postgres.generatedclasses.Public.PUBLIC, org.jooq.impl.SQLDataType.BIGINT);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -10,7 +10,7 @@ package org.jooq.test.sybase.generatedclasses;
|
||||
comments = "This class is generated by jOOQ")
|
||||
public class Dba extends org.jooq.impl.SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = -187178479;
|
||||
private static final long serialVersionUID = 1624815899;
|
||||
|
||||
/**
|
||||
* The singleton instance of dba
|
||||
@ -25,8 +25,8 @@ public class Dba extends org.jooq.impl.SchemaImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final java.util.List<org.jooq.Sequence> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence>asList(org.jooq.test.sybase.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
public final java.util.List<org.jooq.Sequence<?>> getSequences() {
|
||||
return java.util.Arrays.<org.jooq.Sequence<?>>asList(org.jooq.test.sybase.generatedclasses.Sequences.S_AUTHOR_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,9 +13,9 @@ package org.jooq.test.sybase.generatedclasses;
|
||||
public final class Sequences {
|
||||
|
||||
/**
|
||||
* The sequence s_author_id
|
||||
* The sequence dba.dba.s_author_id
|
||||
*/
|
||||
public static final org.jooq.Sequence S_AUTHOR_ID = new org.jooq.impl.SequenceImpl("s_author_id", org.jooq.test.sybase.generatedclasses.Dba.DBA);
|
||||
public static final org.jooq.Sequence<java.math.BigInteger> S_AUTHOR_ID = new org.jooq.impl.SequenceImpl<java.math.BigInteger>("s_author_id", org.jooq.test.sybase.generatedclasses.Dba.DBA, org.jooq.impl.SQLDataType.DECIMAL_INTEGER);
|
||||
|
||||
/**
|
||||
* No instances
|
||||
|
||||
@ -72,5 +72,5 @@ public interface Schema extends NamedQueryPart {
|
||||
/**
|
||||
* List all sequences contained in this schema
|
||||
*/
|
||||
List<Sequence> getSequences();
|
||||
List<Sequence<?>> getSequences();
|
||||
}
|
||||
|
||||
@ -35,22 +35,21 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* A type representing sequences in databases that support this.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface Sequence {
|
||||
public interface Sequence<T extends Number> {
|
||||
|
||||
/**
|
||||
* Get the current value of this sequence
|
||||
*/
|
||||
Field<BigInteger> currval();
|
||||
Field<T> currval();
|
||||
|
||||
/**
|
||||
* Increment the sequence and get the next value
|
||||
*/
|
||||
Field<BigInteger> nextval();
|
||||
Field<T> nextval();
|
||||
}
|
||||
|
||||
@ -1483,8 +1483,8 @@ public class Factory implements Configuration {
|
||||
* Convenience method to fetch the NEXTVAL for a sequence directly from this
|
||||
* {@link Factory}'s underlying JDBC {@link Connection}
|
||||
*/
|
||||
public final BigInteger nextval(Sequence sequence) throws SQLException {
|
||||
Field<BigInteger> nextval = sequence.nextval();
|
||||
public final <T extends Number> T nextval(Sequence<T> sequence) throws SQLException {
|
||||
Field<T> nextval = sequence.nextval();
|
||||
return select(nextval).fetchOne(nextval);
|
||||
}
|
||||
|
||||
@ -1492,8 +1492,8 @@ public class Factory implements Configuration {
|
||||
* Convenience method to fetch the CURRVAL for a sequence directly from this
|
||||
* {@link Factory}'s underlying JDBC {@link Connection}
|
||||
*/
|
||||
public final BigInteger currval(Sequence sequence) throws SQLException {
|
||||
Field<BigInteger> currval = sequence.currval();
|
||||
public final <T extends Number> T currval(Sequence<T> sequence) throws SQLException {
|
||||
Field<T> currval = sequence.currval();
|
||||
return select(currval).fetchOne(currval);
|
||||
}
|
||||
|
||||
|
||||
@ -117,7 +117,7 @@ public class SchemaImpl extends AbstractNamedQueryPart implements Schema {
|
||||
* Subclasses should override this method
|
||||
*/
|
||||
@Override
|
||||
public List<Sequence> getSequences() {
|
||||
public List<Sequence<?>> getSequences() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,8 +37,6 @@ package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Factory.field;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.RenderContext;
|
||||
@ -47,44 +45,44 @@ import org.jooq.SQLDialectNotSupportedException;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
class SequenceFunction extends AbstractFunction<BigInteger> {
|
||||
class SequenceFunction<T extends Number> extends AbstractFunction<T> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 2292275568395094887L;
|
||||
private static final long serialVersionUID = 2292275568395094887L;
|
||||
|
||||
private final SequenceImpl sequence;
|
||||
private final String method;
|
||||
private final SequenceImpl<T> sequence;
|
||||
private final String method;
|
||||
|
||||
SequenceFunction(SequenceImpl sequence, String method) {
|
||||
super(method, SQLDataType.DECIMAL_INTEGER);
|
||||
SequenceFunction(SequenceImpl<T> sequence, String method) {
|
||||
super(method, sequence.type);
|
||||
|
||||
this.sequence = sequence;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
final Field<BigInteger> getFunction0(Configuration configuration) {
|
||||
final Field<T> getFunction0(Configuration configuration) {
|
||||
switch (configuration.getDialect()) {
|
||||
case DB2: // No break
|
||||
case INGRES: // No break
|
||||
case ORACLE: // No break
|
||||
case SYBASE: {
|
||||
String field = getQualifiedName(configuration) + "." + method;
|
||||
return field(field, BigInteger.class);
|
||||
return field(field, getDataType());
|
||||
}
|
||||
case H2: // No break
|
||||
case POSTGRES: {
|
||||
String field = method + "('" + getQualifiedName(configuration) + "')";
|
||||
return field(field, BigInteger.class);
|
||||
return field(field, getDataType());
|
||||
}
|
||||
|
||||
case DERBY: // No break
|
||||
case HSQLDB: {
|
||||
if ("nextval".equals(method)) {
|
||||
String field = "next value for " + getQualifiedName(configuration);
|
||||
return field(field, BigInteger.class);
|
||||
return field(field, getDataType());
|
||||
}
|
||||
else {
|
||||
throw new SQLDialectNotSupportedException("The sequence's current value functionality is not supported for the " + configuration.getDialect() + " dialect.");
|
||||
@ -94,7 +92,7 @@ class SequenceFunction extends AbstractFunction<BigInteger> {
|
||||
// Default is needed for hashCode() and toString()
|
||||
default: {
|
||||
String field = getQualifiedName(configuration) + "." + method;
|
||||
return field(field, BigInteger.class);
|
||||
return field(field, getDataType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,8 +35,7 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Sequence;
|
||||
@ -48,27 +47,29 @@ import org.jooq.Sequence;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class SequenceImpl implements Sequence {
|
||||
public class SequenceImpl<T extends Number> implements Sequence<T> {
|
||||
|
||||
final String name;
|
||||
final Schema schema;
|
||||
final DataType<T> type;
|
||||
|
||||
public SequenceImpl(String name, Schema schema) {
|
||||
public SequenceImpl(String name, Schema schema, DataType<T> type) {
|
||||
this.name = name;
|
||||
this.schema = schema;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field<BigInteger> currval() {
|
||||
public Field<T> currval() {
|
||||
return getSequence("currval");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field<BigInteger> nextval() {
|
||||
public Field<T> nextval() {
|
||||
return getSequence("nextval");
|
||||
}
|
||||
|
||||
private Field<BigInteger> getSequence(final String sequence) {
|
||||
return new SequenceFunction(this, sequence);
|
||||
private Field<T> getSequence(final String sequence) {
|
||||
return new SequenceFunction<T>(this, sequence);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user