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

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

Go to download

数据库操作通用方法和函数,从以前的util包中分离出来,并且整合了部分sys-module中的函数

There is a newer version: 5.3.2302
Show newest version
package com.centit.support.database.ddl;

import java.sql.Connection;

import com.centit.support.database.metadata.TableField;
import com.centit.support.database.metadata.TableInfo;

public class MySqlDDLOperations extends GeneralDDLOperations {


    public MySqlDDLOperations(){

    }

    public MySqlDDLOperations(Connection conn) {
        super(conn);
    }

    @Override
    protected void appendPkSql(final TableInfo tableInfo, StringBuilder sbCreate) {
        if (tableInfo.getPkColumns() !=null && tableInfo.getPkColumns().size()>0){
            sbCreate.append(" primary key ");
            appendPkColumnSql(tableInfo, sbCreate);
        }
    }

    @Override
    public String makeRenameColumnSql(final String tableCode, final String columnCode, final TableField column){
        StringBuilder sbsql = new StringBuilder("alter table ");
        sbsql.append(tableCode);
        sbsql.append(" CHANGE ");
        sbsql.append(columnCode);
        sbsql.append(" ");
        sbsql.append(column.getColumnName());
        sbsql.append(" ");
        sbsql.append(column.getColumnType());
        if (column.getMaxLength() > 0)
            sbsql.append("(").append(column.getMaxLength()).append(")");
        else if (column.getPrecision() > 0) {
            sbsql.append("(").append(column.getPrecision());
            if (column.getScale() > 0)
                sbsql.append(",").append(column.getScale());
            sbsql.append(")");
        }
        return sbsql.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy