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. 1
      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>
<name><![CDATA[Redis数据集]]></name>
<active>yes</active>
<version>5.1</version>
<version>5.2</version>
<env-version>10.0</env-version>
<jartime>2018-11-29</jartime>
<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 MAX_TOTAL = 10;
private static final int MAX_WAIT = -1;
private Conf<String> host = Holders.simple(StringUtils.EMPTY);
private Conf<Integer> port = Holders.simple(DEFAULT_REDIS_PORT);
private Conf<String> password = Holders.simple(StringUtils.EMPTY);
private Conf<Integer> maxTotal = Holders.simple(MAX_TOTAL);
private Conf<Integer> maxWait = Holders.simple(MAX_WAIT);
public RedisDatabaseConnection() {
@ -62,6 +64,14 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
this.maxTotal.set(maxTotal);
}
public int getMaxWait() {
return maxWait.get();
}
public void setMaxWait(int maxWait) {
this.maxWait.set(maxWait);
}
@Override
public void testConnection() throws Exception {
Jedis client = createRedisClient();
@ -77,7 +87,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
}
public Jedis createRedisClient() {
return RedisPool.getPool().getResource(getHost(), getPort(), getPassword(), getMaxTotal());
return RedisPool.getPool().getResource(getHost(), getPort(), getPassword(), getMaxTotal(), getMaxWait());
}
@Override
@ -152,6 +162,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
setPassword(SecurityToolbox.encrypt(pwd));
}
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("maxTotal", getMaxTotal());
writer.attr("maxWait", getMaxWait());
writer.end();
}
@ -176,6 +188,7 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
cloned.port = (Conf<Integer>) port.clone();
cloned.password = (Conf<String>) password.clone();
cloned.maxTotal = (Conf<Integer>) maxTotal.clone();
cloned.maxWait = (Conf<Integer>) maxWait.clone();
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>();
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);
if (jedisPool == null) {
jedisPool = createJedisPool(host, port, password, maxTotal);
jedisPool = createJedisPool(host, port, password, maxTotal, maxWait);
jedisPoolMap.put(host, jedisPool);
}
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();
config.setMaxTotal(maxTotal);
//连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
@ -51,7 +51,7 @@ public class RedisPool {
config.setMaxIdle(10);
//最大连接数,可配置
//获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
config.setMaxWaitMillis(-1);
config.setMaxWaitMillis(maxWait);
//逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
config.setMinEvictableIdleTimeMillis(1800000);
//最小空闲连接数, 默认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.V8Array;
import com.eclipsesource.v8.V8Object;
import com.fr.base.TableData;
import com.fr.data.AbstractDataModel;
import com.fr.plugin.db.redis.help.Console;
import com.fr.plugin.db.redis.help.Files;
@ -61,7 +62,8 @@ public class RedisScriptTableDataModel extends AbstractDataModel {
columnNames[i] = String.valueOf(v8Column.get(i));
}
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);
List<Object> row = new ArrayList<Object>();
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.data.AbstractDataModel;
import com.fr.general.data.TableDataException;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
@ -14,12 +13,9 @@ import com.fr.third.redis.clients.jedis.Jedis;
import java.util.List;
public class RedisTableDataModel extends AbstractDataModel {
private Jedis redisClient;
private String[] columnNames;
private List<List<Object>> data;
public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) {
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(RedisConstants.PLUGIN_ID);
if (pluginLicense.isAvailable()) {
@ -33,11 +29,9 @@ public class RedisTableDataModel extends AbstractDataModel {
if (StringUtils.isEmpty(query)) {
return;
}
if (redisClient == null) {
redisClient = mc.createRedisClient();
redisClient.select(dbIndex);
FineLoggerFactory.getLogger().info("Connect to redis and select database:" + dbIndex);
}
Jedis redisClient = mc.createRedisClient();
redisClient.select(dbIndex);
FineLoggerFactory.getLogger().info("Connect to redis and select database:" + dbIndex);
try {
long start = System.currentTimeMillis();
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redisClient, query, rowCount);
@ -45,33 +39,34 @@ public class RedisTableDataModel extends AbstractDataModel {
wrapper.transform(script);
data = wrapper.getData();
columnNames = wrapper.getColumnNames();
redisClient.close();
} catch (Exception e) {
throw new RuntimeException(e.getCause());
}
}
@Override
public int getColumnCount() throws TableDataException {
public int getColumnCount() {
return columnNames.length;
}
@Override
public String getColumnName(int columnIndex) throws TableDataException {
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
@Override
public boolean hasRow(int rowIndex) throws TableDataException {
public boolean hasRow(int rowIndex) {
return data != null && data.get(0).size() > rowIndex;
}
@Override
public int getRowCount() throws TableDataException {
public int getRowCount() {
return data == null ? 0 : data.get(0).size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException {
public Object getValueAt(int rowIndex, int columnIndex) {
if (data != null && data.size() > columnIndex) {
List<Object> columnData = data.get(columnIndex);
if (columnData != null && columnData.size() > rowIndex) {
@ -83,9 +78,6 @@ public class RedisTableDataModel extends AbstractDataModel {
@Override
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.ilable.UILabel;
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.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
@ -23,6 +24,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
private UIIntNumberField portNumberField;
private UIPasswordField passwordTextField;
private UIIntNumberField maxTotalNumberFiled;
private UINumberField maxWaitNumberField;
@Override
@ -33,16 +35,20 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
portNumberField = new UIIntNumberField();
passwordTextField = new UIPasswordField();
maxTotalNumberFiled = new UIIntNumberField();
maxWaitNumberField = new UINumberField();
maxWaitNumberField.setMinValue(-1);
maxWaitNumberField.setMaxDecimalLength(0);
Component[][] components = new Component[][]{
{new UILabel(Toolkit.i18nText("Plugin-Redis_Host") + ":"), hostTextField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Port") + ":"), portNumberField},
{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[] rowSize = new double[]{p, p, p, p, p};
double[] rowSize = new double[]{p, p, p, p, p, p};
double[] columnSize = new double[]{p, 400};
JPanel settingsUI = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
@ -67,6 +73,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
portNumberField.setValue(ob.getPort());
passwordTextField.setText(ob.getPassword());
maxTotalNumberFiled.setValue(ob.getMaxTotal());
maxWaitNumberField.setValue(ob.getMaxWait());
}
@Override
@ -76,6 +83,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
connection.setPort((int) portNumberField.getValue());
connection.setPassword(passwordTextField.getText());
connection.setMaxTotal((int)maxTotalNumberFiled.getValue());
connection.setMaxWait((int) maxWaitNumberField.getValue());
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_Pool_Max_Total=Max Total
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_Pool_Max_Total=Max Total
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_zh_CN.properties

@ -20,3 +20,4 @@ Plugin-Redis_Script_Text_Description=\u53EF\u4EE5\u4F7F\u7528JavaScript\u811A\u6
{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_Script_Query_Text=\u67E5\u8BE2\u811A\u672C
Plugin-Redis_Pool_Max_Wait=\u6700\u5927\u7B49\u5F85\u65F6\u95F4
Loading…
Cancel
Save