Class SQLErrorCodesResolver
java.lang.Object
org.axonframework.eventsourcing.eventstore.jpa.SQLErrorCodesResolver
- All Implemented Interfaces:
PersistenceExceptionResolver
SQLErrorCodesResolver is an implementation of PersistenceExceptionResolver used to resolve sql error codes to see if
it is an duplicate key constraint violation.
SQL Code configuration is available for the following database engines, which may be identifier automatically via
the data source:
- HSQL DB
- MySQL
- Apache Derby
- DB2
- H2
- Informix Dynamic Server
- MS SQL Server
- Oracle
- PostgreSQL
- Sybase
This implementation will attempt to locate these error codes in the SQLException.getErrorCode() and
SQLException.getSQLState(), respectively.
- Since:
- 0.7
- Author:
- Martin Tilma, Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionSQLErrorCodesResolver(String databaseProductName) Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource.SQLErrorCodesResolver(List<Integer> duplicateKeyCodes) Initializes the SQLErrorCodesResolver using the given list of SQL Codes representing Key Constraint Violations.SQLErrorCodesResolver(Properties properties, String databaseProductName) Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource.SQLErrorCodesResolver(Properties properties, DataSource dataSource) Initialize the SQLErrorCodesResolver with the givenpropertiesand use thedataSourceto automatically retrieve the database product name.SQLErrorCodesResolver(DataSource dataSource) Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanisDuplicateKeyCode(SQLException sqlException, List<Integer> errorCodes) booleanisDuplicateKeyViolation(Exception exception) Indicates whether the givenexceptionrepresents a duplicate key violation.
-
Constructor Details
-
SQLErrorCodesResolver
Initializes the SQLErrorCodesResolver using the given list of SQL Codes representing Key Constraint Violations.- Parameters:
duplicateKeyCodes- A list of Integer containing SQL Codes representing Key Constraint Violations
-
SQLErrorCodesResolver
Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource. The database product name is used to resolve the database error codes.- Parameters:
dataSource- The data source providing the information about the backing database.- Throws:
SQLException- when retrieving the database product name failsAxonConfigurationException- is the dataSource returns an unknown database product name. UseSQLErrorCodesResolver(java.util.Properties, javax.sql.DataSource)instead.
-
SQLErrorCodesResolver
Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource. The database product name is used to resolve the database error codes. As an alternative you could set the property databaseDuplicateKeyCodes- Parameters:
databaseProductName- The product name of the database- Throws:
AxonConfigurationException- is the dataSource returns an unknown database product name. UseSQLErrorCodesResolver(java.util.Properties, String)instead.
-
SQLErrorCodesResolver
Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource. The database product name is used to resolve the database error codes. As an alternative you could set the property databaseDuplicateKeyCodes The form of the properties is expected to be:
databaseName.duplicateKeyCodes=keyCode[,keyCode]*
WheredatabaseNameis the database product name as returned by the driver, with spaces (' ') replaced by underscore ('_'). The key codes must be a comma separated list of SQL Error code numbers (int).- Parameters:
properties- the properties defining SQL Error Codes for Duplicate Key violations for different databasesdatabaseProductName- The product name of the database
-
SQLErrorCodesResolver
Initialize the SQLErrorCodesResolver with the givenpropertiesand use thedataSourceto automatically retrieve the database product name. The form of the properties is expected to be:
databaseName.duplicateKeyCodes=keyCode[,keyCode]*
WheredatabaseNameis the database product name as returned by the driver, with spaces (' ') replaced by underscore ('_'). The key codes must be a comma separated list of SQL Error code numbers (int).- Parameters:
properties- the properties defining SQL Error Codes for Duplicate Key violations for different databasesdataSource- The data source providing the database product name- Throws:
SQLException- when retrieving the database product name fails
-
-
Method Details
-
isDuplicateKeyViolation
Description copied from interface:PersistenceExceptionResolverIndicates whether the givenexceptionrepresents a duplicate key violation. Typically, duplicate key violations indicates concurrent access to an entity in the application. Two users might be accessing the same Aggregate, for example.- Specified by:
isDuplicateKeyViolationin interfacePersistenceExceptionResolver- Parameters:
exception- The exception to evaluate- Returns:
trueif the given exception represents a Duplicate Key Violation,falseotherwise.
-
isDuplicateKeyCode
- Parameters:
sqlException- The exception to locate the error code inerrorCodes- The error codes indicating duplicate key violations- Returns:
trueif the error code of thesqlExceptionis in the given list oferrorCodes, otherwisefalse
-