Browse Source

修复bug

paid
richie 6 years ago
parent
commit
39bed5a703
  1. 3
      plugin.xml
  2. 54
      src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java
  3. 3
      src/main/java/com/fr/plugin/db/redis/core/order/OrderValue.java
  4. 4
      src/main/java/com/fr/plugin/db/redis/core/order/impl/FormulaOrderValue.java

3
plugin.xml

@ -3,12 +3,13 @@
<id>com.fr.solution.plugin.db.redis.v10</id>
<name><![CDATA[Redis数据集]]></name>
<active>yes</active>
<version>3.0</version>
<version>4.0</version>
<env-version>10.0</env-version>
<jartime>2018-08-20</jartime>
<vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[
[2018-11-26]解决10.0版本中服务器数据集无法保存的问题。<br/>
[2018-09-12]适配10.0版本。<br/>
[2018-05-12]增加了keys、hget、hmget、hkeys查询。<br/>
[2018-05-11]增加连接错误判定。<br/>

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

@ -3,25 +3,24 @@ package com.fr.plugin.db.redis.core;
import com.fr.base.Parameter;
import com.fr.base.TableData;
import com.fr.base.TemplateUtils;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.data.AbstractParameterTableData;
import com.fr.data.core.DataCoreXmlUtils;
import com.fr.data.impl.Connection;
import com.fr.data.impl.NameDatabaseConnection;
import com.fr.file.DatasourceManager;
import com.fr.general.Inter;
import com.fr.general.data.DataModel;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.ExtraClassManager;
import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.ParameterProvider;
import com.fr.stable.fun.FunctionHelper;
import com.fr.stable.fun.FunctionProcessor;
import com.fr.stable.fun.impl.AbstractFunctionProcessor;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
@ -32,34 +31,32 @@ import java.util.Map;
@EnableMetrics
public class RedisTableData extends AbstractParameterTableData {
private Connection database;
private OrderValue dbIndex;
private String query;
private Conf<Connection> database = Holders.obj(null, Connection.class);
private Conf<OrderValue> dbIndex = Holders.obj(new NumberOrderValue(0), OrderValue.class);
private Conf<String> query = Holders.simple(StringUtils.EMPTY);
public void setDatabase(Connection c) {
this.database = c;
this.database.set(c);
}
public Connection getDatabase() {
return database;
return database.get();
}
public OrderValue getOrderValue() {
return dbIndex;
return dbIndex.get();
}
public void setOrderValue(OrderValue dbIndex) {
this.dbIndex = dbIndex;
this.dbIndex.set(dbIndex);
}
public String getQuery() {
return query;
return query.get();
}
public void setQuery(String query) {
this.query = query;
this.query.set(query);
}
public void setParameters(ParameterProvider[] providers) {
@ -75,13 +72,15 @@ public class RedisTableData extends AbstractParameterTableData {
@Focus(id = RedisConstants.PLUGIN_ID, text = "Plugin-Redis_DB", source = Original.PLUGIN)
public DataModel createDataModel(Calculator calculator, int rowCount) {
Parameter[] ps = Parameter.providers2Parameter(getParameters(calculator));
if (database instanceof NameDatabaseConnection) {
String name = ((NameDatabaseConnection) database).getName();
Connection connection = database.get();
if (connection instanceof NameDatabaseConnection) {
String name = ((NameDatabaseConnection) connection).getName();
RedisDatabaseConnection rc = DatasourceManager.getProviderInstance().getConnection(name, RedisDatabaseConnection.class);
if (rc != null) {
OrderValue orderValue = dbIndex.get();
return new RedisTableDataModel(calculator, ps, rc,
dbIndex == null ? 0 : dbIndex.toIndex(calculator, ps),
calculateQuery(query, ps),
orderValue == null ? 0 : orderValue.toIndex(calculator, ps),
calculateQuery(query.get(), ps),
rowCount);
}
}
@ -111,7 +110,10 @@ public class RedisTableData extends AbstractParameterTableData {
String tmpVal;
if (OrderValue.XML_TAG.equals(tmpName)) {
this.dbIndex = (OrderValue) GeneralXMLTools.readXMLable(reader);
OrderValue orderValue = (OrderValue) GeneralXMLTools.readXMLable(reader);
if (orderValue != null) {
setOrderValue(orderValue);
}
} else if (com.fr.data.impl.Connection.XML_TAG.equals(tmpName)) {
if (reader.getAttrAsString("class", null) != null) {
com.fr.data.impl.Connection con = DataCoreXmlUtils.readXMLConnection(reader);
@ -129,9 +131,9 @@ public class RedisTableData extends AbstractParameterTableData {
@Override
public void writeXML(XMLPrintWriter writer) {
super.writeXML(writer);
GeneralXMLTools.writeXMLable(writer, dbIndex, OrderValue.XML_TAG);
if (this.database != null) {
DataCoreXmlUtils.writeXMLConnection(writer, this.database);
GeneralXMLTools.writeXMLable(writer, dbIndex.get(), OrderValue.XML_TAG);
if (this.database.get() != null) {
DataCoreXmlUtils.writeXMLConnection(writer, this.database.get());
}
writer.startTAG("Query").textNode(getQuery()).end();
}
@ -143,8 +145,8 @@ public class RedisTableData extends AbstractParameterTableData {
@Override
public Object clone() throws CloneNotSupportedException {
RedisTableData cloned = (RedisTableData) super.clone();
cloned.database = (Connection) database.clone();
cloned.query = query;
cloned.database = (Conf<Connection>) database.clone();
cloned.query = (Conf<String>) query.clone();
cloned.dbIndex = dbIndex;
return cloned;
}

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

@ -1,6 +1,7 @@
package com.fr.plugin.db.redis.core.order;
import com.fr.base.Parameter;
import com.fr.config.utils.UniqueKey;
import com.fr.general.GeneralUtils;
import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
@ -8,7 +9,7 @@ import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
public abstract class OrderValue implements XMLable {
public abstract class OrderValue extends UniqueKey implements XMLable {
private static final long serialVersionUID = -5421898153556627638L;

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

@ -1,11 +1,11 @@
package com.fr.plugin.db.redis.core.order.impl;
import com.fr.base.BaseFormula;
import com.fr.base.FRContext;
import com.fr.base.Parameter;
import com.fr.base.ParameterHelper;
import com.fr.base.ParameterMapNameSpace;
import com.fr.general.GeneralUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.db.redis.core.order.OrderValue;
import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
@ -42,7 +42,7 @@ public class FormulaOrderValue extends OrderValue {
try {
return GeneralUtils.objectToNumber(formula.eval(cal)).intValue();
} catch (UtilEvalError u) {
FRContext.getLogger().error(u.getMessage(), u);
FineLoggerFactory.getLogger().error(u.getMessage(), u);
} finally {
cal.removeNameSpace(nameSpace);
}

Loading…
Cancel
Save