Search in sources :

Example 51 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class PostgresDatabase method loadCheckConstraints.

@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
    CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
    // [#10940] [#10992] Workaround for issue caused by re-using implicit join paths
    PgConstraint pc = PG_CONSTRAINT.as("pc");
    for (Record record : create().select(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, pc.CONNAME.as(cc.CONSTRAINT_NAME), replace(field("pg_get_constraintdef({0}.oid)", VARCHAR, pc), inline("CHECK "), inline("")).as(cc.CHECK_CLAUSE)).from(pc).where(pc.pgClass().pgNamespace().NSPNAME.in(getInputSchemata())).and(pc.CONTYPE.eq(inline("c"))).unionAll(getIncludeSystemCheckConstraints() ? select(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE).from(pc).join(cc).on(pc.CONNAME.eq(cc.CONSTRAINT_NAME)).and(pc.pgNamespace().NSPNAME.eq(cc.CONSTRAINT_NAME)).where(pc.pgNamespace().NSPNAME.in(getInputSchemata())).and(row(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, cc.CONSTRAINT_NAME).notIn(select(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, pc.CONNAME).from(pc).where(pc.CONTYPE.eq(inline("c"))))) : select(inline(""), inline(""), inline(""), inline("")).where(falseCondition())).orderBy(1, 2, 3)) {
        SchemaDefinition schema = getSchema(record.get(pc.pgClass().pgNamespace().NSPNAME));
        TableDefinition table = getTable(schema, record.get(pc.pgClass().RELNAME));
        if (table != null) {
            relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(cc.CONSTRAINT_NAME), record.get(cc.CHECK_CLAUSE)));
        }
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) PgConstraint(org.jooq.meta.postgres.pg_catalog.tables.PgConstraint) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record) DefaultCheckConstraintDefinition(org.jooq.meta.DefaultCheckConstraintDefinition) CheckConstraints(org.jooq.meta.postgres.information_schema.tables.CheckConstraints)

Example 52 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class XMLDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() {
    List<SequenceDefinition> result = new ArrayList<>();
    for (Sequence sequence : info().getSequences()) {
        if (getInputSchemata().contains(sequence.getSequenceSchema())) {
            SchemaDefinition schema = getSchema(sequence.getSequenceSchema());
            DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, sequence.getDataType(), sequence.getCharacterMaximumLength(), sequence.getNumericPrecision(), sequence.getNumericScale(), false, (String) null);
            result.add(new DefaultSequenceDefinition(schema, sequence.getSequenceName(), type, sequence.getComment(), sequence.getStartValue(), sequence.getIncrement(), sequence.getMinimumValue(), sequence.getMaximumValue(), Boolean.TRUE.equals(sequence.isCycleOption()), sequence.getCache()));
        }
    }
    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) Sequence(org.jooq.util.xml.jaxb.Sequence) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 53 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class XMLDatabase method loadUniqueKeys.

@Override
protected void loadUniqueKeys(DefaultRelations relations) {
    for (KeyColumnUsage usage : keyColumnUsage(UNIQUE)) {
        SchemaDefinition schema = getSchema(usage.getConstraintSchema());
        String key = usage.getConstraintName();
        String tableName = usage.getTableName();
        String columnName = usage.getColumnName();
        TableConstraint tc = tableConstraint(usage.getConstraintCatalog(), usage.getConstraintSchema(), usage.getConstraintName());
        TableDefinition table = getTable(schema, tableName);
        if (table != null)
            relations.addUniqueKey(key, table, table.getColumn(columnName), tc != null && !FALSE.equals(tc.isEnforced()));
    }
}
Also used : KeyColumnUsage(org.jooq.util.xml.jaxb.KeyColumnUsage) SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) TableConstraint(org.jooq.util.xml.jaxb.TableConstraint)

Example 54 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class XMLDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) {
    for (KeyColumnUsage usage : keyColumnUsage(PRIMARY_KEY)) {
        SchemaDefinition schema = getSchema(usage.getConstraintSchema());
        String key = usage.getConstraintName();
        String tableName = usage.getTableName();
        String columnName = usage.getColumnName();
        TableConstraint tc = tableConstraint(usage.getConstraintCatalog(), usage.getConstraintSchema(), usage.getConstraintName());
        TableDefinition table = getTable(schema, tableName);
        if (table != null)
            relations.addPrimaryKey(key, table, table.getColumn(columnName), tc != null && !FALSE.equals(tc.isEnforced()));
    }
}
Also used : KeyColumnUsage(org.jooq.util.xml.jaxb.KeyColumnUsage) SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) TableConstraint(org.jooq.util.xml.jaxb.TableConstraint)

Example 55 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class JavaGenerator method generateUDTReferences.

/**
 * Generating central static udt access
 */
protected void generateUDTReferences(Definition schemaOrPackage) {
    String logSuffix = schemaOrPackage instanceof SchemaDefinition ? "" : (" for package " + schemaOrPackage.getOutputName());
    log.info("Generating UDT references" + logSuffix);
    JavaWriter out = newJavaWriter(getStrategy().getGlobalReferencesFile(schemaOrPackage, UDTDefinition.class));
    printGlobalReferencesPackage(out, schemaOrPackage, UDTDefinition.class);
    if (!kotlin) {
        printClassJavadoc(out, "Convenience access to all UDTs in " + schemaNameOrDefault(schemaOrPackage) + ".");
        printClassAnnotations(out, schemaOrPackage, Mode.DEFAULT);
    }
    final String referencesClassName = getStrategy().getGlobalReferencesJavaClassName(schemaOrPackage, UDTDefinition.class);
    if (scala)
        out.println("%sobject %s {", visibility(), referencesClassName);
    else if (kotlin) {
    } else
        out.println("%sclass %s {", visibility(), referencesClassName);
    List<UDTDefinition> udts = new ArrayList<>();
    if (schemaOrPackage instanceof SchemaDefinition) {
        for (UDTDefinition udt : database.getUDTs((SchemaDefinition) schemaOrPackage)) if (udt.getPackage() == null)
            udts.add(udt);
    } else
        udts.addAll(database.getUDTs((PackageDefinition) schemaOrPackage));
    for (UDTDefinition udt : udts) {
        final String className = out.ref(getStrategy().getFullJavaClassName(udt));
        final String id = getStrategy().getJavaIdentifier(udt);
        final String fullId = getStrategy().getFullJavaIdentifier(udt);
        out.javadoc("The type <code>%s</code>", udt.getQualifiedOutputName());
        if (scala)
            out.println("%sdef %s = %s", visibility(), id, fullId);
        else if (kotlin)
            out.println("%sval %s: %s = %s", visibility(), id, className, fullId);
        else
            out.println("%sstatic final %s %s = %s;", visibility(), className, id, fullId);
    }
    generateUDTReferencesClassFooter(schemaOrPackage, out);
    if (!kotlin)
        out.println("}");
    closeJavaWriter(out);
    watch.splitInfo("UDT references generated" + logSuffix);
    if (schemaOrPackage instanceof SchemaDefinition)
        for (PackageDefinition pkg : database.getPackages((SchemaDefinition) schemaOrPackage)) if (!pkg.getUDTs().isEmpty())
            generateUDTReferences(pkg);
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) PackageDefinition(org.jooq.meta.PackageDefinition) ArrayList(java.util.ArrayList) UDTDefinition(org.jooq.meta.UDTDefinition)

Aggregations

SchemaDefinition (org.jooq.meta.SchemaDefinition)81 Record (org.jooq.Record)51 ArrayList (java.util.ArrayList)46 TableDefinition (org.jooq.meta.TableDefinition)44 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)22 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)21 ColumnDefinition (org.jooq.meta.ColumnDefinition)14 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)14 IndexDefinition (org.jooq.meta.IndexDefinition)12 SequenceDefinition (org.jooq.meta.SequenceDefinition)12 List (java.util.List)10 DefaultIndexColumnDefinition (org.jooq.meta.DefaultIndexColumnDefinition)10 DomainDefinition (org.jooq.meta.DomainDefinition)9 RoutineDefinition (org.jooq.meta.RoutineDefinition)9 Result (org.jooq.Result)8 AbstractIndexDefinition (org.jooq.meta.AbstractIndexDefinition)8 DefaultCheckConstraintDefinition (org.jooq.meta.DefaultCheckConstraintDefinition)8 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)8 PackageDefinition (org.jooq.meta.PackageDefinition)8 TableType (org.jooq.TableOptions.TableType)7