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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to