|
@@ -125,32 +125,40 @@ public class ObjectRelationMigration extends MigrationAbstractServiceImpl<Object
|
|
|
@Override
|
|
|
public String migrateForSql(InstanceUrlParam context) {
|
|
|
StringBuffer sqls = new StringBuffer(" \n -- 数据迁移 dt_relation ------ \n");
|
|
|
+ sqls.append(" delete from dt_relation where project_id='"+context.getProjectId()+"' and group_code='"+context.getGroupCode()+"'; \n ");
|
|
|
//获取已经采集的数据
|
|
|
String sqls_temp = "";
|
|
|
ExecutorService service = getExcecutor();
|
|
|
- List<Future<StringBuffer>> futureList = new ArrayList<>();
|
|
|
+ List<Future<String>> futureList = new ArrayList<>();
|
|
|
for (MiGrationRelCode miGrationRelCode: MiGrationRelCode.values()){
|
|
|
QueryCriteria queryCriteria = getQueryCriteria(miGrationRelCode.getCode());
|
|
|
- queryCriteria.setSize(10000L);
|
|
|
- CommonResult<List<ObjectRelation>> admDatas = getAdmDataPage(context,queryCriteria);
|
|
|
- if (admDatas.getResult().equals(DmpResult.SUCCESS) && admDatas.getCount() > queryCriteria.getSize()) {
|
|
|
- long pages = admDatas.getCount() / queryCriteria.getSize() + 1;
|
|
|
- for(long i = 2;i < pages; i++){
|
|
|
+ queryCriteria.setSize(MigrationConstant.BATCH_SQL_DATA_COUNT);
|
|
|
+ CommonResult<List<ObjectRelation>> result = getAdmDataPage(context,queryCriteria);
|
|
|
+ if(result == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<ObjectRelation> admData = result.getData();
|
|
|
+ if(CollUtil.isEmpty(admData)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 拼接sql
|
|
|
+ appendValuesBefore(service,admData,futureList);
|
|
|
+ // 分页处理sql
|
|
|
+ if (result.getCount() > MigrationConstant.BATCH_SQL_DATA_COUNT) {
|
|
|
+ long pages = result.getCount() / queryCriteria.getSize() + 1;
|
|
|
+ for(long i = 2;i <= pages; i++){
|
|
|
queryCriteria.setPage(i);
|
|
|
- List<ObjectRelation> admData = getAdmData(context,queryCriteria);
|
|
|
+ admData = getAdmData(context,queryCriteria);
|
|
|
appendValuesBefore(service,admData,futureList);
|
|
|
}
|
|
|
- }else{
|
|
|
- List<ObjectRelation> admData = admDatas.getData();
|
|
|
- appendValuesBefore(service,admData,futureList);
|
|
|
}
|
|
|
}
|
|
|
service.shutdown();
|
|
|
- for (Future<StringBuffer> future : futureList) {
|
|
|
+ for (Future<String> future : futureList) {
|
|
|
try {
|
|
|
- StringBuffer stringBuffer = future.get();
|
|
|
- if(StrUtil.isNotEmpty(stringBuffer)){
|
|
|
- sqls_temp += stringBuffer.toString();
|
|
|
+ String string = future.get();
|
|
|
+ if(StrUtil.isNotEmpty(string)){
|
|
|
+ sqls_temp += string;
|
|
|
}
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
@@ -164,22 +172,18 @@ public class ObjectRelationMigration extends MigrationAbstractServiceImpl<Object
|
|
|
if(sqls_temp.length() == 0){
|
|
|
return "";
|
|
|
}
|
|
|
- sqls.append(MigrationConstant.DT_RELATION_SQL_PRE);
|
|
|
sqls.append(sqls_temp);
|
|
|
- String sql = sqls.toString();
|
|
|
- sql = sql.substring(0, sql.lastIndexOf(","));
|
|
|
- sql +=";";
|
|
|
- return sql;
|
|
|
+ return sqls.toString();
|
|
|
}
|
|
|
|
|
|
- private void appendValuesBefore(ExecutorService service, List<ObjectRelation> admData, List<Future<StringBuffer>> futureList){
|
|
|
+ private void appendValuesBefore(ExecutorService service, List<ObjectRelation> admData, List<Future<String>> futureList){
|
|
|
if(CollUtil.isEmpty(admData)){
|
|
|
return;
|
|
|
}
|
|
|
StringBuffer sqls_temp = new StringBuffer();
|
|
|
- Future<StringBuffer> future = service.submit(new Callable<StringBuffer>(){
|
|
|
+ Future<String> future = service.submit(new Callable<String>(){
|
|
|
@Override
|
|
|
- public StringBuffer call() throws Exception {
|
|
|
+ public String call() throws Exception {
|
|
|
return appendValues(admData, sqls_temp);
|
|
|
}
|
|
|
});
|
|
@@ -192,56 +196,33 @@ public class ObjectRelationMigration extends MigrationAbstractServiceImpl<Object
|
|
|
* @param sqls
|
|
|
* @return
|
|
|
*/
|
|
|
- private StringBuffer appendValues(List<ObjectRelation> admData, StringBuffer sqls){
|
|
|
+ private String appendValues(List<ObjectRelation> admData, StringBuffer sqls){
|
|
|
admData.forEach(relation -> {
|
|
|
sqls.append("(");
|
|
|
sqls.append("'").append(relation.getId()).append("',");
|
|
|
sqls.append("'").append(relation.getGroupCode()).append("',");
|
|
|
sqls.append("'").append(relation.getProjectId()).append("',");
|
|
|
- if (relation.getGraphId() == null) {
|
|
|
- sqls.append(relation.getGraphId()).append(",");
|
|
|
- } else {
|
|
|
- sqls.append("'").append(relation.getGraphId()).append("',");
|
|
|
- }
|
|
|
- sqls.append("'").append(relation.getGraphCode()).append("',");
|
|
|
- sqls.append("'").append(relation.getRelCode()).append("',");
|
|
|
-
|
|
|
- if (relation.getRelValue() == null) {
|
|
|
- sqls.append(relation.getRelValue()).append(",");
|
|
|
- } else {
|
|
|
- sqls.append("'").append(relation.getRelValue()).append("',");
|
|
|
- }
|
|
|
+ super.processNull(sqls, relation.getGraphId());
|
|
|
+ super.processNull(sqls, relation.getGraphCode());
|
|
|
+ super.processNull(sqls, relation.getRelCode());
|
|
|
+ super.processNull(sqls, relation.getRelValue());
|
|
|
+ super.processNull(sqls, relation.getObjFrom());
|
|
|
+ super.processNull(sqls, relation.getObjTo());
|
|
|
+ super.processNull(sqls, relation.getCreateApp());
|
|
|
+ super.processNull(sqls, relation.getUpdateApp());
|
|
|
+ super.processNull(sqls, relation.getCreator());
|
|
|
+ super.processNull(sqls, relation.getCreationTime());
|
|
|
+ super.processNull(sqls, relation.getModifier());
|
|
|
+ super.processNull(sqls, relation.getModifiedTime());
|
|
|
|
|
|
- if (relation.getObjFrom() == null) {
|
|
|
- sqls.append(relation.getObjFrom()).append(",");
|
|
|
- } else {
|
|
|
- sqls.append("'").append(relation.getObjFrom()).append("',");
|
|
|
- }
|
|
|
-
|
|
|
- if (relation.getObjTo() == null) {
|
|
|
- sqls.append(relation.getObjTo()).append(",");
|
|
|
- } else {
|
|
|
- sqls.append("'").append(relation.getObjTo()).append("',");
|
|
|
- }
|
|
|
-
|
|
|
- if (relation.getCreateApp() == null) {
|
|
|
- sqls.append(relation.getCreateApp()).append(",");
|
|
|
- } else {
|
|
|
- sqls.append("'").append(relation.getCreateApp()).append("',");
|
|
|
- }
|
|
|
- if (relation.getUpdateApp() == null) {
|
|
|
- sqls.append(relation.getUpdateApp()).append(",");
|
|
|
- } else {
|
|
|
- sqls.append("'").append(relation.getUpdateApp()).append("',");
|
|
|
- }
|
|
|
- sqls.append("'").append(relation.getCreator()).append("',");
|
|
|
- sqls.append("'").append(relation.getCreationTime()).append("',");
|
|
|
- sqls.append("'").append(relation.getModifier()).append("',");
|
|
|
- sqls.append("'").append(relation.getModifiedTime()).append("',");
|
|
|
sqls.append(relation.getValid());
|
|
|
sqls.append(")\n ,");
|
|
|
});
|
|
|
- return sqls;
|
|
|
+ String sql = "";
|
|
|
+ if(sqls.length() > 0){
|
|
|
+ sql = MigrationConstant.DT_RELATION_SQL_PRE + StrUtil.sub(sqls.toString(), 0 , -1) + "; \n ";
|
|
|
+ }
|
|
|
+ return sql;
|
|
|
}
|
|
|
private ExecutorService getExcecutor(){
|
|
|
ExecutorService service = new ThreadPoolExecutor(10, 15, 0L, TimeUnit.MILLISECONDS,
|