use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateSchema.
protected void generateSchema(SchemaDefinition schema, JavaWriter out) {
final String catalogId = out.ref(getStrategy().getFullJavaIdentifier(schema.getCatalog()), 2);
final String schemaId = getStrategy().getJavaIdentifier(schema);
final String schemaName = !schema.getQualifiedOutputName().isEmpty() ? schema.getQualifiedOutputName() : schemaId;
final String className = getStrategy().getJavaClassName(schema);
final List<String> interfaces = out.ref(getStrategy().getJavaClassImplements(schema, Mode.DEFAULT));
printPackage(out, schema);
if (scala) {
out.println("object %s {", className);
out.javadoc("The reference instance of <code>%s</code>", schemaName);
out.println("val %s = new %s", schemaId, className);
out.println("}");
out.println();
}
generateSchemaClassJavadoc(schema, out);
printClassAnnotations(out, schema, Mode.DEFAULT);
if (scala) {
out.println("%sclass %s extends %s(\"%s\", %s)[[before= with ][separator= with ][%s]] {", visibility(), className, SchemaImpl.class, escapeString(schema.getOutputName()), catalogId, interfaces);
} else if (kotlin) {
out.println("%sopen class %s : %s(\"%s\", %s)[[before=, ][%s]] {", visibility(), className, SchemaImpl.class, escapeString(schema.getOutputName()), catalogId, interfaces);
out.println("public companion object {");
out.javadoc("The reference instance of <code>%s</code>", schemaName);
out.println("%sval %s: %s = %s()", visibility(), scalaWhitespaceSuffix(schemaId), className, className);
out.println("}");
} else {
out.println("%sclass %s extends %s[[before= implements ][%s]] {", visibility(), className, SchemaImpl.class, interfaces);
out.printSerial();
out.javadoc("The reference instance of <code>%s</code>", schemaName);
out.println("%sstatic final %s %s = new %s();", visibility(), className, schemaId, className);
}
if (generateGlobalTableReferences()) {
Set<String> memberNames = getMemberNames(schema);
for (TableDefinition table : schema.getTables()) {
// reference in the schema, and the function call
if (scala && table.isTableValuedFunction() && table.getParameters().isEmpty())
continue;
final String tableClassName = out.ref(getStrategy().getFullJavaClassName(table));
final String tableId = getStrategy().getJavaIdentifier(table);
final String tableShortId = getShortId(out, memberNames, table);
final String tableComment = escapeEntities(comment(table));
out.javadoc(isBlank(tableComment) ? "The table <code>" + table.getQualifiedOutputName() + "</code>." : tableComment);
if (scala)
out.println("%sdef %s = %s", visibility(), tableId, tableShortId);
else if (kotlin)
out.println("%sval %s: %s get() = %s", visibility(), scalaWhitespaceSuffix(tableId), tableClassName, tableShortId);
else
out.println("%sfinal %s %s = %s;", visibility(), tableClassName, tableId, tableShortId);
// globalObjectReferences
if (table.isTableValuedFunction())
printTableValuedFunction(out, table, getStrategy().getJavaIdentifier(table));
}
}
if (!scala && !kotlin) {
out.javadoc(NO_FURTHER_INSTANCES_ALLOWED);
out.println("private %s() {", className);
out.println("super(\"%s\", null);", escapeString(schema.getOutputName()));
out.println("}");
}
out.println();
if (scala) {
out.println("%soverride def getCatalog: %s = %s", visibilityPublic(), Catalog.class, catalogId);
} else if (kotlin) {
out.println("%soverride fun getCatalog(): %s = %s", visibilityPublic(), Catalog.class, catalogId);
} else {
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s getCatalog() {", visibilityPublic(), Catalog.class);
out.println("return %s;", catalogId);
out.println("}");
}
// [#2255] Avoid referencing sequence literals, if they're not generated
if (generateGlobalSequenceReferences())
printReferences(out, database.getSequences(schema), Sequence.class, true);
// [#681] Avoid referencing domain literals, if they're not generated
if (generateGlobalDomainReferences())
printReferences(out, database.getDomains(schema), Domain.class, true);
// [#9685] Avoid referencing table literals if they're not generated
if (generateTables())
printReferences(out, database.getTables(schema), Table.class, true);
// [#9685] Avoid referencing UDT literals if they're not generated
if (generateUDTs())
printReferences(out, database.getUDTs(schema), UDT.class, true);
generateSchemaClassFooter(schema, out);
out.println("}");
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generatePojos.
protected void generatePojos(SchemaDefinition schema) {
log.info("Generating table POJOs");
for (TableDefinition table : database.getTables(schema)) {
try {
generatePojo(table);
} catch (Exception e) {
log.error("Error while generating table POJO " + table, e);
}
}
watch.splitInfo("Table POJOs generated");
}
use of org.jooq.meta.TableDefinition 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.TableDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateRecords.
protected void generateRecords(SchemaDefinition schema) {
log.info("Generating table records");
for (TableDefinition table : database.getTables(schema)) {
try {
generateRecord(table);
} catch (Exception e) {
log.error("Error while generating table record " + table, e);
}
}
watch.splitInfo("Table records generated");
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations r) throws SQLException {
for (Record record : uniqueKeys(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.addUniqueKey(key, td, td.getColumn(fieldName));
}
}
Aggregations