Custom Configuration Question

From: Dov Rosenberg (dov.rosenber..onviveon.com)
Date: Mon Jan 16 2006 - 16:54:23 EST

  • Next message: Andrus Adamchik: "Re: Cayenne 3t returning DataObjects instead of Persistent"

    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?



    This archive was generated by hypermail 2.0.0 : Mon Jan 16 2006 - 16:54:31 EST