Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Use existing Datasource/Dataset for running QueryDefinition
Use existing Datasource/Dataset for running QueryDefinition [message #937036] Mon, 08 October 2012 15:46 Go to next message
Axel Tessier is currently offline Axel TessierFriend
Messages: 1
Registered: October 2012
Junior Member
Hi,

Is it possible to use the datasource / dataset created in BIRT report for running a QueryDefinition ?

I'm trying to run a query as following using XML Oda DataSource and DataSet:

var des = DataEngine.newDataEngine( myconfig , null);
des.defineDataSource( dataSource );
des.defineDataSet( dataSet );
queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( dataSet.getName() );
queryDefinition.setAutoBinding(true);
...

The dataSource and dataSet have to be instances of OdaDataSourceDesign and OdaDataSetDesign and I have not found a way to a get these designs out of the existing datasource or dataset. What I can do is to create for example the datasource design like this:

var odaDataSource = new OdaDataSourceDesign(title);
odaDataSource.setExtensionID( "org.eclipse.datatools.enablement.oda.xml" );
odaDataSource.addPublicProperty( "FILELIST", reportDataSource.getProperty("FILELIST").toString() );
odaDataSource.addPublicProperty( "ENCODINGLIST", reportDataSource.getProperty("ENCODINGLIST").toString());

The issue with this code is that we do not use physical files to pass the XML, but we use rather "org.eclipse.datatools.enablement.oda.xml.inputStream". And in this case, the OdaDataSourceDesign created does not seem to use it, as BIRT is trying to load the source from the file that was initially set in the rptdesign.


Finally what I'm trying to achieve is to load the results of a dataset in order to build the queryText of a second dataset. Using the QueryDefinition was the only way I found to programatically collect the results from a dataset, so if you know any other way to get this using the datasource and dataset defined in the rptdesign, you will be more than welcome.

Thanks!






Re: Use existing Datasource/Dataset for running QueryDefinition [message #937350 is a reply to message #937036] Mon, 08 October 2012 22:50 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

importPackage( Packages.org.eclipse.birt.report.model.api );
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.data.engine.api);
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.data.engine.api.querydefn);
importPackage(Packages.org.eclipse.birt.data.engine.core);


var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();
var de = DataEngine.newDataEngine( myconfig, null );

var dsrc = reportContext.getDesignHandle().findDataSource("Data Source");
var dset = reportContext.getDesignHandle().findDataSet("Data Set");

var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( "org.eclipse.datatools.enablement.oda.xml" );
odaDataSource.addPublicProperty( "FILELIST", dsrc.getProperty("FILELIST").toString() );



var odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID( "org.eclipse.datatools.enablement.oda.xml.dataSet" );
odaDataSet.setQueryText( dset.getQueryText() );


de.defineDataSource( odaDataSource );
de.defineDataSet( odaDataSet );

queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.setAutoBinding(true);


var pq = de.prepare( queryDefinition );

var qr = pq.execute( null );

rowcount=0;
var ri = qr.getResultIterator( );
while ( ri.next( ) )
{
rowcount++
}

ri.close( );
qr.close( );
de.shutdown( );

Jason
Re: Use existing Datasource/Dataset for running QueryDefinition [message #973793 is a reply to message #937350] Tue, 06 November 2012 16:20 Go to previous message
Murray Hays is currently offline Murray HaysFriend
Messages: 1
Registered: November 2012
Junior Member
Jason,

I was able to use your XML datasource code successfully in RSA. However, I then wanted to use a UML datasource rather than XML datasource. Being ignorant, and not able to find any guidance on the web or your "Extending BIRT..." book, I modified your code to something like:

Quote:
...

odaDataSource.setExtensionID( "com.ibm.ccl.oda.uml" );
odaDataSource.addPublicProperty( "instancemodels", dsrc.getProperty("instancemodels").toString() );
odaDataSource.addPublicProperty( "metamodels", dsrc.getProperty("metamodels").toString() );

var odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID( "com.ibm.ccl.oda.uml.dataSet" );
odaDataSet.setQueryText( dset.getQueryText() );

...

var qr = pq.execute( null );

...


The following exception was thrown when "pq.execute()" was invoked:

Quote:
Wrapped org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot open the connection for the driver: com.ibm.ccl.oda.uml.
org.eclipse.datatools.connectivity.oda.OdaException ;
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/BenefitPaymentIF/BenefitPaymentIF.emx' does not exist. (/report/method[@name="beforeFactory"]#153)
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:287)
at org.eclipse.birt.core.script.ScriptContext.evaluate(ScriptContext.java:154)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:772)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:701)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleScriptInternal(ScriptExecutor.java:61)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleScript(ScriptExecutor.java:48)
at org.eclipse.birt.report.engine.script.internal.ReportScriptExecutor.handleBeforeFactory(ReportScriptExecutor.java:74)
... 21 more
Caused by: org.mozilla.javascript.WrappedException: Wrapped org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot open the connection for the driver: com.ibm.ccl.oda.uml.
org.eclipse.datatools.connectivity.oda.OdaException ;
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/BenefitPaymentIF/BenefitPaymentIF.emx' does not exist. (/report/method[@name="beforeFactory"]#153)
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1773)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:183)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:247)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3330)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at org.mozilla.javascript.SecurityController$1.exec(SecurityController.java:193)
at org.eclipse.birt.report.engine.javascript.ScriptUtil$1.execWithDomain(ScriptUtil.java:59)
at org.mozilla.javascript.SecurityController.callWithDomain(SecurityController.java:189)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2474)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:282)
... 27 more
Caused by: org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot open the connection for the driver: com.ibm.ccl.oda.uml.
org.eclipse.datatools.connectivity.oda.OdaException ;
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/BenefitPaymentIF/BenefitPaymentIF.emx' does not exist.
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.newException(ExceptionHandler.java:54)
at org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:177)
at org.eclipse.birt.data.engine.executor.DataSource.newConnection(DataSource.java:224)
at org.eclipse.birt.data.engine.executor.DataSource.open(DataSource.java:212)
at org.eclipse.birt.data.engine.impl.DataSourceRuntime.openOdiDataSource(DataSourceRuntime.java:208)
at org.eclipse.birt.data.engine.impl.QueryExecutor.openDataSource(QueryExecutor.java:406)
at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:316)
at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:455)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178)
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:145)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:159)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
... 40 more
Caused by: org.eclipse.datatools.connectivity.oda.OdaException ;
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/BenefitPaymentIF/BenefitPaymentIF.emx' does not exist.
at com.ibm.ccl.oda.emf.internal.datasource.EMFConnection.checkExistence(EMFConnection.java:246)
at com.ibm.ccl.oda.emf.internal.datasource.EMFConnection.open(EMFConnection.java:134)
at com.ibm.ccl.oda.uml.internal.datasource.UMLConnection.open(UMLConnection.java:70)
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:250)
at org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:165)
... 56 more
Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/BenefitPaymentIF/BenefitPaymentIF.emx' does not exist.
at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl$WorkbenchHelper.createPlatformResourceInputStream(PlatformResourceURIHandlerImpl.java:222)
at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createInputStream(PlatformResourceURIHandlerImpl.java:452)
at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:301)
at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:295)
at com.ibm.ccl.oda.emf.internal.datasource.EMFConnection.checkExistence(EMFConnection.java:242)
... 60 more
Caused by: org.eclipse.core.internal.resources.ResourceException: Resource '/BenefitPaymentIF/BenefitPaymentIF.emx' does not exist.
at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:326)
at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:200)
at org.eclipse.core.internal.resources.File.getContents(File.java:291)
at org.eclipse.core.internal.resources.File.getContents(File.java:282)
at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl$WorkbenchHelper.createPlatformResourceInputStream(PlatformResourceURIHandlerImpl.java:208)
... 64 more


Any ideas of how I am supposed to use the Data Engine to programmatically retrieve information from a UML datasource in RSA?

Also, do you have any pointers to where I can learn more about what I don't know about this subject? I have googled "com.ibm.ccl.oda.uml" and cannot find any javadoc, or information on using this functionality.

Thanks in advance.

[Updated on: Tue, 06 November 2012 18:11]

Report message to a moderator

Previous Topic:Webservice MS SQL authentication
Next Topic:specify position of dataEntry in radarchart
Goto Forum:
  


Current Time: Sat Apr 20 14:46:57 GMT 2024

Powered by FUDForum. Page generated in 0.02900 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top