use of com.developmentontheedge.be5.metadata.model.ColumnDef in project be5 by DevelopmentOnTheEdge.
the class DefaultTypeManager method getColumnDefinitionClause.
@Override
public String getColumnDefinitionClause(ColumnDef column) {
StringBuilder sb = new StringBuilder(normalizeIdentifier(column.getName()));
sb.append(' ').append(getTypeClause(column));
if (column.isAutoIncrement()) {
sb.append(' ').append(getAutoIncrementClause(column));
}
if (column.getDefaultValue() != null) {
String defaultValue = getDefaultValue(column);
ColumnFunction function = new ColumnFunction(defaultValue);
if (function.isTransformed()) {
if (getGeneratedPrefix() != null) {
sb.append(' ').append(getGeneratedPrefix()).append(' ').append(function.getDefinition(column.getProject().getDatabaseSystem(), column.getEntity().getName()));
}
} else {
sb.append(' ').append("DEFAULT ").append(defaultValue);
}
}
addCanBeNullAndAndConstraintClause(column, sb);
if (column.isPrimaryKey()) {
sb.append(' ').append("PRIMARY KEY");
}
return sb.toString();
}
use of com.developmentontheedge.be5.metadata.model.ColumnDef in project be5 by DevelopmentOnTheEdge.
the class MySqlTypeManager method getRenameColumnStatements.
@Override
public String getRenameColumnStatements(ColumnDef column, String newName) {
StringBuilder sb = new StringBuilder();
ColumnDef newColumn = (ColumnDef) column.clone(column.getOrigin(), newName);
sb.append("ALTER TABLE ").append(normalizeIdentifier(column.getTable().getEntityName())).append(" CHANGE COLUMN ").append(normalizeIdentifier(column.getName())).append(' ').append(getColumnDefinitionClause(newColumn)).append(';');
// TODO: check whether it's necessary to update existing null values
return sb.toString();
}
use of com.developmentontheedge.be5.metadata.model.ColumnDef in project be5 by DevelopmentOnTheEdge.
the class OracleTypeManager method getDropTriggerDefinition.
@Override
public String getDropTriggerDefinition(ColumnDef column) {
String defaultValue = column.getDefaultValue();
if (defaultValue == null)
return "";
ColumnFunction function = new ColumnFunction(defaultValue);
if (ColumnFunction.TRANSFORM_GENERIC.equals(function.getTransform())) {
return "DROP TRIGGER " + getTriggerName(column) + ";\n";
}
return "";
}
use of com.developmentontheedge.be5.metadata.model.ColumnDef 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.model.ColumnDef in project be5 by DevelopmentOnTheEdge.
the class SqlServerTypeManager method getTypeClause.
@Override
public String getTypeClause(ColumnDef column) {
if (column.getDefaultValue() != null) {
String defaultValue = getDefaultValue(column);
ColumnFunction function = new ColumnFunction(defaultValue);
if (function.isTransformed()) {
return "";
}
}
return super.getTypeClause(column);
}
Aggregations