use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class JavaGenerator method printReferences.
protected void printReferences(JavaWriter out, List<? extends Definition> definitions, Class<?> type, boolean isGeneric) {
if (out != null && !definitions.isEmpty()) {
final String generic = isGeneric ? (scala ? "[_]" : kotlin ? "<*>" : "<?>") : "";
final List<String> references = new ArrayList<>();
final Definition first = definitions.get(0);
// members in this class. Java can resolve the ambiguity.
if ((scala || kotlin) && (first instanceof TableDefinition || first instanceof UDTDefinition)) {
final Set<String> memberNames = getMemberNames(first.getSchema());
for (Definition table : definitions) references.add(getShortId(out, memberNames, table));
} else if ((scala || kotlin) && first instanceof SchemaDefinition) {
final Set<String> memberNames = getMemberNames(first.getCatalog());
for (Definition schema : definitions) references.add(getShortId(out, memberNames, schema));
} else {
references.addAll(kotlin ? out.ref(getStrategy().getFullJavaIdentifiers(definitions)) : out.ref(getStrategy().getFullJavaIdentifiers(definitions), 2));
}
out.println();
if (scala) {
if (definitions.size() > maxMembersPerInitialiser()) {
out.println("%soverride def get%ss: %s[%s%s] = {", visibilityPublic(), type.getSimpleName(), List.class, type, generic);
out.println("val result = new %s[%s%s]", ArrayList.class, type, generic);
for (int i = 0; i < definitions.size(); i += maxMembersPerInitialiser()) out.println("result.addAll(get%ss%s)", type.getSimpleName(), i / maxMembersPerInitialiser());
out.println("result");
out.println("}");
} else {
out.println("%soverride def get%ss: %s[%s%s] = %s.asList[%s%s](", visibilityPublic(), type.getSimpleName(), List.class, type, generic, Arrays.class, type, generic);
out.println("[[separator=,\n][%s]]", references);
out.println(")");
}
} else if (kotlin) {
if (definitions.size() > maxMembersPerInitialiser()) {
out.println("%soverride fun get%ss(): %s<%s%s> {", visibilityPublic(), type.getSimpleName(), out.ref(KLIST), type, generic);
out.println("val result = mutableListOf<%s%s>()", type, generic);
for (int i = 0; i < definitions.size(); i += maxMembersPerInitialiser()) out.println("result.addAll(get%ss%s())", type.getSimpleName(), i / maxMembersPerInitialiser());
out.println("return result");
out.println("}");
} else {
out.println("%soverride fun get%ss(): %s<%s%s> = listOf(", visibilityPublic(), type.getSimpleName(), out.ref(KLIST), type, generic);
out.println("[[separator=,\n][%s]]", references);
out.println(")");
}
} else {
out.override();
printNonnullAnnotation(out);
out.println("%sfinal %s<%s%s> get%ss() {", visibilityPublic(), List.class, type, generic, type.getSimpleName());
if (definitions.size() > maxMembersPerInitialiser()) {
out.println("%s result = new %s();", List.class, ArrayList.class);
for (int i = 0; i < definitions.size(); i += maxMembersPerInitialiser()) out.println("result.addAll(get%ss%s());", type.getSimpleName(), i / maxMembersPerInitialiser());
out.println("return result;");
} else {
out.println("return %s.asList(", Arrays.class);
out.println("[[separator=,\n][%s]]", references);
out.println(");");
}
out.println("}");
}
if (definitions.size() > maxMembersPerInitialiser()) {
for (int i = 0; i < definitions.size(); i += maxMembersPerInitialiser()) {
out.println();
if (scala) {
out.println("private def get%ss%s(): %s[%s%s] = %s.asList[%s%s](", type.getSimpleName(), i / maxMembersPerInitialiser(), List.class, type, generic, Arrays.class, type, generic);
out.println("[[separator=,\n][%s]]", references.subList(i, Math.min(i + maxMembersPerInitialiser(), references.size())));
out.println(")");
} else if (kotlin) {
out.println("private fun get%ss%s(): %s<%s%s> = listOf(", type.getSimpleName(), i / maxMembersPerInitialiser(), out.ref(KLIST), type, generic);
out.println("[[separator=,\n][%s]]", references.subList(i, Math.min(i + maxMembersPerInitialiser(), references.size())));
out.println(")");
} else {
out.println("private final %s<%s%s> get%ss%s() {", List.class, type, generic, type.getSimpleName(), i / maxMembersPerInitialiser());
out.println("return %s.asList(", Arrays.class);
out.println("[[separator=,\n][%s]]", references.subList(i, Math.min(i + maxMembersPerInitialiser(), references.size())));
out.println(");");
out.println("}");
}
}
}
}
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class JavaGenerator method getMemberNames.
private Set<String> getMemberNames(CatalogDefinition catalog) {
Set<String> members = new HashSet<>();
members.add(getStrategy().getJavaIdentifier(catalog));
for (SchemaDefinition table : catalog.getSchemata()) members.add(getStrategy().getJavaIdentifier(table));
return members;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchemata().get(0);
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, FirebirdDataType.BIGINT.getTypeName());
result.add(new DefaultSequenceDefinition(schema, record.get(RDB$GENERATORS.RDB$GENERATOR_NAME), type, null, record.get(RDB$GENERATORS.RDB$INITIAL_VALUE), record.get(RDB$GENERATORS.RDB$GENERATOR_INCREMENT), null, null, false, null));
}
return result;
}
use of org.jooq.meta.SchemaDefinition 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.SchemaDefinition 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)));
}
}
}
Aggregations