com.centit.support.database.ddl.DB2DDLOperations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centit-database Show documentation
Show all versions of centit-database Show documentation
数据库操作通用方法和函数,从以前的util包中分离出来,并且整合了部分sys-module中的函数
The newest version!
package com.centit.support.database.ddl;
import com.centit.support.database.metadata.TableField;
import com.centit.support.database.utils.QueryUtils;
import org.apache.commons.lang3.StringUtils;
import java.sql.Connection;
public class DB2DDLOperations extends GeneralDDLOperations {
public DB2DDLOperations() {
}
public DB2DDLOperations(Connection conn) {
super(conn);
}
@Override
public String makeCreateSequenceSql(final String sequenceName) {
return "CREATE SEQUENCE " + QueryUtils.cleanSqlStatement(sequenceName) +
" AS INTEGER START WITH 1 INCREMENT BY 1";
}
@Override
public String makeModifyColumnSql(final String tableCode, final TableField oldColumn, final TableField column) {
StringBuilder sbsql = new StringBuilder("alter table ");
sbsql.append(tableCode);
if (!StringUtils.equalsIgnoreCase(oldColumn.getColumnType(), column.getColumnType())
|| !oldColumn.getMaxLength().equals(column.getMaxLength())
|| !oldColumn.getPrecision().equals(column.getPrecision())) {
sbsql.append(" alter column ")
.append(column.getColumnName())
.append(" set data type ");
appendColumnTypeSQL(column, sbsql);
}
if (oldColumn.isMandatory() != column.isMandatory()) {
sbsql.append(" alter column ")
.append(column.getColumnName())
.append(column.isMandatory() ? " set not null" : " drop not null");
}
return sbsql.toString();
}
}