Search in sources :

Example 21 with DefaultDataTypeDefinition

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

the class JDBCTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    int ordinal = 0;
    for (Field<?> field : table.fields()) {
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), field.getDataType().getTypeName(), field.getDataType().length(), field.getDataType().precision(), field.getDataType().scale(), field.getDataType().nullable(), create().renderInlined(field.getDataType().defaultValue()), (Name) null);
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), field.getName(), ordinal, type, false, null);
        result.add(column);
        ordinal++;
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) ArrayList(java.util.ArrayList) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 22 with DefaultDataTypeDefinition

use of org.jooq.util.DefaultDataTypeDefinition 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 23 with DefaultDataTypeDefinition

use of org.jooq.util.DefaultDataTypeDefinition 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 24 with DefaultDataTypeDefinition

use of org.jooq.util.DefaultDataTypeDefinition 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 25 with DefaultDataTypeDefinition

use of org.jooq.util.DefaultDataTypeDefinition 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)

Aggregations

DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)29 DataTypeDefinition (org.jooq.util.DataTypeDefinition)25 ArrayList (java.util.ArrayList)22 Record (org.jooq.Record)22 SchemaDefinition (org.jooq.util.SchemaDefinition)14 ColumnDefinition (org.jooq.util.ColumnDefinition)13 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)13 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 Rdb$fields (org.jooq.util.firebird.rdb.tables.Rdb$fields)3 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)3 Rdb$procedureParameters (org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters)2 Columns (org.jooq.util.postgres.information_schema.tables.Columns)2 PgType (org.jooq.util.postgres.pg_catalog.tables.PgType)2 Name (org.jooq.Name)1 Schema (org.jooq.Schema)1 AttributeDefinition (org.jooq.util.AttributeDefinition)1