public abstract class DatabaseManager
extends java.lang.Object
DriverManager.registerDriver()
is not necessary).
Here, the term database connection stands for the level on which the connection parameters
are collected (username, password, JDBC parameters etc.) while the connectors are
responsible for connecting to the databases on the driver level. Connections are unique
which means that they use a static (but configurable) data basis for the connectors.
In order to implement a session concept it is possible to create as many connectors
for each of the connections as required. The connection data basis is directly customized
using the DatabaseConnectionDialog
.
Modifier and Type | Field and Description |
---|---|
protected java.util.Vector<java.lang.String[]> |
backupSchemas
List of schemas, includes, and excludes to perform user-space backup.
|
protected java.util.Hashtable<java.lang.String,DatabaseConnection> |
cacheConnectionByID
Container holding the various database connections by their unique identifiers.
|
protected java.util.Hashtable<java.lang.String,java.util.Vector<DatabaseConnector>> |
cacheConnectorByConnectionID
Container holding the various connectors by the connection's unique identifiers.
|
protected java.util.Hashtable<java.lang.Integer,DatabaseConnector> |
cacheConnectorByConnectorID
Container holding the various connectors by the unique identifiers.
|
protected java.util.Hashtable<java.lang.String,DatabaseConnectorDef> |
cacheConnectorDefByType
Container holding the supported database connector definitions by their class name.
|
protected java.util.Hashtable<java.lang.String,EmbeddedHandler> |
cacheEmbeddedByType
Container holding the installed handlers for embedded databases by their connector class name.
|
protected int |
counterConnectorID
Sequence generator for connector identifiers, starts with 1.
|
protected java.lang.String[] |
inspectedSchemas
List of schemas to be used for graph analysis.
|
Constructor and Description |
---|
DatabaseManager()
Constuctor method for the manager.
|
Modifier and Type | Method and Description |
---|---|
void |
addBackupSchema(java.lang.String schema,
java.lang.String includes,
java.lang.String excludes)
Adds a schema used for backing up the user-space (set by sub-classes).
|
void |
addConnection(java.lang.String id,
DatabaseConnection dbconn)
Adds a new connection for a specific database system.
|
void |
addConnectorDef(DatabaseConnectorDef connectordef)
Adds a new connector definition providing if connector is supported and available.
|
void |
addEmbeddedHandler(EmbeddedHandler handler)
Adds a new handler for an embedded database.
|
void |
addInspectedSchema(java.lang.String schema)
Adds a schema used for graph analysis (set by sub-classes).
|
abstract boolean |
changePassword(java.lang.String type,
java.lang.String user,
java.lang.String password)
Changes the user password for the given embedded database.
|
abstract boolean |
connect(DatabaseConnector connector,
boolean updatecheck)
Connects to the configured database.
|
abstract java.sql.Connection |
createNewConnection(DatabaseConnector connector,
java.lang.String jdbcurl)
Lets the given connector create a new connection for the given JDBC URL.
|
DatabaseConnector |
createNewConnector(DatabaseConnection dbconn,
boolean force)
Creates a fresh new connector for the given type.
|
abstract DatabaseTabbedSession |
createNewSession(DatabaseConnection dbconn,
boolean connect)
Convenience method to create a new session.
|
protected int |
createNextConnectorID()
Generates the next unique connector identifier.
|
abstract boolean |
disconnect(DatabaseConnector connector)
Disconnects from the configured database.
|
protected void |
finalize()
Clean-up method to help the gc.
|
static DatabaseConnector[] |
findConnectors(DatabaseConnector[] connectors,
java.lang.Class clazz)
Convenience method to find a certain collector implementation from a list of connectors.
|
abstract boolean |
flushEmbedded(java.lang.String type)
Flushes the given embedded database.
|
abstract boolean |
freezeEmbedded(java.lang.String type)
Freezes the given embedded database.
|
DatabaseConnection[] |
getAllConnections()
Provides the database connection configurations currently managed sorted by names.
|
DatabaseConnectorDef[] |
getAllConnectorDefs()
Provides all connector definitions.
|
DatabaseConnector[] |
getAllConnectors()
Provides all connectors currently installed.
|
protected EmbeddedHandler[] |
getAllEmbeddedHandlers()
Provides the handlers for embedded databases currently managed (internal use only).
|
java.util.Vector<java.lang.String[]> |
getBackupSchemas()
Provides the list of schemas used for backing up the user-space (set by sub-classes).
|
DatabaseConnection |
getConnection(DatabaseConnector connector)
Provides a database connection configuration.
|
DatabaseConnection |
getConnection(java.lang.String id)
Provides a database connection configuration.
|
java.lang.String |
getConnectionName(DatabaseConnector connector)
Provides a database connection configuration.
|
DatabaseConnection[] |
getConnections(java.lang.String type)
Provides the database connections for the given type currently managed sorted by names.
|
DatabaseConnector |
getConnector(int id)
Provides the connector for the unique numerical identifier.
|
DatabaseConnectorDef |
getConnectorDef(java.lang.String clazz)
Removes the connector definition providing if connector is supported and available.
|
int |
getConnectorID(DatabaseConnector connector)
Provides the unique identifier of the connection for the given connector.
|
DatabaseConnector[] |
getConnectors(java.lang.String id)
Provides the connectors for the given connection currently installed.
|
abstract java.lang.String |
getDefaultConnectionURL(DatabaseConnector connector)
Provides the JDBC URL for the default connection (normally a user connection).
|
protected EmbeddedHandler |
getEmbeddedHandler(java.lang.String clazz)
Provides a handler for an embedded database (internal use only).
|
DatabaseConnector |
getFirstBestConnectedConnector(java.lang.String id)
Provides the connectors for the given connection currently installed.
|
java.lang.String[] |
getInspectedSchemas()
Provides the list of schemas used for graph analysis (set by sub-classes).
|
java.lang.String |
getUniqueConnectionID()
Provides the next connection identifier unique for this manager.
|
DatabaseConnectorDef[] |
getUsableConnectorDefs()
Provides the connector definitions that are available and supported.
|
boolean |
hasConnectorDef(java.lang.String clazz)
Checks whether the given connector class is supported by this database manager.
|
boolean |
hasEmbeddedHandler(java.lang.String clazz)
Checks whether the given handler for an embedded database exists.
|
boolean |
hasUsableConnectorDef(java.lang.String clazz)
Checks whether the given connector class is available and supported.
|
boolean |
isEmbedded(DatabaseConnector connector)
Is the given connector designed for an embedded database like Java DB?
|
abstract boolean |
isEmbeddedRunning(java.lang.String type)
Is the embedded database management system currently running?
|
abstract boolean |
isSchemaNewer(java.lang.String versionID1,
java.lang.String versionID2)
Checks whether the first schema version identifier is newer than the second.
|
void |
printDebugConnections()
Prints some debug information (connections).
|
void |
removeAllConnections()
Removes all installed connections from the internal container.
|
void |
removeAllConnectorDefs()
Removes all installed connector definitions providing if connector is supported and available.
|
void |
removeConnection(DatabaseConnection dbconn)
Removes the specified connection from the internal container.
|
void |
removeConnection(java.lang.String id)
Removes the specified connection from the internal container.
|
void |
removeConnector(DatabaseConnector connector)
Removes the given connector from the internal caches.
|
void |
removeConnectorDef(DatabaseConnectorDef connectordef)
Removes a connector definition providing if connector is supported and available.
|
void |
removeConnectorDef(java.lang.String clazz)
Removes a connector definition providing if connector is supported and available.
|
void |
removeEmbeddedHandler(java.lang.String clazz)
Removes a handler for an embedded database.
|
abstract boolean |
reset(DatabaseConnector connector)
Resets the connector for the configured database.
|
abstract boolean |
startEmbedded(java.lang.String type)
Starts the given embedded database.
|
abstract boolean |
stopEmbedded(java.lang.String type)
Stops the given embedded database.
|
abstract boolean |
unfreezeEmbedded(java.lang.String type)
Unfreezes the given embedded database.
|
abstract boolean |
update(DatabaseConnector connector,
SchemaProps schemaprops)
Updates the database schema for the given connector.
|
void |
updateConnections(java.util.Vector<DatabaseConnection> newconnections)
Updates the managed connections with the new configurations.
|
protected java.util.Hashtable<java.lang.String,DatabaseConnection> cacheConnectionByID
protected java.util.Hashtable<java.lang.String,java.util.Vector<DatabaseConnector>> cacheConnectorByConnectionID
protected java.util.Hashtable<java.lang.Integer,DatabaseConnector> cacheConnectorByConnectorID
protected java.util.Hashtable<java.lang.String,DatabaseConnectorDef> cacheConnectorDefByType
protected java.util.Hashtable<java.lang.String,EmbeddedHandler> cacheEmbeddedByType
protected java.util.Vector<java.lang.String[]> backupSchemas
protected java.lang.String[] inspectedSchemas
protected int counterConnectorID
public DatabaseManager()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- Error indicationpublic void addConnection(java.lang.String id, DatabaseConnection dbconn)
id
- The unique connection identifierdbconn
- The connection properties by DatabaseConnectionDialog
java.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If parameters are invalidpublic DatabaseConnection getConnection(java.lang.String id)
id
- The unique connection identifiernull
otherwisejava.lang.NullPointerException
- If parameters are null
public void removeConnection(java.lang.String id)
id
- The unique connection identifierjava.lang.NullPointerException
- If parameters are null
public void removeConnection(DatabaseConnection dbconn)
dbconn
- The connection properties by DatabaseConnectionDialog
java.lang.NullPointerException
- If parameters are null
public void removeAllConnections()
public DatabaseConnection[] getAllConnections()
public DatabaseConnection[] getConnections(java.lang.String type)
type
- The connector class type in FQNjava.lang.NullPointerException
- If parameters are null
public java.lang.String getUniqueConnectionID()
public void updateConnections(java.util.Vector<DatabaseConnection> newconnections)
newconnections
- The connections to be setjava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If parameters are invalidpublic void addConnectorDef(DatabaseConnectorDef connectordef)
connectordef
- The connector definition to be addedjava.lang.NullPointerException
- If parameters are null
public boolean hasConnectorDef(java.lang.String clazz)
clazz
- The connector classjava.lang.NullPointerException
- If parameters are null
public void removeConnectorDef(java.lang.String clazz)
clazz
- The connector classjava.lang.NullPointerException
- If parameters are null
public void removeConnectorDef(DatabaseConnectorDef connectordef)
connectordef
- The connector definition to be addedjava.lang.NullPointerException
- If parameters are null
public void removeAllConnectorDefs()
public DatabaseConnectorDef[] getAllConnectorDefs()
public DatabaseConnectorDef[] getUsableConnectorDefs()
public boolean hasUsableConnectorDef(java.lang.String clazz)
clazz
- The connector classjava.lang.NullPointerException
- If parameters are null
public DatabaseConnectorDef getConnectorDef(java.lang.String clazz)
clazz
- The connector classjava.lang.NullPointerException
- If parameters are null
public DatabaseConnector createNewConnector(DatabaseConnection dbconn, boolean force)
addConnection()
before.
dbconn
- The connectionforce
- Do not check if the connection has been added (required for connection management)java.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If a parameter is invalidpublic void removeConnector(DatabaseConnector connector)
connector
- The connectorjava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If a parameter is invalidpublic java.lang.String getConnectionName(DatabaseConnector connector)
connector
- The connectornull
java.lang.NullPointerException
- If parameters are null
public DatabaseConnection getConnection(DatabaseConnector connector)
connector
- The connectornull
java.lang.NullPointerException
- If parameters are null
public void addEmbeddedHandler(EmbeddedHandler handler)
handler
- The handler to be addedjava.lang.NullPointerException
- If parameters are null
public boolean hasEmbeddedHandler(java.lang.String clazz)
clazz
- The supported connector classjava.lang.NullPointerException
- If parameters are null
public void removeEmbeddedHandler(java.lang.String clazz)
clazz
- The connector classjava.lang.NullPointerException
- If parameters are null
protected EmbeddedHandler getEmbeddedHandler(java.lang.String clazz)
clazz
- The supported connector classnull
java.lang.NullPointerException
- If parameters are null
protected EmbeddedHandler[] getAllEmbeddedHandlers()
public int getConnectorID(DatabaseConnector connector)
connector
- The database connectorpublic DatabaseConnector getConnector(int id)
id
- The connector idnull
public DatabaseConnector[] getAllConnectors()
public DatabaseConnector[] getConnectors(java.lang.String id)
id
- The connection identifierjava.lang.NullPointerException
- If parameters are null
public DatabaseConnector getFirstBestConnectedConnector(java.lang.String id)
id
- The connection identifiernull
java.lang.NullPointerException
- If parameters are null
public static DatabaseConnector[] findConnectors(DatabaseConnector[] connectors, java.lang.Class clazz)
connectors
- The database connectorsclazz
- The desired connector classjava.lang.NullPointerException
- If parameters are invalidpublic void addBackupSchema(java.lang.String schema, java.lang.String includes, java.lang.String excludes)
DatabaseData
class to export/import database contents.
schema
- The schemaincludes
- The regex for tables to be included, all if null
excludes
- The regex for tables to be excluded, none if null
java.lang.NullPointerException
- If parameters are null
public java.util.Vector<java.lang.String[]> getBackupSchemas()
public void addInspectedSchema(java.lang.String schema)
schema
- The schemajava.lang.NullPointerException
- If parameters are null
public void printDebugConnections()
public java.lang.String[] getInspectedSchemas()
protected int createNextConnectorID()
public boolean isEmbedded(DatabaseConnector connector)
connector
- The database connectorpublic abstract java.lang.String getDefaultConnectionURL(DatabaseConnector connector)
connector
- The connectornull
if an error occursjava.lang.NullPointerException
- If the parameters are null
public abstract boolean connect(DatabaseConnector connector, boolean updatecheck)
DatabaseConnector.connect()
method directly. Asks the user for the user credentials if required and not configured.
Typical JDBC URLs look like "jdbc:derby://localhost:1527/lima".
connector
- The connectorupdatecheck
- Update database if necessaryjava.lang.NullPointerException
- If the parameters are null
public abstract boolean disconnect(DatabaseConnector connector)
DatabaseConnector.disconnect()
method directly.
connector
- The connectorjava.lang.NullPointerException
- If the parameters are null
public abstract boolean reset(DatabaseConnector connector)
connector
- The connectorjava.lang.NullPointerException
- If the parameters are null
public abstract java.sql.Connection createNewConnection(DatabaseConnector connector, java.lang.String jdbcurl)
connector
- The connectorjdbcurl
- The JDBC URLnull
if an error occurredjava.lang.NullPointerException
- If the parameters are null
public abstract boolean isSchemaNewer(java.lang.String versionID1, java.lang.String versionID2)
versionID1
- The first version identifierversionID2
- The second version identifierjava.lang.NullPointerException
- If the parameters are null
public abstract boolean update(DatabaseConnector connector, SchemaProps schemaprops)
connector
- The connector to use, should be already connectedschemaprops
- The schema propertiespublic abstract boolean isEmbeddedRunning(java.lang.String type)
type
- The connector class name in FQNpublic abstract boolean startEmbedded(java.lang.String type)
type
- The connector class name in FQNpublic abstract boolean stopEmbedded(java.lang.String type)
type
- The connector class name in FQNpublic abstract boolean flushEmbedded(java.lang.String type)
type
- The connector class name in FQNpublic abstract boolean freezeEmbedded(java.lang.String type)
type
- The connector class name in FQNpublic abstract boolean unfreezeEmbedded(java.lang.String type)
type
- The connector class name in FQNpublic abstract boolean changePassword(java.lang.String type, java.lang.String user, java.lang.String password)
type
- The connector class name in FQNuser
- The database userpassword
- The new passwordpublic abstract DatabaseTabbedSession createNewSession(DatabaseConnection dbconn, boolean connect)
dbconn
- The connection to useconnect
- Connect to databasenull
Copyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.