Browse Source

插件适配

paid
richie 5 years ago
parent
commit
5781911058
  1. 7
      pom.xml
  2. 4
      src/main/java/com/fr/plugin/db/redis/RedisConnectionImpl.java
  3. 7
      src/main/java/com/fr/plugin/db/redis/core/DataWrapper.java
  4. 16
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  5. 8
      src/main/java/com/fr/plugin/db/redis/core/RedisPool.java
  6. 19
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableData.java
  7. 22
      src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java
  8. 14
      src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java
  9. 3
      src/main/java/com/fr/plugin/db/redis/core/order/OrderValue.java
  10. 15
      src/main/java/com/fr/plugin/db/redis/core/order/impl/FormulaOrderValue.java
  11. 4
      src/main/java/com/fr/plugin/db/redis/core/order/impl/NumberOrderValue.java
  12. 3
      src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionPoolConfig.java
  13. 3
      src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionProxyConfig.java
  14. 8
      src/main/java/com/fr/plugin/db/redis/core/visit/AbstractVisitor.java
  15. 8
      src/main/java/com/fr/plugin/db/redis/core/visit/Visitor.java
  16. 17
      src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java
  17. 5
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java
  18. 3
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java
  19. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java
  20. 3
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java
  21. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java
  22. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java
  23. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java
  24. 8
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java
  25. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java
  26. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java
  27. 3
      src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java
  28. 8
      src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java

7
pom.xml

@ -27,6 +27,13 @@
<artifactId>designer-base</artifactId> <artifactId>designer-base</artifactId>
<version>10.0</version> <version>10.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.fanruan.api</groupId>
<artifactId>finekit</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/finekit-10.0-20190830.jar.jar</systemPath>
</dependency>
</dependencies> </dependencies>
<build> <build>
<!---如果要更改调试插件,改这里的配置就可以了--> <!---如果要更改调试插件,改这里的配置就可以了-->

4
src/main/java/com/fr/plugin/db/redis/RedisConnectionImpl.java

@ -1,12 +1,12 @@
package com.fr.plugin.db.redis; package com.fr.plugin.db.redis;
import com.fr.data.impl.Connection;
import com.fanruan.api.design.ui.container.BasicBeanPane; import com.fanruan.api.design.ui.container.BasicBeanPane;
import com.fr.data.impl.Connection;
import com.fr.design.fun.impl.AbstractConnectionProvider; import com.fr.design.fun.impl.AbstractConnectionProvider;
import com.fr.plugin.db.redis.core.RedisDatabaseConnection; import com.fr.plugin.db.redis.core.RedisDatabaseConnection;
import com.fr.plugin.db.redis.ui.RedisConnectionPane; import com.fr.plugin.db.redis.ui.RedisConnectionPane;
public class RedisConnectionImpl extends AbstractConnectionProvider { public class RedisConnectionImpl extends AbstractConnectionProvider {
@Override @Override
public int currentAPILevel() { public int currentAPILevel() {

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

@ -1,12 +1,11 @@
package com.fr.plugin.db.redis.core; package com.fr.plugin.db.redis.core;
import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.IOKit; import com.fanruan.api.runtime.EnvKit;
import com.fanruan.api.script.ScriptKit; import com.fanruan.api.script.ScriptKit;
import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.util.IOKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fr.workspace.WorkContext;
import com.fanruan.api.runtime.EnvKit;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptException; import javax.script.ScriptException;

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

@ -1,22 +1,18 @@
package com.fr.plugin.db.redis.core; package com.fr.plugin.db.redis.core;
import cpm.fanruan.api.conf.HolderKit; import com.fanruan.api.conf.HolderKit;
import com.fanruan.api.conf.impl.ColConf;
import com.fr.data.impl.AbstractDatabaseConnection;
import com.fr.data.impl.Connection;
import com.fanruan.api.i18n.I18nKit; import com.fanruan.api.i18n.I18nKit;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fanruan.api.security.SecurityKit; import com.fanruan.api.security.SecurityKit;
import com.fanruan.api.util.ArrayKit; import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.TypeKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fanruan.api.util.TypeKit;
import com.fr.config.holder.Conf;
import com.fr.data.impl.AbstractDatabaseConnection;
import com.fr.data.impl.Connection;
import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.third.redis.clients.jedis.Jedis;
import com.fr.config.holder.Conf;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;

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

@ -1,8 +1,9 @@
package com.fr.plugin.db.redis.core; package com.fr.plugin.db.redis.core;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.config.Configuration; import com.fr.config.Configuration;
import com.fr.config.holder.ConfigChangeListener; import com.fr.config.holder.ConfigChangeListener;
import com.fanruan.api.log.LogKit;
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.emb.impl.ProxyRedis; 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.emb.impl.SimpleRedis;
@ -11,10 +12,9 @@ import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig;
import com.fr.ssh.jsch.JSch; import com.fr.ssh.jsch.JSch;
import com.fr.ssh.jsch.JSchException; import com.fr.ssh.jsch.JSchException;
import com.fr.ssh.jsch.Session; import com.fr.ssh.jsch.Session;
import com.fanruan.api.util.StringKit;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import com.fanruan.api.redis.pool.JedisPool; import com.fr.third.redis.clients.jedis.JedisPool;
import com.fanruan.api.redis.pool.JedisPoolConfig; import com.fr.third.redis.clients.jedis.JedisPoolConfig;
import com.fr.transaction.ValidateProxy; import com.fr.transaction.ValidateProxy;
import java.util.Map; import java.util.Map;

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

@ -1,28 +1,25 @@
package com.fr.plugin.db.redis.core; package com.fr.plugin.db.redis.core;
import com.fr.stable.ParameterProvider;
import com.fr.base.TableData;
import com.fanruan.api.conf.HolderKit; import com.fanruan.api.conf.HolderKit;
import com.fanruan.api.data.ConnectionKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fanruan.api.xml.XmlKit;
import com.fr.base.TableData;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.XmlHolders; import com.fr.config.holder.factory.XmlHolders;
import com.fr.data.AbstractParameterTableData; import com.fr.data.AbstractParameterTableData;
import com.fanruan.api.xml.XmlKit;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fanruan.api.database.nameDatabase.NameReference;
import com.fanruan.api.data.ConnectionKit;
import com.fr.general.data.DataModel; import com.fr.general.data.DataModel;
import com.fanruan.api.xml.XmlKit;
import com.fr.intelli.record.Focus; import com.fr.intelli.record.Focus;
import com.fanruan.api.log.LogKit;
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.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;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fanruan.api.util.StringKit;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.config.holder.Conf;
/** /**
* @author richie * @author richie
@ -75,7 +72,7 @@ public class RedisScriptTableData extends AbstractParameterTableData {
@Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_Script_Table_Data") @Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_Script_Table_Data")
public DataModel createDataModel(Calculator calculator, int rowCount) { public DataModel createDataModel(Calculator calculator, int rowCount) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Parameter[] ps = Parameter.providers2Parameter(getParameters(calculator)); ParameterProvider[] ps = getParameters(calculator);
Connection connection = database.get(); Connection connection = database.get();
if (connection instanceof NameReference) { if (connection instanceof NameReference) {
String name = ((NameReference) connection).getName(); String name = ((NameReference) connection).getName();
@ -86,7 +83,7 @@ public class RedisScriptTableData extends AbstractParameterTableData {
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);
FineLoggerFactory.getLogger().info("Build data model spend time {} ms.", System.currentTimeMillis() - start); LogKit.info("Build data model spend time {} ms.", System.currentTimeMillis() - start);
return model; return model;
} }
} }

22
src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java

@ -1,34 +1,26 @@
package com.fr.plugin.db.redis.core; package com.fr.plugin.db.redis.core;
import com.fr.stable.ParameterProvider;
import com.fr.base.TableData;
import com.fanruan.api.conf.HolderKit; import com.fanruan.api.conf.HolderKit;
import com.fanruan.api.data.ConnectionKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fanruan.api.xml.XmlKit;
import com.fr.base.TableData;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.XmlHolders; import com.fr.config.holder.factory.XmlHolders;
import com.fr.data.AbstractParameterTableData; import com.fr.data.AbstractParameterTableData;
import com.fanruan.api.xml.XmlKit;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fanruan.api.database.nameDatabase.NameReference;
import com.fanruan.api.data.ConnectionKit;
import com.fr.general.data.DataModel; import com.fr.general.data.DataModel;
import com.fanruan.api.xml.XmlKit;
import com.fr.intelli.record.Focus; import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original; import com.fr.intelli.record.Original;
import com.fanruan.api.log.LogKit;
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.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;
import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.StringKit;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.config.holder.Conf;
import java.util.HashMap;
import java.util.Map;
@EnableMetrics @EnableMetrics
@ -85,7 +77,7 @@ public class RedisTableData extends AbstractParameterTableData {
@Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_DB", source = Original.PLUGIN) @Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_DB", source = Original.PLUGIN)
public DataModel createDataModel(Calculator calculator, int rowCount) { public DataModel createDataModel(Calculator calculator, int rowCount) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Parameter[] ps = Parameter.providers2Parameter(getParameters(calculator)); ParameterProvider[] ps = getParameters(calculator);
Connection connection = database.get(); Connection connection = database.get();
if (connection instanceof NameReference) { if (connection instanceof NameReference) {
String name = ((NameReference) connection).getName(); String name = ((NameReference) connection).getName();

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

@ -1,15 +1,13 @@
package com.fr.plugin.db.redis.core; package com.fr.plugin.db.redis.core;
import com.fr.stable.ParameterProvider;
import com.fr.data.AbstractDataModel;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fanruan.api.runtime.PluginKit; import com.fanruan.api.runtime.PluginKit;
import com.fanruan.api.util.StringKit;
import com.fr.data.AbstractDataModel;
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.visit.VisitorFactory; import com.fr.plugin.db.redis.core.visit.VisitorFactory;
import com.fr.plugin.db.redis.util.RedisUtils; import com.fr.stable.ParameterProvider;
import com.fr.script.Calculator; import com.fr.stable.script.CalculatorProvider;
import com.fanruan.api.util.StringKit;
import com.fr.third.redis.clients.jedis.Jedis;
import java.util.List; import java.util.List;
@ -17,7 +15,7 @@ public class RedisTableDataModel extends AbstractDataModel {
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(CalculatorProvider calculator, ParameterProvider[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) {
if (PluginKit.isCurrentPluginAvailable()) { if (PluginKit.isCurrentPluginAvailable()) {
initRedisData(calculator, ps, mc, dbIndex, query, script, rowCount); initRedisData(calculator, ps, mc, dbIndex, query, script, rowCount);
} else { } else {
@ -25,7 +23,7 @@ public class RedisTableDataModel extends AbstractDataModel {
} }
} }
private synchronized void initRedisData(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) { private synchronized void initRedisData(CalculatorProvider calculator, ParameterProvider[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) {
if (StringKit.isEmpty(query)) { if (StringKit.isEmpty(query)) {
return; return;
} }

3
src/main/java/com/fr/plugin/db/redis/core/order/OrderValue.java

@ -1,6 +1,5 @@
package com.fr.plugin.db.redis.core.order; package com.fr.plugin.db.redis.core.order;
import com.fr.stable.ParameterProvider;
import com.fanruan.api.conf.BaseUniqueKey; import com.fanruan.api.conf.BaseUniqueKey;
import com.fanruan.api.util.GeneralKit; import com.fanruan.api.util.GeneralKit;
import com.fr.script.Calculator; import com.fr.script.Calculator;
@ -17,7 +16,7 @@ public abstract class OrderValue extends BaseUniqueKey implements XMLable {
public abstract Object getValue(); public abstract Object getValue();
public abstract int toIndex(Calculator cal, Parameter[] ps); public abstract int toIndex(Calculator cal, ParameterProvider[] ps);
public ParameterProvider[] analyze4Parameters() { public ParameterProvider[] analyze4Parameters() {
return new ParameterProvider[0]; return new ParameterProvider[0];

15
src/main/java/com/fr/plugin/db/redis/core/order/impl/FormulaOrderValue.java

@ -1,17 +1,14 @@
package com.fr.plugin.db.redis.core.order.impl; package com.fr.plugin.db.redis.core.order.impl;
import com.fr.base.BaseFormula;
import com.fanruan.api.cal.FormulaKit; import com.fanruan.api.cal.FormulaKit;
import com.fr.stable.ParameterProvider;
import com.fanruan.api.cal.ParameterKit; import com.fanruan.api.cal.ParameterKit;
import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.BaseFormula;
import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fanruan.api.util.StringKit;
import com.fanruan.api.cal.ParameterKit;
import com.fanruan.api.util.err.UtilEvalError;
import com.fr.stable.script.NameSpace; import com.fr.stable.script.NameSpace;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
@ -37,12 +34,12 @@ public class FormulaOrderValue extends OrderValue {
} }
@Override @Override
public int toIndex(Calculator cal, Parameter[] ps) { public int toIndex(Calculator cal, ParameterProvider[] ps) {
NameSpace nameSpace = ParameterKit.createParameterProvider(ps); NameSpace nameSpace = ParameterKit.createParameterMapNameSpace(ps);
cal.pushNameSpace(nameSpace); cal.pushNameSpace(nameSpace);
try { try {
return GeneralKit.objectToNumber(formula.eval(cal)).intValue(); return GeneralKit.objectToNumber(formula.eval(cal)).intValue();
} catch (UtilEvalError u) { } catch (Exception u) {
LogKit.error(u.getMessage(), u); LogKit.error(u.getMessage(), u);
} finally { } finally {
cal.removeNameSpace(nameSpace); cal.removeNameSpace(nameSpace);

4
src/main/java/com/fr/plugin/db/redis/core/order/impl/NumberOrderValue.java

@ -1,8 +1,8 @@
package com.fr.plugin.db.redis.core.order.impl; package com.fr.plugin.db.redis.core.order.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
public class NumberOrderValue extends OrderValue { public class NumberOrderValue extends OrderValue {
@ -24,7 +24,7 @@ public class NumberOrderValue extends OrderValue {
} }
@Override @Override
public int toIndex(Calculator cal, Parameter[] ps) { public int toIndex(Calculator cal, ParameterProvider[] ps) {
return getValue(); return getValue();
} }

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

@ -1,6 +1,5 @@
package com.fr.plugin.db.redis.core.pool; package com.fr.plugin.db.redis.core.pool;
import com.fr.config.ConfigContext;
import com.fanruan.api.conf.BaseConfiguration; import com.fanruan.api.conf.BaseConfiguration;
import com.fanruan.api.conf.HolderKit; import com.fanruan.api.conf.HolderKit;
import com.fr.config.holder.Conf; import com.fr.config.holder.Conf;
@ -17,7 +16,7 @@ public class RedisConnectionPoolConfig extends BaseConfiguration {
public static RedisConnectionPoolConfig getInstance() { public static RedisConnectionPoolConfig getInstance() {
if (instance == null) { if (instance == null) {
instance = ConfigContext.getConfigInstance(RedisConnectionPoolConfig.class); instance = getConfigInstance(RedisConnectionPoolConfig.class);
} }
return instance; return instance;
} }

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

@ -1,6 +1,5 @@
package com.fr.plugin.db.redis.core.pool; package com.fr.plugin.db.redis.core.pool;
import com.fr.config.ConfigContext;
import com.fanruan.api.conf.BaseConfiguration; import com.fanruan.api.conf.BaseConfiguration;
import com.fanruan.api.conf.HolderKit; import com.fanruan.api.conf.HolderKit;
import com.fanruan.api.security.SecurityKit; import com.fanruan.api.security.SecurityKit;
@ -18,7 +17,7 @@ public class RedisConnectionProxyConfig extends BaseConfiguration {
public static RedisConnectionProxyConfig getInstance() { public static RedisConnectionProxyConfig getInstance() {
if (instance == null) { if (instance == null) {
instance = ConfigContext.getConfigInstance(RedisConnectionProxyConfig.class); instance = getConfigInstance(RedisConnectionProxyConfig.class);
} }
return instance; return instance;
} }

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

@ -1,10 +1,10 @@
package com.fr.plugin.db.redis.core.visit; package com.fr.plugin.db.redis.core.visit;
import com.fr.stable.ParameterProvider; import com.fanruan.api.util.StringKit;
import com.fr.plugin.db.redis.core.DataWrapper; import com.fr.plugin.db.redis.core.DataWrapper;
import com.fr.plugin.db.redis.core.RedisConstants; import com.fr.plugin.db.redis.core.RedisConstants;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fanruan.api.util.StringKit; import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
/** /**
@ -13,7 +13,7 @@ import com.fr.third.redis.clients.jedis.Jedis;
public abstract class AbstractVisitor<T> implements Visitor<T> { public abstract class AbstractVisitor<T> implements Visitor<T> {
@Override @Override
public DataWrapper<T> buildData(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public DataWrapper<T> buildData(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
return DataWrapper.create(getContent(calculator, ps, client, query, rowCount), RedisConstants.DEFAULT_COLUMN_NAMES); return DataWrapper.create(getContent(calculator, ps, client, query, rowCount), RedisConstants.DEFAULT_COLUMN_NAMES);
} }

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

@ -1,8 +1,8 @@
package com.fr.plugin.db.redis.core.visit; package com.fr.plugin.db.redis.core.visit;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.DataWrapper; import com.fr.plugin.db.redis.core.DataWrapper;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.List; import java.util.List;
@ -14,9 +14,9 @@ public interface Visitor<T> {
String TOKEN_SPACE = "\\s+"; String TOKEN_SPACE = "\\s+";
List<List<T>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception; List<List<T>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception;
DataWrapper<T> buildData(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception; DataWrapper<T> buildData(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception;
boolean match(String query); boolean match(String query);

17
src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java

@ -1,9 +1,18 @@
package com.fr.plugin.db.redis.core.visit; package com.fr.plugin.db.redis.core.visit;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.DataWrapper; import com.fr.plugin.db.redis.core.DataWrapper;
import com.fr.plugin.db.redis.core.visit.impl.*; import com.fr.plugin.db.redis.core.visit.impl.GetVisitor;
import com.fr.script.Calculator; import com.fr.plugin.db.redis.core.visit.impl.HashGetVisitor;
import com.fr.plugin.db.redis.core.visit.impl.HashKeysVisitor;
import com.fr.plugin.db.redis.core.visit.impl.HashMGetVisitor;
import com.fr.plugin.db.redis.core.visit.impl.HashVisitor;
import com.fr.plugin.db.redis.core.visit.impl.KeysVisitor;
import com.fr.plugin.db.redis.core.visit.impl.ListVisitor;
import com.fr.plugin.db.redis.core.visit.impl.MGetVisitor;
import com.fr.plugin.db.redis.core.visit.impl.SetVisitor;
import com.fr.plugin.db.redis.core.visit.impl.ZRangeVisitor;
import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -29,7 +38,7 @@ public class VisitorFactory {
visitors.add(new KeysVisitor()); visitors.add(new KeysVisitor());
} }
public static <T> DataWrapper<T> getKeyValueResult(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public static <T> DataWrapper<T> getKeyValueResult(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
Visitor visitor = getMatchedVisitor(query); Visitor visitor = getMatchedVisitor(query);
if (visitor == null) { if (visitor == null) {
return DataWrapper.EMPTY; return DataWrapper.EMPTY;

5
src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java

@ -1,8 +1,9 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,7 +11,7 @@ import java.util.List;
public class GetVisitor extends AbstractVisitor<String> { public class GetVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 2) { if (arr.length < 2) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

3
src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java

@ -3,6 +3,7 @@ package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,7 +11,7 @@ import java.util.List;
public class HashGetVisitor extends AbstractVisitor <String>{ public class HashGetVisitor extends AbstractVisitor <String>{
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 3) { if (arr.length < 3) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

6
src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java

@ -1,8 +1,8 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -11,7 +11,7 @@ import java.util.Set;
public class HashKeysVisitor extends AbstractVisitor<String> { public class HashKeysVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 2) { if (arr.length < 2) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

3
src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java

@ -3,6 +3,7 @@ package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,7 +11,7 @@ import java.util.List;
public class HashMGetVisitor extends AbstractVisitor<String>{ public class HashMGetVisitor extends AbstractVisitor<String>{
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 3) { if (arr.length < 3) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

6
src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java

@ -1,8 +1,8 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,7 +14,7 @@ import java.util.Map;
*/ */
public class HashVisitor extends AbstractVisitor<String> { public class HashVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 2) { if (arr.length < 2) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

6
src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java

@ -1,8 +1,8 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -11,7 +11,7 @@ import java.util.Set;
public class KeysVisitor extends AbstractVisitor<String> { public class KeysVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 2) { if (arr.length < 2) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

6
src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java

@ -1,9 +1,9 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,7 +14,7 @@ import java.util.List;
*/ */
public class ListVisitor extends AbstractVisitor<String> { public class ListVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 4) { if (arr.length < 4) {

8
src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java

@ -1,9 +1,9 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator;
import com.fanruan.api.util.ArrayKit; import com.fanruan.api.util.ArrayKit;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,7 +14,7 @@ import java.util.List;
*/ */
public class MGetVisitor extends AbstractVisitor<String> { public class MGetVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 2) { if (arr.length < 2) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

6
src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java

@ -1,8 +1,8 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.util.ArrayList; import java.util.ArrayList;
@ -15,7 +15,7 @@ import java.util.Set;
public class SetVisitor extends AbstractVisitor<String> { public class SetVisitor extends AbstractVisitor<String> {
@Override @Override
public List<List<String>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 2) { if (arr.length < 2) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

6
src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java

@ -1,9 +1,9 @@
package com.fr.plugin.db.redis.core.visit.impl; package com.fr.plugin.db.redis.core.visit.impl;
import com.fr.stable.ParameterProvider;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.plugin.db.redis.core.visit.AbstractVisitor;
import com.fr.script.Calculator; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.CalculatorProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import com.fr.third.redis.clients.jedis.Tuple; import com.fr.third.redis.clients.jedis.Tuple;
@ -16,7 +16,7 @@ import java.util.Set;
*/ */
public class ZRangeVisitor extends AbstractVisitor<Object> { public class ZRangeVisitor extends AbstractVisitor<Object> {
@Override @Override
public List<List<Object>> getContent(Calculator calculator, Parameter[] ps, Jedis client, String query, int rowCount) throws Exception { public List<List<Object>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE); String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 4) { if (arr.length < 4) {
throw new IllegalArgumentException("Illegal query:" + query); throw new IllegalArgumentException("Illegal query:" + query);

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

@ -1,7 +1,7 @@
package com.fr.plugin.db.redis.help.client; package com.fr.plugin.db.redis.help.client;
import com.fr.base.TableData;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fr.base.TableData;
import com.fr.plugin.db.redis.core.emb.Redis; import com.fr.plugin.db.redis.core.emb.Redis;
import com.fr.plugin.db.redis.help.Console; import com.fr.plugin.db.redis.help.Console;
import com.fr.plugin.db.redis.help.ScriptBridge; import com.fr.plugin.db.redis.help.ScriptBridge;
@ -11,7 +11,6 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

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

@ -1,10 +1,10 @@
package com.fr.plugin.db.redis.util; package com.fr.plugin.db.redis.util;
import com.eclipsesource.v8.V8Object; import com.eclipsesource.v8.V8Object;
import com.fr.stable.ParameterProvider; import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.RenderKit; import com.fanruan.api.util.RenderKit;
import com.fr.plugin.db.redis.help.ScriptBridge; import com.fr.plugin.db.redis.help.ScriptBridge;
import com.fanruan.api.util.ArrayKit; import com.fr.stable.ParameterProvider;
import com.fr.third.redis.clients.jedis.Jedis; import com.fr.third.redis.clients.jedis.Jedis;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -26,12 +26,12 @@ public class RedisUtils {
jedis.close(); jedis.close();
} }
public static String calculateQuery(String query, Parameter[] ps) { public static String calculateQuery(String query, ParameterProvider[] ps) {
if (ArrayKit.isEmpty(ps)) { if (ArrayKit.isEmpty(ps)) {
return query; return query;
} }
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
for (Parameter p : ps) { for (ParameterProvider p : ps) {
map.put(p.getName(), p.getValue()); map.put(p.getName(), p.getValue());
} }
try { try {

Loading…
Cancel
Save