All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tc.database.DatabaseManager

java.lang.Object
   |
   +----tc.database.DatabaseManager

public class DatabaseManager
extends Object
implements ExceptionObserver
DatabaseManager handles the communication with the database. A new DatabaseManager object is intended to be created for every database connection (for every database user).

DatabaseManager stores the user name and id and marker ids of the user for whom the database is opened (via this manager). These attributes are obtained during database opening and marker fetching and they are later used to ensure that only data associated with this user is tampered via this manager.

The interface ExceptionObserver (namely the operation exceptionOccured) is implemented so that it closes the database. This mechanism is used in exception situations.

Version:
0.30, 1998/04/01
Author:
Antti Viljamaa, FRED development team
See Also:
ExceptionObserver

Variable Index

 o connectionDescriptor
The connection descriptor for the database.
 o database
The database.
 o databaseOpen
Determines whether the database is open.
 o databaseStarted
Determines whether the database was succesfully started.
 o databaseStartException
The possible exception that occured upon a failed database start.
 o markerIDs
Vector of marker ids of the user.
 o userID
The user id (ssn) of the user.
 o userName
The user name of the user.

Constructor Index

 o DatabaseManager()
Constructs a new DatabaseManager object and tries to start it.

Method Index

 o closeDatabase()
Closes the database.
 o createDataSet(String, boolean)
Creates a new QueryDataSet and executes the specified query to fill it.
 o exceptionOccured(Exception)
An exception has occured during message sending or receiving.
 o getConnectionDescriptor()
Returns connection descriptor for the database.
 o getDatabase()
Returns the database.
 o getDatabaseStartException()
Gets the possible exception occured during database starting.
 o getMarkerIDs()
Returns the marker ids of the user.
 o getUserID()
Gets the user id.
 o getUserName()
Gets the username.
 o isDatabaseOpen()
Determines if the database is opened.
 o isDatabaseStarted()
Determines whether the database is started.
 o isValidMarker(int)
Determines if the specified marker is valid.
 o openDatabase(String, byte[])
Opens the database and returns the account options associated with the given userName.
 o runQuery(DatabaseQuery)
Executes the given query.
 o setConnectionDescriptor(ConnectionDescriptor)
Sets connection descriptor for the database.
 o setDatabaseOpen(boolean)
Sets the flag that determines if the database is opened.
 o setDatabaseStarted(boolean)
Sets the flag that determines whether the database is started.
 o setDatabaseStartException(Exception)
Sets the possible exception occured during database starting.
 o setMarkerIDs(Vector)
Sets the marker ids of the user.
 o setUserID(String)
Sets the user id.
 o setUserName(String)
Sets the username.
 o startDatabaseManager()
Starts the database.
 o trunc(long)
Truncates last three digits from a long integer.

Variables

 o database
 private Database database
The database.

 o databaseOpen
 private boolean databaseOpen
Determines whether the database is open.

 o databaseStarted
 private boolean databaseStarted
Determines whether the database was succesfully started.

 o databaseStartException
 private Exception databaseStartException
The possible exception that occured upon a failed database start.

 o markerIDs
 private Vector markerIDs
Vector of marker ids of the user.

 o userID
 private String userID
The user id (ssn) of the user. The key in the 'Worker' table.

 o userName
 private String userName
The user name of the user. The key in the 'UserAccount' table.

 o connectionDescriptor
 private ConnectionDescriptor connectionDescriptor
The connection descriptor for the database.

Constructors

 o DatabaseManager
 public DatabaseManager()
Constructs a new DatabaseManager object and tries to start it. A possible exception that occurs is stored and later thrown when the openDatabase method is invoked.

See Also:
openDatabase

Methods

 o closeDatabase
 public void closeDatabase() throws DataSetException, DatabaseAlreadyClosedException
Closes the database.

 o exceptionOccured
 public void exceptionOccured(Exception exception)
An exception has occured during message sending or receiving. We assume that connection to the client has terminated. Closes the database.

This method is the implementation for ExceptionObserver interface.

Parameters:
exception - The exception that has occured.
See Also:
ExceptionObserver
 o getMarkerIDs
 public Vector getMarkerIDs()
Returns the marker ids of the user.

 o getUserID
 public String getUserID()
Gets the user id.

 o getUserName
 public String getUserName()
Gets the username.

 o isDatabaseOpen
 public boolean isDatabaseOpen()
Determines if the database is opened.

 o isDatabaseStarted
 public boolean isDatabaseStarted()
Determines whether the database is started.

 o openDatabase
 public AccountOptionsMessage openDatabase(String userName,
                                           byte passwd[]) throws Exception
Opens the database and returns the account options associated with the given userName. Checks that the given encrypted password matches the one in the database.

Parameters:
userName - The user whose data is going to be examined (and altered).
passwd - The encrypted password of the user.
 o runQuery
 public Object runQuery(DatabaseQuery query) throws ValidationException, DataSetException
Executes the given query.

Parameters:
DatabaseQuery - The query to be executed.
Returns:
Object The query result.
 o getConnectionDescriptor
 public ConnectionDescriptor getConnectionDescriptor()
Returns connection descriptor for the database.

 o setConnectionDescriptor
 public void setConnectionDescriptor(ConnectionDescriptor cd)
Sets connection descriptor for the database.

 o getDatabase
 protected Database getDatabase()
Returns the database.

 o getDatabaseStartException
 protected Exception getDatabaseStartException()
Gets the possible exception occured during database starting.

 o isValidMarker
 protected boolean isValidMarker(int markerid)
Determines if the specified marker is valid. Marker id is valid if it is found among the markers calculated for the user.

Parameters:
markerid - The marker id that is checked.
 o setDatabaseOpen
 protected void setDatabaseOpen(boolean flag)
Sets the flag that determines if the database is opened.

 o setDatabaseStarted
 protected void setDatabaseStarted(boolean flag)
Sets the flag that determines whether the database is started.

 o setUserID
 protected void setUserID(String id)
Sets the user id.

 o setUserName
 protected void setUserName(String n)
Sets the username.

 o createDataSet
 private QueryDataSet createDataSet(String queryClause,
                                    boolean updatable) throws DataSetException
Creates a new QueryDataSet and executes the specified query to fill it.

Parameters:
queryClause - An SQL query as a string.
updatable - Determines if the dataset to be created must be updatable (used in insertion or deletion).
Returns:
QueryDataSet The created data set.
 o setDatabaseStartException
 private void setDatabaseStartException(Exception e)
Sets the possible exception occured during database starting.

 o setMarkerIDs
 private void setMarkerIDs(Vector v)
Sets the marker ids of the user.

 o startDatabaseManager
 private void startDatabaseManager() throws DataSetException, ValidationException
Starts the database.

 o trunc
 static long trunc(long original)
Truncates last three digits from a long integer.

Parameters:
original - The original value.
Returns:
long The truncated value.

All Packages  Class Hierarchy  This Package  Previous  Next  Index