Browse Source

重新实现返回非基本类型的查询方法

paid
richie 5 years ago
parent
commit
913e7cc45e
  1. 2
      plugin.xml
  2. 16
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableData.java
  3. 7
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java
  4. 30
      src/main/java/com/fr/plugin/db/redis/core/script/EngineType.java
  5. 16
      src/main/java/com/fr/plugin/db/redis/help/RedisClient.java
  6. 6
      src/main/java/com/fr/plugin/db/redis/help/RedisClientSelector.java
  7. 89
      src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java
  8. 60
      src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java
  9. 63
      src/main/java/com/fr/plugin/db/redis/help/client/RedisV8Client.java
  10. 48
      src/main/java/com/fr/plugin/db/redis/ui/RedisScriptPane.java
  11. 6
      src/main/java/com/fr/plugin/db/redis/ui/RedisScriptTableDataPane.java
  12. BIN
      src/main/resources/com/fr/plugin/db/redis/images/help.png
  13. 3
      src/main/resources/com/fr/plugin/db/redis/locale/redis.properties
  14. 3
      src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties
  15. 3
      src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

2
plugin.xml

@ -5,7 +5,7 @@
<active>yes</active> <active>yes</active>
<version>7.0</version> <version>7.0</version>
<env-version>10.0</env-version> <env-version>10.0</env-version>
<jartime>2019-07-29</jartime> <jartime>2019-02-29</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description> <description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[

16
src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableData.java

@ -14,6 +14,7 @@ import com.fr.general.data.DataModel;
import com.fr.intelli.record.Focus; import com.fr.intelli.record.Focus;
import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue; import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue;
import com.fr.plugin.db.redis.core.script.EngineType;
import com.fr.plugin.db.redis.util.RedisUtils; import com.fr.plugin.db.redis.util.RedisUtils;
import com.fr.record.analyzer.EnableMetrics; import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.Calculator; import com.fr.script.Calculator;
@ -35,6 +36,7 @@ public class RedisScriptTableData extends BaseTableData {
private Conf<Connection> database = HolderKit.obj(null, Connection.class); private Conf<Connection> database = HolderKit.obj(null, Connection.class);
private Conf<OrderValue> dbIndex = XmlHolderKit.obj(new NumberOrderValue(0), OrderValue.class, OrderValue.XML_TAG); private Conf<OrderValue> dbIndex = XmlHolderKit.obj(new NumberOrderValue(0), OrderValue.class, OrderValue.XML_TAG);
private Conf<String> script = HolderKit.simple(StringKit.EMPTY); private Conf<String> script = HolderKit.simple(StringKit.EMPTY);
private Conf<Integer> engineType = HolderKit.simple(EngineType.JAVA.getType());
public void setDatabase(Connection c) { public void setDatabase(Connection c) {
this.database.set(c); this.database.set(c);
@ -52,6 +54,14 @@ public class RedisScriptTableData extends BaseTableData {
this.dbIndex.set(dbIndex); this.dbIndex.set(dbIndex);
} }
public EngineType getEngineType() {
return EngineType.parse(engineType.get());
}
public void setEngineType(EngineType engineType) {
this.engineType.set(engineType.getType());
}
public String getScript() { public String getScript() {
return script.get(); return script.get();
} }
@ -80,7 +90,9 @@ public class RedisScriptTableData extends BaseTableData {
RedisDatabaseConnection rc = ConnectionKit.getConnection(name, RedisDatabaseConnection.class); RedisDatabaseConnection rc = ConnectionKit.getConnection(name, RedisDatabaseConnection.class);
if (rc != null) { if (rc != null) {
OrderValue orderValue = dbIndex.get(); OrderValue orderValue = dbIndex.get();
EngineType engineType = getEngineType();
DataModel model = new RedisScriptTableDataModel(rc, DataModel model = new RedisScriptTableDataModel(rc,
engineType,
orderValue == null ? 0 : orderValue.toIndex(calculator, ps), orderValue == null ? 0 : orderValue.toIndex(calculator, ps),
RedisUtils.calculateQuery(script.get(), ps), RedisUtils.calculateQuery(script.get(), ps),
rowCount); rowCount);
@ -113,6 +125,8 @@ public class RedisScriptTableData extends BaseTableData {
if (isNotNullValue(tmpVal)) { if (isNotNullValue(tmpVal)) {
this.setScript(tmpVal); this.setScript(tmpVal);
} }
} else if ("ScriptAttr".equals(tmpName)) {
setEngineType(EngineType.parse(reader.getAttrAsInt("engineType", 0)));
} }
} }
} }
@ -125,6 +139,7 @@ public class RedisScriptTableData extends BaseTableData {
XmlKit.writeXMLConnection(writer, this.database.get()); XmlKit.writeXMLConnection(writer, this.database.get());
} }
writer.startTAG("Script").textNode(getScript()).end(); writer.startTAG("Script").textNode(getScript()).end();
writer.startTAG("ScriptAttr").attr("engineType", engineType.get()).end();
} }
private boolean isNotNullValue(String value) { private boolean isNotNullValue(String value) {
@ -137,6 +152,7 @@ public class RedisScriptTableData extends BaseTableData {
cloned.database = (Conf<Connection>) database.clone(); cloned.database = (Conf<Connection>) database.clone();
cloned.script = (Conf<String>) script.clone(); cloned.script = (Conf<String>) script.clone();
cloned.dbIndex = (Conf<OrderValue>) dbIndex.clone(); cloned.dbIndex = (Conf<OrderValue>) dbIndex.clone();
cloned.engineType = (Conf<Integer>) engineType.clone();
return cloned; return cloned;
} }
} }

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

@ -2,6 +2,7 @@ package com.fr.plugin.db.redis.core;
import com.fanruan.api.data.open.BaseDataModel; import com.fanruan.api.data.open.BaseDataModel;
import com.fr.plugin.db.redis.core.emb.Redis; import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.plugin.db.redis.core.script.EngineType;
import com.fr.plugin.db.redis.help.RedisClient; import com.fr.plugin.db.redis.help.RedisClient;
import com.fr.plugin.db.redis.help.RedisClientSelector; import com.fr.plugin.db.redis.help.RedisClientSelector;
import com.fr.plugin.db.redis.help.client.SimpleDataModel; import com.fr.plugin.db.redis.help.client.SimpleDataModel;
@ -17,14 +18,16 @@ import java.util.List;
public class RedisScriptTableDataModel extends BaseDataModel { public class RedisScriptTableDataModel extends BaseDataModel {
private RedisDatabaseConnection mc; private RedisDatabaseConnection mc;
private EngineType engineType;
private String script; private String script;
private int dbIndex; private int dbIndex;
private int rowCount; private int rowCount;
private List<List<Object>> data = new ArrayList<List<Object>>(); private List<List<Object>> data = new ArrayList<List<Object>>();
private String[] columnNames = null; private String[] columnNames = null;
public RedisScriptTableDataModel(RedisDatabaseConnection mc, int dbIndex, String script, int rowCount) { public RedisScriptTableDataModel(RedisDatabaseConnection mc, EngineType engineType, int dbIndex, String script, int rowCount) {
this.mc = mc; this.mc = mc;
this.engineType = engineType;
this.script = script; this.script = script;
this.dbIndex = dbIndex; this.dbIndex = dbIndex;
this.rowCount = rowCount; this.rowCount = rowCount;
@ -36,7 +39,7 @@ public class RedisScriptTableDataModel extends BaseDataModel {
} }
Redis redis = mc.createRedisClient(); Redis redis = mc.createRedisClient();
redis.getClient().select(dbIndex); redis.getClient().select(dbIndex);
RedisClient redisClient = RedisClientSelector.select(redis); RedisClient redisClient = RedisClientSelector.select(redis, engineType);
SimpleDataModel simple = redisClient.build(redis, script, rowCount); SimpleDataModel simple = redisClient.build(redis, script, rowCount);
if (simple != null) { if (simple != null) {
this.columnNames = simple.getColumnNames(); this.columnNames = simple.getColumnNames();

30
src/main/java/com/fr/plugin/db/redis/core/script/EngineType.java

@ -0,0 +1,30 @@
package com.fr.plugin.db.redis.core.script;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-18
*/
public enum EngineType {
V8(0), JAVA(1);
private int index;
EngineType(int index) {
this.index = index;
}
public int getType() {
return index;
}
public static EngineType parse(int type) {
for (EngineType engineType : values()) {
if (engineType.index == type) {
return engineType;
}
}
return V8;
}
}

16
src/main/java/com/fr/plugin/db/redis/help/RedisClient.java

@ -8,7 +8,7 @@ import com.fr.plugin.db.redis.help.client.SimpleDataModel;
* @version 10.0 * @version 10.0
* Created by richie on 2019-08-26 * Created by richie on 2019-08-26
*/ */
public interface RedisClient<A, O> { public interface RedisClient<A> {
SimpleDataModel build(Redis redis, String query, int limit); SimpleDataModel build(Redis redis, String query, int limit);
@ -19,23 +19,23 @@ public interface RedisClient<A, O> {
String hget(String key, String field); String hget(String key, String field);
@ScriptBridge @ScriptBridge
A hkeys(String key); String hkeys(String key);
@ScriptBridge @ScriptBridge
A hmget(String key, String... fields); String hmget(String key, String... fields);
@ScriptBridge @ScriptBridge
O hgetAll(String key); String hgetAll(String key);
@ScriptBridge @ScriptBridge
A keys(String pattern); String keys(String pattern);
@ScriptBridge @ScriptBridge
A lrange(String key, long start, long end); String lrange(String key, long start, long end);
@ScriptBridge @ScriptBridge
A mget(A keys); String mget(A keys);
@ScriptBridge @ScriptBridge
A smembers(String key); String smembers(String key);
} }

6
src/main/java/com/fr/plugin/db/redis/help/RedisClientSelector.java

@ -2,6 +2,7 @@ package com.fr.plugin.db.redis.help;
import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8;
import com.fr.plugin.db.redis.core.emb.Redis; import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.plugin.db.redis.core.script.EngineType;
import com.fr.plugin.db.redis.help.client.RedisNashornClient; import com.fr.plugin.db.redis.help.client.RedisNashornClient;
import com.fr.plugin.db.redis.help.client.RedisV8Client; import com.fr.plugin.db.redis.help.client.RedisV8Client;
@ -25,7 +26,10 @@ public class RedisClientSelector {
return true; return true;
} }
public static RedisClient select(Redis redis) { public static RedisClient select(Redis redis, EngineType engineType) {
if (engineType == EngineType.JAVA) {
return new RedisNashornClient(redis.getClient());
}
if (SUPPORT_J2V8) { if (SUPPORT_J2V8) {
return new RedisV8Client(redis.getClient()); return new RedisV8Client(redis.getClient());
} else { } else {

89
src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java

@ -1,18 +1,24 @@
package com.fr.plugin.db.redis.help.client; package com.fr.plugin.db.redis.help.client;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fr.json.JSON;
import com.fr.json.JSONFactory;
import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.accessor.EmbedRedis;
import com.fr.plugin.db.redis.help.ScriptBridge;
import com.fr.plugin.db.redis.help.RedisClient; import com.fr.plugin.db.redis.help.RedisClient;
import redis.clients.jedis.Jedis; import com.fr.plugin.db.redis.help.ScriptBridge;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
* Created by richie on 2019-08-26 * Created by richie on 2019-08-26
*/ */
public abstract class BaseRedisClient<A, O> implements RedisClient<A, O> { public abstract class BaseRedisClient<A> implements RedisClient<A> {
EmbedRedis jedis; EmbedRedis jedis;
@ -40,4 +46,79 @@ public abstract class BaseRedisClient<A, O> implements RedisClient<A, O> {
} }
} }
@Override
@ScriptBridge
public String hkeys(String key) {
long start = System.currentTimeMillis();
Set<String> set = jedis.keys(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return object2JSONString(set);
}
@Override
@ScriptBridge
public String hmget(String key, String... fields) {
long start = System.currentTimeMillis();
List<String> list = jedis.hmget(key, fields);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return object2JSONString(list);
}
@Override
@ScriptBridge
public String hgetAll(String key) {
long start = System.currentTimeMillis();
Map<String, String> map = jedis.hgetAll(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return object2JSONString(map);
}
@Override
@ScriptBridge
public String keys(String pattern) {
long start = System.currentTimeMillis();
Set<String> set = jedis.keys(pattern);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return object2JSONString(set);
}
@Override
@ScriptBridge
public String lrange(String key, long start, long end) {
long start0 = System.currentTimeMillis();
List<String> list = jedis.lrange(key, start, end);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start0);
return object2JSONString(list);
}
@Override
@ScriptBridge
public String smembers(String key) {
long start = System.currentTimeMillis();
Set<String> set = jedis.smembers(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return object2JSONString(set);
}
/**
* 将集合输出为JSON格式的字符串便于JS和Java互传数据
*
* @param collection 集合
* @return 字符串
*/
String object2JSONString(Collection<String> collection) {
return JSONFactory.createJSON(collection).toString();
}
/**
* 将集合输出为JSON格式的字符串便于JS和Java互传数据
*
* @param map 集合
* @return 字符串
*/
String object2JSONString(Map<String, String> map) {
Map<String, Object> newMap = new TreeMap<String, Object>();
newMap.putAll(map);
return JSONFactory.createJSON(JSON.OBJECT, newMap).toString();
}
} }

60
src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java

@ -23,7 +23,7 @@ import java.util.TreeMap;
* @version 10.0 * @version 10.0
* Created by richie on 2019-08-26 * Created by richie on 2019-08-26
*/ */
public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Object>> { public class RedisNashornClient extends BaseRedisClient<Object[]> {
private static final String PREPARE_SCRIPT = private static final String PREPARE_SCRIPT =
"function unique(array) {var res = [];for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {for (var j = 0, resLen = res.length; j < resLen; j++ ) {if (array[i] === res[j]) {break;}} if (j === resLen) {res.push(array[i])}} return res;}\n" + "function unique(array) {var res = [];for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {for (var j = 0, resLen = res.length; j < resLen; j++ ) {if (array[i] === res[j]) {break;}} if (j === resLen) {res.push(array[i])}} return res;}\n" +
@ -38,52 +38,7 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob
@Override @Override
@ScriptBridge @ScriptBridge
public Object[] hkeys(String key) { public String mget(Object[] keys) {
long start = System.currentTimeMillis();
Set<String> set = jedis.keys(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return set.toArray(new String[0]);
}
@Override
@ScriptBridge
public Object[] hmget(String key, String... fields) {
long start = System.currentTimeMillis();
List<String> list = jedis.hmget(key, fields);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return list.toArray(new String[0]);
}
@Override
@ScriptBridge
public Map<Object, Object> hgetAll(String key) {
long start = System.currentTimeMillis();
Map<String, String> map = jedis.hgetAll(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return new TreeMap<Object, Object>(map);
}
@Override
@ScriptBridge
public Object[] keys(String pattern) {
long start = System.currentTimeMillis();
Set<String> set = jedis.keys(pattern);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return set.toArray(new String[0]);
}
@Override
@ScriptBridge
public Object[] lrange(String key, long start, long end) {
long start0 = System.currentTimeMillis();
List<String> list = jedis.lrange(key, start, end);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start0);
return list.toArray(new String[0]);
}
@Override
@ScriptBridge
public Object[] mget(Object[] keys) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
int len = keys.length; int len = keys.length;
String[] parameters = new String[len]; String[] parameters = new String[len];
@ -92,16 +47,7 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob
} }
List<String> list = jedis.mget(parameters); List<String> list = jedis.mget(parameters);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start); LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return list.toArray(new String[0]); return object2JSONString(list);
}
@Override
@ScriptBridge
public Object[] smembers(String key) {
long start = System.currentTimeMillis();
Set<String> set = jedis.smembers(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return set.toArray(new String[0]);
} }
@Override @Override

63
src/main/java/com/fr/plugin/db/redis/help/client/RedisV8Client.java

@ -3,7 +3,6 @@ package com.fr.plugin.db.redis.help.client;
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.eclipsesource.v8.utils.V8ObjectUtils;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.accessor.EmbedRedis;
@ -14,15 +13,13 @@ import com.fr.plugin.db.redis.util.RedisUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
* Created by richie on 2019-03-18 * Created by richie on 2019-03-18
*/ */
public class RedisV8Client extends BaseRedisClient<V8Array, V8Object> { public class RedisV8Client extends BaseRedisClient<V8Array> {
private V8 v8; private V8 v8;
@ -33,52 +30,7 @@ public class RedisV8Client extends BaseRedisClient<V8Array, V8Object> {
@Override @Override
@ScriptBridge @ScriptBridge
public V8Array hkeys(String key) { public String mget(V8Array keys) {
long start = System.currentTimeMillis();
Set<String> set = jedis.hkeys(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return V8ObjectUtils.toV8Array(v8, new ArrayList<String>(set));
}
@Override
@ScriptBridge
public V8Array hmget(String key, String... fields) {
long start = System.currentTimeMillis();
List<String> list = jedis.hmget(key, fields);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return V8ObjectUtils.toV8Array(v8, list);
}
@Override
@ScriptBridge
public V8Object hgetAll(String key) {
long start = System.currentTimeMillis();
Map<String, String> map = jedis.hgetAll(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return V8ObjectUtils.toV8Object(v8, map);
}
@Override
@ScriptBridge
public V8Array keys(String pattern) {
long start = System.currentTimeMillis();
Set<String> set = jedis.keys(pattern);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return V8ObjectUtils.toV8Array(v8, new ArrayList<String>(set));
}
@Override
@ScriptBridge
public V8Array lrange(String key, long start, long end) {
long start0 = System.currentTimeMillis();
List<String> list = jedis.lrange(key, start, end);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start0);
return V8ObjectUtils.toV8Array(v8, list);
}
@Override
@ScriptBridge
public V8Array mget(V8Array keys) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
int len = keys.length(); int len = keys.length();
String[] parameters = new String[len]; String[] parameters = new String[len];
@ -88,16 +40,7 @@ public class RedisV8Client extends BaseRedisClient<V8Array, V8Object> {
List<String> list = jedis.mget(parameters); List<String> list = jedis.mget(parameters);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start); LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
keys.release(); keys.release();
return V8ObjectUtils.toV8Array(v8, list); return object2JSONString(list);
}
@Override
@ScriptBridge
public V8Array smembers(String key) {
long start = System.currentTimeMillis();
Set<String> set = jedis.smembers(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return V8ObjectUtils.toV8Array(v8, new ArrayList<String>(set));
} }
@Override @Override

48
src/main/java/com/fr/plugin/db/redis/ui/RedisScriptPane.java

@ -1,17 +1,27 @@
package com.fr.plugin.db.redis.ui; package com.fr.plugin.db.redis.ui;
import com.fanruan.api.design.DesignKit; import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UIDictionaryComboBox;
import com.fanruan.api.design.ui.component.UILabel; import com.fanruan.api.design.ui.component.UILabel;
import com.fanruan.api.design.ui.component.code.SyntaxConstants; import com.fanruan.api.design.ui.component.code.SyntaxConstants;
import com.fanruan.api.design.ui.component.code.UISyntaxTextArea; import com.fanruan.api.design.ui.component.code.UISyntaxTextArea;
import com.fanruan.api.design.ui.container.BasicPane; import com.fanruan.api.design.ui.container.BasicPane;
import com.fanruan.api.design.ui.editor.ValueEditorPane; import com.fanruan.api.design.ui.editor.ValueEditorPane;
import com.fanruan.api.design.ui.layout.TableLayoutKit; import com.fanruan.api.design.ui.layout.TableLayoutKit;
import com.fanruan.api.design.util.GUICoreKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.IOKit;
import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.plugin.db.redis.core.script.EngineType;
import com.fr.plugin.db.redis.ui.value.IndexValuePaneFactory; import com.fr.plugin.db.redis.ui.value.IndexValuePaneFactory;
import com.fr.plugin.db.redis.util.RedisDesignUtils; import com.fr.plugin.db.redis.util.RedisDesignUtils;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
/** /**
* @author richie * @author richie
@ -21,6 +31,7 @@ import java.awt.*;
public class RedisScriptPane extends BasicPane { public class RedisScriptPane extends BasicPane {
private ValueEditorPane dbIndexEditor; private ValueEditorPane dbIndexEditor;
private UIDictionaryComboBox<EngineType> engineTypeComboBox;
private UISyntaxTextArea scriptTextPane; private UISyntaxTextArea scriptTextPane;
public RedisScriptPane() { public RedisScriptPane() {
@ -31,16 +42,41 @@ public class RedisScriptPane extends BasicPane {
dbIndexEditor = IndexValuePaneFactory.createValueEditorPane(); dbIndexEditor = IndexValuePaneFactory.createValueEditorPane();
engineTypeComboBox = new UIDictionaryComboBox<EngineType>(
new EngineType[]{
EngineType.V8, EngineType.JAVA
},
new String[]{
DesignKit.i18nText("Plugin-Redis_Script_Engine_Type_V8"),
DesignKit.i18nText("Plugin-Redis_Script_Engine_Type_Default")
}
);
UIButton helpButton = new UIButton();
helpButton.setIcon(IOKit.readIcon("/com/fr/plugin/db/redis/images/help.png"));
helpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Desktop.getDesktop().browse(URI.create("https://help.finereport.com/doc-view-1957.html"));
} catch (IOException ex) {
LogKit.error(ex.getMessage(), ex);
}
}
});
Component[][] coms = new Component[][]{ Component[][] coms = new Component[][]{
{new UILabel(DesignKit.i18nText("Plugin-Redis_DB_Index") + ":"), dbIndexEditor}, {new UILabel(DesignKit.i18nText("Plugin-Redis_DB_Index") + ":"), dbIndexEditor},
{new UILabel(DesignKit.i18nText("Plugin-Redis_Script_Engine_Type") + ":"),
GUICoreKit.createBorderLayoutPane(engineTypeComboBox, BorderLayout.CENTER, helpButton, BorderLayout.EAST)},
{new UILabel(DesignKit.i18nText("Plugin-Redis_Script_Query_Text") + ":"), {new UILabel(DesignKit.i18nText("Plugin-Redis_Script_Query_Text") + ":"),
RedisDesignUtils.createConditionTextPane(scriptTextPane, SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, 350)}, RedisDesignUtils.createConditionTextPane(scriptTextPane, SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, 300)},
}; };
double p = TableLayoutKit.PREFERRED; double p = TableLayoutKit.PREFERRED;
double f = TableLayoutKit.FILL; double f = TableLayoutKit.FILL;
double[] rowSize = {p, p, p}; double[] rowSize = {p, p, p, p};
double[] columnSize = {p, f}; double[] columnSize = {p, f};
add(TableLayoutKit.createTableLayoutPane(coms, rowSize, columnSize)); add(TableLayoutKit.createTableLayoutPane(coms, rowSize, columnSize));
@ -60,6 +96,14 @@ public class RedisScriptPane extends BasicPane {
dbIndexEditor.populate(orderValue); dbIndexEditor.populate(orderValue);
} }
public EngineType getEngineType() {
return engineTypeComboBox.getSelectedItem();
}
public void setEngineType(EngineType engineType) {
this.engineTypeComboBox.setSelectedItem(engineType);
}
public String getScript() { public String getScript() {
return scriptTextPane.getText(); return scriptTextPane.getText();
} }

6
src/main/java/com/fr/plugin/db/redis/ui/RedisScriptTableDataPane.java

@ -33,7 +33,7 @@ public class RedisScriptTableDataPane extends RedisBaseTableDataPane<RedisScript
@Override @Override
protected String[] paramTexts() { protected String[] paramTexts() {
return new String[] {scriptPane.getScript()}; return new String[]{scriptPane.getScript()};
} }
@Override @Override
@ -55,6 +55,8 @@ public class RedisScriptTableDataPane extends RedisBaseTableDataPane<RedisScript
scriptPane.setScript(tableData.getScript()); scriptPane.setScript(tableData.getScript());
scriptPane.setOrderValue(tableData.getOrderValue()); scriptPane.setOrderValue(tableData.getOrderValue());
scriptPane.setEngineType(tableData.getEngineType());
} }
@Override @Override
@ -71,6 +73,8 @@ public class RedisScriptTableDataPane extends RedisBaseTableDataPane<RedisScript
tableData.setScript(scriptPane.getScript()); tableData.setScript(scriptPane.getScript());
tableData.setOrderValue(scriptPane.getOrderValue()); tableData.setOrderValue(scriptPane.getOrderValue());
tableData.setEngineType(scriptPane.getEngineType());
return tableData; return tableData;
} }
} }

BIN
src/main/resources/com/fr/plugin/db/redis/images/help.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 B

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

@ -35,3 +35,6 @@ Plugin-Redis_Pool_Timeout=Timeout
Plugin-Redis_Proxy_Description=Only Support SSH Protocol Plugin-Redis_Proxy_Description=Only Support SSH Protocol
Plugin-Redis_Connect_Cluster_Description=Connect Cluster Description Plugin-Redis_Connect_Cluster_Description=Connect Cluster Description
Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separator. Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separator.
Plugin-Redis_Script_Engine_Type=Script Engine Type
Plugin-Redis_Script_Engine_Type_Default=Default
Plugin-Redis_Script_Engine_Type_V8=V8

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

@ -35,3 +35,6 @@ Plugin-Redis_Pool_Timeout=Timeout
Plugin-Redis_Proxy_Description=Only Support SSH Protocol Plugin-Redis_Proxy_Description=Only Support SSH Protocol
Plugin-Redis_Connect_Cluster_Description=Connect Cluster Description Plugin-Redis_Connect_Cluster_Description=Connect Cluster Description
Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separator. Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separator.
Plugin-Redis_Script_Engine_Type=Script Engine Type
Plugin-Redis_Script_Engine_Type_Default=Default
Plugin-Redis_Script_Engine_Type_V8=V8

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

@ -36,3 +36,6 @@ Plugin-Redis_Pool_Timeout=\u8D85\u65F6\u65F6\u95F4
Plugin-Redis_Proxy_Description=\u8DF3\u677F\u670D\u52A1\u5668\u8FDE\u63A5\u4EC5\u652F\u6301ssh\u534F\u8BAE\uFF08\u6CE8\u610F\uFF1A\u542F\u7528\u8DF3\u677F\u670D\u52A1\u5668\u5C06\u65E0\u6CD5\u4F7F\u7528\u8FDE\u63A5\u6C60\uFF09 Plugin-Redis_Proxy_Description=\u8DF3\u677F\u670D\u52A1\u5668\u8FDE\u63A5\u4EC5\u652F\u6301ssh\u534F\u8BAE\uFF08\u6CE8\u610F\uFF1A\u542F\u7528\u8DF3\u677F\u670D\u52A1\u5668\u5C06\u65E0\u6CD5\u4F7F\u7528\u8FDE\u63A5\u6C60\uFF09
Plugin-Redis_Connect_Cluster_Description=\u8FDE\u63A5\u96C6\u7FA4\u914D\u7F6E\u8BF4\u660E Plugin-Redis_Connect_Cluster_Description=\u8FDE\u63A5\u96C6\u7FA4\u914D\u7F6E\u8BF4\u660E
Plugin-Redis_Cluster_Config_Description=1\u3001\u4F7F\u7528\u9017\u53F7\u5206\u5272\u96C6\u7FA4\u4E2D\u7684\u591A\u4E2A\u6570\u636E\u5E93\u5730\u5740\u548C\u7AEF\u53E3\uFF0C\u5FC5\u987B\u8981\u6C42\u5730\u5740\u548C\u7AEF\u53E3\u6570\u91CF\u4E00\u81F4\uFF1B\n2\u3001\u6240\u6709redis\u8282\u70B9\u7684\u5BC6\u7801\u5FC5\u987B\u76F8\u540C;\n3\u3001\u8FDE\u63A5\u96C6\u7FA4\u7684\u65F6\u5019\u65E0\u6CD5\u4F7F\u7528\u8DF3\u677F\u673A\u3002 Plugin-Redis_Cluster_Config_Description=1\u3001\u4F7F\u7528\u9017\u53F7\u5206\u5272\u96C6\u7FA4\u4E2D\u7684\u591A\u4E2A\u6570\u636E\u5E93\u5730\u5740\u548C\u7AEF\u53E3\uFF0C\u5FC5\u987B\u8981\u6C42\u5730\u5740\u548C\u7AEF\u53E3\u6570\u91CF\u4E00\u81F4\uFF1B\n2\u3001\u6240\u6709redis\u8282\u70B9\u7684\u5BC6\u7801\u5FC5\u987B\u76F8\u540C;\n3\u3001\u8FDE\u63A5\u96C6\u7FA4\u7684\u65F6\u5019\u65E0\u6CD5\u4F7F\u7528\u8DF3\u677F\u673A\u3002
Plugin-Redis_Script_Engine_Type=\u811A\u672C\u5F15\u64CE
Plugin-Redis_Script_Engine_Type_Default=\u9ED8\u8BA4
Plugin-Redis_Script_Engine_Type_V8=V8\u9AD8\u901F\u5F15\u64CE
Loading…
Cancel
Save