1 package org.apache.torque; 2 3 21 22 import java.sql.Connection ; 23 import java.util.Map ; 24 25 import org.apache.commons.configuration.Configuration; 26 import org.apache.torque.adapter.DB; 27 import org.apache.torque.manager.AbstractBaseManager; 28 import org.apache.torque.map.DatabaseMap; 29 import org.apache.torque.map.MapBuilder; 30 31 45 public class Torque 46 { 47 50 public static final String TORQUE_KEY = "torque"; 51 52 56 public static final String DATABASE_KEY = "database"; 57 58 61 public static final String DEFAULT_KEY = "default"; 62 63 68 public static final String DATABASE_DEFAULT 69 = DATABASE_KEY + "." + DEFAULT_KEY; 70 71 74 public static final String MANAGER_PREFIX = "managed_class."; 75 76 80 public static final String MANAGER_SUFFIX = ".manager"; 81 82 85 public static final String CACHE_KEY = "manager.useCache"; 86 87 91 private static TorqueInstance torqueSingleton = null; 92 93 98 public Torque() 99 { 100 } 101 102 108 public static TorqueInstance getInstance() 109 { 110 if (torqueSingleton == null) 111 { 112 torqueSingleton = new TorqueInstance(); 113 } 114 return torqueSingleton; 115 } 116 117 124 public static synchronized void setInstance(TorqueInstance instance) 125 { 126 torqueSingleton = instance; 127 } 128 129 136 public static void init(String configFile) 137 throws TorqueException 138 { 139 getInstance().init(configFile); 140 } 141 142 149 public static void init(Configuration conf) 150 throws TorqueException 151 { 152 getInstance().init(conf); 153 } 154 155 160 public static boolean isInit() 161 { 162 return getInstance().isInit(); 163 } 164 165 170 public static void setConfiguration(Configuration conf) 171 { 172 getInstance().setConfiguration(conf); 173 } 174 175 180 public static Configuration getConfiguration() 181 { 182 return getInstance().getConfiguration(); 183 } 184 185 191 public static AbstractBaseManager getManager(String name) 192 { 193 return getInstance().getManager(name); 194 } 195 196 204 public static AbstractBaseManager getManager(String name, 205 String defaultClassName) 206 { 207 return getInstance().getManager(name, defaultClassName); 208 } 209 210 220 public static void shutdown() 221 throws TorqueException 222 { 223 getInstance().shutdown(); 224 } 225 226 233 public static DatabaseMap getDatabaseMap() 234 throws TorqueException 235 { 236 return getInstance().getDatabaseMap(); 237 } 238 239 249 public static DatabaseMap getDatabaseMap(String name) 250 throws TorqueException 251 { 252 return getInstance().getDatabaseMap(name); 253 } 254 255 260 public static void registerMapBuilder(String className) 261 { 262 getInstance().registerMapBuilder(className); 263 } 264 265 271 public static void registerMapBuilder(MapBuilder builder) 272 { 273 getInstance().registerMapBuilder(builder); 274 } 275 276 284 public static MapBuilder getMapBuilder(String className) 285 throws TorqueException 286 { 287 return getInstance().getMapBuilder(className); 288 } 289 290 297 public static Connection getConnection() 298 throws TorqueException 299 { 300 return getInstance().getConnection(); 301 } 302 303 311 public static Connection getConnection(String name) 312 throws TorqueException 313 { 314 return getInstance().getConnection(name); 315 } 316 317 329 public static Connection getConnection(String name, String username, 330 String password) 331 throws TorqueException 332 { 333 return getInstance().getConnection(name, username, password); 334 } 335 343 public static DB getDB(String name) throws TorqueException 344 { 345 return getInstance().getDB(name); 346 } 347 348 353 public static String getDefaultDB() 354 { 355 return getInstance().getDefaultDB(); 356 } 357 358 363 public static void closeConnection(Connection con) 364 { 365 getInstance().closeConnection(con); 366 } 367 368 376 public static void setSchema(String name, String schema) 377 throws TorqueException 378 { 379 getInstance().setSchema(name, schema); 380 } 381 382 390 public static String getSchema(String name) 391 throws TorqueException 392 { 393 return getInstance().getSchema(name); 394 } 395 396 404 public static Database getDatabase(String name) throws TorqueException 405 { 406 return getInstance().getDatabase(name); 407 } 408 409 423 public static Map getDatabases() throws TorqueException 424 { 425 return getInstance().getDatabases(); 426 } 427 } 428 | Popular Tags |