5. Configuring C-JDBC with 3rd party software

5.1. Forenotes on configuring C-JDBC with your application

If the application you are using C-JDBC with requires a mapper, the best thing to do is to configure the mapping to be that of C-JDBC's underlying databases. For example, if you were using JBoss with PostgreSQL , then using C-JDBC on top of the PostgreSQL backends with JBoss would imply to still use the mapping for PostgreSQL while plugging the application server to C-JDBC (using C-JDBC's driver and C-JDBC's url).

5.2. Configuring C-JDBC with Jakarta Tomcat

Copy the c-jdbc-driver.jar file to the lib directory of your web application (for example: $TOMCAT_HOME/webapps/mywebapp/WEB-INF/lib).

There are many ways to obtain connections from a Tomcat application. Just ensure that you are using org.objectweb.cjdbc.driver.Driver as the driver class name and that the JDBC URL is a C-JDBC URL (see Section 4.3, “C-JDBC JDBC URL”).

5.3. Configuring C-JDBC with JOnAS

The c-jdbc-driver.jar file must be found in the JOnAS CLASSPATH.

Here is an example of a cjdbc.properties file to store in JONAS 3.x conf directory (use the config directory for JOnAS 2.x):

        ###################### C-JDBC DataSource configuration example # 
        datasource.name      jdbc_1 
        datasource.url       jdbc:cjdbc://someMachine/someDatabase 
        datasource.classname org.objectweb.cjdbc.driver.Driver 
        datasource.username  your-username 
        datasource.password  your-password 

5.4. Configuring C-JDBC with JBoss

Copy the c-jdbc-driver.jar file to $JBOSS_DIST/server/default/lib for JBoss 3.x or to $JBOSS_DIST/jboss/lib/ext for JBoss 2.x.

Here is an example of a datasource configuration file to be used with JBoss:

        <?xml version="1.0" encoding="UTF-8"?> 
        <!-- ===================================================================== --> 
        <!--                                                                       --> 
        <!-- JBoss Server Configuration                                            -->
        <!--                                                                       --> 
        <!-- ===================================================================== --> 

        <!-- ===================================================================== --> 
        <!-- Datasource config for C-JDBC                                          -->
        <!-- ===================================================================== --> 

5.5. Configuring C-JDBC with BEA Weblogic Server 7.x/8.x

Place the c-jdbc-driver.jar file in the classpath of the Weblogic Server.

Here is an example of a connection pool configuration for use with Weblogic:

        InitialCapacity="1"  MaxCapacity="15" 
        Name="cjdbcPool" Properties="user=username;password=password" 
        ShrinkingEnabled="true" SupportsLocalTransaction="true" 
        Targets="wlservername" URL="jdbc:cjdbc://" 

Next, create the required TXDataSources:

        <JDBCTxDataSource EnableTwoPhaseCommit="true" 
          JNDIName="cjdbc-DS" Name="C-JDBC TX Data Source" 
          PoolName="cjdbcPool" RowPrefetchEnabled="true" Targets="wlservername"/>

5.6. Configuring C-JDBC with Hibernate

C-JDBC just has to be defined as any JDBC driver in Hibernate, leaving the syntax set to the proper database. Here is a configuration example to use Hibernate with a C-JDBC cluster made of Sybase backends:

hibernate.dialect                 net.sf.hibernate.dialect.SybaseDialect
hibernate.connection.driver_class org.objectweb.cjdbc.driver.Driver
hibernate.connection.username     user
hibernate.connection.password     pass
hibernate.connection.url          jdbc:cjdbc://localhost:25322/test        

5.7. Using sequences with Hibernate, C-JDBC and PostgreSQL

Our Hibernate dialect is as follows:

        import net.sf.hibernate.dialect.PostgreSQLDialect; 
        public class CJDBCPostgreSQLDialect extends PostgreSQLDialect 
          public String getSequenceNextValString(String sequenceName) 
            return "{call nextval('"+sequenceName+"')}"; 

We simply extend the default PostgreSQL Dialect and override the getSequenceNextValString() method and tell it to use "{call ..." so that all the sequences in the cluster get incremented.

We then changed our Hibernate conf file to user to our custom dialect instead of net.sf.hibernate.dialect.PostgreSQLDialect.