|
|
|
package com.fr.plugin.db.redis;
|
|
|
|
|
|
|
|
import com.fanruan.api.cal.FormulaKit;
|
|
|
|
import com.fanruan.api.data.ConnectionKit;
|
|
|
|
import com.fanruan.api.data.TableDataKit;
|
|
|
|
import com.fanruan.api.util.StringKit;
|
|
|
|
import com.fr.data.impl.Connection;
|
|
|
|
import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider;
|
|
|
|
import com.fr.json.JSONObject;
|
|
|
|
import com.fr.plugin.db.redis.bean.ParameterBean;
|
|
|
|
import com.fr.plugin.db.redis.core.RedisConstants;
|
|
|
|
import com.fr.plugin.db.redis.core.RedisScriptTableData;
|
|
|
|
import com.fr.plugin.db.redis.core.order.impl.FormulaOrderValue;
|
|
|
|
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.script.Calculator;
|
|
|
|
import com.fr.stable.NameReference;
|
|
|
|
import com.fr.web.struct.Atom;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Elijah
|
|
|
|
* @version 10.0.4
|
|
|
|
* Created by Elijah on 2019/10/30
|
|
|
|
*/
|
|
|
|
public class RedisScriptUniversalTableDataImpl extends AbstractUniversalServerTableDataProvider<RedisScriptTableData> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<RedisScriptTableData> classForTableData() {
|
|
|
|
return RedisScriptTableData.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String nameForTableData() {
|
|
|
|
return "RedisScript";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JSONObject serialize(RedisScriptTableData redisScriptTableData) {
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
Connection database = redisScriptTableData.getDatabase();
|
|
|
|
data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY);
|
|
|
|
data.put(RedisConstants.ORDER, redisScriptTableData.getOrderValue().toString());
|
|
|
|
data.put(RedisConstants.SCRIPT, redisScriptTableData.getScript());
|
|
|
|
data.put(RedisConstants.ENGINE, redisScriptTableData.getEngineType().getType());
|
|
|
|
data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisScriptTableData.getParameters(Calculator.createCalculator())));
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RedisScriptTableData deserialize(RedisScriptTableData oldTableData, JSONObject data) {
|
|
|
|
RedisScriptTableData newTableData = new RedisScriptTableData();
|
|
|
|
String databaseName = data.getString(RedisConstants.DATABASE);
|
|
|
|
String script = data.getString(RedisConstants.SCRIPT);
|
|
|
|
if (!StringKit.isEmpty(databaseName) && TableDataKit.findTableData(databaseName) != null) {
|
|
|
|
newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName));
|
|
|
|
}
|
|
|
|
newTableData.setEngineType(EngineType.parse(data.getInt(RedisConstants.ENGINE)));
|
|
|
|
newTableData.setScript(script);
|
|
|
|
Object order = data.get(RedisConstants.ORDER);
|
|
|
|
if (order instanceof Integer) {
|
|
|
|
newTableData.setOrderValue(new NumberOrderValue((Integer) order));
|
|
|
|
} else {
|
|
|
|
newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order)));
|
|
|
|
}
|
|
|
|
|
|
|
|
newTableData.setParameters(RedisUtils.analyzeParameter(oldTableData.getParameters(Calculator.createCalculator()), newTableData.getOrderValue(), script));
|
|
|
|
|
|
|
|
return newTableData;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Atom client() {
|
|
|
|
return RedisConnectionComponent.KEY;
|
|
|
|
}
|
|
|
|
}
|