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

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.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 javax.naming.*;
 
5
import org.postgresql.jdbc2.optional.PGObjectFactory;
 
6
 
 
7
/**
 
8
 * JDBC3 version of the Object Factory used to recreate objects
 
9
 * from their JNDI references.
 
10
 *
 
11
 * @author Aaron Mulder (ammulder@alumni.princeton.edu)
 
12
 * @version $Revision: 1.1 $
 
13
 */
 
14
public class Jdbc3ObjectFactory extends PGObjectFactory
 
15
{
 
16
    /**
 
17
     * Dereferences a PostgreSQL DataSource.  Other types of references are
 
18
     * ignored.
 
19
     */
 
20
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
 
21
                                    Hashtable environment) throws Exception
 
22
    {
 
23
        Reference ref = (Reference) obj;
 
24
        if (ref.getClassName().equals(Jdbc3SimpleDataSource.class.getName()))
 
25
        {
 
26
            return loadSimpleDataSource(ref);
 
27
        }
 
28
        else if (ref.getClassName().equals(Jdbc3ConnectionPool.class.getName()))
 
29
        {
 
30
            return loadConnectionPool(ref);
 
31
        }
 
32
        else if (ref.getClassName().equals(Jdbc3PoolingDataSource.class.getName()))
 
33
        {
 
34
            return loadPoolingDataSource(ref);
 
35
        }
 
36
        else
 
37
        {
 
38
            return null;
 
39
        }
 
40
    }
 
41
 
 
42
    private Object loadPoolingDataSource(Reference ref)
 
43
    {
 
44
        // If DataSource exists, return it
 
45
        String name = getProperty(ref, "dataSourceName");
 
46
        Jdbc3PoolingDataSource pds = Jdbc3PoolingDataSource.getDataSource(name);
 
47
        if (pds != null)
 
48
        {
 
49
            return pds;
 
50
        }
 
51
        // Otherwise, create a new one
 
52
        pds = new Jdbc3PoolingDataSource();
 
53
        pds.setDataSourceName(name);
 
54
        loadBaseDataSource(pds, ref);
 
55
        String min = getProperty(ref, "initialConnections");
 
56
        if (min != null)
 
57
        {
 
58
            pds.setInitialConnections(Integer.parseInt(min));
 
59
        }
 
60
        String max = getProperty(ref, "maxConnections");
 
61
        if (max != null)
 
62
        {
 
63
            pds.setMaxConnections(Integer.parseInt(max));
 
64
        }
 
65
        return pds;
 
66
    }
 
67
 
 
68
    private Object loadSimpleDataSource(Reference ref)
 
69
    {
 
70
        Jdbc3SimpleDataSource ds = new Jdbc3SimpleDataSource();
 
71
        return loadBaseDataSource(ds, ref);
 
72
    }
 
73
 
 
74
    private Object loadConnectionPool(Reference ref)
 
75
    {
 
76
        Jdbc3ConnectionPool cp = new Jdbc3ConnectionPool();
 
77
        return loadBaseDataSource(cp, ref);
 
78
    }
 
79
 
 
80
}