KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > dbadmin > Restore


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Nicolas Modrzyk
21  * Contributor(s): Emmanuel Cecchet.
22  */

23
24 package org.continuent.sequoia.console.text.commands.dbadmin;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
30 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
31 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
32
33 /**
34  * This class defines a Restore
35  *
36  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
37  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
38  * </a>
39  * @version 1.0
40  */

41 public class Restore extends AbstractAdminCommand
42 {
43
44   /**
45    * Creates a new <code>Restore.java</code> object
46    *
47    * @param module the command is attached to
48    */

49   public Restore(VirtualDatabaseAdmin module)
50   {
51     super(module);
52   }
53
54   /**
55    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
56    */

57   public void parse(String JavaDoc commandText) throws Exception JavaDoc
58   {
59     String JavaDoc dumpName = null;
60     String JavaDoc backendName = null;
61     ArrayList JavaDoc tables = null;
62     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText.trim());
63
64     try
65     {
66       backendName = st.nextToken();
67       dumpName = st.nextToken();
68       if (st.hasMoreTokens())
69       {
70         tables = new ArrayList JavaDoc();
71         while (st.hasMoreTokens())
72         {
73           tables.add(st.nextToken());
74         }
75       }
76     }
77     catch (Exception JavaDoc e)
78     {
79       console.printError(getUsage());
80       return;
81     }
82
83     if (backendName == null || dumpName == null)
84     {
85       console.printError(getUsage());
86       return;
87     }
88     String JavaDoc login = console.readLine(ConsoleTranslate.get("admin.restore.user")); //$NON-NLS-1$
89
if (login == null)
90       return;
91
92     String JavaDoc pwd = console.readPassword(ConsoleTranslate
93         .get("admin.restore.password")); //$NON-NLS-1$
94
if (pwd == null)
95       return;
96
97     console.printInfo(ConsoleTranslate.get("admin.command.restore.echo", //$NON-NLS-1$
98
new String JavaDoc[]{backendName, dumpName}));
99     VirtualDatabaseMBean vjdc = jmxClient.getVirtualDatabaseProxy(dbName, user,
100         password);
101     vjdc.restoreDumpOnBackend(backendName, login, pwd, dumpName, tables);
102   }
103
104   /**
105    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
106    */

107   public String JavaDoc getCommandName()
108   {
109
110     return "restore backend"; //$NON-NLS-1$
111
}
112
113   /**
114    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
115    */

116   public String JavaDoc getCommandDescription()
117   {
118     return ConsoleTranslate.get("admin.command.restore.description"); //$NON-NLS-1$
119
}
120
121   /**
122    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
123    */

124   public String JavaDoc getCommandParameters()
125   {
126     return ConsoleTranslate.get("admin.command.restore.params"); //$NON-NLS-1$
127
}
128 }
Popular Tags