Hi Isomorphic,
I need to dynamically modify a DataSource depending on some configuration stored in the database (using 5.1d).
I managed to call my DynamicDSGenerator with the information I found in the QSG and the forums. The only thing the QSG left unclear IMHO is what you wrote in this post and perhaps the information on ServerInit (my web.xml only had one way of loading Init, perhaps because I started from a 4.0/4.1 builtInDS).
On modifying the DataSource itself, this is my java code:
First of all, this works, which is great and an impressive feature (I can see the "foobar" in the DSLoader response). I have two questions though:
Blama
I need to dynamically modify a DataSource depending on some configuration stored in the database (using 5.1d).
I managed to call my DynamicDSGenerator with the information I found in the QSG and the forums. The only thing the QSG left unclear IMHO is what you wrote in this post and perhaps the information on ServerInit (my web.xml only had one way of loading Init, perhaps because I started from a 4.0/4.1 builtInDS).
On modifying the DataSource itself, this is my java code:
Code:
import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DataSource; import com.isomorphic.datasource.DynamicDSGenerator; public class RegisterDS extends HttpServlet { private static final long serialVersionUID = 7849924835392267735L; @Override public void init() throws ServletException { System.out.println("Called RegisterDS"); DynamicDSGenerator myDynamicDSGenerator = new DynamicDSGenerator() { @Override public DataSource getDataSource(String id, DSRequest dsRequest) { DataSource ds = null; try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); ServletContext servletContext = getServletContext(); String strAbsolutePath = servletContext.getRealPath("ds"); Document doc = builder.parse(strAbsolutePath + "/V_LEADUPLOAD.ds.xml"); doc.getDocumentElement().setAttribute("foobar", "foobar"); ds = DataSource.fromXML(doc); } catch (Exception ex) { ex.printStackTrace(); } return ds; } }; DataSource.addDynamicDSGenerator(myDynamicDSGenerator, "V_LEADUPLOAD"); } }
- Is this the correct way to get the path to the .ds.xml file I use as template?
- Is the configuration always xml-modification and DataSource.fromXML(doc) in the end? Or is there some other java-only way (á la "myField = new DSField(); myField.set...(); myDS.setFields(myField); return myDS;")
Blama
Comment