01: package org.rege.isqlj.squirrel;
02:
03: /**
04: * <p>Title: sqsc-isqlj</p>
05: * <p>Description: SquirrelSQL plugin for iSqlJ</p>
06: * <p>Copyright: Copyright (c) 2003 Stathis Alexopoulos</p>
07: * @author Stathis Alexopoulos stathis@rege.org
08: * <br>
09: * <br>
10: * <p>
11: * This file is part of sqsc-isqlj.
12: * </p>
13: * <br>
14: * <p>
15: * sqsc-isqlj is free software; you can redistribute it and/or modify
16: * it under the terms of the GNU Lesser General Public License as published by
17: * the Free Software Foundation; either version 2 of the License, or
18: * (at your option) any later version.
19: *
20: * Foobar is distributed in the hope that it will be useful,
21: * but WITHOUT ANY WARRANTY; without even the implied warranty of
22: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23: * GNU Lesser General Public License for more details.
24: *
25: * You should have received a copy of the GNU Lesser General Public License
26: * along with Foobar; if not, write to the Free Software
27: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28: * </p>
29: */
30:
31: import java.awt.Frame;
32: import java.io.*;
33:
34: import javax.swing.JFileChooser;
35:
36: import net.sourceforge.squirrel_sql.fw.gui.*;
37: import net.sourceforge.squirrel_sql.fw.util.*;
38:
39: import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
40: import net.sourceforge.squirrel_sql.client.session.ISession;
41: import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
42:
43: import net.sourceforge.squirrel_sql.fw.sql.SQLConnection;
44:
45: import org.rege.isqlj.JavaSql;
46: import org.rege.isqlj.ISqlJConnection;
47:
48: public class ExecuteISqlJCommand implements ICommand {
49: private final ISession session;
50: private ISqlJPlugin plugin;
51: private final Frame frame;
52:
53: public ExecuteISqlJCommand(Frame frame, ISession session,
54: ISqlJPlugin plugin) throws IllegalArgumentException {
55: super ();
56: if (session == null) {
57: throw new IllegalArgumentException("Null ISession passed");
58: }
59: if (plugin == null) {
60: throw new IllegalArgumentException("Null IPlugin passed");
61: }
62: this .frame = frame;
63: this .session = session;
64: this .plugin = plugin;
65: }
66:
67: public void execute() throws BaseException {
68: if (session != null) {
69: String str = session.getSessionInternalFrame()
70: .getSQLPanelAPI().getSQLScriptToBeExecuted();
71: try {
72: JavaSql sqlj = new JavaSql();
73: sqlj.getInterpreter().set("session",
74: new SqscConnection(session, plugin));
75: sqlj.getInterpreter().set(
76: "jdbc",
77: new ISqlJConnection(session.getSQLConnection()
78: .getConnection()));
79: sqlj.exec(new StringReader(str));
80: } catch (Exception ex) {
81: throw new BaseException(ex);
82: }
83: }
84: }
85:
86: }
|