use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method getIndexes0.
@Override
protected List<IndexDefinition> getIndexes0() throws SQLException {
final List<IndexDefinition> result = new ArrayList<>();
final Rdb$relationConstraints c = RDB$RELATION_CONSTRAINTS.as("c");
final Rdb$indices i = RDB$INDICES.as("i");
final Rdb$indexSegments s = RDB$INDEX_SEGMENTS.as("s");
Map<Record, Result<Record>> indexes = create().select(s.rdb$indices().RDB$RELATION_NAME.trim().as(i.RDB$RELATION_NAME), s.rdb$indices().RDB$INDEX_NAME.trim().as(i.RDB$INDEX_NAME), s.rdb$indices().RDB$UNIQUE_FLAG, s.RDB$FIELD_NAME.trim().as(s.RDB$FIELD_NAME), s.RDB$FIELD_POSITION).from(s).where(s.rdb$indices().RDB$INDEX_NAME.notIn(select(c.RDB$CONSTRAINT_NAME).from(c))).orderBy(s.rdb$indices().RDB$RELATION_NAME, s.rdb$indices().RDB$INDEX_NAME, s.RDB$FIELD_POSITION).fetchGroups(new Field[] { i.RDB$RELATION_NAME, i.RDB$INDEX_NAME, i.RDB$UNIQUE_FLAG }, new Field[] { s.RDB$FIELD_NAME, s.RDB$FIELD_POSITION });
indexLoop: for (Entry<Record, Result<Record>> entry : indexes.entrySet()) {
final Record index = entry.getKey();
final Result<Record> columns = entry.getValue();
final SchemaDefinition schema = getSchemata().get(0);
final String indexName = index.get(i.RDB$INDEX_NAME);
final String tableName = index.get(i.RDB$RELATION_NAME);
final TableDefinition table = getTable(schema, tableName);
if (table == null)
continue indexLoop;
final boolean unique = index.get(i.RDB$UNIQUE_FLAG, boolean.class);
// [#6310] [#6620] Function-based indexes are not yet supported
for (Record column : columns) if (table.getColumn(column.get(s.RDB$FIELD_NAME)) == null)
continue indexLoop;
result.add(new AbstractIndexDefinition(schema, indexName, table, unique) {
List<IndexColumnDefinition> indexColumns = new ArrayList<>();
{
for (Record column : columns) {
indexColumns.add(new DefaultIndexColumnDefinition(this, table.getColumn(column.get(s.RDB$FIELD_NAME)), SortOrder.ASC, column.get(s.RDB$FIELD_POSITION, int.class)));
}
}
@Override
protected List<IndexColumnDefinition> getIndexColumns0() {
return indexColumns;
}
});
}
return result;
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method loadCheckConstraints.
@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
Rdb$relationConstraints r = RDB$RELATION_CONSTRAINTS.as("r");
Rdb$checkConstraints c = RDB$CHECK_CONSTRAINTS.as("c");
Rdb$triggers t = RDB$TRIGGERS.as("t");
// for RDB$TRIGGER_TYPE 1 (before insert) and 3 (before update)
for (Record record : create().select(r.RDB$RELATION_NAME.trim().as(r.RDB$RELATION_NAME), r.RDB$CONSTRAINT_NAME.trim().as(r.RDB$CONSTRAINT_NAME), max(t.RDB$TRIGGER_SOURCE.trim()).as(t.RDB$TRIGGER_SOURCE)).from(r).join(c).on(r.RDB$CONSTRAINT_NAME.eq(c.RDB$CONSTRAINT_NAME)).join(t).on(c.RDB$TRIGGER_NAME.eq(t.RDB$TRIGGER_NAME)).where(r.RDB$CONSTRAINT_TYPE.eq(inline("CHECK"))).groupBy(r.RDB$RELATION_NAME, r.RDB$CONSTRAINT_NAME).orderBy(r.RDB$RELATION_NAME, r.RDB$CONSTRAINT_NAME)) {
SchemaDefinition schema = getSchemata().get(0);
TableDefinition table = getTable(schema, record.get(r.RDB$RELATION_NAME));
if (table != null) {
relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(r.RDB$CONSTRAINT_NAME), record.get(t.RDB$TRIGGER_SOURCE)));
}
}
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations r) throws SQLException {
for (Record record : primaryKeys(Collections.<String>emptyList())) {
String tableName = record.get(RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME);
String fieldName = record.get(RDB$INDEX_SEGMENTS.RDB$FIELD_NAME);
String key = record.get(RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_NAME);
TableDefinition td = getTable(this.getSchemata().get(0), tableName);
if (td != null)
r.addPrimaryKey(key, td, td.getColumn(fieldName));
}
}
use of org.jooq.meta.TableDefinition 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.TableDefinition 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)));
}
}
}
Aggregations