1 | /* |
---|
2 | Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
---|
3 | |
---|
4 | |
---|
5 | The MySQL Connector/J is licensed under the terms of the GPLv2 |
---|
6 | <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors. |
---|
7 | There are special exceptions to the terms and conditions of the GPLv2 as it is applied to |
---|
8 | this software, see the FLOSS License Exception |
---|
9 | <http://www.mysql.com/about/legal/licensing/foss-exception.html>. |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under the terms |
---|
12 | of the GNU General Public License as published by the Free Software Foundation; version 2 |
---|
13 | of the License. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
---|
16 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
17 | See the GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License along with this |
---|
20 | program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth |
---|
21 | Floor, Boston, MA 02110-1301 USA |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | */ |
---|
26 | package com.mysql.jdbc.jdbc2.optional; |
---|
27 | |
---|
28 | import java.sql.Connection; |
---|
29 | import java.sql.SQLException; |
---|
30 | |
---|
31 | import javax.sql.XAConnection; |
---|
32 | |
---|
33 | /** |
---|
34 | * @author mmatthew |
---|
35 | * |
---|
36 | * To change this generated comment edit the template variable "typecomment": |
---|
37 | * Window>Preferences>Java>Templates. To enable and disable the creation of type |
---|
38 | * comments go to Window>Preferences>Java>Code Generation. |
---|
39 | */ |
---|
40 | public class MysqlXADataSource extends MysqlDataSource implements |
---|
41 | javax.sql.XADataSource { |
---|
42 | |
---|
43 | static final long serialVersionUID = 7911390333152247455L; |
---|
44 | |
---|
45 | /** |
---|
46 | * @see javax.sql.XADataSource#getXAConnection() |
---|
47 | */ |
---|
48 | public XAConnection getXAConnection() throws SQLException { |
---|
49 | |
---|
50 | Connection conn = getConnection(); |
---|
51 | |
---|
52 | return wrapConnection(conn); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * @see javax.sql.XADataSource#getXAConnection(String, String) |
---|
57 | */ |
---|
58 | public XAConnection getXAConnection(String u, String p) |
---|
59 | throws SQLException { |
---|
60 | |
---|
61 | Connection conn = getConnection(u, p); |
---|
62 | |
---|
63 | return wrapConnection(conn); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Wraps a connection as a 'fake' XAConnection |
---|
68 | */ |
---|
69 | |
---|
70 | private XAConnection wrapConnection(Connection conn) throws SQLException { |
---|
71 | if (getPinGlobalTxToPhysicalConnection() || |
---|
72 | ((com.mysql.jdbc.Connection)conn).getPinGlobalTxToPhysicalConnection()) { |
---|
73 | return SuspendableXAConnection.getInstance((com.mysql.jdbc.ConnectionImpl) conn); |
---|
74 | } |
---|
75 | |
---|
76 | return MysqlXAConnection.getInstance((com.mysql.jdbc.ConnectionImpl) conn, getLogXaCommands()); |
---|
77 | } |
---|
78 | } |
---|