01: package org.postgresql.xa;
02:
03: import java.sql.Connection;
04: import java.sql.SQLException;
05:
06: import javax.naming.Referenceable;
07: import javax.naming.Reference;
08: import javax.sql.XAConnection;
09: import javax.sql.XADataSource;
10:
11: import org.postgresql.core.BaseConnection;
12: import org.postgresql.ds.common.BaseDataSource;
13:
14: /**
15: * XA-enabled DataSource implementation.
16: *
17: * @author Heikki Linnakangas (heikki.linnakangas@iki.fi)
18: */
19: public class PGXADataSource extends BaseDataSource implements
20: Referenceable, XADataSource {
21: /**
22: * Gets a connection to the PostgreSQL database. The database is identified by the
23: * DataSource properties serverName, databaseName, and portNumber. The user to
24: * connect as is identified by the DataSource properties user and password.
25: *
26: * @return A valid database connection.
27: * @throws SQLException
28: * Occurs when the database connection cannot be established.
29: */
30: public XAConnection getXAConnection() throws SQLException {
31: return getXAConnection(getUser(), getPassword());
32: }
33:
34: /**
35: * Gets a XA-enabled connection to the PostgreSQL database. The database is identified by the
36: * DataSource properties serverName, databaseName, and portNumber. The user to
37: * connect as is identified by the arguments user and password, which override
38: * the DataSource properties by the same name.
39: *
40: * @return A valid database connection.
41: * @throws SQLException
42: * Occurs when the database connection cannot be established.
43: */
44: public XAConnection getXAConnection(String user, String password)
45: throws SQLException {
46: Connection con = super .getConnection(user, password);
47: return new PGXAConnection((BaseConnection) con);
48: }
49:
50: public String getDescription() {
51: return "JDBC3 XA-enabled DataSource from "
52: + org.postgresql.Driver.getVersion();
53: }
54:
55: /**
56: * Generates a reference using the appropriate object factory.
57: */
58: protected Reference createReference() {
59: return new Reference(getClass().getName(),
60: PGXADataSourceFactory.class.getName(), null);
61: }
62: }
|