use of org.jooq.util.xml.jaxb.CheckConstraint in project jOOQ by jOOQ.
the class InformationSchemaExport method exportCheck0.
private static final void exportCheck0(Configuration configuration, InformationSchema result, Table<?> t, Check<?> chk) {
exportTableConstraint(result, t, chk.getName(), CHECK);
CheckConstraint c = new CheckConstraint();
String catalogName = catalogName(t);
String schemaName = schemaName(t);
if (!isBlank(catalogName))
c.setConstraintCatalog(catalogName);
if (!isBlank(schemaName))
c.setConstraintSchema(schemaName);
c.setConstraintName(chk.getName());
c.setCheckClause(configuration.dsl().render(chk.condition()));
result.getCheckConstraints().add(c);
}
use of org.jooq.util.xml.jaxb.CheckConstraint in project jOOQ by jOOQ.
the class InformationSchemaMetaImpl method init.
@SuppressWarnings({ "unchecked", "rawtypes" })
private final void init(InformationSchema meta) {
List<String> errors = new ArrayList<>();
// Catalogs
// -------------------------------------------------------------------------------------------------------------
boolean hasCatalogs = false;
for (org.jooq.util.xml.jaxb.Catalog xc : meta.getCatalogs()) {
InformationSchemaCatalog ic = new InformationSchemaCatalog(xc.getCatalogName(), xc.getComment());
catalogs.add(ic);
catalogsByName.put(name(xc.getCatalogName()), ic);
hasCatalogs = true;
}
// -------------------------------------------------------------------------------------------------------------
schemaLoop: for (org.jooq.util.xml.jaxb.Schema xs : meta.getSchemata()) {
// [#6662] This is kept for backwards compatibility reasons
if (!hasCatalogs) {
InformationSchemaCatalog ic = new InformationSchemaCatalog(xs.getCatalogName(), null);
if (!catalogs.contains(ic)) {
catalogs.add(ic);
catalogsByName.put(name(xs.getCatalogName()), ic);
}
}
Name catalogName = name(xs.getCatalogName());
Catalog catalog = catalogsByName.get(catalogName);
if (catalog == null) {
errors.add("Catalog " + catalogName + " not defined for schema " + xs.getSchemaName());
continue schemaLoop;
}
InformationSchemaSchema is = new InformationSchemaSchema(xs.getSchemaName(), catalog, xs.getComment());
schemas.add(is);
schemasByName.put(name(xs.getCatalogName(), xs.getSchemaName()), is);
}
// -------------------------------------------------------------------------------------------------------------
domainLoop: for (org.jooq.util.xml.jaxb.Domain d : meta.getDomains()) {
Name schemaName = name(d.getDomainCatalog(), d.getDomainSchema());
Schema schema = schemasByName.get(schemaName);
if (schema == null) {
errors.add("Schema " + schemaName + " not defined for domain " + d.getDomainName());
continue domainLoop;
}
Name domainName = name(d.getDomainCatalog(), d.getDomainSchema(), d.getDomainName());
int length = d.getCharacterMaximumLength() == null ? 0 : d.getCharacterMaximumLength();
int precision = d.getNumericPrecision() == null ? 0 : d.getNumericPrecision();
int scale = d.getNumericScale() == null ? 0 : d.getNumericScale();
// TODO [#10239] Support NOT NULL constraints
boolean nullable = true;
List<Check<?>> checks = new ArrayList<>();
for (org.jooq.util.xml.jaxb.DomainConstraint dc : meta.getDomainConstraints()) {
if (domainName.equals(name(dc.getDomainCatalog(), dc.getDomainSchema(), dc.getDomainName()))) {
Name constraintName = name(dc.getConstraintCatalog(), dc.getConstraintSchema(), dc.getConstraintName());
for (org.jooq.util.xml.jaxb.CheckConstraint cc : meta.getCheckConstraints()) if (constraintName.equals(name(cc.getConstraintCatalog(), cc.getConstraintSchema(), cc.getConstraintName())))
checks.add(new CheckImpl<>(null, constraintName, DSL.condition(cc.getCheckClause()), true));
}
}
InformationSchemaDomain<?> id = new InformationSchemaDomain<Object>(schema, name(d.getDomainName()), (DataType) type(d.getDataType(), length, precision, scale, nullable, false, null, null), checks.toArray(EMPTY_CHECK));
domains.add(id);
domainsByName.put(domainName, id);
}
// -------------------------------------------------------------------------------------------------------------
tableLoop: for (org.jooq.util.xml.jaxb.Table xt : meta.getTables()) {
Name schemaName = name(xt.getTableCatalog(), xt.getTableSchema());
Schema schema = schemasByName.get(schemaName);
if (schema == null) {
errors.add("Schema " + schemaName + " not defined for table " + xt.getTableName());
continue tableLoop;
}
TableType tableType;
switch(xt.getTableType()) {
case GLOBAL_TEMPORARY:
tableType = TableType.TEMPORARY;
break;
case VIEW:
tableType = TableType.VIEW;
break;
case BASE_TABLE:
default:
tableType = TableType.TABLE;
break;
}
String sql = null;
if (tableType == TableType.VIEW) {
viewLoop: for (org.jooq.util.xml.jaxb.View vt : meta.getViews()) {
if (StringUtils.equals(defaultIfNull(xt.getTableCatalog(), ""), defaultIfNull(vt.getTableCatalog(), "")) && StringUtils.equals(defaultIfNull(xt.getTableSchema(), ""), defaultIfNull(vt.getTableSchema(), "")) && StringUtils.equals(defaultIfNull(xt.getTableName(), ""), defaultIfNull(vt.getTableName(), ""))) {
sql = vt.getViewDefinition();
break viewLoop;
}
}
}
InformationSchemaTable it = new InformationSchemaTable(xt.getTableName(), schema, xt.getComment(), tableType, sql);
tables.add(it);
tablesByName.put(name(xt.getTableCatalog(), xt.getTableSchema(), xt.getTableName()), it);
}
// Columns
// -------------------------------------------------------------------------------------------------------------
List<Column> columns = new ArrayList<>(meta.getColumns());
columns.sort((o1, o2) -> {
Integer p1 = o1.getOrdinalPosition();
Integer p2 = o2.getOrdinalPosition();
if (Objects.equals(p1, p2))
return 0;
if (p1 == null)
return -1;
if (p2 == null)
return 1;
return p1.compareTo(p2);
});
columnLoop: for (Column xc : columns) {
String typeName = xc.getDataType();
int length = xc.getCharacterMaximumLength() == null ? 0 : xc.getCharacterMaximumLength();
int precision = xc.getNumericPrecision() == null ? 0 : xc.getNumericPrecision();
int scale = xc.getNumericScale() == null ? 0 : xc.getNumericScale();
boolean nullable = !FALSE.equals(xc.isIsNullable());
boolean readonly = TRUE.equals(xc.isReadonly());
Field<?> generatedAlwaysAs = TRUE.equals(xc.isIsGenerated()) ? DSL.field(xc.getGenerationExpression()) : null;
GenerationOption generationOption = TRUE.equals(xc.isIsGenerated()) ? "STORED".equalsIgnoreCase(xc.getGenerationOption()) ? STORED : "VIRTUAL".equalsIgnoreCase(xc.getGenerationOption()) ? VIRTUAL : null : null;
// TODO: Exception handling should be moved inside SQLDataType
Name tableName = name(xc.getTableCatalog(), xc.getTableSchema(), xc.getTableName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for column " + xc.getColumnName());
continue columnLoop;
}
AbstractTable.createField(name(xc.getColumnName()), type(typeName, length, precision, scale, nullable, readonly, generatedAlwaysAs, generationOption), table, xc.getComment());
}
// Indexes
// -------------------------------------------------------------------------------------------------------------
Map<Name, List<SortField<?>>> columnsByIndex = new HashMap<>();
List<IndexColumnUsage> indexColumnUsages = new ArrayList<>(meta.getIndexColumnUsages());
indexColumnUsages.sort(comparingInt(IndexColumnUsage::getOrdinalPosition));
indexColumnLoop: for (IndexColumnUsage ic : indexColumnUsages) {
Name indexName = name(ic.getIndexCatalog(), ic.getIndexSchema(), ic.getTableName(), ic.getIndexName());
List<SortField<?>> fields = columnsByIndex.computeIfAbsent(indexName, k -> new ArrayList<>());
Name tableName = name(ic.getTableCatalog(), ic.getTableSchema(), ic.getTableName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for index " + indexName);
continue indexColumnLoop;
}
TableField<Record, ?> field = (TableField<Record, ?>) table.field(ic.getColumnName());
if (field == null) {
errors.add("Column " + ic.getColumnName() + " not defined for table " + tableName);
continue indexColumnLoop;
}
fields.add(Boolean.TRUE.equals(ic.isIsDescending()) ? field.desc() : field.asc());
}
indexLoop: for (org.jooq.util.xml.jaxb.Index i : meta.getIndexes()) {
Name tableName = name(i.getTableCatalog(), i.getTableSchema(), i.getTableName());
Name indexName = name(i.getIndexCatalog(), i.getIndexSchema(), i.getTableName(), i.getIndexName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for index " + indexName);
continue indexLoop;
}
List<SortField<?>> c = columnsByIndex.get(indexName);
if (c == null || c.isEmpty()) {
errors.add("No columns defined for index " + indexName);
continue indexLoop;
}
IndexImpl index = (IndexImpl) Internal.createIndex(i.getIndexName(), table, c.toArray(EMPTY_SORTFIELD), Boolean.TRUE.equals(i.isIsUnique()));
table.indexes.add(index);
indexesByName.put(indexName, index);
}
// Constraints
// -------------------------------------------------------------------------------------------------------------
Map<Name, List<TableField<Record, ?>>> columnsByConstraint = new HashMap<>();
List<KeyColumnUsage> keyColumnUsages = new ArrayList<>(meta.getKeyColumnUsages());
keyColumnUsages.sort(comparing(KeyColumnUsage::getOrdinalPosition));
keyColumnLoop: for (KeyColumnUsage xc : keyColumnUsages) {
Name constraintName = name(xc.getConstraintCatalog(), xc.getConstraintSchema(), xc.getConstraintName());
List<TableField<Record, ?>> fields = columnsByConstraint.computeIfAbsent(constraintName, k -> new ArrayList<>());
Name tableName = name(xc.getTableCatalog(), xc.getTableSchema(), xc.getTableName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for constraint " + constraintName);
continue keyColumnLoop;
}
TableField<Record, ?> field = (TableField<Record, ?>) table.field(xc.getColumnName());
if (field == null) {
errors.add("Column " + xc.getColumnName() + " not defined for table " + tableName);
continue keyColumnLoop;
}
fields.add(field);
}
tableConstraintLoop: for (TableConstraint xc : meta.getTableConstraints()) {
switch(xc.getConstraintType()) {
case PRIMARY_KEY:
case UNIQUE:
{
Name tableName = name(xc.getTableCatalog(), xc.getTableSchema(), xc.getTableName());
Name constraintName = name(xc.getConstraintCatalog(), xc.getConstraintSchema(), xc.getConstraintName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for constraint " + constraintName);
continue tableConstraintLoop;
}
List<TableField<Record, ?>> c = columnsByConstraint.get(constraintName);
if (c == null || c.isEmpty()) {
errors.add("No columns defined for constraint " + constraintName);
continue tableConstraintLoop;
}
UniqueKeyImpl<Record> key = (UniqueKeyImpl<Record>) Internal.createUniqueKey(table, xc.getConstraintName(), c.toArray(new TableField[0]));
if (xc.getConstraintType() == PRIMARY_KEY) {
table.primaryKey = key;
primaryKeys.add(key);
} else
table.uniqueKeys.add(key);
keysByName.put(constraintName, key);
break;
}
}
}
for (ReferentialConstraint xr : meta.getReferentialConstraints()) {
referentialKeys.put(name(xr.getConstraintCatalog(), xr.getConstraintSchema(), xr.getConstraintName()), name(xr.getUniqueConstraintCatalog(), xr.getUniqueConstraintSchema(), xr.getUniqueConstraintName()));
}
tableConstraintLoop: for (TableConstraint xc : meta.getTableConstraints()) {
switch(xc.getConstraintType()) {
case FOREIGN_KEY:
{
Name tableName = name(xc.getTableCatalog(), xc.getTableSchema(), xc.getTableName());
Name constraintName = name(xc.getConstraintCatalog(), xc.getConstraintSchema(), xc.getConstraintName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for constraint " + constraintName);
continue tableConstraintLoop;
}
List<TableField<Record, ?>> c = columnsByConstraint.get(constraintName);
if (c == null || c.isEmpty()) {
errors.add("No columns defined for constraint " + constraintName);
continue tableConstraintLoop;
}
UniqueKeyImpl<Record> uniqueKey = keysByName.get(referentialKeys.get(constraintName));
if (uniqueKey == null) {
errors.add("No unique key defined for foreign key " + constraintName);
continue tableConstraintLoop;
}
ForeignKey<Record, Record> key = Internal.createForeignKey(uniqueKey, table, xc.getConstraintName(), c.toArray(new TableField[0]));
table.foreignKeys.add(key);
break;
}
}
}
tableConstraintLoop: for (TableConstraint xc : meta.getTableConstraints()) {
switch(xc.getConstraintType()) {
case CHECK:
{
Name tableName = name(xc.getTableCatalog(), xc.getTableSchema(), xc.getTableName());
Name constraintName = name(xc.getConstraintCatalog(), xc.getConstraintSchema(), xc.getConstraintName());
InformationSchemaTable table = tablesByName.get(tableName);
if (table == null) {
errors.add("Table " + tableName + " not defined for constraint " + constraintName);
continue tableConstraintLoop;
}
for (CheckConstraint cc : meta.getCheckConstraints()) {
if (constraintName.equals(name(cc.getConstraintCatalog(), cc.getConstraintSchema(), cc.getConstraintName()))) {
table.checks.add(new CheckImpl<>(table, constraintName, DSL.condition(cc.getCheckClause()), true));
continue tableConstraintLoop;
}
}
errors.add("No check clause found for check constraint " + constraintName);
continue tableConstraintLoop;
}
}
}
// -------------------------------------------------------------------------------------------------------------
sequenceLoop: for (org.jooq.util.xml.jaxb.Sequence xs : meta.getSequences()) {
Name schemaName = name(xs.getSequenceCatalog(), xs.getSequenceSchema());
Schema schema = schemasByName.get(schemaName);
if (schema == null) {
errors.add("Schema " + schemaName + " not defined for sequence " + xs.getSequenceName());
continue sequenceLoop;
}
String typeName = xs.getDataType();
int length = xs.getCharacterMaximumLength() == null ? 0 : xs.getCharacterMaximumLength();
int precision = xs.getNumericPrecision() == null ? 0 : xs.getNumericPrecision();
int scale = xs.getNumericScale() == null ? 0 : xs.getNumericScale();
boolean nullable = true;
BigInteger startWith = xs.getStartValue();
BigInteger incrementBy = xs.getIncrement();
BigInteger minvalue = xs.getMinimumValue();
BigInteger maxvalue = xs.getMaximumValue();
Boolean cycle = xs.isCycleOption();
BigInteger cache = xs.getCache();
InformationSchemaSequence is = new InformationSchemaSequence(xs.getSequenceName(), schema, type(typeName, length, precision, scale, nullable, false, null, null), startWith, incrementBy, minvalue, maxvalue, cycle, cache);
sequences.add(is);
}
// -------------------------------------------------------------------------------------------------------------
for (Schema s : schemas) initLookup(schemasPerCatalog, s.getCatalog(), s);
for (InformationSchemaDomain<?> d : domains) initLookup(domainsPerSchema, d.getSchema(), d);
for (InformationSchemaTable t : tables) initLookup(tablesPerSchema, t.getSchema(), t);
for (Sequence<?> q : sequences) initLookup(sequencesPerSchema, q.getSchema(), q);
if (!errors.isEmpty())
throw new IllegalArgumentException(errors.toString());
}
use of org.jooq.util.xml.jaxb.CheckConstraint in project jOOQ by jOOQ.
the class XMLGenerator method generate0.
@Override
public void generate0(Database db) {
logDatabaseParameters(db);
log.info("");
logGenerationRemarks(db);
log.info("");
log.info("----------------------------------------------------------");
TextWriter out = new TextWriter(getStrategy().getFile("information_schema.xml"), targetEncoding);
log.info("");
log.info("Generating XML", out.file().getName());
log.info("==========================================================");
InformationSchema is = new InformationSchema();
boolean hasNonDefaultCatalogs = false;
for (CatalogDefinition c : db.getCatalogs()) {
if (!StringUtils.isBlank(c.getName())) {
hasNonDefaultCatalogs = true;
break;
}
}
for (CatalogDefinition c : db.getCatalogs()) {
String catalogName = c.getOutputName();
if (hasNonDefaultCatalogs)
is.getCatalogs().add(new Catalog().withCatalogName(catalogName).withComment(generateCommentsOnCatalogs() ? c.getComment() : null));
for (SchemaDefinition s : c.getSchemata()) {
String schemaName = s.getOutputName();
Schema schema = new Schema();
schema.setCatalogName(catalogName);
schema.setSchemaName(schemaName);
if (generateCommentsOnSchemas())
schema.setComment(s.getComment());
is.getSchemata().add(schema);
for (TableDefinition t : s.getTables()) {
String tableName = t.getOutputName();
Table table = new Table();
table.setTableCatalog(catalogName);
table.setTableSchema(schemaName);
table.setTableName(tableName);
table.setTableType(t.isView() ? TableType.VIEW : t.isTemporary() ? TableType.GLOBAL_TEMPORARY : TableType.BASE_TABLE);
if (generateCommentsOnTables())
table.setComment(t.getComment());
is.getTables().add(table);
if (t.isView()) {
View view = new View();
view.setTableCatalog(catalogName);
view.setTableSchema(schemaName);
view.setTableName(tableName);
if (generateSourcesOnViews())
view.setViewDefinition(t.getSource());
is.getViews().add(view);
}
for (ColumnDefinition co : t.getColumns()) {
String columnName = co.getOutputName();
DataTypeDefinition type = co.getType();
Column column = new Column();
column.setTableCatalog(catalogName);
column.setTableSchema(schemaName);
column.setTableName(tableName);
column.setColumnName(columnName);
if (generateCommentsOnColumns())
column.setComment(co.getComment());
column.setCharacterMaximumLength(type.getLength());
column.setColumnDefault(type.getDefaultValue());
column.setDataType(type.getType());
if (co.isIdentity())
column.setIdentityGeneration("YES");
column.setIsNullable(type.isNullable());
column.setNumericPrecision(type.getPrecision());
column.setNumericScale(type.getScale());
column.setOrdinalPosition(co.getPosition());
column.setReadonly(co.isReadonly());
if (type.isComputed()) {
column.setIsGenerated(type.isComputed());
column.setGenerationExpression(type.getGeneratedAlwaysAs());
column.setGenerationOption(type.getGenerationOption() == VIRTUAL ? "VIRTUAL" : type.getGenerationOption() == STORED ? "STORED" : null);
}
is.getColumns().add(column);
}
}
for (IndexDefinition i : db.getIndexes(s)) {
String indexName = i.getOutputName();
TableDefinition table = i.getTable();
List<IndexColumnDefinition> columns = i.getIndexColumns();
Index index = new Index();
index.setIndexCatalog(catalogName);
index.setIndexSchema(schemaName);
index.setIndexName(indexName);
if (generateCommentsOnKeys())
index.setComment(i.getComment());
index.setTableCatalog(table.getCatalog().getOutputName());
index.setTableSchema(table.getSchema().getOutputName());
index.setTableName(table.getOutputName());
index.setIsUnique(i.isUnique());
is.getIndexes().add(index);
for (int j = 0; j < columns.size(); j++) {
IndexColumnDefinition indexColumn = columns.get(j);
ColumnDefinition column = indexColumn.getColumn();
IndexColumnUsage ic = new IndexColumnUsage();
ic.setIndexCatalog(catalogName);
ic.setIndexSchema(schemaName);
ic.setIndexName(indexName);
ic.setColumnName(column.getOutputName());
ic.setOrdinalPosition(j + 1);
ic.setIsDescending(indexColumn.getSortOrder() == SortOrder.DESC);
ic.setTableCatalog(table.getCatalog().getOutputName());
ic.setTableSchema(table.getSchema().getOutputName());
ic.setTableName(table.getOutputName());
is.getIndexColumnUsages().add(ic);
}
}
for (UniqueKeyDefinition u : db.getKeys(s)) {
String constraintName = u.getOutputName();
TableDefinition table = u.getTable();
List<ColumnDefinition> columns = u.getKeyColumns();
TableConstraint tc = new TableConstraint();
tc.setConstraintCatalog(catalogName);
tc.setConstraintSchema(schemaName);
tc.setConstraintName(constraintName);
tc.setConstraintType(u.isPrimaryKey() ? PRIMARY_KEY : UNIQUE);
if (generateCommentsOnKeys())
tc.setComment(u.getComment());
tc.setTableCatalog(table.getCatalog().getOutputName());
tc.setTableSchema(table.getSchema().getOutputName());
tc.setTableName(table.getOutputName());
tc.setEnforced(u.enforced());
is.getTableConstraints().add(tc);
for (int i = 0; i < columns.size(); i++) {
ColumnDefinition column = columns.get(i);
KeyColumnUsage kc = new KeyColumnUsage();
kc.setConstraintCatalog(catalogName);
kc.setConstraintSchema(schemaName);
kc.setConstraintName(constraintName);
kc.setColumnName(column.getOutputName());
kc.setOrdinalPosition(i + 1);
kc.setTableCatalog(table.getCatalog().getOutputName());
kc.setTableSchema(table.getSchema().getOutputName());
kc.setTableName(table.getOutputName());
is.getKeyColumnUsages().add(kc);
}
}
for (ForeignKeyDefinition f : db.getForeignKeys(s)) {
String constraintName = f.getOutputName();
UniqueKeyDefinition referenced = f.getReferencedKey();
TableDefinition table = f.getKeyTable();
List<ColumnDefinition> columns = f.getKeyColumns();
TableConstraint tc = new TableConstraint();
tc.setConstraintCatalog(catalogName);
tc.setConstraintSchema(schemaName);
tc.setConstraintName(constraintName);
tc.setConstraintType(FOREIGN_KEY);
if (generateCommentsOnKeys())
tc.setComment(f.getComment());
tc.setTableCatalog(table.getCatalog().getOutputName());
tc.setTableSchema(table.getSchema().getOutputName());
tc.setTableName(table.getOutputName());
tc.setEnforced(f.enforced());
ReferentialConstraint rc = new ReferentialConstraint();
rc.setConstraintCatalog(catalogName);
rc.setConstraintSchema(schemaName);
rc.setConstraintName(constraintName);
rc.setUniqueConstraintCatalog(referenced.getCatalog().getOutputName());
rc.setUniqueConstraintSchema(referenced.getSchema().getOutputName());
rc.setUniqueConstraintName(referenced.getOutputName());
is.getTableConstraints().add(tc);
is.getReferentialConstraints().add(rc);
for (int i = 0; i < columns.size(); i++) {
ColumnDefinition column = columns.get(i);
KeyColumnUsage kc = new KeyColumnUsage();
kc.setConstraintCatalog(catalogName);
kc.setConstraintSchema(schemaName);
kc.setConstraintName(constraintName);
kc.setColumnName(column.getOutputName());
kc.setOrdinalPosition(i + 1);
kc.setTableCatalog(table.getCatalog().getOutputName());
kc.setTableSchema(table.getSchema().getOutputName());
kc.setTableName(table.getOutputName());
is.getKeyColumnUsages().add(kc);
}
}
for (CheckConstraintDefinition ch : db.getCheckConstraints(s)) {
String constraintName = ch.getOutputName();
TableDefinition table = ch.getTable();
TableConstraint tc = new TableConstraint();
tc.setConstraintCatalog(catalogName);
tc.setConstraintSchema(schemaName);
tc.setConstraintName(constraintName);
tc.setConstraintType(CHECK);
if (generateCommentsOnKeys())
tc.setComment(ch.getComment());
tc.setTableCatalog(table.getCatalog().getOutputName());
tc.setTableSchema(table.getSchema().getOutputName());
tc.setTableName(table.getOutputName());
tc.setEnforced(ch.enforced());
is.getTableConstraints().add(tc);
CheckConstraint cc = new CheckConstraint();
cc.setConstraintCatalog(catalogName);
cc.setConstraintSchema(schemaName);
cc.setConstraintName(constraintName);
cc.setCheckClause(ch.getCheckClause());
is.getCheckConstraints().add(cc);
}
for (SequenceDefinition se : db.getSequences(s)) {
String sequenceName = se.getOutputName();
DataTypeDefinition type = se.getType();
Sequence sequence = new Sequence();
sequence.setSequenceCatalog(catalogName);
sequence.setSequenceSchema(schemaName);
sequence.setSequenceName(sequenceName);
if (generateCommentsOnSequences())
sequence.setComment(se.getComment());
sequence.setCharacterMaximumLength(type.getLength());
sequence.setDataType(type.getType());
sequence.setNumericPrecision(type.getPrecision());
sequence.setNumericScale(type.getScale());
sequence.setStartValue(Convert.convert(se.getStartWith(), BigInteger.class));
sequence.setIncrement(Convert.convert(se.getIncrementBy(), BigInteger.class));
sequence.setMinimumValue(Convert.convert(se.getMinvalue(), BigInteger.class));
sequence.setMaximumValue(Convert.convert(se.getMaxvalue(), BigInteger.class));
sequence.setCycleOption(se.getCycle());
sequence.setCache(Convert.convert(se.getCache(), BigInteger.class));
is.getSequences().add(sequence);
}
for (PackageDefinition pkg : db.getPackages(s)) for (RoutineDefinition r : pkg.getRoutines()) exportRoutine(is, r, catalogName, schemaName);
for (RoutineDefinition r : db.getRoutines(s)) exportRoutine(is, r, catalogName, schemaName);
}
}
StringWriter writer = new StringWriter();
MiniJAXB.marshal(is, writer);
out.print(writer.toString());
out.close();
}
Aggregations