KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > sqlconsole > SetReadOnly


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent, Inc.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
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  */

21
22 package org.continuent.sequoia.console.text.commands.sqlconsole;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
28 import org.continuent.sequoia.console.text.ConsoleException;
29 import org.continuent.sequoia.console.text.commands.ConsoleCommand;
30 import org.continuent.sequoia.console.text.module.VirtualDatabaseConsole;
31
32 /**
33  * This class defines a "setreadonly" sql command
34  *
35  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
36  * @version 1.0
37  */

38 public class SetReadOnly extends ConsoleCommand
39 {
40
41   /**
42    * Creates a new <code>SetReadOnly</code> object
43    *
44    * @param module the command is attached to
45    */

46   public SetReadOnly(VirtualDatabaseConsole module)
47   {
48     super(module);
49   }
50
51   /**
52    * {@inheritDoc}
53    *
54    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
55    */

56   public String JavaDoc getCommandDescription()
57   {
58     return ConsoleTranslate.get("sql.command.readonly.description"); //$NON-NLS-1$
59
}
60
61   /**
62    * {@inheritDoc}
63    *
64    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
65    */

66   public String JavaDoc getCommandName()
67   {
68     return "setreadonly"; //$NON-NLS-1$
69
}
70
71   /**
72    * {@inheritDoc}
73    *
74    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
75    */

76   public String JavaDoc getCommandParameters()
77   {
78     return ConsoleTranslate.get("sql.command.readonly.params"); //$NON-NLS-1$
79
}
80
81   /**
82    * {@inheritDoc}
83    *
84    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
85    */

86   public void parse(String JavaDoc commandText) throws Exception JavaDoc
87   {
88     try
89     {
90       boolean readOnly = Boolean.valueOf(commandText.trim()).booleanValue();
91       Connection JavaDoc connection = ((VirtualDatabaseConsole) module).getConnection();
92       connection.setReadOnly(readOnly);
93       console.printInfo(ConsoleTranslate.get("sql.command.readonly.value", //$NON-NLS-1$
94
readOnly));
95     }
96     catch (SQLException JavaDoc e)
97     {
98       throw new ConsoleException(ConsoleTranslate
99           .get("sql.command.readonly.failed"), e); //$NON-NLS-1$
100
}
101   }
102
103 }
104
Popular Tags