Search in sources :

Example 11 with SchemaDefinition

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

the class H2Database method loadCheckConstraints2_0.

private void loadCheckConstraints2_0(DefaultRelations relations) {
    CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
    for (Record record : create().select(cc.tableConstraints().TABLE_SCHEMA, cc.tableConstraints().TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE).from(cc).where(cc.tableConstraints().TABLE_SCHEMA.in(getInputSchemata()))) {
        SchemaDefinition schema = getSchema(record.get(cc.tableConstraints().TABLE_SCHEMA));
        TableDefinition table = getTable(schema, record.get(cc.tableConstraints().TABLE_NAME));
        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) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record) DefaultCheckConstraintDefinition(org.jooq.meta.DefaultCheckConstraintDefinition) CheckConstraints(org.jooq.meta.hsqldb.information_schema.tables.CheckConstraints)

Example 12 with SchemaDefinition

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

the class H2Database method getRoutines1_4.

private List<RoutineDefinition> getRoutines1_4() {
    List<RoutineDefinition> result = new ArrayList<>();
    Field<Boolean> overloaded = field(select(field(DSL.exists(select(one()).from(FUNCTION_ALIASES.as("a")).where(field(name("a", FUNCTION_ALIASES.ALIAS_SCHEMA.getName())).eq(FUNCTION_ALIASES.ALIAS_SCHEMA)).and(field(name("a", FUNCTION_ALIASES.ALIAS_NAME.getName())).eq(FUNCTION_ALIASES.ALIAS_NAME)).and(field(name("a", FUNCTION_ALIASES.COLUMN_COUNT.getName())).ne(FUNCTION_ALIASES.COLUMN_COUNT)))))).as("overloaded");
    for (Record record : create().select(FUNCTION_ALIASES.ALIAS_SCHEMA, FUNCTION_ALIASES.ALIAS_NAME, FUNCTION_ALIASES.REMARKS, FUNCTION_ALIASES.DATA_TYPE, FUNCTION_ALIASES.RETURNS_RESULT, FUNCTION_ALIASES.COLUMN_COUNT, overloaded, TYPE_INFO.TYPE_NAME, TYPE_INFO.PRECISION, TYPE_INFO.MAXIMUM_SCALE).from(FUNCTION_ALIASES).leftOuterJoin(TYPE_INFO).on(FUNCTION_ALIASES.DATA_TYPE.equal(TYPE_INFO.DATA_TYPE)).and(TYPE_INFO.POS.equal(0)).where(FUNCTION_ALIASES.ALIAS_SCHEMA.in(getInputSchemata())).and(FUNCTION_ALIASES.RETURNS_RESULT.in((short) 1, (short) 2)).orderBy(FUNCTION_ALIASES.ALIAS_NAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(FUNCTION_ALIASES.ALIAS_SCHEMA));
        if (schema != null) {
            String name = record.get(FUNCTION_ALIASES.ALIAS_NAME);
            String comment = record.get(FUNCTION_ALIASES.REMARKS);
            String typeName = record.get(TYPE_INFO.TYPE_NAME);
            Integer precision = record.get(TYPE_INFO.PRECISION);
            Short scale = record.get(TYPE_INFO.MAXIMUM_SCALE);
            String overload = record.get(overloaded) ? record.get(FUNCTION_ALIASES.COLUMN_COUNT, String.class) : null;
            result.add(new H2RoutineDefinition(schema, name, null, typeName, precision, scale, comment, overload));
        }
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.meta.RoutineDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Example 13 with SchemaDefinition

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

the class HSQLDBDatabase method getTables0.

@Override
protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<>();
    for (Record record : create().select(SYSTEM_TABLES.TABLE_SCHEM, SYSTEM_TABLES.TABLE_NAME, inline("").as(ROUTINES.SPECIFIC_NAME), SYSTEM_TABLES.REMARKS, when(SYSTEM_TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name())).else_(inline(TableType.TABLE.name())).trim().as("table_type"), when(VIEWS.VIEW_DEFINITION.lower().like(inline("create%")), VIEWS.VIEW_DEFINITION).else_(inline("create view \"").concat(SYSTEM_TABLES.TABLE_NAME).concat("\" as ").concat(VIEWS.VIEW_DEFINITION)).as(VIEWS.VIEW_DEFINITION)).from(SYSTEM_TABLES).leftJoin(VIEWS).on(SYSTEM_TABLES.TABLE_SCHEM.eq(VIEWS.TABLE_SCHEMA)).and(SYSTEM_TABLES.TABLE_NAME.eq(VIEWS.TABLE_NAME)).where(SYSTEM_TABLES.TABLE_SCHEM.in(getInputSchemata())).unionAll(tableValuedFunctions() ? select(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME, ROUTINES.SPECIFIC_NAME, inline(""), inline(TableType.FUNCTION.name()), ROUTINES.ROUTINE_DEFINITION).from(ROUTINES).where(ROUTINES.ROUTINE_SCHEMA.in(getInputSchemata())).and(ROUTINES.ROUTINE_TYPE.eq(inline("FUNCTION"))).and(ROUTINES.DATA_TYPE.startsWith(inline("ROW("))) : select(inline(""), inline(""), inline(""), inline(""), inline(TableType.FUNCTION.name()), inline("")).where(falseCondition())).orderBy(SYSTEM_TABLES.TABLE_SCHEM, SYSTEM_TABLES.TABLE_NAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(SYSTEM_TABLES.TABLE_SCHEM));
        String name = record.get(SYSTEM_TABLES.TABLE_NAME);
        String specificName = record.get(ROUTINES.SPECIFIC_NAME);
        String comment = record.get(SYSTEM_TABLES.REMARKS);
        TableType tableType = record.get("table_type", TableType.class);
        String source = record.get(VIEWS.VIEW_DEFINITION);
        if (tableType == TableType.FUNCTION)
            result.add(new HSQLDBTableValuedFunction(schema, name, specificName, comment, source));
        else
            result.add(new HSQLDBTableDefinition(schema, name, comment, tableType, source));
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableType(org.jooq.TableOptions.TableType) ArrayList(java.util.ArrayList) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Example 14 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition 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 15 with SchemaDefinition

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

the class HSQLDBDatabase method getIndexes0.

@Override
protected List<IndexDefinition> getIndexes0() throws SQLException {
    List<IndexDefinition> result = new ArrayList<>();
    // Same implementation as in H2Database and MySQLDatabase
    Map<Record, Result<Record>> indexes = create().select(SYSTEM_INDEXINFO.TABLE_SCHEM, SYSTEM_INDEXINFO.TABLE_NAME, SYSTEM_INDEXINFO.INDEX_NAME, SYSTEM_INDEXINFO.NON_UNIQUE, SYSTEM_INDEXINFO.COLUMN_NAME, SYSTEM_INDEXINFO.ORDINAL_POSITION, SYSTEM_INDEXINFO.ASC_OR_DESC).from(SYSTEM_INDEXINFO).where(SYSTEM_INDEXINFO.TABLE_SCHEM.in(getInputSchemata())).and(getIncludeSystemIndexes() ? noCondition() : SYSTEM_INDEXINFO.INDEX_NAME.notLike("SYS!_IDX!_%", '!')).orderBy(SYSTEM_INDEXINFO.TABLE_SCHEM, SYSTEM_INDEXINFO.TABLE_NAME, SYSTEM_INDEXINFO.INDEX_NAME, SYSTEM_INDEXINFO.ORDINAL_POSITION).fetchGroups(new Field[] { SYSTEM_INDEXINFO.TABLE_SCHEM, SYSTEM_INDEXINFO.TABLE_NAME, SYSTEM_INDEXINFO.INDEX_NAME, SYSTEM_INDEXINFO.NON_UNIQUE }, new Field[] { SYSTEM_INDEXINFO.COLUMN_NAME, SYSTEM_INDEXINFO.ORDINAL_POSITION, SYSTEM_INDEXINFO.ASC_OR_DESC });
    indexLoop: for (Entry<Record, Result<Record>> entry : indexes.entrySet()) {
        final Record index = entry.getKey();
        final Result<Record> cols = entry.getValue();
        final SchemaDefinition tableSchema = getSchema(index.get(SYSTEM_INDEXINFO.TABLE_SCHEM));
        if (tableSchema == null)
            continue indexLoop;
        final String indexName = index.get(SYSTEM_INDEXINFO.INDEX_NAME);
        final String tableName = index.get(SYSTEM_INDEXINFO.TABLE_NAME);
        final TableDefinition table = getTable(tableSchema, tableName);
        if (table == null)
            continue indexLoop;
        final boolean unique = !index.get(SYSTEM_INDEXINFO.NON_UNIQUE, boolean.class);
        // [#6310] [#6620] Function-based indexes are not yet supported
        for (Record column : cols) if (table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)) == null)
            continue indexLoop;
        result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {

            List<IndexColumnDefinition> indexColumns = new ArrayList<>();

            {
                for (Record column : cols) {
                    indexColumns.add(new DefaultIndexColumnDefinition(this, table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)), "D".equals(column.get(SYSTEM_INDEXINFO.ASC_OR_DESC)) ? SortOrder.DESC : SortOrder.ASC, column.get(SYSTEM_INDEXINFO.ORDINAL_POSITION, int.class)));
                }
            }

            @Override
            protected List<IndexColumnDefinition> getIndexColumns0() {
                return indexColumns;
            }
        });
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) ArrayList(java.util.ArrayList) Result(org.jooq.Result) DefaultIndexColumnDefinition(org.jooq.meta.DefaultIndexColumnDefinition) IndexColumnDefinition(org.jooq.meta.IndexColumnDefinition) Entry(java.util.Map.Entry) AbstractIndexDefinition(org.jooq.meta.AbstractIndexDefinition) IndexDefinition(org.jooq.meta.IndexDefinition) AbstractIndexDefinition(org.jooq.meta.AbstractIndexDefinition) DefaultIndexColumnDefinition(org.jooq.meta.DefaultIndexColumnDefinition) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record) List(java.util.List) ArrayList(java.util.ArrayList)

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