Browse Source

更新

paid
richie 6 years ago
parent
commit
aa99f88e09
  1. 2
      plugin.xml
  2. 15
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  3. 8
      src/main/java/com/fr/plugin/db/redis/core/RedisPool.java
  4. 4
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java
  5. 28
      src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java
  6. 12
      src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java
  7. 1
      src/main/resources/com/fr/plugin/db/redis/locale/redis.properties
  8. 1
      src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties
  9. 3
      src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

2
plugin.xml

@ -3,7 +3,7 @@
<id>com.fr.solution.plugin.db.redis.v10</id> <id>com.fr.solution.plugin.db.redis.v10</id>
<name><![CDATA[Redis数据集]]></name> <name><![CDATA[Redis数据集]]></name>
<active>yes</active> <active>yes</active>
<version>5.1</version> <version>5.2</version>
<env-version>10.0</env-version> <env-version>10.0</env-version>
<jartime>2018-11-29</jartime> <jartime>2018-11-29</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>

15
src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java

@ -20,11 +20,13 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
private static final int DEFAULT_REDIS_PORT = 6379; private static final int DEFAULT_REDIS_PORT = 6379;
private static final int MAX_TOTAL = 10; private static final int MAX_TOTAL = 10;
private static final int MAX_WAIT = -1;
private Conf<String> host = Holders.simple(StringUtils.EMPTY); private Conf<String> host = Holders.simple(StringUtils.EMPTY);
private Conf<Integer> port = Holders.simple(DEFAULT_REDIS_PORT); private Conf<Integer> port = Holders.simple(DEFAULT_REDIS_PORT);
private Conf<String> password = Holders.simple(StringUtils.EMPTY); private Conf<String> password = Holders.simple(StringUtils.EMPTY);
private Conf<Integer> maxTotal = Holders.simple(MAX_TOTAL); private Conf<Integer> maxTotal = Holders.simple(MAX_TOTAL);
private Conf<Integer> maxWait = Holders.simple(MAX_WAIT);
public RedisDatabaseConnection() { public RedisDatabaseConnection() {
@ -62,6 +64,14 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
this.maxTotal.set(maxTotal); this.maxTotal.set(maxTotal);
} }
public int getMaxWait() {
return maxWait.get();
}
public void setMaxWait(int maxWait) {
this.maxWait.set(maxWait);
}
@Override @Override
public void testConnection() throws Exception { public void testConnection() throws Exception {
Jedis client = createRedisClient(); Jedis client = createRedisClient();
@ -77,7 +87,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
} }
public Jedis createRedisClient() { public Jedis createRedisClient() {
return RedisPool.getPool().getResource(getHost(), getPort(), getPassword(), getMaxTotal()); return RedisPool.getPool().getResource(getHost(), getPort(), getPassword(), getMaxTotal(), getMaxWait());
} }
@Override @Override
@ -152,6 +162,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
setPassword(SecurityToolbox.encrypt(pwd)); setPassword(SecurityToolbox.encrypt(pwd));
} }
setMaxTotal(reader.getAttrAsInt("maxTotal", MAX_TOTAL)); setMaxTotal(reader.getAttrAsInt("maxTotal", MAX_TOTAL));
setMaxWait(reader.getAttrAsInt("maxWait", MAX_WAIT));
} }
} }
} }
@ -166,6 +177,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
writer.attr("password", SecurityToolbox.decrypt(getPassword())); writer.attr("password", SecurityToolbox.decrypt(getPassword()));
} }
writer.attr("maxTotal", getMaxTotal()); writer.attr("maxTotal", getMaxTotal());
writer.attr("maxWait", getMaxWait());
writer.end(); writer.end();
} }
@ -176,6 +188,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
cloned.port = (Conf<Integer>) port.clone(); cloned.port = (Conf<Integer>) port.clone();
cloned.password = (Conf<String>) password.clone(); cloned.password = (Conf<String>) password.clone();
cloned.maxTotal = (Conf<Integer>) maxTotal.clone(); cloned.maxTotal = (Conf<Integer>) maxTotal.clone();
cloned.maxWait = (Conf<Integer>) maxWait.clone();
return cloned; return cloned;
} }
} }

8
src/main/java/com/fr/plugin/db/redis/core/RedisPool.java

@ -25,16 +25,16 @@ public class RedisPool {
private Map<String, JedisPool> jedisPoolMap = new ConcurrentHashMap<String, JedisPool>(); private Map<String, JedisPool> jedisPoolMap = new ConcurrentHashMap<String, JedisPool>();
public Jedis getResource(String host, int port, String password, int maxTotal) { public Jedis getResource(String host, int port, String password, int maxTotal, int maxWait) {
JedisPool jedisPool = jedisPoolMap.get(host); JedisPool jedisPool = jedisPoolMap.get(host);
if (jedisPool == null) { if (jedisPool == null) {
jedisPool = createJedisPool(host, port, password, maxTotal); jedisPool = createJedisPool(host, port, password, maxTotal, maxWait);
jedisPoolMap.put(host, jedisPool); jedisPoolMap.put(host, jedisPool);
} }
return jedisPool.getResource(); return jedisPool.getResource();
} }
private JedisPool createJedisPool(String host, int port, String password, int maxTotal) { private JedisPool createJedisPool(String host, int port, String password, int maxTotal, int maxWait) {
JedisPoolConfig config = new JedisPoolConfig(); JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(maxTotal); config.setMaxTotal(maxTotal);
//连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true //连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
@ -51,7 +51,7 @@ public class RedisPool {
config.setMaxIdle(10); config.setMaxIdle(10);
//最大连接数,可配置 //最大连接数,可配置
//获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 //获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
config.setMaxWaitMillis(-1); config.setMaxWaitMillis(maxWait);
//逐出连接的最小空闲时间 默认1800000毫秒(30分钟) //逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
config.setMinEvictableIdleTimeMillis(1800000); config.setMinEvictableIdleTimeMillis(1800000);
//最小空闲连接数, 默认0 //最小空闲连接数, 默认0

4
src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java

@ -3,6 +3,7 @@ package com.fr.plugin.db.redis.core;
import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8;
import com.eclipsesource.v8.V8Array; import com.eclipsesource.v8.V8Array;
import com.eclipsesource.v8.V8Object; import com.eclipsesource.v8.V8Object;
import com.fr.base.TableData;
import com.fr.data.AbstractDataModel; import com.fr.data.AbstractDataModel;
import com.fr.plugin.db.redis.help.Console; import com.fr.plugin.db.redis.help.Console;
import com.fr.plugin.db.redis.help.Files; import com.fr.plugin.db.redis.help.Files;
@ -61,7 +62,8 @@ public class RedisScriptTableDataModel extends AbstractDataModel {
columnNames[i] = String.valueOf(v8Column.get(i)); columnNames[i] = String.valueOf(v8Column.get(i));
} }
int returnRowCount = v8Table.length(); int returnRowCount = v8Table.length();
for (int i = 0, realCount = Math.min(returnRowCount, this.rowCount); i < realCount; i++) { int realCount = rowCount == TableData.RESULT_ALL ? returnRowCount : Math.min(returnRowCount, this.rowCount);
for (int i = 0; i < realCount; i++) {
V8Array v8Row = v8Table.getArray(i); V8Array v8Row = v8Table.getArray(i);
List<Object> row = new ArrayList<Object>(); List<Object> row = new ArrayList<Object>();
for (int j = 0, col = v8Row.length(); j < col; j++) { for (int j = 0, col = v8Row.length(); j < col; j++) {

28
src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java

@ -2,7 +2,6 @@ package com.fr.plugin.db.redis.core;
import com.fr.base.Parameter; import com.fr.base.Parameter;
import com.fr.data.AbstractDataModel; import com.fr.data.AbstractDataModel;
import com.fr.general.data.TableDataException;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.plugin.PluginLicense; import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager; import com.fr.plugin.PluginLicenseManager;
@ -14,12 +13,9 @@ import com.fr.third.redis.clients.jedis.Jedis;
import java.util.List; import java.util.List;
public class RedisTableDataModel extends AbstractDataModel { public class RedisTableDataModel extends AbstractDataModel {
private Jedis redisClient;
private String[] columnNames; private String[] columnNames;
private List<List<Object>> data; private List<List<Object>> data;
public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) { public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) {
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(RedisConstants.PLUGIN_ID); PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(RedisConstants.PLUGIN_ID);
if (pluginLicense.isAvailable()) { if (pluginLicense.isAvailable()) {
@ -33,11 +29,9 @@ public class RedisTableDataModel extends AbstractDataModel {
if (StringUtils.isEmpty(query)) { if (StringUtils.isEmpty(query)) {
return; return;
} }
if (redisClient == null) { Jedis redisClient = mc.createRedisClient();
redisClient = mc.createRedisClient(); redisClient.select(dbIndex);
redisClient.select(dbIndex); FineLoggerFactory.getLogger().info("Connect to redis and select database:" + dbIndex);
FineLoggerFactory.getLogger().info("Connect to redis and select database:" + dbIndex);
}
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redisClient, query, rowCount); DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redisClient, query, rowCount);
@ -45,33 +39,34 @@ public class RedisTableDataModel extends AbstractDataModel {
wrapper.transform(script); wrapper.transform(script);
data = wrapper.getData(); data = wrapper.getData();
columnNames = wrapper.getColumnNames(); columnNames = wrapper.getColumnNames();
redisClient.close();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getCause()); throw new RuntimeException(e.getCause());
} }
} }
@Override @Override
public int getColumnCount() throws TableDataException { public int getColumnCount() {
return columnNames.length; return columnNames.length;
} }
@Override @Override
public String getColumnName(int columnIndex) throws TableDataException { public String getColumnName(int columnIndex) {
return columnNames[columnIndex]; return columnNames[columnIndex];
} }
@Override @Override
public boolean hasRow(int rowIndex) throws TableDataException { public boolean hasRow(int rowIndex) {
return data != null && data.get(0).size() > rowIndex; return data != null && data.get(0).size() > rowIndex;
} }
@Override @Override
public int getRowCount() throws TableDataException { public int getRowCount() {
return data == null ? 0 : data.get(0).size(); return data == null ? 0 : data.get(0).size();
} }
@Override @Override
public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException { public Object getValueAt(int rowIndex, int columnIndex) {
if (data != null && data.size() > columnIndex) { if (data != null && data.size() > columnIndex) {
List<Object> columnData = data.get(columnIndex); List<Object> columnData = data.get(columnIndex);
if (columnData != null && columnData.size() > rowIndex) { if (columnData != null && columnData.size() > rowIndex) {
@ -83,9 +78,6 @@ public class RedisTableDataModel extends AbstractDataModel {
@Override @Override
public void release() throws Exception { public void release() throws Exception {
if (redisClient != null) {
redisClient.quit();
redisClient = null;
}
} }
} }

12
src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java

@ -5,6 +5,7 @@ import com.fr.design.data.datapane.connect.DatabaseConnectionPane;
import com.fr.design.gui.ibutton.UIPasswordField; import com.fr.design.gui.ibutton.UIPasswordField;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.gui.itextfield.UINumberField;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
@ -23,6 +24,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
private UIIntNumberField portNumberField; private UIIntNumberField portNumberField;
private UIPasswordField passwordTextField; private UIPasswordField passwordTextField;
private UIIntNumberField maxTotalNumberFiled; private UIIntNumberField maxTotalNumberFiled;
private UINumberField maxWaitNumberField;
@Override @Override
@ -33,16 +35,20 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
portNumberField = new UIIntNumberField(); portNumberField = new UIIntNumberField();
passwordTextField = new UIPasswordField(); passwordTextField = new UIPasswordField();
maxTotalNumberFiled = new UIIntNumberField(); maxTotalNumberFiled = new UIIntNumberField();
maxWaitNumberField = new UINumberField();
maxWaitNumberField.setMinValue(-1);
maxWaitNumberField.setMaxDecimalLength(0);
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
{new UILabel(Toolkit.i18nText("Plugin-Redis_Host") + ":"), hostTextField}, {new UILabel(Toolkit.i18nText("Plugin-Redis_Host") + ":"), hostTextField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Port") + ":"), portNumberField}, {new UILabel(Toolkit.i18nText("Plugin-Redis_Port") + ":"), portNumberField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Password") + ":"), passwordTextField}, {new UILabel(Toolkit.i18nText("Plugin-Redis_Password") + ":"), passwordTextField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Pool_Max_Total") + ":"), maxTotalNumberFiled} {new UILabel(Toolkit.i18nText("Plugin-Redis_Pool_Max_Total") + ":"), maxTotalNumberFiled},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Pool_Max_Wait") + ":"), maxWaitNumberField}
}; };
double p = TableLayout.PREFERRED; double p = TableLayout.PREFERRED;
double[] rowSize = new double[]{p, p, p, p, p}; double[] rowSize = new double[]{p, p, p, p, p, p};
double[] columnSize = new double[]{p, 400}; double[] columnSize = new double[]{p, 400};
JPanel settingsUI = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); JPanel settingsUI = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
@ -67,6 +73,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
portNumberField.setValue(ob.getPort()); portNumberField.setValue(ob.getPort());
passwordTextField.setText(ob.getPassword()); passwordTextField.setText(ob.getPassword());
maxTotalNumberFiled.setValue(ob.getMaxTotal()); maxTotalNumberFiled.setValue(ob.getMaxTotal());
maxWaitNumberField.setValue(ob.getMaxWait());
} }
@Override @Override
@ -76,6 +83,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
connection.setPort((int) portNumberField.getValue()); connection.setPort((int) portNumberField.getValue());
connection.setPassword(passwordTextField.getText()); connection.setPassword(passwordTextField.getText());
connection.setMaxTotal((int)maxTotalNumberFiled.getValue()); connection.setMaxTotal((int)maxTotalNumberFiled.getValue());
connection.setMaxWait((int) maxWaitNumberField.getValue());
return connection; return connection;
} }

1
src/main/resources/com/fr/plugin/db/redis/locale/redis.properties

@ -19,3 +19,4 @@ Plugin-Redis_Script_Text=Transform Script
Plugin-Redis_Script_Text_Description=Script Description Plugin-Redis_Script_Text_Description=Script Description
Plugin-Redis_Pool_Max_Total=Max Total Plugin-Redis_Pool_Max_Total=Max Total
Plugin-Redis_Script_Query_Text=Query Script Plugin-Redis_Script_Query_Text=Query Script
Plugin-Redis_Pool_Max_Wait=Max Wait

1
src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties

@ -19,3 +19,4 @@ Plugin-Redis_Script_Text=Transform Script
Plugin-Redis_Script_Text_Description=Script Description Plugin-Redis_Script_Text_Description=Script Description
Plugin-Redis_Pool_Max_Total=Max Total Plugin-Redis_Pool_Max_Total=Max Total
Plugin-Redis_Script_Query_Text=Query Script Plugin-Redis_Script_Query_Text=Query Script
Plugin-Redis_Pool_Max_Wait=Max Wait

3
src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

@ -19,4 +19,5 @@ Plugin-Redis_Script_Text=\u8F6C\u6362\u811A\u672C
Plugin-Redis_Script_Text_Description=\u53EF\u4EE5\u4F7F\u7528JavaScript\u811A\u672C\u6765\u8F6C\u6362\u67E5\u8BE2\u7ED3\u679C\u3002\n\u6CE8\u610F1\uFF1A\u5185\u7F6E\u53C2\u6570$content\u548C$column\uFF0C\u5206\u522B\u8868\u793A\u539F\u59CB\u7684\u6570\u636E\u96C6\u5185\u5BB9\uFF08\u4E8C\u7EF4\u6570\u7EC4\uFF09\u548C\u6570\u636E\u96C6\u7684\u5217\u540D\uFF08\u4E00\u7EF4\u6570\u7EC4\uFF09\u3002\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u4E8C\u7EF4\u6570\u7EC4\uFF0C\u8868\u793A\u4EC5\u4FEE\u6539\u6570\u636E\u96C6\u5185\u5BB9\uFF0C\u4E0D\u4FEE\u6539\u6570\u636E\u96C6\u7684\u5217\u540D\uFF1B\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u5982\u4E0B\u683C\u5F0F\u7684\u5BF9\u8C61:\ Plugin-Redis_Script_Text_Description=\u53EF\u4EE5\u4F7F\u7528JavaScript\u811A\u672C\u6765\u8F6C\u6362\u67E5\u8BE2\u7ED3\u679C\u3002\n\u6CE8\u610F1\uFF1A\u5185\u7F6E\u53C2\u6570$content\u548C$column\uFF0C\u5206\u522B\u8868\u793A\u539F\u59CB\u7684\u6570\u636E\u96C6\u5185\u5BB9\uFF08\u4E8C\u7EF4\u6570\u7EC4\uFF09\u548C\u6570\u636E\u96C6\u7684\u5217\u540D\uFF08\u4E00\u7EF4\u6570\u7EC4\uFF09\u3002\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u4E8C\u7EF4\u6570\u7EC4\uFF0C\u8868\u793A\u4EC5\u4FEE\u6539\u6570\u636E\u96C6\u5185\u5BB9\uFF0C\u4E0D\u4FEE\u6539\u6570\u636E\u96C6\u7684\u5217\u540D\uFF1B\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u5982\u4E0B\u683C\u5F0F\u7684\u5BF9\u8C61:\
{content:[][],column:[]}\uFF0C\u8868\u793A\u540C\u65F6\u4FEE\u6539\u4E86\u6570\u636E\u96C6\u7684\u5185\u5BB9\u548C\u5217\u540D\u3002\n\u6CE8\u610F2\uFF1A\u5982\u679C\u5E0C\u671B\u5F15\u7528\u5916\u90E8JS\uFF0C\u53EF\u4EE5\u5728\u811A\u672C\u6846\u4E2D\u5199\u5165file:///$ENV_HOME/transform.js\uFF0C\u5176\u4E2D$ENV_HOME\u8868\u793A\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u3002 {content:[][],column:[]}\uFF0C\u8868\u793A\u540C\u65F6\u4FEE\u6539\u4E86\u6570\u636E\u96C6\u7684\u5185\u5BB9\u548C\u5217\u540D\u3002\n\u6CE8\u610F2\uFF1A\u5982\u679C\u5E0C\u671B\u5F15\u7528\u5916\u90E8JS\uFF0C\u53EF\u4EE5\u5728\u811A\u672C\u6846\u4E2D\u5199\u5165file:///$ENV_HOME/transform.js\uFF0C\u5176\u4E2D$ENV_HOME\u8868\u793A\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u3002
Plugin-Redis_Pool_Max_Total=\u6700\u5927\u8FDE\u63A5\u6570 Plugin-Redis_Pool_Max_Total=\u6700\u5927\u8FDE\u63A5\u6570
Plugin-Redis_Script_Query_Text=\u67E5\u8BE2\u811A\u672C Plugin-Redis_Script_Query_Text=\u67E5\u8BE2\u811A\u672C
Plugin-Redis_Pool_Max_Wait=\u6700\u5927\u7B49\u5F85\u65F6\u95F4
Loading…
Cancel
Save