[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.birt] Re: Change library Datasource URL at runtime

Anthony,

Where are you calling this code from?
You can always code it to open a lib and copy the elements and paste them into the report and then change them.


Jason

Anthony wrote:
If I try to add the datasource to the library (commented out below) I get:
org.eclipse.birt.report.model.api.command.ContentException: The ODA Data Source("Runtime Data Source") is not allowed directly or indirectly inside the Library's slot(dataSources).


If I add the datasource to the report it works but I get an exception when changing the datasource of the datasets:

IllegalOperationException: The module is read-only and operation is forbidden.


Is there a simpler approach all together?

----------------------------------------------------

String dataSourceName = "Runtime Data Source";
ElementFactory designFactory = this.currentReport.getDesignHandle().getElementFactory();


OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(dataSourceName, "org.eclipse.birt.report.data.oda.jdbc");
dsHandle.setProperty("odaDriverClass", "org.sqlite.JDBC");
dsHandle.setProperty("odaURL", this.databaseURL);
LibraryHandle library = (LibraryHandle) currentReport.getDesignHandle().getModuleHandle().getLibraries().get(0);
currentReport.getDesignHandle().getModuleHandle().getDataSources().add(dsHandle);


// library.getDataSources().add(dsHandle); // Exception on this line if swapped for the above line


// update ALL datasets SlotHandle slotHandle = library.getDataSets();

for (Iterator i = slotHandle.iterator(); i.hasNext();) {
   DataSetHandle dataSetHandle = (DataSetHandle) i.next();
   dataSetHandle.setDataSource(dataSourceName); //Exception on this line
}

Jason Weathersby wrote:

Anthony,

can you post the code you used to do this?

Jason

Anthony wrote:
Actually, the workaround via the API - adding a datasource at runtime, and setting it as the source for each dataset - doesn't work, since the datasets and datasource are in a library - you get an exception:

org.eclipse.birt.report.model.api.IllegalOperationException: The module is read-only and operation is forbidden.

Anthony

Anthony wrote:

In the library I have the datasource, and the parameter, and the property binding is set there in the Edit Data Source -> Property Binding screen.

Report parameter binding in datasets in the library *does* seem to work if I hard code the datasource, so I believe the problem is with the datasource.

I can display the parameter values in a dynamic text field just fine so I know they are being passed into the report.

It doesn't seem to make any difference if the parameters are also in the Report (rather than just in the library) - I'm not sure whether or not they should be?

I believe this *does* worked in some cases, so perhaps there is some other condition triggering this.

Anthony

Jason Weathersby wrote:

Anthony,

I tried this with BIRT 2.3.1 and it worked for me. Do you have the parameter and the ds in the library and did you set the property binding in the lib?

Jason

Anthony wrote:
Changing a datasource URL at runtime is trivial using property binding and report parameters (e.g. params["runtimeURL"].value). However this doesn't seem to work when the datasource is in a library - the parameters are ignored, and the defaults are used. So I have two questions

1) How can I change the JDBC driver URL of a datasource once the report is loaded as IReportRunable? Or can I only do it by creating a new datasource and updating all the datasets to reference it?

2) Is there a way to get this to work with property binding and report parameters? Or is it not possible to use libraries to share datasources that need to be changed at runtime? https://bugs.eclipse.org/bugs/show_bug.cgi?id=154189 makes it look like it's not.