01: package net.sourceforge.squirrel_sql.plugins.mysql.action;
02:
03: /*
04: * Copyright (C) 2003 Arun Kapilan.P
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
21: import net.sourceforge.squirrel_sql.fw.util.ICommand;
22:
23: import net.sourceforge.squirrel_sql.plugins.mysql.MysqlPlugin;
24:
25: import net.sourceforge.squirrel_sql.client.session.ISession;
26:
27: /**
28: * DropDatabaseCommand.java
29: *
30: * Created on June 9, 2003, 2:59 PM
31: *
32: * @author Arun Kapilan.P
33: */
34: public class DropDatabaseCommand implements ICommand {
35: /** Current session. */
36: private ISession _session;
37:
38: /** Current plugin. */
39: private final MysqlPlugin _plugin;
40:
41: /** Databases to be dropped. */
42: private final IDatabaseObjectInfo[] _dbs;
43:
44: /**
45: * Ctor specifying the current session.
46: *
47: * @param session Current session.
48: * @param dbs Array of databases to be dropped.
49: */
50: public DropDatabaseCommand(ISession session, MysqlPlugin plugin,
51: IDatabaseObjectInfo[] dbs) {
52: super ();
53: if (session == null) {
54: throw new IllegalArgumentException("IClientSession == null");
55: }
56: if (dbs == null) {
57: throw new IllegalArgumentException(
58: "Databases array is null");
59: }
60:
61: _session = session;
62: _plugin = plugin;
63: _dbs = dbs;
64: }
65:
66: public void execute() {
67: if (_dbs.length > 0) {
68: final String sqlSep = _session.getQueryTokenizer()
69: .getSQLStatementSeparator();
70: final StringBuffer buf = new StringBuffer();
71: for (int i = 0; i < _dbs.length; i++) {
72: final IDatabaseObjectInfo ti = _dbs[i];
73: buf.append("drop database ").append(
74: ti.getQualifiedName()).append(" ").append(
75: sqlSep).append('\n');
76: }
77: _session.getSessionInternalFrame().getSQLPanelAPI()
78: .executeSQL(buf.toString());
79: }
80: }
81: }
|