tppt.db
Class DBLocker

java.lang.Object
  |
  +--tppt.db.DBLocker
Direct Known Subclasses:
DB2DBLocker, SybaseDBLocker

public class DBLocker
extends java.lang.Object

DBLocker is the class that is responsbile to obtain and releasse the Database lock for the single user mode. By using this class we can ensure there is only one user accessing the database at a time. Note that different DBMS has different ways to obtain the lock; it needs different stored procedure that is defined in the sync.xml file and there is different SQL State code to catch. Therefore, you should use this class as interface and each DBMS has to extends this class and implement its own class that overwrite how to get the db lock and its own SQL state code.

Version:
2.0
Author:
Jodie Wu
See Also:
SybaseDBLocker, DB2DBLocker

Field Summary
protected static java.sql.Connection conn
          DB Connection
protected static int LOCK_SP_NOT_EXIST
          The SQL State Error code: the getDBLock stored procedure does not exist.
protected static int LOCK_TABLE_NOT_EXIST
          The SQL State Error code: the Sync table does not exist.
protected static int TABLE_ALREADY_EXIST
          The SQL State Error code: the Sync table already exist.
protected static int TABLE_LOCK_INUSE
          The SQL State Error code: the Sync table has been locked.
 
Constructor Summary
DBLocker()
          The constructor
 
Method Summary
static boolean closeConnection(java.sql.Connection conn)
          Close the connection and it results in db lock releasing
static boolean closeStmt(java.sql.Statement stmt)
          Close the statement.
static boolean createConnection()
          connect to the database using the id and passd from GlobalData class.
static boolean createSyncTable(java.lang.String tablename, java.sql.Connection connection)
          Create the Sync table if it does not exist.
static boolean getDBLock()
          Obtain the database lock.
static void main(java.lang.String[] args)
           
static void releaseDBLock()
          Release the lock.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

LOCK_TABLE_NOT_EXIST

protected static final int LOCK_TABLE_NOT_EXIST
The SQL State Error code: the Sync table does not exist.

TABLE_ALREADY_EXIST

protected static final int TABLE_ALREADY_EXIST
The SQL State Error code: the Sync table already exist.

TABLE_LOCK_INUSE

protected static final int TABLE_LOCK_INUSE
The SQL State Error code: the Sync table has been locked.

LOCK_SP_NOT_EXIST

protected static final int LOCK_SP_NOT_EXIST
The SQL State Error code: the getDBLock stored procedure does not exist.

conn

protected static java.sql.Connection conn
DB Connection
Constructor Detail

DBLocker

public DBLocker()
The constructor
Method Detail

getDBLock

public static boolean getDBLock()
Obtain the database lock. It should be overwritten by the DBMS specfic class.
Returns:
true if db lock is obtained.

releaseDBLock

public static void releaseDBLock()
Release the lock.
See Also:
closeConnection(java.sql.Connection)

closeConnection

public static boolean closeConnection(java.sql.Connection conn)
Close the connection and it results in db lock releasing
Parameters:
conn - The database coneection
Returns:
true if the db connection otain sucessfully; false otherwise.

closeStmt

public static boolean closeStmt(java.sql.Statement stmt)
Close the statement.
Parameters:
stmt - the statemenet object
Returns:
true if close the statement sucessfully; false otherwise.

createConnection

public static boolean createConnection()
connect to the database using the id and passd from GlobalData class.

createSyncTable

public static boolean createSyncTable(java.lang.String tablename,
                                      java.sql.Connection connection)
Create the Sync table if it does not exist.
Parameters:
tablename - the name of table.
connection - DB connection.
Returns:
true if creation succeeds; false otherwise.

main

public static void main(java.lang.String[] args)