Search in sources :

Example 1 with CatalogDefinition

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

the class JavaGenerator method printClassAnnotations.

protected void printClassAnnotations(JavaWriter out, Definition definition, Mode mode) {
    if (generateGeneratedAnnotation()) {
        SchemaDefinition schema = definition.getSchema();
        CatalogDefinition catalog = definition.getCatalog();
        // [#7581] The concrete annotation type depends on the JDK, with
        // javax.annotation.Generated being deprecated in JDK 9
        GeneratedAnnotationType type = generateGeneratedAnnotationType();
        if (type == null)
            type = GeneratedAnnotationType.DETECT_FROM_JDK;
        String generated;
        switch(type) {
            case DETECT_FROM_JDK:
                try {
                    // Seems more reliable than tampering with java.version
                    Reflect.onClass("java.util.Optional").call("of", new Object()).call("stream");
                    generated = "javax.annotation.processing.Generated";
                } catch (ReflectException e) {
                    generated = "javax.annotation.Generated";
                }
                break;
            case JAVAX_ANNOTATION_GENERATED:
                generated = "javax.annotation.Generated";
                break;
            case JAVAX_ANNOTATION_PROCESSING_GENERATED:
                generated = "javax.annotation.processing.Generated";
                break;
            default:
                throw new IllegalStateException("Unsupported type: " + type);
        }
        out.println("@%s(", out.ref(generated));
        if (useSchemaVersionProvider() || useCatalogVersionProvider()) {
            boolean hasCatalogVersion = !StringUtils.isBlank(catalogVersions.get(catalog));
            boolean hasSchemaVersion = !StringUtils.isBlank(schemaVersions.get(schema));
            if (scala)
                out.println("value = %s(", out.ref("scala.Array"));
            else if (kotlin)
                out.println("value = [");
            else
                out.println("value = {");
            out.println("\"https://www.jooq.org\",");
            out.println("\"jOOQ version:%s\"%s", Constants.VERSION, (hasCatalogVersion || hasSchemaVersion ? "," : ""));
            if (hasCatalogVersion)
                out.println("\"catalog version:%s\"%s", escapeString(catalogVersions.get(catalog)), (hasSchemaVersion ? "," : ""));
            if (hasSchemaVersion)
                out.println("\"schema version:%s\"", escapeString(schemaVersions.get(schema)));
            if (scala)
                out.println("),");
            else if (kotlin)
                out.println("],");
            else
                out.println("},");
            if (generateGeneratedAnnotationDate())
                out.println("date = \"" + isoDate + "\",");
            out.println("comments = \"This class is generated by jOOQ\"");
        } else {
            if (scala)
                out.println("value = %s(", out.ref("scala.Array"));
            else if (kotlin)
                out.println("value = [");
            else
                out.println("value = {");
            out.println("\"https://www.jooq.org\",");
            out.println("\"jOOQ version:%s\"", Constants.VERSION);
            if (scala)
                out.println("),");
            else if (kotlin)
                out.println("],");
            else
                out.println("},");
            out.println("comments = \"This class is generated by jOOQ\"");
        }
        out.println(")");
    }
    if (scala) {
    } else if (kotlin)
        out.println("@Suppress(\"UNCHECKED_CAST\")");
    else
        out.println("@%s({ \"all\", \"unchecked\", \"rawtypes\" })", out.ref("java.lang.SuppressWarnings"));
}
Also used : CatalogDefinition(org.jooq.meta.CatalogDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) GeneratedAnnotationType(org.jooq.meta.jaxb.GeneratedAnnotationType) ReflectException(org.jooq.tools.reflect.ReflectException)

Example 2 with CatalogDefinition

use of org.jooq.meta.CatalogDefinition 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;
}
Also used : CatalogDefinition(org.jooq.meta.CatalogDefinition) TypedElementDefinition(org.jooq.meta.TypedElementDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) AttributeDefinition(org.jooq.meta.AttributeDefinition) TableDefinition(org.jooq.meta.TableDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition)

Example 3 with CatalogDefinition

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

the class PostgresDatabase method getCatalogs0.

@Override
protected List<CatalogDefinition> getCatalogs0() throws SQLException {
    List<CatalogDefinition> result = new ArrayList<>();
    result.add(new CatalogDefinition(this, "", ""));
    return result;
}
Also used : CatalogDefinition(org.jooq.meta.CatalogDefinition) ArrayList(java.util.ArrayList)

Example 4 with CatalogDefinition

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

the class HSQLDBDatabase method getCatalogs0.

@Override
protected List<CatalogDefinition> getCatalogs0() throws SQLException {
    List<CatalogDefinition> result = new ArrayList<>();
    result.add(new CatalogDefinition(this, "", ""));
    return result;
}
Also used : CatalogDefinition(org.jooq.meta.CatalogDefinition) ArrayList(java.util.ArrayList)

Example 5 with CatalogDefinition

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

the class FirebirdDatabase method getCatalogs0.

@Override
protected List<CatalogDefinition> getCatalogs0() throws SQLException {
    List<CatalogDefinition> result = new ArrayList<>();
    result.add(new CatalogDefinition(this, "", ""));
    return result;
}
Also used : CatalogDefinition(org.jooq.meta.CatalogDefinition) ArrayList(java.util.ArrayList)

Aggregations

CatalogDefinition (org.jooq.meta.CatalogDefinition)13 ArrayList (java.util.ArrayList)9 SchemaDefinition (org.jooq.meta.SchemaDefinition)3 ColumnDefinition (org.jooq.meta.ColumnDefinition)2 TableDefinition (org.jooq.meta.TableDefinition)2 ReflectException (org.jooq.tools.reflect.ReflectException)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 BigInteger (java.math.BigInteger)1 SQLDialectNotSupportedException (org.jooq.exception.SQLDialectNotSupportedException)1 AttributeDefinition (org.jooq.meta.AttributeDefinition)1 CheckConstraintDefinition (org.jooq.meta.CheckConstraintDefinition)1 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)1 ForeignKeyDefinition (org.jooq.meta.ForeignKeyDefinition)1 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)1 IndexDefinition (org.jooq.meta.IndexDefinition)1 PackageDefinition (org.jooq.meta.PackageDefinition)1 RoutineDefinition (org.jooq.meta.RoutineDefinition)1 SequenceDefinition (org.jooq.meta.SequenceDefinition)1 TypedElementDefinition (org.jooq.meta.TypedElementDefinition)1