Class QueryExceptionHandler
- java.lang.Object
-
- com.feedzai.commons.sql.abstraction.engine.handler.QueryExceptionHandler
-
- Direct Known Subclasses:
H2QueryExceptionHandler,MySqlQueryExceptionHandler,OracleQueryExceptionHandler,PostgresSqlQueryExceptionHandler
public class QueryExceptionHandler extends Object
A handler that can be used to disambiguate the meaning of anSQLExceptionthrown when executing a JDBC method. The methods in this class can be used for example to tell whether an exception is retryable, or more in particular if it is a timeout (which can also be considered retryable).- Since:
- 2.5.1
- Author:
- José Fidalgo (jose.fidalgo@feedzai.com)
-
-
Constructor Summary
Constructors Constructor Description QueryExceptionHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DatabaseEngineExceptionhandleException(Exception exception, String message)Handles the Exception, disambiguating it into a specific PDB Exception and throwing it.booleanisRetryableException(SQLException exception)Checks if an Exception occurred due to serialization failures in concurrent transactions and may be retried on the client-side.booleanisTimeoutException(SQLException exception)Indicates if a given exception is a timeout.
-
-
-
Method Detail
-
isTimeoutException
public boolean isTimeoutException(SQLException exception)
Indicates if a given exception is a timeout. Logic for this may be driver-specific, so drivers that support query timeouts may have to override this method. A timeout exception can also be considered retryable.- Parameters:
exception- The exception to check.- Returns:
trueif the exception is a timeout,falseotherwise.
-
isRetryableException
public boolean isRetryableException(SQLException exception)
Checks if an Exception occurred due to serialization failures in concurrent transactions and may be retried on the client-side.- Parameters:
exception- The exception to check.- Returns:
trueif the exception is retryable,falseotherwise.
-
handleException
public DatabaseEngineException handleException(Exception exception, String message) throws DatabaseEngineException
Handles the Exception, disambiguating it into a specific PDB Exception and throwing it.If a specific type does not match the info in the provided Exception, throws a
DatabaseEngineException.- Parameters:
exception- The exception to handle.message- The message to associate with the thrown exception.- Returns:
- a
DatabaseEngineException(declared, but only to keep Java type system happy; this method will always throw an exception). - Throws:
DatabaseEngineException- Since:
- 2.5.1
-
-