use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method getDomains0.
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
List<DomainDefinition> result = new ArrayList<>();
Rdb$fields f = RDB$FIELDS;
for (Record record : create().select(trim(f.RDB$FIELD_NAME).as(f.RDB$FIELD_NAME), CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), DSL.bitOr(f.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(f.RDB$NULL_FLAG), trim(f.RDB$VALIDATION_SOURCE).as(f.RDB$VALIDATION_SOURCE), trim(f.RDB$DEFAULT_SOURCE).as(f.RDB$DEFAULT_SOURCE)).from(f).where(f.RDB$FIELD_NAME.notLike(any("RDB$%", "SEC$%", "MON$%"))).orderBy(f.RDB$FIELD_NAME)) {
SchemaDefinition schema = getSchemata().get(0);
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(f.RDB$NULL_FLAG) == 0, record.get(f.RDB$DEFAULT_SOURCE) == null ? null : record.get(f.RDB$DEFAULT_SOURCE).replaceAll("(?i:default )", ""));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(f.RDB$FIELD_NAME), baseType);
if (!StringUtils.isBlank(record.get(f.RDB$VALIDATION_SOURCE)))
domain.addCheckClause(record.get(f.RDB$VALIDATION_SOURCE).replaceAll("(?i:check )", ""));
result.add(domain);
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method getSchemata0.
@Override
protected List<SchemaDefinition> getSchemata0() throws SQLException {
List<SchemaDefinition> result = new ArrayList<>();
result.add(new SchemaDefinition(this, "", ""));
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class DerbyDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys("P")) {
SchemaDefinition schema = getSchema(record.get(SYSSCHEMAS.SCHEMANAME));
String key = record.get(SYSCONSTRAINTS.CONSTRAINTNAME);
String tableName = record.get(SYSTABLES.TABLENAME);
String descriptor = record.get(SYSCONGLOMERATES.DESCRIPTOR, String.class);
TableDefinition table = getTable(schema, tableName);
if (table != null)
for (int index : decode(descriptor)) relations.addPrimaryKey(key, table, table.getColumn(index));
}
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class DerbyDatabase method loadCheckConstraints.
@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
for (Record record : create().select(SYSCHECKS.sysconstraints().systables().sysschemas().SCHEMANAME, SYSCHECKS.sysconstraints().systables().TABLENAME, SYSCHECKS.sysconstraints().CONSTRAINTNAME, SYSCHECKS.CHECKDEFINITION).from(SYSCHECKS).where(SYSCHECKS.sysconstraints().systables().sysschemas().SCHEMANAME.in(getInputSchemata()))) {
SchemaDefinition schema = getSchema(record.get(SYSCHECKS.sysconstraints().systables().sysschemas().SCHEMANAME));
TableDefinition table = getTable(schema, record.get(SYSCHECKS.sysconstraints().systables().TABLENAME));
if (table != null) {
relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(SYSCHECKS.sysconstraints().CONSTRAINTNAME), record.get(SYSCHECKS.CHECKDEFINITION)));
}
}
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class DerbyDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (Record record : create().select(SYSTABLES.sysschemas().SCHEMANAME, SYSTABLES.TABLENAME, SYSTABLES.TABLEID, when(SYSTABLES.TABLETYPE.eq(inline("V")), inline(TableType.VIEW.name())).else_(inline(TableType.TABLE.name())).as("table_type"), SYSVIEWS.VIEWDEFINITION).from(SYSTABLES).leftJoin(SYSVIEWS).on(SYSTABLES.TABLEID.eq(SYSVIEWS.TABLEID)).where(SYSTABLES.sysschemas().SCHEMANAME.cast(VARCHAR(32672)).in(getInputSchemata())).orderBy(SYSTABLES.sysschemas().SCHEMANAME, SYSTABLES.TABLENAME)) {
SchemaDefinition schema = getSchema(record.get(SYSTABLES.sysschemas().SCHEMANAME));
String name = record.get(SYSTABLES.TABLENAME);
String id = record.get(SYSTABLES.TABLEID);
TableType tableType = record.get("table_type", TableType.class);
String source = record.get(SYSVIEWS.VIEWDEFINITION);
DerbyTableDefinition table = new DerbyTableDefinition(schema, name, id, tableType, source);
result.add(table);
}
return result;
}
Aggregations