Re: using cayenne data connection pools with struts.

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Nov 06 2003 - 21:07:04 EST

  • Next message: Andrus Adamchik: "Re: using cayenne data connection pools with struts."

    Hi Mike,

    If I understand correctly, you are not using ORM features of Cayenne in
    your app, and simply using it as a DataSource provider for a Struts app
    that otherwise uses JDBC, right? You maybe loosing quiet some
    functionality this way. ;-) If this is not the case, you can obtain
    DataSource from Cayenne DataNode.

    While sometime back I indeed advocated a standalone use of Cayenne
    "conn" package, in the last few releases we decided that supporting a
    standalone DataSource is somewhat outside the scope of Cayenne, and is
    not our priority:

    http://objectstyle.org/cayenne/userguide/design/datasrc.html

    Now back to your problem.... Per Struts FAQ at

    http://jakarta.apache.org/struts/faqs/database.html

    " The Struts DataSource manager is configured as an element in the
    Struts configuration file (struts-config.xml). The manager can be used
    to deploy any connection pool that implements the javax.sql.DataSource
    interface and is configurable totally from JavaBean properties. If your
    DBMS or container provides a connection pool that meets these
    requirements, then that component might be your first choice."

    Note that "configurable totally from JavaBean properties" doesn't
    exactly apply to PoolManager. It doesn't have a no-arg constructor (I
    think this is what is causing the error you are seeing), and expects
    all parameters to be passed in constructor instead of calling "setXYZ".
    The good news is that you can easily write a simple bean wrapper for
    it, that collects parameters via set methods, and on the first call to
    "getConnection" instantiates a PoolManager, further delegating all
    calls to it. You can subclass another Cayenne class, DataSourceInfo to
    make it easier. Something like this:

    public class MyPool extends org.objectstyle.cayenne.conn.DataSourceInfo
    implements DataSource {
        PoolManager realPool;

       public Connection getConnection() throws SQLException {
            checkRealPool();
            return realPool;
       }

       private synchronized void checkRealPool() {
          if(realPool == null) {
            realPool = new PoolManager(...);
          }
        }
        ....
    }

    Regards
    Andrus

    On Nov 6, 2003, at 3:18 PM, Mike Block wrote:

    > Hi,
    > I am trying to figure out how to use Cayenne's db connection
    > pooling with struts. Are there any examples showing this?
    >
    > What I have tried is:
    > I have create a data-source in the struts config file:
    > my host, my database, etc are obviously filled in with correct
    > values.... :-)
    >
    > <data-sources>
    > <data-source type="org.objectstyle.cayenne.conn.PoolManager">
    > <set-property property="dataSourceUrl" value="jdbc:postgresql://<my
    > host>/<my database>"/>
    > <set-property property="jdbcDriver" value="org.postgresql.Driver"/>
    > <set-property property="maxConnections" value="5"/>
    > <set-property property="minConnections" value="2"/>
    > <set-property property="userName" value="<my username>"/>
    > <set-property property="password" value="<my password>"/>
    > </data-source>
    > </data-sources>
    >
    >
    > The webapp fails to load with the following stack trace:
    > NB : ExtendedActionServlet is mine which currently just calls
    > super.init(), super.initModulesConfig() methods [it does nothing].
    >
    > ERROR ActionServlet: Initializing application data source
    > org.apache.struts.action.DATA_SOURCE
    > java.lang.InstantiationException:
    > org.objectstyle.cayenne.conn.PoolManager



    This archive was generated by hypermail 2.0.0 : Thu Nov 06 2003 - 21:07:15 EST