org.axonframework.eventstore.jpa
Class SQLErrorCodesResolver

java.lang.Object
  extended by org.axonframework.eventstore.jpa.SQLErrorCodesResolver
All Implemented Interfaces:
PersistenceExceptionResolver

public class SQLErrorCodesResolver
extends Object
implements 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:

Since:
0.7
Author:
Martin Tilma, Allard Buijze

Constructor Summary
SQLErrorCodesResolver(DataSource dataSource)
          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, DataSource dataSource)
          Initialize the SQLErrorCodesResolver with the given properties and use the dataSource to automatically retrieve the database product name.
SQLErrorCodesResolver(Properties properties, String databaseProductName)
          Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource.
SQLErrorCodesResolver(String databaseProductName)
          Initialize a SQLErrorCodesResolver, automatically detecting the database name through the given dataSource.
 
Method Summary
 boolean isDuplicateKeyViolation(Exception exception)
          Indicates whether the given exception represents a duplicate key violation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLErrorCodesResolver

public SQLErrorCodesResolver(List<Integer> duplicateKeyCodes)
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

public SQLErrorCodesResolver(DataSource dataSource)
                      throws SQLException
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 fails
AxonConfigurationException - is the dataSource returns an unknown database product name. Use SQLErrorCodesResolver(java.util.Properties, javax.sql.DataSource) instead.

SQLErrorCodesResolver

public SQLErrorCodesResolver(String databaseProductName)
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. Use SQLErrorCodesResolver(java.util.Properties, String) instead.

SQLErrorCodesResolver

public SQLErrorCodesResolver(Properties properties,
                             String databaseProductName)
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 properies is expected to be:
databaseName.duplicateKeyCodes=keyCode[,keyCode]*
Where databaseName is 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 databases
databaseProductName - The product name of the database

SQLErrorCodesResolver

public SQLErrorCodesResolver(Properties properties,
                             DataSource dataSource)
                      throws SQLException
Initialize the SQLErrorCodesResolver with the given properties and use the dataSource to automatically retrieve the database product name.

The form of the properies is expected to be:
databaseName.duplicateKeyCodes=keyCode[,keyCode]*
Where databaseName is 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 databases
dataSource - The data source providing the database product name
Throws:
SQLException - when retrieving the database product name fails
Method Detail

isDuplicateKeyViolation

public boolean isDuplicateKeyViolation(Exception exception)
Description copied from interface: PersistenceExceptionResolver
Indicates whether the given exception represents 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:
isDuplicateKeyViolation in interface PersistenceExceptionResolver
Parameters:
exception - The exception to evaluate
Returns:
true if the given exception represents a Duplicate Key Violation, false otherwise.


Copyright © 2011. All Rights Reserved.