bug with PGXADataSource in JNDI

Поиск
Список
Период
Сортировка
Искать

bug with PGXADataSource in JNDI

От:
Jonathan Halliday <jonathan.halliday@redhat.com>
Дата:

Hello JDBC driver developers

I have a requirement to store and retrieve PGXADataSource 
instances from JNDI, specifically using Sun's fscontext 
provider.

I can get instances into JNDI no problem and they are 
written out to the .bindings file.

I can't retrieve them because 
PGObjectFactory.getObjectInstance does not know about 
ClassName=org.postgresql.xa.PGXADataSource

Please would one of the developers address this for the next 
8.1 driver release.

Thanks

Jonathan Halliday
JBoss, a division of Red Hat

Re: bug with PGXADataSource in JNDI

От:
Heikki Linnakangas <heikki@enterprisedb.com>
Дата:
Jonathan Halliday wrote:
> 
> Hello JDBC driver developers
> 
> I have a requirement to store and retrieve PGXADataSource instances from 
> JNDI, specifically using Sun's fscontext provider.
> 
> I can get instances into JNDI no problem and they are written out to the 
> .bindings file.
> 
> I can't retrieve them because PGObjectFactory.getObjectInstance does not 
> know about ClassName=org.postgresql.xa.PGXADataSource
> 
> Please would one of the developers address this for the next 8.1 driver 
> release.

I can write the patch to fix that. Do you happen to have a simple test 
case I can use to test it?

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

Re: bug with PGXADataSource in JNDI

От:
Heikki Linnakangas <heikki@enterprisedb.com>
Дата:
Heikki Linnakangas wrote:
> Jonathan Halliday wrote:
>>
>> Hello JDBC driver developers
>>
>> I have a requirement to store and retrieve PGXADataSource instances 
>> from JNDI, specifically using Sun's fscontext provider.
>>
>> I can get instances into JNDI no problem and they are written out to 
>> the .bindings file.
>>
>> I can't retrieve them because PGObjectFactory.getObjectInstance does 
>> not know about ClassName=org.postgresql.xa.PGXADataSource
>>
>> Please would one of the developers address this for the next 8.1 
>> driver release.
> 
> I can write the patch to fix that. Do you happen to have a simple test 
> case I can use to test it?

Thanks, I got your test case off-list.

Here's the patch against CVS head. It should apply cleanly to 8.1 branch 
as well.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
? xa-PGObjectFactory-fix.patch
? xa-endthenjoin-2.diff
? xa-endthenjoin.diff
Index: org/postgresql/ds/common/PGObjectFactory.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/ds/common/PGObjectFactory.java,v
retrieving revision 1.5
diff -c -r1.5 PGObjectFactory.java
*** org/postgresql/ds/common/PGObjectFactory.java	11 Jan 2005 08:25:45 -0000	1.5
--- org/postgresql/ds/common/PGObjectFactory.java	26 Feb 2007 16:59:38 -0000
***************
*** 14,19 ****
--- 14,20 ----
  import java.util.Hashtable;
  
  import org.postgresql.ds.*;
+ import org.postgresql.xa.PGXADataSource;
  
  /**
   * Returns a DataSource-ish thing based on a JNDI reference.  In the case of a
***************
*** 42,47 ****
--- 43,52 ----
          {
              return loadSimpleDataSource(ref);
          }
+         else if (className.equals("org.postgresql.xa.PGXADataSource"))
+         {
+             return loadXADataSource(ref);
+         }
          else if (className.equals("org.postgresql.ds.PGConnectionPoolDataSource")
                   || className.equals("org.postgresql.jdbc2.optional.ConnectionPool")
                   || className.equals("org.postgresql.jdbc3.Jdbc3ConnectionPool"))
***************
*** 92,97 ****
--- 97,108 ----
          return loadBaseDataSource(ds, ref);
      }
  
+     private Object loadXADataSource(Reference ref)
+     {
+         PGXADataSource ds = new PGXADataSource();
+         return loadBaseDataSource(ds, ref);
+     }
+ 
      private Object loadConnectionPool(Reference ref)
      {
          PGConnectionPoolDataSource cp = new PGConnectionPoolDataSource();

Re: bug with PGXADataSource in JNDI

От:
Kris Jurka <books@ejurka.com>
Дата:


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.

Kris Jurka

Re: bug with PGXADataSource in JNDI

От:
Heikki Linnakangas <heikki@enterprisedb.com>
Дата:
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);
+     }
+ }

Re: bug with PGXADataSource in JNDI

От:
Kris Jurka <books@ejurka.com>
Дата:


On Mon, 26 Feb 2007, Heikki Linnakangas wrote:

> 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..

Applied to 8.1, 8.2, and CVS HEAD.

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

Unfortunately yes, and finding linux machines I can still run 1.2 JDKs on 
is getting tougher and tougher.

Kris Jurka
FAQ