cn.schoolwow.quickdao.module.operation.flow.upgrade.DatabaseUpgradeFlow Maven / Gradle / Ivy
package cn.schoolwow.quickdao.module.operation.flow.upgrade;
import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickdao.domain.database.parent.UpgradeRequest;
import cn.schoolwow.quickdao.domain.entity.DatabaseUpgrade;
import cn.schoolwow.quickdao.domain.entity.Entity;
import cn.schoolwow.quickdao.module.database.dml.domain.ManipulationOption;
import cn.schoolwow.quickdao.module.database.dml.flow.instance.insert.common.SetInsertInstanceParameterFlow;
import cn.schoolwow.quickdao.module.database.dml.flow.instance.insert.common.SetInsertInstanceStatementFlow;
import cn.schoolwow.quickdao.module.database.dql.query.service.fetch.FetchListFlow;
import cn.schoolwow.quickdao.module.database.parent.flow.executor.ExecuteUpdateConnectionFlow;
import cn.schoolwow.quickdao.module.database.parent.flow.executor.common.UpdateLogFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import com.alibaba.fastjson.JSONArray;
public class DatabaseUpgradeFlow implements BusinessFlow {
@Override
public void executeBusinessFlow(FlowContext flowContext) throws Exception {
UpgradeRequest upgradeRequest = (UpgradeRequest) flowContext.checkData("upgradeRequest");
QuickDAOConfig quickDAOConfig = (QuickDAOConfig) flowContext.checkData("quickDAOConfig");
DAO dao = quickDAOConfig.dao;
Entity entity = dao.getEntity(DatabaseUpgrade.class);
if(null==entity){
throw new IllegalArgumentException("日志类信息获取失败!日志类名:"+DatabaseUpgrade.class.getName());
}
flowContext.startFlow(new FetchListFlow())
.putTemporaryData("entity", entity)
.putTemporaryData("column", "comment")
.putTemporaryData("value", upgradeRequest.comment)
.execute();
JSONArray resultSetArray = (JSONArray) flowContext.getData("resultSetArray");
DatabaseUpgrade databaseUpgrade = resultSetArray.isEmpty()?null:resultSetArray.toJavaList(DatabaseUpgrade.class).get(0);
if(null!=databaseUpgrade){
if(!databaseUpgrade.isSuccess()){
upgradeRequest.upgradeConsumer.accept(dao);
databaseUpgrade.setSuccess(true);
flowContext.startFlow(new UpdateLogFlow())
.putTemporaryData("instance", databaseUpgrade)
.execute();
}
return;
}
databaseUpgrade = new DatabaseUpgrade();
databaseUpgrade.setComment(upgradeRequest.comment);
dao.startRecord();
try {
upgradeRequest.upgradeConsumer.accept(dao);
databaseUpgrade.setSuccess(true);
}catch (Exception e){
databaseUpgrade.setSuccess(false);
throw e;
}finally {
String sql = dao.stopRecord();
databaseUpgrade.setSql(sql);
ManipulationOption manipulationOption = new ManipulationOption();
manipulationOption.returnGeneratedKeys = false;
flowContext.startFlow("插入数据库升级语句")
.putTemporaryData("insertSqlLog", false)
.putTemporaryData("name", "插入数据库升级语句")
.putTemporaryData("manipulationOption", manipulationOption)
.putTemporaryData("entity", entity)
.putTemporaryData("instance", databaseUpgrade)
.next(new SetInsertInstanceStatementFlow())
.next(new SetInsertInstanceParameterFlow())
.next(new ExecuteUpdateConnectionFlow())
.execute();
}
}
@Override
public String name() {
return "数据库升级";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy