KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > tools > DBConglomerateRepairTool


1 /**
2  * com.mckoi.tools.DBConglomerateRepairTool 11 Apr 2001
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.tools;
26
27 import com.mckoi.database.*;
28 import com.mckoi.util.CommandLine;
29 import com.mckoi.util.ShellUserTerminal;
30 import com.mckoi.database.control.*;
31 import java.io.*;
32
33 /**
34  * A command line repair tool for repairing a corrupted conglomerate.
35  *
36  * @author Tobias Downer
37  */

38
39 public class DBConglomerateRepairTool {
40
41   private static void repair(String JavaDoc path, String JavaDoc name) {
42
43     ShellUserTerminal terminal = new ShellUserTerminal();
44
45     TransactionSystem system = new TransactionSystem();
46     DefaultDBConfig config = new DefaultDBConfig();
47     config.setDatabasePath(path);
48     config.setLogPath("");
49     config.setMinimumDebugLevel(50000);
50     // We do not use the NIO API for repairs for safety.
51
config.setValue("do_not_use_nio_api", "enabled");
52     system.setDebugOutput(new StringWriter());
53     system.init(config);
54     final TableDataConglomerate conglomerate =
55                      new TableDataConglomerate(system, system.storeSystem());
56     // Check it.
57
conglomerate.fix(name, terminal);
58
59     // Dispose the transaction system
60
system.dispose();
61   }
62
63   /**
64    * Prints the syntax.
65    */

66   private static void printSyntax() {
67     System.out.println("DBConglomerateRepairTool -path [data directory] " +
68                        "[-name [database name]]");
69   }
70
71   /**
72    * Application start point.
73    */

74   public static void main(String JavaDoc[] args) {
75     CommandLine cl = new CommandLine(args);
76
77     String JavaDoc path = cl.switchArgument("-path");
78     String JavaDoc name = cl.switchArgument("-name", "DefaultDatabase");
79
80     if (path == null) {
81       printSyntax();
82       System.out.println("Error: -path not found on command line.");
83       System.exit(-1);
84     }
85
86     // Start the tool.
87
repair(path, name);
88
89   }
90
91
92 }
93
Popular Tags