Просмотр исходного кода

[search-console-b2b] modify try-catch

sunyj 8 лет назад
Родитель
Сommit
a13cb60647

+ 2 - 1
search-console-b2b/src/main/java/com/uas/search/console/b2b/controller/IndexController.java

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -42,7 +43,7 @@ public class IndexController {
 
 	@RequestMapping("/create")
 	@ResponseBody
-	public String createIndexs(String tableNames, Boolean fromFiles, Boolean ifStartListener) {
+	public String createIndexs(String tableNames, Boolean fromFiles, Boolean ifStartListener) throws IOException, InterruptedException {
 		List<Table_name> tableNameList = getTableNames(tableNames);
 		return String.format("Indexes created success in %.2fs",
 				indexService.createIndexes(tableNameList, fromFiles, ifStartListener) / 1000.0);

+ 2 - 1
search-console-b2b/src/main/java/com/uas/search/console/b2b/service/IndexService.java

@@ -4,6 +4,7 @@ import com.uas.search.b2b.service.SearchService.Table_name;
 import com.uas.search.console.b2b.jms.ParsedQueueMessage;
 import com.uas.search.console.b2b.support.DownloadHelper;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -25,7 +26,7 @@ public interface IndexService {
 	 *            可为空,是否开启实时更新,默认开启
 	 * @return 创建的索引花费总时间 ms
 	 */
-	public Long createIndexes(List<Table_name> tableNames, Boolean fromFiles, Boolean ifStartListener);
+	public Long createIndexes(List<Table_name> tableNames, Boolean fromFiles, Boolean ifStartListener) throws IOException, InterruptedException;
 
 	/**
 	 * 下载指定表的数据至本地文件中,以供建索引用

+ 1 - 4
search-console-b2b/src/main/java/com/uas/search/console/b2b/service/impl/IndexServiceImpl.java

@@ -82,7 +82,7 @@ public class IndexServiceImpl implements IndexService {
 	private static IndexWriterManager indexWriterManager = new IndexWriterManager();
 
 	@Override
-	public Long createIndexes(List<Table_name> tableNames, Boolean fromFiles, Boolean ifStartListener) {
+	public Long createIndexes(List<Table_name> tableNames, Boolean fromFiles, Boolean ifStartListener) throws IOException, InterruptedException {
 		if (creatingIndex) {
 			throw new SearchException("已存在线程在创建索引,不可重复请求");
 		}
@@ -105,9 +105,6 @@ public class IndexServiceImpl implements IndexService {
 				}
 				indexSearcherManager.flushCache(tableName, indexWriter, null);
 			}
-		} catch (Throwable e) {
-			// 防止SQLRecoverableException导致应用终止
-			throw new SearchException(e).setDetailedMessage(e);
 		} finally {
 			creatingIndex = false;
 			if (ifStartListener == null || ifStartListener.booleanValue()) {

+ 18 - 30
search-console-b2b/src/main/java/com/uas/search/console/b2b/service/impl/UpdateVirtualColumnServiceImpl.java

@@ -1,40 +1,29 @@
 package com.uas.search.console.b2b.service.impl;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.PrintWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.uas.search.util.CollectionUtils;
-
 import com.alibaba.fastjson.JSONObject;
 import com.uas.search.b2b.exception.SearchException;
 import com.uas.search.b2b.model.SPage;
 import com.uas.search.b2b.service.SearchService.Table_name;
-import com.uas.search.console.b2b.util.ContextUtils;
 import com.uas.search.console.b2b.schedule.model.DailyTaskInformation;
 import com.uas.search.console.b2b.schedule.service.Executable;
 import com.uas.search.console.b2b.schedule.service.TaskService;
 import com.uas.search.console.b2b.service.IndexService;
 import com.uas.search.console.b2b.service.InnerSearchService;
 import com.uas.search.console.b2b.service.UpdateVirtualColumnService;
-import com.uas.search.console.b2b.util.ClassAndTableNameUtils;
-import com.uas.search.console.b2b.util.FileUtils;
-import com.uas.search.console.b2b.util.ObjectUtil;
-import com.uas.search.console.b2b.util.SearchUtils;
+import com.uas.search.console.b2b.util.*;
+import com.uas.search.util.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.Map.Entry;
 
 /**
  * 每天定时更新虚拟列索引
@@ -124,13 +113,12 @@ public class UpdateVirtualColumnServiceImpl implements UpdateVirtualColumnServic
 			}
 			printWriter.flush();
 			printWriter.close();
-		} catch (FileNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException
-				| IllegalArgumentException | InvocationTargetException e) {
+            Long endTime = new Date().getTime();
+            logger.info(String.format("修改数据%s条,耗时%.2fs\n ", totalElements, (endTime - startTime) / 1000.0));
+            indexService.createIndexes(Arrays.asList(tableName), true, true);
+		} catch (Exception e) {
 			throw new SearchException(e).setDetailedMessage(e);
 		}
-		Long endTime = new Date().getTime();
-		logger.info(String.format("修改数据%s条,耗时%.2fs\n ", totalElements, (endTime - startTime) / 1000.0));
-		indexService.createIndexes(Arrays.asList(tableName), true, true);
 	}
 
 	@Override