users@glassfish.java.net

Using HA-JDBC in Glassfish

From: <glassfish_at_javadesktop.org>
Date: Sat, 10 Nov 2007 18:30:45 PST

I've dropped the required libs for HA-JDBC into <glassfish_root>/lib. Then I created the following ha-jdbc-0.xml configuration file:

<ha-jdbc>
<sync id="passive" class="net.sf.hajdbc.sync.PassiveSynchronizationStrategy"></sync>
<cluster balancer="load" dialect="mysql" meta-data-cache="lazy" transaction-mode="parallel" min-threads="0" max-threads="100" max-idle="60" detect-identity-columns="false" eval-current-date="true" eval-current-timestamp="true" eval-current-time="true" eval-rand="false" default-sync="passive" detect-sequences="false" failure-detect-schedule="0 * * ? * *" auto-activate-schedule="0 0 2 ? * *">
<datasource id="mysql-2" local="false" weight="1">
<name>java:comp/env/jdbc/sql1</name>
<user>***********</user>
<password>*************</password>
</datasource>
<datasource id="mysql-3" local="false" weight="1">
<name>java:comp/env/jdbc/sql2</name>
<user>*********</user>
<password>*********</password>
</datasource>
</cluster>
</ha-jdbc>

jdbc/sql1 and jdbc/sql2 have been created via the glassfish admin GUI using two connection pools, sql1-pool and sql2-pool. The beauty of that setup is that HA-JDBC can wrap one or more DataSources to obtain connections. Thus, glassfish components handle the connection pools for each SQL server and create the original DataSources to be wrapped.

So, now to create such a DataSource wrapping those two DataSources. Were I working in Tomcat, I would do the following:

[b]Add to server.xml <Context>:[/b]
<Resource name="jdbc/sql-cluster" type="javax.sql.DataSource"
          factory="net.sf.hajdbc.sql.DataSource"
          cluster="cluster2" config="file:///path/to/ha-jdbc-{0}.xml"/>

[b]And add the following to web.xml:[/b]
<resource-env-ref>
    <resource-env-ref-name>jdbc/sql-cluster</resource-env-ref-name>
    <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>

I can still make the addition to the web.xml, but I'm not sure how to create the resource above. When I try to create a new JDBC resource through the admin GUI, it forces me to choose a connection pool. But this resource doesn't use a connection pool, it wraps other DataSources.

How can I create this resource?
[Message sent by forum member 'rwillie6' (rwillie6)]

http://forums.java.net/jive/thread.jspa?messageID=244929