DataSourceProcess

public abstract class DataSourceProcess

DataSourceProcess represents a data source transaction process. Subclasses are required to implement the doTransaction() method for the transaction process.

This process will only manage, for example commit or rollback, the transaction encapsulated if its DataSourceDAO is not under a transaction and it is not explicitly instructed, in construction, to use a specified transaction.

Author:Hugo Y. K. Lam

Constructors

DataSourceProcess

public DataSourceProcess(DataSourceDAO dao)

Creates a new instance of DataSourceProcess.

Parameters:
  • dao – the DAO to which this process correspond.

DataSourceProcess

public DataSourceProcess(DataSourceDAO dao, DataSourceTransaction transaction)

Creates a new instance of DataSourceProcess.

Parameters:
  • dao – the DAO to which this process correspond.
  • transaction – the transaction in which this process should execute.

Methods

doTransaction

protected abstract void doTransaction(DataSourceTransaction tx)

Executes the transaction process.

Parameters:
  • tx – the DataSourceTransaction object in which this process executes.
Throws:

getDAO

protected DataSourceDAO getDAO()

Gets the DAO to which this process correspond.

Returns:the DAO to which this process correspond.

getParameterCount

protected int getParameterCount(PreparedStatement pStmt, String sql)

Counts the number of parameters required by the prepared statement. If a parameter meta data is not available, it counts the occurrences of ‘?’ in the given SQL statement.

Parameters:
  • pStmt – the prepared statement.
  • sql – the SQL statement.
Returns:

the numbder of parameters.

getResult

public Object getResult()

Gets the result of this process.

Returns:the result of this process.

isCommitted

public boolean isCommitted()

Checks if this process has committed the transaction.

Returns:true if this process has committed the transaction.

isRolledBack

public boolean isRolledBack()

Checks if this process has rolled back the transaction.

Returns:true if this process has rolled back the transaction.

isStarted

public boolean isStarted()

Checks if this process has already been started.

Returns:true if the this process has already been started.

setParameter

protected void setParameter(PreparedStatement pStmt, int pos, Object param)

Sets a parameter to the prepared statement.

Parameters:
  • pStmt – the prepared statement.
  • pos – the position of the parameter.
  • param – the parameter.
Throws:
  • SQLException – if unable to set the parameter.

setResult

protected void setResult(Object result)

Sets the result of this process.

Parameters:
  • result – the result of this process.

start

public synchronized void start()

Starts executing this process. A process can only be started if it has not yet been started.

Throws:
  • DAOException – if there is any error in the execution or the process has already been started.

toString

public String toString()

Returns a string representation of this process.

Returns:a string representation of this process.

See also: java.lang.Object.toString()