org.jcreme.sql
Class DefaultSQLExceptionHandler

java.lang.Object
  extended byorg.jcreme.sql.DefaultSQLExceptionHandler
All Implemented Interfaces:
SQLExceptionHandler
Direct Known Subclasses:
SQLExceptionHandlerDB2, SQLExceptionHandlerOracle, SQLExceptionHandlerSybase

public class DefaultSQLExceptionHandler
extends java.lang.Object
implements SQLExceptionHandler

This generic class enables to handle SQLExceptions. The class is able to handle differently Losses of Connection and Dead locks.


Field Summary
static java.lang.String SQL92_CONNECTION_ERROR_SQLSTATE_CLASS
          As specified in SQL92.
static java.lang.String SQL92_SERIALIZATION_FAILURE
          As specified in SQL92.
 
Fields inherited from interface org.jcreme.sql.SQLExceptionHandler
EXCEPTION_TYPE_LOSS_OF_CONNECTION, EXCEPTION_TYPE_PLAIN_DEADLOCK, EXCEPTION_TYPE_ROLLEDBACK_DEADLOCK, EXCEPTION_TYPE_UNKNOWN, WAS_HANDLED
 
Constructor Summary
DefaultSQLExceptionHandler()
           
 
Method Summary
 int getDeadlockTimeout()
          This method gives access to the number of milliseconds that the thread will wait for before making a new attempt to resolve a deadlock.
 int getNumberOfTries()
          This method gives access to the number of attempts that will be done to resolve a deadlock (number of calls to the redo action).
protected  int handleConnectionClosed(CremeAction lossOfConnection)
          This method enables to execute when the connection is closed.
 int handleException(java.sql.SQLException e)
          This method handles an SQLException.
 int handleException(java.sql.SQLException e, CremeAction rollback, CremeAction lossOfConnection)
          This method handles an SQLException.
 int handleException(java.sql.SQLException e, CremeAction rollback, CremeAction lossOfConnection, CremeAction redo)
          This method handles an SQLException.
protected  int handlePlainDeadLock(CremeAction redo)
          This method enables to apply the redo action for numberOfTries times until it succeeds.
protected  int handleRolledBackDeadLock(CremeAction rollback)
          This method enables to execute the rollback.
 boolean isDeadLock(java.sql.SQLException e)
          This method can be used to test an SQLException.
 boolean isLossOfConnection(int i)
          This method can be used to test a result returned by a handleException method call.
 boolean isLossOfConnection(java.sql.SQLException e)
          This method can be used to test an SQLException.
 boolean isPlainDeadLock(int i)
          This method can be used to test a result returned by a handleException method call.
 boolean isPlainDeadLock(java.sql.SQLException e)
          This method can be used to test an SQLException.
 boolean isRolledBackDeadLock(int i)
          This method can be used to test a result returned by a handleException method call.
 boolean isRolledBackDeadLock(java.sql.SQLException e)
          This method can be used to test an SQLException.
 boolean isUnknown(int i)
          This method can be used to test a result returned by a handleException method call.
 void setDeadlockTimeout(int timeout)
          This method enables to change the number of milliseconds that the thread will wait for before making a new attempt to resolve a deadlock.
 void setNumberOfTries(int number)
          This method enables to change the number of tries attempts that will be done to resolve a deadlock (number of calls to the redo action).
 boolean wasHandled(int i)
          This method can be used to test a result returned by a handleException method call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SQL92_CONNECTION_ERROR_SQLSTATE_CLASS

public static final java.lang.String SQL92_CONNECTION_ERROR_SQLSTATE_CLASS
As specified in SQL92.

See Also:
Constant Field Values

SQL92_SERIALIZATION_FAILURE

public static final java.lang.String SQL92_SERIALIZATION_FAILURE
As specified in SQL92.

See Also:
Constant Field Values
Constructor Detail

DefaultSQLExceptionHandler

public DefaultSQLExceptionHandler()
Method Detail

handleException

public int handleException(java.sql.SQLException e)
This method handles an SQLException. There is no special handling of deadlocks.

Specified by:
handleException in interface SQLExceptionHandler
Parameters:
e - the exception to handle.
Returns:
the type of the exception e.

handleException

public int handleException(java.sql.SQLException e,
                           CremeAction rollback,
                           CremeAction lossOfConnection)
This method handles an SQLException. The rollback action is invoked if the exception is a rolled back deadlock.

Specified by:
handleException in interface SQLExceptionHandler
Parameters:
e - the exception to handle.
rollback - the action to invoke to rollback.
lossOfConnection - the action to invoke in case of a loss of connection.
Returns:
the type of the exception e.

handleException

public int handleException(java.sql.SQLException e,
                           CremeAction rollback,
                           CremeAction lossOfConnection,
                           CremeAction redo)
This method handles an SQLException. The rollback action is invoked if the exception is a rolled back deadlock. The redo action is invoked if the exception is a simple deadlock.

Specified by:
handleException in interface SQLExceptionHandler
Parameters:
e - the exception to handle.
rollback - the action to invoke to rollback.
lossOfConnection - the action to invoke in case of a loss of connection.
redo - the action to invoke in case of a simple deadlock.
Returns:
the type of the exception e.

handleConnectionClosed

protected int handleConnectionClosed(CremeAction lossOfConnection)
This method enables to execute when the connection is closed.

Parameters:
lossOfConnection - the action to apply when the connection is closed.
Returns:
WAS_HANDLED if the action succeeded, 0 otherwise.

handleRolledBackDeadLock

protected int handleRolledBackDeadLock(CremeAction rollback)
This method enables to execute the rollback.

Parameters:
rollback - the action to apply when a rollback occured.
Returns:
WAS_HANDLED if the action succeeded, 0 otherwise.

handlePlainDeadLock

protected int handlePlainDeadLock(CremeAction redo)
This method enables to apply the redo action for numberOfTries times until it succeeds. Each attempt is preceded by a waiting period of deadlockTimeout milliseconds.

Parameters:
redo - the action to repeat.
Returns:
WAS_HANDLED if the action succeeded, 0 otherwise.

isLossOfConnection

public boolean isLossOfConnection(java.sql.SQLException e)
This method can be used to test an SQLException.

Specified by:
isLossOfConnection in interface SQLExceptionHandler
Parameters:
e - an SQLException to test.
Returns:
true if the exception is a loss of connection, false otherwise.

isRolledBackDeadLock

public boolean isRolledBackDeadLock(java.sql.SQLException e)
This method can be used to test an SQLException.

Specified by:
isRolledBackDeadLock in interface SQLExceptionHandler
Parameters:
e - an SQLException to test.
Returns:
true if the exception is a deadlock and the transaction was rolled back, false otherwise.

isPlainDeadLock

public boolean isPlainDeadLock(java.sql.SQLException e)
This method can be used to test an SQLException.

Specified by:
isPlainDeadLock in interface SQLExceptionHandler
Parameters:
e - an SQLException to test.
Returns:
true if the exception is a simple deadlock, false otherwise.

wasHandled

public final boolean wasHandled(int i)
This method can be used to test a result returned by a handleException method call.

Specified by:
wasHandled in interface SQLExceptionHandler
Parameters:
i - an int produced by a handleException method call.
Returns:
true if the exception was handled, false otherwise.

isUnknown

public final boolean isUnknown(int i)
This method can be used to test a result returned by a handleException method call.

Specified by:
isUnknown in interface SQLExceptionHandler
Parameters:
i - an int produced by a handleException method call.
Returns:
true if the type of the exception is not known, false otherwise.

isLossOfConnection

public final boolean isLossOfConnection(int i)
This method can be used to test a result returned by a handleException method call.

Specified by:
isLossOfConnection in interface SQLExceptionHandler
Parameters:
i - an int produced by a handleException method call.
Returns:
true if the exception is a loss of connection, false otherwise.

isRolledBackDeadLock

public final boolean isRolledBackDeadLock(int i)
This method can be used to test a result returned by a handleException method call.

Specified by:
isRolledBackDeadLock in interface SQLExceptionHandler
Parameters:
i - an int produced by a handleException method call.
Returns:
true if the exception is a deadlock and the transaction was rolled back, false otherwise.

isPlainDeadLock

public final boolean isPlainDeadLock(int i)
This method can be used to test a result returned by a handleException method call.

Specified by:
isPlainDeadLock in interface SQLExceptionHandler
Parameters:
i - an int produced by a handleException method call.
Returns:
true if the exception is a simple deadlock, false otherwise.

isDeadLock

public final boolean isDeadLock(java.sql.SQLException e)
This method can be used to test an SQLException.

Specified by:
isDeadLock in interface SQLExceptionHandler
Parameters:
e - an SQLException to test.
Returns:
true if the exception is a deadlock (simple or not), false otherwise.

getDeadlockTimeout

public int getDeadlockTimeout()
This method gives access to the number of milliseconds that the thread will wait for before making a new attempt to resolve a deadlock.

Specified by:
getDeadlockTimeout in interface SQLExceptionHandler
Returns:
the number of milliseconds that the thread will wait for before making a new attempt to resolve a deadlock.

getNumberOfTries

public int getNumberOfTries()
This method gives access to the number of attempts that will be done to resolve a deadlock (number of calls to the redo action).

Specified by:
getNumberOfTries in interface SQLExceptionHandler
Returns:
the number of attempts that will be done to resolve a deadlock.

setDeadlockTimeout

public void setDeadlockTimeout(int timeout)
This method enables to change the number of milliseconds that the thread will wait for before making a new attempt to resolve a deadlock.

Specified by:
setDeadlockTimeout in interface SQLExceptionHandler
Parameters:
timeout - the number of milliseconds that the thread will wait for before making a new attempt to resolve a deadlock.

setNumberOfTries

public void setNumberOfTries(int number)
This method enables to change the number of tries attempts that will be done to resolve a deadlock (number of calls to the redo action).

Specified by:
setNumberOfTries in interface SQLExceptionHandler
Parameters:
number - the number of attempts that will be done


Copyright 2006 null. All Rights Reserved.