Search in sources :

Example 11 with DataTypeDefinition

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

the class CUBRIDDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (Record record : create().select(DB_SERIAL.NAME, DB_SERIAL.MAX_VAL).from(DB_SERIAL).fetch()) {
        BigInteger value = defaultIfNull(record.get(DB_SERIAL.MAX_VAL, BigInteger.class), BigInteger.valueOf(Long.MAX_VALUE));
        DataTypeDefinition type = getDataTypeForMAX_VAL(getSchemata().get(0), value);
        result.add(new DefaultSequenceDefinition(getSchemata().get(0), record.get(DB_SERIAL.NAME), type));
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Record(org.jooq.Record) DataTypeDefinition(org.jooq.util.DataTypeDefinition)

Example 12 with DataTypeDefinition

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

the class CUBRIDTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    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).fetch()) {
        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));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(DB_ATTRIBUTE.ATTR_NAME), record.get(DB_ATTRIBUTE.DEF_ORDER), type, record.get(DB_SERIAL.NAME) != null, 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 13 with DataTypeDefinition

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

the class DerbyDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (Record record : create().select(Sysschemas.SCHEMANAME, Syssequences.SEQUENCENAME, Syssequences.SEQUENCEDATATYPE).from(SYSSEQUENCES).join(SYSSCHEMAS).on(Sysschemas.SCHEMAID.equal(Syssequences.SCHEMAID)).where(Sysschemas.SCHEMANAME.in(getInputSchemata())).orderBy(Sysschemas.SCHEMANAME, Syssequences.SEQUENCENAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(Sysschemas.SCHEMANAME));
        DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(Syssequences.SEQUENCEDATATYPE));
        result.add(new DefaultSequenceDefinition(schema, record.get(Syssequences.SEQUENCENAME, String.class), 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)

Example 14 with DataTypeDefinition

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

the class PostgresDatabase method getDomains0.

@SuppressWarnings("unchecked")
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
    List<DomainDefinition> result = new ArrayList<DomainDefinition>();
    if (existAll(PG_CONSTRAINT, PG_TYPE)) {
        PgNamespace n = PG_NAMESPACE.as("n");
        PgConstraint c = PG_CONSTRAINT.as("c");
        PgType d = PG_TYPE.as("d");
        PgType b = PG_TYPE.as("b");
        Field<String[]> src = field(name("domains", "src"), String[].class);
        for (Record record : create().withRecursive("domains", "domain_id", "base_id", "typbasetype", "src").as(select(oid(d), oid(d), d.TYPBASETYPE, array(c.CONSRC)).from(d).join(n).on(oid(n).eq(d.TYPNAMESPACE)).leftJoin(c).on(oid(d).eq(c.CONTYPID)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).unionAll(select(field(name("domains", "domain_id"), Long.class), oid(d), d.TYPBASETYPE, decode().when(c.CONSRC.isNull(), src).otherwise(arrayAppend(src, c.CONSRC))).from(name("domains")).join(d).on(field(name("domains", d.TYPBASETYPE.getName())).eq(oid(d))).leftJoin(c).on(oid(d).eq(c.CONTYPID)))).select(n.NSPNAME, d.TYPNAME, d.TYPNOTNULL, d.TYPDEFAULT, b.TYPNAME, b.TYPLEN, src).from(d).join(name("domains")).on(field(name("domains", "typbasetype")).eq(0)).and(field(name("domains", "domain_id")).eq(oid(d))).join(b).on(field(name("domains", "base_id")).eq(oid(b))).join(n).on(oid(n).eq(d.TYPNAMESPACE)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata()))) {
            SchemaDefinition schema = getSchema(record.get(n.NSPNAME));
            DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(b.TYPNAME), record.get(b.TYPLEN), record.get(b.TYPLEN), // ?
            0, !record.get(d.TYPNOTNULL, boolean.class), record.get(d.TYPDEFAULT), name(record.get(n.NSPNAME), record.get(b.TYPNAME)));
            DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.TYPNAME), baseType);
            domain.addCheckClause(record.get(src));
            result.add(domain);
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DomainDefinition(org.jooq.util.DomainDefinition) DefaultDomainDefinition(org.jooq.util.DefaultDomainDefinition) PgType(org.jooq.util.postgres.pg_catalog.tables.PgType) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDomainDefinition(org.jooq.util.DefaultDomainDefinition) PgConstraint(org.jooq.util.postgres.pg_catalog.tables.PgConstraint) Record(org.jooq.Record) PgNamespace(org.jooq.util.postgres.pg_catalog.tables.PgNamespace)

Example 15 with DataTypeDefinition

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

the class PostgresMaterializedViewDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    Columns col = COLUMNS;
    PgAttribute a = PG_ATTRIBUTE.as("a");
    PgAttrdef ad = PG_ATTRDEF.as("ad");
    PgType t = PG_TYPE.as("t");
    PgType bt = PG_TYPE.as("bt");
    PgClass c = PG_CLASS.as("c");
    PgCollation co = PG_COLLATION.as("co");
    PgNamespace nt = PG_NAMESPACE.as("nt");
    PgNamespace nc = PG_NAMESPACE.as("nc");
    PgNamespace nbt = PG_NAMESPACE.as("nbt");
    PgNamespace nco = PG_NAMESPACE.as("nco");
    for (Record record : create().select(field("({0})::information_schema.sql_identifier", col.COLUMN_NAME.getDataType(), a.ATTNAME).as(col.COLUMN_NAME), field("({0})::information_schema.cardinal_number", col.ORDINAL_POSITION.getDataType(), a.ATTNUM).as(col.ORDINAL_POSITION), field("({0})::information_schema.character_data", col.DATA_TYPE.getDataType(), when(t.TYPTYPE.eq(inline("d")), when(bt.TYPELEM.ne(inline(0L)).and(bt.TYPLEN.eq(inline((short) -1))), inline("ARRAY")).when(nbt.NSPNAME.eq(inline("pg_catalog")), field("format_type({0}, NULL::integer)", String.class, t.TYPBASETYPE)).otherwise(inline("USER-DEFINED"))).otherwise(when(t.TYPELEM.ne(inline(0L)).and(t.TYPLEN.eq(inline((short) -1))), inline("ARRAY")).when(nt.NSPNAME.eq(inline("pg_catalog")), field("format_type({0}, NULL::integer)", String.class, a.ATTTYPID)).otherwise(inline("USER-DEFINED")))).as(col.DATA_TYPE), field("(information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.CHARACTER_MAXIMUM_LENGTH.getDataType()).as(col.CHARACTER_MAXIMUM_LENGTH), field("(information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.NUMERIC_PRECISION.getDataType()).as(col.NUMERIC_PRECISION), field("(information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.NUMERIC_SCALE.getDataType()).as(col.NUMERIC_SCALE), field("({0})::information_schema.yes_or_no", col.IS_NULLABLE.getDataType(), when(condition(a.ATTNOTNULL).or(t.TYPTYPE.eq(inline("d")).and(t.TYPNOTNULL)), inline("NO")).otherwise(inline("YES"))).as(col.IS_NULLABLE), field("(pg_get_expr({0}, {1}))::information_schema.character_data", col.COLUMN_DEFAULT.getDataType(), ad.ADBIN, ad.ADRELID).as(col.COLUMN_DEFAULT), field("({0})::information_schema.sql_identifier", col.UDT_SCHEMA.getDataType(), nvl(nbt.NSPNAME, nt.NSPNAME)).as(col.UDT_SCHEMA), field("({0})::information_schema.sql_identifier", col.UDT_NAME.getDataType(), nvl(bt.TYPNAME, t.TYPNAME)).as(col.UDT_NAME), PG_DESCRIPTION.DESCRIPTION).from(a.leftJoin(ad).on(a.ATTRELID.eq(ad.ADRELID)).and(a.ATTNUM.eq(ad.ADNUM)).join(c.join(nc).on(c.RELNAMESPACE.eq(oid(nc)))).on(a.ATTRELID.eq(oid(c))).join(t.join(nt).on(t.TYPNAMESPACE.eq(oid(nt)))).on(a.ATTTYPID.eq(oid(t)))).leftJoin(bt.join(nbt).on(bt.TYPNAMESPACE.eq(oid(nbt)))).on(t.TYPTYPE.eq(inline("d")).and(t.TYPBASETYPE.eq(oid(bt)))).leftJoin(co.join(nco).on(co.COLLNAMESPACE.eq(oid(nco)))).on(a.ATTCOLLATION.eq(oid(co)).and(nco.NSPNAME.ne(inline("pg_catalog")).or(co.COLLNAME.ne(inline("default"))))).leftJoin(PG_DESCRIPTION).on(PG_DESCRIPTION.OBJOID.eq(oid(c))).and(PG_DESCRIPTION.OBJSUBID.eq(a.ATTNUM.coerce(PG_DESCRIPTION.OBJSUBID))).where(not(condition("pg_is_other_temp_schema({0})", oid(nc))).and(a.ATTNUM.gt(inline((short) 0))).and(not(a.ATTISDROPPED)).and(c.RELKIND.eq(inline("m"))).and(nc.NSPNAME.in(getSchema().getName())).and(c.RELNAME.eq(getName()))).orderBy(a.ATTNUM)) {
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(COLUMNS.UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(COLUMNS.DATA_TYPE), 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(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME)));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), record.get(COLUMNS.ORDINAL_POSITION, int.class), type, defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).startsWith("nextval"), record.get(PG_DESCRIPTION.DESCRIPTION));
        result.add(column);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) PgType(org.jooq.util.postgres.pg_catalog.tables.PgType) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) PgAttrdef(org.jooq.util.postgres.pg_catalog.tables.PgAttrdef) ArrayList(java.util.ArrayList) Columns(org.jooq.util.postgres.information_schema.tables.Columns) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) PgClass(org.jooq.util.postgres.pg_catalog.tables.PgClass) Record(org.jooq.Record) PgAttribute(org.jooq.util.postgres.pg_catalog.tables.PgAttribute) PgCollation(org.jooq.util.postgres.pg_catalog.tables.PgCollation) PgNamespace(org.jooq.util.postgres.pg_catalog.tables.PgNamespace)

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