From ef65d3e927227b8e4afac2ae3a3c6609c3136f97 Mon Sep 17 00:00:00 2001 From: ronger <1207296860@qq.com> Date: Sat, 18 Feb 2017 21:36:36 +0800 Subject: [PATCH] modify transfer to add try catch exception --- .../src/main/java/com/ossean/TestDate.java | 17 ++++++++++------- .../main/java/com/ossean/TransferProjects.java | 3 ++- .../com/ossean/util/TransferProjectsUtil2.java | 9 ++++++++- .../resource/applicationContext-myBatis.xml | 8 ++++---- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/project_match/src/main/java/com/ossean/TestDate.java b/project_match/src/main/java/com/ossean/TestDate.java index 9f048a5..f3e4274 100644 --- a/project_match/src/main/java/com/ossean/TestDate.java +++ b/project_match/src/main/java/com/ossean/TestDate.java @@ -4,6 +4,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Set; import javax.annotation.Resource; @@ -46,13 +47,15 @@ public class TestDate { } public void start_test(){ - String homepage = "http://github.com/apache/abdera;http://incubator.apache.org/abdera/"; - String homepage1 = "http://incubator.apache.org/abdera/"; - String arr[] = homepage1.split(";"); - System.out.println(arr.length); - for(String a : arr){ - System.out.println(a); - } +// String homepage = "http://github.com/apache/abdera;http://incubator.apache.org/abdera/"; +// String homepage1 = "http://incubator.apache.org/abdera/"; +// String arr[] = homepage1.split(";"); +// System.out.println(arr.length); +// for(String a : arr){ +// System.out.println(a); +// } + Set set = dbDest.selectOpenSourceProjectsIds("gather_projects_test"); + System.out.println(set.size()); diff --git a/project_match/src/main/java/com/ossean/TransferProjects.java b/project_match/src/main/java/com/ossean/TransferProjects.java index 2746a07..d0603e4 100644 --- a/project_match/src/main/java/com/ossean/TransferProjects.java +++ b/project_match/src/main/java/com/ossean/TransferProjects.java @@ -67,7 +67,7 @@ public class TransferProjects { } public void start(){ - boolean isUpdate = false; + haveTransferSet = new HashSet(); haveTransferSet = dbDest.selectOpenSourceProjectsIds(targetTableName); int delCount = 0; @@ -85,6 +85,7 @@ public class TransferProjects { } } for(EddRelations relation:eddRelationList){ + boolean isUpdate = false; String gather_projects_ids = relation.getGather_projects_ids(); try { gather_projects_ids = gather_projects_ids.substring(1, gather_projects_ids.length() - 1); diff --git a/project_match/src/main/java/com/ossean/util/TransferProjectsUtil2.java b/project_match/src/main/java/com/ossean/util/TransferProjectsUtil2.java index 3a7f4fe..68eafcb 100644 --- a/project_match/src/main/java/com/ossean/util/TransferProjectsUtil2.java +++ b/project_match/src/main/java/com/ossean/util/TransferProjectsUtil2.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -213,7 +214,13 @@ public class TransferProjectsUtil2 { dbSource.deleteTaggingsByTaggableId(taggingTableName, formerOsp.getId()); //由于没有级联删除 因此需要手动删除 dbDest.deleteMatchResult(formerOsp.getId(), getTargetTable(formerOsp.getId())); } - dbDest.insertOsp(openSourceProjectTableName, osp);//将数据插入open_source_projects表中 + try{ + dbDest.insertOsp(openSourceProjectTableName, osp);//将数据插入open_source_projects表中 + }catch (DuplicateKeyException e){ + System.out.println(isUpdate); + System.out.println(e); + } + int osp_id = osp.getId(); String tags = osp.getTags();//tag分离 if(tags != null){//表示该项目没有标签 diff --git a/project_match/src/main/resource/applicationContext-myBatis.xml b/project_match/src/main/resource/applicationContext-myBatis.xml index 1221373..89374ce 100644 --- a/project_match/src/main/resource/applicationContext-myBatis.xml +++ b/project_match/src/main/resource/applicationContext-myBatis.xml @@ -19,9 +19,9 @@ destroy-method="close"> + value="jdbc:mysql://localhost/ossean_production?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true" /> - + @@ -38,9 +38,9 @@ destroy-method="close"> + value="jdbc:mysql://localhost:3306/ossean_production?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true" /> - +