Search in sources :

Example 1 with DataTypeDefinition

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

the class JavaGenerator method printValidationAnnotation.

private void printValidationAnnotation(JavaWriter out, TypedElementDefinition<?> column) {
    if (generateValidationAnnotations()) {
        String prefix = kotlin ? "get:" : "";
        DataTypeDefinition type = column.getType(resolver(out));
        // [#5128] defaulted columns are nullable in Java
        if (!column.getType(resolver(out)).isNullable() && !column.getType(resolver(out)).isDefaulted() && !column.getType(resolver(out)).isIdentity())
            out.println("@%s%s", prefix, out.ref("jakarta.validation.constraints.NotNull"));
        String javaType = getJavaType(type, out);
        if ("java.lang.String".equals(javaType) || "byte[]".equals(javaType)) {
            int length = type.getLength();
            if (length > 0)
                out.println("@%s%s(max = %s)", prefix, out.ref("jakarta.validation.constraints.Size"), length);
        }
    }
}
Also used : DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 2 with DataTypeDefinition

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

the class FirebirdRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
    Rdb$functionArguments a = RDB$FUNCTION_ARGUMENTS.as("a");
    Rdb$fields f = RDB$FIELDS.as("f");
    int i = 0;
    for (Record record : returnValue == null ? create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_TYPE, p.RDB$PARAMETER_NAME.trim().as(p.RDB$PARAMETER_NAME), FIELD_TYPE(f).as("FIELD_TYPE"), CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).orderBy(p.RDB$PARAMETER_TYPE.desc(), p.RDB$PARAMETER_NUMBER.asc()) : create().select(a.RDB$ARGUMENT_POSITION.as(p.RDB$PARAMETER_NUMBER), inline(0).as(p.RDB$PARAMETER_TYPE), a.RDB$ARGUMENT_NAME.trim().as(p.RDB$PARAMETER_NAME), FIELD_TYPE(f).as("FIELD_TYPE"), CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), DSL.bitOr(a.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), a.RDB$DEFAULT_SOURCE).from(a).leftOuterJoin(f).on(a.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(a.RDB$FUNCTION_NAME.eq(getName())).and(a.RDB$ARGUMENT_POSITION.gt(inline((short) 0))).orderBy(a.RDB$ARGUMENT_POSITION)) {
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(p.RDB$PARAMETER_NAME), i++, type);
        addParameter(record.get(p.RDB$PARAMETER_TYPE, int.class).equals(0) ? InOutDefinition.IN : InOutDefinition.OUT, parameter);
    }
}
Also used : Rdb$functionArguments(org.jooq.meta.firebird.rdb.tables.Rdb$functionArguments) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) Rdb$fields(org.jooq.meta.firebird.rdb.tables.Rdb$fields) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) Rdb$procedureParameters(org.jooq.meta.firebird.rdb.tables.Rdb$procedureParameters) ParameterDefinition(org.jooq.meta.ParameterDefinition) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition)

Example 3 with DataTypeDefinition

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

the class H2TableDefinition method getElements1_4.

public List<ColumnDefinition> getElements1_4() {
    List<ColumnDefinition> result = new ArrayList<>();
    // [#7206] H2 defaults to these precision/scale values when a DECIMAL/NUMERIC type
    // does not have any precision/scale. What works in H2 works in almost no
    // other database, which is relevant when using the DDLDatabase for instance,
    // which is based on the H2Database
    Param<Long> maxP = inline(65535L);
    Param<Long> maxS = inline(32767L);
    H2Database db = (H2Database) getDatabase();
    for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, // [#2230] [#11733] Translate INTERVAL_TYPE to supported types
    (db.is1_4_198() ? (when(COLUMNS.INTERVAL_TYPE.like(any(inline("%YEAR%"), inline("%MONTH%"))), inline("INTERVAL YEAR TO MONTH")).when(COLUMNS.INTERVAL_TYPE.like(any(inline("%DAY%"), inline("%HOUR%"), inline("%MINUTE%"), inline("%SECOND%"))), inline("INTERVAL DAY TO SECOND")).else_(COLUMNS.TYPE_NAME)) : COLUMNS.TYPE_NAME).as(COLUMNS.TYPE_NAME), choose().when(COLUMNS.NUMERIC_PRECISION.eq(maxP).and(COLUMNS.NUMERIC_SCALE.eq(maxS)), inline(0L)).otherwise(COLUMNS.CHARACTER_MAXIMUM_LENGTH).as(COLUMNS.CHARACTER_MAXIMUM_LENGTH), COLUMNS.NUMERIC_PRECISION.decode(maxP, inline(0L), COLUMNS.NUMERIC_PRECISION).as(COLUMNS.NUMERIC_PRECISION), COLUMNS.NUMERIC_SCALE.decode(maxS, inline(0L), COLUMNS.NUMERIC_SCALE).as(COLUMNS.NUMERIC_SCALE), COLUMNS.IS_NULLABLE, COLUMNS.IS_COMPUTED.as(COLUMNS.IS_COMPUTED), COLUMNS.COLUMN_DEFAULT.as("GENERATION_EXPRESSION"), COLUMNS.COLUMN_DEFAULT, COLUMNS.REMARKS, field(COLUMNS.SEQUENCE_NAME.isNotNull()).as("IS_IDENTITY"), db.is1_4_198() ? COLUMNS.DOMAIN_SCHEMA : inline("").as(COLUMNS.DOMAIN_SCHEMA), db.is1_4_198() ? COLUMNS.DOMAIN_NAME : inline("").as(COLUMNS.DOMAIN_NAME)).from(COLUMNS).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).and(!getDatabase().getIncludeInvisibleColumns() ? db.is1_4_198() ? COLUMNS.IS_VISIBLE.eq(inline("TRUE")) : COLUMNS.COLUMN_TYPE.notLike(inline("%INVISIBLE%")) : noCondition()).orderBy(COLUMNS.ORDINAL_POSITION)) {
        // [#5331] AUTO_INCREMENT (MySQL style)
        // [#5331] DEFAULT nextval('sequence') (PostgreSQL style)
        // [#6332] [#6339] system-generated defaults shouldn't produce a default clause
        boolean isIdentity = record.get("IS_IDENTITY", boolean.class) || defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).trim().toLowerCase().startsWith("nextval");
        boolean isComputed = record.get(COLUMNS.IS_COMPUTED, boolean.class);
        // [#7644] H2 1.4.200 puts DATETIME_PRECISION in NUMERIC_SCALE column
        boolean isTimestamp = record.get(COLUMNS.TYPE_NAME).trim().toLowerCase().startsWith("timestamp");
        // [#681] Domain name if available
        Name userType = record.get(COLUMNS.DOMAIN_NAME) != null ? name(record.get(COLUMNS.DOMAIN_SCHEMA), record.get(COLUMNS.DOMAIN_NAME)) : name(getSchema().getName(), getName() + "_" + record.get(COLUMNS.COLUMN_NAME));
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(COLUMNS.TYPE_NAME), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), isTimestamp ? record.get(COLUMNS.NUMERIC_SCALE) : record.get(COLUMNS.NUMERIC_PRECISION), isTimestamp ? 0 : record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), isIdentity || isComputed ? null : record.get(COLUMNS.COLUMN_DEFAULT), userType).generatedAlwaysAs(isComputed ? record.get("GENERATION_EXPRESSION", String.class) : null);
        result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, isIdentity, record.get(COLUMNS.REMARKS)));
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition) Name(org.jooq.Name)

Example 4 with DataTypeDefinition

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

the class HSQLDBDatabase 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));
        DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SEQUENCES.DATA_TYPE));
        result.add(new DefaultSequenceDefinition(schema, record.get(SEQUENCES.SEQUENCE_NAME), type));
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 5 with DataTypeDefinition

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

the class HSQLDBTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, // [#2230] Translate INTERVAL_TYPE to supported types
    when(COLUMNS.INTERVAL_TYPE.like(any(inline("%YEAR%"), inline("%MONTH%"))), inline("INTERVAL YEAR TO MONTH")).when(COLUMNS.INTERVAL_TYPE.like(any(inline("%DAY%"), inline("%HOUR%"), inline("%MINUTE%"), inline("%SECOND%"))), inline("INTERVAL DAY TO SECOND")).else_(COLUMNS.DATA_TYPE)).as(COLUMNS.DATA_TYPE), COLUMNS.IDENTITY_GENERATION, COLUMNS.IS_NULLABLE, COLUMNS.COLUMN_DEFAULT, COLUMNS.GENERATION_EXPRESSION, nvl(ELEMENT_TYPES.CHARACTER_MAXIMUM_LENGTH, COLUMNS.CHARACTER_MAXIMUM_LENGTH).as(COLUMNS.CHARACTER_MAXIMUM_LENGTH), coalesce(ELEMENT_TYPES.DATETIME_PRECISION, ELEMENT_TYPES.NUMERIC_PRECISION, COLUMNS.DATETIME_PRECISION, COLUMNS.NUMERIC_PRECISION).as(COLUMNS.NUMERIC_PRECISION), nvl(ELEMENT_TYPES.NUMERIC_SCALE, COLUMNS.NUMERIC_SCALE).as(COLUMNS.NUMERIC_SCALE), coalesce(COLUMNS.DOMAIN_SCHEMA, COLUMNS.UDT_SCHEMA).as(COLUMNS.UDT_SCHEMA), coalesce(COLUMNS.DOMAIN_NAME, COLUMNS.UDT_NAME).as(COLUMNS.UDT_NAME), SYSTEM_COLUMNS.REMARKS).from(COLUMNS).leftOuterJoin(SYSTEM_COLUMNS).on(COLUMNS.TABLE_CATALOG.eq(SYSTEM_COLUMNS.TABLE_CAT)).and(COLUMNS.TABLE_SCHEMA.eq(SYSTEM_COLUMNS.TABLE_SCHEM)).and(COLUMNS.TABLE_NAME.eq(SYSTEM_COLUMNS.TABLE_NAME)).and(COLUMNS.COLUMN_NAME.eq(SYSTEM_COLUMNS.COLUMN_NAME)).leftOuterJoin(ELEMENT_TYPES).on(COLUMNS.TABLE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(COLUMNS.TABLE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(COLUMNS.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).orderBy(COLUMNS.ORDINAL_POSITION)) {
        String generated = record.get(COLUMNS.GENERATION_EXPRESSION);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(COLUMNS.DATA_TYPE), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), record.get(COLUMNS.NUMERIC_PRECISION), record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), generated != null ? null : record.get(COLUMNS.COLUMN_DEFAULT), DSL.name(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME))).generatedAlwaysAs(generated);
        result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, null != record.get(COLUMNS.IDENTITY_GENERATION), record.get(SYSTEM_COLUMNS.REMARKS)));
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition)

Aggregations

DataTypeDefinition (org.jooq.meta.DataTypeDefinition)33 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)31 Record (org.jooq.Record)26 ArrayList (java.util.ArrayList)23 SchemaDefinition (org.jooq.meta.SchemaDefinition)18 ColumnDefinition (org.jooq.meta.ColumnDefinition)12 DefaultColumnDefinition (org.jooq.meta.DefaultColumnDefinition)11 DefaultParameterDefinition (org.jooq.meta.DefaultParameterDefinition)8 ParameterDefinition (org.jooq.meta.ParameterDefinition)7 SequenceDefinition (org.jooq.meta.SequenceDefinition)7 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)6 DefaultDomainDefinition (org.jooq.meta.DefaultDomainDefinition)5 DomainDefinition (org.jooq.meta.DomainDefinition)5 Name (org.jooq.Name)3 PgNamespace (org.jooq.meta.postgres.pg_catalog.tables.PgNamespace)3 PgType (org.jooq.meta.postgres.pg_catalog.tables.PgType)3 BigInteger (java.math.BigInteger)2 Rdb$fields (org.jooq.meta.firebird.rdb.tables.Rdb$fields)2 DomainConstraints (org.jooq.meta.hsqldb.information_schema.tables.DomainConstraints)2 Columns (org.jooq.meta.postgres.information_schema.tables.Columns)2