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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations