Browse Source

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

refactor
richie 5 years ago committed by Gogs
parent
commit
d53d61a0e2
  1. 6
      src/main/java/com/fr/plugin/db/redis/RedisConnectionComponent.java
  2. 13
      src/main/java/com/fr/plugin/db/redis/RedisScriptUniversalTableDataImpl.java
  3. 13
      src/main/java/com/fr/plugin/db/redis/RedisUniversalTableDataImpl.java
  4. 7
      src/main/java/com/fr/plugin/db/redis/bean/ParameterBean.java
  5. 8
      src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java
  6. 2030
      src/main/resources/com/fr/plugin/db/redis/web/redis.css
  7. 16
      src/main/resources/com/fr/plugin/db/redis/web/redis.js

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

@ -3,6 +3,7 @@ package com.fr.plugin.db.redis;
import com.fr.web.struct.Component; import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient; import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath; import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
public class RedisConnectionComponent extends Component { public class RedisConnectionComponent extends Component {
public static final RedisConnectionComponent KEY = new RedisConnectionComponent(); public static final RedisConnectionComponent KEY = new RedisConnectionComponent();
@ -10,4 +11,9 @@ public class RedisConnectionComponent extends Component {
public ScriptPath script(RequestClient req) { public ScriptPath script(RequestClient req) {
return ScriptPath.build("com/fr/plugin/db/redis/web/redis.js"); return ScriptPath.build("com/fr/plugin/db/redis/web/redis.js");
} }
@Override
public StylePath style(RequestClient req) {
return StylePath.build("com/fr/plugin/db/redis/web/redis.css");
}
} }

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

@ -2,7 +2,6 @@ package com.fr.plugin.db.redis;
import com.fanruan.api.cal.FormulaKit; import com.fanruan.api.cal.FormulaKit;
import com.fanruan.api.data.ConnectionKit; import com.fanruan.api.data.ConnectionKit;
import com.fanruan.api.data.TableDataKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider; import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider;
@ -40,7 +39,11 @@ public class RedisScriptUniversalTableDataImpl extends AbstractUniversalServerTa
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
Connection database = redisScriptTableData.getDatabase(); Connection database = redisScriptTableData.getDatabase();
data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY); data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY);
data.put(RedisConstants.ORDER, redisScriptTableData.getOrderValue().toString()); if (redisScriptTableData.getOrderValue() instanceof FormulaOrderValue) {
data.put(RedisConstants.ORDER, redisScriptTableData.getOrderValue().toString());
} else {
data.put(RedisConstants.ORDER, redisScriptTableData.getOrderValue().getValue());
}
data.put(RedisConstants.SCRIPT, redisScriptTableData.getScript()); data.put(RedisConstants.SCRIPT, redisScriptTableData.getScript());
data.put(RedisConstants.ENGINE, redisScriptTableData.getEngineType().getType()); data.put(RedisConstants.ENGINE, redisScriptTableData.getEngineType().getType());
data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisScriptTableData.getParameters(Calculator.createCalculator()))); data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisScriptTableData.getParameters(Calculator.createCalculator())));
@ -52,7 +55,7 @@ public class RedisScriptUniversalTableDataImpl extends AbstractUniversalServerTa
RedisScriptTableData newTableData = new RedisScriptTableData(); RedisScriptTableData newTableData = new RedisScriptTableData();
String databaseName = data.getString(RedisConstants.DATABASE); String databaseName = data.getString(RedisConstants.DATABASE);
String script = data.getString(RedisConstants.SCRIPT); String script = data.getString(RedisConstants.SCRIPT);
if (!StringKit.isEmpty(databaseName) && TableDataKit.findTableData(databaseName) != null) { if (StringKit.isNotEmpty(databaseName) && ConnectionKit.getConnection(databaseName) != null) {
newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName)); newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName));
} }
newTableData.setEngineType(EngineType.parse(data.getInt(RedisConstants.ENGINE))); newTableData.setEngineType(EngineType.parse(data.getInt(RedisConstants.ENGINE)));
@ -63,9 +66,7 @@ public class RedisScriptUniversalTableDataImpl extends AbstractUniversalServerTa
} else { } else {
newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order))); newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order)));
} }
newTableData.setParameters(RedisUtils.analyzeParameter(data.getJSONArray(RedisConstants.PARAMETERS), newTableData.getOrderValue(), script));
newTableData.setParameters(RedisUtils.analyzeParameter(oldTableData.getParameters(Calculator.createCalculator()), newTableData.getOrderValue(), script));
return newTableData; return newTableData;
} }

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

@ -2,7 +2,6 @@ package com.fr.plugin.db.redis;
import com.fanruan.api.cal.FormulaKit; import com.fanruan.api.cal.FormulaKit;
import com.fanruan.api.data.ConnectionKit; import com.fanruan.api.data.ConnectionKit;
import com.fanruan.api.data.TableDataKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider; import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider;
@ -39,7 +38,11 @@ public class RedisUniversalTableDataImpl extends AbstractUniversalServerTableDat
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
Connection database = redisTableData.getDatabase(); Connection database = redisTableData.getDatabase();
data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY); data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY);
data.put(RedisConstants.ORDER, redisTableData.getOrderValue().toString()); if (redisTableData.getOrderValue() instanceof FormulaOrderValue) {
data.put(RedisConstants.ORDER, redisTableData.getOrderValue().toString());
} else {
data.put(RedisConstants.ORDER, redisTableData.getOrderValue().getValue());
}
data.put(RedisConstants.SCRIPT, redisTableData.getScript()); data.put(RedisConstants.SCRIPT, redisTableData.getScript());
data.put(RedisConstants.QUERY, redisTableData.getQuery()); data.put(RedisConstants.QUERY, redisTableData.getQuery());
data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisTableData.getParameters(Calculator.createCalculator()))); data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisTableData.getParameters(Calculator.createCalculator())));
@ -48,11 +51,11 @@ public class RedisUniversalTableDataImpl extends AbstractUniversalServerTableDat
@Override @Override
public RedisTableData deserialize(RedisTableData oldTableData, JSONObject data) { public RedisTableData deserialize(RedisTableData oldTableData, JSONObject data) {
RedisTableData newTableData = oldTableData; RedisTableData newTableData = new RedisTableData();
String databaseName = data.getString(RedisConstants.DATABASE); String databaseName = data.getString(RedisConstants.DATABASE);
String script = data.getString(RedisConstants.SCRIPT); String script = data.getString(RedisConstants.SCRIPT);
String query = data.getString(RedisConstants.QUERY); String query = data.getString(RedisConstants.QUERY);
if (!StringKit.isEmpty(databaseName) && TableDataKit.findTableData(databaseName) != null) { if (StringKit.isNotEmpty(databaseName) && ConnectionKit.getConnection(databaseName) != null) {
newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName)); newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName));
} }
newTableData.setScript(script); newTableData.setScript(script);
@ -64,7 +67,7 @@ public class RedisUniversalTableDataImpl extends AbstractUniversalServerTableDat
} else { } else {
newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order))); newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order)));
} }
newTableData.setParameters(RedisUtils.analyzeParameter(oldTableData.getParameters(Calculator.createCalculator()), newTableData.getOrderValue(), script, query)); newTableData.setParameters(RedisUtils.analyzeParameter(data.getJSONArray(RedisConstants.PARAMETERS), newTableData.getOrderValue(), script, query));
return newTableData; return newTableData;
} }

7
src/main/java/com/fr/plugin/db/redis/bean/ParameterBean.java

@ -1,5 +1,6 @@
package com.fr.plugin.db.redis.bean; package com.fr.plugin.db.redis.bean;
import com.fanruan.api.util.StringKit;
import com.fr.base.ParameterTypeHandler; import com.fr.base.ParameterTypeHandler;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
@ -59,7 +60,11 @@ public class ParameterBean{
} }
public static ParameterBean createBean(ParameterProvider parameterProvider) { public static ParameterBean createBean(ParameterProvider parameterProvider) {
return new ParameterBean(parameterProvider.getClass().getSimpleName(),parameterProvider.getName(), parameterProvider.valueToString()); if (parameterProvider.getValue() != null) {
return new ParameterBean(parameterProvider.getValue().getClass().getSimpleName(), parameterProvider.getName(), parameterProvider.valueToString());
} else {
return new ParameterBean(String.class.getSimpleName(), parameterProvider.getName(), StringKit.EMPTY);
}
} }
public static List<ParameterBean> createParameterBeans(ParameterProvider[] parameterProviders) { public static List<ParameterBean> createParameterBeans(ParameterProvider[] parameterProviders) {

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

@ -6,6 +6,8 @@ import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.GeneralKit; import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.util.RenderKit; import com.fanruan.api.util.RenderKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fr.base.Parameter;
import com.fr.json.JSONArray;
import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.plugin.db.redis.help.ScriptBridge; import com.fr.plugin.db.redis.help.ScriptBridge;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
@ -72,7 +74,11 @@ public class RedisUtils {
} }
} }
public static ParameterProvider[] analyzeParameter(ParameterProvider[] oldParameters, OrderValue orderValue, String ...parameterTexts) { public static ParameterProvider[] analyzeParameter(JSONArray existParameters, OrderValue orderValue, String ...parameterTexts) {
Parameter[] oldParameters = new Parameter[existParameters.size()];
for (int i = 0; i < existParameters.size(); i++) {
oldParameters[i] = Parameter.getParameterFromJson(existParameters.getJSONObject(i));
}
ParameterProvider[] newParameters = ParameterKit.analyzeAndUnionSameParameters(parameterTexts, oldParameters); ParameterProvider[] newParameters = ParameterKit.analyzeAndUnionSameParameters(parameterTexts, oldParameters);
ParameterProvider[] newOrderParameters = orderValue.analyze4Parameters(); ParameterProvider[] newOrderParameters = orderValue.analyze4Parameters();
Map<String, ParameterProvider> parameterProviderMap = new HashMap<String, ParameterProvider>(); Map<String, ParameterProvider> parameterProviderMap = new HashMap<String, ParameterProvider>();

2030
src/main/resources/com/fr/plugin/db/redis/web/redis.css

File diff suppressed because it is too large Load Diff

16
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