Re: bug with PGXADataSource in JNDI - Mailing list pgsql-jdbc

From Heikki Linnakangas
Subject Re: bug with PGXADataSource in JNDI
Date
Msg-id 45E3274D.2070201@enterprisedb.com
Whole thread Raw
In response to Re: bug with PGXADataSource in JNDI  (Kris Jurka <books@ejurka.com>)
Responses Re: bug with PGXADataSource in JNDI
List pgsql-jdbc
Kris Jurka wrote:
> On Mon, 26 Feb 2007, Heikki Linnakangas wrote:
>
>> Here's the patch against CVS head. It should apply cleanly to 8.1
>> branch as well.
>>
>
> This fails to compile for the JDBC2-EE driver because it supports
> datasources, but not XA.

Oh, I see. Here's another patch that introduces a new
PGXADataSourceFactory instead of modifying the existing PGObjectFactory.
It's a bit inconsistent that XADataSources have a factory of their own
while others use the plain PGObjectFactory, but I can't get too excited
about this..

How do you test the different builds? Do you need a separate, older JDK
to build each edition?

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
? build.local.properties
? xa-PGObjectFactory-fix-2.patch
? xa-PGObjectFactory-fix.patch
? xa-endthenjoin-2.diff
? xa-endthenjoin.diff
Index: org/postgresql/xa/PGXADataSource.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/xa/PGXADataSource.java,v
retrieving revision 1.2
diff -c -r1.2 PGXADataSource.java
*** org/postgresql/xa/PGXADataSource.java    29 Oct 2005 18:59:39 -0000    1.2
--- org/postgresql/xa/PGXADataSource.java    26 Feb 2007 18:24:52 -0000
***************
*** 4,9 ****
--- 4,10 ----
  import java.sql.SQLException;

  import javax.naming.Referenceable;
+ import javax.naming.Reference;
  import javax.sql.XAConnection;
  import javax.sql.XADataSource;

***************
*** 50,53 ****
--- 51,64 ----
      public String getDescription() {
          return "JDBC3 XA-enabled DataSource from " + org.postgresql.Driver.getVersion();
      }
+
+     /**
+      * Generates a reference using the appropriate object factory.
+      */
+     protected Reference createReference() {
+         return new Reference(
+                    getClass().getName(),
+                    PGXADataSourceFactory.class.getName(),
+                    null);
+     }
  }
Index: org/postgresql/xa/PGXADataSourceFactory.java
===================================================================
RCS file: org/postgresql/xa/PGXADataSourceFactory.java
diff -N org/postgresql/xa/PGXADataSourceFactory.java
*** /dev/null    1 Jan 1970 00:00:00 -0000
--- org/postgresql/xa/PGXADataSourceFactory.java    26 Feb 2007 18:24:53 -0000
***************
*** 0 ****
--- 1,47 ----
+ /*-------------------------------------------------------------------------
+ *
+ * Copyright (c) 2007, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *   $PostgreSQL$
+ *
+ *-------------------------------------------------------------------------
+ */
+ package org.postgresql.xa;
+
+ import org.postgresql.ds.common.*;
+
+ import javax.naming.*;
+ import java.util.Hashtable;
+
+ /**
+  * An ObjectFactory implementation for PGXADataSource-objects.
+  */
+
+ public class PGXADataSourceFactory extends PGObjectFactory
+ {
+     /* All the other PostgreSQL DataSource use PGObjectFactory directly, but we
+      * can't do that with PGXADataSource because referencing PGXADataSource
+      * from PGObjectFactory would break "JDBC2 Enterprise" edition build which
+      * doesn't include PGXADataSource.
+      */
+
+     public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+                                     Hashtable environment) throws Exception
+     {
+         Reference ref = (Reference)obj;
+         String className = ref.getClassName();
+         if (className.equals("org.postgresql.xa.PGXADataSource"))
+         {
+             return loadXADataSource(ref);
+         }
+     else
+         return null;
+     }
+
+     private Object loadXADataSource(Reference ref)
+     {
+         PGXADataSource ds = new PGXADataSource();
+         return loadBaseDataSource(ds, ref);
+     }
+ }

pgsql-jdbc by date:

Previous
From: Gene
Date:
Subject: Re: does prepareThreshold work? forced to use old driver
Next
From: Kris Jurka
Date:
Subject: Re: bug with PGXADataSource in JNDI