| 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; |
| 26 | |
| 27 | import java.sql.SQLException; |
| 28 | |
| 29 | import java.util.Properties; |
| 30 | |
| 31 | /** |
| 32 | * Utility functions for admin functionality from Java. |
| 33 | * |
| 34 | * @author Mark Matthews |
| 35 | */ |
| 36 | public class MiniAdmin { |
| 37 | // ~ Instance fields |
| 38 | // -------------------------------------------------------- |
| 39 | |
| 40 | private Connection conn; |
| 41 | |
| 42 | // ~ Constructors |
| 43 | // ----------------------------------------------------------- |
| 44 | |
| 45 | /** |
| 46 | * Create a new MiniAdmin using the given connection |
| 47 | * |
| 48 | * @param conn |
| 49 | * the existing connection to use. |
| 50 | * |
| 51 | * @throws SQLException |
| 52 | * if an error occurs |
| 53 | */ |
| 54 | public MiniAdmin(java.sql.Connection conn) throws SQLException { |
| 55 | if (conn == null) { |
| 56 | throw new SQLException( |
| 57 | Messages.getString("MiniAdmin.0"), SQLError.SQL_STATE_GENERAL_ERROR); //$NON-NLS-1$ |
| 58 | } |
| 59 | |
| 60 | if (!(conn instanceof Connection)) { |
| 61 | throw new SQLException(Messages.getString("MiniAdmin.1"), //$NON-NLS-1$ |
| 62 | SQLError.SQL_STATE_GENERAL_ERROR); |
| 63 | } |
| 64 | |
| 65 | this.conn = (Connection) conn; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Create a new MiniAdmin, connecting using the given JDBC URL. |
| 70 | * |
| 71 | * @param jdbcUrl |
| 72 | * the JDBC URL to use |
| 73 | * |
| 74 | * @throws SQLException |
| 75 | * if an error occurs |
| 76 | */ |
| 77 | public MiniAdmin(String jdbcUrl) throws SQLException { |
| 78 | this(jdbcUrl, new Properties()); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Create a new MiniAdmin, connecting using the given JDBC URL and |
| 83 | * properties |
| 84 | * |
| 85 | * @param jdbcUrl |
| 86 | * the JDBC URL to use |
| 87 | * @param props |
| 88 | * the properties to use when connecting |
| 89 | * |
| 90 | * @throws SQLException |
| 91 | * if an error occurs |
| 92 | */ |
| 93 | public MiniAdmin(String jdbcUrl, Properties props) throws SQLException { |
| 94 | this.conn = (Connection) (new Driver().connect(jdbcUrl, props)); |
| 95 | } |
| 96 | |
| 97 | // ~ Methods |
| 98 | // ---------------------------------------------------------------- |
| 99 | |
| 100 | /** |
| 101 | * Shuts down the MySQL server at the other end of the connection that this |
| 102 | * MiniAdmin was created from/for. |
| 103 | * |
| 104 | * @throws SQLException |
| 105 | * if an error occurs |
| 106 | */ |
| 107 | public void shutdown() throws SQLException { |
| 108 | this.conn.shutdownServer(); |
| 109 | } |
| 110 | } |