Search in sources :

Example 16 with DataTypeDefinition

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

the class PostgresRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    for (Record record : create().select(PARAMETERS.PARAMETER_NAME, PARAMETERS.DATA_TYPE, PARAMETERS.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.NUMERIC_PRECISION, PARAMETERS.NUMERIC_SCALE, PARAMETERS.UDT_SCHEMA, PARAMETERS.UDT_NAME, PARAMETERS.ORDINAL_POSITION, PARAMETERS.PARAMETER_MODE, ((PostgresDatabase) getDatabase()).is94() ? PARAMETERS.PARAMETER_DEFAULT : inline((String) null).as(PARAMETERS.PARAMETER_DEFAULT)).from(PARAMETERS).where(PARAMETERS.SPECIFIC_SCHEMA.equal(getSchema().getName())).and(PARAMETERS.SPECIFIC_NAME.equal(specificName)).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch()) {
        String inOut = record.get(PARAMETERS.PARAMETER_MODE);
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(PARAMETERS.UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(PARAMETERS.DATA_TYPE), record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, record.get(PARAMETERS.PARAMETER_DEFAULT), name(record.get(PARAMETERS.UDT_SCHEMA), record.get(PARAMETERS.UDT_NAME)));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME), record.get(PARAMETERS.ORDINAL_POSITION), type, record.get(PARAMETERS.PARAMETER_DEFAULT) != null, StringUtils.isBlank(record.get(PARAMETERS.PARAMETER_NAME)));
        addParameter(InOutDefinition.getFromString(inOut), parameter);
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 17 with DataTypeDefinition

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

the class PostgresTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, COLUMNS.DATA_TYPE, COLUMNS.CHARACTER_MAXIMUM_LENGTH, COLUMNS.NUMERIC_PRECISION, COLUMNS.NUMERIC_SCALE, COLUMNS.IS_NULLABLE, COLUMNS.COLUMN_DEFAULT, COLUMNS.UDT_SCHEMA, COLUMNS.UDT_NAME, PG_DESCRIPTION.DESCRIPTION).from(COLUMNS).join(PG_NAMESPACE).on(COLUMNS.TABLE_SCHEMA.eq(PG_NAMESPACE.NSPNAME)).join(PG_CLASS).on(PG_CLASS.RELNAME.eq(COLUMNS.TABLE_NAME)).and(PG_CLASS.RELNAMESPACE.eq(oid(PG_NAMESPACE))).leftOuterJoin(PG_DESCRIPTION).on(PG_DESCRIPTION.OBJOID.eq(oid(PG_CLASS))).and(PG_DESCRIPTION.OBJSUBID.eq(COLUMNS.ORDINAL_POSITION)).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).orderBy(COLUMNS.ORDINAL_POSITION).fetch()) {
        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)).trim().toLowerCase().startsWith("nextval"), record.get(PG_DESCRIPTION.DESCRIPTION));
        result.add(column);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 18 with DataTypeDefinition

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

the class PostgresUDTDefinition method getElements0.

@Override
protected List<AttributeDefinition> getElements0() throws SQLException {
    List<AttributeDefinition> result = new ArrayList<AttributeDefinition>();
    for (Record record : create().select(ATTRIBUTES.ATTRIBUTE_NAME, ATTRIBUTES.ORDINAL_POSITION, ATTRIBUTES.DATA_TYPE, ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH, ATTRIBUTES.NUMERIC_PRECISION, ATTRIBUTES.NUMERIC_SCALE, ATTRIBUTES.IS_NULLABLE, ATTRIBUTES.ATTRIBUTE_DEFAULT, ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA, ATTRIBUTES.ATTRIBUTE_UDT_NAME).from(ATTRIBUTES).where(ATTRIBUTES.UDT_SCHEMA.equal(getSchema().getName())).and(ATTRIBUTES.UDT_NAME.equal(getName())).orderBy(ATTRIBUTES.ORDINAL_POSITION).fetch()) {
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema == null ? getSchema() : typeSchema, record.get(ATTRIBUTES.DATA_TYPE), record.get(ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH), record.get(ATTRIBUTES.NUMERIC_PRECISION), record.get(ATTRIBUTES.NUMERIC_SCALE), record.get(ATTRIBUTES.IS_NULLABLE, boolean.class), record.get(ATTRIBUTES.ATTRIBUTE_DEFAULT), name(record.get(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA), record.get(ATTRIBUTES.ATTRIBUTE_UDT_NAME)));
        AttributeDefinition column = new DefaultAttributeDefinition(this, record.get(ATTRIBUTES.ATTRIBUTE_NAME), record.get(ATTRIBUTES.ORDINAL_POSITION), type);
        result.add(column);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultAttributeDefinition(org.jooq.util.DefaultAttributeDefinition) AttributeDefinition(org.jooq.util.AttributeDefinition) Record(org.jooq.Record) DefaultAttributeDefinition(org.jooq.util.DefaultAttributeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition)

Example 19 with DataTypeDefinition

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

the class HSQLDBRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Result<?> result = create().select(PARAMETERS.PARAMETER_MODE, PARAMETERS.PARAMETER_NAME, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, PARAMETERS.DATA_TYPE).as("datatype"), PARAMETERS.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.NUMERIC_PRECISION, PARAMETERS.NUMERIC_SCALE, PARAMETERS.ORDINAL_POSITION).from(PARAMETERS).join(ROUTINES).on(PARAMETERS.SPECIFIC_SCHEMA.equal(ROUTINES.SPECIFIC_SCHEMA)).and(PARAMETERS.SPECIFIC_NAME.equal(ROUTINES.SPECIFIC_NAME)).leftOuterJoin(ELEMENT_TYPES).on(ROUTINES.ROUTINE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(ROUTINES.ROUTINE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(PARAMETERS.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(PARAMETERS.SPECIFIC_SCHEMA.equal(getSchema().getName())).and(PARAMETERS.SPECIFIC_NAME.equal(this.specificName)).and(condition(val(!isAggregate())).or(PARAMETERS.ORDINAL_POSITION.eq(1L))).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch();
    for (Record record : result) {
        String inOut = record.get(PARAMETERS.PARAMETER_MODE);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("datatype", String.class), record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, (String) null);
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME).replaceAll("@", ""), record.get(PARAMETERS.ORDINAL_POSITION, int.class), type);
        addParameter(InOutDefinition.getFromString(inOut), parameter);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 20 with DataTypeDefinition

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

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