Source Code Cross Referenced for DBController.java in  » Database-DBMS » mckoi » com » mckoi » database » control » 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 » mckoi » com.mckoi.database.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * com.mckoi.dbcontrol.DBController  26 Mar 2002
003:         *
004:         * Mckoi SQL Database ( http://www.mckoi.com/database )
005:         * Copyright (C) 2000, 2001, 2002  Diehl and Associates, Inc.
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * Version 2 as published by the Free Software Foundation.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License Version 2 for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * Version 2 along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         * Change Log:
021:         * 
022:         * 
023:         */package com.mckoi.database.control;
024:
025:        import com.mckoi.database.Database;
026:        import com.mckoi.database.DatabaseSystem;
027:        import com.mckoi.database.DatabaseException;
028:        import com.mckoi.debug.*;
029:        import com.mckoi.util.LogWriter;
030:
031:        import java.io.File;
032:        import java.io.Writer;
033:        import java.io.PrintWriter;
034:        import java.io.IOException;
035:        import java.util.Date;
036:
037:        /**
038:         * An object that provides methods for creating and controlling database
039:         * systems in the current JVM.
040:         *
041:         * @author Tobias Downer
042:         */
043:
044:        public final class DBController {
045:
046:            /**
047:             * This object can not be constructed outside of this package.
048:             */
049:            DBController() {
050:            }
051:
052:            /**
053:             * Returns true if a Mckoi database exists in the given directory of the
054:             * file system, otherwise returns false if the path doesn't contain a
055:             * database.
056:             * <p>
057:             * The path string must be formatted using Unix '/' deliminators as
058:             * directory separators.
059:             *
060:             * @param config the configuration of the database to check the existence
061:             *   of.
062:             * @return true if a database exists at the given path, false otherwise.
063:             */
064:            public boolean databaseExists(DBConfig config) {
065:                Database database = createDatabase(config);
066:                boolean b = database.exists();
067:                database.getSystem().dispose();
068:                return b;
069:            }
070:
071:            /**
072:             * Creates a database in the local JVM (and filesystem) given the
073:             * configuration in DBConfig and returns a DBSystem object.  When this
074:             * method returns, the database created will be up and running providing
075:             * there was no failure during the database creation process.
076:             * <p>
077:             * A failure might happen because the database path does not exist.
078:             *
079:             * @param admin_user the username of the administrator for the new database.
080:             * @param admin_pass the password of the administrator for the new database.
081:             * @param config the configuration of the database to create and start in the
082:             *   local JVM.
083:             * @return the DBSystem object used to access the database created.
084:             */
085:            public DBSystem createDatabase(DBConfig config, String admin_user,
086:                    String admin_pass) {
087:
088:                // Create the Database object with this configuration.
089:                Database database = createDatabase(config);
090:                DatabaseSystem system = database.getSystem();
091:
092:                // Create the database.
093:                try {
094:                    database.create(admin_user, admin_pass);
095:                    database.init();
096:                } catch (DatabaseException e) {
097:                    system.Debug().write(Lvl.ERROR, this ,
098:                            "Database create failed");
099:                    system.Debug().writeException(e);
100:                    throw new RuntimeException(e.getMessage());
101:                }
102:
103:                // Return the DBSystem object for the newly created database.
104:                return new DBSystem(this , config, database);
105:
106:            }
107:
108:            /**
109:             * Starts a database in the local JVM given the configuration in DBConfig
110:             * and returns a DBSystem object.  When this method returns, the database
111:             * will be up and running providing there was no failure to initialize the
112:             * database.
113:             * <p>
114:             * A failure might happen if the database does not exist in the path given
115:             * in the configuration.
116:             *
117:             * @param config the configuration of the database to start in the local
118:             *   JVM.
119:             * @return the DBSystem object used to access the database started.
120:             */
121:            public DBSystem startDatabase(DBConfig config) {
122:
123:                // Create the Database object with this configuration.
124:                Database database = createDatabase(config);
125:                DatabaseSystem system = database.getSystem();
126:
127:                // First initialise the database
128:                try {
129:                    database.init();
130:                } catch (DatabaseException e) {
131:                    system.Debug().write(Lvl.ERROR, this ,
132:                            "Database init failed");
133:                    system.Debug().writeException(e);
134:                    throw new RuntimeException(e.getMessage());
135:                }
136:
137:                // Return the DBSystem object for the newly created database.
138:                return new DBSystem(this , config, database);
139:
140:            }
141:
142:            // ---------- Static methods ----------
143:
144:            /**
145:             * Creates a Database object for the given DBConfig configuration.
146:             */
147:            private static Database createDatabase(DBConfig config) {
148:
149:                DatabaseSystem system = new DatabaseSystem();
150:
151:                // Initialize the DatabaseSystem first,
152:                // ------------------------------------
153:
154:                // This will throw an Error exception if the database system has already
155:                // been initialized.
156:                system.init(config);
157:
158:                // Start the database class
159:                // ------------------------
160:
161:                // Note, currently we only register one database, and it is named
162:                //   'DefaultDatabase'.
163:                Database database = new Database(system, "DefaultDatabase");
164:
165:                // Start up message
166:                system.Debug().write(Lvl.MESSAGE, DBController.class,
167:                        "Starting Database Server");
168:
169:                return database;
170:            }
171:
172:            /**
173:             * Returns the static controller for this JVM.
174:             */
175:            public static DBController getDefault() {
176:                return VM_DB_CONTROLLER;
177:            }
178:
179:            /**
180:             * The static DBController object.
181:             */
182:            private final static DBController VM_DB_CONTROLLER = new DBController();
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.