Hello,
I'am now ok with dynamic datasource
Thread: http://forums.smartclient.com/showthread.php?t=20962
The servlet should extends DataSourceLoader.
Now in getDataSource I setup my datasource.
Is it possible to get the fields dynamically direct from the database ?
I have see DataSource.forName(dsname, DSRequest) (For what is this method ?)
and DataSource.fromXML(xml, DSRequest) (you get the xml with DSRequest ? direct from database ?)
I'am now ok with dynamic datasource
Thread: http://forums.smartclient.com/showthread.php?t=20962
The servlet should extends DataSourceLoader.
Now in getDataSource I setup my datasource.
Is it possible to get the fields dynamically direct from the database ?
I have see DataSource.forName(dsname, DSRequest) (For what is this method ?)
and DataSource.fromXML(xml, DSRequest) (you get the xml with DSRequest ? direct from database ?)
Code:
public class CustomGenerator implements DynamicDSGenerator {
@Override
public DataSource getDataSource(String arg0, DSRequest arg1) {
DataSource ds = null;
System.err.println("@@@@@@"+arg0);
String table = arg0.split("_")[1];
try {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("<DataSource");
stringBuffer.append(" ID=\""+table+"\"");
stringBuffer.append(" serverType=\"sql\"");
stringBuffer.append(" tableName=\""+table+ "\"");
stringBuffer.append(">");
stringBuffer.append("<fields>");
stringBuffer.append("<field name=\"id\" type=\"integer\" primaryKey=\"true\"/>");
stringBuffer.append("<field name=\"marque\" type=\"text\" length=\"2147483647\"/>");
stringBuffer.append("<field name=\"type\" type=\"text\" length=\"2147483647\"/>");
stringBuffer.append("</fields>");
stringBuffer.append("</DataSource>");
PrintWriter pw = new PrintWriter(new File("ds/" + table + ".ds.xml"));
pw.print(stringBuffer.toString());
pw.close();
System.out.println(stringBuffer);
ds = DataSource.fromXML(stringBuffer.toString());
} catch (Exception e) {
e.printStackTrace();
}
return ds;
}
Comment