Package adams.db
Class DatabaseManager<T extends AbstractDatabaseConnection>
- java.lang.Object
-
- adams.db.DatabaseManager<T>
-
- Type Parameters:
T
- the type of database this manager is for
- All Implemented Interfaces:
Serializable
public class DatabaseManager<T extends AbstractDatabaseConnection> extends Object implements Serializable
Manages the database URL/connection object relations.- Author:
- fracpete (fracpete at waikato dot ac dot
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static Map<String,AbstractDatabaseConnection>
m_AllConnections
for storing all database connection objects.protected Map<String,T>
m_Connections
for storing the database connection objects.protected String
m_DatabaseName
the database this manager is for.protected T
m_DefaultDatabaseConnection
the default database connection.
-
Constructor Summary
Constructors Constructor Description DatabaseManager(String dbName)
Initializes the manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
add(T dbcon)
Adds the database object (uses the current URL as key).String
createURL(String url, String user, BasePassword password)
Generates a URL that includes the user name.String
createURL(T dbcon)
Generates a URL that includes the user name.static void
disconnectAllConnections()
Performs a disconnect on all connects and removes them.void
disconnectConnections()
Performs a disconnect on all connects and removes them.T
get(String url, String user, BasePassword password)
Gets the database object for the specified URL.static List<AbstractDatabaseConnection>
getActiveConnectionObjects()
Returns active (ie currently connected) connection objects.static List<AbstractDatabaseConnection>
getConnectionObjects()
Returns the connection objects.String
getDatabaseName()
Returns the name of the database this manager is handling.T
getDefault()
Returns the default database connection.boolean
has(String url, String user, BasePassword password)
Checks whether a database object for the specified URL is available.Iterator<T>
iterator()
Returns an iterator over all databases.void
setDefault(T value)
Sets the default database connection.String
toString()
Returns a short string representation of the manager.
-
-
-
Field Detail
-
m_DatabaseName
protected String m_DatabaseName
the database this manager is for.
-
m_Connections
protected Map<String,T extends AbstractDatabaseConnection> m_Connections
for storing the database connection objects.
-
m_DefaultDatabaseConnection
protected T extends AbstractDatabaseConnection m_DefaultDatabaseConnection
the default database connection.
-
m_AllConnections
protected static Map<String,AbstractDatabaseConnection> m_AllConnections
for storing all database connection objects.
-
-
Constructor Detail
-
DatabaseManager
public DatabaseManager(String dbName)
Initializes the manager.- Parameters:
dbName
- the name of the database this manager is for
-
-
Method Detail
-
getDatabaseName
public String getDatabaseName()
Returns the name of the database this manager is handling.- Returns:
- the database name
-
createURL
public String createURL(T dbcon)
Generates a URL that includes the user name.- Parameters:
dbcon
- the database connection object to create the URL for- Returns:
- the complete URL
-
createURL
public String createURL(String url, String user, BasePassword password)
Generates a URL that includes the user name.- Parameters:
url
- the JDBC URLuser
- the database userpassword
- the database password- Returns:
- the complete URL
-
has
public boolean has(String url, String user, BasePassword password)
Checks whether a database object for the specified URL is available.- Parameters:
url
- the URL to checkuser
- the database userpassword
- the database password- Returns:
- true if a database object is available
-
get
public T get(String url, String user, BasePassword password)
Gets the database object for the specified URL.- Parameters:
url
- the URL to get the database foruser
- the database userpassword
- the database password- Returns:
- the database object if available, otherwise null
-
add
public T add(T dbcon)
Adds the database object (uses the current URL as key).- Parameters:
dbcon
- the database object to add- Returns:
- the previous database, null if no previous one stored
-
setDefault
public void setDefault(T value)
Sets the default database connection.- Parameters:
value
- the default connection object
-
getDefault
public T getDefault()
Returns the default database connection.- Returns:
- the default
-
iterator
public Iterator<T> iterator()
Returns an iterator over all databases.- Returns:
- the iterator
-
toString
public String toString()
Returns a short string representation of the manager.
-
getConnectionObjects
public static List<AbstractDatabaseConnection> getConnectionObjects()
Returns the connection objects.- Returns:
- the connection objects
-
getActiveConnectionObjects
public static List<AbstractDatabaseConnection> getActiveConnectionObjects()
Returns active (ie currently connected) connection objects.- Returns:
- the connection objects
-
disconnectConnections
public void disconnectConnections()
Performs a disconnect on all connects and removes them.- See Also:
m_Connections
-
disconnectAllConnections
public static void disconnectAllConnections()
Performs a disconnect on all connects and removes them.- See Also:
m_AllConnections
-
-