Geronimo_MoinMoin_wiki > OpenJCA
Added by Confluence Administrator, last edited by Confluence Administrator on Aug 02, 2006

''About''

OpenJCA is a JCA JDBC Implementation.

Building

  • Get the source code of OpenJCA version of openejb jca-jdbc wrapper from JCA Impl for OpenEJB
  • run gzip -d openjca.tar.gz followed by tar -xvf openjca.tar to extract the sources or simply tar zxvf openjca[1].tar.gz if you're lucky enough to work with GNU tar
  • Go to openjca directory and run maven build

Installing

NOTE: Unless stated otherwise, it's assumed the commands are performed from openjca directory.

  • drop target/openejb-jca-DEV.jar into Geronimo's target/geronimo-DEV/lib
  • copy src/resources/META-INF directory to Geronimo's target/geronimo-DEV/deploy directory (or target/geronimo-DEV/petstore if you're installing PetStore, so it will become logically connected)
  • Edit META-INF/geronimo-ra.xml, which has already been copied to Geronimo's target/geronimo-DEV/deploy or other monitored directory (see step above), to reflect your requirements.

META-INF/geronimo-ra.xml for PetStore that sets up a datasource to HSQL database with sa as a username and empty password. The name of the datasource is petstoredb:

  • <?xml version="1.0" encoding="UTF-8"?>
    
    <connector xmlns="http://org.apache.geronimo/xml/ns/j2ee"
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:SchemaLocation="http://org.apache.geronimo/xml/ns/j2ee geronimo-connector_1_5.xsd">
      <resourceadapter>
        <outbound-resourceadapter>
          <connection-definition>
            <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
            <name>petstoredb</name>
            <config-property-setting name="DefaultUserName" >sa</config-property-setting>
            <config-property-setting name="DefaultPassword" ><!-- empty --></config-property-setting>
            <config-property-setting name="JdbcDriver" >org.hsqldb.jdbcDriver</config-property-setting>
            <config-property-setting name="JdbcUrl" >jdbc:hsqldb:.</config-property-setting>
            <connectionmanager-factory>
              <connectionmanagerfactory-descriptor>org.apache.geronimo.connector.outbound.ConnectionManagerDeployment</connectionmanagerfactory-descriptor>
              <config-property-setting name="UseConnectionRequestInfo">false</config-property-setting>
              <config-property-setting name="UseSubject">false</config-property-setting>
              <config-property-setting name="UseTransactionCaching">true</config-property-setting>
              <config-property-setting name="UseTransactions">true</config-property-setting>
              <config-property-setting name="UseLocalTransactions">true</config-property-setting>
              <config-property-setting name="MaxSize">100</config-property-setting>
              <config-property-setting name="BlockingTimeout">5000</config-property-setting>
              <config-property-setting name="Name">petstoredb</config-property-setting>
            </connectionmanager-factory>
          </connection-definition>
        </outbound-resourceadapter>
      </resourceadapter>
    </connector>

Using the datasource in an application boils down to declare the name of that datasource in Geronimo deployment descriptor, i.e. META-INF/geronimo-ejb-jar.xml for EJBs and WEB-INF/geronimo-web.xml for WARs.

  1. Declaring a datasource in web applications is done using <jndi-name> element. It expects the name of a connection factory's JMX MBean. In other words, unless the name is visible in Geronimo Web Console, the datasource won't work for the web app.
  •   <resource-ref>
        <description>Allow the Fast Lane Reader Pattern to Read Catalog Data Directly via JDBC in the Web Tier</description>
        <res-ref-name>jdbc/CatalogDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <jndi-name>geronimo.management:j2eeType=JCAManagedConnectionFactory,name=petstoredb</jndi-name>
      </resource-ref>
    1. Declaring a datasource for CMP Entity EJBs is done using <datasource-name> element of <ejb-jar>. It expects the name of a datasource as declared in META-INF/geronimo-ra.xml of J2EECA JDBC implementation.
        <datasource-name>petstoredb</datasource-name>
      
  • Start up Geronimo
  • Open up Geronimo web console (http://localhost:8080/geronimo-web-console) and enter geronimo.management:* as a filter. You should see 2 entries with petstoredb in the name.
    geronimo.management
      j2eeType=ConnectionManager,name=petstoredb 
      j2eeType=JCAManagedConnectionFactory,name=petstoredb