Search in sources :

Example 1 with UDTDefinition

use of org.jooq.meta.UDTDefinition in project jOOQ by jOOQ.

the class JavaGenerator method generateUDTRecords.

/**
 * Generating UDT record classes
 */
protected void generateUDTRecords(SchemaDefinition schema) {
    log.info("Generating UDT records");
    for (UDTDefinition udt : database.getUDTs(schema)) {
        try {
            generateUDTRecord(udt);
        } catch (Exception e) {
            log.error("Error while generating UDT record " + udt, e);
        }
    }
    watch.splitInfo("UDT records generated");
}
Also used : UDTDefinition(org.jooq.meta.UDTDefinition) IOException(java.io.IOException) SQLDialectNotSupportedException(org.jooq.exception.SQLDialectNotSupportedException) ReflectException(org.jooq.tools.reflect.ReflectException)

Example 2 with UDTDefinition

use of org.jooq.meta.UDTDefinition in project jOOQ by jOOQ.

the class JavaGenerator method generateUDTInterfaces.

protected void generateUDTInterfaces(SchemaDefinition schema) {
    log.info("Generating UDT interfaces");
    for (UDTDefinition udt : database.getUDTs(schema)) {
        try {
            generateUDTInterface(udt);
        } catch (Exception e) {
            log.error("Error while generating UDT interface " + udt, e);
        }
    }
    watch.splitInfo("UDT interfaces generated");
}
Also used : UDTDefinition(org.jooq.meta.UDTDefinition) IOException(java.io.IOException) SQLDialectNotSupportedException(org.jooq.exception.SQLDialectNotSupportedException) ReflectException(org.jooq.tools.reflect.ReflectException)

Example 3 with UDTDefinition

use of org.jooq.meta.UDTDefinition in project jOOQ by jOOQ.

the class JavaGenerator method isArrayOfUDTs.

private boolean isArrayOfUDTs(final TypedElementDefinition<?> t, final JavaTypeResolver r) {
    // [#11183] TODO: Move this to DataTypeDefinition?
    String javaType = t.getType(r).getJavaType(r);
    if (!isArrayType(javaType))
        return false;
    String baseType = getArrayBaseType(javaType);
    for (UDTDefinition udt : t.getDatabase().getUDTs()) if (baseType.equals(getStrategy().getFullJavaClassName(udt, Mode.RECORD)))
        return true;
    return false;
}
Also used : UDTDefinition(org.jooq.meta.UDTDefinition)

Example 4 with UDTDefinition

use of org.jooq.meta.UDTDefinition in project jOOQ by jOOQ.

the class JavaGenerator method generateUDTs.

protected void generateUDTs(SchemaDefinition schema) {
    log.info("Generating UDTs");
    for (UDTDefinition udt : database.getUDTs(schema)) {
        try {
            generateUDT(schema, udt);
        } catch (Exception e) {
            log.error("Error while generating udt " + udt, e);
        }
    }
    watch.splitInfo("UDTs generated");
}
Also used : UDTDefinition(org.jooq.meta.UDTDefinition) IOException(java.io.IOException) SQLDialectNotSupportedException(org.jooq.exception.SQLDialectNotSupportedException) ReflectException(org.jooq.tools.reflect.ReflectException)

Example 5 with UDTDefinition

use of org.jooq.meta.UDTDefinition in project jOOQ by jOOQ.

the class JavaGenerator method generateUDTReferences.

/**
 * Generating central static udt access
 */
protected void generateUDTReferences(Definition schemaOrPackage) {
    String logSuffix = schemaOrPackage instanceof SchemaDefinition ? "" : (" for package " + schemaOrPackage.getOutputName());
    log.info("Generating UDT references" + logSuffix);
    JavaWriter out = newJavaWriter(getStrategy().getGlobalReferencesFile(schemaOrPackage, UDTDefinition.class));
    printGlobalReferencesPackage(out, schemaOrPackage, UDTDefinition.class);
    if (!kotlin) {
        printClassJavadoc(out, "Convenience access to all UDTs in " + schemaNameOrDefault(schemaOrPackage) + ".");
        printClassAnnotations(out, schemaOrPackage, Mode.DEFAULT);
    }
    final String referencesClassName = getStrategy().getGlobalReferencesJavaClassName(schemaOrPackage, UDTDefinition.class);
    if (scala)
        out.println("%sobject %s {", visibility(), referencesClassName);
    else if (kotlin) {
    } else
        out.println("%sclass %s {", visibility(), referencesClassName);
    List<UDTDefinition> udts = new ArrayList<>();
    if (schemaOrPackage instanceof SchemaDefinition) {
        for (UDTDefinition udt : database.getUDTs((SchemaDefinition) schemaOrPackage)) if (udt.getPackage() == null)
            udts.add(udt);
    } else
        udts.addAll(database.getUDTs((PackageDefinition) schemaOrPackage));
    for (UDTDefinition udt : udts) {
        final String className = out.ref(getStrategy().getFullJavaClassName(udt));
        final String id = getStrategy().getJavaIdentifier(udt);
        final String fullId = getStrategy().getFullJavaIdentifier(udt);
        out.javadoc("The type <code>%s</code>", udt.getQualifiedOutputName());
        if (scala)
            out.println("%sdef %s = %s", visibility(), id, fullId);
        else if (kotlin)
            out.println("%sval %s: %s = %s", visibility(), id, className, fullId);
        else
            out.println("%sstatic final %s %s = %s;", visibility(), className, id, fullId);
    }
    generateUDTReferencesClassFooter(schemaOrPackage, out);
    if (!kotlin)
        out.println("}");
    closeJavaWriter(out);
    watch.splitInfo("UDT references generated" + logSuffix);
    if (schemaOrPackage instanceof SchemaDefinition)
        for (PackageDefinition pkg : database.getPackages((SchemaDefinition) schemaOrPackage)) if (!pkg.getUDTs().isEmpty())
            generateUDTReferences(pkg);
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) PackageDefinition(org.jooq.meta.PackageDefinition) ArrayList(java.util.ArrayList) UDTDefinition(org.jooq.meta.UDTDefinition)

Aggregations

UDTDefinition (org.jooq.meta.UDTDefinition)9 IOException (java.io.IOException)6 SQLDialectNotSupportedException (org.jooq.exception.SQLDialectNotSupportedException)6 ReflectException (org.jooq.tools.reflect.ReflectException)6 ArrayList (java.util.ArrayList)4 PackageDefinition (org.jooq.meta.PackageDefinition)4 SchemaDefinition (org.jooq.meta.SchemaDefinition)4 AbstractTypedElementDefinition (org.jooq.meta.AbstractTypedElementDefinition)3 ArrayDefinition (org.jooq.meta.ArrayDefinition)3 AttributeDefinition (org.jooq.meta.AttributeDefinition)3 CatalogDefinition (org.jooq.meta.CatalogDefinition)3 CheckConstraintDefinition (org.jooq.meta.CheckConstraintDefinition)3 ColumnDefinition (org.jooq.meta.ColumnDefinition)3 ConstraintDefinition (org.jooq.meta.ConstraintDefinition)3 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)3 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)3 Definition (org.jooq.meta.Definition)3 DomainDefinition (org.jooq.meta.DomainDefinition)3 EmbeddableColumnDefinition (org.jooq.meta.EmbeddableColumnDefinition)3 EmbeddableDefinition (org.jooq.meta.EmbeddableDefinition)3