01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2006 Continuent.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: * Initial developer(s): Gilles Rayrat.
19: * Contributor(s): ______________________.
20: */package org.continuent.sequoia.console.text.commands.dbadmin;
21:
22: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
23: import org.continuent.sequoia.common.jmx.mbeans.RequestManagerMBean;
24: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
25:
26: /**
27: * This class defines the command used to get the parsing result of a given sql
28: * query.
29: */
30: public class ParseRequest extends AbstractAdminCommand {
31: protected static final String LINE_SEPARATOR = System
32: .getProperty("line.separator");
33:
34: /**
35: * Creates a new <code>DumpBackendSchema</code> object
36: *
37: * @param module the commands is attached to
38: */
39: public ParseRequest(VirtualDatabaseAdmin module) {
40: super (module);
41: }
42:
43: /**
44: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
45: */
46: public void parse(String commandText) throws Exception {
47: // args: request
48: // remove possible '"' chars
49: if (commandText.indexOf('"', 0) != -1)
50: commandText = commandText.replace('"', ' ');
51: String request = commandText.trim();
52: if (request.length() == 0) {
53: console.printError(getUsage());
54: return;
55: }
56:
57: RequestManagerMBean requestManager = jmxClient
58: .getRequestManager(dbName, user, password);
59: console.println(requestManager.parseSqlRequest(request,
60: LINE_SEPARATOR));
61: }
62:
63: /**
64: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
65: */
66: public String getCommandName() {
67:
68: return "parse request"; //$NON-NLS-1$
69: }
70:
71: /**
72: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
73: */
74: public String getCommandParameters() {
75: return ConsoleTranslate.get("ParseRequest.params"); //$NON-NLS-1$
76: }
77:
78: /**
79: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
80: */
81: public String getCommandDescription() {
82: return ConsoleTranslate.get("ParseRequest.description"); //$NON-NLS-1$
83: }
84: }
|