Top Description Fields Constructors Methods
org.hsqldb

public Class DatabaseManager

extends Object
Class Inheritance
Imports
java.util.TimeZone, java.util.concurrent.atomic.AtomicInteger, org.hsqldb.error.Error, .ErrorCode, org.hsqldb.lib.FileUtil, .HashMap, .HashSet, .HsqlArrayList, .HsqlTimer, .IntKeyHashMap, .Iterator, .Notified, org.hsqldb.map.ValuePool, org.hsqldb.persist.HsqlProperties

Handles initial attempts to connect to HSQLDB databases within the JVM (or a classloader within the JVM). Opens the database if it is not open or connects to it if it is already open. This allows the same database to be used by different instances of Server and by direct connections.

Maintains a map of Server instances and notifies each server when its database has shut down.

Maintains a reference to the timer used for file locks and logging.

Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
2.7.3

Field Summary

Modifier and TypeField and Description
pack-priv static final IntKeyHashMap<Database>
databaseIDMap

id number to Database for Databases currently in registry

private static AtomicInteger
dbIDCounter

provides unique ID's for the Databases currently in registry

pack-priv static final HashMap<String, Database>
fileDatabaseMap

File to Database mapping for file: databases

pack-priv static final HashMap<String, Database>
memDatabaseMap

name to Database mapping for mem: databases

pack-priv static final HashMap<String, Database>
resDatabaseMap

File to Database mapping for res: databases

pack-priv static final HashMap<Notified, HashSet<Database>>
serverMap

Maintains a map of servers to sets of databases.

private static final HsqlTimer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static synchronized void
addDatabaseObject(DatabaseType type, String path, Database db)

Adds a database to the registry.

public static void
closeDatabases(int mode)

Closes all the databases using the given mode.

public static void
deRegisterServer(Notified server)

Deregisters a server completely.

private static String
public static int
getDatabase(String type, String path, Notified server, HsqlProperties props)

Used by server to open or create a database

public static Database
getDatabase(int id)

public static Database
getDatabase(String dbtype, String path, HsqlProperties props)

This has to be improved once a threading model is in place.

private static synchronized Database
public static HsqlArrayList<String>
getDatabaseURIs()

Returns a list containing the URI (type + path) for all the databases.

public static Session
getSession(int dbId, long sessionId)

Returns an existing session.

public static HsqlTimer
pack-priv static boolean
public static synchronized Database
lookupDatabaseObject(DatabaseType type, String path)

Looks up database of a given type and path in the registry.

public static Session
newSession(int dbID, String user, String password, String zoneString)

Used by server to open a new session

public static Session
newSession(String type, String path, String user, String password, HsqlProperties props, TimeZone zone)

Used by in-process connections and by Servlet

private static void
notifyServers(Database db)

Notifies all servers that serve the database that the database has been shutdown.

private static void
registerServer(Notified server, Database db)

Registers a server as serving a given database.

pack-priv static void
removeDatabase(Database database)

Removes the database from registry.

public static void
shutdownDatabases(Notified server, int shutdownMode)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databaseIDMapback to summary
pack-priv static final IntKeyHashMap<Database> databaseIDMap

id number to Database for Databases currently in registry

dbIDCounterback to summary
private static AtomicInteger dbIDCounter

provides unique ID's for the Databases currently in registry

fileDatabaseMapback to summary
pack-priv static final HashMap<String, Database> fileDatabaseMap

File to Database mapping for file: databases

memDatabaseMapback to summary
pack-priv static final HashMap<String, Database> memDatabaseMap

name to Database mapping for mem: databases

resDatabaseMapback to summary
pack-priv static final HashMap<String, Database> resDatabaseMap

File to Database mapping for res: databases

serverMapback to summary
pack-priv static final HashMap<Notified, HashSet<Database>> serverMap

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.

timerback to summary
private static final HsqlTimer timer

Constructor Detail

DatabaseManagerback to summary
public DatabaseManager()

Method Detail

addDatabaseObjectback to summary
private static synchronized void addDatabaseObject(DatabaseType type, String path, Database db)

Adds a database to the registry.

closeDatabasesback to summary
public static void closeDatabases(int mode)

Closes all the databases using the given mode.

CLOSEMODE_IMMEDIATELY = 1; CLOSEMODE_NORMAL = 2; CLOSEMODE_COMPACT = 3; CLOSEMODE_SCRIPT = 4;

deRegisterServerback to summary
public static void deRegisterServer(Notified server)

Deregisters a server completely.

filePathToKeyback to summary
private static String filePathToKey(String path)
getDatabaseback to summary
public static int getDatabase(String type, String path, Notified server, HsqlProperties props)

Used by server to open or create a database

getDatabaseback to summary
public static Database getDatabase(int id)
getDatabaseback to summary
public static Database getDatabase(String dbtype, String path, HsqlProperties props)

This has to be improved once a threading model is in place. Current behaviour: Attempts to connect to different databases do not block. Two db's can open simultaneously. Attempts to connect to a db while it is opening or closing will block until the db is open or closed. At this point the db state is either DATABASE_ONLINE (after db.open() has returned) which allows a new connection to be made, or the state is DATABASE_SHUTDOWN which means the db can be reopened for the new connection.

getDatabaseObjectback to summary
private static synchronized Database getDatabaseObject(DatabaseType type, String path, HsqlProperties props)
getDatabaseURIsback to summary
public static HsqlArrayList<String> getDatabaseURIs()

Returns a list containing the URI (type + path) for all the databases.

getSessionback to summary
public static Session getSession(int dbId, long sessionId)

Returns an existing session. Used with repeat HTTP connections belonging to the same JDBC Connection / HSQL Session pair.

getTimerback to summary
public static HsqlTimer getTimer()
isServerDBback to summary
pack-priv static boolean isServerDB(Database db)
lookupDatabaseObjectback to summary
public static synchronized Database lookupDatabaseObject(DatabaseType type, String path)

Looks up database of a given type and path in the registry. Returns null if there is none.

newSessionback to summary
public static Session newSession(int dbID, String user, String password, String zoneString)

Used by server to open a new session

newSessionback to summary
public static Session newSession(String type, String path, String user, String password, HsqlProperties props, TimeZone zone)

Used by in-process connections and by Servlet

notifyServersback to summary
private static void notifyServers(Database db)

Notifies all servers that serve the database that the database has been shutdown.

registerServerback to summary
private static void registerServer(Notified server, Database db)

Registers a server as serving a given database.

removeDatabaseback to summary
pack-priv static void removeDatabase(Database database)

Removes the database from registry.

shutdownDatabasesback to summary
public static void shutdownDatabases(Notified server, int shutdownMode)