001: package net.sourceforge.squirrel_sql.plugins.mysql.action;
002:
003: /*
004: * Copyright (C) 2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.event.ActionEvent;
022:
023: import net.sourceforge.squirrel_sql.fw.util.Resources;
024:
025: import net.sourceforge.squirrel_sql.plugins.mysql.MysqlPlugin;
026:
027: import net.sourceforge.squirrel_sql.client.IApplication;
028: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
029: import net.sourceforge.squirrel_sql.client.session.ISession;
030: import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
031:
032: /**
033: * This <TT>Action</TT> will run a "CHECK TABLE" over the
034: * currently selected tables.
035: *
036: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
037: */
038: public class CheckTableAction extends SquirrelAction implements
039: ISessionAction {
040: private static final long serialVersionUID = 1L;
041:
042: /** Different check types that can be run. */
043: interface ICheckTypes {
044: int QUICK = 0;
045: int FAST = 1;
046: int MEDIUM = 2;
047: int EXTENDED = 3;
048: int CHANGED = 4;
049: }
050:
051: /** Current session. */
052: transient private ISession _session;
053:
054: /** Current plugin. */
055: transient private final MysqlPlugin _plugin;
056:
057: /** Type of check to run on the tables @see ICheckTypes. */
058: private int _checkType;
059:
060: /**
061: * Ctor.
062: *
063: * @param app Application API.
064: * @param rsrc Plugins resources.
065: * @param plugin This plugin.
066: * @param checktype The type of table check to be done.
067: * @see ICheckTypes.
068: *
069: * @throws IllegalArgumentException
070: * Thrown if a?<TT>null</TT> <TT>IApplication</TT>,
071: * <TT>Resources</TT> or <TT>MysqlPlugin</TT> passed.
072: *
073: * @throws IllegalArgumentException
074: * Thrown if an invalid <TT>checktype</TT> passed.
075: */
076: private CheckTableAction(IApplication app, Resources rsrc,
077: MysqlPlugin plugin, int checkType) {
078: super (app, rsrc);
079: if (app == null) {
080: throw new IllegalArgumentException("IApplication == null");
081: }
082: if (rsrc == null) {
083: throw new IllegalArgumentException("Resources == null");
084: }
085: if (plugin == null) {
086: throw new IllegalArgumentException("MysqlPlugin == null");
087: }
088: if (checkType < ICheckTypes.QUICK
089: || checkType > ICheckTypes.CHANGED) {
090: throw new IllegalArgumentException("Invalid checkType of "
091: + checkType);
092: }
093:
094: _plugin = plugin;
095: _checkType = checkType;
096: }
097:
098: public void actionPerformed(ActionEvent evt) {
099: if (_session != null) {
100: try {
101: new CheckTableCommand(_session, _plugin, _checkType)
102: .execute();
103: } catch (Throwable th) {
104: _session.showErrorMessage(th);
105: }
106: }
107: }
108:
109: /**
110: * Set the current session.
111: *
112: * @param session The current session.
113: */
114: public void setSession(ISession session) {
115: _session = session;
116: }
117:
118: public static final class ChangedCheckTableAction extends
119: CheckTableAction {
120: private static final long serialVersionUID = 1L;
121:
122: public ChangedCheckTableAction(IApplication app,
123: Resources rsrc, MysqlPlugin plugin) {
124: super (app, rsrc, plugin, ICheckTypes.CHANGED);
125: }
126: }
127:
128: public static final class ExtendedCheckTableAction extends
129: CheckTableAction {
130: private static final long serialVersionUID = 1L;
131:
132: public ExtendedCheckTableAction(IApplication app,
133: Resources rsrc, MysqlPlugin plugin) {
134: super (app, rsrc, plugin, ICheckTypes.EXTENDED);
135: }
136: }
137:
138: public static final class FastCheckTableAction extends
139: CheckTableAction {
140: private static final long serialVersionUID = 1L;
141:
142: public FastCheckTableAction(IApplication app, Resources rsrc,
143: MysqlPlugin plugin) {
144: super (app, rsrc, plugin, ICheckTypes.FAST);
145: }
146: }
147:
148: public static final class MediumCheckTableAction extends
149: CheckTableAction {
150: private static final long serialVersionUID = 1L;
151:
152: public MediumCheckTableAction(IApplication app, Resources rsrc,
153: MysqlPlugin plugin) {
154: super (app, rsrc, plugin, ICheckTypes.MEDIUM);
155: }
156: }
157:
158: public static final class QuickCheckTableAction extends
159: CheckTableAction {
160: private static final long serialVersionUID = 1L;
161:
162: public QuickCheckTableAction(IApplication app, Resources rsrc,
163: MysqlPlugin plugin) {
164: super(app, rsrc, plugin, ICheckTypes.QUICK);
165: }
166: }
167: }
|