use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class DerbyDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SYSSEQUENCES.sysschemas().SCHEMANAME));
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SYSSEQUENCES.SEQUENCEDATATYPE));
result.add(new DefaultSequenceDefinition(schema, record.get(SYSSEQUENCES.SEQUENCENAME), type, null, record.get(SYSSEQUENCES.STARTVALUE), record.get(SYSSEQUENCES.INCREMENT), record.get(SYSSEQUENCES.MINIMUMVALUE), record.get(SYSSEQUENCES.MAXIMUMVALUE), record.get(SYSSEQUENCES.CYCLEOPTION, Boolean.class), null));
}
return result;
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class MySQLRoutineDefinition method init55.
private void init55() {
// table is available, which is much more reliable than mysql.proc
for (Record record : create().select(PARAMETERS.ORDINAL_POSITION, PARAMETERS.PARAMETER_NAME, PARAMETERS.PARAMETER_MODE, PARAMETERS.DATA_TYPE, PARAMETERS.DTD_IDENTIFIER, PARAMETERS.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.NUMERIC_PRECISION, PARAMETERS.NUMERIC_SCALE).from(PARAMETERS).where(PARAMETERS.SPECIFIC_SCHEMA.in(getSchema().getInputName(), getSchema().getInputName())).and(PARAMETERS.SPECIFIC_NAME.eq(getInputName())).and(PARAMETERS.ROUTINE_TYPE.eq(procType.name())).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch()) {
String inOut = record.get(PARAMETERS.PARAMETER_MODE);
String dataType = record.get(PARAMETERS.DATA_TYPE);
// [#519] Some types have unsigned versions
if (getDatabase().supportsUnsignedTypes()) {
if (asList("tinyint", "smallint", "mediumint", "int", "bigint").contains(dataType.toLowerCase())) {
if (record.get(PARAMETERS.DTD_IDENTIFIER).toLowerCase().contains("unsigned")) {
dataType += "unsigned";
}
}
}
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, (String) null);
if (inOut == null) {
addParameter(InOutDefinition.RETURN, new DefaultParameterDefinition(this, "RETURN_VALUE", -1, type));
} else {
ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME).replaceAll("@", ""), record.get(PARAMETERS.ORDINAL_POSITION, int.class), type);
addParameter(InOutDefinition.getFromString(inOut), parameter);
}
}
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class MySQLRoutineDefinition method createParameter.
private ParameterDefinition createParameter(Matcher matcher, int group, int columnIndex, String paramName) {
String paramType = matcher.group(group + 1);
Number precision = 0;
Number scale = 0;
if (!StringUtils.isBlank(matcher.group(group + 2))) {
precision = Integer.valueOf(matcher.group(group + 2));
}
if (!StringUtils.isBlank(matcher.group(group + 3))) {
scale = Integer.valueOf(matcher.group(group + 3));
}
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), paramType, precision, precision, scale, null, (String) null);
return new DefaultParameterDefinition(this, paramName, columnIndex, type);
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class MySQLTableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
for (Record record : create().select(COLUMNS.ORDINAL_POSITION, COLUMNS.COLUMN_NAME, COLUMNS.COLUMN_COMMENT, COLUMNS.COLUMN_TYPE, COLUMNS.DATA_TYPE, COLUMNS.IS_NULLABLE, COLUMNS.COLUMN_DEFAULT, COLUMNS.EXTRA, COLUMNS.GENERATION_EXPRESSION, COLUMNS.CHARACTER_MAXIMUM_LENGTH, // [#10856] Some older versions of MySQL 5.7 don't have the DATETIME_PRECISION column yet
getDatabase().exists(COLUMNS.DATETIME_PRECISION) ? coalesce(COLUMNS.NUMERIC_PRECISION, COLUMNS.DATETIME_PRECISION).as(COLUMNS.NUMERIC_PRECISION) : COLUMNS.NUMERIC_PRECISION, COLUMNS.NUMERIC_SCALE, COLUMNS.EXTRA).from(COLUMNS).where(COLUMNS.TABLE_SCHEMA.in(getSchema().getName(), getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).orderBy(COLUMNS.ORDINAL_POSITION)) {
String dataType = record.get(COLUMNS.DATA_TYPE);
// [#519] Some types have unsigned versions
boolean unsigned = getDatabase().supportsUnsignedTypes();
// [#7719]
boolean displayWidths = getDatabase().integerDisplayWidths();
// [#6492] MariaDB supports a standard IS_GENERATED, but MySQL doesn't (yet)
boolean generated = record.get(COLUMNS.EXTRA) != null && record.get(COLUMNS.EXTRA).toUpperCase().contains("GENERATED");
GenerationOption generationOption = "VIRTUAL GENERATED".equalsIgnoreCase(record.get(COLUMNS.EXTRA)) ? GenerationOption.VIRTUAL : "STORED GENERATED".equalsIgnoreCase(record.get(COLUMNS.EXTRA)) ? GenerationOption.STORED : null;
columnTypeFix: if (unsigned || displayWidths) {
if (asList("tinyint", "smallint", "mediumint", "int", "bigint").contains(dataType.toLowerCase())) {
String columnType = record.get(COLUMNS.COLUMN_TYPE).toLowerCase();
Matcher matcher = COLUMN_TYPE.matcher(columnType);
if (matcher.find()) {
String mType = matcher.group(1);
String mPrecision = matcher.group(2);
String mUnsigned = matcher.group(3);
dataType = mType + (unsigned && mUnsigned != null ? mUnsigned : "") + (displayWidths && mPrecision != null ? mPrecision : "");
}
}
}
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), record.get(COLUMNS.NUMERIC_PRECISION), record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), generated ? null : record.get(COLUMNS.COLUMN_DEFAULT), name(getSchema().getName(), getName() + "_" + record.get(COLUMNS.COLUMN_NAME))).generatedAlwaysAs(generated ? record.get(COLUMNS.GENERATION_EXPRESSION) : null).generationOption(generationOption);
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, "auto_increment".equalsIgnoreCase(record.get(COLUMNS.EXTRA)), record.get(COLUMNS.COLUMN_COMMENT)));
}
return result;
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class PostgresRoutineDefinition method init0.
@Override
protected void init0() throws SQLException {
Parameters p = PARAMETERS;
Field<Integer> count = count().filterWhere(p.PARAMETER_NAME.ne(inline(""))).over(partitionBy(p.SPECIFIC_NAME, p.PARAMETER_NAME));
Field<Integer> c = count.as("c");
for (Record record : create().select(p.PARAMETER_NAME, when(p.DATA_TYPE.eq(inline("USER-DEFINED")).and(p.UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(p.DATA_TYPE).as(p.DATA_TYPE), p.CHARACTER_MAXIMUM_LENGTH, pNumericPrecision(p).as(p.NUMERIC_PRECISION), p.NUMERIC_SCALE, p.UDT_SCHEMA, p.UDT_NAME, p.ORDINAL_POSITION, p.PARAMETER_MODE, ((PostgresDatabase) getDatabase()).is94() ? p.PARAMETER_DEFAULT : inline((String) null).as(p.PARAMETER_DEFAULT), c).from(p).where(p.SPECIFIC_SCHEMA.equal(getSchema().getName())).and(p.SPECIFIC_NAME.equal(specificName)).orderBy(p.ORDINAL_POSITION.asc())) {
String parameterName = record.get(p.PARAMETER_NAME);
String inOut = record.get(p.PARAMETER_MODE);
SchemaDefinition typeSchema = null;
String schemaName = record.get(p.UDT_SCHEMA);
if (schemaName != null)
typeSchema = getDatabase().getSchema(schemaName);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(p.DATA_TYPE), record.get(p.CHARACTER_MAXIMUM_LENGTH), record.get(p.NUMERIC_PRECISION), record.get(p.NUMERIC_SCALE), null, record.get(p.PARAMETER_DEFAULT), name(record.get(p.UDT_SCHEMA), record.get(p.UDT_NAME)));
ParameterDefinition parameter = new DefaultParameterDefinition(this, parameterName, record.get(p.ORDINAL_POSITION), type, record.get(p.PARAMETER_DEFAULT) != null, StringUtils.isBlank(parameterName), "", record.get(c) > 1 ? record.get(p.ORDINAL_POSITION, String.class) : null);
addParameter(InOutDefinition.getFromString(inOut), parameter);
}
}
Aggregations