summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java
diff options
context:
space:
mode:
authorBarry Lind <barry@xythos.com>2002-09-25 07:01:31 +0000
committerBarry Lind <barry@xythos.com>2002-09-25 07:01:31 +0000
commit7bf1c8b0ad5f2534362fb6938be28bb041d79c90 (patch)
tree4e12707f3fb34f61d91c24f6b4b86cee49596c62 /src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java
parent65bf5a39e08ed5ae395725c8353714482a8ec132 (diff)
downloadpostgresql-7bf1c8b0ad5f2534362fb6938be28bb041d79c90.tar.gz
Applied patch from Aaron Mulder (ammulder@alumni.princeton.edu) that fixes
jdbc datasource support for jdk1.4/jdbc3 Modified Files: jdbc/build.xml jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/jdbc2/optional/BaseDataSource.java jdbc/org/postgresql/jdbc2/optional/PGObjectFactory.java jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java jdbc/org/postgresql/jdbc2/optional/PoolingDataSource.java jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java jdbc/org/postgresql/test/jdbc2/optional/OptionalTestSuite.java jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java Added Files: jdbc/org/postgresql/jdbc3/Jdbc3ConnectionPool.java jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java jdbc/org/postgresql/jdbc3/Jdbc3PooledConnection.java jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java jdbc/org/postgresql/jdbc3/Jdbc3SimpleDataSource.java jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java jdbc/org/postgresql/test/jdbc3/Jdbc3ConnectionPoolTest.java jdbc/org/postgresql/test/jdbc3/Jdbc3PoolingDataSourceTest.java jdbc/org/postgresql/test/jdbc3/Jdbc3SimpleDataSourceTest.java jdbc/org/postgresql/test/util/MiniJndiContext.java jdbc/org/postgresql/test/util/MiniJndiContextFactory.java
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java
new file mode 100644
index 0000000000..df3e50ad07
--- /dev/null
+++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java
@@ -0,0 +1,96 @@
+package org.postgresql.jdbc3;
+
+import java.util.*;
+import org.postgresql.jdbc2.optional.PoolingDataSource;
+import org.postgresql.jdbc2.optional.ConnectionPool;
+
+import javax.naming.Reference;
+
+/**
+ * JDBC 3 implementation of a pooling DataSource. This is best
+ * used outside of an application server environment. Application
+ * servers generally prefer to deal with instances of
+ * ConnectionPoolDataSource (see ConnectionPool) or XADataSource
+ * (not available for PostgreSQL).
+ *
+ * @author Aaron Mulder (ammulder@alumni.princeton.edu)
+ * @version $Revision: 1.1 $
+ */
+public class Jdbc3PoolingDataSource extends PoolingDataSource
+{
+ /**
+ * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
+ */
+ private static Map dataSources = new HashMap();
+
+ /**
+ * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
+ */
+ static Jdbc3PoolingDataSource getDataSource(String name)
+ {
+ return (Jdbc3PoolingDataSource) dataSources.get(name);
+ }
+
+ /**
+ * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
+ */
+ protected void removeStoredDataSource()
+ {
+ synchronized (dataSources)
+ {
+ dataSources.remove(dataSourceName);
+ }
+ }
+
+ /**
+ * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
+ */
+ public void setDataSourceName(String dataSourceName)
+ {
+ if (isInitialized())
+ {
+ throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used");
+ }
+ if (this.dataSourceName != null && dataSourceName != null && dataSourceName.equals(this.dataSourceName))
+ {
+ return;
+ }
+ synchronized (dataSources)
+ {
+ if (getDataSource(dataSourceName) != null)
+ {
+ throw new IllegalArgumentException("DataSource with name '" + dataSourceName + "' already exists!");
+ }
+ if (this.dataSourceName != null)
+ {
+ dataSources.remove(this.dataSourceName);
+ }
+ this.dataSourceName = dataSourceName;
+ dataSources.put(dataSourceName, this);
+ }
+ }
+
+ /**
+ * Generates a JDBC3 object factory reference.
+ */
+ protected Reference createReference()
+ {
+ return new Reference(getClass().getName(), Jdbc3ObjectFactory.class.getName(), null);
+ }
+
+ /**
+ * Creates a JDBC3 ConnectionPool to use with this DataSource.
+ */
+ protected ConnectionPool createConnectionPool()
+ {
+ return new Jdbc3ConnectionPool();
+ }
+
+ /**
+ * Gets a description of this DataSource.
+ */
+ public String getDescription()
+ {
+ return "JDBC3 Pooling DataSource from " + org.postgresql.Driver.getVersion();
+ }
+}