Browse Source

readme

master
rinoux 4 years ago
parent
commit
24b6836456
  1. 8
      README.md
  2. 19
      src/main/java/com/fr/plugin/tabledata/build/DemoTableData.java
  3. 13
      src/main/java/com/fr/plugin/tabledata/build/DemoTableDataBuilder.java

8
README.md

@ -0,0 +1,8 @@
# 数据集TableData创建插件
## 使用场景
- 如果需要以插件的方式,根据<TableData>标签的class属性解析为其它类型TableData,满足额外的数据集功能需要。
## 注意事项
- `getClassAttr`返回的Class一般是`matchPattern`方法匹配的类型,这样能保证保存TableData到xml时不会修改class属性。
- 示例插件作用是给数据集加一LastUpdateDataTime子标签存储上次修改时间,通过getLastUpdateDataTime获取。

19
src/main/java/com/fr/plugin/tabledata/build/DemoTableData.java

@ -2,9 +2,12 @@ package com.fr.plugin.tabledata.build;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.DBTableData; import com.fr.data.impl.DBTableData;
import com.fr.general.DateUtils;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import java.util.Date;
/** /**
* @author rinoux * @author rinoux
* @version 10.0 * @version 10.0
@ -12,10 +15,10 @@ import com.fr.stable.xml.XMLableReader;
*/ */
public class DemoTableData extends DBTableData { public class DemoTableData extends DBTableData {
private static final String DemoTag = "ExtraInfo"; private static final String DemoTag = "LastUpdateDataTime";
private String extraInfo; private String lastUpdateDataTime;
public DemoTableData() { public DemoTableData() {
} }
@ -28,12 +31,12 @@ public class DemoTableData extends DBTableData {
super(database, query); super(database, query);
} }
public String getExtraInfo() { public String getLastUpdateDataTime() {
return extraInfo; return lastUpdateDataTime;
} }
public void setExtraInfo(String extraInfo) { public void setLastUpdateDataTime(String lastUpdateDataTime) {
this.extraInfo = extraInfo; this.lastUpdateDataTime = lastUpdateDataTime;
} }
@Override @Override
@ -42,7 +45,7 @@ public class DemoTableData extends DBTableData {
if (reader.isChildNode()) { if (reader.isChildNode()) {
String tagName = reader.getTagName(); String tagName = reader.getTagName();
if (DemoTag.equals(tagName)) { if (DemoTag.equals(tagName)) {
setExtraInfo(reader.getContent()); setLastUpdateDataTime(reader.getElementValue());
} }
} }
} }
@ -51,7 +54,7 @@ public class DemoTableData extends DBTableData {
public void writeXML(XMLPrintWriter writer) { public void writeXML(XMLPrintWriter writer) {
super.writeXML(writer); super.writeXML(writer);
writer.startTAG(DemoTag); writer.startTAG(DemoTag);
writer.textNode("some demo extra info"); writer.textNode(DateUtils.DATETIMEFORMAT2.format(new Date()));
writer.end(); writer.end();
} }
} }

13
src/main/java/com/fr/plugin/tabledata/build/DemoTableDataBuilder.java

@ -1,6 +1,7 @@
package com.fr.plugin.tabledata.build; package com.fr.plugin.tabledata.build;
import com.fr.plugin.transform.ExecuteFunctionRecord; import com.fr.base.TableData;
import com.fr.data.impl.DBTableData;
import com.fr.plugin.transform.FunctionRecorder; import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.fun.impl.AbstractTableDataBuildProvider; import com.fr.stable.fun.impl.AbstractTableDataBuildProvider;
@ -11,14 +12,14 @@ import com.fr.stable.fun.impl.AbstractTableDataBuildProvider;
*/ */
@FunctionRecorder @FunctionRecorder
public class DemoTableDataBuilder extends AbstractTableDataBuildProvider<DemoTableData> { public class DemoTableDataBuilder extends AbstractTableDataBuildProvider<DemoTableData> {
@Override @Override
public boolean matchPattern(String tdClassName) { public Class<? extends TableData> getAttrClass() {
return tdClassName.endsWith(".DBTableData"); return DBTableData.class;
} }
@Override @Override
@ExecuteFunctionRecord public Class<DemoTableData> getBuildClass() {
public DemoTableData newInstance() { return DemoTableData.class;
return new DemoTableData();
} }
} }

Loading…
Cancel
Save