[libpostgresql-jdbc-java] 04/10: Fix persistence of XA datasources. PGObjectFactory wasn't aware of PGXADataSource and can't be because of the requirements for different build versions. Add a new PGXADataSourceFactory to provide this functionality.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:00 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_409
in repository libpostgresql-jdbc-java.

commit 04fcfc1064e129038eec6059d681ab046a889107
Author: Kris Jurka <books at ejurka.com>
Date:   Mon Feb 26 19:24:46 2007 +0000

    Fix persistence of XA datasources.  PGObjectFactory wasn't aware of
    PGXADataSource and can't be because of the requirements for different
    build versions.  Add a new PGXADataSourceFactory to provide this
    functionality.
    
    Heikki Linnakangas
---
 org/postgresql/xa/PGXADataSource.java        | 11 +++++++
 org/postgresql/xa/PGXADataSourceFactory.java | 47 ++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/org/postgresql/xa/PGXADataSource.java b/org/postgresql/xa/PGXADataSource.java
index ddb54e0..b5966ae 100644
--- a/org/postgresql/xa/PGXADataSource.java
+++ b/org/postgresql/xa/PGXADataSource.java
@@ -4,6 +4,7 @@ import java.sql.Connection;
 import java.sql.SQLException;
 
 import javax.naming.Referenceable;
+import javax.naming.Reference;
 import javax.sql.XAConnection;
 import javax.sql.XADataSource;
 
@@ -50,4 +51,14 @@ public class PGXADataSource extends BaseDataSource implements Referenceable, XAD
     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);
+    }
 }
diff --git a/org/postgresql/xa/PGXADataSourceFactory.java b/org/postgresql/xa/PGXADataSourceFactory.java
new file mode 100644
index 0000000..eb3a238
--- /dev/null
+++ b/org/postgresql/xa/PGXADataSourceFactory.java
@@ -0,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);
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list