01: package net.sourceforge.squirrel_sql.plugins.SybaseASE;
02:
03: import net.sourceforge.squirrel_sql.client.IApplication;
04: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
05: import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
06: import net.sourceforge.squirrel_sql.client.session.ISession;
07: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
08: import net.sourceforge.squirrel_sql.fw.sql.IProcedureInfo;
09: import net.sourceforge.squirrel_sql.fw.util.Resources;
10:
11: import java.awt.event.ActionEvent;
12: import java.sql.ResultSet;
13: import java.sql.Statement;
14:
15: public class ScriptSybaseASEProcedureAction extends SquirrelAction {
16: private ISession _session;
17:
18: public ScriptSybaseASEProcedureAction(IApplication app,
19: Resources rsrc, ISession session) {
20: super (app, rsrc);
21: _session = session;
22: }
23:
24: public void actionPerformed(ActionEvent evt) {
25: try {
26:
27: IDatabaseObjectInfo[] dbObjs = _session
28: .getSessionInternalFrame().getObjectTreeAPI()
29: .getSelectedDatabaseObjects();
30:
31: Statement stat = _session.getSQLConnection()
32: .createStatement();
33:
34: StringBuffer script = new StringBuffer();
35: for (int i = 0; i < dbObjs.length; i++) {
36: IProcedureInfo pi = (IProcedureInfo) dbObjs[i];
37:
38: ///////////////////////////////////////////////////////////
39: // SybaseASE specific code to read procedure definitions.
40: String sql = "Select text "
41: + "from sysobjects inner join syscomments on syscomments.id = sysobjects.id "
42: + "where name = '"
43: + pi.getSimpleName().replace(";1", "") + "'";
44:
45: ResultSet res = stat.executeQuery(sql);
46:
47: while (res.next()) {
48: script.append(res.getString("text"));
49: }
50: script.append(getStatementSeparator());
51: res.close();
52: //
53: ///////////////////////////////////////////////////////////
54: }
55: stat.close();
56:
57: SessionInternalFrame sessMainFrm = _session
58: .getSessionInternalFrame();
59: sessMainFrm.getSQLPanelAPI().appendSQLScript(
60: script.toString());
61: sessMainFrm.getSessionPanel().selectMainTab(
62: ISession.IMainPanelTabIndexes.SQL_TAB);
63: } catch (Exception e) {
64: throw new RuntimeException(e);
65: }
66: }
67:
68: private String getStatementSeparator() {
69: String statementSeparator = _session.getQueryTokenizer()
70: .getSQLStatementSeparator();
71:
72: if (1 < statementSeparator.length()) {
73: statementSeparator = "\n" + statementSeparator + "\n";
74: }
75:
76: return statementSeparator;
77: }
78:
79: }
|