01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2006 Continuent.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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): Gilles Rayrat.
19: * Contributor(s): ______________________.
20: */package org.continuent.sequoia.console.text.commands.dbadmin;
21:
22: import java.util.List;
23: import java.util.StringTokenizer;
24:
25: import javax.management.openmbean.TabularData;
26:
27: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
28: import org.continuent.sequoia.common.jmx.mbeans.RecoveryLogControlMBean;
29: import org.continuent.sequoia.console.text.formatter.TableFormatter;
30: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
31:
32: public class DumpTransaction extends AbstractAdminCommand {
33:
34: public DumpTransaction(VirtualDatabaseAdmin module) {
35: super (module);
36: }
37:
38: /**
39: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
40: */
41: public void parse(String commandText) throws Exception {
42: StringTokenizer st = new StringTokenizer(commandText.trim());
43: if (st.countTokens() != 1) {
44: console.printError(getUsage());
45: return;
46: }
47:
48: long tid = Long.parseLong(st.nextToken());
49:
50: RecoveryLogControlMBean recoveryLog = jmxClient.getRecoveryLog(
51: dbName, user, password);
52:
53: String[] headers = recoveryLog.getHeaders();
54: // first headers is used to sort the entries
55: final String idKey = headers[0];
56: TabularData logEntries = recoveryLog
57: .getRequestsInTransaction(tid);
58:
59: if (logEntries.isEmpty()) {
60: console.printInfo(ConsoleTranslate.get(
61: "DumpTransaction.empty", tid)); //$NON-NLS-1$
62: return;
63: }
64:
65: List entries = JMXUtils.sortEntriesByKey(logEntries, idKey);
66: String[][] entriesStr = JMXUtils.from(entries, headers);
67: console.println(TableFormatter
68: .format(headers, entriesStr, true));
69:
70: }
71:
72: /**
73: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
74: */
75: public String getCommandName() {
76: return "dump transaction"; //$NON-NLS-1$
77: }
78:
79: /**
80: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
81: */
82: public String getCommandParameters() {
83: return "<transaction ID>"; //$NON-NLS-1$
84: }
85:
86: /**
87: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
88: */
89: public String getCommandDescription() {
90: return ConsoleTranslate.get("DumpTransaction.description"); //$NON-NLS-1$
91: }
92: }
|