1
package org.postgresql.jdbc3;
5
import org.postgresql.jdbc2.optional.PGObjectFactory;
8
* JDBC3 version of the Object Factory used to recreate objects
9
* from their JNDI references.
11
* @author Aaron Mulder (ammulder@alumni.princeton.edu)
12
* @version $Revision: 1.1 $
14
public class Jdbc3ObjectFactory extends PGObjectFactory
17
* Dereferences a PostgreSQL DataSource. Other types of references are
20
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
21
Hashtable environment) throws Exception
23
Reference ref = (Reference) obj;
24
if (ref.getClassName().equals(Jdbc3SimpleDataSource.class.getName()))
26
return loadSimpleDataSource(ref);
28
else if (ref.getClassName().equals(Jdbc3ConnectionPool.class.getName()))
30
return loadConnectionPool(ref);
32
else if (ref.getClassName().equals(Jdbc3PoolingDataSource.class.getName()))
34
return loadPoolingDataSource(ref);
42
private Object loadPoolingDataSource(Reference ref)
44
// If DataSource exists, return it
45
String name = getProperty(ref, "dataSourceName");
46
Jdbc3PoolingDataSource pds = Jdbc3PoolingDataSource.getDataSource(name);
51
// Otherwise, create a new one
52
pds = new Jdbc3PoolingDataSource();
53
pds.setDataSourceName(name);
54
loadBaseDataSource(pds, ref);
55
String min = getProperty(ref, "initialConnections");
58
pds.setInitialConnections(Integer.parseInt(min));
60
String max = getProperty(ref, "maxConnections");
63
pds.setMaxConnections(Integer.parseInt(max));
68
private Object loadSimpleDataSource(Reference ref)
70
Jdbc3SimpleDataSource ds = new Jdbc3SimpleDataSource();
71
return loadBaseDataSource(ds, ref);
74
private Object loadConnectionPool(Reference ref)
76
Jdbc3ConnectionPool cp = new Jdbc3ConnectionPool();
77
return loadBaseDataSource(cp, ref);