1 | /* |
2 | Copyright (C) 2005 MySQL AB |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of version 2 of the GNU General Public License as |
6 | published by the Free Software Foundation. |
7 | |
8 | There are special exceptions to the terms and conditions of the GPL |
9 | as it is applied to this software. View the full text of the |
10 | exception in file EXCEPTIONS-CONNECTOR-J in the directory of this |
11 | software distribution. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | |
22 | |
23 | |
24 | */ |
25 | package com.mysql.jdbc.jdbc2.optional; |
26 | |
27 | import java.sql.Connection; |
28 | import java.sql.SQLException; |
29 | |
30 | import javax.sql.XAConnection; |
31 | |
32 | /** |
33 | * @author mmatthew |
34 | * |
35 | * To change this generated comment edit the template variable "typecomment": |
36 | * Window>Preferences>Java>Templates. To enable and disable the creation of type |
37 | * comments go to Window>Preferences>Java>Code Generation. |
38 | */ |
39 | public class MysqlXADataSource extends MysqlDataSource implements |
40 | javax.sql.XADataSource { |
41 | |
42 | /** |
43 | * @see javax.sql.XADataSource#getXAConnection() |
44 | */ |
45 | public XAConnection getXAConnection() throws SQLException { |
46 | |
47 | Connection conn = getConnection(); |
48 | |
49 | return wrapConnection(conn); |
50 | } |
51 | |
52 | /** |
53 | * @see javax.sql.XADataSource#getXAConnection(String, String) |
54 | */ |
55 | public XAConnection getXAConnection(String user, String password) |
56 | throws SQLException { |
57 | |
58 | Connection conn = getConnection(user, password); |
59 | |
60 | return wrapConnection(conn); |
61 | } |
62 | |
63 | /** |
64 | * Wraps a connection as a 'fake' XAConnection |
65 | */ |
66 | |
67 | private XAConnection wrapConnection(Connection conn) throws SQLException { |
68 | if (getPinGlobalTxToPhysicalConnection() || |
69 | ((com.mysql.jdbc.Connection)conn).getPinGlobalTxToPhysicalConnection()) { |
70 | return new SuspendableXAConnection((com.mysql.jdbc.Connection) conn); |
71 | } |
72 | |
73 | return new MysqlXAConnection((com.mysql.jdbc.Connection) conn); |
74 | } |
75 | } |