Browse Source

增加redis使用代理的服务器的特性

paid
richie 6 years ago
parent
commit
5170d636f9
  1. 5
      plugin.xml
  2. 41
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  3. 63
      src/main/java/com/fr/plugin/db/redis/core/RedisPool.java
  4. 9
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java
  5. 10
      src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java
  6. 15
      src/main/java/com/fr/plugin/db/redis/core/emb/Redis.java
  7. 32
      src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java
  8. 28
      src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java
  9. 53
      src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionPoolConfig.java
  10. 97
      src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionProxyConfig.java
  11. 79
      src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java
  12. 57
      src/main/java/com/fr/plugin/db/redis/ui/pool/RedisConnectionPoolConfigPane.java
  13. 107
      src/main/java/com/fr/plugin/db/redis/ui/proxy/RedisConnectionProxyConfigPane.java
  14. 9
      src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java
  15. 9
      src/main/resources/com/fr/plugin/db/redis/locale/redis.properties
  16. 9
      src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties
  17. 11
      src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

5
plugin.xml

@ -3,13 +3,14 @@
<id>com.fr.solution.plugin.db.redis.v10</id>
<name><![CDATA[Redis数据集]]></name>
<active>yes</active>
<version>5.2</version>
<version>6.0</version>
<env-version>10.0</env-version>
<jartime>2018-11-29</jartime>
<vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[
[2019-03-18]修复连接美语释放的问题。<br/>
[2019-03-21]增加代理服务配置。<br/>
[2019-03-18]修复连接没有释放的问题。<br/>
[2019-03-18]增加程序数据集,可以使用javascript进行取数,需要2019-03-01之后的版本。<br/>
[2019-02-15]结果集可以通过JavaScript脚本进行转换。<br/>
[2018-11-30]解决远程设计时无法查询key列表的问题。<br/>

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

@ -5,6 +5,7 @@ import com.fr.config.holder.factory.Holders;
import com.fr.data.impl.AbstractDatabaseConnection;
import com.fr.data.impl.Connection;
import com.fr.locale.InterProviderFactory;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.security.SecurityToolbox;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils;
@ -19,14 +20,10 @@ import java.util.Set;
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() {
@ -56,27 +53,12 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
this.password.set(password);
}
public int getMaxTotal() {
return maxTotal.get();
}
public void setMaxTotal(Integer maxTotal) {
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();
Redis client = createRedisClient();
try {
String text = client.ping();
String text = client.getClient().ping();
if (!"pong".equalsIgnoreCase(text)) {
throw new Exception(text);
}
@ -86,8 +68,8 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
}
public Jedis createRedisClient() {
return RedisPool.getPool().getResource(getHost(), getPort(), getPassword(), getMaxTotal(), getMaxWait());
public Redis createRedisClient() {
return RedisPool.getPool().getResource(getHost(), getPort(), getPassword());
}
@Override
@ -100,8 +82,11 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
if (ArrayUtils.isEmpty(args)) {
return ArrayUtils.EMPTY_STRING_ARRAY;
} else {
Set<String> keys = createRedisClient().keys(args[0]);
return keys.toArray(new String[0]);
Redis redis = createRedisClient();
Set<String> keys = redis.getClient().keys(args[0]);
String[] array = keys.toArray(new String[0]);
redis.close();
return array;
}
}
@ -161,8 +146,6 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
if (StringUtils.isNotEmpty(pwd)) {
setPassword(SecurityToolbox.encrypt(pwd));
}
setMaxTotal(reader.getAttrAsInt("maxTotal", MAX_TOTAL));
setMaxWait(reader.getAttrAsInt("maxWait", MAX_WAIT));
}
}
}
@ -176,8 +159,6 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
if (StringUtils.isNotEmpty(getPassword())) {
writer.attr("password", SecurityToolbox.decrypt(getPassword()));
}
writer.attr("maxTotal", getMaxTotal());
writer.attr("maxWait", getMaxWait());
writer.end();
}
@ -187,8 +168,6 @@ public class RedisDatabaseConnection extends AbstractDatabaseConnection {
cloned.host = (Conf<String>) host.clone();
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;
}
}

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

@ -1,5 +1,14 @@
package com.fr.plugin.db.redis.core;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.plugin.db.redis.core.emb.impl.ProxyRedis;
import com.fr.plugin.db.redis.core.emb.impl.SimpleRedis;
import com.fr.plugin.db.redis.core.pool.RedisConnectionPoolConfig;
import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig;
import com.fr.ssh.jsch.JSch;
import com.fr.ssh.jsch.JSchException;
import com.fr.ssh.jsch.Session;
import com.fr.stable.StringUtils;
import com.fr.third.redis.clients.jedis.Jedis;
import com.fr.third.redis.clients.jedis.JedisPool;
@ -25,18 +34,30 @@ public class RedisPool {
private Map<String, JedisPool> jedisPoolMap = new ConcurrentHashMap<String, JedisPool>();
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, maxWait);
jedisPoolMap.put(host, jedisPool);
public Redis getResource(String host, int port, String password) {
if (RedisConnectionProxyConfig.getInstance().isOpen()) {
try {
return createJedisBySSH(host, port, password);
} catch (JSchException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
} else {
JedisPool jedisPool = jedisPoolMap.get(host);
if (jedisPool == null) {
jedisPool = createJedisPool(host, port, password);
jedisPoolMap.put(host, jedisPool);
}
return new SimpleRedis(jedisPool.getResource());
}
return jedisPool.getResource();
Jedis jedis = new Jedis(host, port);
jedis.auth(password);
return new SimpleRedis(jedis);
}
private JedisPool createJedisPool(String host, int port, String password, int maxTotal, int maxWait) {
private JedisPool createJedisPool(String host, int port, String password) {
RedisConnectionPoolConfig poolConfig = RedisConnectionPoolConfig.getInstance();
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(maxTotal);
config.setMaxTotal(poolConfig.getMaxTotal());
//连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
config.setBlockWhenExhausted(true);
//设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数)
@ -51,7 +72,7 @@ public class RedisPool {
config.setMaxIdle(10);
//最大连接数,可配置
//获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
config.setMaxWaitMillis(maxWait);
config.setMaxWaitMillis(poolConfig.getMaxWait());
//逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
config.setMinEvictableIdleTimeMillis(1800000);
//最小空闲连接数, 默认0
@ -72,4 +93,28 @@ public class RedisPool {
return new JedisPool(config, host, port, TIME_OUT);
}
}
private Redis createJedisBySSH(String host, int port, String password) throws JSchException {
RedisConnectionProxyConfig proxyConfig = RedisConnectionProxyConfig.getInstance();
JSch jsch = new JSch();
if (StringUtils.isNotBlank(proxyConfig.getPrivateKeyPath())) {
jsch.addIdentity(proxyConfig.getPrivateKeyPath());
}
Session session = jsch.getSession(proxyConfig.getUsername(), proxyConfig.getHost(), proxyConfig.getPort());
if (StringUtils.isNotBlank(proxyConfig.getPassword())) {
session.setPassword(proxyConfig.getPassword());
}
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
int newPort = session.setPortForwardingL(0, host, port);
Jedis jedis = new Jedis(host, newPort);
if (StringUtils.isNotBlank(password)) {
jedis.auth(password);
}
return new ProxyRedis(session, jedis);
}
}

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

@ -5,6 +5,7 @@ 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.core.emb.Redis;
import com.fr.plugin.db.redis.help.Console;
import com.fr.plugin.db.redis.help.Files;
import com.fr.plugin.db.redis.help.RedisClient;
@ -40,10 +41,10 @@ public class RedisScriptTableDataModel extends AbstractDataModel {
if (columnNames != null) {
return;
}
Jedis jedis = mc.createRedisClient();
jedis.select(dbIndex);
Redis redis = mc.createRedisClient();
redis.getClient().select(dbIndex);
V8 v8 = V8.createV8Runtime();
RedisClient client = new RedisClient(v8, jedis);
RedisClient client = new RedisClient(v8, redis.getClient());
V8Object v8Console = initConsole(v8);
V8Object v8Require = initRequire(v8);
V8Object v8Client = initRedis(v8, client);
@ -72,7 +73,7 @@ public class RedisScriptTableDataModel extends AbstractDataModel {
v8Row.release();
data.add(row);
}
jedis.close();
redis.close();
v8Table.release();
v8Column.release();
returnObj.release();

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

@ -5,7 +5,9 @@ import com.fr.data.AbstractDataModel;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.plugin.db.redis.core.visit.VisitorFactory;
import com.fr.plugin.db.redis.util.RedisUtils;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
import com.fr.third.redis.clients.jedis.Jedis;
@ -29,17 +31,17 @@ public class RedisTableDataModel extends AbstractDataModel {
if (StringUtils.isEmpty(query)) {
return;
}
Jedis redisClient = mc.createRedisClient();
redisClient.select(dbIndex);
Redis redis = mc.createRedisClient();
redis.getClient().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);
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount);
FineLoggerFactory.getLogger().info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
wrapper.transform(script);
data = wrapper.getData();
columnNames = wrapper.getColumnNames();
redisClient.close();
redis.close();
} catch (Exception e) {
throw new RuntimeException(e.getCause());
}

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

@ -0,0 +1,15 @@
package com.fr.plugin.db.redis.core.emb;
import com.fr.third.redis.clients.jedis.Jedis;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public interface Redis {
Jedis getClient();
void close();
}

32
src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java

@ -0,0 +1,32 @@
package com.fr.plugin.db.redis.core.emb.impl;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.ssh.jsch.Session;
import com.fr.third.redis.clients.jedis.Jedis;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public class ProxyRedis implements Redis {
private Session session;
private Jedis jedis;
public ProxyRedis(Session session, Jedis jedis) {
this.session = session;
this.jedis = jedis;
}
@Override
public Jedis getClient() {
return jedis;
}
@Override
public void close() {
jedis.close();
session.disconnect();
}
}

28
src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java

@ -0,0 +1,28 @@
package com.fr.plugin.db.redis.core.emb.impl;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.third.redis.clients.jedis.Jedis;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public class SimpleRedis implements Redis {
private Jedis jedis;
public SimpleRedis(Jedis jedis) {
this.jedis = jedis;
}
@Override
public Jedis getClient() {
return jedis;
}
@Override
public void close() {
jedis.close();
}
}

53
src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionPoolConfig.java

@ -0,0 +1,53 @@
package com.fr.plugin.db.redis.core.pool;
import com.fr.config.ConfigContext;
import com.fr.config.DefaultConfiguration;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public class RedisConnectionPoolConfig extends DefaultConfiguration {
private static volatile RedisConnectionPoolConfig instance = null;
public static RedisConnectionPoolConfig getInstance() {
if (instance == null) {
instance = ConfigContext.getConfigInstance(RedisConnectionPoolConfig.class);
}
return instance;
}
private static final int MAX_TOTAL = 10;
private static final int MAX_WAIT = -1;
private Conf<Integer> maxTotal = Holders.simple(MAX_TOTAL);
private Conf<Integer> maxWait = Holders.simple(MAX_WAIT);
public int getMaxTotal() {
return maxTotal.get();
}
public void setMaxTotal(Integer maxTotal) {
this.maxTotal.set(maxTotal);
}
public int getMaxWait() {
return maxWait.get();
}
public void setMaxWait(int maxWait) {
this.maxWait.set(maxWait);
}
@Override
public Object clone() throws CloneNotSupportedException {
RedisConnectionPoolConfig cloned = (RedisConnectionPoolConfig) super.clone();
cloned.maxTotal = (Conf<Integer>) maxTotal.clone();
cloned.maxWait = (Conf<Integer>) maxWait.clone();
return cloned;
}
}

97
src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionProxyConfig.java

@ -0,0 +1,97 @@
package com.fr.plugin.db.redis.core.pool;
import com.fr.config.ConfigContext;
import com.fr.config.DefaultConfiguration;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.stable.StringUtils;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public class RedisConnectionProxyConfig extends DefaultConfiguration {
private static volatile RedisConnectionProxyConfig instance = null;
public static RedisConnectionProxyConfig getInstance() {
if (instance == null) {
instance = ConfigContext.getConfigInstance(RedisConnectionProxyConfig.class);
}
return instance;
}
private Conf<Boolean> open = Holders.simple(false);
private Conf<String> host = Holders.simple(StringUtils.EMPTY);
private Conf<Integer> port = Holders.simple(22);
private Conf<String> username = Holders.simple(StringUtils.EMPTY);
private Conf<String> password = Holders.simple(StringUtils.EMPTY);
private Conf<String> privateKeyPath = Holders.simple(StringUtils.EMPTY);
public boolean isOpen() {
return open.get();
}
public void setOpen(boolean open) {
this.open.set(open);
}
public String getHost() {
return host.get();
}
public void setHost(String host) {
this.host.set(host);
}
public int getPort() {
return port.get();
}
public void setPort(int port) {
this.port.set(port);
}
public String getUsername() {
return username.get();
}
public void setUsername(String username) {
this.username.set(username);
}
public String getPassword() {
return password.get();
}
public void setPassword(String password) {
this.password.set(password);
}
public String getPrivateKeyPath() {
return privateKeyPath.get();
}
public void setPrivateKeyPath(String privateKeyPath) {
this.privateKeyPath.set(privateKeyPath);
}
@Override
public Object clone() throws CloneNotSupportedException {
RedisConnectionProxyConfig cloned = (RedisConnectionProxyConfig) super.clone();
cloned.open = (Conf<Boolean>) open.clone();
cloned.host = (Conf<String>) host.clone();
cloned.port = (Conf<Integer>) port.clone();
cloned.username = (Conf<String>) username.clone();
cloned.password = (Conf<String>) password.clone();
cloned.privateKeyPath = (Conf<String>) privateKeyPath.clone();
return cloned;
}
}

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

@ -2,7 +2,10 @@ package com.fr.plugin.db.redis.ui;
import com.fr.design.border.UITitledBorder;
import com.fr.design.data.datapane.connect.DatabaseConnectionPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.ibutton.UIPasswordField;
import com.fr.design.gui.ilable.ActionLabel;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.gui.itextfield.UINumberField;
@ -11,11 +14,19 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.general.Inter;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.plugin.db.redis.core.RedisDatabaseConnection;
import com.fr.plugin.db.redis.core.pool.RedisConnectionPoolConfig;
import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig;
import com.fr.plugin.db.redis.ui.pool.RedisConnectionPoolConfigPane;
import com.fr.plugin.db.redis.ui.proxy.RedisConnectionProxyConfigPane;
import com.fr.transaction.Configurations;
import com.fr.transaction.WorkerFacade;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db.redis.core.RedisDatabaseConnection> {
@ -23,8 +34,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
private UITextField hostTextField;
private UIIntNumberField portNumberField;
private UIPasswordField passwordTextField;
private UIIntNumberField maxTotalNumberFiled;
private UINumberField maxWaitNumberField;
@Override
@ -34,21 +44,66 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
hostTextField = new UITextField();
portNumberField = new UIIntNumberField();
passwordTextField = new UIPasswordField();
maxTotalNumberFiled = new UIIntNumberField();
maxWaitNumberField = new UINumberField();
maxWaitNumberField.setMinValue(-1);
maxWaitNumberField.setMaxDecimalLength(0);
JPanel globalConfigPane = new JPanel();
GridLayout gridLayout = new GridLayout(1, 2);
globalConfigPane.setLayout(gridLayout);
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_Wait") + ":"), maxWaitNumberField}
{null, globalConfigPane}
};
ActionLabel poolConfigLabel = new ActionLabel(Toolkit.i18nText("Plugin-Redis_Pool_Config"));
ActionLabel proxyConfigLabel = new ActionLabel(Toolkit.i18nText("Plugin-Redis_Proxy_Config"));
poolConfigLabel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final RedisConnectionPoolConfig poolConfig = RedisConnectionPoolConfig.getInstance();
final RedisConnectionPoolConfigPane poolConfigPane = new RedisConnectionPoolConfigPane();
poolConfigPane.populate(poolConfig);
BasicDialog dialog = poolConfigPane.showWindow(SwingUtilities.getWindowAncestor(RedisConnectionPane.this), new DialogActionAdapter() {
@Override
public void doOk() {
Configurations.modify(new WorkerFacade(RedisConnectionPoolConfig.class) {
@Override
public void run() {
poolConfigPane.update(poolConfig);
}
});
}
});
dialog.setVisible(true);
}
});
proxyConfigLabel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final RedisConnectionProxyConfig proxyConfig = RedisConnectionProxyConfig.getInstance();
final RedisConnectionProxyConfigPane proxyConfigPane = new RedisConnectionProxyConfigPane();
proxyConfigPane.populate(proxyConfig);
BasicDialog dialog = proxyConfigPane.showWindow(SwingUtilities.getWindowAncestor(RedisConnectionPane.this), new DialogActionAdapter() {
@Override
public void doOk() {
Configurations.modify(new WorkerFacade(RedisConnectionProxyConfig.class) {
@Override
public void run() {
proxyConfigPane.update(proxyConfig);
}
});
}
});
dialog.setVisible(true);
}
});
globalConfigPane.add(GUICoreUtils.createFlowPane(poolConfigLabel, FlowLayout.LEFT));
globalConfigPane.add(GUICoreUtils.createFlowPane(proxyConfigLabel, FlowLayout.LEFT));
double p = TableLayout.PREFERRED;
double[] rowSize = new double[]{p, p, p, p, p, p};
double[] rowSize = new double[]{p, p, p, p, p};
double[] columnSize = new double[]{p, 400};
JPanel settingsUI = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
@ -72,8 +127,6 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
hostTextField.setText(ob.getHost());
portNumberField.setValue(ob.getPort());
passwordTextField.setText(ob.getPassword());
maxTotalNumberFiled.setValue(ob.getMaxTotal());
maxWaitNumberField.setValue(ob.getMaxWait());
}
@Override
@ -82,8 +135,6 @@ public class RedisConnectionPane extends DatabaseConnectionPane<com.fr.plugin.db
connection.setHost(hostTextField.getText());
connection.setPort((int) portNumberField.getValue());
connection.setPassword(passwordTextField.getText());
connection.setMaxTotal((int)maxTotalNumberFiled.getValue());
connection.setMaxWait((int) maxWaitNumberField.getValue());
return connection;
}

57
src/main/java/com/fr/plugin/db/redis/ui/pool/RedisConnectionPoolConfigPane.java

@ -0,0 +1,57 @@
package com.fr.plugin.db.redis.ui.pool;
import com.fr.design.dialog.BasicPane;
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.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.plugin.db.redis.core.pool.RedisConnectionPoolConfig;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public class RedisConnectionPoolConfigPane extends BasicPane {
private UIIntNumberField maxTotalNumberFiled;
private UINumberField maxWaitNumberField;
public RedisConnectionPoolConfigPane() {
setLayout(new BorderLayout());
maxTotalNumberFiled = new UIIntNumberField();
maxWaitNumberField = new UINumberField();
maxWaitNumberField.setMinValue(-1);
maxWaitNumberField.setMaxDecimalLength(0);
JComponent[][] comps = new JComponent[][]{
{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 f = TableLayout.FILL;
double[] rowSize = new double[]{p, p};
double[] columnSize = new double[]{p, f};
add(TableLayoutHelper.createTableLayoutPane(comps, rowSize, columnSize), BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Plugin-Redis_Pool_Config");
}
public void populate(RedisConnectionPoolConfig config) {
maxTotalNumberFiled.setValue(config.getMaxTotal());
maxWaitNumberField.setValue(config.getMaxWait());
}
public void update(RedisConnectionPoolConfig config) {
config.setMaxTotal((int)maxTotalNumberFiled.getValue());
config.setMaxWait((int) maxWaitNumberField.getValue());
}
}

107
src/main/java/com/fr/plugin/db/redis/ui/proxy/RedisConnectionProxyConfigPane.java

@ -0,0 +1,107 @@
package com.fr.plugin.db.redis.ui.proxy;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ipasswordfield.UIPassWordField;
import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
public class RedisConnectionProxyConfigPane extends BasicPane {
private UICheckBox openCheckBox;
private UITextField hostTextField;
private UIIntNumberField portNumberField;
private UITextField usernameTextField;
private UIPassWordField passwordTextField;
private UITextField privateKeyPathTextField;
public RedisConnectionProxyConfigPane() {
setLayout(new BorderLayout());
openCheckBox = new UICheckBox();
openCheckBox.setSelected(false);
hostTextField = new UITextField();
portNumberField = new UIIntNumberField();
usernameTextField = new UITextField();
passwordTextField = new UIPassWordField();
privateKeyPathTextField = new UITextField();
privateKeyPathTextField.setPlaceholder(Toolkit.i18nText("Plugin-Redis_Proxy_Private_Key_Tip"));
UIButton fileSelectButton = new UIButton("...");
JComponent[][] comps = new JComponent[][]{
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Open") + ":"), openCheckBox},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Host") + ":"), hostTextField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Port") + ":"), portNumberField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Username") + ":"), usernameTextField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Password") + ":"), passwordTextField},
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Private_Key_Path") + ":"), GUICoreUtils.createBorderLayoutPane(
privateKeyPathTextField, BorderLayout.CENTER,
fileSelectButton, BorderLayout.EAST
)},
};
fileSelectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(SwingUtilities.getWindowAncestor(RedisConnectionProxyConfigPane.this));
File file = chooser.getSelectedFile();
if (file != null) {
privateKeyPathTextField.setText(file.getAbsolutePath());
}
}
});
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] rowSize = new double[]{p, p, p, p, p, p};
double[] columnSize = new double[]{p, f};
add(TableLayoutHelper.createTableLayoutPane(comps, rowSize, columnSize), BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Plugin-Redis_Proxy_Config");
}
public void populate(RedisConnectionProxyConfig config) {
openCheckBox.setSelected(config.isOpen());
hostTextField.setText(config.getHost());
portNumberField.setValue(config.getPort());
usernameTextField.setText(config.getUsername());
passwordTextField.setText(config.getPassword());
privateKeyPathTextField.setText(config.getPrivateKeyPath());
}
public void update(RedisConnectionProxyConfig config) {
config.setOpen(openCheckBox.isSelected());
config.setHost(hostTextField.getText());
config.setPort((int) portNumberField.getValue());
config.setUsername(usernameTextField.getText());
config.setPassword(passwordTextField.getText());
config.setPrivateKeyPath(privateKeyPathTextField.getText());
}
}

9
src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java

@ -4,6 +4,7 @@ import com.eclipsesource.v8.V8Object;
import com.fr.base.Parameter;
import com.fr.base.TemplateUtils;
import com.fr.stable.ArrayUtils;
import com.fr.third.redis.clients.jedis.Jedis;
import java.lang.reflect.Method;
import java.util.HashMap;
@ -16,6 +17,14 @@ import java.util.Map;
*/
public class RedisUtils {
/**
* 关闭redis客户端
* @param jedis redis客户端对象
*/
public static void close(Jedis jedis) {
jedis.close();
}
public static String calculateQuery(String query, Parameter[] ps) {
if (ArrayUtils.isEmpty(ps)) {
return query;

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

@ -20,3 +20,12 @@ 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
Plugin-Redis_Pool_Config=Jedis Pool Config
Plugin-Redis_Proxy_Config=Proxy Config
Plugin-Redis_Proxy_Open=Open Proxy Server
Plugin-Redis_Proxy_Host=Host
Plugin-Redis_Proxy_Port=Port
Plugin-Redis_Proxy_Username=Username
Plugin-Redis_Proxy_Password=Password
Plugin-Redis_Proxy_Private_Key_Path=Key Path
Plugin-Redis_Proxy_Private_Key_Tip=Path To Private Key in PEM Format

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

@ -20,3 +20,12 @@ 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
Plugin-Redis_Pool_Config=Jedis Pool Config
Plugin-Redis_Proxy_Config=Proxy Config
Plugin-Redis_Proxy_Open=Open Proxy Server
Plugin-Redis_Proxy_Host=Host
Plugin-Redis_Proxy_Port=Port
Plugin-Redis_Proxy_Username=Username
Plugin-Redis_Proxy_Password=Password
Plugin-Redis_Proxy_Private_Key_Path=Key Path
Plugin-Redis_Proxy_Private_Key_Tip=Path To Private Key in PEM Format

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

@ -20,4 +20,13 @@ 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
Plugin-Redis_Pool_Max_Wait=\u6700\u5927\u7B49\u5F85\u65F6\u95F4
Plugin-Redis_Pool_Config=\u8FDE\u63A5\u6C60\u914D\u7F6E
Plugin-Redis_Proxy_Config=\u4EE3\u7406\u670D\u52A1\u5668\u8BBE\u7F6E
Plugin-Redis_Proxy_Open=\u542F\u7528\u4EE3\u7406\u670D\u52A1\u5668
Plugin-Redis_Proxy_Host=\u4E3B\u673A\u5730\u5740
Plugin-Redis_Proxy_Port=\u7AEF\u53E3
Plugin-Redis_Proxy_Username=\u7528\u6237\u540D
Plugin-Redis_Proxy_Password=\u5BC6\u7801
Plugin-Redis_Proxy_Private_Key_Path=\u79D8\u94A5\u6587\u4EF6
Plugin-Redis_Proxy_Private_Key_Tip=PEM\u683C\u5F0F\u7684\u79D8\u94A5\u6587\u4EF6\u8DEF\u5F84
Loading…
Cancel
Save