Search in sources :

Example 1 with SequenceDefinition

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");
}
Also used : SequenceDefinition(org.jooq.meta.SequenceDefinition) Internal(org.jooq.impl.Internal) Sequence(org.jooq.Sequence)

Example 2 with SequenceDefinition

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;
}
Also used : DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Example 3 with SequenceDefinition

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;
}
Also used : DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 4 with SequenceDefinition

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;
}
Also used : DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 5 with SequenceDefinition

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;
}
Also used : DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Aggregations

SequenceDefinition (org.jooq.meta.SequenceDefinition)10 ArrayList (java.util.ArrayList)8 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)8 SchemaDefinition (org.jooq.meta.SchemaDefinition)8 Record (org.jooq.Record)7 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)7 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)7 BigInteger (java.math.BigInteger)2 Sequence (org.jooq.util.xml.jaxb.Sequence)2 StringWriter (java.io.StringWriter)1 Sequence (org.jooq.Sequence)1 Internal (org.jooq.impl.Internal)1 CatalogDefinition (org.jooq.meta.CatalogDefinition)1 CheckConstraintDefinition (org.jooq.meta.CheckConstraintDefinition)1 ColumnDefinition (org.jooq.meta.ColumnDefinition)1 ForeignKeyDefinition (org.jooq.meta.ForeignKeyDefinition)1 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)1 IndexDefinition (org.jooq.meta.IndexDefinition)1 PackageDefinition (org.jooq.meta.PackageDefinition)1 RoutineDefinition (org.jooq.meta.RoutineDefinition)1