Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Dynamic Data source creation
KavithaD
Hi All,
I want to create data source dynamically and read from properties file to set data source properties.
In report intialization script i am doing something like this i dont know whether i am doing correctly or not,I just want to create dynamic data source.
importPackage(Packages.org.eclipse.birt.report.model.api.ElementFactory);
importPackage(Packages.org.eclipse.birt.report.model.api.OdaDataSourceHandle);
importPackage(Packages.java.util.Properties);
importPackage(Packages.java.io);
report = reportContext.getDesignHandle();
designFactory = designHandle.getElementFactory();
dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
property = new Properties();
property.load(new FileInputStream(reportContext.getDesignHandle().getResourceFolder()+"/Oracle_Profile"));
dsHandle.setProperty( "odaDriverClass",property.getValue("odaDriverClass"));
dsHandle.setProperty( "odaURL", property.getValue("odaURL"));
dsHandle.setProperty( "odaUser", property.getValue("odaUser"));
dsHandle.setProperty( "odaPassword", property.getValue("odaPassword"));
designHandle.getDataSources( ).add( dsHandle );
Please help me.
Thank you,
Kavitha
Find more posts tagged with
Comments
johnw
This would go into the beforeFactory method. <br />
<br />
The first line of your script is assigning the design handle to a variable called report, but you are referencing designHandle throughout the script. I think that might be a big source of your problems since designHandle is never initialized. <br />
<br />
But off the top of my head, with the exception of those errors, that looks correct.<br />
<br />
John<br />
<br />
<blockquote class='ipsBlockquote' data-author="'KavithaD'" data-cid="67993" data-time="1283349080" data-date="01 September 2010 - 06:51 AM"><p>
Hi All,<br />
<br />
I want to create data source dynamically and read from properties file to set data source properties.<br />
<br />
In report intialization script i am doing something like this i dont know whether i am doing correctly or not,I just want to create dynamic data source.<br />
<br />
importPackage(Packages.org.eclipse.birt.report.model.api.ElementFactory);<br />
importPackage(Packages.org.eclipse.birt.report.model.api.OdaDataSourceHandle);<br />
importPackage(Packages.java.util.Properties); <br />
importPackage(Packages.java.io);<br />
<br />
report = reportContext.getDesignHandle();<br />
designFactory = designHandle.getElementFactory();<br />
dsHandle = designFactory.newOdaDataSource(<br />
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );<br />
property = new Properties(); <br />
property.load(new FileInputStream(reportContext.getDesignHandle().getResourceFolder()+"/Oracle_Profile")); <br />
dsHandle.setProperty( "odaDriverClass",property.getValue("odaDriverClass"));<br />
dsHandle.setProperty( "odaURL", property.getValue("odaURL"));<br />
dsHandle.setProperty( "odaUser", property.getValue("odaUser"));<br />
dsHandle.setProperty( "odaPassword", property.getValue("odaPassword"));<br />
designHandle.getDataSources( ).add( dsHandle );<br />
<br />
Please help me.<br />
Thank you,<br />
Kavitha<br /></p></blockquote>
KavithaD
Hi Johnw,
I have created a JDBC data source & given default development db and in the report beforeFactory i given like,
importPackage(Packages.java.util.Properties);
importPackage(Packages.java.io);
ds = reportContext.getDesignHandle().getDesign().findDataSource("Data Source");
property = new Properties();
property.load(new FileInputStream(reportContext.getDesignHandle().getResourceFolder()+"/Oracle_Profile"));
ds.setProperty( "odaDriverClass",property.getValue("odaDriverClass"));
ds.setProperty( "odaURL", property.getValue("odaURL"));
ds.setProperty( "odaUser", property.getValue("odaUser"));
ds.setProperty( "odaPassword", property.getValue("odaPassword"));
reportContext.getDesignHandle().getDesign().add(ds);
In while running report at run time i am reading from property file which has different db property.I am getting exceptions like below,
org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "importPackage(Packages.java.util.Properties); importPackage(Packages.java.io); ds = reportContext.getDesignHandle().getDesign().findDataSource("Data Source"); property = new Properties(); property.load(new FileInputStream(reportContext.getDesignHandle().getResourceFolder()+"/Oracle_Profile")); ds.setProperty( "odaDriverClass",property.getValue("odaDriverClass")); ds.setProperty( "odaURL", property.getValue("odaURL")); ds.setProperty( "odaUser", property.getValue("odaUser")); ds.setProperty( "odaPassword", property.getValue("odaPassword")); ": Function importPackage must be called with a package; had "[JavaClass java.util.Properties]" instead. (/report/method[
@name="
;beforeFactory"]#1)
what could be the problem??????
Thank you,
Kavitha
PRAMODML
Hi Kavitha,
I to have same requirement , Can you help me on this.