use of org.jooq.meta.AttributeDefinition 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.AttributeDefinition 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.AttributeDefinition in project jOOQ by jOOQ.
the class PostgresUDTDefinition method getElements0.
@Override
protected List<AttributeDefinition> getElements0() throws SQLException {
List<AttributeDefinition> result = new ArrayList<>();
for (Record record : create().select(ATTRIBUTES.ATTRIBUTE_NAME, ATTRIBUTES.ORDINAL_POSITION, coalesce(DOMAINS.DATA_TYPE, when(ATTRIBUTES.DATA_TYPE.eq(inline("USER-DEFINED")).and(ATTRIBUTES.ATTRIBUTE_UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(ATTRIBUTES.DATA_TYPE)).as(ATTRIBUTES.DATA_TYPE), coalesce(DOMAINS.CHARACTER_MAXIMUM_LENGTH, ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH).as(ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH), coalesce(DOMAINS.NUMERIC_PRECISION, ATTRIBUTES.NUMERIC_PRECISION).as(ATTRIBUTES.NUMERIC_PRECISION), coalesce(DOMAINS.NUMERIC_SCALE, ATTRIBUTES.NUMERIC_SCALE).as(ATTRIBUTES.NUMERIC_SCALE), ATTRIBUTES.IS_NULLABLE, ATTRIBUTES.ATTRIBUTE_DEFAULT, ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA, ATTRIBUTES.ATTRIBUTE_UDT_NAME).from(ATTRIBUTES).leftJoin(DOMAINS).on(ATTRIBUTES.ATTRIBUTE_UDT_CATALOG.eq(DOMAINS.DOMAIN_CATALOG)).and(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA.eq(DOMAINS.DOMAIN_SCHEMA)).and(ATTRIBUTES.ATTRIBUTE_UDT_NAME.eq(DOMAINS.DOMAIN_NAME)).where(ATTRIBUTES.UDT_SCHEMA.equal(getSchema().getName())).and(ATTRIBUTES.UDT_NAME.equal(getName())).orderBy(ATTRIBUTES.ORDINAL_POSITION).fetch()) {
SchemaDefinition typeSchema = null;
String schemaName = record.get(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA);
if (schemaName != null)
typeSchema = getDatabase().getSchema(schemaName);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema == null ? getSchema() : typeSchema, record.get(ATTRIBUTES.DATA_TYPE), record.get(ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH), record.get(ATTRIBUTES.NUMERIC_PRECISION), record.get(ATTRIBUTES.NUMERIC_SCALE), record.get(ATTRIBUTES.IS_NULLABLE, boolean.class), record.get(ATTRIBUTES.ATTRIBUTE_DEFAULT), name(record.get(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA), record.get(ATTRIBUTES.ATTRIBUTE_UDT_NAME)));
AttributeDefinition column = new DefaultAttributeDefinition(this, record.get(ATTRIBUTES.ATTRIBUTE_NAME), record.get(ATTRIBUTES.ORDINAL_POSITION), type);
result.add(column);
}
return result;
}
use of org.jooq.meta.AttributeDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateRecord0.
private final void generateRecord0(Definition tableUdtOrEmbeddable, JavaWriter out) {
final UniqueKeyDefinition key = (tableUdtOrEmbeddable instanceof TableDefinition) ? ((TableDefinition) tableUdtOrEmbeddable).getPrimaryKey() : null;
final String className = getStrategy().getJavaClassName(tableUdtOrEmbeddable, Mode.RECORD);
final String tableIdentifier = !(tableUdtOrEmbeddable instanceof EmbeddableDefinition) ? out.ref(getStrategy().getFullJavaIdentifier(tableUdtOrEmbeddable), 2) : null;
final List<String> interfaces = out.ref(getStrategy().getJavaClassImplements(tableUdtOrEmbeddable, Mode.RECORD));
printPackage(out, tableUdtOrEmbeddable, Mode.RECORD);
if (tableUdtOrEmbeddable instanceof TableDefinition)
generateRecordClassJavadoc((TableDefinition) tableUdtOrEmbeddable, out);
else if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
generateEmbeddableClassJavadoc((EmbeddableDefinition) tableUdtOrEmbeddable, out);
else
generateUDTRecordClassJavadoc((UDTDefinition) tableUdtOrEmbeddable, out);
printClassAnnotations(out, tableUdtOrEmbeddable, Mode.RECORD);
if (tableUdtOrEmbeddable instanceof TableDefinition)
printTableJPAAnnotation(out, (TableDefinition) tableUdtOrEmbeddable);
Class<?> baseClass;
if (tableUdtOrEmbeddable instanceof UDTDefinition)
baseClass = UDTRecordImpl.class;
else if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
baseClass = EmbeddableRecordImpl.class;
else if (generateRelations() && key != null)
baseClass = UpdatableRecordImpl.class;
else
baseClass = TableRecordImpl.class;
// [#10481] Use the types from replaced embeddables if applicable
List<Definition> embeddablesAndColumns = embeddablesAndColumns(tableUdtOrEmbeddable);
List<Definition> embeddablesAndUnreplacedColumns = embeddablesAndUnreplacedColumns(tableUdtOrEmbeddable);
List<Definition> replacingEmbeddablesAndUnreplacedColumns = replacingEmbeddablesAndUnreplacedColumns(tableUdtOrEmbeddable);
List<Definition> embeddablesOrColumns = embeddablesOrColumns(tableUdtOrEmbeddable);
int degree = replacingEmbeddablesAndUnreplacedColumns.size();
String rowType = null;
String rowTypeRecord = null;
// [#6072] Generate these super types only if configured to do so
if (generateRecordsImplementingRecordN() && degree > 0 && degree <= Constants.MAX_ROW_DEGREE) {
rowType = refRowType(out, replacingEmbeddablesAndUnreplacedColumns);
if (scala)
rowTypeRecord = out.ref(Record.class.getName() + degree) + "[" + rowType + "]";
else
rowTypeRecord = out.ref(Record.class.getName() + degree) + "<" + rowType + ">";
interfaces.add(rowTypeRecord);
}
if (generateInterfaces())
interfaces.add(out.ref(getStrategy().getFullJavaClassName(tableUdtOrEmbeddable, Mode.INTERFACE)));
if (scala)
if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
out.println("%sclass %s extends %s[%s](%s.%s.getDataType.getRow)[[before= with ][separator= with ][%s]] {", visibility(), className, baseClass, className, out.ref(getStrategy().getFullJavaIdentifier(((EmbeddableDefinition) tableUdtOrEmbeddable).getTable()), 2), getStrategy().getJavaIdentifier(tableUdtOrEmbeddable), interfaces);
else
out.println("%sclass %s extends %s[%s](%s)[[before= with ][separator= with ][%s]] {", visibility(), className, baseClass, className, tableIdentifier, interfaces);
else if (kotlin)
if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
out.println("%sopen class %s() : %s<%s>(%s.%s.dataType.row)[[before=, ][%s]] {", visibility(), className, baseClass, className, out.ref(getStrategy().getFullJavaIdentifier(((EmbeddableDefinition) tableUdtOrEmbeddable).getTable()), 2), getStrategy().getJavaIdentifier(tableUdtOrEmbeddable), interfaces);
else
out.println("%sopen class %s() : %s<%s>(%s)[[before=, ][%s]] {", visibility(), className, baseClass, className, tableIdentifier, interfaces);
else
out.println("%sclass %s extends %s<%s>[[before= implements ][%s]] {", visibility(), className, baseClass, className, interfaces);
out.printSerial();
for (Definition column : embeddablesAndUnreplacedColumns) {
final int index = replacingEmbeddablesAndUnreplacedColumns.indexOf(column);
if (column instanceof EmbeddableDefinition) {
final EmbeddableDefinition embeddable = (EmbeddableDefinition) column;
generateEmbeddableRecordSetter(embeddable, index, out);
generateEmbeddableRecordGetter(embeddable, index, out);
} else {
final TypedElementDefinition<?> c = (TypedElementDefinition<?>) column;
if (tableUdtOrEmbeddable instanceof TableDefinition) {
generateRecordSetter(c, index, out);
generateRecordGetter(c, index, out);
} else if (tableUdtOrEmbeddable instanceof EmbeddableDefinition) {
generateEmbeddableSetter(c, index, out);
generateEmbeddableGetter(c, index, out);
} else {
generateUDTRecordSetter(c, index, out);
generateUDTRecordGetter(c, index, out);
}
}
}
if (generateRelations() && key != null) {
int keyDegree = key.getKeyColumns().size();
if (keyDegree <= Constants.MAX_ROW_DEGREE) {
final String recordNType = out.ref(Record.class.getName() + keyDegree);
final String keyType = refRowType(out, key.getKeyColumns());
out.header("Primary key information");
if (scala) {
out.println();
out.println("%soverride def key: %s[%s] = super.key.asInstanceOf[ %s[%s] ]", visibilityPublic(), recordNType, keyType, recordNType, keyType);
} else if (kotlin) {
out.println();
out.println("%soverride fun key(): %s<%s> = super.key() as %s<%s>", visibilityPublic(), recordNType, keyType, recordNType, keyType);
} else {
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s<%s> key() {", visibilityPublic(), recordNType, keyType);
out.println("return (%s) super.key();", recordNType);
out.println("}");
}
}
}
if (tableUdtOrEmbeddable instanceof UDTDefinition) {
// [#799] Oracle UDT's can have member procedures
for (RoutineDefinition routine : ((UDTDefinition) tableUdtOrEmbeddable).getRoutines()) {
// Instance methods ship with a SELF parameter at the first position
// [#1584] Static methods don't have that
boolean instance = routine.getInParameters().size() > 0 && routine.getInParameters().get(0).getInputName().toUpperCase(getStrategy().getTargetLocale()).equals("SELF");
try {
if (!routine.isSQLUsable()) {
// Instance execute() convenience method
printConvenienceMethodProcedure(out, routine, instance);
} else {
// Instance execute() convenience method
if (!routine.isAggregate()) {
printConvenienceMethodFunction(out, routine, instance);
}
}
} catch (Exception e) {
log.error("Error while generating routine " + routine, e);
}
}
}
// [#3130] Invalid UDTs may have a degree of 0
if (generateRecordsImplementingRecordN() && degree > 0 && degree <= Constants.MAX_ROW_DEGREE) {
final String recordNType = out.ref(Row.class.getName() + degree);
out.header("Record%s type implementation", degree);
// fieldsRow()
if (scala) {
out.println();
out.println("%soverride def fieldsRow: %s[%s] = super.fieldsRow.asInstanceOf[ %s[%s] ]", visibilityPublic(), recordNType, rowType, recordNType, rowType);
} else if (kotlin) {
out.println();
out.println("%soverride fun fieldsRow(): %s<%s> = super.fieldsRow() as %s<%s>", visibilityPublic(), recordNType, rowType, recordNType, rowType);
} else {
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s<%s> fieldsRow() {", visibilityPublic(), recordNType, rowType);
out.println("return (%s) super.fieldsRow();", recordNType);
out.println("}");
}
// valuesRow()
if (scala) {
out.println();
out.println("%soverride def valuesRow: %s[%s] = super.valuesRow.asInstanceOf[ %s[%s] ]", visibilityPublic(), recordNType, rowType, recordNType, rowType);
} else if (kotlin) {
out.println("%soverride fun valuesRow(): %s<%s> = super.valuesRow() as %s<%s>", visibilityPublic(), recordNType, rowType, recordNType, rowType);
} else {
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s<%s> valuesRow() {", visibilityPublic(), recordNType, rowType);
out.println("return (%s) super.valuesRow();", recordNType);
out.println("}");
}
// field[N]()
for (int i = 1; i <= degree; i++) {
Definition column = replacingEmbeddablesAndUnreplacedColumns.get(i - 1);
if (column instanceof EmbeddableColumnDefinition)
column = ((EmbeddableColumnDefinition) column).getReferencingColumn();
final String colTypeFull = getJavaType(column, out);
final String colType = out.ref(colTypeFull);
final String colIdentifierFull = out.ref(getStrategy().getFullJavaIdentifier(column), colRefSegments(column));
final String colIdentifier = getStrategy().getJavaIdentifier(column);
if (scala) {
printDeprecationIfUnknownType(out, colTypeFull);
if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
out.println("%soverride def field%s: %s[%s] = field(%s).asInstanceOf[%s [%s] ]", visibilityPublic(), i, Field.class, colType, i - 1, Field.class, colType);
else
out.println("%soverride def field%s: %s[%s] = %s", visibilityPublic(), i, Field.class, colType, colIdentifierFull);
} else if (kotlin) {
printDeprecationIfUnknownType(out, colTypeFull);
if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
out.println("%soverride fun field%s(): %s<%s?> = field(%s) as %s<%s?>", visibilityPublic(), i, Field.class, colType, i - 1, Field.class, colType);
else if (tableUdtOrEmbeddable instanceof UDTDefinition)
out.println("%soverride fun field%s(): %s<%s%s> = %s.%s", visibilityPublic(), i, Field.class, colType, column instanceof EmbeddableDefinition ? "" : "?", out.ref(getStrategy().getFullJavaIdentifier(((AttributeDefinition) column).getContainer()), 2), colIdentifier);
else
out.println("%soverride fun field%s(): %s<%s%s> = %s", visibilityPublic(), i, Field.class, colType, column instanceof EmbeddableDefinition ? "" : "?", colIdentifierFull);
} else {
if (printDeprecationIfUnknownType(out, colTypeFull))
out.override();
else
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s<%s> field%s() {", visibilityPublic(), Field.class, colType, i);
if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
out.println("return (%s<%s>) field(%s);", Field.class, colType, i - 1);
else
out.println("return %s;", colIdentifierFull);
out.println("}");
}
}
// component[N]()
for (int i = 1; i <= degree; i++) {
Definition column = replacingEmbeddablesAndUnreplacedColumns.get(i - 1);
final String colTypeFull = getJavaType(column, out);
final String colType = out.ref(colTypeFull);
final String colGetter = getStrategy().getJavaGetterName(column, Mode.RECORD);
final String colMember = getStrategy().getJavaMemberName(column, Mode.POJO);
if (scala) {
printDeprecationIfUnknownType(out, colTypeFull);
out.println("%soverride def component%s: %s = %s", visibilityPublic(), i, colType, colGetter);
} else if (kotlin) {
printDeprecationIfUnknownType(out, colTypeFull);
out.println("%soverride fun component%s(): %s? = %s", visibilityPublic(), i, colType, colMember);
} else {
if (printDeprecationIfUnknownType(out, colTypeFull))
out.override();
else
out.overrideInherit();
printNullableOrNonnullAnnotation(out, column);
out.println("%s%s component%s() {", visibilityPublic(), colType, i);
out.println("return %s();", colGetter);
out.println("}");
}
}
// value[N]()
for (int i = 1; i <= degree; i++) {
Definition column = replacingEmbeddablesAndUnreplacedColumns.get(i - 1);
final String colTypeFull = getJavaType(column, out);
final String colType = out.ref(colTypeFull);
final String colGetter = getStrategy().getJavaGetterName(column, Mode.RECORD);
final String colMember = getStrategy().getJavaMemberName(column, Mode.POJO);
if (scala) {
printDeprecationIfUnknownType(out, colTypeFull);
out.println("%soverride def value%s: %s = %s", visibilityPublic(), i, colType, colGetter);
} else if (kotlin) {
printDeprecationIfUnknownType(out, colTypeFull);
out.println("%soverride fun value%s(): %s? = %s", visibilityPublic(), i, colType, colMember);
} else {
if (printDeprecationIfUnknownType(out, colTypeFull))
out.override();
else
out.overrideInherit();
printNullableOrNonnullAnnotation(out, column);
out.println("%s%s value%s() {", visibilityPublic(), colType, i);
out.println("return %s();", colGetter);
out.println("}");
}
}
// value[N](T[N])
for (int i = 1; i <= degree; i++) {
Definition column = replacingEmbeddablesAndUnreplacedColumns.get(i - 1);
final String colTypeFull = getJavaType(column, out);
final String colType = out.ref(colTypeFull);
final String colSetter = getStrategy().getJavaSetterName(column, Mode.RECORD);
final String colMember = getStrategy().getJavaMemberName(column, Mode.POJO);
if (scala) {
out.println();
printDeprecationIfUnknownType(out, colTypeFull);
out.println("%soverride def value%s(value: %s): %s = {", visibilityPublic(), i, colType, className);
out.println("%s(value)", colSetter);
out.println("this");
out.println("}");
} else if (kotlin) {
out.println();
printDeprecationIfUnknownType(out, colTypeFull);
out.println("%soverride fun value%s(value: %s%s): %s {", visibilityPublic(), i, colType, column instanceof EmbeddableDefinition ? "" : "?", className);
out.println("this.%s = value", colMember);
out.println("return this");
out.println("}");
} else {
final String nullableAnnotation = nullableOrNonnullAnnotation(out, column);
if (printDeprecationIfUnknownType(out, colTypeFull))
out.override();
else
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s value%s([[before=@][after= ][%s]]%s value) {", visibilityPublic(), className, i, list(nullableAnnotation), varargsIfArray(colType));
out.println("%s(value);", colSetter);
out.println("return this;");
out.println("}");
}
}
List<String> arguments = new ArrayList<>(degree);
List<String> calls = new ArrayList<>(degree);
for (int i = 1; i <= degree; i++) {
final Definition column = replacingEmbeddablesAndUnreplacedColumns.get(i - 1);
final String colType = getJavaTypeRef(column, out);
if (scala) {
arguments.add("value" + i + " : " + colType);
calls.add("this.value" + i + "(value" + i + ")");
} else if (kotlin) {
arguments.add("value" + i + ": " + colType + (column instanceof EmbeddableDefinition ? "" : "?"));
calls.add("this.value" + i + "(value" + i + ")");
} else {
final String nullableAnnotation = nullableOrNonnullAnnotation(out, column);
arguments.add((nullableAnnotation == null ? "" : "@" + nullableAnnotation + " ") + colType + " value" + i);
calls.add("value" + i + "(value" + i + ");");
}
}
if (scala) {
out.println();
out.println("%soverride def values([[%s]]): %s = {", visibilityPublic(), arguments, className);
for (String call : calls) out.println(call);
out.println("this");
out.println("}");
} else if (kotlin) {
out.println();
out.println("%soverride fun values([[%s]]): %s {", visibilityPublic(), arguments, className);
for (String call : calls) out.println(call);
out.println("return this");
out.println("}");
} else {
out.overrideInherit();
printNonnullAnnotation(out);
out.println("%s%s values([[%s]]) {", visibilityPublic(), className, arguments);
for (String call : calls) out.println(call);
out.println("return this;");
out.println("}");
}
}
if (generateInterfaces())
printFromAndInto(out, tableUdtOrEmbeddable, Mode.RECORD);
if (scala || kotlin) {
} else {
out.header("Constructors");
out.javadoc("Create a detached %s", className);
out.println("%s%s() {", visibility(), className);
if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
out.println("super(%s.%s.getDataType().getRow());", out.ref(getStrategy().getFullJavaIdentifier(((EmbeddableDefinition) tableUdtOrEmbeddable).getTable()), 2), getStrategy().getJavaIdentifier(tableUdtOrEmbeddable));
else
out.println("super(%s);", tableIdentifier);
out.println("}");
}
// [#3130] Invalid UDTs may have a degree of 0
// [#3176] Avoid generating constructors for tables with more than 255 columns (Java's method argument limit)
generateRecordConstructor(tableUdtOrEmbeddable, out, replacingEmbeddablesAndUnreplacedColumns, false);
if (!replacingEmbeddablesAndUnreplacedColumns.equals(embeddablesOrColumns))
generateRecordConstructor(tableUdtOrEmbeddable, out, embeddablesOrColumns, false);
if (generatePojos())
generateRecordConstructor(tableUdtOrEmbeddable, out, replacingEmbeddablesAndUnreplacedColumns, true);
if (tableUdtOrEmbeddable instanceof TableDefinition)
generateRecordClassFooter((TableDefinition) tableUdtOrEmbeddable, out);
else if (tableUdtOrEmbeddable instanceof EmbeddableDefinition)
generateEmbeddableClassFooter((EmbeddableDefinition) tableUdtOrEmbeddable, out);
else
generateUDTRecordClassFooter((UDTDefinition) tableUdtOrEmbeddable, out);
out.println("}");
}
Aggregations