use of com.developmentontheedge.be5.metadata.sql.Rdbms in project be5 by DevelopmentOnTheEdge.
the class TableDef method getCreateDdl.
@Override
public String getCreateDdl() {
StringBuilder sb = new StringBuilder();
Project project = getProject();
Rdbms dbms = project.getDatabaseSystem();
DbmsTypeManager typeManager = dbms.getTypeManager();
sb.append(typeManager.getCreateTableClause(getEntityName()) + " (\n");
StringBuilder triggers = new StringBuilder();
for (ColumnDef column : getColumns().getAvailableElements()) {
sb.append(typeManager.getColumnDefinitionClause(column));
sb.append(",\n");
triggers.append(typeManager.getColumnTriggerDefinition(column));
}
if (getColumnsCount() > 0) {
sb.delete(sb.length() - 2, sb.length());
}
sb.append(");\n");
ColumnDef autoincrementColumn = getAutoincrementColumn();
if (autoincrementColumn != null) {
String value = getStartId();
if (value != null)
sb.append(typeManager.getStartingIncrementDefinition(getEntityName(), autoincrementColumn.getName(), Long.parseLong(value)));
}
sb.append(triggers);
List<String> indexDdls = new ArrayList<>();
for (IndexDef index : getIndices().getAvailableElements()) {
if (!typeManager.isFunctionalIndexSupported() && index.isFunctional())
continue;
if (dbms == Rdbms.DB2 && index.getName().length() > Rdbms.DB2_INDEX_LENGTH)
continue;
indexDdls.add(index.getCreateDdl() + "\n");
}
Collections.sort(indexDdls);
sb.append(String.join("", indexDdls));
return sb.toString();
}
Aggregations