01: //jTDS JDBC Driver for Microsoft SQL Server and Sybase
02: //Copyright (C) 2004 The jTDS Project
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: //
18: package net.sourceforge.jtds.jdbcx;
19:
20: import java.sql.Connection;
21: import java.sql.SQLException;
22: import javax.sql.XAConnection;
23: import javax.transaction.xa.XAResource;
24:
25: import net.sourceforge.jtds.jdbc.XASupport;
26:
27: /**
28: * jTDS implementation of the <code>XAConnection</code> interface.
29: *
30: * @version $Id: JtdsXAConnection.java,v 1.4 2005/04/28 14:29:30 alin_sinpalean Exp $
31: */
32: public class JtdsXAConnection extends PooledConnection implements
33: XAConnection {
34: /** The XAResource used by the transaction manager to control this connection.*/
35: private final XAResource resource;
36: private final JtdsDataSource dataSource;
37: private final int xaConnectionId;
38:
39: /**
40: * Construct a new <code>XAConnection</code> object.
41: *
42: * @param dataSource the parent <code>DataSource</code> object
43: * @param connection the real database connection
44: */
45: public JtdsXAConnection(JtdsDataSource dataSource,
46: Connection connection) throws SQLException {
47: super (connection);
48: this .resource = new JtdsXAResource(this , connection);
49: this .dataSource = dataSource;
50: xaConnectionId = XASupport.xa_open(connection);
51: }
52:
53: /**
54: * Retrieves the XA Connection ID to pass to server.
55: *
56: * @return the XA connection ID as an <code>Integer</code>
57: */
58: int getXAConnectionID() {
59: return this .xaConnectionId;
60: }
61:
62: //
63: // ------------------- javax.sql.XAConnection interface methods -------------------
64: //
65:
66: public XAResource getXAResource() throws SQLException {
67: return resource;
68: }
69:
70: public synchronized void close() throws SQLException {
71: try {
72: XASupport.xa_close(connection, xaConnectionId);
73: } catch (SQLException e) {
74: // Ignore close errors
75: }
76: super .close();
77: }
78:
79: protected JtdsDataSource getXADataSource() {
80: return this.dataSource;
81: }
82: }
|