Package st.orm.spi

Interface ExceptionMapper

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ExceptionMapper
Maps failures raised during query execution to the runtime exception thrown to the caller.

The default mapper throws a PersistenceException as it is and wraps any other failure in one. Integrations may translate to platform exception hierarchies instead, such as Spring's DataAccessException.

Exception mappers are configured per ORM template via the template builder; they are deliberately not discovered through the ServiceLoader mechanism. The framework enriches the failure with SQL diagnostics (as a suppressed exception on the cause) and classifies it before invoking the mapper: a deadlock or a serialization failure arrives as a TransientPersistenceException and a write the database refused for a constraint as an IntegrityViolationException, each with the driver's exception as its cause. The mapper only decides the exception type that is thrown.

The failures Storm's own logic detects after a statement ran pass through the mapper as well: an optimistic lock conflict, a single result that is missing or not unique, a write that affected no row. Their context names the operation and, for a write, the entity type, but no statement. A mapper that translates to a platform hierarchy translates them too, so a caller sees one exception family whichever side detected the failure.

Since:
1.13
See Also:
  • Method Details

    • map

      Maps the given failure to the runtime exception that is thrown to the caller.
      Parameters:
      cause - the failure; typically a PersistenceException, or a SQLException the framework could not classify. The framework has already attached SQL diagnostics as a suppressed exception where available.
      context - the execution context of the failure; never null.
      Returns:
      the exception to throw; never null.
    • defaultMapper

      static ExceptionMapper defaultMapper()
      Returns the default exception mapper.

      The default mapper passes a PersistenceException through unchanged and wraps any other failure in a new PersistenceException.

      Returns:
      the default exception mapper.