Search in sources :

Example 6 with DataTypeDefinition

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

the class H2RoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    for (Record record : create().select(FunctionColumns.COLUMN_NAME, FunctionColumns.TYPE_NAME, FunctionColumns.PRECISION, FunctionColumns.SCALE, FunctionColumns.POS, FunctionColumns.NULLABLE, FunctionColumns.COLUMN_DEFAULT).from(FUNCTION_COLUMNS).where(FunctionColumns.ALIAS_SCHEMA.equal(getSchema().getName())).and(FunctionColumns.ALIAS_NAME.equal(getName())).and(FunctionColumns.POS.gt(0)).orderBy(FunctionColumns.POS.asc()).fetch()) {
        String paramName = record.get(FunctionColumns.COLUMN_NAME);
        String typeName = record.get(FunctionColumns.TYPE_NAME);
        Integer precision = record.get(FunctionColumns.PRECISION);
        Short scale = record.get(FunctionColumns.SCALE);
        int position = record.get(FunctionColumns.POS);
        boolean nullable = record.get(FunctionColumns.NULLABLE, boolean.class);
        String defaultValue = record.get(FunctionColumns.COLUMN_DEFAULT);
        // It is only used internally by H2 to provide a connection to the current database.
        if (position == 0 && H2DataType.OTHER.getTypeName().equalsIgnoreCase(typeName)) {
            continue;
        }
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), typeName, precision, precision, scale, nullable, defaultValue);
        ParameterDefinition parameter = new DefaultParameterDefinition(this, paramName, position, type);
        addParameter(InOutDefinition.IN, 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 7 with DataTypeDefinition

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

the class H2TableDefinition 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.TYPE_NAME, Columns.CHARACTER_MAXIMUM_LENGTH, Columns.NUMERIC_PRECISION, Columns.NUMERIC_SCALE, Columns.IS_NULLABLE, Columns.COLUMN_DEFAULT, Columns.REMARKS, Columns.SEQUENCE_NAME).from(COLUMNS).where(Columns.TABLE_SCHEMA.equal(getSchema().getName())).and(Columns.TABLE_NAME.equal(getName())).orderBy(Columns.ORDINAL_POSITION).fetch()) {
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(Columns.TYPE_NAME), 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));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(Columns.COLUMN_NAME), record.get(Columns.ORDINAL_POSITION), type, // [#5331] AUTO_INCREMENT (MySQL style)
        null != record.get(Columns.SEQUENCE_NAME) || // [#5331] DEFAULT nextval('sequence') (PostgreSQL style)
        defaultString(record.get(Columns.COLUMN_DEFAULT)).trim().toLowerCase().startsWith("nextval"), record.get(Columns.REMARKS));
        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 8 with DataTypeDefinition

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

the class XMLDatabase method getSequences0.

@Override
protected List<SequenceDefinition> getSequences0() {
    List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
    for (Sequence sequence : info().getSequences()) {
        if (getInputSchemata().contains(sequence.getSequenceSchema())) {
            SchemaDefinition schema = getSchema(sequence.getSequenceSchema());
            DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, sequence.getDataType(), sequence.getCharacterMaximumLength(), sequence.getNumericPrecision(), sequence.getNumericScale(), false, (String) null);
            result.add(new DefaultSequenceDefinition(schema, sequence.getSequenceName(), type));
        }
    }
    return result;
}
Also used : DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) SequenceDefinition(org.jooq.util.SequenceDefinition) DefaultSequenceDefinition(org.jooq.util.DefaultSequenceDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Sequence(org.jooq.util.xml.jaxb.Sequence) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition)

Example 9 with DataTypeDefinition

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

the class XMLRoutineDefinition method init0.

@Override
protected void init0() {
    for (Parameter parameter : info.getParameters()) {
        Name parameterRoutineName = name(parameter.getSpecificCatalog(), parameter.getSpecificSchema(), parameter.getSpecificPackage(), parameter.getSpecificName());
        if (getQualifiedNamePart().equals(parameterRoutineName)) {
            DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), parameter.getDataType(), parameter.getCharacterMaximumLength(), parameter.getNumericPrecision(), parameter.getNumericScale(), null, parameter.getParameterDefault());
            ParameterDefinition p = new DefaultParameterDefinition(this, parameter.getParameterName(), parameter.getOrdinalPosition(), type, !StringUtils.isBlank(parameter.getParameterDefault()), StringUtils.isBlank(parameter.getParameterName()));
            switch(parameter.getParameterMode()) {
                case IN:
                    addParameter(InOutDefinition.IN, p);
                    break;
                case INOUT:
                    addParameter(InOutDefinition.INOUT, p);
                    break;
                case OUT:
                    addParameter(InOutDefinition.OUT, p);
                    break;
            }
        }
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Parameter(org.jooq.util.xml.jaxb.Parameter) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Name(org.jooq.Name) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 10 with DataTypeDefinition

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

the class FirebirdRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
    Rdb$fields f = RDB$FIELDS.as("f");
    int i = 0;
    for (Record record : create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_TYPE, p.RDB$PARAMETER_NAME.trim().as(p.RDB$PARAMETER_NAME), FIELD_TYPE(f).as("FIELD_TYPE"), CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).orderBy(p.RDB$PARAMETER_TYPE.desc(), p.RDB$PARAMETER_NUMBER.asc())) {
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHARACTER_LENGTH", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(p.RDB$PARAMETER_NAME), i++, type);
        addParameter(record.get(p.RDB$PARAMETER_TYPE, int.class).equals(0) ? InOutDefinition.IN : InOutDefinition.OUT, parameter);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Rdb$fields(org.jooq.util.firebird.rdb.tables.Rdb$fields) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Rdb$procedureParameters(org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

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