I have a BIRT report which connects to our test database. In the productive environment I would like to supply a datasource which is provided by the container through jndi.
I like Adams approach. Here's how we do it:
/*
* Change the data sources in the .rptdesign
*/
void changeDataSource(ElementFactory designFactory,
ReportDesignHandle designHandle, String userConnect)
throws SemanticException {
SlotHandle datasources = designHandle.getDataSources();
SlotIterator iter = (SlotIterator) datasources.iterator();
while (iter.hasNext()) {
DesignElementHandle dsHandle = (DesignElementHandle) iter.next();
if (dsHandle instanceof OdaDataSourceHandle && dsHandle.getName().equals("lisa")) {
log.debug("changeDataSource: Changing datasource "
+ dsHandle.getName() + " new url=" + getLisaDbUrl());
dsHandle.setProperty("odaDriverClass",
"oracle.jdbc.driver.OracleDriver");
dsHandle.setProperty("odaURL", getLisaDbUrl());
dsHandle.setProperty("odaUser", getLisaUser());
dsHandle.setProperty("odaPassword", getLisaPassword());
} else {
log.debug("changeDataSource: Ignoring DS " + dsHandle.getName());
}
}
}
Here, "lisa" ist he name of the datasource we would like to change at runtime. The get... function return the values needed at "production" run time.