suncertify.common
Class QueryInterfaceImpl

java.lang.Object
  |
  +--suncertify.common.QueryInterfaceImpl
All Implemented Interfaces:
QueryInterface, java.rmi.Remote

public class QueryInterfaceImpl
extends java.lang.Object
implements QueryInterface

QueryInterface implementation for accessing Database. It have the same as DBMain interface but thay are additionally equipped with client login parameter and two additional method dataBase login and logout. Each method checks if client is logged in and sets the thread name to the login name value (important for locking mechnism) and execute appriopriate method on underlaying DBMain object additionally basic logging is being made.


Constructor Summary
QueryInterfaceImpl()
          Creates QueryInterfaceImpl instance.
QueryInterfaceImpl(DBMain data, LoggerSupport logger)
          Creates QueryInterfaceImpl instance.
QueryInterfaceImpl(LoggerSupport logger)
          Creates QueryInterfaceImpl instance.
 
Method Summary
 void closeDB()
          The method closes the db file - created for secure server shutdown you should never use the QueryImpl object after calling this method!!
 int create(java.lang.String[] data, java.lang.String clientId)
          Creates a new record in the database.
static java.lang.String createObjectURL(java.lang.String host, int port)
          Method formats URL string for binding remote object named DBServerQuery.
 void delete(int recNo, java.lang.String clientId)
          Deletes a record, making the record number and associated disk storage available for reuse.
 int[] find(java.lang.String[] criteria, java.lang.String clientId)
          Returns an array of record numbers that match the specified criteria.
 java.lang.String getClientList()
          Returns the String - list of the currently logged in clients
 boolean isLocked(int recNo, java.lang.String clientId)
          Determines if a record is currenly locked.
 void lock(int recNo, java.lang.String clientId)
          Locks a record so that it can only be updated or deleted by this client.
 java.lang.String logIn()
          The method performs client login.
 void logIn(java.lang.String login)
          The method performs client login.
 void logOut(java.lang.String clientId)
          The method performs client logout - no others connections with such login will be available
 java.lang.String[] read(int recNo, java.lang.String clientId)
          Reads a record from the file.
 void unlock(int recNo, java.lang.String clientId)
          Releases the lock on a record.
 void update(int recNo, java.lang.String[] data, java.lang.String clientId)
          Modifies the fields of a record.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryInterfaceImpl

public QueryInterfaceImpl()
                   throws IncorrectDataFile,
                          java.io.IOException
Creates QueryInterfaceImpl instance. It takes no parameters. Internaly creates the DBMain object instance on which db operation will be performed and the reference to the object is null so that no logging will be performed.

Throws:
java.io.IOException - - is thrown if file does not exist or cannot be opened
IncorrectDataFile - - is thrown when magic cookie value is incorrect

QueryInterfaceImpl

public QueryInterfaceImpl(LoggerSupport logger)
                   throws IncorrectDataFile,
                          java.io.IOException
Creates QueryInterfaceImpl instance. It takes one parameter, the reference to the object that can perform logging. Internaly creates the DBMain object instance on which db operation will be performed

Parameters:
logger - - the logger reference
Throws:
java.io.IOException - - is thrown if file does not exist or cannot be opened
IncorrectDataFile - - is thrown when magic cookie value is incorrect

QueryInterfaceImpl

public QueryInterfaceImpl(DBMain data,
                          LoggerSupport logger)
Creates QueryInterfaceImpl instance. It takes two parameters, the DBMain object instance reference on which db operation will be performed and the reference to the object that can perform logging.

Parameters:
data - - the DBMain reference
logger - - the logger reference
Method Detail

create

public int create(java.lang.String[] data,
                  java.lang.String clientId)
           throws DuplicateKeyException,
                  ClientNotLoggedInException
Creates a new record in the database.

Specified by:
create in interface QueryInterface
Parameters:
data - the array string representig values of the fields of the new record
clientId - the unique identifier of the clienent thet is performing request
Returns:
index of the newly created record
Throws:
DuplicateKeyException - - thrown when record could not be created
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.create(String[], String), DBMain.create(String[])

delete

public void delete(int recNo,
                   java.lang.String clientId)
            throws RecordNotFoundException,
                   ClientNotLoggedInException
Deletes a record, making the record number and associated disk storage available for reuse.

Specified by:
delete in interface QueryInterface
Parameters:
recNo - the index of the record to delete
clientId - the unique identifier of the clienent thet is performing request
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.delete(int, String), DBMain.delete(int)

find

public int[] find(java.lang.String[] criteria,
                  java.lang.String clientId)
           throws RecordNotFoundException,
                  ClientNotLoggedInException
Returns an array of record numbers that match the specified criteria.

Specified by:
find in interface QueryInterface
Parameters:
criteria - String array representing the criteria for each record field
clientId - the unique identifier of the clienent thet is performing request
Returns:
array containig indexes of all records meeting the criteria
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.find(String[], String), DBMain.find(String[])

isLocked

public boolean isLocked(int recNo,
                        java.lang.String clientId)
                 throws RecordNotFoundException,
                        ClientNotLoggedInException
Determines if a record is currenly locked. Returns true if the record is locked, false otherwise.

Specified by:
isLocked in interface QueryInterface
Parameters:
clientId - the unique identifier of the clienent thet is performing request
recNo - the index of the record to check
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.isLocked(int, String), DBMain.isLocked(int)

lock

public void lock(int recNo,
                 java.lang.String clientId)
          throws RecordNotFoundException,
                 ClientNotLoggedInException
Locks a record so that it can only be updated or deleted by this client.

Specified by:
lock in interface QueryInterface
Parameters:
recNo - the index of the record to lock
clientId - the unique identifier of the clienent thet is performing request
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.lock(int, String), DBMain.lock(int)

read

public java.lang.String[] read(int recNo,
                               java.lang.String clientId)
                        throws RecordNotFoundException,
                               ClientNotLoggedInException
Reads a record from the file.

Specified by:
read in interface QueryInterface
Parameters:
recNo - the index of the requested record
clientId - the unique identifier of the clienent thet is performing request
Returns:
string array with the values of requested record fields
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.read(int, String), DBMain.read(int)

unlock

public void unlock(int recNo,
                   java.lang.String clientId)
            throws RecordNotFoundException,
                   ClientNotLoggedInException
Releases the lock on a record.

Specified by:
unlock in interface QueryInterface
Parameters:
recNo - the index of the record to lock
clientId - the unique identifier of the clienent thet is performing request
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.unlock(int, String), DBMain.unlock(int)

update

public void update(int recNo,
                   java.lang.String[] data,
                   java.lang.String clientId)
            throws RecordNotFoundException,
                   ClientNotLoggedInException
Modifies the fields of a record.

Specified by:
update in interface QueryInterface
Parameters:
recNo - the index of the record to operate on
data - the new set of data for the requested record
clientId - the unique identifier of the clienent thet is performing request
Throws:
RecordNotFoundException - is thrown if a specified record does not exist or is marked as deleted in the database file.
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)
See Also:
QueryInterface.update(int,String[], String), DBMain.update(int, String[])

logIn

public void logIn(java.lang.String login)
           throws java.rmi.RemoteException
The method performs client login. It is required as server needs to identify clients. Client sugest login name value. Client is responsible for the name to be unique.

Specified by:
logIn in interface QueryInterface
Parameters:
login - client login
Throws:
java.rmi.RemoteException - - required for remote access
See Also:
QueryInterface.logIn(String)

logIn

public java.lang.String logIn()
                       throws java.rmi.RemoteException
The method performs client login. It is required as server needs to identify clients. Unique login name generated by the server is returned to the client

Specified by:
logIn in interface QueryInterface
Returns:
uniqe identifier that is required for all dataBase action invocations
Throws:
java.rmi.RemoteException - - required for remote access
See Also:
QueryInterface.logIn(String)

logOut

public void logOut(java.lang.String clientId)
            throws java.rmi.RemoteException,
                   ClientNotLoggedInException
The method performs client logout - no others connections with such login will be available

Specified by:
logOut in interface QueryInterface
Parameters:
clientId - uniqe client identifier
Throws:
java.rmi.RemoteException - - required for remote access
ClientNotLoggedInException - - is thrown when client login passed as argument is not a valid client login (e.g. client has not been logged in)

getClientList

public java.lang.String getClientList()
Returns the String - list of the currently logged in clients

Returns:
list of the logged in clients

closeDB

public void closeDB()
The method closes the db file - created for secure server shutdown you should never use the QueryImpl object after calling this method!! Note that it only works with Data class implementing DBmain interface


createObjectURL

public static java.lang.String createObjectURL(java.lang.String host,
                                               int port)
Method formats URL string for binding remote object named DBServerQuery.

Parameters:
host - - the name of the host on which object exists
port - - the port where object can be found
Returns:
the String representing object reference URL