01: /*
02: * WbFeedback.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql.wbcommands;
13:
14: import java.sql.SQLException;
15: import workbench.resource.ResourceMgr;
16: import workbench.sql.SqlCommand;
17: import workbench.sql.StatementRunnerResult;
18: import workbench.sql.formatter.SQLLexer;
19: import workbench.sql.formatter.SQLToken;
20: import workbench.util.ArgumentParser;
21:
22: /**
23: *
24: * @author support@sql-workbench.net
25: */
26: public class WbFeedback extends SqlCommand {
27: public static final String VERB = "WBFEEDBACK";
28: private final String command;
29:
30: public WbFeedback() {
31: this (VERB);
32: }
33:
34: public WbFeedback(String verb) {
35: this .command = verb;
36: this .cmdLine = new ArgumentParser(false);
37: this .cmdLine.addArgument("on");
38: this .cmdLine.addArgument("off");
39: }
40:
41: public String getVerb() {
42: return command;
43: }
44:
45: protected boolean isConnectionRequired() {
46: return false;
47: }
48:
49: public StatementRunnerResult execute(String sql)
50: throws SQLException {
51: StatementRunnerResult result = new StatementRunnerResult();
52: result.setSuccess();
53:
54: SQLLexer lexer = new SQLLexer(sql);
55: // Skip the SQL Verb
56: SQLToken token = lexer.getNextToken(false, false);
57:
58: // get the parameter
59: token = lexer.getNextToken(false, false);
60: String parm = (token != null ? token.getContents() : null);
61:
62: if (parm == null) {
63: if (runner.getVerboseLogging()) {
64: result.addMessage(ResourceMgr
65: .getString("MsgFeedbackEnabled"));
66: } else {
67: result.addMessage(ResourceMgr
68: .getString("MsgFeedbackDisabled"));
69: }
70: result.setSuccess();
71: } else if ("off".equalsIgnoreCase(parm)
72: || "false".equalsIgnoreCase(parm)) {
73: this .runner.setVerboseLogging(false);
74: result.addMessage(ResourceMgr
75: .getString("MsgFeedbackDisabled"));
76: } else if ("on".equalsIgnoreCase(parm)
77: || "true".equalsIgnoreCase(parm)) {
78: this .runner.setVerboseLogging(true);
79: result.addMessage(ResourceMgr
80: .getString("MsgFeedbackEnabled"));
81: } else {
82: result.setFailure();
83: result.addMessage(ResourceMgr
84: .getString("ErrFeedbackWrongParameter"));
85: }
86: return result;
87: }
88:
89: }
|