Search in sources :

Example 11 with DefaultColumnDefinition

use of org.jooq.util.DefaultColumnDefinition 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 12 with DefaultColumnDefinition

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

the class SQLiteTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    int position = 0;
    for (Record record : create().fetch("pragma table_info('" + getName() + "')")) {
        position++;
        String name = record.get("name", String.class);
        String dataType = record.get("type", String.class).replaceAll("\\(\\d+(\\s*,\\s*\\d+)?\\)", "");
        Number precision = parsePrecision(record.get("type", String.class));
        Number scale = parseScale(record.get("type", String.class));
        // SQLite identities are primary keys whose tables are mentioned in
        // sqlite_sequence
        int pk = record.get("pk", int.class);
        boolean identity = pk > 0 && existsSqliteSequence() && create().fetchOne("select count(*) from sqlite_sequence where name = ?", getName()).get(0, Boolean.class);
        DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, precision, precision, scale, !record.get("notnull", boolean.class), record.get("dflt_value", String.class));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), name, position, type, identity, 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) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 13 with DefaultColumnDefinition

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

the class XMLTableDefinition method getElements0.

@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    for (Column column : info.getColumns()) {
        if (StringUtils.equals(table.getTableCatalog(), column.getTableCatalog()) && StringUtils.equals(table.getTableSchema(), column.getTableSchema()) && StringUtils.equals(table.getTableName(), 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());
            result.add(new DefaultColumnDefinition(this, column.getColumnName(), unbox(column.getOrdinalPosition()), type, column.getIdentityGeneration() != null, ""));
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) Column(org.jooq.util.xml.jaxb.Column) 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)

Aggregations

ArrayList (java.util.ArrayList)13 ColumnDefinition (org.jooq.util.ColumnDefinition)13 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)13 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)13 Record (org.jooq.Record)11 DataTypeDefinition (org.jooq.util.DataTypeDefinition)10 SchemaDefinition (org.jooq.util.SchemaDefinition)4 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)3 Rdb$fields (org.jooq.util.firebird.rdb.tables.Rdb$fields)2 Columns (org.jooq.util.postgres.information_schema.tables.Columns)2 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)2 Rdb$procedureParameters (org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters)1 Rdb$relationFields (org.jooq.util.firebird.rdb.tables.Rdb$relationFields)1 Parameters (org.jooq.util.postgres.information_schema.tables.Parameters)1 Routines (org.jooq.util.postgres.information_schema.tables.Routines)1 PgAttrdef (org.jooq.util.postgres.pg_catalog.tables.PgAttrdef)1 PgAttribute (org.jooq.util.postgres.pg_catalog.tables.PgAttribute)1 PgClass (org.jooq.util.postgres.pg_catalog.tables.PgClass)1 PgCollation (org.jooq.util.postgres.pg_catalog.tables.PgCollation)1 PgProc (org.jooq.util.postgres.pg_catalog.tables.PgProc)1