1 | /* |
---|
2 | Copyright (c) 2002, 2011, 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; |
---|
27 | |
---|
28 | import java.sql.SQLException; |
---|
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 SQLError.createSQLException( |
---|
57 | Messages.getString("MiniAdmin.0"), SQLError.SQL_STATE_GENERAL_ERROR, null); //$NON-NLS-1$ |
---|
58 | } |
---|
59 | |
---|
60 | if (!(conn instanceof Connection)) { |
---|
61 | throw SQLError.createSQLException(Messages.getString("MiniAdmin.1"), //$NON-NLS-1$ |
---|
62 | SQLError.SQL_STATE_GENERAL_ERROR, ((com.mysql.jdbc.ConnectionImpl)conn).getExceptionInterceptor()); |
---|
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 | } |
---|