You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Al Brown <al...@yahoo.com> on 2008/02/12 00:05:48 UTC
modular database action
I'm trying to figure out how to use a mysql database in an cocoon action.
I'm using cocoon 2.1.10
I have a mysql database and forms for all the attributes of all the
tables. When the form action returns the new values for
all the attributes in a table what is the recommended way to get a basic
sql update to happen.
I found the modulardatabaseAction wiki document and I can see how I can
make a descriptor file that describes a table but
1) where does this file go.
2) how does the sql update command get created?
I guess I can just put jdbc command in a java class and use the
<map:act> to call the class but it looks likes a
lot of good folks have already solved this problem but the solution is
not obvious to me. I found the ModularDatabaseActions wiki pages
but I have not found a how-to or tutorial and where all the pieced go.
I have seen the database connection stuff and the pooling stuff so it
seems like I should not create another mysql connection in my java code
but I do not know how to get at and use the connection in cocoon.
I can query my database using the sql transform and that works great.
Now I need to get data back into the tables.
Al
--
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: modular database action
Posted by Al Brown <al...@yahoo.com>.
Tobia Conforto wrote:
> Al Brown wrote:
>> I guess I can just put jdbc command in a java class and use the
>> <map:act> to call the class but it looks likes a lot of good folks
>> have already solved this problem but the solution is not obvious to
>> me. I found the ModularDatabaseActions wiki pages but I have not
>> found a how-to or tutorial and where all the pieced go.
>>
>> I have seen the database connection stuff and the pooling stuff so it
>> seems like I should not create another mysql connection in my java
>> code but I do not know how to get at and use the connection in cocoon.
>
> I cannot help you with that ModularDatabaseAction, but this is how I
> use the pooled connections in my own java components:
>
>
> public class ... implements Serviceable {
>
> protected ServiceSelector dataSourceSelector;
>
> public void service(ServiceManager manager) throws ServiceException {
> try {
> dataSourceSelector = (ServiceSelector)
> manager.lookup(DataSourceComponent.ROLE + "Selector");
> } catch (ServiceException e) {
> throw new CascadingRuntimeException("DataSource selector is
> not available.", e);
> }
> }
>
> // this is a wrapper for using JDBI. you can take it out if you'd
> rather use JDBC directly
> private class DataSourceWrapper implements ConnectionFactory {
> private Connection conn;
> public DataSourceWrapper(Connection c) { conn = c; }
> public Connection getConnection() { return conn; }
> }
>
> // this is the main method of your action/transformer/input
> module/...
> public ...() {
> Connection conn = null;
> try {
>
> try {
> conn = ((DataSourceComponent)
> dataSourceSelector.select(DATASOURCE)).getConnection();
> } catch (Exception e) {
> throw new CascadingRuntimeException("Cannot get a connection
> for \""+DATASOURCE+"\".", e);
> }
> Handle DB = new DBI(new DataSourceWrapper(conn)).open();
>
> DB.query(...)
> DB.execute(...)
> ...
>
> } finally {
> try {
> if (conn != null) conn.close();
> } catch (Exception e) {
> throw new CascadingRuntimeException("Cannot close the
> connection for \""+DATASOURCE+"\".", e);
> }
> }
> }
> }
>
>
> HTH
> Tobia
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
> --
>
> This message has been verified by LastSpam eMail security service
>
> Ce courriel a été vérifié par le service de sécurité pour courriels
> LastSpam
> http://www.lastspam.com
>
>
Thanks for your help. This is what I was looking for. I'm on vacation so
I will try it when I get back.
Al
--
Al; Dir. Software Development; Light Technology Publishing
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: modular database action
Posted by Tobia Conforto <to...@linux.it>.
Al Brown wrote:
> I guess I can just put jdbc command in a java class and use the
> <map:act> to call the class but it looks likes a lot of good folks
> have already solved this problem but the solution is not obvious to
> me. I found the ModularDatabaseActions wiki pages but I have not
> found a how-to or tutorial and where all the pieced go.
>
> I have seen the database connection stuff and the pooling stuff so
> it seems like I should not create another mysql connection in my
> java code but I do not know how to get at and use the connection in
> cocoon.
I cannot help you with that ModularDatabaseAction, but this is how I
use the pooled connections in my own java components:
public class ... implements Serviceable {
protected ServiceSelector dataSourceSelector;
public void service(ServiceManager manager) throws
ServiceException {
try {
dataSourceSelector = (ServiceSelector)
manager.lookup(DataSourceComponent.ROLE + "Selector");
} catch (ServiceException e) {
throw new CascadingRuntimeException("DataSource selector is not
available.", e);
}
}
// this is a wrapper for using JDBI. you can take it out if you'd
rather use JDBC directly
private class DataSourceWrapper implements ConnectionFactory {
private Connection conn;
public DataSourceWrapper(Connection c) { conn = c; }
public Connection getConnection() { return conn; }
}
// this is the main method of your action/transformer/input
module/...
public ...() {
Connection conn = null;
try {
try {
conn = ((DataSourceComponent)
dataSourceSelector.select(DATASOURCE)).getConnection();
} catch (Exception e) {
throw new CascadingRuntimeException("Cannot get a connection for
\""+DATASOURCE+"\".", e);
}
Handle DB = new DBI(new DataSourceWrapper(conn)).open();
DB.query(...)
DB.execute(...)
...
} finally {
try {
if (conn != null) conn.close();
} catch (Exception e) {
throw new CascadingRuntimeException("Cannot close the connection for
\""+DATASOURCE+"\".", e);
}
}
}
}
HTH
Tobia
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: modular database action
Posted by warrell harries <wa...@googlemail.com>.
I recommend you look at the sqltransformer component. Try the examples
and you should find this is the most generic approach
On 11/02/2008, Al Brown <al...@yahoo.com> wrote:
> I'm trying to figure out how to use a mysql database in an cocoon action.
> I'm using cocoon 2.1.10
>
> I have a mysql database and forms for all the attributes of all the
> tables. When the form action returns the new values for
> all the attributes in a table what is the recommended way to get a basic
> sql update to happen.
>
> I found the modulardatabaseAction wiki document and I can see how I can
> make a descriptor file that describes a table but
>
> 1) where does this file go.
> 2) how does the sql update command get created?
>
> I guess I can just put jdbc command in a java class and use the
> <map:act> to call the class but it looks likes a
> lot of good folks have already solved this problem but the solution is
> not obvious to me. I found the ModularDatabaseActions wiki pages
> but I have not found a how-to or tutorial and where all the pieced go.
>
> I have seen the database connection stuff and the pooling stuff so it
> seems like I should not create another mysql connection in my java code
> but I do not know how to get at and use the connection in cocoon.
>
> I can query my database using the sql transform and that works great.
> Now I need to get data back into the tables.
>
> Al
>
> --
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org