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();
}
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;
}
}
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;
}
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);
}
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;
}
}
Aggregations