Search in sources :

Example 41 with SchemaDefinition

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

the class FirebirdDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (String sequenceName : create().select(RDB$GENERATORS.RDB$GENERATOR_NAME.trim()).from(RDB$GENERATORS).orderBy(1).fetch(RDB$GENERATORS.RDB$GENERATOR_NAME.trim())) {
        SchemaDefinition schema = getSchemata().get(0);
        DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, FirebirdDataType.BIGINT.getTypeName());
        result.add(new DefaultSequenceDefinition(schema, sequenceName, type));
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition)

Example 42 with SchemaDefinition

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

the class H2Database method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (Record record : create().select(Sequences.SEQUENCE_SCHEMA, Sequences.SEQUENCE_NAME).from(SEQUENCES).where(Sequences.SEQUENCE_SCHEMA.in(getInputSchemata())).orderBy(Sequences.SEQUENCE_SCHEMA, Sequences.SEQUENCE_NAME).fetch()) {
        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));
        }
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Example 43 with SchemaDefinition

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

the class H2Database method loadForeignKeys.

@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
    for (Record record : create().select(CrossReferences.FK_NAME, CrossReferences.FKTABLE_NAME, CrossReferences.FKTABLE_SCHEMA, CrossReferences.FKCOLUMN_NAME, Constraints.CONSTRAINT_NAME, Constraints.CONSTRAINT_SCHEMA).from(CROSS_REFERENCES).join(CONSTRAINTS).on(CrossReferences.PK_NAME.equal(Constraints.UNIQUE_INDEX_NAME)).and(CrossReferences.PKTABLE_NAME.equal(Constraints.TABLE_NAME)).and(CrossReferences.PKTABLE_SCHEMA.equal(Constraints.TABLE_SCHEMA)).where(CrossReferences.FKTABLE_SCHEMA.in(getInputSchemata())).and(Constraints.CONSTRAINT_TYPE.in("PRIMARY KEY", "UNIQUE")).orderBy(CrossReferences.FKTABLE_SCHEMA.asc(), CrossReferences.FK_NAME.asc(), CrossReferences.ORDINAL_POSITION.asc()).fetch()) {
        SchemaDefinition foreignKeySchema = getSchema(record.get(CrossReferences.FKTABLE_SCHEMA));
        SchemaDefinition uniqueKeySchema = getSchema(record.get(Constraints.CONSTRAINT_SCHEMA));
        if (foreignKeySchema != null && uniqueKeySchema != null) {
            String foreignKeyTableName = record.get(CrossReferences.FKTABLE_NAME);
            String foreignKeyColumn = record.get(CrossReferences.FKCOLUMN_NAME);
            String foreignKey = record.get(CrossReferences.FK_NAME);
            String uniqueKey = record.get(Constraints.CONSTRAINT_NAME);
            TableDefinition foreignKeyTable = getTable(foreignKeySchema, foreignKeyTableName);
            if (foreignKeyTable != null) {
                ColumnDefinition referencingColumn = foreignKeyTable.getColumn(foreignKeyColumn);
                relations.addForeignKey(foreignKey, uniqueKey, referencingColumn, uniqueKeySchema);
            }
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record) ColumnDefinition(org.jooq.util.ColumnDefinition)

Example 44 with SchemaDefinition

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

the class H2Database method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys("PRIMARY KEY")) {
        SchemaDefinition schema = getSchema(record.get(Constraints.TABLE_SCHEMA));
        if (schema != null) {
            String tableName = record.get(Constraints.TABLE_NAME);
            String primaryKey = record.get(Constraints.CONSTRAINT_NAME);
            String columnName = record.get(Indexes.COLUMN_NAME);
            TableDefinition table = getTable(schema, tableName);
            if (table != null) {
                relations.addPrimaryKey(primaryKey, table.getColumn(columnName));
            }
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 45 with SchemaDefinition

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

the class HSQLDBDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (Record record : create().select(SEQUENCES.SEQUENCE_SCHEMA, SEQUENCES.SEQUENCE_NAME, SEQUENCES.DATA_TYPE).from(SEQUENCES).where(SEQUENCES.SEQUENCE_SCHEMA.in(getInputSchemata())).orderBy(SEQUENCES.SEQUENCE_SCHEMA, SEQUENCES.SEQUENCE_NAME).fetch()) {
        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.util.DefaultSequenceDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition)

Aggregations

SchemaDefinition (org.jooq.util.SchemaDefinition)51 Record (org.jooq.Record)36 ArrayList (java.util.ArrayList)29 TableDefinition (org.jooq.util.TableDefinition)28 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)14 DataTypeDefinition (org.jooq.util.DataTypeDefinition)13 ColumnDefinition (org.jooq.util.ColumnDefinition)12 DefaultSequenceDefinition (org.jooq.util.DefaultSequenceDefinition)7 SequenceDefinition (org.jooq.util.SequenceDefinition)7 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)4 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)4 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)3 RoutineDefinition (org.jooq.util.RoutineDefinition)3 KeyColumnUsage (org.jooq.util.xml.jaxb.KeyColumnUsage)3 Record6 (org.jooq.Record6)2 Schema (org.jooq.Schema)2 DefaultCheckConstraintDefinition (org.jooq.util.DefaultCheckConstraintDefinition)2 DefaultEnumDefinition (org.jooq.util.DefaultEnumDefinition)2 EnumDefinition (org.jooq.util.EnumDefinition)2 Columns (org.jooq.util.postgres.information_schema.tables.Columns)2