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).
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”).
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
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 --> <!-- ===================================================================== --> <datasources> <local-tx-datasource> <jndi-name>cjdbc-DS</jndi-name> <connection-url>jdbc:cjdbc://localhost:25322/lscluster</connection-url> <driver-class>org.objectweb.cjdbc.driver.Driver</driver-class> <user-name>user</user-name> <password>tagada</password> </local-tx-datasource> </datasources>
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:
<JDBCConnectionPool DriverName="org.objectweb.cjdbc.driver.Driver" InitialCapacity="1" MaxCapacity="15" Name="cjdbcPool" Properties="user=username;password=password" ShrinkingEnabled="true" SupportsLocalTransaction="true" Targets="wlservername" URL="jdbc:cjdbc://192.168.0.1/vdb" XAPreparedStatementCacheSize="0"/>
Next, create the required TXDataSources:
<JDBCTxDataSource EnableTwoPhaseCommit="true" JNDIName="cjdbc-DS" Name="C-JDBC TX Data Source" PoolName="cjdbcPool" RowPrefetchEnabled="true" Targets="wlservername"/>
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:
## C-JDBC 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
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.