JProjects.eab.data
Class DatastoreJDBC

java.lang.Object
  |
  +--JProjects.eab.data.DatastoreJDBC
Direct Known Subclasses:
InformixJDBC

public class DatastoreJDBC
extends java.lang.Object
implements java.io.Serializable, JProjects.eab.data.OnThreadActionExecutor

Datastore JDBC objects represent datastore connections. This class manages these connections by providing client connection to the database, disconnection from the database, and the ability to commit and roll back database transactions.

Author:
Alexander Jaremenko
< jarem@altavista.net >
See Also:
Serialized Form

Field Summary
protected  ConnectionSupport _connectSupport
           
static int TRANSACTION_NONE
           
static int TRANSACTION_NOT_SET
           
static int TRANSACTION_READ_COMMITTED
           
static int TRANSACTION_READ_UNCOMMITTED
           
static int TRANSACTION_REPEATABLE_READ
           
static int TRANSACTION_SERIALIZABLE
           
 
Constructor Summary
DatastoreJDBC()
          This is the default constructor.
DatastoreJDBC(java.lang.String url)
          This constructor allows you to specify a URL that points to the database you want to connect to.
DatastoreJDBC(java.lang.String url, java.util.Properties prop)
          This constructor allows you to specify a URL that points to the datastore you want to connect to, and the properties information (user ID and password) for the datastore connection.
 
Method Summary
 void _executeAction(java.lang.String acnN, java.lang.Object[] params)
           
 void _handleException(java.lang.Exception ex)
           
protected  void _loadDriver()
           
protected  boolean _onBackground()
           
protected  void _putOnBackgroundThread(java.lang.String acnN, java.lang.Object[] params)
           
protected  void _setBusy(boolean flag)
           
 void addConnectionListener(ConnectionListener l)
          Use this method to register a listener for connection events.
 void cancel()
          This method cancels the method (for example, a database query) that is currently running.
 void commit()
          This method commits the current set of transations to the database.
 void connect()
          This method establishes a client connection to the current datastore object using default settings for the object's attributes.
 void connect(java.lang.String usr, java.lang.String passwd)
          This method establishes a client connection to the current datastore object using the passed-in user name and password.
 void disconnect()
          This method closes the connection to the datastore.
 void executeSQL(java.lang.String qry)
          This method executes the passed-in SQL statement in the current datastore.
 void finalize()
          This override of the Object finalize method checks to see if the connection object is closed, and if it is not, closes it.
static DatastoreJDBC getApplicationDatastore()
          This method gets the datastore object that has been set as default for the application.
 java.sql.Connection getConnection()
          This method returns a java.sql.Connection object that represents the client connection to the current datastore object.
 java.lang.String getDriver()
          This method gets the JDBC driver setting of the current datastore.
 java.util.Properties getProperties()
          This method gets the properties of the current datastore.
 int getTransactionIsolation()
          This method gets the current connection object's transaction isolation level.
 java.lang.String getURL()
          This method gets the URL used by the current connection.
 boolean isAsynchronous()
          This method tells you whether methods are set to run on a background thread or not.
 boolean isAutoCommit()
          This method queries the current connection object's auto-commit setting.
 boolean isBusy()
          This method tells you whether the object is running a method in the background.
 boolean isConnected()
          This method queries whether there is a connection established to the database.
 boolean isReadOnly()
          This method returns a boolean indicating the read/write status of the datastore.
 void removeConnectionListener(ConnectionListener l)
          Use this method to remove the listener on the connection object.
 void rollback()
          This method rolls back all transactions since the last successful commit.
static void setApplicationDatastore(DatastoreJDBC ds)
          This method sets the application's default datastore to the passed-in datastore.
 void setAsApplicationDatastore()
          Use this method to set the application's default datastore to the current DatastoreJDBC object.
 void setAsynchronous(boolean isAs)
          This method lets you set whether the database methods are run on a background thread.
 void setAutoCommit(boolean flag)
          This method lets you set the current connection object so that it automatically commits all transactions.
 void setConnection(java.sql.Connection con)
          Sets connection for this datastore object.
 void setDriver(java.lang.String drvName)
          This method sets the JDBC driver for the database to which you want to connect.
 void setProperties(java.util.Properties prop)
          This method uses the passed-in Properties object to set the user ID and password properties of the current datastore.
 void setReadOnly(boolean flag)
          This method allows you to change the read/write access for the current datastore connection.
 void setTransactionIsolation(int level)
          This method sets the current connection object's isolation level to the level you pass in.
 void setURL(java.lang.String url)
          This method sets the URL for the database to which you want to connect.
 java.lang.String toString()
          This method outputs a string indicating URL for the current database.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRANSACTION_NONE

public static final int TRANSACTION_NONE

TRANSACTION_READ_UNCOMMITTED

public static final int TRANSACTION_READ_UNCOMMITTED

TRANSACTION_READ_COMMITTED

public static final int TRANSACTION_READ_COMMITTED

TRANSACTION_REPEATABLE_READ

public static final int TRANSACTION_REPEATABLE_READ

TRANSACTION_SERIALIZABLE

public static final int TRANSACTION_SERIALIZABLE

TRANSACTION_NOT_SET

public static final int TRANSACTION_NOT_SET

_connectSupport

protected transient ConnectionSupport _connectSupport
Constructor Detail

DatastoreJDBC

public DatastoreJDBC()
This is the default constructor.

DatastoreJDBC

public DatastoreJDBC(java.lang.String url)
This constructor allows you to specify a URL that points to the database you want to connect to.
Parameters:
url - - URL of the Database.

DatastoreJDBC

public DatastoreJDBC(java.lang.String url,
                     java.util.Properties prop)
This constructor allows you to specify a URL that points to the datastore you want to connect to, and the properties information (user ID and password) for the datastore connection.
Parameters:
url - - URL of the Database.
prop - - Properties for the database connection.
Method Detail

_executeAction

public void _executeAction(java.lang.String acnN,
                           java.lang.Object[] params)
                    throws java.lang.Exception
Specified by:
_executeAction in interface JProjects.eab.data.OnThreadActionExecutor

_handleException

public void _handleException(java.lang.Exception ex)
Specified by:
_handleException in interface JProjects.eab.data.OnThreadActionExecutor

addConnectionListener

public void addConnectionListener(ConnectionListener l)
Use this method to register a listener for connection events.
Parameters:
l - a ConnectionListener to listen for connection events.

cancel

public void cancel()
            throws DAException
This method cancels the method (for example, a database query) that is currently running.
Throws:
DAException - - if data access error occur.

commit

public void commit()
            throws DAException
This method commits the current set of transations to the database.
Throws:
DAException - - if data access error occur.

connect

public void connect()
             throws DAException,
                    java.lang.ClassNotFoundException
This method establishes a client connection to the current datastore object using default settings for the object's attributes.
Throws:
DAException - - if data access error occur.
java.lang.ClassNotFoundException - - if fail register driver for default URL.

connect

public void connect(java.lang.String usr,
                    java.lang.String passwd)
             throws DAException,
                    java.lang.ClassNotFoundException
This method establishes a client connection to the current datastore object using the passed-in user name and password.
Parameters:
usr - - user's name known to the Database server.
passwd - - user's password.
Throws:
DAException - - if data access error occur.
java.lang.ClassNotFoundException - - if fail register driver for default URL.

disconnect

public void disconnect()
                throws DAException
This method closes the connection to the datastore.
Throws:
DAException - - if data access error occur.

executeSQL

public void executeSQL(java.lang.String qry)
                throws DAException
This method executes the passed-in SQL statement in the current datastore.
Parameters:
qry - - SQL statement.
Throws:
DAException - - if data access error occur.

finalize

public void finalize()
This override of the Object finalize method checks to see if the connection object is closed, and if it is not, closes it.
Overrides:
finalize in class java.lang.Object

getApplicationDatastore

public static DatastoreJDBC getApplicationDatastore()
This method gets the datastore object that has been set as default for the application.

getConnection

public java.sql.Connection getConnection()
This method returns a java.sql.Connection object that represents the client connection to the current datastore object.

setConnection

public void setConnection(java.sql.Connection con)
Sets connection for this datastore object.
Parameters:
con - - established client connection to the Database.

getDriver

public java.lang.String getDriver()
This method gets the JDBC driver setting of the current datastore.

getProperties

public java.util.Properties getProperties()
This method gets the properties of the current datastore.

getTransactionIsolation

public int getTransactionIsolation()
                            throws DAException
This method gets the current connection object's transaction isolation level.
Throws:
DAException - - if data access error occur.

getURL

public java.lang.String getURL()
This method gets the URL used by the current connection.

isAsynchronous

public boolean isAsynchronous()
This method tells you whether methods are set to run on a background thread or not.

isAutoCommit

public boolean isAutoCommit()
                     throws DAException
This method queries the current connection object's auto-commit setting.
Returns:
true if this connection is in autocommit mode.
Throws:
DAException - - if data access error occur.

isBusy

public boolean isBusy()
This method tells you whether the object is running a method in the background.

isConnected

public boolean isConnected()
This method queries whether there is a connection established to the database.

isReadOnly

public boolean isReadOnly()
                   throws DAException
This method returns a boolean indicating the read/write status of the datastore.
Throws:
DAException - - if data access error occur.

removeConnectionListener

public void removeConnectionListener(ConnectionListener l)
Use this method to remove the listener on the connection object.
Parameters:
l - - ConnectionListener object to remove.

rollback

public void rollback()
              throws DAException
This method rolls back all transactions since the last successful commit.
Throws:
DAException - - if data access error occur.

setApplicationDatastore

public static void setApplicationDatastore(DatastoreJDBC ds)
This method sets the application's default datastore to the passed-in datastore.

setAsApplicationDatastore

public void setAsApplicationDatastore()
Use this method to set the application's default datastore to the current DatastoreJDBC object.

setAsynchronous

public void setAsynchronous(boolean isAs)
This method lets you set whether the database methods are run on a background thread.

setAutoCommit

public void setAutoCommit(boolean flag)
                   throws DAException
This method lets you set the current connection object so that it automatically commits all transactions.
Throws:
DAException - - if data access error occur.

setDriver

public void setDriver(java.lang.String drvName)
This method sets the JDBC driver for the database to which you want to connect.

setProperties

public void setProperties(java.util.Properties prop)
This method uses the passed-in Properties object to set the user ID and password properties of the current datastore.

setReadOnly

public void setReadOnly(boolean flag)
                 throws DAException
This method allows you to change the read/write access for the current datastore connection.
Throws:
DAException - - if data access error occur.

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws DAException
This method sets the current connection object's isolation level to the level you pass in.
Throws:
DAException - - if data access error occur.

setURL

public void setURL(java.lang.String url)
This method sets the URL for the database to which you want to connect.

toString

public java.lang.String toString()
This method outputs a string indicating URL for the current database.
Overrides:
toString in class java.lang.Object

_loadDriver

protected void _loadDriver()
                    throws java.lang.ClassNotFoundException

_onBackground

protected boolean _onBackground()

_putOnBackgroundThread

protected void _putOnBackgroundThread(java.lang.String acnN,
                                      java.lang.Object[] params)

_setBusy

protected void _setBusy(boolean flag)