All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.centit.support.database.ddl.DB2DDLOperations Maven / Gradle / Ivy

Go to download

数据库操作通用方法和函数,从以前的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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy