Search in sources :

Example 1 with Strings2

use of com.developmentontheedge.be5.metadata.util.Strings2 in project be5 by DevelopmentOnTheEdge.

the class SqlServerTypeManager method getAlterColumnStatements.

@Override
public String getAlterColumnStatements(ColumnDef column, ColumnDef oldColumn) {
    String tableName = column.getTable().getEntityName();
    String columnName = column.getName();
    String prefix = "ALTER TABLE " + normalizeIdentifier(tableName) + " ALTER COLUMN " + normalizeIdentifier(columnName) + " ";
    StringBuilder sb = new StringBuilder();
    StringBuilder endSb = new StringBuilder();
    for (IndexDef index : oldColumn.getTable().getIndices().getAvailableElements()) {
        for (IndexColumnDef indexColumn : index.getAvailableElements()) {
            if (indexColumn.getName().equals(oldColumn.getName())) {
                sb.append(index.getDropDdl());
                endSb.append(index.getCreateDdl());
                break;
            }
        }
    }
    if (column.isCanBeNull() && (!oldColumn.isCanBeNull() || (!column.getType().toString().equals(oldColumn.getType().toString())))) {
        sb.append(prefix).append(getTypeClause(column.getType())).append(" NULL;");
    }
    if (!column.isCanBeNull() && (oldColumn.isCanBeNull() || (!column.getType().toString().equals(oldColumn.getType().toString())))) {
        if (oldColumn.isCanBeNull() && !Strings2.isNullOrEmpty(column.getDefaultValue())) {
            sb.append("UPDATE ").append(normalizeIdentifier(tableName)).append(" SET ").append(normalizeIdentifier(columnName)).append('=').append(column.getDefaultValue()).append(" WHERE ").append(normalizeIdentifier(columnName)).append(" IS NULL;");
        }
        sb.append(prefix).append(getTypeClause(column.getType())).append(" NOT NULL;");
    }
    if (!Strings2.nullToEmpty(column.getDefaultValue()).equals(Strings2.nullToEmpty(oldColumn.getDefaultValue()))) {
        if (!Strings2.isNullOrEmpty(oldColumn.getDefaultValue())) {
            sb.append(getDropDefaultStatements(tableName, columnName));
        }
        if (!Strings2.isNullOrEmpty(column.getDefaultValue())) {
            sb.append("ALTER TABLE ").append(normalizeIdentifier(tableName)).append(" ADD CONSTRAINT df_").append(tableName).append('_').append(columnName).append(" DEFAULT ").append(column.getDefaultValue()).append(" FOR ").append(normalizeIdentifier(columnName)).append(';');
        }
    }
    sb.append(endSb);
    return sb.toString();
}
Also used : IndexColumnDef(com.developmentontheedge.be5.metadata.model.IndexColumnDef) IndexDef(com.developmentontheedge.be5.metadata.model.IndexDef)

Example 2 with Strings2

use of com.developmentontheedge.be5.metadata.util.Strings2 in project be5 by DevelopmentOnTheEdge.

the class QuerySelector method getTags.

@Override
public String[] getTags() {
    try {
        List<String> queries = new ArrayList<>();
        Query query;
        if (getBean() instanceof Query) {
            query = (Query) getBean();
            queries.add("");
        } else {
            query = ((QuickFilter) getBean()).getQuery();
        }
        queries.addAll(query.getEntity().getQueries().getNameList());
        return queries.toArray(new String[queries.size()]);
    } catch (Exception e) {
        return Strings2.EMPTY;
    }
}
Also used : Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList)

Example 3 with Strings2

use of com.developmentontheedge.be5.metadata.util.Strings2 in project be5 by DevelopmentOnTheEdge.

the class BeModelElementSupport method isAvailable.

@PropertyName("Available in current project")
@Override
public boolean isAvailable() {
    if (usedInExtras == null || usedInExtras.length == 0)
        return true;
    Module module = getModule();
    String[] extras = module == null ? Strings2.EMPTY : module.getExtras();
    Project project = getProject();
    for (String usedInExtra : usedInExtras) {
        if (!hasExtra(extras, project, usedInExtra))
            return false;
    }
    return true;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Module(com.developmentontheedge.be5.metadata.model.Module) PropertyName(com.developmentontheedge.beans.annot.PropertyName)

Example 4 with Strings2

use of com.developmentontheedge.be5.metadata.util.Strings2 in project be5 by DevelopmentOnTheEdge.

the class ColumnSelector method getTags.

@Override
public String[] getTags() {
    final Entity entity = (Entity) getBean();
    final TableDef tableDefinition = entity.findTableDefinition();
    if (tableDefinition == null)
        return Strings2.EMPTY;
    return tableDefinition.getColumns().names().toArray(String[]::new);
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Example 5 with Strings2

use of com.developmentontheedge.be5.metadata.util.Strings2 in project be5 by DevelopmentOnTheEdge.

the class RoleMultiSelector method getAvailableValues.

@Override
protected String[] getAvailableValues() {
    try {
        Object bean = getBean();
        Project project = ((RoleSet) bean).getProject();
        List<String> roleList = project.getRolesWithGroups();
        return roleList.toArray(new String[roleList.size()]);
    } catch (Exception e) {
        return Strings2.EMPTY;
    }
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) RoleSet(com.developmentontheedge.be5.metadata.model.RoleSet)

Aggregations

Project (com.developmentontheedge.be5.metadata.model.Project)2 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 Query (com.developmentontheedge.be5.metadata.model.Query)1 RoleSet (com.developmentontheedge.be5.metadata.model.RoleSet)1 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)1 PropertyName (com.developmentontheedge.beans.annot.PropertyName)1 ArrayList (java.util.ArrayList)1