Browse Source

Merge branch 'refactor' of Elijah/demo-tabledata-redis into refactor

paid
richie 5 years ago committed by Gogs
parent
commit
a6e1206d96
  1. 6
      plugin.xml
  2. 13
      src/main/java/com/fr/plugin/db/redis/RedisConnectionComponent.java
  3. 105
      src/main/java/com/fr/plugin/db/redis/RedisUniversalConnectionImpl.java
  4. 2
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  5. 2
      src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionPoolConfig.java
  6. 2
      src/main/java/com/fr/plugin/db/redis/core/pool/RedisConnectionProxyConfig.java
  7. BIN
      src/main/resources/com/fr/plugin/db/redis/web/demo-tabledate-redis-web.zip
  8. 1
      src/main/resources/com/fr/plugin/db/redis/web/redis.js

6
plugin.xml

@ -3,12 +3,13 @@
<id>com.fr.solution.plugin.db.redis.v10</id>
<name><![CDATA[Redis数据集]]></name>
<active>yes</active>
<version>6.2</version>
<version>6.3</version>
<env-version>10.0</env-version>
<jartime>2018-11-29</jartime>
<vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[
[2019-09-03]适配新数据连接接口。<br/>
[2019-08-26]给console增加一个engine()函数,判断使用的脚本引擎名字。<br/>
[2019-08-26]不支持V8引擎的机器上使用JDK内置的脚本引擎(仅支持ES5语法)。<br/>
[2019-03-21]现在可以通过跳板服务连接redis。<br/>
@ -33,6 +34,9 @@
<TableDataDefineProvider class="com.fr.plugin.db.redis.RedisScriptTableDataDefine"/>
<ServerTableDataDefineProvider class="com.fr.plugin.db.redis.RedisScriptTableDataDefine"/>
</extra-designer>
<extra-decision>
<UniversalConnectionProvider class="com.fr.plugin.db.redis.RedisUniversalConnectionImpl"/>
</extra-decision>
<function-recorder class="com.fr.plugin.db.redis.core.RedisTableData"/>
<function-recorder class="com.fr.plugin.db.redis.core.RedisScriptTableData"/>
</plugin>

13
src/main/java/com/fr/plugin/db/redis/RedisConnectionComponent.java

@ -0,0 +1,13 @@
package com.fr.plugin.db.redis;
import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
public class RedisConnectionComponent extends Component {
public static final RedisConnectionComponent KEY = new RedisConnectionComponent();
@Override
public ScriptPath script(RequestClient req) {
return ScriptPath.build("com/fr/plugin/db/redis/web/redis.js");
}
}

105
src/main/java/com/fr/plugin/db/redis/RedisUniversalConnectionImpl.java

@ -0,0 +1,105 @@
package com.fr.plugin.db.redis;
import com.fr.decision.fun.impl.AbstractUniversalConnectionProvider;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.decision.webservice.utils.WebServiceUtils;
import com.fr.json.JSONObject;
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.stable.AssistUtils;
import com.fr.transaction.Configurations;
import com.fr.transaction.WorkerAdaptor;
import com.fr.web.struct.Atom;
public class RedisUniversalConnectionImpl extends AbstractUniversalConnectionProvider<RedisDatabaseConnection> {
private static final String BASIC_INFO = "basicConfig";
private static final String POOL_INFO = "poolConfig";
private static final String PROXY_INFO = "proxyConfig";
@Override
public String nameForConnection() {
return "Redis";
}
@Override
public String iconPathForConnection() {
return "/com/fr/plugin/db/redis/images/redis.png";
}
@Override
public Class<RedisDatabaseConnection> classForConnection() {
return RedisDatabaseConnection.class;
}
@Override
public Atom client() {
return RedisConnectionComponent.KEY;
}
@Override
public JSONObject serialize(RedisDatabaseConnection connection) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(BASIC_INFO, JSONObject.mapFrom(connection.clone()));
//将ConnectionPoolConfig和RedisConnectionProxyConfig也一次塞给前台展示
jsonObject.put(POOL_INFO, JSONObject.mapFrom(RedisConnectionPoolConfig.getInstance().clone()));
JSONObject proxy = JSONObject.mapFrom(RedisConnectionProxyConfig.getInstance().clone());
proxy.put("password", DecisionServiceConstants.DEFAULT_PASSWORD);
jsonObject.put(PROXY_INFO, proxy);
} catch (CloneNotSupportedException ignore) {
}
return jsonObject;
}
@Override
public RedisDatabaseConnection deserialize(RedisDatabaseConnection oldConnection, JSONObject pluginData) {
JSONObject redisDatabaseConnection = getRedisDataConnection(pluginData);
if (oldConnection != null && DecisionServiceConstants.DEFAULT_PASSWORD.equals(redisDatabaseConnection.getString("password"))) {
redisDatabaseConnection.put("password", oldConnection.getPassword());
} else {
redisDatabaseConnection.put("password", WebServiceUtils.getBase64DecodeStr(redisDatabaseConnection.getString("password")));
}
return redisDatabaseConnection.mapTo(RedisDatabaseConnection.class);
}
private JSONObject getRedisDataConnection(JSONObject object) {
final JSONObject pool = object.getJSONObject(POOL_INFO);
if (pool != null) {
final RedisConnectionPoolConfig poolConfig = pool.mapTo(RedisConnectionPoolConfig.class);
Configurations.update(new WorkerAdaptor(RedisConnectionPoolConfig.class) {
@Override
public void run() {
RedisConnectionPoolConfig.getInstance().setBlockWhenExhausted(poolConfig.getBlockWhenExhausted());
RedisConnectionPoolConfig.getInstance().setLifo(poolConfig.getLifo());
RedisConnectionPoolConfig.getInstance().setMaxIdle(poolConfig.getMaxIdle());
RedisConnectionPoolConfig.getInstance().setMaxTotal(poolConfig.getMaxTotal());
RedisConnectionPoolConfig.getInstance().setMaxWait(poolConfig.getMaxWait());
RedisConnectionPoolConfig.getInstance().setTimeout(poolConfig.getTimeout());
}
});
}
final JSONObject proxy = object.getJSONObject(PROXY_INFO);
if (proxy != null) {
final RedisConnectionProxyConfig proxyConfig = proxy.mapTo(RedisConnectionProxyConfig.class);
Configurations.update(new WorkerAdaptor(RedisConnectionProxyConfig.class) {
@Override
public void run() {
RedisConnectionProxyConfig.getInstance().setHost(proxyConfig.getHost());
RedisConnectionProxyConfig.getInstance().setOpen(proxyConfig.isOpen());
if (!AssistUtils.equals(proxyConfig.getPassword(), DecisionServiceConstants.DEFAULT_PASSWORD)) {
RedisConnectionProxyConfig.getInstance().setPassword(WebServiceUtils.getBase64DecodeStr(proxyConfig.getPassword()));
}
RedisConnectionProxyConfig.getInstance().setPort(proxyConfig.getPort());
RedisConnectionProxyConfig.getInstance().setPrivateKeyPath(proxyConfig.getPrivateKeyPath());
RedisConnectionProxyConfig.getInstance().setUsername(proxyConfig.getUsername());
}
});
}
return object.getJSONObject(BASIC_INFO);
}
}

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

@ -12,10 +12,12 @@ 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.XMLableReader;
import com.fr.third.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import java.util.Set;
@JsonIgnoreProperties({"id", "data", "classInfo", "nameSpace", "driver"})
public class RedisDatabaseConnection extends AbstractDatabaseConnection {
private static final int DEFAULT_REDIS_PORT = 6379;

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

@ -3,6 +3,7 @@ package com.fr.plugin.db.redis.core.pool;
import com.fanruan.api.conf.BaseConfiguration;
import com.fanruan.api.conf.HolderKit;
import com.fr.config.holder.Conf;
import com.fr.third.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
@ -10,6 +11,7 @@ import com.fr.config.holder.Conf;
* @version 10.0
* Created by richie on 2019-03-21
*/
@JsonIgnoreProperties("nameSpace")
public class RedisConnectionPoolConfig extends BaseConfiguration {
private static volatile RedisConnectionPoolConfig instance = null;

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

@ -5,12 +5,14 @@ import com.fanruan.api.conf.HolderKit;
import com.fanruan.api.security.SecurityKit;
import com.fanruan.api.util.StringKit;
import com.fr.config.holder.Conf;
import com.fr.third.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-21
*/
@JsonIgnoreProperties("nameSpace")
public class RedisConnectionProxyConfig extends BaseConfiguration {
private static volatile RedisConnectionProxyConfig instance = null;

BIN
src/main/resources/com/fr/plugin/db/redis/web/demo-tabledate-redis-web.zip

Binary file not shown.

1
src/main/resources/com/fr/plugin/db/redis/web/redis.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save