KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.tools.DataFileConvertTool 23 Nov 2000
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 java.io.*;
28 import com.mckoi.database.*;
29 import com.mckoi.database.control.*;
30 import com.mckoi.util.CommandLine;
31 import com.mckoi.debug.*;
32
33 /**
34  * A tool for converting between different versions of the database file
35  * system.
36  *
37  * @author Tobias Downer
38  */

39
40 public class DataFileConvertTool {
41
42   /**
43    * Prints the syntax.
44    */

45   private static void printSyntax() {
46     System.out.println("DataFileConvertTool -path [data files path] " +
47                        "-u [admin username] -p [admin password]");
48   }
49
50   /**
51    * Application start point.
52    */

53   public static void main(String JavaDoc[] args) {
54     CommandLine cl = new CommandLine(args);
55
56     String JavaDoc path = cl.switchArgument("-path");
57     String JavaDoc admin_username = cl.switchArgument("-u");
58     String JavaDoc admin_password = cl.switchArgument("-p");
59     
60     if (path == null) {
61       printSyntax();
62       System.out.println("Error: -path not found on command line.");
63       System.exit(-1);
64     }
65     if (admin_username == null) {
66       printSyntax();
67       System.out.println("Error: -u [username] not found on command line.");
68       System.exit(-1);
69     }
70     if (admin_password == null) {
71       printSyntax();
72       System.out.println("Error: -p [password] not found on command line.");
73       System.exit(-1);
74     }
75
76     DatabaseSystem system = new DatabaseSystem();
77
78     // Create a default configuration
79
DefaultDBConfig config = new DefaultDBConfig();
80     config.setDatabasePath(path);
81     config.setMinimumDebugLevel(Integer.MAX_VALUE);
82     
83     // Set up the log file
84
system.setDebugLevel(Integer.MAX_VALUE);
85
86     // Initialize the DatabaseSystem,
87
// -----------------------------
88

89     // This will throw an Error exception if the database system has already
90
// been initialized.
91
system.init(config);
92
93     // Start the database class
94
// ------------------------
95

96     // Note, currently we only register one database, and it is named
97
// 'DefaultDatabase'.
98
Database database = new Database(system, "DefaultDatabase");
99
100     boolean success = false;
101     try {
102       // Convert to the current version.
103
success = database.convertToCurrent(System.out, admin_username);
104     }
105     catch (IOException e) {
106       System.out.println("IO Error: " + e.getMessage());
107       e.printStackTrace(System.out);
108     }
109
110     if (success) {
111       System.out.println("-- Convert Successful --");
112     }
113     else {
114       System.out.println("-- Convert Failed --");
115     }
116
117     // Shut down (and clean up) the database
118
database.startShutDownThread();
119     database.waitUntilShutdown();
120     
121   }
122
123 }
124
Popular Tags