01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2002-2004 French National Institute For Research In Computer
04: * Science And Control (INRIA).
05: * Contact: sequoia@continuent.org
06: *
07: * Licensed under the Apache License, Version 2.0 (the "License");
08: * you may not use this file except in compliance with the License.
09: * You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: *
19: * Initial developer(s): Nicolas Modrzyk.
20: * Contributor(s): ______________________.
21: */package org.continuent.sequoia.console.text.commands.dbadmin;
22:
23: import java.util.Iterator;
24: import java.util.Map;
25:
26: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
27: import org.continuent.sequoia.common.jmx.mbeans.RecoveryLogControlMBean;
28: import org.continuent.sequoia.console.text.formatter.TableFormatter;
29: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
30:
31: /**
32: * This class defines a ViewCheckpointNames
33: *
34: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
35: * @version 1.0
36: */
37: public class ViewCheckpointNames extends AbstractAdminCommand {
38:
39: /**
40: * Creates a new <code>ViewCheckpointNames</code> object
41: *
42: * @param module module that owns this commands
43: */
44: public ViewCheckpointNames(VirtualDatabaseAdmin module) {
45: super (module);
46: }
47:
48: /**
49: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
50: */
51: public void parse(String commandText) throws Exception {
52: RecoveryLogControlMBean recoveryLog = jmxClient.getRecoveryLog(
53: dbName, user, password);
54: Map checkpoints = recoveryLog.getCheckpoints();
55: if (checkpoints.size() == 0) {
56: console.printInfo(ConsoleTranslate
57: .get("ViewCheckpointNames.nocheckpoints")); //$NON-NLS-1$
58: return;
59: }
60: // iterate over checkpoints
61: String[][] cp = getCheckpointsAsStrings(checkpoints);
62: String[] headers = new String[] { "id", "name" }; //$NON-NLS-1$//$NON-NLS-2$
63: String formattedCheckpoints = TableFormatter.format(headers,
64: cp, true);
65: console.println(formattedCheckpoints);
66:
67: }
68:
69: private String[][] getCheckpointsAsStrings(Map checkpoints) {
70: String[][] cp = new String[checkpoints.entrySet().size()][2];
71: Iterator iter = checkpoints.entrySet().iterator();
72: int i = 0;
73: while (iter.hasNext()) {
74: // we display first the log ID and then the checkpoint names
75: Map.Entry checkpoint = (Map.Entry) iter.next();
76: cp[i][1] = (String) checkpoint.getKey();
77: cp[i][0] = (String) checkpoint.getValue();
78: i++;
79: }
80: return cp;
81: }
82:
83: /**
84: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
85: */
86: public String getCommandName() {
87: return "show checkpoints"; //$NON-NLS-1$
88: }
89:
90: /**
91: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
92: */
93: public String getCommandDescription() {
94: return ConsoleTranslate.get("ViewCheckpointNames.description"); //$NON-NLS-1$
95: }
96:
97: }
|