|
Re: execute DML in events, execution order of DataSets [message #672279 is a reply to message #672185] |
Fri, 20 May 2011 14:00 |
|
BIRT only calls the datasets if they are used to prevent wasted calls.
We are looking at supporting multiple calls within one dataset that
should help in this case. You could always call out to jdbc from a
script but I am not certain that will be any more user friendly than
adding a table/list to the top or bottom of the report. If you want to
guarantee the dsinit if fired first you could bind a grid to the dsinit
dataset and then put the grid in the library and then nest your other
tables/list in it.
Jason
On 5/20/2011 4:53 AM, forums-noreply@eclipse.org wrote:
> I have a report where part of the data has to be prepared inside the
> Oracle database using a stored procedures (for various reasons).
>
> So I need to call pkg.init(...) at the beginning of the report execution
> and pkg.cleanup() at the end of the execution (where pkg is a PL/SQL
> package = a program executed inside the DB).
>
> The SQL queries in in the report's main DataSets rely on the fact that
> pkg.init() has been called before.
>
> I managed to do this using two JDBC DataSets "dsinit" and "dscleanup",
> where "dsinit" looks like this: "{call pkg.init(?)}" and "dscleanup"
> looks like this: "{call pkg.cleanup()}"; and using hidden lists for
> these DataSets at the top and the bottom of the layout.
>
> However, after I moved the lists from the .rptdesign to a .rptlibrary
> and let the report reference them from there, this does not work any
> more. By tracing the afterOpen events, I found that the "dsinit" opened
> too late; the main DataSets where executed earlier (resulting in missing
> output data).
>
> How can I force the execution order of the DataSets to be like I want it?
>
> The need to create DataSets and List or Tables in the layout just to
> execute an SQL statements seems strange for a report generator tool like
> BIRT.
>
> Is there a recommended way to execute simple DML statements or stored
> procedure calls in BIRT event handlers?
>
> If yes, I could use the beforeFactory/afterFactory events of the report
> to call my init/cleanup code.
>
> If no - why not?
>
> I think about creating a JDBC Connection Wrapper Java class that expects
> an additional "connectionID" property and then stores the connection
> (once opened) in an internal Map (String connectionID => Connection)
> before it returns it to the caller.
> A related Java class could then offer methods like
> static void executeDML(String connectionID, String dmlStatement);
> static void commit(String connectionID);
> static void rollback(String connectionID);
>
> Does that sound reasonable?
>
> Henning
|
|
|
|
Re: execute DML in events, execution order of DataSets [message #672371 is a reply to message #672306] |
Fri, 20 May 2011 20:28 |
|
Where are you creating the connection? Are you using the viewer or RE
API? If the connection is in the app context you should be able to get
it using reportContext.getAppContext().get("Whatevervariablenameugaveit");
anywhere in js (script or expression).
Jason
On 5/20/2011 11:59 AM, forums-noreply@eclipse.org wrote:
> Thanks for the feedback, I'll try it that way next week.
>
> Today I wrote code for the idea I mentioned.
> I used http
> //birtworld.blogspot.com/2007/01/birt-connection-pooling-continued.html
> as a template.
> Instead of injecting the Connection from outside, my code stores the
> connection in a static Map (using the OdaPropertyConfigId as a key).
>
> Unfortunately, I'm struggling with class loader issues here:
>
> After open() exits, the map contains a connection (logged from inside
> MyJdbcDriver).
>
> But when I try to get the connection from Javascript, the map is empty
> (again logged from within the class).
> I guess (though it is declared static), Javascript uses a different
> ClassLoader than the plugin...
>
> Can I somehow access the (JS) reportContext from within the plugin
> instead? That would help.
>
> Another oddity: it seems like the plugin is only used once I used the
> preview (not if I use run/view as pdf). Why is that?
|
|
|
|
Re: execute DML in events, execution order of DataSets [message #673443 is a reply to message #673336] |
Mon, 23 May 2011 16:36 |
|
You could always try putting it in the app context
public void setAppContext( Object context ) throws OdaException
{
HashMap ctx = (HashMap)context;
ctx.put("myobj", myobj);
}
Then in script try reportContext.getAppContext().get("myobj");
I still think this may cause classpath issues. You may need to add your plugin to the manifest list for the report engine plugin.
Jason
|
|
|
|
|
|
|
Re: execute DML in events, execution order of DataSets [message #710142 is a reply to message #710119] |
Thu, 04 August 2011 18:49 |
|
Can you post the script? You may want to use importPackage like
importPackage(Packages.org.eclipse.birt.report.data.testjdbc);
var sqlobj = new Sql();
sqlobj.someMethod();
Jason
On 8/4/2011 2:19 PM, VinceG wrote:
> Hi,
> I am trying to do something similar by calling a stored procedure inside
> AfterOpen trigger of the DataSource.
> I tried your last sample and it gives me the following error:
> [JavaPackage org.eclipse.birt.report.data.testjdbc.Sql] is not a
> function, it is object
>
> Do you mind explaining how did you achieve this?
>
> Thanks
|
|
|
|
Re: execute DML in events, execution order of DataSets [message #710188 is a reply to message #710154] |
Thu, 04 August 2011 19:45 |
|
That class was an example class created by the original poster.
Jason
On 8/4/2011 3:01 PM, VinceG wrote:
> Thank you for your help.
>
> That's all I have in the afterOpen script and similar issue:
> Script engine error: ReferenceError: "Sql" is not defined.
>
> Do you know where can I find any API regarding that testJDBC class?
>
> Thanks
>
>
|
|
|
Re: execute DML in events, execution order of DataSets [message #710197 is a reply to message #710188] |
Thu, 04 August 2011 19:46 |
|
If you have a Java Class that calls your stored procedure you can call
it from BIRT script.
Jason
On 8/4/2011 3:45 PM, Jason Weathersby wrote:
> That class was an example class created by the original poster.
>
> Jason
>
> On 8/4/2011 3:01 PM, VinceG wrote:
>> Thank you for your help.
>>
>> That's all I have in the afterOpen script and similar issue:
>> Script engine error: ReferenceError: "Sql" is not defined.
>>
>> Do you know where can I find any API regarding that testJDBC class?
>>
>> Thanks
>>
>>
>
|
|
|
|
|
|
|
Re: execute DML in events, execution order of DataSets [message #713645 is a reply to message #710919] |
Mon, 08 August 2011 17:28 |
|
It would be great if you could open an enhancement and post your work
around with a note to add a script option to do this.
Jason
On 8/5/2011 11:19 AM, h.vonbargen wrote:
> I could donate the code for executing SQL to the Eclipse BIRT project
> but I won't have the time to maintain it.
> However, I would much prefer if a JDBC Datasource had an official script
> API to let me execute SQL (including bind vars) in the current connection.
>
> Henning
|
|
|
Powered by
FUDForum. Page generated in 0.08525 seconds