1 24 25 package com.mckoi.database.control; 26 27 import com.mckoi.database.Database; 28 import com.mckoi.database.DatabaseSystem; 29 import com.mckoi.database.DatabaseException; 30 import com.mckoi.debug.*; 31 import com.mckoi.util.LogWriter; 32 33 import java.io.File ; 34 import java.io.Writer ; 35 import java.io.PrintWriter ; 36 import java.io.IOException ; 37 import java.util.Date ; 38 39 45 46 public final class DBController { 47 48 51 DBController() { 52 } 53 54 66 public boolean databaseExists(DBConfig config) { 67 Database database = createDatabase(config); 68 boolean b = database.exists(); 69 database.getSystem().dispose(); 70 return b; 71 } 72 73 87 public DBSystem createDatabase(DBConfig config, 88 String admin_user, String admin_pass) { 89 90 Database database = createDatabase(config); 92 DatabaseSystem system = database.getSystem(); 93 94 try { 96 database.create(admin_user, admin_pass); 97 database.init(); 98 } 99 catch (DatabaseException e) { 100 system.Debug().write(Lvl.ERROR, this, "Database create failed"); 101 system.Debug().writeException(e); 102 throw new RuntimeException (e.getMessage()); 103 } 104 105 return new DBSystem(this, config, database); 107 108 } 109 110 123 public DBSystem startDatabase(DBConfig config) { 124 125 Database database = createDatabase(config); 127 DatabaseSystem system = database.getSystem(); 128 129 try { 131 database.init(); 132 } 133 catch (DatabaseException e) { 134 system.Debug().write(Lvl.ERROR, this, "Database init failed"); 135 system.Debug().writeException(e); 136 throw new RuntimeException (e.getMessage()); 137 } 138 139 return new DBSystem(this, config, database); 141 142 } 143 144 145 147 150 private static Database createDatabase(DBConfig config) { 151 152 DatabaseSystem system = new DatabaseSystem(); 153 154 157 system.init(config); 160 161 164 Database database = new Database(system, "DefaultDatabase"); 167 168 system.Debug().write(Lvl.MESSAGE, DBController.class, 170 "Starting Database Server"); 171 172 return database; 173 } 174 175 178 public static DBController getDefault() { 179 return VM_DB_CONTROLLER; 180 } 181 182 185 private final static DBController VM_DB_CONTROLLER = new DBController(); 186 187 } 188 | Popular Tags |