use of com.developmentontheedge.be5.metadata.model.ColumnDef in project be5 by DevelopmentOnTheEdge.
the class TableDef method getWarnings.
@Override
public List<ProjectElementException> getWarnings() {
ArrayList<ProjectElementException> warnings = new ArrayList<>();
Rdbms rdbms = getProject().getDatabaseSystem();
DbmsTypeManager typeManager = rdbms.getTypeManager();
if (!typeManager.isFunctionalIndexSupported()) {
for (IndexDef index : getIndices().getAvailableElements()) {
if (index.isFunctional()) {
warnings.add(new ProjectElementException(index, "Functional indices are not supported by " + rdbms));
}
}
}
if (rdbms == Rdbms.DB2) {
for (IndexDef index : getIndices().getAvailableElements()) {
if (index.getName().length() > Rdbms.DB2_INDEX_LENGTH) {
warnings.add(new ProjectElementException(index, "Index name too long for DB2 (" + index.getName().length() + ">" + Rdbms.DB2_INDEX_LENGTH + "); will be skipped"));
}
}
}
if (!typeManager.isCustomAutoincrementSupported()) {
ColumnDef autoincrementColumn = getAutoincrementColumn();
if (autoincrementColumn != null && getStartId() != null) {
warnings.add(new ProjectElementException(autoincrementColumn, "Custom starting autoincrement value is not supported by " + rdbms));
}
}
for (ColumnDef def : getColumns().getAvailableElements()) {
if (def.getType().getTypeName().equals(TYPE_UNKNOWN)) {
warnings.add(new ProjectElementException(def, "Cannot determine column type: probably it references to invalid table or column"));
}
}
for (IndexDef def : getIndices().getAvailableElements()) {
for (IndexColumnDef col : def) {
ColumnDef column = getColumns().getCaseInsensitive(col.getName());
if (column == null)
warnings.add(new ProjectElementException(col, "Index refers to unknown column"));
else if (!column.isAvailable())
warnings.add(new ProjectElementException(col, "Index refers to non-available column"));
}
}
return warnings;
}
use of com.developmentontheedge.be5.metadata.model.ColumnDef 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