You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by ypomonh <yp...@freemail.gr> on 2007/05/11 15:15:05 UTC
(newbie) Query a given datasource from a javascript flow?
I'm searching an easy way to query a given datasource (defined in) from
within a flow (javascript). Not using an ORM framework but even plain JDBC.
Have tried to use
org.apache.cocoon.components.flow.javascript.ScriptableConnection:
importPackage(Packages.org.apache.cocoon.components.flow.javascript.ScriptableConnection);
var db = Database.getConnection("mydatasource");
var queryVal = cocoon.parameters["rid"];
var startRow = 0;
var maxRows = 100;
row = db.query("select * from report_parameter_map where report_id
= ?", queryVal, startRow, maxRows);
print (row.rowCount);
but get : "'Database' is not defined" ?
Is there a simpler way to query a given datasource from within a flow
(javascript)?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by Sylvain Wallez <sy...@apache.org>.
Joerg Heinicke wrote:
> That's not what I had in mind - but it made me remembering what it was
> :) Something with J, B and I, added another arbitrary letter, searched
> repeatedly the Cocoon lists - until I found [1]. JDBI [2] was what I
> had in mind. That's not really about JDBC scripting, but easier
> integration into Java at least. Might be an option.
>
> Joerg
>
> [1] http://marc.info/?t=112993036900004&r=1&w=4
> [2] http://jdbi.codehaus.org/
Yes, this actually where I took the code sample from. JDBI eases the use
of JDBC a lot, and the little integration with flowscript makes it
really simple.
It now lives at
http://svn.apache.org/repos/asf/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/sql/
Sylvain
--
Sylvain Wallez - http://bluxte.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by Joerg Heinicke <jo...@gmx.de>.
On 16.05.2007 14:16, Sylvain Wallez wrote:
>> But I guess there are more standard ways to do it. Hadn't we a simple
>> JDBC scripting framework in Cocoon? IIRC Sylvain and Bertrand should
>> best. I hope they can help.
>
> You actually don't need ScriptableConnection at all. To get a connection
>>from the DataSource component in flowscript, use the following:
That's not what I had in mind - but it made me remembering what it was
:) Something with J, B and I, added another arbitrary letter, searched
repeatedly the Cocoon lists - until I found [1]. JDBI [2] was what I had
in mind. That's not really about JDBC scripting, but easier integration
into Java at least. Might be an option.
Joerg
[1] http://marc.info/?t=112993036900004&r=1&w=4
[2] http://jdbi.codehaus.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by Sylvain Wallez <sy...@apache.org>.
Joerg Heinicke wrote:
> On 16.05.2007 18:43, ypomonh wrote:
>> Sylvain Wallez wrote:
>>> Joerg Heinicke wrote:
>>> Sorry for the late answer.
>>
>> Thanks Joerg, I appreciate the help :)
>
> Honour to whom honour is due. It was Sylvain :)
Eh ;-)
Sylvain
--
Sylvain Wallez - http://bluxte.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by Joerg Heinicke <jo...@gmx.de>.
On 16.05.2007 18:43, ypomonh wrote:
> Sylvain Wallez wrote:
>> Joerg Heinicke wrote:
>> Sorry for the late answer.
>
> Thanks Joerg, I appreciate the help :)
Honour to whom honour is due. It was Sylvain :)
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by ypomonh <yp...@freemail.gr>.
Sylvain Wallez wrote:
> Joerg Heinicke wrote:
>
> Sorry for the late answer.
Thanks Joerg, I appreciate the help :)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by Sylvain Wallez <sy...@apache.org>.
Joerg Heinicke wrote:
> On 11.05.2007 15:15, ypomonh wrote:
>
>> I'm searching an easy way to query a given datasource (defined in)
>> from within a flow (javascript). Not using an ORM framework but even
>> plain JDBC.
>>
>> Have tried to use
>> org.apache.cocoon.components.flow.javascript.ScriptableConnection:
>>
>>
>> importPackage(Packages.org.apache.cocoon.components.flow.javascript.ScriptableConnection);
>>
>> var db = Database.getConnection("mydatasource");
>> var queryVal = cocoon.parameters["rid"];
>> var startRow = 0;
>> var maxRows = 100;
>>
>> row = db.query("select * from report_parameter_map where
>> report_id = ?", queryVal, startRow, maxRows);
>> print (row.rowCount);
>>
>> but get : "'Database' is not defined" ?
>>
>> Is there a simpler way to query a given datasource from within a flow
>> (javascript)?
>
> This stuff is only part of the petstore block and so probably rarely
> used and even less documented. To make it work you can have a look
> into the petstore samples. Following the flow script there you need to
> import Database.js and not the ScriptableConnection directly:
>
> cocoon.load("resource://org/apache/cocoon/components/flow/javascript/Database.js");
>
>
> But I guess there are more standard ways to do it. Hadn't we a simple
> JDBC scripting framework in Cocoon? IIRC Sylvain and Bertrand should
> best. I hope they can help.
Sorry for the late answer.
You actually don't need ScriptableConnection at all. To get a connection
from the DataSource component in flowscript, use the following:
var selector =
cocoon.getComponent(Packages.org.apache.avalon.excalibur.datasource.DataSourceComponent.ROLE
+ "Selector");
var datasource = selector.select("my-datasource");
var connection = datasource.getConnection();
Don't forget to release the connection with connection.close().
Sylvain
--
Sylvain Wallez - http://bluxte.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: (newbie) Query a given datasource from a javascript flow?
Posted by Joerg Heinicke <jo...@gmx.de>.
On 11.05.2007 15:15, ypomonh wrote:
> I'm searching an easy way to query a given datasource (defined in) from
> within a flow (javascript). Not using an ORM framework but even plain JDBC.
>
> Have tried to use
> org.apache.cocoon.components.flow.javascript.ScriptableConnection:
>
>
> importPackage(Packages.org.apache.cocoon.components.flow.javascript.ScriptableConnection);
>
> var db = Database.getConnection("mydatasource");
> var queryVal = cocoon.parameters["rid"];
> var startRow = 0;
> var maxRows = 100;
>
> row = db.query("select * from report_parameter_map where report_id =
> ?", queryVal, startRow, maxRows);
> print (row.rowCount);
>
> but get : "'Database' is not defined" ?
>
> Is there a simpler way to query a given datasource from within a flow
> (javascript)?
This stuff is only part of the petstore block and so probably rarely
used and even less documented. To make it work you can have a look into
the petstore samples. Following the flow script there you need to import
Database.js and not the ScriptableConnection directly:
cocoon.load("resource://org/apache/cocoon/components/flow/javascript/Database.js");
But I guess there are more standard ways to do it. Hadn't we a simple
JDBC scripting framework in Cocoon? IIRC Sylvain and Bertrand should
best. I hope they can help.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org