Search in sources :

Example 21 with DataTypeDefinition

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

the class MySQLRoutineDefinition method createParameter.

private ParameterDefinition createParameter(Matcher matcher, int group, int columnIndex, String paramName) {
    String paramType = matcher.group(group + 1);
    Number precision = 0;
    Number scale = 0;
    if (!StringUtils.isBlank(matcher.group(group + 2))) {
        precision = Integer.valueOf(matcher.group(group + 2));
    }
    if (!StringUtils.isBlank(matcher.group(group + 3))) {
        scale = Integer.valueOf(matcher.group(group + 3));
    }
    DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), paramType, precision, precision, scale, null, (String) null);
    return new DefaultParameterDefinition(this, paramName, columnIndex, type);
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition)

Example 22 with DataTypeDefinition

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

the class MySQLTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    for (Record record : create().select(Columns.ORDINAL_POSITION, Columns.COLUMN_NAME, Columns.COLUMN_COMMENT, Columns.COLUMN_TYPE, Columns.DATA_TYPE, Columns.IS_NULLABLE, Columns.COLUMN_DEFAULT, Columns.CHARACTER_MAXIMUM_LENGTH, Columns.NUMERIC_PRECISION, Columns.NUMERIC_SCALE, Columns.EXTRA).from(COLUMNS).where(TABLE_SCHEMA.equal(getSchema().getName())).and(TABLE_NAME.equal(getName())).orderBy(ORDINAL_POSITION)) {
        String dataType = record.get(Columns.DATA_TYPE);
        // [#519] Some types have unsigned versions
        if (getDatabase().supportsUnsignedTypes()) {
            if (asList("tinyint", "smallint", "mediumint", "int", "bigint").contains(dataType.toLowerCase())) {
                if (record.get(Columns.COLUMN_TYPE).toLowerCase().contains("unsigned")) {
                    dataType += "unsigned";
                }
            }
        }
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(Columns.CHARACTER_MAXIMUM_LENGTH), record.get(Columns.NUMERIC_PRECISION), record.get(Columns.NUMERIC_SCALE), record.get(Columns.IS_NULLABLE, boolean.class), record.get(Columns.COLUMN_DEFAULT), name(getSchema().getName(), getName() + "_" + record.get(Columns.COLUMN_NAME)));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(Columns.COLUMN_NAME), record.get(Columns.ORDINAL_POSITION, int.class), type, "auto_increment".equalsIgnoreCase(record.get(Columns.EXTRA)), record.get(Columns.COLUMN_COMMENT));
        result.add(column);
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 23 with DataTypeDefinition

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

the class DerbyTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    for (Record record : create().select(Syscolumns.COLUMNNAME, Syscolumns.COLUMNNUMBER, Syscolumns.COLUMNDATATYPE, Syscolumns.COLUMNDEFAULT, Syscolumns.AUTOINCREMENTINC).from(SYSCOLUMNS).where(Syscolumns.REFERENCEID.equal(inline(tableid))).orderBy(Syscolumns.COLUMNNUMBER).fetch()) {
        String typeName = record.get(Syscolumns.COLUMNDATATYPE, String.class);
        Number precision = parsePrecision(typeName);
        Number scale = parseScale(typeName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), parseTypeName(typeName), precision, precision, scale, !parseNotNull(typeName), record.get(Syscolumns.COLUMNDEFAULT));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(Syscolumns.COLUMNNAME), record.get(Syscolumns.COLUMNNUMBER), type, null != record.get(Syscolumns.AUTOINCREMENTINC), null);
        result.add(column);
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 24 with DataTypeDefinition

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

the class FirebirdDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (String sequenceName : create().select(RDB$GENERATORS.RDB$GENERATOR_NAME.trim()).from(RDB$GENERATORS).orderBy(1).fetch(RDB$GENERATORS.RDB$GENERATOR_NAME.trim())) {
        SchemaDefinition schema = getSchemata().get(0);
        DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, FirebirdDataType.BIGINT.getTypeName());
        result.add(new DefaultSequenceDefinition(schema, sequenceName, type));
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition)

Example 25 with DataTypeDefinition

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

the class HSQLDBDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (Record record : create().select(SEQUENCES.SEQUENCE_SCHEMA, SEQUENCES.SEQUENCE_NAME, SEQUENCES.DATA_TYPE).from(SEQUENCES).where(SEQUENCES.SEQUENCE_SCHEMA.in(getInputSchemata())).orderBy(SEQUENCES.SEQUENCE_SCHEMA, SEQUENCES.SEQUENCE_NAME).fetch()) {
        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.util.DefaultSequenceDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition)

Aggregations

DataTypeDefinition (org.jooq.util.DataTypeDefinition)26 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)25 ArrayList (java.util.ArrayList)19 Record (org.jooq.Record)19 SchemaDefinition (org.jooq.util.SchemaDefinition)13 ColumnDefinition (org.jooq.util.ColumnDefinition)10 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)10 DefaultParameterDefinition (org.jooq.util.DefaultParameterDefinition)7 DefaultSequenceDefinition (org.jooq.util.DefaultSequenceDefinition)7 SequenceDefinition (org.jooq.util.SequenceDefinition)7 ParameterDefinition (org.jooq.util.ParameterDefinition)6 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)3 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)3 Columns (org.jooq.util.postgres.information_schema.tables.Columns)2 PgType (org.jooq.util.postgres.pg_catalog.tables.PgType)2 BigInteger (java.math.BigInteger)1 Name (org.jooq.Name)1 Schema (org.jooq.Schema)1 AttributeDefinition (org.jooq.util.AttributeDefinition)1 DefaultAttributeDefinition (org.jooq.util.DefaultAttributeDefinition)1