KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConsoleException;
33 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
34
35 /**
36  * This class defines the Backup command for the text console. It backups a
37  * backend to a dump file.
38  *
39  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
40  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
41  * </a>
42  * @version 1.0
43  */

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

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

60   public void parse(String JavaDoc commandText) throws Exception JavaDoc
61   {
62
63     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText.trim());
64
65     if (st == null || st.countTokens() < 4)
66       throw new ConsoleException("Usage: " + getCommandName() + " "
67           + getCommandParameters());
68
69     String JavaDoc backendName = st.nextToken();
70     String JavaDoc dumpName = st.nextToken();
71     String JavaDoc backuperName = st.nextToken();
72     String JavaDoc path = st.nextToken();
73     ArrayList JavaDoc tables = null;
74     if (st.hasMoreTokens())
75     {
76       tables = new ArrayList JavaDoc();
77       while (st.hasMoreTokens())
78       {
79         tables.add(st.nextToken());
80       }
81     }
82
83     String JavaDoc login = console.readLine(ConsoleTranslate.get("admin.backup.user"));
84     if (login == null)
85       return;
86
87     String JavaDoc pwd = console.readPassword(ConsoleTranslate
88         .get("admin.backup.password"));
89     if (pwd == null)
90       return;
91
92     console.println(ConsoleTranslate.get("admin.command.backup.echo",
93         new String JavaDoc[]{backendName, dumpName}));
94     if (tables != null)
95       console.println(ConsoleTranslate.get("admin.command.backup.tables",
96           tables));
97     VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user,
98         password);
99     vdjc.backupBackend(backendName, login, pwd, dumpName, backuperName, path,
100         tables);
101   }
102
103   /**
104    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
105    */

106   public String JavaDoc getCommandName()
107   {
108     return "backup";
109   }
110
111   /**
112    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
113    */

114   public String JavaDoc getCommandDescription()
115   {
116     return ConsoleTranslate.get("admin.command.backup.description");
117   }
118
119   /**
120    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
121    */

122   public String JavaDoc getCommandParameters()
123   {
124     return ConsoleTranslate.get("admin.command.backup.params");
125   }
126
127 }
Popular Tags