use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class DerbyTableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
for (Record record : create().select(SYSCOLUMNS.COLUMNNAME, SYSCOLUMNS.COLUMNNUMBER, SYSCOLUMNS.COLUMNDATATYPE, when(SYSCOLUMNS.AUTOINCREMENTINC.isNull(), SYSCOLUMNS.COLUMNDEFAULT).as(SYSCOLUMNS.COLUMNDEFAULT), SYSCOLUMNS.AUTOINCREMENTINC).from(SYSCOLUMNS).where(SYSCOLUMNS.REFERENCEID.cast(VARCHAR(32672)).equal(inline(tableid))).orderBy(SYSCOLUMNS.COLUMNNUMBER)) {
String columnDataType = record.get(SYSCOLUMNS.COLUMNDATATYPE, String.class);
String typeName = parseTypeName(columnDataType);
// [#9945] Derby timestamps always have a precision of 9
Number precision = "TIMESTAMP".equalsIgnoreCase(typeName) ? 9 : parsePrecision(columnDataType);
Number scale = parseScale(columnDataType);
String defaultValue = record.get(SYSCOLUMNS.COLUMNDEFAULT);
boolean generated = defaultValue != null && defaultValue.toUpperCase().startsWith("GENERATED ALWAYS AS");
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), typeName, precision, precision, scale, !parseNotNull(columnDataType), generated ? null : defaultValue).generatedAlwaysAs(generated ? defaultValue.replaceAll("(?i:GENERATED\\s+ALWAYS\\s+AS\\s*\\(\\s*(.*?)\\s*\\)\\s*)", "$1") : null);
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(SYSCOLUMNS.COLUMNNAME), result.size() + 1, type, null != record.get(SYSCOLUMNS.AUTOINCREMENTINC), null));
}
return result;
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class H2Database method getDomains1_4.
private List<DomainDefinition> getDomains1_4() {
List<DomainDefinition> result = new ArrayList<>();
for (Record record : create().select(DOMAINS.DOMAIN_SCHEMA, DOMAINS.DOMAIN_NAME, DOMAINS.TYPE_NAME, DOMAINS.PRECISION, DOMAINS.SCALE, DOMAINS.IS_NULLABLE, DOMAINS.COLUMN_DEFAULT, DOMAINS.CHECK_CONSTRAINT).from(DOMAINS).where(DOMAINS.DOMAIN_SCHEMA.in(getInputSchemata())).and(DOMAINS.TYPE_NAME.ne(inline("ENUM"))).orderBy(DOMAINS.DOMAIN_SCHEMA, DOMAINS.DOMAIN_NAME)) {
// [#7644] [#11721] H2 puts DATETIME_PRECISION in NUMERIC_SCALE column
boolean isTimestamp = record.get(DOMAINS.TYPE_NAME).trim().toLowerCase().startsWith("timestamp");
SchemaDefinition schema = getSchema(record.get(DOMAINS.DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(DOMAINS.TYPE_NAME), record.get(DOMAINS.PRECISION), isTimestamp ? record.get(DOMAINS.SCALE) : record.get(DOMAINS.PRECISION), isTimestamp ? 0 : record.get(DOMAINS.SCALE), !record.get(DOMAINS.IS_NULLABLE, boolean.class), record.get(DOMAINS.COLUMN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(DOMAINS.DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(DOMAINS.CHECK_CONSTRAINT)))
domain.addCheckClause(record.get(DOMAINS.CHECK_CONSTRAINT));
result.add(domain);
}
return result;
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class H2Database method getDomains2_0.
private List<DomainDefinition> getDomains2_0() {
List<DomainDefinition> result = new ArrayList<>();
Domains d = Tables.DOMAINS.as("d");
DomainConstraints dc = DOMAIN_CONSTRAINTS.as("dc");
for (Record record : create().select(d.DOMAIN_SCHEMA, d.DOMAIN_NAME, d.DATA_TYPE, d.CHARACTER_MAXIMUM_LENGTH, coalesce(d.DATETIME_PRECISION, d.NUMERIC_PRECISION).as(d.NUMERIC_PRECISION), d.NUMERIC_SCALE, d.DOMAIN_DEFAULT, dc.checkConstraints().CHECK_CLAUSE).from(d).leftJoin(dc).on(d.DOMAIN_CATALOG.eq(dc.DOMAIN_CATALOG)).and(d.DOMAIN_SCHEMA.eq(dc.DOMAIN_SCHEMA)).and(d.DOMAIN_NAME.eq(dc.DOMAIN_NAME)).where(d.DOMAIN_SCHEMA.in(getInputSchemata())).and(d.DATA_TYPE.ne(inline("ENUM"))).orderBy(d.DOMAIN_SCHEMA, d.DOMAIN_NAME)) {
SchemaDefinition schema = getSchema(record.get(d.DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(d.DATA_TYPE), record.get(d.CHARACTER_MAXIMUM_LENGTH), record.get(d.NUMERIC_PRECISION), record.get(d.NUMERIC_SCALE), true, record.get(d.DOMAIN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(dc.checkConstraints().CHECK_CLAUSE)))
domain.addCheckClause(record.get(dc.checkConstraints().CHECK_CLAUSE));
result.add(domain);
}
return result;
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class H2TableDefinition method getElements2_0.
public List<ColumnDefinition> getElements2_0() {
List<ColumnDefinition> result = new ArrayList<>();
H2Database db = (H2Database) getDatabase();
for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, // [#2230] [#11733] Translate INTERVAL_TYPE to supported types
nvl(concat(ELEMENT_TYPES.DATA_TYPE, inline(" ARRAY")), when(COLUMNS.INTERVAL_TYPE.like(any(inline("%YEAR%"), inline("%MONTH%"))), inline("INTERVAL YEAR TO MONTH")).when(COLUMNS.INTERVAL_TYPE.like(any(inline("%DAY%"), inline("%HOUR%"), inline("%MINUTE%"), inline("%SECOND%"))), inline("INTERVAL DAY TO SECOND")).else_(Tables.COLUMNS.DATA_TYPE)).as(COLUMNS.TYPE_NAME), nvl(ELEMENT_TYPES.CHARACTER_MAXIMUM_LENGTH, COLUMNS.CHARACTER_MAXIMUM_LENGTH).as(COLUMNS.CHARACTER_MAXIMUM_LENGTH), coalesce(ELEMENT_TYPES.DATETIME_PRECISION, ELEMENT_TYPES.NUMERIC_PRECISION, COLUMNS.DATETIME_PRECISION, COLUMNS.NUMERIC_PRECISION).as(COLUMNS.NUMERIC_PRECISION), nvl(ELEMENT_TYPES.NUMERIC_SCALE, COLUMNS.NUMERIC_SCALE).as(COLUMNS.NUMERIC_SCALE), COLUMNS.IS_NULLABLE, field(Tables.COLUMNS.IS_GENERATED.eq(inline("ALWAYS"))).as(COLUMNS.IS_COMPUTED), Tables.COLUMNS.GENERATION_EXPRESSION, COLUMNS.COLUMN_DEFAULT, COLUMNS.REMARKS, field(Tables.COLUMNS.IS_IDENTITY.eq(inline("YES"))).as(Tables.COLUMNS.IS_IDENTITY), COLUMNS.DOMAIN_SCHEMA, COLUMNS.DOMAIN_NAME).from(COLUMNS).leftJoin(ELEMENT_TYPES).on(Tables.COLUMNS.TABLE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(Tables.COLUMNS.TABLE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(Tables.COLUMNS.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).and(!getDatabase().getIncludeInvisibleColumns() ? condition(COLUMNS.IS_VISIBLE.coerce(BOOLEAN)) : noCondition()).orderBy(COLUMNS.ORDINAL_POSITION)) {
// [#5331] AUTO_INCREMENT (MySQL style)
// [#5331] DEFAULT nextval('sequence') (PostgreSQL style)
// [#6332] [#6339] system-generated defaults shouldn't produce a default clause
boolean isIdentity = record.get(Tables.COLUMNS.IS_IDENTITY, boolean.class) || defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).trim().toLowerCase().startsWith("nextval");
boolean isComputed = record.get(COLUMNS.IS_COMPUTED, boolean.class);
// [#681] Domain name if available
Name userType = record.get(COLUMNS.DOMAIN_NAME) != null ? name(record.get(COLUMNS.DOMAIN_SCHEMA), record.get(COLUMNS.DOMAIN_NAME)) : name(getSchema().getName(), getName() + "_" + record.get(COLUMNS.COLUMN_NAME));
SchemaDefinition typeSchema = record.get(COLUMNS.DOMAIN_NAME) != null ? getDatabase().getSchema(record.get(COLUMNS.DOMAIN_SCHEMA)) : getSchema();
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema == null ? getSchema() : typeSchema, 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), isIdentity || isComputed ? null : record.get(COLUMNS.COLUMN_DEFAULT), userType).generatedAlwaysAs(isComputed ? record.get(Tables.COLUMNS.GENERATION_EXPRESSION) : null);
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, isIdentity, record.get(COLUMNS.REMARKS)));
}
return result;
}
use of org.jooq.meta.DataTypeDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getDomains0.
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
List<DomainDefinition> result = new ArrayList<>();
DomainConstraints dc = DOMAIN_CONSTRAINTS.as("dc");
for (Record record : create().select(dc.domains().DOMAIN_SCHEMA, dc.domains().DOMAIN_NAME, dc.domains().DATA_TYPE, dc.domains().CHARACTER_MAXIMUM_LENGTH, dc.domains().NUMERIC_PRECISION, dc.domains().NUMERIC_SCALE, dc.domains().DOMAIN_DEFAULT, dc.checkConstraints().CHECK_CLAUSE).from(dc).where(dc.domains().DOMAIN_SCHEMA.in(getInputSchemata())).orderBy(dc.domains().DOMAIN_SCHEMA, dc.domains().DOMAIN_NAME)) {
SchemaDefinition schema = getSchema(record.get(dc.domains().DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(dc.domains().DATA_TYPE), record.get(dc.domains().CHARACTER_MAXIMUM_LENGTH), record.get(dc.domains().NUMERIC_PRECISION), record.get(dc.domains().NUMERIC_SCALE), true, record.get(dc.domains().DOMAIN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(dc.domains().DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(dc.checkConstraints().CHECK_CLAUSE)))
domain.addCheckClause(record.get(dc.checkConstraints().CHECK_CLAUSE));
result.add(domain);
}
return result;
}
Aggregations