net.datacrow.core.db
Class DatabaseManager

java.lang.Object
  extended by net.datacrow.core.db.DatabaseManager

public class DatabaseManager
extends java.lang.Object

The database manager is responsible for all databases. This class is the only service providing access to the databases.

Author:
Robert Jan van der Waals

Field Summary
static boolean initialized
           
 
Constructor Summary
DatabaseManager()
           
 
Method Summary
static void applySettings()
          Apply settings on the databases.
static void changePassword(User user, java.lang.String password)
          Change the password for the given user.
static void closeDatabases(boolean compact)
          Closes the database connections.
static void createUser(User user, java.lang.String password)
          Creates a user with all the correct privileges
static void delete(DcObject dco)
           
static void deleteUser(User user)
          Removes a user from the database
static java.sql.ResultSet executeSQL(java.lang.String sql)
          Executes a query.
static java.sql.Connection getAdminConnection()
          Creates an admin connection to the database.
static java.sql.Connection getConnection()
          Returns a new connection to the database based on the logged on user.
static java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Returns a connection for the given user credentials.
static java.util.Map<java.lang.String,java.lang.Integer> getKeys(DataFilter filter)
           
static Version getOriginalVersion()
          Retrieves the original database version (the version before the database was upgraded).
static int getQueueSize()
          Retrieves the count of currently queued queries.
static Version getVersion()
          Retrieves the current database version.
static void initialize()
          Initializes the database.
static void insert(DcObject dco)
          Stores the item in the database.
static boolean isLocked()
          Checks whether the database is available.
static boolean isUnique(DcObject o, boolean isExisting)
          Checks the database to see if the item already exists.
protected static void setPriviliges(DcModule module, java.lang.String user, boolean admin)
          Applies the users privileges on the database tables and columns.
protected static void setPriviliges(DcModule module, User user)
           
static void setPriviliges(java.lang.String user, boolean admin)
          Updates the privileges of an existing user.
static void setPriviliges(User user)
          Updates the privileges of an existing user.
static void update(DcObject dco)
          Update the item in the database with the values from the specified item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initialized

public static boolean initialized
Constructor Detail

DatabaseManager

public DatabaseManager()
Method Detail

initialize

public static void initialize()
Initializes the database. A connection with the HSQL database engine is established and the if needed the databases are upgraded.


getOriginalVersion

public static Version getOriginalVersion()
Retrieves the original database version (the version before the database was upgraded).

Returns:

getVersion

public static Version getVersion()
Retrieves the current database version.

Returns:
The current version. If version information could not be found an undetermined version is returned.

getQueueSize

public static int getQueueSize()
Retrieves the count of currently queued queries.


applySettings

public static void applySettings()
Apply settings on the databases.


isLocked

public static boolean isLocked()
Checks whether the database is available. It could be the database is locked.


closeDatabases

public static void closeDatabases(boolean compact)
Closes the database connections.

Parameters:
compact - Indicates if the database should be compacted.

getConnection

public static java.sql.Connection getConnection()
Returns a new connection to the database based on the logged on user.


getConnection

public static java.sql.Connection getConnection(java.lang.String username,
                                                java.lang.String password)
Returns a connection for the given user credentials. Note that this connection always needs to be closed manually. For re-use use getConnection() or getAdminConnection().

Parameters:
username -
password -
Returns:

getKeys

public static java.util.Map<java.lang.String,java.lang.Integer> getKeys(DataFilter filter)

executeSQL

public static java.sql.ResultSet executeSQL(java.lang.String sql)
                                     throws java.sql.SQLException
Executes a query.

Parameters:
sql - SQL statement.
log - Indicates if information on the query should be logged.
Returns:
The result set.
Throws:
java.sql.SQLException

update

public static void update(DcObject dco)
Update the item in the database with the values from the specified item.

Parameters:
dco -

insert

public static void insert(DcObject dco)
Stores the item in the database.

Parameters:
dco -

delete

public static void delete(DcObject dco)

isUnique

public static boolean isUnique(DcObject o,
                               boolean isExisting)
Checks the database to see if the item already exists.

Parameters:
o - The item to check.
isExisting - Indicates if the check is performed for a new or an existing item.

getAdminConnection

public static java.sql.Connection getAdminConnection()
Creates an admin connection to the database.


changePassword

public static void changePassword(User user,
                                  java.lang.String password)
Change the password for the given user.

Parameters:
user -
password -

deleteUser

public static void deleteUser(User user)
Removes a user from the database


createUser

public static void createUser(User user,
                              java.lang.String password)
Creates a user with all the correct privileges


setPriviliges

public static void setPriviliges(User user)
Updates the privileges of an existing user.

Parameters:
user -

setPriviliges

public static void setPriviliges(java.lang.String user,
                                 boolean admin)
Updates the privileges of an existing user.

Parameters:
user -
admin - Indicates if the user is an administrator.

setPriviliges

protected static void setPriviliges(DcModule module,
                                    User user)

setPriviliges

protected static void setPriviliges(DcModule module,
                                    java.lang.String user,
                                    boolean admin)
Applies the users privileges on the database tables and columns.

Parameters:
module -
user -
admin -