📄 databasemanager.java
字号:
key = filePathToKey(path); } else if (type == DatabaseURL.S_RES) { databaseMap = resDatabaseMap; } else if (type == DatabaseURL.S_MEM) { databaseMap = memDatabaseMap; } else { throw Trace.runtimeError(Trace.UNSUPPORTED_INTERNAL_OPERATION, "DatabaseManager.getDatabaseObject"); } db = (Database) databaseMap.get(key); if (db == null) { db = new Database(type, path, type + key, props); db.databaseID = dbIDCounter; databaseIDMap.put(dbIDCounter, db); dbIDCounter++; databaseMap.put(key, db); } return db; } /** * Looks up database of a given type and path in the registry. Returns * null if there is none. */ private static synchronized Database lookupDatabaseObject(String type, String path) throws HsqlException { Object key = path; HashMap databaseMap; if (type == DatabaseURL.S_FILE) { databaseMap = fileDatabaseMap; key = filePathToKey(path); } else if (type == DatabaseURL.S_RES) { databaseMap = resDatabaseMap; } else if (type == DatabaseURL.S_MEM) { databaseMap = memDatabaseMap; } else { throw (Trace.runtimeError( Trace.UNSUPPORTED_INTERNAL_OPERATION, "DatabaseManager.lookupDatabaseObject()")); } return (Database) databaseMap.get(key); } /** * Adds a database to the registry. Returns * null if there is none. */ private static synchronized void addDatabaseObject(String type, String path, Database db) throws HsqlException { Object key = path; HashMap databaseMap; if (type == DatabaseURL.S_FILE) { databaseMap = fileDatabaseMap; key = filePathToKey(path); } else if (type == DatabaseURL.S_RES) { databaseMap = resDatabaseMap; } else if (type == DatabaseURL.S_MEM) { databaseMap = memDatabaseMap; } else { throw Trace.runtimeError(Trace.UNSUPPORTED_INTERNAL_OPERATION, "DatabaseManager.addDatabaseObject()"); } databaseIDMap.put(db.databaseID, db); databaseMap.put(key, db); } /** * Removes the database from registry. */ static void removeDatabase(Database database) { int dbID = database.databaseID; String type = database.getType(); String path = database.getPath(); Object key = path; HashMap databaseMap; notifyServers(database); if (type == DatabaseURL.S_FILE) { databaseMap = fileDatabaseMap;// boucherb@users 20040124 - patch 1.7.2// Under the current contract, it's essentially impossible for an// exception to get thrown here, because the database could not// have been registered successfully before hand using the same// path//// Eventually, we might think about storing the key with the// database instance so as to avoid this unnecessary additional// conversion and highly unlikely corner case handling. try { key = filePathToKey(path); } catch (HsqlException e) { Iterator it = databaseMap.keySet().iterator(); Object foundKey = null; while (it.hasNext()) { Object currentKey = it.next(); if (databaseMap.get(currentKey) == database) { foundKey = currentKey; break; } } if (foundKey == null) { // ??? return; } else { key = foundKey; } } } else if (type == DatabaseURL.S_RES) { databaseMap = resDatabaseMap; } else if (type == DatabaseURL.S_MEM) { databaseMap = memDatabaseMap; } else { throw (Trace.runtimeError( Trace.UNSUPPORTED_INTERNAL_OPERATION, "DatabaseManager.lookupDatabaseObject()")); } databaseIDMap.remove(dbID); databaseMap.remove(key); if (databaseIDMap.isEmpty()) { ValuePool.resetPool(); } } /** * Maintains a map of servers to sets of databases. * Servers register each of their databases. * When a database is shutdown, all the servers accessing it are notified. * The database is then removed form the sets for all servers and the * servers that have no other database are removed from the map. */ static HashMap serverMap = new HashMap(); /** * Deregisters a server completely. */ static void deRegisterServer(Server server) { serverMap.remove(server); } /** * Deregisters a server as serving a given database. Not yet used. */ private static void deRegisterServer(Server server, Database db) { Iterator it = serverMap.values().iterator(); for (; it.hasNext(); ) { HashSet databases = (HashSet) it.next(); databases.remove(db); if (databases.isEmpty()) { it.remove(); } } } /** * Registers a server as serving a given database. */ private static void registerServer(Server server, Database db) { if (!serverMap.containsKey(server)) { serverMap.put(server, new HashSet()); } HashSet databases = (HashSet) serverMap.get(server); databases.add(db); } /** * Notifies all servers that serve the database that the database has been * shutdown. */ private static void notifyServers(Database db) { Iterator it = serverMap.keySet().iterator(); for (; it.hasNext(); ) { Server server = (Server) it.next(); HashSet databases = (HashSet) serverMap.get(server); if (databases.contains(db)) { server.notify(ServerConstants.SC_DATABASE_SHUTDOWN, db.databaseID); } } } static boolean isServerDB(Database db) { Iterator it = serverMap.keySet().iterator(); for (; it.hasNext(); ) { Server server = (Server) it.next(); HashSet databases = (HashSet) serverMap.get(server); if (databases.contains(db)) { return true; } } return false; } // Timer private static final HsqlTimer timer = new HsqlTimer(); public static HsqlTimer getTimer() { return timer; } // converts file path to database lookup key, converting any // thrown exception to an HsqlException in the process private static String filePathToKey(String path) throws HsqlException { try { return FileUtil.canonicalPath(path); } catch (Exception e) { throw Trace.error(Trace.FILE_IO_ERROR, e.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -