01: package net.sourceforge.squirrel_sql.plugins.mssql.action;
02:
03: /*
04: * Copyright (C) 2004 Ryan Walberg <generalpf@yahoo.com>
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:
21: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
22: import net.sourceforge.squirrel_sql.client.session.ISession;
23: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
24: import net.sourceforge.squirrel_sql.fw.util.ICommand;
25: import net.sourceforge.squirrel_sql.plugins.mssql.MssqlPlugin;
26:
27: public class UpdateStatisticsCommand implements ICommand {
28: private ISession _session;
29: private final MssqlPlugin _plugin;
30:
31: public UpdateStatisticsCommand(ISession session, MssqlPlugin plugin) {
32: super ();
33: if (session == null)
34: throw new IllegalArgumentException("ISession == null");
35:
36: _session = session;
37: _plugin = plugin;
38: }
39:
40: public void execute() {
41: final String sqlSep = _session.getQueryTokenizer()
42: .getSQLStatementSeparator();
43: final IObjectTreeAPI api = _session.getSessionInternalFrame()
44: .getObjectTreeAPI();
45: final IDatabaseObjectInfo[] dbObjs = api
46: .getSelectedDatabaseObjects();
47:
48: // Get the names of all the selected tables in a comma separated list,
49: final StringBuffer cmd = new StringBuffer(512);
50: for (int i = 0; i < dbObjs.length; ++i) {
51: cmd.append("UPDATE STATISTICS ");
52: cmd.append(dbObjs[i].getCatalogName());
53: cmd.append(".");
54: cmd.append(dbObjs[i].getSchemaName());
55: cmd.append(".");
56: cmd.append(dbObjs[i].getSimpleName());
57: cmd.append(" WITH FULLSCAN, ALL\n");
58: cmd.append(sqlSep);
59: cmd.append("\n");
60: }
61:
62: if (cmd != null && cmd.length() > 0) {
63: _session.getSessionInternalFrame().getSQLPanelAPI()
64: .appendSQLScript(cmd.toString(), true);
65: _session.getSessionInternalFrame().getSQLPanelAPI()
66: .executeCurrentSQL();
67: _session
68: .selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
69: }
70: }
71: }
|