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