|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|