01: package net.sourceforge.squirrel_sql.client.mainframe.action;
02:
03: /*
04: * Copyright (C) 2001-2003 Colin Bell and Johan Compagner
05: * colbell@users.sourceforge.net
06: * jcompagner@j-com.nl
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public
10: * License as published by the Free Software Foundation; either
11: * version 2.1 of the License, or (at your option) any later version.
12: *
13: * This library 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 GNU
16: * Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public
19: * License along with this library; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: */
22: import java.util.ArrayList;
23: import java.util.Iterator;
24: import java.util.List;
25:
26: import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
27: import net.sourceforge.squirrel_sql.fw.util.ICommand;
28:
29: import net.sourceforge.squirrel_sql.client.IApplication;
30: import net.sourceforge.squirrel_sql.client.gui.db.DataCache;
31: import net.sourceforge.squirrel_sql.client.gui.db.SQLAlias;
32:
33: /**
34: * This <CODE>ICommand</CODE> connects to all aliases specified as "connect
35: * at startup.
36: *
37: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
38: */
39: public class ConnectToStartupAliasesCommand implements ICommand {
40: /** Application API. */
41: private final IApplication _app;
42:
43: /**
44: * Ctor.
45: *
46: * @param app Application API
47: *
48: * @throws IllegalArgumentException
49: * Thrown if <TT>null</TT> <TT>IApplication</TT> passed.
50: */
51: public ConnectToStartupAliasesCommand(IApplication app) {
52: super ();
53: if (app == null) {
54: throw new IllegalArgumentException("IApplication == null");
55: }
56:
57: _app = app;
58: }
59:
60: public void execute() {
61: final List<ISQLAlias> aliases = new ArrayList<ISQLAlias>();
62: final DataCache cache = _app.getDataCache();
63: synchronized (cache) {
64: for (Iterator<ISQLAlias> it = cache.aliases(); it.hasNext();) {
65: ISQLAlias alias = it.next();
66: if (alias.isConnectAtStartup()) {
67: aliases.add(alias);
68: }
69: }
70: }
71: final Iterator<ISQLAlias> it = aliases.iterator();
72: while (it.hasNext()) {
73: final SQLAlias alias = (SQLAlias) it.next();
74: new ConnectToAliasCommand(_app, alias).execute();
75: }
76: }
77: }
|