KickJava   Java API By Example, From Geeks To Geeks.

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


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

21
22 package org.continuent.sequoia.console.text.commands.dbadmin;
23
24 import java.text.SimpleDateFormat JavaDoc;
25
26 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
27 import org.continuent.sequoia.common.jmx.management.DumpInfo;
28 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
29 import org.continuent.sequoia.console.text.formatter.TableFormatter;
30 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
31
32 /**
33  * This class defines the command used to display available dumps of a given
34  * virtual database.
35  *
36  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
37  * </a>
38  * @version 1.0
39  */

40 public class ViewDumps extends AbstractAdminCommand
41 {
42
43   /**
44    * Creates a "view dumps" command for the admin module.
45    *
46    * @param module module that owns this commands
47    */

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

56   public void parse(String JavaDoc commandText) throws Exception JavaDoc
57   {
58     VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user,
59         password);
60     DumpInfo[] dumps = vdjc.getAvailableDumps();
61     if (dumps.length == 0)
62     {
63       console.printError(ConsoleTranslate
64           .get("admin.command.view.dumps.nodump")); //$NON-NLS-1$
65
}
66     else
67     {
68       String JavaDoc formattedDumps = TableFormatter.format(getDumpsDescriptions(),
69           getDumpsAsStrings(dumps), true); // FIXME should display dumps
70
// headers in colums
71
console.println(formattedDumps);
72     }
73   }
74
75   /**
76    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
77    */

78   public String JavaDoc getCommandName()
79   {
80     return "show dumps"; //$NON-NLS-1$
81
}
82
83   /**
84    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
85    */

86   public String JavaDoc getCommandDescription()
87   {
88     return ConsoleTranslate.get("admin.command.view.dumps.description"); //$NON-NLS-1$
89
}
90
91   private static String JavaDoc[][] getDumpsAsStrings(DumpInfo[] dumps)
92   {
93     SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc();
94     String JavaDoc[][] dumpStr = new String JavaDoc[dumps.length][7];
95     for (int i = 0; i < dumpStr.length; i++)
96     {
97       DumpInfo dump = dumps[i];
98       dumpStr[i][0] = dump.getDumpName();
99       dumpStr[i][1] = dump.getCheckpointName();
100       dumpStr[i][2] = dump.getDumpFormat();
101       dumpStr[i][3] = dump.getDumpPath();
102       dumpStr[i][4] = sdf.format(dump.getDumpDate());
103       dumpStr[i][5] = dump.getBackendName();
104       dumpStr[i][6] = dump.getTables();
105     }
106     return dumpStr;
107   }
108
109   private static String JavaDoc[] getDumpsDescriptions()
110   {
111     String JavaDoc[] desc = new String JavaDoc[7];
112     desc[0] = ConsoleTranslate.get("admin.command.view.dumps.prop.name"); //$NON-NLS-1$
113
desc[1] = ConsoleTranslate.get("admin.command.view.dumps.prop.checkpoint"); //$NON-NLS-1$
114
desc[2] = ConsoleTranslate.get("admin.command.view.dumps.prop.format"); //$NON-NLS-1$
115
desc[3] = ConsoleTranslate.get("admin.command.view.dumps.prop.path"); //$NON-NLS-1$
116
desc[4] = ConsoleTranslate.get("admin.command.view.dumps.prop.date"); //$NON-NLS-1$
117
desc[5] = ConsoleTranslate.get("admin.command.view.dumps.prop.backend"); //$NON-NLS-1$
118
desc[6] = ConsoleTranslate.get("admin.command.view.dumps.prop.tables"); //$NON-NLS-1$
119
return desc;
120   }
121 }
Popular Tags