|
@@ -2,6 +2,7 @@ package cn.com.taiji.cql.service.impl;
|
|
import cn.com.taiji.common.domain.PageResult;
|
|
import cn.com.taiji.common.domain.PageResult;
|
|
import cn.com.taiji.common.domain.Result;
|
|
import cn.com.taiji.common.domain.Result;
|
|
import cn.com.taiji.common.enums.CommonConstant;
|
|
import cn.com.taiji.common.enums.CommonConstant;
|
|
|
|
+import cn.com.taiji.common.util.HashCodeUtil;
|
|
import cn.com.taiji.common.util.IdGenerator;
|
|
import cn.com.taiji.common.util.IdGenerator;
|
|
import cn.com.taiji.cql.service.IECqlService;
|
|
import cn.com.taiji.cql.service.IECqlService;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -29,11 +30,14 @@ import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class ECqlServiceImpl implements IECqlService{
|
|
public class ECqlServiceImpl implements IECqlService{
|
|
|
|
|
|
|
|
+ private Map<String,DataStore> dataStoreMaps = new ConcurrentHashMap<String,DataStore>();
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* cql 通用查询接口
|
|
* cql 通用查询接口
|
|
* @param mapParams
|
|
* @param mapParams
|
|
@@ -49,8 +53,12 @@ public class ECqlServiceImpl implements IECqlService{
|
|
|
|
|
|
String host = mapParams.get(JDBCDataStoreFactory.HOST.key).toString();
|
|
String host = mapParams.get(JDBCDataStoreFactory.HOST.key).toString();
|
|
|
|
|
|
|
|
+ String port = mapParams.get(JDBCDataStoreFactory.PORT.key).toString();
|
|
|
|
+
|
|
String database = mapParams.get(JDBCDataStoreFactory.DATABASE.key).toString();
|
|
String database = mapParams.get(JDBCDataStoreFactory.DATABASE.key).toString();
|
|
|
|
|
|
|
|
+ int hashKey = HashCodeUtil.hashCode(host+"-"+port+"-"+database);
|
|
|
|
+
|
|
//查询记录总数
|
|
//查询记录总数
|
|
Long count =0l;
|
|
Long count =0l;
|
|
|
|
|
|
@@ -66,11 +74,23 @@ public class ECqlServiceImpl implements IECqlService{
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
|
- dataStore = DataStoreFinder.getDataStore(mapParams);
|
|
|
|
|
|
+ if(dataStoreMaps.containsKey(String.valueOf(hashKey))){
|
|
|
|
|
|
- if (dataStore != null) {
|
|
|
|
|
|
+ dataStore = dataStoreMaps.get(String.valueOf(hashKey));
|
|
|
|
|
|
- log.info("系统连接到位于:" + host + "的空间数据库" + database + "成功!");
|
|
|
|
|
|
+ log.info("系统从内存连接到位于:" + host + "的空间数据库" + database + "成功!");
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+
|
|
|
|
+ dataStore = DataStoreFinder.getDataStore(mapParams);
|
|
|
|
+
|
|
|
|
+ dataStoreMaps.put(String.valueOf(hashKey),dataStore);
|
|
|
|
+
|
|
|
|
+ log.info("系统新建连接到位于:" + host + "的空间数据库" + database + "成功!");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (dataStore != null) {
|
|
|
|
|
|
//根据表名获取source
|
|
//根据表名获取source
|
|
SimpleFeatureSource fSource=dataStore.getFeatureSource(mapParams.get("tableName").toString());
|
|
SimpleFeatureSource fSource=dataStore.getFeatureSource(mapParams.get("tableName").toString());
|
|
@@ -210,13 +230,6 @@ public class ECqlServiceImpl implements IECqlService{
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
log.error("系统连接到位于:" + mapParams.get(JDBCDataStoreFactory.HOST.key) + "的空间数据库" + mapParams.get(JDBCDataStoreFactory.DATABASE.key) + "失败!请检查相关参数");
|
|
log.error("系统连接到位于:" + mapParams.get(JDBCDataStoreFactory.HOST.key) + "的空间数据库" + mapParams.get(JDBCDataStoreFactory.DATABASE.key) + "失败!请检查相关参数");
|
|
|
|
|
|
- }finally {
|
|
|
|
-
|
|
|
|
- if(dataStore !=null){
|
|
|
|
-
|
|
|
|
- dataStore.dispose();
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
int respCode = 0;
|
|
int respCode = 0;
|