01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2006 Continuent, Inc.
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): Emmanuel Cecchet.
19: * Contributor(s): ______________________.
20: */package org.continuent.sequoia.console.text.commands.sqlconsole;
21:
22: import java.sql.Connection;
23: import java.sql.SQLException;
24:
25: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
26: import org.continuent.sequoia.console.text.ConsoleException;
27: import org.continuent.sequoia.console.text.commands.ConsoleCommand;
28: import org.continuent.sequoia.console.text.module.VirtualDatabaseConsole;
29:
30: /**
31: * This class defines a "setreadonly" sql command
32: *
33: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
34: * @version 1.0
35: */
36: public class SetReadOnly extends ConsoleCommand {
37:
38: /**
39: * Creates a new <code>SetReadOnly</code> object
40: *
41: * @param module the command is attached to
42: */
43: public SetReadOnly(VirtualDatabaseConsole module) {
44: super (module);
45: }
46:
47: /**
48: * {@inheritDoc}
49: *
50: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
51: */
52: public String getCommandDescription() {
53: return ConsoleTranslate.get("sql.command.readonly.description"); //$NON-NLS-1$
54: }
55:
56: /**
57: * {@inheritDoc}
58: *
59: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
60: */
61: public String getCommandName() {
62: return "setreadonly"; //$NON-NLS-1$
63: }
64:
65: /**
66: * {@inheritDoc}
67: *
68: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
69: */
70: public String getCommandParameters() {
71: return ConsoleTranslate.get("sql.command.readonly.params"); //$NON-NLS-1$
72: }
73:
74: /**
75: * {@inheritDoc}
76: *
77: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
78: */
79: public void parse(String commandText) throws Exception {
80: try {
81: boolean readOnly = Boolean.valueOf(commandText.trim())
82: .booleanValue();
83: Connection connection = ((VirtualDatabaseConsole) module)
84: .getConnection();
85: connection.setReadOnly(readOnly);
86: console.printInfo(ConsoleTranslate.get(
87: "sql.command.readonly.value", //$NON-NLS-1$
88: readOnly));
89: } catch (SQLException e) {
90: throw new ConsoleException(ConsoleTranslate
91: .get("sql.command.readonly.failed"), e); //$NON-NLS-1$
92: }
93: }
94:
95: }
|