Source Code Cross Referenced for Install.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » tools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » Ozone 1.1 » org.ozoneDB.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006:        //
007:        // $Id: Install.java,v 1.2 2002/05/08 15:48:50 per_nyfelt Exp $
008:
009:        package org.ozoneDB.tools;
010:
011:        import java.io.*;
012:        import java.util.*;
013:        import org.ozoneDB.*;
014:        import org.ozoneDB.core.*;
015:
016:        public class Install extends Object {
017:
018:            protected static String dirName;
019:
020:            /* our log message outputter, we set to console per default so users of
021:             * static methods does not get a NPE
022:             */
023:            protected static PrintWriter log = new PrintWriter(System.out);
024:
025:            public static void main(String[] args) throws Exception {
026:                String dir = File.separator + "tmp" + File.separator + "db"
027:                        + File.separator;
028:                boolean help = false;
029:
030:                for (int i = 0; i < args.length; i++) {
031:                    if (args[i].startsWith("-d")) {
032:                        dir = args[i].substring(2) + File.separator;
033:                    } else if (args[i].startsWith("-h")) {
034:                        help = true;
035:                    } else {
036:                        System.out.println("illegal option: " + args[i]);
037:                        help = true;
038:                    }
039:                }
040:
041:                if (args.length == 0 || help) {
042:                    System.out
043:                            .println("usage: ozoneInst -d<dir> [-D<property>=<value>]*");
044:                    System.out
045:                            .println("   -d<directory>         database directory");
046:                    // System.out.println ("   -id<database id>      id-number of the database");
047:                    System.out
048:                            .println("   -h                    shows this help");
049:                    System.out.println("");
050:
051:                    System.out.println("where properties include:");
052:                    Setup defaults = new Setup(null);
053:                    defaults.fillWithOzoneDefaults();
054:                    for (Enumeration e = defaults.propertyNames(); e
055:                            .hasMoreElements();) {
056:                        System.out.println("    " + (String) e.nextElement());
057:                    }
058:                    System.exit(0);
059:                }
060:
061:                //
062:                try {
063:                    File file = new File(dir);
064:                    if (file.list().length > 0) {
065:                        System.out
066:                                .print("Do you want to recursively delete all files in "
067:                                        + dir + " ? [y/N]");
068:
069:                        InputStreamReader is = new InputStreamReader(System.in);
070:
071:                        int c = is.read();
072:                        if (c != 'y') {
073:                            System.exit(0);
074:                        }
075:                    }
076:                } catch (Exception e) {
077:                }
078:
079:                System.out.println("installing database in " + dir + " ...");
080:
081:                Setup defaults = new Setup(null);
082:                defaults.addProperties(System.getProperties(), "ozoneDB.");
083:                createDB(dir, defaults, new PrintWriter(System.out, true));
084:
085:                // System.out.println ("");
086:                System.out.println("Edit the file " + dir
087:                        + "config.properties to change settings.");
088:                System.out.println("Ready.");
089:            }
090:
091:            public static void createDB(String _dirName, Setup _defaults,
092:                    PrintWriter _log) throws Exception {
093:                log = _log;
094:                dirName = _dirName + File.separator;
095:
096:                mkDir();
097:                makeDataDir();
098:                makeIdTableDir();
099:
100:                resetConfigFile(_defaults);
101:                resetStateFile(_defaults);
102:            }
103:
104:            /**
105:             * Create the ozone database directory.
106:             */
107:            public static void mkDir() throws Exception {
108:                //        deleteDir (dirName + Env.DATA_DIR);
109:                //        deleteDir (dirName + Env.STATS_DIR);
110:                deleteDir(dirName, true);
111:
112:                File f = new File(dirName);
113:                if (!f.exists()) {
114:                    log.println("making dir " + dirName + " ...");
115:                    f.mkdir();
116:                }
117:            }
118:
119:            public static void resetStateFile(Setup config) throws IOException {
120:                log.println("making " + dirName + Env.STATE_FILE + " ...");
121:
122:                Setup state = new Setup(null);
123:                long dbID = config.longProperty(Setup.DB_ID, 0);
124:
125:                // keep 100 ids free for internal use
126:                state.setLongProperty(Setup.XOID, (dbID << 40) + 100);
127:                log.println("    ID counter = " + dbID + " * 2^40");
128:
129:                OutputStream out = new PrintStream(new FileOutputStream(
130:                        new File(dirName, Env.STATE_FILE)));
131:                state.save(out, "Ozone Server State File.\n#Do not edit!");
132:                out.close();
133:            }
134:
135:            public static Setup resetConfigFile(Setup _defaults)
136:                    throws IOException {
137:                log.println("making " + dirName + Env.CONFIG_FILE + " ...");
138:
139:                Setup defaults = new Setup(null);
140:                defaults.fillWithOzoneDefaults();
141:                defaults.addProperties(_defaults, "ozoneDB.");
142:
143:                OutputStream out = new FileOutputStream(new File(dirName,
144:                        Env.CONFIG_FILE));
145:                defaults
146:                        .save(
147:                                out,
148:                                "Ozone Config File.\n"
149:                                        + "#\n"
150:                                        + "# Do not use comments. This file will be overwritten,\n"
151:                                        + "# if the config changes. See the ozone documentation\n"
152:                                        + "# for details about the properties and their values.\n");
153:                out.close();
154:
155:                defaults.print(System.out, "", "    ");
156:                // System.out.println ("The server will use these default settings.");
157:                return defaults;
158:            }
159:
160:            /**
161:             * Create the cluster directory.
162:             */
163:            public static void makeDataDir() throws IOException {
164:                log.println("making " + dirName + Env.DATA_DIR + " ...");
165:
166:                File f = new File(dirName + Env.DATA_DIR);
167:                if (!f.exists()) {
168:                    f.mkdir();
169:                }
170:            }
171:
172:            public static void makeIdTableDir() throws IOException {
173:                log.println("making " + dirName + Env.OS_DIR + " ...");
174:
175:                File f = new File(dirName + Env.OS_DIR);
176:                if (!f.exists()) {
177:                    f.mkdir();
178:                }
179:            }
180:
181:            public static void deleteDir(String path, boolean recursive)
182:                    throws IOException {
183:                log.println("deleting " + path + " ...");
184:                File f = new File(path);
185:                String[] files = f.list();
186:                if (files == null) {
187:                    return;
188:                }
189:
190:                for (int i = 0; i < files.length; i++) {
191:                    File file = new File(path, files[i]);
192:                    if (file.isDirectory()) {
193:                        if (recursive) {
194:                            deleteDir(file.getPath(), recursive);
195:                        }
196:                    } else {
197:                        if (!file.delete()) {
198:                            log.println("Unable to delete " + file + ".");
199:                        }
200:                    }
201:                }
202:            }
203:
204:            /* Tells whether a database has been installed in the dbDir directory or not
205:             * by checking to see if we have a config file in the database directory.
206:             * Useful for erver when starting up the ExternalDatabase and makes it possible to
207:             * determine whether to create or open a LocalDatabase
208:             */
209:            public static boolean dbExists(String dbDir) {
210:                File testFile = new File(dbDir, Env.CONFIG_FILE);
211:                return testFile.exists();
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.