use of org.jooq.meta.SequenceDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateSequences.
protected void generateSequences(SchemaDefinition schema) {
log.info("Generating sequences");
JavaWriter out = newJavaWriter(getStrategy().getGlobalReferencesFile(schema, SequenceDefinition.class));
out.refConflicts(getStrategy().getJavaIdentifiers(database.getSequences(schema)));
printGlobalReferencesPackage(out, schema, SequenceDefinition.class);
if (!kotlin) {
printClassJavadoc(out, "Convenience access to all sequences in " + schemaNameOrDefault(schema) + ".");
printClassAnnotations(out, schema, Mode.DEFAULT);
}
final String referencesClassName = getStrategy().getGlobalReferencesJavaClassName(schema, SequenceDefinition.class);
if (scala)
out.println("%sobject %s {", visibility(), referencesClassName);
else if (kotlin) {
} else
out.println("%sclass %s {", visibility(), referencesClassName);
for (SequenceDefinition sequence : database.getSequences(schema)) {
final String seqTypeFull = getJavaType(sequence.getType(resolver(out)), out);
final String seqType = out.ref(seqTypeFull);
final String seqId = getStrategy().getJavaIdentifier(sequence);
final String seqName = sequence.getOutputName();
final String schemaId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
final String typeRef = getJavaTypeReference(sequence.getDatabase(), sequence.getType(resolver(out)), out);
if (!printDeprecationIfUnknownType(out, seqTypeFull))
out.javadoc("The sequence <code>%s</code>", sequence.getQualifiedOutputName());
boolean flags = generateSequenceFlags();
if (scala)
out.println("%sval %s: %s[%s] = %s.createSequence(\"%s\", %s, %s, %s, %s, %s, %s, %s, %s)", visibility(), scalaWhitespaceSuffix(seqId), Sequence.class, seqType, Internal.class, seqName, schemaId, typeRef, flags ? numberLiteral(sequence.getStartWith()) : "null", flags ? numberLiteral(sequence.getIncrementBy()) : "null", flags ? numberLiteral(sequence.getMinvalue()) : "null", flags ? numberLiteral(sequence.getMaxvalue()) : "null", flags && sequence.getCycle(), flags ? numberLiteral(sequence.getCache()) : "null");
else if (kotlin)
out.println("%sval %s: %s<%s> = %s.createSequence(\"%s\", %s, %s, %s, %s, %s, %s, %s, %s)", visibility(), seqId, Sequence.class, seqType, Internal.class, seqName, schemaId, typeRef, flags ? numberLiteral(sequence.getStartWith()) : "null", flags ? numberLiteral(sequence.getIncrementBy()) : "null", flags ? numberLiteral(sequence.getMinvalue()) : "null", flags ? numberLiteral(sequence.getMaxvalue()) : "null", flags && sequence.getCycle(), flags ? numberLiteral(sequence.getCache()) : "null");
else
out.println("%sstatic final %s<%s> %s = %s.createSequence(\"%s\", %s, %s, %s, %s, %s, %s, %s, %s);", visibility(), Sequence.class, seqType, seqId, Internal.class, seqName, schemaId, typeRef, flags ? numberLiteral(sequence.getStartWith()) : "null", flags ? numberLiteral(sequence.getIncrementBy()) : "null", flags ? numberLiteral(sequence.getMinvalue()) : "null", flags ? numberLiteral(sequence.getMaxvalue()) : "null", flags && sequence.getCycle(), flags ? numberLiteral(sequence.getCache()) : "null");
}
generateSequencesClassFooter(schema, out);
if (!kotlin)
out.println("}");
closeJavaWriter(out);
watch.splitInfo("Sequences generated");
}
use of org.jooq.meta.SequenceDefinition in project jOOQ by jOOQ.
the class H2Database method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SEQUENCES.SEQUENCE_SCHEMA));
if (schema != null) {
String name = record.get(SEQUENCES.SEQUENCE_NAME);
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, H2DataType.BIGINT.getTypeName());
result.add(new DefaultSequenceDefinition(schema, name, type, null, // H2 doesn't support Postgres-style START WITH
null, record.get(SEQUENCES.INCREMENT), record.get(SEQUENCES.MIN_VALUE), record.get(SEQUENCES.MAX_VALUE), record.get(SEQUENCES.IS_CYCLE), record.get(SEQUENCES.CACHE)));
}
}
return result;
}
use of org.jooq.meta.SequenceDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SEQUENCES.SEQUENCE_SCHEMA));
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SEQUENCES.DATA_TYPE));
result.add(new DefaultSequenceDefinition(schema, record.get(SEQUENCES.SEQUENCE_NAME), type));
}
return result;
}
use of org.jooq.meta.SequenceDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SEQUENCES.SEQUENCE_SCHEMA));
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SEQUENCES.DATA_TYPE), 0, record.get(SEQUENCES.NUMERIC_PRECISION), record.get(SEQUENCES.NUMERIC_SCALE), false, (String) null);
result.add(new DefaultSequenceDefinition(schema, record.get(SEQUENCES.SEQUENCE_NAME), type, null, record.get(SEQUENCES.START_VALUE, BigInteger.class), record.get(SEQUENCES.INCREMENT, BigInteger.class), record.get(SEQUENCES.MINIMUM_VALUE, BigInteger.class), record.get(SEQUENCES.MAXIMUM_VALUE, BigInteger.class), record.get(SEQUENCES.CYCLE_OPTION, Boolean.class), // [#9442] The CACHE flag is not available from SEQUENCES
null));
}
return result;
}
use of org.jooq.meta.SequenceDefinition in project jOOQ by jOOQ.
the class DerbyDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SYSSEQUENCES.sysschemas().SCHEMANAME));
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SYSSEQUENCES.SEQUENCEDATATYPE));
result.add(new DefaultSequenceDefinition(schema, record.get(SYSSEQUENCES.SEQUENCENAME), type, null, record.get(SYSSEQUENCES.STARTVALUE), record.get(SYSSEQUENCES.INCREMENT), record.get(SYSSEQUENCES.MINIMUMVALUE), record.get(SYSSEQUENCES.MAXIMUMVALUE), record.get(SYSSEQUENCES.CYCLEOPTION, Boolean.class), null));
}
return result;
}
Aggregations