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

cn.schoolwow.quickdao.module.database.ddl.flow.column.DropTableColumnFlow Maven / Gradle / Ivy

There is a newer version: 5.3.1
Show newest version
package cn.schoolwow.quickdao.module.database.ddl.flow.column;

import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickdao.domain.database.parent.DatabaseType;
import cn.schoolwow.quickdao.domain.entity.Property;
import cn.schoolwow.quickdao.module.database.ddl.flow.property.GetPropertyFlow;
import cn.schoolwow.quickdao.module.database.parent.flow.executor.ExecuteUpdateConnectionFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class DropTableColumnFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        checkCanAlterTableColumn(flowContext);
        dropTableColumn(flowContext);
    }

    @Override
    public String name() {
        return "删除表字段";
    }

    private void checkCanAlterTableColumn(FlowContext flowContext){
        DatabaseType databaseType = (DatabaseType) flowContext.checkData("databaseType");
        switch (databaseType){
            case SQLite:{
                throw new IllegalArgumentException("SQLite数据库不支持删除字段");
            }
        }
    }

    private void dropTableColumn(FlowContext flowContext){
        QuickDAOConfig quickDAOConfig = (QuickDAOConfig) flowContext.checkData("quickDAOConfig");

        flowContext.executeFlowList(new GetPropertyFlow());
        Property property = (Property) flowContext.getData("property");

        String tableName = (String) flowContext.checkData("tableName");
        String columnName = (String) flowContext.checkData("columnName");
        if(null==property){
            throw new IllegalArgumentException("被删除的列不存在!表名:" + tableName + ",列名:" + columnName);
        }

        flowContext.startFlow(new ExecuteUpdateConnectionFlow())
                .putTemporaryData("name", "删除列")
                .putTemporaryData("sql", "alter table " + quickDAOConfig.databaseContext.databaseProvider.escape(tableName) + " drop column " + quickDAOConfig.databaseContext.databaseProvider.escape(columnName) + ";")
                .execute();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy