001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Nicolas Modrzyk
021: * Contributor(s): Emmanuel Cecchet.
022: */package org.continuent.sequoia.console.text.commands.dbadmin;
023:
024: import java.util.ArrayList;
025: import java.util.StringTokenizer;
026:
027: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
028: import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
029: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
030:
031: /**
032: * This class defines a Restore
033: *
034: * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
035: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
036: * </a>
037: * @version 1.0
038: */
039: public class Restore extends AbstractAdminCommand {
040:
041: /**
042: * Creates a new <code>Restore.java</code> object
043: *
044: * @param module the command is attached to
045: */
046: public Restore(VirtualDatabaseAdmin module) {
047: super (module);
048: }
049:
050: /**
051: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
052: */
053: public void parse(String commandText) throws Exception {
054: String dumpName = null;
055: String backendName = null;
056: ArrayList tables = null;
057: StringTokenizer st = new StringTokenizer(commandText.trim());
058:
059: try {
060: backendName = st.nextToken();
061: dumpName = st.nextToken();
062: if (st.hasMoreTokens()) {
063: tables = new ArrayList();
064: while (st.hasMoreTokens()) {
065: tables.add(st.nextToken());
066: }
067: }
068: } catch (Exception e) {
069: console.printError(getUsage());
070: return;
071: }
072:
073: if (backendName == null || dumpName == null) {
074: console.printError(getUsage());
075: return;
076: }
077: String login = console.readLine(ConsoleTranslate
078: .get("admin.restore.user")); //$NON-NLS-1$
079: if (login == null)
080: return;
081:
082: String pwd = console.readPassword(ConsoleTranslate
083: .get("admin.restore.password")); //$NON-NLS-1$
084: if (pwd == null)
085: return;
086:
087: console.printInfo(ConsoleTranslate.get(
088: "admin.command.restore.echo", //$NON-NLS-1$
089: new String[] { backendName, dumpName }));
090: VirtualDatabaseMBean vjdc = jmxClient.getVirtualDatabaseProxy(
091: dbName, user, password);
092: vjdc.restoreDumpOnBackend(backendName, login, pwd, dumpName,
093: tables);
094: }
095:
096: /**
097: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
098: */
099: public String getCommandName() {
100:
101: return "restore backend"; //$NON-NLS-1$
102: }
103:
104: /**
105: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
106: */
107: public String getCommandDescription() {
108: return ConsoleTranslate
109: .get("admin.command.restore.description"); //$NON-NLS-1$
110: }
111:
112: /**
113: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
114: */
115: public String getCommandParameters() {
116: return ConsoleTranslate.get("admin.command.restore.params"); //$NON-NLS-1$
117: }
118: }
|