Re: Custom Configuration Question

From: Dov Rosenberg (dov.rosenber..onviveon.com)
Date: Mon Jan 16 2006 - 21:47:12 EST

  • Next message: Andrus Adamchik: "Re: Custom Configuration Question"

    Thanks

    Our product is a commercial product that requires flexibility in deployment.
    Currently our EOF based solution stores the DB connection info in a well
    known location outside of the web app deployment folder.

    Our plan is to be able to support either JNDI or our current configuration
    file scheme.

    Is there some type of delegate class we can register or some type of event
    notification we can react to so that we can set our parameters?

    Maybe we can create our own subclass of DataSourceFactory that looks in our
    config file for either a JNDI name to lookup or the parameters we need for
    the file based datasource. Perhaps something like

    ....
    DataSourceFactory factory = null;
    If (param=="JNDI"){
        factory = new JNDIDataSourceFactory(jndiname);
    } else {
        factory = new DriverDataSourceFactory(configfilepath);
    }
    ...

    Question: For the DriverDataSourceFactory is there a way to provide the
    params such as driver class, URL, userid, passwd? It looks like there is
    some sort of XML file but I could not find the required format.

    On 1/16/06 7:53 PM, "Andrus Adamchik" <andru..bjectstyle.org> wrote:

    > I like using JNDI as that's a standard way to obtain DataSource in J2EE.
    >
    > If you'd still want to preserve the property files (which is fine too
    > of course), here is one possible solution - defer the real DataSource
    > creation with a custom org.objectstyle.cayenne.conf.DataSourceFactory
    > (can be set per DataNode in the Modeler):
    >
    > // DataSource that does nothing
    > class NoopDataSource implements DataSource {
    > ...
    > }
    >
    > public class NoopDataSourceFactory implements DataSourceFactory {
    > public DataSource getDataSource(String location) {
    > return new NoopDataSource();
    > }
    > }
    >
    > That'll get you started, i.e. your initialization code below will
    > work after the call to 'getSharedConfiguration'. But you can go
    > further and implement a smarter DataSourceFactory of course (such as
    > one actually reading the properties file inside 'getDataSource').
    >
    > Andrus
    >
    >
    > On Jan 16, 2006, at 4:54 PM, Dov Rosenberg wrote:
    >> We are trying to read and set our configuration information from an
    >> existing properties file. Below is the relevant code. We wrote an
    >> initialization Servlet with an init() method to do the
    >> initialization. Our cayenne deployment files do not contain any
    >> connection info. We want to deploy the app without any db connect
    >> info.
    >>
    >>
    >>
    >> Code:
    >> public static void init() {
    >> System.out.println("Initializing Database connections");
    >> try {
    >> String driver = IMWSConfiguration.getPropertyForKey("JDBCDriver");
    >> String url = IMWSConfiguration.getPropertyForKey("JDBCURL");
    >> String user = IMWSConfiguration.getPropertyForKey("JDBCUserid");
    >> String pass = IMWSConfiguration.getPropertyForKey("JDBCPassword");
    >> DataSource dataSource = new PoolManager(driver, url, 1, 5, user,
    >> pass);
    >>
    >> System.out.println("1");
    >> Configuration config = Configuration.getSharedConfiguration();
    >> System.out.println("2");
    >> DataDomain domain = config.getDomain();
    >> System.out.println("3");
    >> DataNode node = domain.getNode("IMDataNode");
    >> System.out.println("4");
    >> node.setDataSource(dataSource);
    >> System.out.println("5");
    >>
    >> System.out.println("Database OK");
    >> } catch (SQLException e) {
    >> e.printStackTrace();
    >> logger.error("Can't connect to database");
    >> System.out.println("Can't connect to database");
    >> logger.error(e);
    >>
    >> throw new IMDataException("Can't Connect to Database");
    >> }
    >>
    >> }
    >>
    >>
    >> Everything works except during the initialization the
    >> Configuration.getSharedConfiguration(); method generates the
    >> following output:
    >>
    >> Initializing Database connections
    >> 1
    >> - started configuration loading.
    >> - loaded domain: UntitledDomain
    >> - loaded <map name='Content' location='Content.map.xml'>.
    >> - loading <node name='IMDataNode'
    >> datasource='IMDataNode.driver.xml'
    >> factory='org.objectstyle.cayenne.conf.DriverDataSourceFactory'>.
    >> - using factory: org.objectstyle.cayenne.conf.DriverDataSourceFactory
    >> - loading driver information from 'IMDataNode.driver.xml'.
    >> - loading driver null
    >> - Created connection pool: null
    >> Driver class: null
    >> Min. connections in the pool: 1
    >> Max. connections in the pool: 1
    >> - loaded datasource.
    >> - no adapter set, using automatic adapter.
    >> - loaded map-ref: Content.
    >> - finished configuration loading in 629 ms.
    >> 2
    >>
    >> Our information gets set after the getSharedConfiguration() call
    >> and is correct, but the log output happens before our info is set.
    >> In the EOF world we listened for a ModelLoaded notification and
    >> intercepted it to perform our Connection Dictionary replacement.
    >> That worked great. Is there something similar in Cayenne?
    >>
    >>
    >

    -- 
    Dov Rosenberg
    Inquira Inc
    370 Centerpointe Circle, ste 1178
    Altamonte Springs, FL 32701
    (407) 339-1177 x 102
    (407) 339-6704 (fax)
    drosenber..nquira.com
    AOL IM: dovrosenberg
    



    This archive was generated by hypermail 2.0.0 : Mon Jan 16 2006 - 21:47:42 EST