use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generate.
private void generate(CatalogDefinition catalog) {
String newVersion = catalog.getDatabase().getCatalogVersionProvider().version(catalog);
if (StringUtils.isBlank(newVersion)) {
log.info("No schema version is applied for catalog " + catalog.getInputName() + ". Regenerating.");
} else {
catalogVersions.put(catalog, newVersion);
String oldVersion = readVersion(getFile(catalog), "catalog");
if (StringUtils.isBlank(oldVersion)) {
log.info("No previous version available for catalog " + catalog.getInputName() + ". Regenerating.");
} else if (!oldVersion.equals(newVersion)) {
log.info("Existing version " + oldVersion + " is not up to date with " + newVersion + " for catalog " + catalog.getInputName() + ". Regenerating.");
} else {
log.info("Existing version " + oldVersion + " is up to date with " + newVersion + " for catalog " + catalog.getInputName() + ". Ignoring catalog.");
// [#5614] If a catalog is not regenerated, we must flag it as "not for removal", because its contents
// will not be listed in the files directory.
directoriesNotForRemoval.add(getFile(catalog).getParentFile());
return;
}
}
generateCatalog(catalog);
log.info("Generating schemata", "Total: " + catalog.getSchemata().size());
for (SchemaDefinition schema : catalog.getSchemata()) {
try {
if (generateSchemaIfEmpty(schema))
generate(schema);
else
log.info("Excluding empty schema", schema);
} catch (Exception e) {
throw new GeneratorException("Error generating code for schema " + schema, e);
}
}
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateUDT.
protected void generateUDT(UDTDefinition udt, JavaWriter out) {
final SchemaDefinition schema = udt.getSchema();
final PackageDefinition pkg = udt.getPackage();
final boolean synthetic = udt.isSynthetic();
final String className = getStrategy().getJavaClassName(udt);
final String recordType = out.ref(getStrategy().getFullJavaClassName(udt, Mode.RECORD));
final List<String> interfaces = out.ref(getStrategy().getJavaClassImplements(udt, Mode.DEFAULT));
final String schemaId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
final String packageId = pkg == null ? null : out.ref(getStrategy().getFullJavaIdentifier(pkg), 2);
final String udtId = out.ref(getStrategy().getJavaIdentifier(udt), 2);
printPackage(out, udt);
if (scala) {
out.println("object %s {", className);
printSingletonInstance(out, udt);
for (AttributeDefinition attribute : udt.getAttributes()) {
final String attrId = out.ref(getStrategy().getJavaIdentifier(attribute), 2);
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
out.println("val %s = %s.%s", attrId, udtId, attrId);
}
out.println("}");
out.println();
}
generateUDTClassJavadoc(udt, out);
printClassAnnotations(out, udt, Mode.DEFAULT);
if (scala) {
out.println("%sclass %s extends %s[%s](\"%s\", null, %s, %s)[[before= with ][separator= with ][%s]] {", visibility(), className, UDTImpl.class, recordType, escapeString(udt.getOutputName()), packageId, synthetic, interfaces);
} else if (kotlin) {
out.println("%sopen class %s : %s<%s>(\"%s\", null, %s, %s)[[before=, ][%s]] {", visibility(), className, UDTImpl.class, recordType, escapeString(udt.getOutputName()), packageId, synthetic, interfaces);
out.println();
out.println("public companion object {");
out.javadoc("The reference instance of <code>%s</code>", udt.getQualifiedOutputName());
out.println("public val %s: %s = %s()", getStrategy().getJavaIdentifier(udt), className, className);
out.println("}");
} else {
out.println("%sclass %s extends %s<%s>[[before= implements ][%s]] {", visibility(), className, UDTImpl.class, recordType, interfaces);
out.printSerial();
printSingletonInstance(out, udt);
}
printRecordTypeMethod(out, udt);
for (AttributeDefinition attribute : udt.getAttributes()) {
final String attrTypeFull = getJavaType(attribute.getType(resolver(out)), out);
final String attrType = out.ref(attrTypeFull);
final String attrTypeRef = getJavaTypeReference(attribute.getDatabase(), attribute.getType(resolver(out)), out);
final String attrId = out.ref(getStrategy().getJavaIdentifier(attribute), 2);
final String attrName = attribute.getName();
final List<String> converter = out.ref(list(attribute.getType(resolver(out)).getConverter()));
final List<String> binding = out.ref(list(attribute.getType(resolver(out)).getBinding()));
if (!printDeprecationIfUnknownType(out, attrTypeFull))
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
if (scala)
out.println("private val %s: %s[%s, %s] = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")", scalaWhitespaceSuffix(attrId), UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), converter, binding);
else if (kotlin)
out.println("%sval %s: %s<%s, %s> = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")", visibility(), attrId, UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), converter, binding);
else
out.println("%sstatic final %s<%s, %s> %s = createField(%s.name(\"%s\"), %s, %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ");", visibility(), UDTField.class, recordType, attrType, attrId, DSL.class, escapeString(attrName), attrTypeRef, udtId, escapeString(""), converter, binding);
}
// [#799] Oracle UDT's can have member procedures
for (RoutineDefinition routine : udt.getRoutines()) {
try {
if (!routine.isSQLUsable()) {
// Static execute() convenience method
printConvenienceMethodProcedure(out, routine, false);
} else {
// Static execute() convenience method
if (!routine.isAggregate())
printConvenienceMethodFunction(out, routine, false);
// Static asField() convenience method
printConvenienceMethodFunctionAsField(out, routine, false);
printConvenienceMethodFunctionAsField(out, routine, true);
}
} catch (Exception e) {
log.error("Error while generating routine " + routine, e);
}
}
if (scala || kotlin) {
} else {
out.javadoc(NO_FURTHER_INSTANCES_ALLOWED);
out.println("private %s() {", className);
out.println("super(\"%s\", null, %s, %s);", udt.getOutputName(), packageId, synthetic);
out.println("}");
}
if (scala) {
out.println();
out.println("%soverride def getSchema: %s = %s", visibilityPublic(), Schema.class, schemaId);
} else if (kotlin) {
out.println();
out.println("%s override fun getSchema(): %s = %s", visibilityPublic(), Schema.class, schemaId);
} else {
out.overrideInherit();
out.println("%s%s getSchema() {", visibilityPublic(), Schema.class);
out.println("return %s != null ? %s : new %s(%s.name(\"%s\"));", schemaId, schemaId, SchemaImpl.class, DSL.class, schema.getOutputName());
out.println("}");
}
generateUDTClassFooter(udt, out);
out.println("}");
closeJavaWriter(out);
}
use of org.jooq.meta.SchemaDefinition 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.SchemaDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method getSchemata0.
@Override
protected List<SchemaDefinition> getSchemata0() throws SQLException {
List<SchemaDefinition> result = new ArrayList<>();
result.add(new SchemaDefinition(this, "", ""));
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class H2Database method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SEQUENCES.SEQUENCE_SCHEMA));
if (schema != null) {
String name = record.get(SEQUENCES.SEQUENCE_NAME);
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, H2DataType.BIGINT.getTypeName());
result.add(new DefaultSequenceDefinition(schema, name, type, null, // H2 doesn't support Postgres-style START WITH
null, record.get(SEQUENCES.INCREMENT), record.get(SEQUENCES.MIN_VALUE), record.get(SEQUENCES.MAX_VALUE), record.get(SEQUENCES.IS_CYCLE), record.get(SEQUENCES.CACHE)));
}
}
return result;
}
Aggregations