Re: set DB Adapter from jdbc-Driver?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Jan 07 2004 - 10:17:12 EST

  • Next message: Andrus Adamchik: "Re: default schema"

    On Jan 5, 2004, at 6:25 AM, Tore Halset wrote:

    > Hello.
    >
    > I have one application that uses two different databases. I am using
    > JNDIDataSourceFactory and with two different database types (MS SQL
    > Server and PostgreSQL). It would be realy nice if cayenne could
    > discover and use the correct DB Adapter based on the actual
    > jdbc-Driver. Can it be done? How?
    >
    > - Tore.

    Currently this can be done manually. Since adapter has no stored state
    related to project configuration, it can be set per DataNode at any
    time. For example this can be done during app startup:

    DataDomain domain = Configuration.getSharedConfiguration().getDomain();
    DataNode node = domain.getNode("MyNode");

    DataSource ds = node.getDataSource();
    if(ds instanceof org.objectstyle.cayenne.conn.PoolManager) {
         String driverClass = ((PoolManager)ds).getJdbcDriver();
         if(driverClass.startsWith("com.mysql")) {
             node.setAdapter(new MySQLAdapter());
         }
         else if .... {

         }
    }
    else {
       // if this is a container provided DataSource,
       // it is still possible to determine its origin, but it is
    environment specific....
    }

    The limitation is that such simplistic approach won't work for Oracle
    that uses a subclass of the DataNode.

    Andrus



    This archive was generated by hypermail 2.0.0 : Wed Jan 07 2004 - 10:17:16 EST