Browse Source

连接释放问题

master
richie 4 years ago
parent
commit
62959e5c3b
  1. 3
      plugin.xml
  2. 17
      src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java

3
plugin.xml

@ -3,12 +3,13 @@
<id>com.fr.plugin.db.es.v10</id>
<name><![CDATA[Elasticsearch数据集]]></name>
<active>yes</active>
<version>2.0.0</version>
<version>2.0.1</version>
<env-version>10.0</env-version>
<jartime>2019-10-25</jartime>
<vendor>fanruan.richie</vendor>
<description><![CDATA[Elasticsearch数据查询。]]></description>
<change-notes><![CDATA[
[2020-11-04]修复取消预览时连接没有被关闭的问。<br/>
[2020-11-03]支持通过https协议连接服务器。<br/>
[2020-09-09]查询语句中可以使用函数拼接。<br>
[2020-03-18]默认使用$..*查询语句获取所有值。<br/>

17
src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java

@ -2,10 +2,10 @@ package com.fr.plugin.db.es.fun;
import com.fanruan.api.data.open.BaseDataModel;
import com.fanruan.api.err.TableDataException;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.json.JSON;
import com.fr.json.JSONFactory;
import com.fr.json.JSONObject;
import com.fr.plugin.db.es.fun.assist.SimpleDataModel;
import com.fr.plugin.db.es.fun.category.ResultStandardizeSelector;
import com.fr.plugin.db.es.fun.type.ConverterType;
@ -16,6 +16,7 @@ import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
@ -68,6 +69,15 @@ public class ElasticsearchDataModel extends BaseDataModel {
initData();
} catch (Exception e) {
throw new TableDataException(e.getMessage(), e);
} finally {
if (client != null) {
try {
client.close();
} catch (IOException e) {
LogKit.error(e.getMessage(), e);
}
client = null;
}
}
}
}
@ -132,9 +142,6 @@ public class ElasticsearchDataModel extends BaseDataModel {
@Override
public void release() throws Exception {
if (client != null) {
client.close();
client = null;
}
}
}

Loading…
Cancel
Save