1
package org.postgresql.jdbc3;
4
import org.postgresql.jdbc2.optional.PoolingDataSource;
5
import org.postgresql.jdbc2.optional.ConnectionPool;
7
import javax.naming.Reference;
10
* JDBC 3 implementation of a pooling DataSource. This is best
11
* used outside of an application server environment. Application
12
* servers generally prefer to deal with instances of
13
* ConnectionPoolDataSource (see ConnectionPool) or XADataSource
14
* (not available for PostgreSQL).
16
* @author Aaron Mulder (ammulder@alumni.princeton.edu)
17
* @version $Revision: 1.1 $
19
public class Jdbc3PoolingDataSource extends PoolingDataSource
22
* Store JDBC3 DataSources in different bucket than JDBC2 DataSources
24
private static Map dataSources = new HashMap();
27
* Store JDBC3 DataSources in different bucket than JDBC2 DataSources
29
static Jdbc3PoolingDataSource getDataSource(String name)
31
return (Jdbc3PoolingDataSource) dataSources.get(name);
35
* Store JDBC3 DataSources in different bucket than JDBC2 DataSources
37
protected void removeStoredDataSource()
39
synchronized (dataSources)
41
dataSources.remove(dataSourceName);
46
* Store JDBC3 DataSources in different bucket than JDBC2 DataSources
48
public void setDataSourceName(String dataSourceName)
52
throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used");
54
if (this.dataSourceName != null && dataSourceName != null && dataSourceName.equals(this.dataSourceName))
58
synchronized (dataSources)
60
if (getDataSource(dataSourceName) != null)
62
throw new IllegalArgumentException("DataSource with name '" + dataSourceName + "' already exists!");
64
if (this.dataSourceName != null)
66
dataSources.remove(this.dataSourceName);
68
this.dataSourceName = dataSourceName;
69
dataSources.put(dataSourceName, this);
74
* Generates a JDBC3 object factory reference.
76
protected Reference createReference()
78
return new Reference(getClass().getName(), Jdbc3ObjectFactory.class.getName(), null);
82
* Creates a JDBC3 ConnectionPool to use with this DataSource.
84
protected ConnectionPool createConnectionPool()
86
return new Jdbc3ConnectionPool();
90
* Gets a description of this DataSource.
92
public String getDescription()
94
return "JDBC3 Pooling DataSource from " + org.postgresql.Driver.getVersion();