~ubuntu-branches/ubuntu/gutsy/libpgjava/gutsy

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2005-04-21 14:25:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050421142511-wibh5vc31fkrorx7
Tags: 7.4.7-3
Built with sources...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.postgresql.jdbc3;
 
2
 
 
3
import java.util.*;
 
4
import org.postgresql.jdbc2.optional.PoolingDataSource;
 
5
import org.postgresql.jdbc2.optional.ConnectionPool;
 
6
 
 
7
import javax.naming.Reference;
 
8
 
 
9
/**
 
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).
 
15
 *
 
16
 * @author Aaron Mulder (ammulder@alumni.princeton.edu)
 
17
 * @version $Revision: 1.1 $
 
18
 */
 
19
public class Jdbc3PoolingDataSource extends PoolingDataSource
 
20
{
 
21
    /**
 
22
     * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
 
23
     */
 
24
    private static Map dataSources = new HashMap();
 
25
 
 
26
    /**
 
27
     * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
 
28
     */
 
29
    static Jdbc3PoolingDataSource getDataSource(String name)
 
30
    {
 
31
        return (Jdbc3PoolingDataSource) dataSources.get(name);
 
32
    }
 
33
 
 
34
    /**
 
35
     * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
 
36
     */
 
37
    protected void removeStoredDataSource()
 
38
    {
 
39
        synchronized (dataSources)
 
40
        {
 
41
            dataSources.remove(dataSourceName);
 
42
        }
 
43
    }
 
44
 
 
45
    /**
 
46
     * Store JDBC3 DataSources in different bucket than JDBC2 DataSources
 
47
     */
 
48
    public void setDataSourceName(String dataSourceName)
 
49
    {
 
50
        if (isInitialized())
 
51
        {
 
52
            throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used");
 
53
        }
 
54
        if (this.dataSourceName != null && dataSourceName != null && dataSourceName.equals(this.dataSourceName))
 
55
        {
 
56
            return;
 
57
        }
 
58
        synchronized (dataSources)
 
59
        {
 
60
            if (getDataSource(dataSourceName) != null)
 
61
            {
 
62
                throw new IllegalArgumentException("DataSource with name '" + dataSourceName + "' already exists!");
 
63
            }
 
64
            if (this.dataSourceName != null)
 
65
            {
 
66
                dataSources.remove(this.dataSourceName);
 
67
            }
 
68
            this.dataSourceName = dataSourceName;
 
69
            dataSources.put(dataSourceName, this);
 
70
        }
 
71
    }
 
72
 
 
73
    /**
 
74
     * Generates a JDBC3 object factory reference.
 
75
     */
 
76
    protected Reference createReference()
 
77
    {
 
78
        return new Reference(getClass().getName(), Jdbc3ObjectFactory.class.getName(), null);
 
79
    }
 
80
 
 
81
    /**
 
82
     * Creates a JDBC3 ConnectionPool to use with this DataSource.
 
83
     */
 
84
    protected ConnectionPool createConnectionPool()
 
85
    {
 
86
        return new Jdbc3ConnectionPool();
 
87
    }
 
88
 
 
89
    /**
 
90
     * Gets a description of this DataSource.
 
91
     */
 
92
    public String getDescription()
 
93
    {
 
94
        return "JDBC3 Pooling DataSource from " + org.postgresql.Driver.getVersion();
 
95
    }
 
96
}