Re: Switching between test and production environment?

From: Tore Halset (halse..vv.ntnu.no)
Date: Thu Nov 11 2004 - 03:34:34 EST

  • Next message: Andreas Pardeike: "Bug? umlaut in column names?"

    On Nov 11, 2004, at 9:02, Andreas Pardeike wrote:

    > I wonder if there is an easy way to switch between driver and/or
    > table definitions that change between my local dev environment and
    > my production environment?

    I am happy with JNDI. My cayenne applications are packed in war's and
    deployed using jboss+tomcat. I run several instances of the same
    cayenne application on the same server. Each cayenne application
    connects to a separate database. I am using a separate configuration
    file that specify that "gurba.war" should use java:/gurbaDS etc.

    My application detects the database type and set the correct Adapter.
    It is working, but I would likt this to be a standard part of cayenne.
    I am using PostgreSQL for development and we are (currently) using MS
    SQL Server for testing and production.

             if (!cayenneAdapterSet) {
                 DataDomain domain =
    Configuration.getSharedConfiguration().getDomain();
                 DataNode node = domain.getNode("mydatanode");

                 Connection conn = null;
                 try {
                     conn = getConnection();
                     String driverName = conn.getMetaData().getDriverName();
                     if (driverName.startsWith("PostgreSQL")) {
                         log.info("use cayenne PostgresAdapter");
                         node.setAdapter(new PostgresAdapter());
                     } else if (driverName.startsWith("SQLServer")) {
                         log.info("use cayenne SQLServerAdapter");
                         node.setAdapter(new SQLServerAdapter());
                     } else if (driverName.startsWith("jTDS")
                             && (driverName.indexOf("MS SQL Server") >= 0)) {
                         log.info("use cayenne SQLServerAdapter");
                         node.setAdapter(new SQLServerAdapter());
                     } else {
                         log.error("could not find cayenne db adapter for "
    + driverName);
                         node.setAdapter(new JdbcAdapter());
                     }
                     cayenneAdapterSet = true;
                 } catch (SQLException e) {
                     log.error("failed setting cayenne db adapter", e);
                 } finally {
                     clearUp(conn, null, null);
                 }
             }

    Regards,
      - Tore.



    This archive was generated by hypermail 2.0.0 : Thu Nov 11 2004 - 03:34:46 EST