Search in sources :

Example 1 with StringUtils.defaultString

use of org.jooq.tools.StringUtils.defaultString in project jOOQ by jOOQ.

the class JavaGenerator method generateRecordSetter0.

private final void generateRecordSetter0(TypedElementDefinition<?> column, int index, JavaWriter out) {
    final String comment = StringUtils.defaultString(column.getComment());
    final String className = getStrategy().getJavaClassName(column.getContainer(), Mode.RECORD);
    final String setterReturnType = fluentSetters() ? className : tokenVoid;
    final String setter = getStrategy().getJavaSetterName(column, Mode.RECORD);
    final String type = out.ref(getJavaType(column.getType()));
    final String name = column.getQualifiedOutputName();
    final boolean isUDT = column.getType().isUDT();
    final boolean isArray = column.getType().isArray();
    final boolean isUDTArray = column.getType().isArray() && database.getArray(column.getType().getSchema(), column.getType().getQualifiedUserType()).getElementType().isUDT();
    // We cannot have covariant setters for arrays because of type erasure
    if (!(generateInterfaces() && isArray)) {
        out.tab(1).javadoc("Setter for <code>%s</code>.%s", name, defaultIfBlank(" " + escapeEntities(comment), ""));
        if (scala) {
            out.tab(1).println("def %s(value : %s) : %s = {", setter, type, setterReturnType);
            out.tab(2).println("set(%s, value)", index);
            if (fluentSetters())
                out.tab(2).println("this");
            out.tab(1).println("}");
        } else {
            out.tab(1).overrideIf(generateInterfaces() && !generateImmutableInterfaces() && !isUDT);
            out.tab(1).println("public %s %s(%s value) {", setterReturnType, setter, varargsIfArray(type));
            out.tab(2).println("set(%s, value);", index);
            if (fluentSetters())
                out.tab(2).println("return this;");
            out.tab(1).println("}");
        }
    }
    // [#3117] Avoid covariant setters for UDTs when generating interfaces
    if (generateInterfaces() && !generateImmutableInterfaces() && (isUDT || isArray)) {
        final String columnType = out.ref(getJavaType(column.getType(), Mode.RECORD));
        final String columnTypeInterface = out.ref(getJavaType(column.getType(), Mode.INTERFACE));
        out.tab(1).javadoc("Setter for <code>%s</code>.%s", name, defaultIfBlank(" " + comment, ""));
        out.tab(1).override();
        if (scala) {
            // [#3082] TODO Handle <interfaces/> + ARRAY also for Scala
            out.tab(1).println("def %s(value : %s) : %s = {", setter, columnTypeInterface, setterReturnType);
            out.tab(2).println("if (value == null)");
            out.tab(3).println("set(%s, null)", index);
            out.tab(2).println("else");
            out.tab(3).println("set(%s, value.into(new %s()))", index, type);
            if (fluentSetters())
                out.tab(2).println("this");
            out.tab(1).println("}");
        } else {
            out.tab(1).println("public %s %s(%s value) {", setterReturnType, setter, varargsIfArray(columnTypeInterface));
            out.tab(2).println("if (value == null)");
            out.tab(3).println("set(%s, null);", index);
            if (isUDT) {
                out.tab(2).println("else");
                out.tab(3).println("set(%s, value.into(new %s()));", index, type);
            } else if (isArray) {
                final ArrayDefinition array = database.getArray(column.getType().getSchema(), column.getType().getQualifiedUserType());
                final String componentType = out.ref(getJavaType(array.getElementType(), Mode.RECORD));
                final String componentTypeInterface = out.ref(getJavaType(array.getElementType(), Mode.INTERFACE));
                out.tab(2).println("else {");
                out.tab(3).println("%s a = new %s();", columnType, columnType);
                out.println();
                out.tab(3).println("for (%s i : value)", componentTypeInterface);
                if (isUDTArray)
                    out.tab(4).println("a.add(i.into(new %s()));", componentType);
                else
                    out.tab(4).println("a.add(i);", componentType);
                out.println();
                out.tab(3).println("set(1, a);");
                out.tab(2).println("}");
            }
            if (fluentSetters())
                out.tab(2).println("return this;");
            out.tab(1).println("}");
        }
    }
}
Also used : StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString)

Example 2 with StringUtils.defaultString

use of org.jooq.tools.StringUtils.defaultString in project jOOQ by jOOQ.

the class JavaGenerator method generateTable.

protected void generateTable(TableDefinition table, JavaWriter out) {
    final SchemaDefinition schema = table.getSchema();
    final UniqueKeyDefinition primaryKey = table.getPrimaryKey();
    final boolean updatable = generateRelations() && primaryKey != null;
    final String className = getStrategy().getJavaClassName(table);
    final String tableId = scala ? out.ref(getStrategy().getFullJavaIdentifier(table), 2) : getStrategy().getJavaIdentifier(table);
    final String recordType = out.ref(getStrategy().getFullJavaClassName(table, Mode.RECORD));
    final List<String> interfaces = out.ref(getStrategy().getJavaClassImplements(table, Mode.DEFAULT));
    final String schemaId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
    final String comment = defaultString(table.getComment());
    log.info("Generating table", out.file().getName() + " [input=" + table.getInputName() + ", output=" + table.getOutputName() + ", pk=" + (primaryKey != null ? primaryKey.getName() : "N/A") + "]");
    printPackage(out, table);
    if (scala) {
        out.println("object %s {", className);
        printSingletonInstance(out, table);
        out.println("}");
        out.println();
    }
    generateTableClassJavadoc(table, out);
    printClassAnnotations(out, schema);
    if (scala) {
        out.println("class %s(alias : String, aliased : %s[%s], parameters : %s[ %s[_] ]) extends %s[%s](alias, %s, aliased, parameters, \"%s\")[[before= with ][separator= with ][%s]] {", className, Table.class, recordType, out.ref("scala.Array"), Field.class, TableImpl.class, recordType, schemaId, escapeString(comment), interfaces);
    } else {
        out.println("public class %s extends %s<%s>[[before= implements ][%s]] {", className, TableImpl.class, recordType, interfaces);
        out.printSerial();
        printSingletonInstance(out, table);
    }
    printRecordTypeMethod(out, table);
    for (ColumnDefinition column : table.getColumns()) {
        final String columnType = out.ref(getJavaType(column.getType()));
        final String columnTypeRef = getJavaTypeReference(column.getDatabase(), column.getType());
        final String columnId = out.ref(getStrategy().getJavaIdentifier(column), colRefSegments(column));
        final String columnName = column.getName();
        final String columnComment = StringUtils.defaultString(column.getComment());
        final List<String> converter = out.ref(list(column.getType().getConverter()));
        final List<String> binding = out.ref(list(column.getType().getBinding()));
        out.tab(1).javadoc("The column <code>%s</code>.%s", column.getQualifiedOutputName(), defaultIfBlank(" " + escapeEntities(columnComment), ""));
        if (scala) {
            out.tab(1).println("val %s : %s[%s, %s] = createField(\"%s\", %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")", columnId, TableField.class, recordType, columnType, columnName, columnTypeRef, escapeString(columnComment), converter, binding);
        } else {
            String isStatic = generateInstanceFields() ? "" : "static ";
            String tableRef = generateInstanceFields() ? "this" : out.ref(getStrategy().getJavaIdentifier(table), 2);
            out.tab(1).println("public %sfinal %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ");", isStatic, TableField.class, recordType, columnType, columnId, columnName, columnTypeRef, tableRef, escapeString(columnComment), converter, binding);
        }
    }
    if (scala) {
        out.tab(1).javadoc("Create a <code>%s</code> table reference", table.getQualifiedOutputName());
        out.tab(1).println("def this() = {");
        out.tab(2).println("this(\"%s\", null, null)", table.getOutputName());
        out.tab(1).println("}");
    } else {
        // be public, as tables are no longer singletons
        if (generateInstanceFields()) {
            out.tab(1).javadoc("Create a <code>%s</code> table reference", table.getQualifiedOutputName());
            out.tab(1).println("public %s() {", className);
        } else {
            out.tab(1).javadoc(NO_FURTHER_INSTANCES_ALLOWED);
            out.tab(1).println("private %s() {", className);
        }
        out.tab(2).println("this(\"%s\", null);", table.getOutputName());
        out.tab(1).println("}");
    }
    if (scala) {
        out.tab(1).javadoc("Create an aliased <code>%s</code> table reference", table.getQualifiedOutputName());
        out.tab(1).println("def this(alias : %s) = {", String.class);
        out.tab(2).println("this(alias, %s, null)", tableId);
        out.tab(1).println("}");
    } else // be public, as tables are no longer singletons
    if (generateInstanceFields()) {
        out.tab(1).javadoc("Create an aliased <code>%s</code> table reference", table.getQualifiedOutputName());
        out.tab(1).println("public %s(%s alias) {", className, String.class);
        out.tab(2).println("this(alias, %s);", tableId);
        out.tab(1).println("}");
    }
    out.println();
    if (scala) {
        out.tab(1).println("private def this(alias : %s, aliased : %s[%s]) = {", String.class, Table.class, recordType);
        if (table.isTableValuedFunction())
            out.tab(2).println("this(alias, aliased, new %s[ %s[_] ](%s))", out.ref("scala.Array"), Field.class, table.getParameters().size());
        else
            out.tab(2).println("this(alias, aliased, null)");
        out.tab(1).println("}");
    } else {
        out.tab(1).println("private %s(%s alias, %s<%s> aliased) {", className, String.class, Table.class, recordType);
        if (table.isTableValuedFunction())
            out.tab(2).println("this(alias, aliased, new %s[%s]);", Field.class, table.getParameters().size());
        else
            out.tab(2).println("this(alias, aliased, null);");
        out.tab(1).println("}");
        out.println();
        out.tab(1).println("private %s(%s alias, %s<%s> aliased, %s<?>[] parameters) {", className, String.class, Table.class, recordType, Field.class);
        out.tab(2).println("super(alias, null, aliased, parameters, \"%s\");", escapeString(comment));
        out.tab(1).println("}");
    }
    if (scala) {
        out.println();
        out.tab(1).println("override def getSchema : %s = %s", Schema.class, schemaId);
    } else {
        out.tab(1).overrideInherit();
        out.tab(1).println("public %s getSchema() {", Schema.class);
        out.tab(2).println("return %s;", schemaId);
        out.tab(1).println("}");
    }
    // Add primary / unique / foreign key information
    if (generateRelations()) {
        IdentityDefinition identity = table.getIdentity();
        // The identity column
        if (identity != null) {
            final String identityType = out.ref(getJavaType(identity.getColumn().getType()));
            final String identityFullId = out.ref(getStrategy().getFullJavaIdentifier(identity), 2);
            if (scala) {
                out.println();
                out.tab(1).println("override def getIdentity : %s[%s, %s] = {", Identity.class, recordType, identityType);
                out.tab(2).println("%s", identityFullId);
                out.tab(1).println("}");
            } else {
                out.tab(1).overrideInherit();
                out.tab(1).println("public %s<%s, %s> getIdentity() {", Identity.class, recordType, identityType);
                out.tab(2).println("return %s;", identityFullId);
                out.tab(1).println("}");
            }
        }
        // The primary / main unique key
        if (primaryKey != null) {
            final String keyFullId = out.ref(getStrategy().getFullJavaIdentifier(primaryKey), 2);
            if (scala) {
                out.println();
                out.tab(1).println("override def getPrimaryKey : %s[%s] = {", UniqueKey.class, recordType);
                out.tab(2).println("%s", keyFullId);
                out.tab(1).println("}");
            } else {
                out.tab(1).overrideInherit();
                out.tab(1).println("public %s<%s> getPrimaryKey() {", UniqueKey.class, recordType);
                out.tab(2).println("return %s;", keyFullId);
                out.tab(1).println("}");
            }
        }
        // The remaining unique keys
        List<UniqueKeyDefinition> uniqueKeys = table.getUniqueKeys();
        if (uniqueKeys.size() > 0) {
            final List<String> keyFullIds = out.ref(getStrategy().getFullJavaIdentifiers(uniqueKeys), 2);
            if (scala) {
                out.println();
                out.tab(1).println("override def getKeys : %s[ %s[%s] ] = {", List.class, UniqueKey.class, recordType);
                out.tab(2).println("return %s.asList[ %s[%s] ]([[%s]])", Arrays.class, UniqueKey.class, recordType, keyFullIds);
                out.tab(1).println("}");
            } else {
                out.tab(1).overrideInherit();
                out.tab(1).println("public %s<%s<%s>> getKeys() {", List.class, UniqueKey.class, recordType);
                out.tab(2).println("return %s.<%s<%s>>asList([[%s]]);", Arrays.class, UniqueKey.class, recordType, keyFullIds);
                out.tab(1).println("}");
            }
        }
        // Foreign keys
        List<ForeignKeyDefinition> foreignKeys = table.getForeignKeys();
        if (foreignKeys.size() > 0) {
            final List<String> keyFullIds = out.ref(getStrategy().getFullJavaIdentifiers(foreignKeys), 2);
            if (scala) {
                out.println();
                out.tab(1).println("override def getReferences : %s[ %s[%s, _] ] = {", List.class, ForeignKey.class, recordType);
                out.tab(2).println("return %s.asList[ %s[%s, _] ]([[%s]])", Arrays.class, ForeignKey.class, recordType, keyFullIds);
                out.tab(1).println("}");
            } else {
                out.tab(1).overrideInherit();
                out.tab(1).println("public %s<%s<%s, ?>> getReferences() {", List.class, ForeignKey.class, recordType);
                out.tab(2).println("return %s.<%s<%s, ?>>asList([[%s]]);", Arrays.class, ForeignKey.class, recordType, keyFullIds);
                out.tab(1).println("}");
            }
        }
    }
    // if properly configured
    if (updatable) {
        patternLoop: for (String pattern : database.getRecordVersionFields()) {
            Pattern p = Pattern.compile(pattern, Pattern.COMMENTS);
            for (ColumnDefinition column : table.getColumns()) {
                if ((p.matcher(column.getName()).matches() || p.matcher(column.getQualifiedName()).matches())) {
                    final String columnType = out.ref(getJavaType(column.getType()));
                    final String columnId = getStrategy().getJavaIdentifier(column);
                    if (scala) {
                        out.println();
                        out.tab(1).println("override def getRecordVersion : %s[%s, %s] = {", TableField.class, recordType, columnType);
                        out.tab(2).println("%s", columnId);
                        out.tab(1).println("}");
                    } else {
                        out.tab(1).overrideInherit();
                        out.tab(1).println("public %s<%s, %s> getRecordVersion() {", TableField.class, recordType, columnType);
                        out.tab(2).println("return %s;", columnId);
                        out.tab(1).println("}");
                    }
                    // Avoid generating this method twice
                    break patternLoop;
                }
            }
        }
        timestampLoop: for (String pattern : database.getRecordTimestampFields()) {
            Pattern p = Pattern.compile(pattern, Pattern.COMMENTS);
            for (ColumnDefinition column : table.getColumns()) {
                if ((p.matcher(column.getName()).matches() || p.matcher(column.getQualifiedName()).matches())) {
                    final String columnType = out.ref(getJavaType(column.getType()));
                    final String columnId = getStrategy().getJavaIdentifier(column);
                    if (scala) {
                        out.println();
                        out.tab(1).println("override def getRecordTimestamp : %s[%s, %s] = {", TableField.class, recordType, columnType);
                        out.tab(2).println("%s", columnId);
                        out.tab(1).println("}");
                    } else {
                        out.tab(1).overrideInherit();
                        out.tab(1).println("public %s<%s, %s> getRecordTimestamp() {", TableField.class, recordType, columnType);
                        out.tab(2).println("return %s;", columnId);
                        out.tab(1).println("}");
                    }
                    // Avoid generating this method twice
                    break timestampLoop;
                }
            }
        }
    }
    if (scala) {
        out.println();
        out.tab(1).println("override def as(alias : %s) : %s = {", String.class, className);
        if (table.isTableValuedFunction())
            out.tab(2).println("new %s(alias, this, parameters)", className);
        else
            out.tab(2).println("new %s(alias, this)", className);
        out.tab(1).println("}");
    } else // type-safe table alias
    if (generateInstanceFields()) {
        out.tab(1).overrideInherit();
        out.tab(1).println("public %s as(%s alias) {", className, String.class);
        if (table.isTableValuedFunction())
            out.tab(2).println("return new %s(alias, this, parameters);", className);
        else
            out.tab(2).println("return new %s(alias, this);", className);
        out.tab(1).println("}");
    }
    if (scala) {
        out.tab(1).javadoc("Rename this table");
        out.tab(1).println("override def rename(name : %s) : %s = {", String.class, className);
        if (table.isTableValuedFunction())
            out.tab(2).println("new %s(name, null, parameters)", className);
        else
            out.tab(2).println("new %s(name, null)", className);
        out.tab(1).println("}");
    } else // [#2921] With instance fields, tables can be renamed.
    if (generateInstanceFields()) {
        out.tab(1).javadoc("Rename this table");
        out.tab(1).override();
        out.tab(1).println("public %s rename(%s name) {", className, String.class);
        if (table.isTableValuedFunction())
            out.tab(2).println("return new %s(name, null, parameters);", className);
        else
            out.tab(2).println("return new %s(name, null);", className);
        out.tab(1).println("}");
    }
    // [#1070] Table-valued functions should generate an additional set of call() methods
    if (table.isTableValuedFunction()) {
        for (boolean parametersAsField : new boolean[] { false, true }) {
            // Don't overload no-args call() methods
            if (parametersAsField && table.getParameters().size() == 0)
                break;
            out.tab(1).javadoc("Call this table-valued function");
            if (scala) {
                out.tab(1).print("def call(");
                printParameterDeclarations(out, table, parametersAsField);
                out.println(") : %s = {", className);
                out.tab(2).println("return new %s(getName(), null, %s(", className, out.ref("scala.Array"));
                String separator = "  ";
                for (ParameterDefinition parameter : table.getParameters()) {
                    final String paramArgName = getStrategy().getJavaMemberName(parameter);
                    final String paramTypeRef = getJavaTypeReference(parameter.getDatabase(), parameter.getType());
                    out.tab(3).print(separator);
                    if (parametersAsField) {
                        out.println("%s", paramArgName);
                    } else {
                        out.println("%s.value(%s, %s)", DSL.class, paramArgName, paramTypeRef);
                    }
                    separator = ", ";
                }
                out.tab(2).println("));");
                out.tab(1).println("}");
            } else {
                out.tab(1).print("public %s call(", className);
                printParameterDeclarations(out, table, parametersAsField);
                out.println(") {");
                out.tab(2).println("return new %s(getName(), null, new %s[] { ", className, Field.class);
                String separator = "  ";
                for (ParameterDefinition parameter : table.getParameters()) {
                    final String paramArgName = getStrategy().getJavaMemberName(parameter);
                    final String paramTypeRef = getJavaTypeReference(parameter.getDatabase(), parameter.getType());
                    out.tab(3).print(separator);
                    if (parametersAsField) {
                        out.println("%s", paramArgName);
                    } else {
                        out.println("%s.val(%s, %s)", DSL.class, paramArgName, paramTypeRef);
                    }
                    separator = ", ";
                }
                out.tab(2).println("});");
                out.tab(1).println("}");
            }
        }
    }
    generateTableClassFooter(table, out);
    out.println("}");
    closeJavaWriter(out);
}
Also used : Pattern(java.util.regex.Pattern) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) TableField(org.jooq.TableField) Field(org.jooq.Field) TableField(org.jooq.TableField) UDTField(org.jooq.UDTField)

Example 3 with StringUtils.defaultString

use of org.jooq.tools.StringUtils.defaultString in project jOOQ by jOOQ.

the class JavaGenerator method generateInterfaceSetter0.

private final void generateInterfaceSetter0(TypedElementDefinition<?> column, @SuppressWarnings("unused") int index, JavaWriter out) {
    final String className = getStrategy().getJavaClassName(column.getContainer(), Mode.INTERFACE);
    final String comment = StringUtils.defaultString(column.getComment());
    final String setterReturnType = fluentSetters() ? className : "void";
    final String setter = getStrategy().getJavaSetterName(column, Mode.INTERFACE);
    final String type = out.ref(getJavaType(column.getType(), Mode.INTERFACE));
    final String name = column.getQualifiedOutputName();
    out.tab(1).javadoc("Setter for <code>%s</code>.%s", name, defaultIfBlank(" " + escapeEntities(comment), ""));
    if (scala)
        out.tab(1).println("def %s(value : %s) : %s", setter, type, setterReturnType);
    else
        out.tab(1).println("public %s %s(%s value);", setterReturnType, setter, varargsIfArray(type));
}
Also used : StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString)

Example 4 with StringUtils.defaultString

use of org.jooq.tools.StringUtils.defaultString in project jOOQ by jOOQ.

the class JavaGenerator method generateRecordGetter0.

private final void generateRecordGetter0(TypedElementDefinition<?> column, int index, JavaWriter out) {
    final String comment = StringUtils.defaultString(column.getComment());
    final String getter = getStrategy().getJavaGetterName(column, Mode.RECORD);
    final String type = out.ref(getJavaType(column.getType()));
    final String name = column.getQualifiedOutputName();
    out.tab(1).javadoc("Getter for <code>%s</code>.%s", name, defaultIfBlank(" " + escapeEntities(comment), ""));
    if (column.getContainer() instanceof TableDefinition)
        printColumnJPAAnnotation(out, (ColumnDefinition) column);
    printValidationAnnotation(out, column);
    if (scala) {
        out.tab(1).println("def %s : %s = {", getter, type);
        out.tab(2).println("val r = get(%s)", index);
        out.tab(2).println("if (r == null) null else r.asInstanceOf[%s]", type);
        out.tab(1).println("}");
    } else {
        out.tab(1).overrideIf(generateInterfaces());
        out.tab(1).println("public %s %s() {", type, getter);
        out.tab(2).println("return (%s) get(%s);", type, index);
        out.tab(1).println("}");
    }
}
Also used : StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString)

Example 5 with StringUtils.defaultString

use of org.jooq.tools.StringUtils.defaultString 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 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);
            final String attrComment = StringUtils.defaultString(attribute.getComment());
            out.tab(1).javadoc("The attribute <code>%s</code>.%s", attribute.getQualifiedOutputName(), defaultIfBlank(" " + escapeEntities(attrComment), ""));
            out.tab(1).println("val %s = %s.%s", attrId, udtId, attrId);
        }
        out.println("}");
        out.println();
    }
    generateUDTClassJavadoc(udt, out);
    printClassAnnotations(out, schema);
    // [#799] Oracle UDTs with member procedures have similarities with packages
    if (udt.getRoutines().size() > 0) {
        interfaces.add(out.ref(Package.class));
    }
    if (scala) {
        out.println("class %s extends %s[%s](\"%s\", null[[before=, ][%s]])[[before= with ][separator= with ][%s]] {", className, UDTImpl.class, recordType, udt.getOutputName(), list(packageId), interfaces);
    } else {
        out.println("public class %s extends %s<%s>[[before= implements ][%s]] {", className, UDTImpl.class, recordType, interfaces);
        out.printSerial();
        printSingletonInstance(out, udt);
    }
    printRecordTypeMethod(out, udt);
    for (AttributeDefinition attribute : udt.getAttributes()) {
        final String attrType = out.ref(getJavaType(attribute.getType()));
        final String attrTypeRef = getJavaTypeReference(attribute.getDatabase(), attribute.getType());
        final String attrId = out.ref(getStrategy().getJavaIdentifier(attribute), 2);
        final String attrName = attribute.getName();
        final String attrComment = StringUtils.defaultString(attribute.getComment());
        final List<String> converter = out.ref(list(attribute.getType().getConverter()));
        final List<String> binding = out.ref(list(attribute.getType().getBinding()));
        if (scala) {
            out.tab(1).println("private val %s : %s[%s, %s] = %s.createField(\"%s\", %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")", attrId, UDTField.class, recordType, attrType, UDTImpl.class, attrName, attrTypeRef, escapeString(""), converter, binding);
        } else {
            out.tab(1).javadoc("The attribute <code>%s</code>.%s", attribute.getQualifiedOutputName(), defaultIfBlank(" " + attrComment, ""));
            out.tab(1).println("public static final %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ");", UDTField.class, recordType, attrType, attrId, 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) {
    } else {
        out.tab(1).javadoc(NO_FURTHER_INSTANCES_ALLOWED);
        out.tab(1).println("private %s() {", className);
        out.tab(2).println("super(\"%s\", null[[before=, ][%s]]);", udt.getOutputName(), list(packageId));
        out.tab(1).println("}");
    }
    if (scala) {
        out.println();
        out.tab(1).println("override def getSchema : %s = %s", Schema.class, schemaId);
    } else {
        out.tab(1).overrideInherit();
        out.tab(1).println("public %s getSchema() {", Schema.class);
        out.tab(2).println("return %s;", schemaId);
        out.tab(1).println("}");
    }
    generateUDTClassFooter(udt, out);
    out.println("}");
    closeJavaWriter(out);
}
Also used : StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) Package(org.jooq.Package) SQLDialectNotSupportedException(org.jooq.exception.SQLDialectNotSupportedException) IOException(java.io.IOException) ReflectException(org.jooq.tools.reflect.ReflectException)

Aggregations

StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)7 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 Field (org.jooq.Field)1 Package (org.jooq.Package)1 TableField (org.jooq.TableField)1 UDTField (org.jooq.UDTField)1 SQLDialectNotSupportedException (org.jooq.exception.SQLDialectNotSupportedException)1 ReflectException (org.jooq.tools.reflect.ReflectException)1