Search in sources :

Example 16 with DefaultDataTypeDefinition

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

the class XMLTableDefinition method getElements0.

@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    for (Column column : info.getColumns()) {
        if (StringUtils.equals(defaultIfNull(table.getTableCatalog(), ""), defaultIfNull(column.getTableCatalog(), "")) && StringUtils.equals(defaultIfNull(table.getTableSchema(), ""), defaultIfNull(column.getTableSchema(), "")) && StringUtils.equals(defaultIfNull(table.getTableName(), ""), defaultIfNull(column.getTableName(), ""))) {
            SchemaDefinition schema = getDatabase().getSchema(column.getTableSchema());
            DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), schema, column.getDataType(), unbox(column.getCharacterMaximumLength()), unbox(column.getNumericPrecision()), unbox(column.getNumericScale()), column.isIsNullable(), column.getColumnDefault()).generatedAlwaysAs(TRUE.equals(column.isIsGenerated()) ? column.getGenerationExpression() : null).generationOption(TRUE.equals(column.isIsGenerated()) ? "STORED".equalsIgnoreCase(column.getGenerationOption()) ? STORED : "VIRTUAL".equalsIgnoreCase(column.getGenerationOption()) ? VIRTUAL : null : null);
            result.add(new DefaultColumnDefinition(this, column.getColumnName(), unbox(column.getOrdinalPosition()), type, column.getIdentityGeneration() != null, TRUE.equals(column.isReadonly()), column.getComment()));
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) Column(org.jooq.util.xml.jaxb.Column) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition)

Example 17 with DefaultDataTypeDefinition

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

the class CUBRIDTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    for (Record record : create().select(DB_ATTRIBUTE.ATTR_NAME, DB_ATTRIBUTE.DEF_ORDER, DB_ATTRIBUTE.DATA_TYPE, DB_ATTRIBUTE.PREC, DB_ATTRIBUTE.SCALE, DB_ATTRIBUTE.IS_NULLABLE, DB_ATTRIBUTE.DEFAULT_VALUE, DB_SERIAL.NAME).from(DB_ATTRIBUTE).leftOuterJoin(DB_SERIAL).on(DB_ATTRIBUTE.ATTR_NAME.equal(DB_SERIAL.ATT_NAME).and(DB_ATTRIBUTE.CLASS_NAME.equal(DB_SERIAL.CLASS_NAME))).where(DB_ATTRIBUTE.CLASS_NAME.equal(getName())).orderBy(DB_ATTRIBUTE.DEF_ORDER)) {
        String dataType = record.get(DB_ATTRIBUTE.DATA_TYPE);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(DB_ATTRIBUTE.PREC), record.get(DB_ATTRIBUTE.PREC), record.get(DB_ATTRIBUTE.SCALE), record.get(DB_ATTRIBUTE.IS_NULLABLE, boolean.class), record.get(DB_ATTRIBUTE.DEFAULT_VALUE), getName() + "_" + record.get(DB_ATTRIBUTE.ATTR_NAME));
        result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(DB_ATTRIBUTE.ATTR_NAME), result.size() + 1, type, record.get(DB_SERIAL.NAME) != null, null));
    }
    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) ColumnDefinition(org.jooq.meta.ColumnDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition)

Example 18 with DefaultDataTypeDefinition

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

the class DerbyDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<>();
    for (Record record : sequences(getInputSchemata())) {
        SchemaDefinition schema = getSchema(record.get(SYSSEQUENCES.sysschemas().SCHEMANAME));
        DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SYSSEQUENCES.SEQUENCEDATATYPE));
        result.add(new DefaultSequenceDefinition(schema, record.get(SYSSEQUENCES.SEQUENCENAME), type, null, record.get(SYSSEQUENCES.STARTVALUE), record.get(SYSSEQUENCES.INCREMENT), record.get(SYSSEQUENCES.MINIMUMVALUE), record.get(SYSSEQUENCES.MAXIMUMVALUE), record.get(SYSSEQUENCES.CYCLEOPTION, Boolean.class), null));
    }
    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 19 with DefaultDataTypeDefinition

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

the class MariaDBDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<>();
    for (Record record : create().select(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME).from(TABLES).where(TABLES.TABLE_TYPE.eq("SEQUENCE"))) {
        SchemaDefinition schema = getSchema(record.get(TABLES.TABLE_SCHEMA));
        if (schema != null) {
            String name = record.get(TABLES.TABLE_NAME);
            DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, BIGINT.getTypeName());
            Field<Long> startWith = nullif(field("start_value", BIGINT), inline(1L));
            Field<Long> incrementBy = nullif(field("increment", BIGINT), inline(1L));
            Field<Long> minValue = inline(field("minimum_value", BIGINT), inline(1L));
            Field<Long> maxValue = nullif(field("maximum_value", BIGINT), inline(DEFAULT_SEQUENCE_MAXVALUE));
            Field<Boolean> cycle = field("cycle_option", BOOLEAN);
            Field<Long> cache = nullif(field("cache_size", BIGINT), inline(DEFAULT_SEQUENCE_CACHE));
            Record flags = create().select(startWith, incrementBy, minValue, maxValue, cycle, cache).from(name(schema.getName(), name)).fetchOne();
            result.add(new DefaultSequenceDefinition(schema, name, type, null, flags.get(startWith), flags.get(incrementBy), flags.get(minValue), flags.get(maxValue), flags.get(cycle), flags.get(cache)));
        }
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Example 20 with DefaultDataTypeDefinition

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

the class MySQLRoutineDefinition method init55.

private void init55() {
    // table is available, which is much more reliable than mysql.proc
    for (Record record : create().select(PARAMETERS.ORDINAL_POSITION, PARAMETERS.PARAMETER_NAME, PARAMETERS.PARAMETER_MODE, PARAMETERS.DATA_TYPE, PARAMETERS.DTD_IDENTIFIER, PARAMETERS.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.NUMERIC_PRECISION, PARAMETERS.NUMERIC_SCALE).from(PARAMETERS).where(PARAMETERS.SPECIFIC_SCHEMA.in(getSchema().getInputName(), getSchema().getInputName())).and(PARAMETERS.SPECIFIC_NAME.eq(getInputName())).and(PARAMETERS.ROUTINE_TYPE.eq(procType.name())).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch()) {
        String inOut = record.get(PARAMETERS.PARAMETER_MODE);
        String dataType = record.get(PARAMETERS.DATA_TYPE);
        // [#519] Some types have unsigned versions
        if (getDatabase().supportsUnsignedTypes()) {
            if (asList("tinyint", "smallint", "mediumint", "int", "bigint").contains(dataType.toLowerCase())) {
                if (record.get(PARAMETERS.DTD_IDENTIFIER).toLowerCase().contains("unsigned")) {
                    dataType += "unsigned";
                }
            }
        }
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, (String) null);
        if (inOut == null) {
            addParameter(InOutDefinition.RETURN, new DefaultParameterDefinition(this, "RETURN_VALUE", -1, type));
        } else {
            ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME).replaceAll("@", ""), record.get(PARAMETERS.ORDINAL_POSITION, int.class), type);
            addParameter(InOutDefinition.getFromString(inOut), parameter);
        }
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) ParameterDefinition(org.jooq.meta.ParameterDefinition) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition)

Aggregations

DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)36 Record (org.jooq.Record)30 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)30 ArrayList (java.util.ArrayList)27 SchemaDefinition (org.jooq.meta.SchemaDefinition)19 ColumnDefinition (org.jooq.meta.ColumnDefinition)14 DefaultColumnDefinition (org.jooq.meta.DefaultColumnDefinition)14 DefaultParameterDefinition (org.jooq.meta.DefaultParameterDefinition)8 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)7 ParameterDefinition (org.jooq.meta.ParameterDefinition)7 SequenceDefinition (org.jooq.meta.SequenceDefinition)7 DefaultDomainDefinition (org.jooq.meta.DefaultDomainDefinition)5 DomainDefinition (org.jooq.meta.DomainDefinition)5 Rdb$fields (org.jooq.meta.firebird.rdb.tables.Rdb$fields)4 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 Rdb$procedureParameters (org.jooq.meta.firebird.rdb.tables.Rdb$procedureParameters)2 DomainConstraints (org.jooq.meta.hsqldb.information_schema.tables.DomainConstraints)2 Columns (org.jooq.meta.postgres.information_schema.tables.Columns)2