From 39bed5a703976462c067691d6dffaafd898f37bd Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 26 Nov 2018 12:49:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 3 +- .../plugin/db/redis/core/RedisTableData.java | 54 ++++++++++--------- .../db/redis/core/order/OrderValue.java | 3 +- .../core/order/impl/FormulaOrderValue.java | 4 +- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/plugin.xml b/plugin.xml index 76e51c2..3611e87 100755 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ com.fr.solution.plugin.db.redis.v10 yes - 3.0 + 4.0 10.0 2018-08-20 richie [2018-09-12]适配10.0版本。
[2018-05-12]增加了keys、hget、hmget、hkeys查询。
[2018-05-11]增加连接错误判定。
diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java b/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java index 8edf946..51a6a7a 100755 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java +++ b/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 database = Holders.obj(null, Connection.class); + private Conf dbIndex = Holders.obj(new NumberOrderValue(0), OrderValue.class); + private Conf 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) database.clone(); + cloned.query = (Conf) query.clone(); cloned.dbIndex = dbIndex; return cloned; } diff --git a/src/main/java/com/fr/plugin/db/redis/core/order/OrderValue.java b/src/main/java/com/fr/plugin/db/redis/core/order/OrderValue.java index 04ffe79..ff22369 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/order/OrderValue.java +++ b/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; diff --git a/src/main/java/com/fr/plugin/db/redis/core/order/impl/FormulaOrderValue.java b/src/main/java/com/fr/plugin/db/redis/core/order/impl/FormulaOrderValue.java index 97b09a2..cb5c616 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/order/impl/FormulaOrderValue.java +++ b/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); }