forked from hugh/demo-connection-provider
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
package com.tptj.demo.hg.connection.data; |
|
|
|
import com.fanruan.api.conf.HolderKit; |
|
import com.fanruan.api.data.ConnectionKit; |
|
import com.fanruan.api.data.open.BaseTableData; |
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.config.holder.Conf; |
|
import com.fr.general.data.DataModel; |
|
import com.fr.intelli.record.Focus; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.record.analyzer.EnableMetrics; |
|
import com.fr.script.Calculator; |
|
import com.fr.stable.xml.XMLPrintWriter; |
|
import com.fr.stable.xml.XMLableReader; |
|
import com.tptj.demo.hg.connection.conn.DemoConnection; |
|
|
|
/** |
|
* @author 秃破天际 |
|
* @version 10.0 |
|
* Created by 秃破天际 on 2021-03-31 |
|
**/ |
|
@EnableMetrics |
|
public class DemoData extends BaseTableData { |
|
private Conf<String> database = HolderKit.simple(StringKit.EMPTY); |
|
|
|
public String getDatabase() { |
|
return database.get(); |
|
} |
|
|
|
public void setDatabase( String database) { |
|
this.database.set(database); |
|
} |
|
|
|
@Override |
|
@Focus(id = "com.tptj.demo.hg.connection.v10",text = "connection demo") |
|
public DataModel createDataModel(Calculator calculator) { |
|
DemoConnection conn = ConnectionKit.getConnection(getDatabase(),DemoConnection.class); |
|
try { |
|
conn.testConnection(); |
|
}catch (Exception e){ |
|
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
|
return DataModel.EMPTY_DATAMODEL; |
|
} |
|
return new DemoModel(conn); |
|
} |
|
|
|
@Override |
|
public void readXML(XMLableReader reader) { |
|
super.readXML(reader); |
|
if (reader.isChildNode()) { |
|
String tagName = reader.getTagName(); |
|
if ("Attr".equals(tagName)) { |
|
setDatabase(reader.getAttrAsString("source", StringKit.EMPTY)); |
|
} |
|
} |
|
} |
|
|
|
@Override |
|
public void writeXML(XMLPrintWriter writer) { |
|
super.writeXML(writer); |
|
writer.startTAG("Attr").attr("source", getDatabase()).end(); |
|
} |
|
|
|
@Override |
|
public Object clone() throws CloneNotSupportedException { |
|
DemoData cloned = (DemoData) super.clone(); |
|
cloned.database = (Conf<String>) database.clone(); |
|
return cloned; |
|
} |
|
}
|
|
|