KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > commands > dbadmin > Restore


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): Emmanuel Cecchet.
23  */

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

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

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

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

112   public String JavaDoc getCommandName()
113   {
114
115     return "restore backend";
116   }
117
118   /**
119    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
120    */

121   public String JavaDoc getCommandDescription()
122   {
123     return ConsoleTranslate.get("admin.command.restore.description");
124   }
125
126   /**
127    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
128    */

129   public String JavaDoc getCommandParameters()
130   {
131     return ConsoleTranslate.get("admin.command.restore.params");
132   }
133 }
Popular Tags