Search in sources :

Example 6 with TableDefinition

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

the class DefaultGeneratorStrategy method getJavaMethodName.

@Override
public String getJavaMethodName(Definition definition, Mode mode) {
    // for the implicit JOIN path. Otherwise, fall back to the foreign key name
    if (definition instanceof ForeignKeyDefinition) {
        ForeignKeyDefinition fk = (ForeignKeyDefinition) definition;
        TableDefinition referenced = fk.getReferencedTable();
        if (fk.getKeyTable().getForeignKeys(referenced).size() == 1)
            return getJavaMethodName(referenced, mode);
    }
    return getJavaClassName0LC(definition, Mode.DEFAULT);
}
Also used : TableDefinition(org.jooq.meta.TableDefinition) ForeignKeyDefinition(org.jooq.meta.ForeignKeyDefinition)

Example 7 with TableDefinition

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

the class JavaGenerator method getMemberNames.

private Set<String> getMemberNames(SchemaDefinition schema) {
    Set<String> members = new HashSet<>();
    members.add(getStrategy().getJavaIdentifier(schema));
    for (TableDefinition table : schema.getTables()) members.add(getStrategy().getJavaIdentifier(table));
    return members;
}
Also used : TableDefinition(org.jooq.meta.TableDefinition) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 8 with TableDefinition

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

the class GeneratorStrategyWrapper method getJavaIdentifier.

@Override
public String getJavaIdentifier(Definition definition) {
    String identifier = getFixedJavaIdentifier(definition);
    if (identifier != null)
        return identifier;
    identifier = convertToIdentifier(delegate.getJavaIdentifier(definition), getTargetLanguage());
    // [#1212] Don't trust custom strategies and disambiguate identifiers here
    if (definition instanceof ColumnDefinition || definition instanceof AttributeDefinition) {
        TypedElementDefinition<?> e = (TypedElementDefinition<?>) definition;
        if (identifier.equals(getJavaIdentifier(e.getContainer())))
            return identifier + "_";
        // [#2781] Disambiguate collisions with the leading package name
        if (identifier.equals(getJavaPackageName(e.getContainer()).replaceAll("\\..*", "")))
            return identifier + "_";
    } else if (definition instanceof TableDefinition) {
        SchemaDefinition schema = definition.getSchema();
        if (identifier.equals(getJavaIdentifier(schema)))
            return identifier + "_";
    } else // [#5557] Once more, this causes issues...
    if (definition instanceof SchemaDefinition) {
        CatalogDefinition catalog = definition.getCatalog();
        if (identifier.equals(getJavaIdentifier(catalog)))
            return identifier + "_";
    }
    identifier = overload(definition, Mode.DEFAULT, identifier);
    return identifier;
}
Also used : CatalogDefinition(org.jooq.meta.CatalogDefinition) TypedElementDefinition(org.jooq.meta.TypedElementDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) AttributeDefinition(org.jooq.meta.AttributeDefinition) TableDefinition(org.jooq.meta.TableDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition)

Example 9 with TableDefinition

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

the class CUBRIDDatabase method getTables0.

@Override
protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<>();
    for (Record record : create().select(DB_CLASS.CLASS_NAME).from(DB_CLASS).orderBy(DB_CLASS.CLASS_NAME.asc()).fetch()) {
        String name = record.get(DB_CLASS.CLASS_NAME);
        CUBRIDTableDefinition table = new CUBRIDTableDefinition(getSchemata().get(0), name, null);
        result.add(table);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Example 10 with TableDefinition

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

the class FirebirdDatabase method loadForeignKeys.

@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
    Rdb$relationConstraints pk = RDB$RELATION_CONSTRAINTS.as("pk");
    Rdb$relationConstraints fk = RDB$RELATION_CONSTRAINTS.as("fk");
    Rdb$refConstraints rc = RDB$REF_CONSTRAINTS.as("rc");
    Rdb$indexSegments isp = RDB$INDEX_SEGMENTS.as("isp");
    Rdb$indexSegments isf = RDB$INDEX_SEGMENTS.as("isf");
    for (Record record : create().selectDistinct(fk.RDB$CONSTRAINT_NAME.trim().as("fk"), fk.RDB$RELATION_NAME.trim().as("fkTable"), isf.RDB$FIELD_NAME.trim().as("fkField"), pk.RDB$CONSTRAINT_NAME.trim().as("pk"), pk.RDB$RELATION_NAME.trim().as("pkTable")).from(fk).join(rc).on(fk.RDB$CONSTRAINT_NAME.eq(rc.RDB$CONSTRAINT_NAME)).join(pk).on(pk.RDB$CONSTRAINT_NAME.eq(rc.RDB$CONST_NAME_UQ)).join(isp).on(isp.RDB$INDEX_NAME.eq(pk.RDB$INDEX_NAME)).join(isf).on(isf.RDB$INDEX_NAME.eq(fk.RDB$INDEX_NAME)).where(isp.RDB$FIELD_POSITION.eq(isf.RDB$FIELD_POSITION)).orderBy(fk.RDB$CONSTRAINT_NAME.asc(), isf.RDB$FIELD_POSITION.asc()).fetch()) {
        String pkName = record.get("pk", String.class);
        String pkTable = record.get("pkTable", String.class);
        String fkName = record.get("fk", String.class);
        String fkTable = record.get("fkTable", String.class);
        String fkField = record.get("fkField", String.class);
        TableDefinition foreignKeyTable = getTable(getSchemata().get(0), fkTable, true);
        TableDefinition primaryKeyTable = getTable(getSchemata().get(0), pkTable, true);
        if (primaryKeyTable != null && foreignKeyTable != null)
            relations.addForeignKey(fkName, foreignKeyTable, foreignKeyTable.getColumn(fkField), pkName, primaryKeyTable);
    }
}
Also used : TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record) Rdb$relationConstraints(org.jooq.meta.firebird.rdb.tables.Rdb$relationConstraints) Rdb$indexSegments(org.jooq.meta.firebird.rdb.tables.Rdb$indexSegments) Rdb$refConstraints(org.jooq.meta.firebird.rdb.tables.Rdb$refConstraints)

Aggregations

TableDefinition (org.jooq.meta.TableDefinition)67 SchemaDefinition (org.jooq.meta.SchemaDefinition)47 Record (org.jooq.Record)44 ArrayList (java.util.ArrayList)23 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)16 IndexDefinition (org.jooq.meta.IndexDefinition)14 List (java.util.List)12 ColumnDefinition (org.jooq.meta.ColumnDefinition)12 IOException (java.io.IOException)10 DefaultIndexColumnDefinition (org.jooq.meta.DefaultIndexColumnDefinition)10 Result (org.jooq.Result)9 CatalogDefinition (org.jooq.meta.CatalogDefinition)9 EnumDefinition (org.jooq.meta.EnumDefinition)9 RoutineDefinition (org.jooq.meta.RoutineDefinition)9 Arrays.asList (java.util.Arrays.asList)8 TableType (org.jooq.TableOptions.TableType)8 AbstractIndexDefinition (org.jooq.meta.AbstractIndexDefinition)8 DefaultCheckConstraintDefinition (org.jooq.meta.DefaultCheckConstraintDefinition)8 PackageDefinition (org.jooq.meta.PackageDefinition)8 SequenceDefinition (org.jooq.meta.SequenceDefinition)8