From c37facbfb503dfb0715853dd900c041bdfa5c76e Mon Sep 17 00:00:00 2001 From: abel Date: Mon, 17 Dec 2018 11:18:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'src/main/java/com/fr/plugin/db/redis/core'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/db/redis/core/RedisTableData.java | 307 +++++++++--------- 1 file changed, 154 insertions(+), 153 deletions(-) mode change 100755 => 100644 src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java 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 old mode 100755 new mode 100644 index 06a8b09..b1a81c6 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisTableData.java @@ -1,154 +1,155 @@ -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.config.holder.factory.XmlHolders; -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.data.DataModel; -import com.fr.general.xml.GeneralXMLTools; -import com.fr.intelli.record.Focus; -import com.fr.intelli.record.Original; -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.StringUtils; -import com.fr.stable.xml.XMLPrintWriter; -import com.fr.stable.xml.XMLableReader; - -import java.util.HashMap; -import java.util.Map; - - -@EnableMetrics -public class RedisTableData extends AbstractParameterTableData { - - private Conf database = Holders.obj(null, Connection.class); - private Conf dbIndex = XmlHolders.obj(new NumberOrderValue(0), OrderValue.class, OrderValue.XML_TAG); - private Conf query = Holders.simple(StringUtils.EMPTY); - - public void setDatabase(Connection c) { - this.database.set(c); - } - - public Connection getDatabase() { - return database.get(); - } - - public OrderValue getOrderValue() { - return dbIndex.get(); - } - - public void setOrderValue(OrderValue dbIndex) { - this.dbIndex.set(dbIndex); - } - - public String getQuery() { - return query.get(); - } - - public void setQuery(String query) { - this.query.set(query); - } - - public void setParameters(ParameterProvider[] providers) { - super.setDefaultParameters(providers); - } - - @Override - public DataModel createDataModel(Calculator calculator) { - return createDataModel(calculator, TableData.RESULT_ALL); - } - - @Override - @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)); - 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, - orderValue == null ? 0 : orderValue.toIndex(calculator, ps), - calculateQuery(query.get(), ps), - rowCount); - } - } - return null; - } - - private String calculateQuery(String query, Parameter[] ps) { - if (ArrayUtils.isEmpty(ps)) { - return query; - } - Map map = new HashMap(); - for (Parameter p : ps) { - map.put(p.getName(), p.getValue()); - } - try { - return TemplateUtils.renderParameter4Tpl(query, map); - } catch (Exception e) { - return query; - } - } - - public void readXML(XMLableReader reader) { - super.readXML(reader); - - if (reader.isChildNode()) { - String tmpName = reader.getTagName(); - String tmpVal; - - if (OrderValue.XML_TAG.equals(tmpName)) { - 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); - this.setDatabase(con); - } - } else if ("Query".equals(tmpName)) { - tmpVal = reader.getElementValue(); - if (isNotNullValue(tmpVal)) { - this.setQuery(tmpVal); - } - } - } - } - - @Override - public void writeXML(XMLPrintWriter writer) { - super.writeXML(writer); - 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(); - } - - private boolean isNotNullValue(String value) { - return value != null && !"null".equals(value); - } - - @Override - public Object clone() throws CloneNotSupportedException { - RedisTableData cloned = (RedisTableData) super.clone(); - cloned.database = (Conf) database.clone(); - cloned.query = (Conf) query.clone(); - cloned.dbIndex = (Conf) dbIndex.clone(); - return cloned; - } +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.config.holder.factory.XmlHolders; +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.data.DataModel; +import com.fr.general.xml.GeneralXMLTools; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +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.StringUtils; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + +import java.util.HashMap; +import java.util.Map; + + +@EnableMetrics +public class RedisTableData extends AbstractParameterTableData { + + private static final long serialVersionUID = 7017455818551800001L; + private Conf database = Holders.obj(null, Connection.class); + private Conf dbIndex = XmlHolders.obj(new NumberOrderValue(0), OrderValue.class, OrderValue.XML_TAG); + private Conf query = Holders.simple(StringUtils.EMPTY); + + public void setDatabase(Connection c) { + this.database.set(c); + } + + public Connection getDatabase() { + return database.get(); + } + + public OrderValue getOrderValue() { + return dbIndex.get(); + } + + public void setOrderValue(OrderValue dbIndex) { + this.dbIndex.set(dbIndex); + } + + public String getQuery() { + return query.get(); + } + + public void setQuery(String query) { + this.query.set(query); + } + + public void setParameters(ParameterProvider[] providers) { + super.setDefaultParameters(providers); + } + + @Override + public DataModel createDataModel(Calculator calculator) { + return createDataModel(calculator, TableData.RESULT_ALL); + } + + @Override + @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)); + 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, + orderValue == null ? 0 : orderValue.toIndex(calculator, ps), + calculateQuery(query.get(), ps), + rowCount); + } + } + return null; + } + + private String calculateQuery(String query, Parameter[] ps) { + if (ArrayUtils.isEmpty(ps)) { + return query; + } + Map map = new HashMap(); + for (Parameter p : ps) { + map.put(p.getName(), p.getValue()); + } + try { + return TemplateUtils.renderParameter4Tpl(query, map); + } catch (Exception e) { + return query; + } + } + + public void readXML(XMLableReader reader) { + super.readXML(reader); + + if (reader.isChildNode()) { + String tmpName = reader.getTagName(); + String tmpVal; + + if (OrderValue.XML_TAG.equals(tmpName)) { + 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); + this.setDatabase(con); + } + } else if ("Query".equals(tmpName)) { + tmpVal = reader.getElementValue(); + if (isNotNullValue(tmpVal)) { + this.setQuery(tmpVal); + } + } + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + super.writeXML(writer); + 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(); + } + + private boolean isNotNullValue(String value) { + return value != null && !"null".equals(value); + } + + @Override + public Object clone() throws CloneNotSupportedException { + RedisTableData cloned = (RedisTableData) super.clone(); + cloned.database = (Conf) database.clone(); + cloned.query = (Conf) query.clone(); + cloned.dbIndex = (Conf) dbIndex.clone(); + return cloned; + } } \ No newline at end of file