Search in sources :

Example 6 with DbmsTypeManager

use of com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager 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;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) ArrayList(java.util.ArrayList) DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)

Example 7 with DbmsTypeManager

use of com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager 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();
}
Also used : Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) ArrayList(java.util.ArrayList) DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)

Aggregations

DbmsTypeManager (com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)6 Rdbms (com.developmentontheedge.be5.metadata.sql.Rdbms)5 ArrayList (java.util.ArrayList)3 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)2 SqlColumnType (com.developmentontheedge.be5.metadata.model.SqlColumnType)2 MetadataUtils (com.developmentontheedge.be5.metadata.MetadataUtils)1 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 IndexColumnDef (com.developmentontheedge.be5.metadata.model.IndexColumnDef)1 IndexDef (com.developmentontheedge.be5.metadata.model.IndexDef)1 Module (com.developmentontheedge.be5.metadata.model.Module)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)1 ViewDef (com.developmentontheedge.be5.metadata.model.ViewDef)1 BeCaseInsensitiveCollection (com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection)1 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)1 BeVectorCollection (com.developmentontheedge.be5.metadata.model.base.BeVectorCollection)1 IndexInfo (com.developmentontheedge.be5.metadata.sql.pojo.IndexInfo)1 SqlColumnInfo (com.developmentontheedge.be5.metadata.sql.pojo.SqlColumnInfo)1 DefaultTypeManager (com.developmentontheedge.be5.metadata.sql.type.DefaultTypeManager)1