001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Jeff Mesnil
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.console.text.commands.sqlconsole;
022:
023: import java.io.IOException;
024: import java.sql.Connection;
025: import java.sql.Savepoint;
026:
027: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
028: import org.continuent.sequoia.console.text.ConsoleException;
029: import org.continuent.sequoia.console.text.commands.ConsoleCommand;
030: import org.continuent.sequoia.console.text.module.VirtualDatabaseConsole;
031:
032: /**
033: * This class defines a "rollback" sql command
034: *
035: * @author <a href="mailto:jeff.mesnil@emicnetworks.com">Jeff Mesnil</a>
036: */
037: public class Rollback extends ConsoleCommand {
038:
039: /**
040: * Creates a new <code>Rollback</code> object
041: *
042: * @param module the command is attached to
043: */
044: public Rollback(VirtualDatabaseConsole module) {
045: super (module);
046: }
047:
048: /**
049: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
050: */
051: public void parse(String commandText) throws IOException,
052: ConsoleException {
053: VirtualDatabaseConsole consoleModule = (VirtualDatabaseConsole) module;
054: Connection connection = consoleModule.getConnection();
055:
056: String savePointName = commandText.trim();
057:
058: try {
059: if (consoleModule.getRequestDelimiter().equals(
060: savePointName)
061: || "".equals(savePointName)) //$NON-NLS-1$
062: {
063: connection.rollback();
064: console.printInfo(ConsoleTranslate
065: .get("sql.command.rollback.done")); //$NON-NLS-1$
066: } else {
067: Savepoint savepoint = ((VirtualDatabaseConsole) module)
068: .getSavePoint(savePointName);
069: if (savepoint == null) {
070: console
071: .printError(ConsoleTranslate
072: .get(
073: "sql.command.rollback.no.savepoint", savePointName)); //$NON-NLS-1$
074: return;
075: }
076: connection.rollback(savepoint);
077: console
078: .printInfo(ConsoleTranslate
079: .get(
080: "sql.command.rollback.to.savepoint", savePointName)); //$NON-NLS-1$
081: }
082: connection.setAutoCommit(true);
083: } catch (Exception e) {
084: console.printError(ConsoleTranslate.get(
085: "sql.display.exception", e), e); //$NON-NLS-1$
086: }
087:
088: }
089:
090: /**
091: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
092: */
093: public String getCommandName() {
094: return "rollback"; //$NON-NLS-1$
095: }
096:
097: /**
098: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
099: */
100: public String getCommandParameters() {
101: return ConsoleTranslate.get("sql.command.rollback.params"); //$NON-NLS-1$
102: }
103:
104: /**
105: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
106: */
107: public String getCommandDescription() {
108: return ConsoleTranslate.get("sql.command.rollback.description"); //$NON-NLS-1$
109: }
110: }
|