diff options
author | Barry Lind <barry@xythos.com> | 2002-09-25 07:01:31 +0000 |
---|---|---|
committer | Barry Lind <barry@xythos.com> | 2002-09-25 07:01:31 +0000 |
commit | 7bf1c8b0ad5f2534362fb6938be28bb041d79c90 (patch) | |
tree | 4e12707f3fb34f61d91c24f6b4b86cee49596c62 /src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java | |
parent | 65bf5a39e08ed5ae395725c8353714482a8ec132 (diff) | |
download | postgresql-7bf1c8b0ad5f2534362fb6938be28bb041d79c90.tar.gz postgresql-7bf1c8b0ad5f2534362fb6938be28bb041d79c90.zip |
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/Jdbc3ObjectFactory.java')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java new file mode 100644 index 00000000000..53151b80a24 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java @@ -0,0 +1,80 @@ +package org.postgresql.jdbc3; + +import java.util.*; +import javax.naming.*; +import org.postgresql.jdbc2.optional.PGObjectFactory; + +/** + * JDBC3 version of the Object Factory used to recreate objects + * from their JNDI references. + * + * @author Aaron Mulder (ammulder@alumni.princeton.edu) + * @version $Revision: 1.1 $ + */ +public class Jdbc3ObjectFactory extends PGObjectFactory +{ + /** + * Dereferences a PostgreSQL DataSource. Other types of references are + * ignored. + */ + public Object getObjectInstance(Object obj, Name name, Context nameCtx, + Hashtable environment) throws Exception + { + Reference ref = (Reference) obj; + if (ref.getClassName().equals(Jdbc3SimpleDataSource.class.getName())) + { + return loadSimpleDataSource(ref); + } + else if (ref.getClassName().equals(Jdbc3ConnectionPool.class.getName())) + { + return loadConnectionPool(ref); + } + else if (ref.getClassName().equals(Jdbc3PoolingDataSource.class.getName())) + { + return loadPoolingDataSource(ref); + } + else + { + return null; + } + } + + private Object loadPoolingDataSource(Reference ref) + { + // If DataSource exists, return it + String name = getProperty(ref, "dataSourceName"); + Jdbc3PoolingDataSource pds = Jdbc3PoolingDataSource.getDataSource(name); + if (pds != null) + { + return pds; + } + // Otherwise, create a new one + pds = new Jdbc3PoolingDataSource(); + pds.setDataSourceName(name); + loadBaseDataSource(pds, ref); + String min = getProperty(ref, "initialConnections"); + if (min != null) + { + pds.setInitialConnections(Integer.parseInt(min)); + } + String max = getProperty(ref, "maxConnections"); + if (max != null) + { + pds.setMaxConnections(Integer.parseInt(max)); + } + return pds; + } + + private Object loadSimpleDataSource(Reference ref) + { + Jdbc3SimpleDataSource ds = new Jdbc3SimpleDataSource(); + return loadBaseDataSource(ds, ref); + } + + private Object loadConnectionPool(Reference ref) + { + Jdbc3ConnectionPool cp = new Jdbc3ConnectionPool(); + return loadBaseDataSource(cp, ref); + } + +} |