1 | /* |
---|
2 | Copyright (c) 2002, 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.ConnectionPoolDataSource; |
---|
32 | import javax.sql.PooledConnection; |
---|
33 | |
---|
34 | /** |
---|
35 | * This class is used to obtain a physical connection and instantiate and return |
---|
36 | * a MysqlPooledConnection. J2EE application servers map client calls to |
---|
37 | * dataSource.getConnection to this class based upon mapping set within |
---|
38 | * deployment descriptor. This class extends MysqlDataSource. |
---|
39 | * |
---|
40 | * @see javax.sql.PooledConnection |
---|
41 | * @see javax.sql.ConnectionPoolDataSource |
---|
42 | * @see org.gjt.mm.mysql.MysqlDataSource |
---|
43 | * @author Todd Wolff <todd.wolff_at_prodigy.net> |
---|
44 | */ |
---|
45 | public class MysqlConnectionPoolDataSource extends MysqlDataSource implements |
---|
46 | ConnectionPoolDataSource { |
---|
47 | |
---|
48 | static final long serialVersionUID = -7767325445592304961L; |
---|
49 | |
---|
50 | // ~ Methods |
---|
51 | // ---------------------------------------------------------------- |
---|
52 | |
---|
53 | /** |
---|
54 | * Returns a pooled connection. |
---|
55 | * |
---|
56 | * @exception SQLException |
---|
57 | * if an error occurs |
---|
58 | * @return a PooledConnection |
---|
59 | */ |
---|
60 | public synchronized PooledConnection getPooledConnection() |
---|
61 | throws SQLException { |
---|
62 | Connection connection = getConnection(); |
---|
63 | MysqlPooledConnection mysqlPooledConnection = MysqlPooledConnection.getInstance( |
---|
64 | (com.mysql.jdbc.Connection)connection); |
---|
65 | |
---|
66 | return mysqlPooledConnection; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * This method is invoked by the container. Obtains physical connection |
---|
71 | * using mySql.Driver class and returns a mysqlPooledConnection object. |
---|
72 | * |
---|
73 | * @param s |
---|
74 | * user name |
---|
75 | * @param s1 |
---|
76 | * password |
---|
77 | * @exception SQLException |
---|
78 | * if an error occurs |
---|
79 | * @return a PooledConnection |
---|
80 | */ |
---|
81 | public synchronized PooledConnection getPooledConnection(String s, String s1) |
---|
82 | throws SQLException { |
---|
83 | Connection connection = getConnection(s, s1); |
---|
84 | MysqlPooledConnection mysqlPooledConnection = MysqlPooledConnection.getInstance( |
---|
85 | (com.mysql.jdbc.Connection)connection); |
---|
86 | |
---|
87 | return mysqlPooledConnection; |
---|
88 | } |
---|
89 | } |
---|