Search in sources :

Example 26 with ColumnDefinition

use of org.jooq.util.ColumnDefinition 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 27 with ColumnDefinition

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

ColumnDefinition (org.jooq.util.ColumnDefinition)27 Record (org.jooq.Record)23 ArrayList (java.util.ArrayList)15 TableDefinition (org.jooq.util.TableDefinition)14 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)13 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)13 SchemaDefinition (org.jooq.util.SchemaDefinition)12 DataTypeDefinition (org.jooq.util.DataTypeDefinition)10 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)3 DefaultEnumDefinition (org.jooq.util.DefaultEnumDefinition)2 EnumDefinition (org.jooq.util.EnumDefinition)2 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 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Record5 (org.jooq.Record5)1 Schema (org.jooq.Schema)1 CSVReader (org.jooq.tools.csv.CSVReader)1 Rdb$indexSegments (org.jooq.util.firebird.rdb.tables.Rdb$indexSegments)1