Class CassandraExceptionTranslator

java.lang.Object
org.springframework.data.cassandra.core.cql.CassandraExceptionTranslator
All Implemented Interfaces:
org.springframework.dao.support.PersistenceExceptionTranslator, CqlExceptionTranslator

public class CassandraExceptionTranslator extends Object implements CqlExceptionTranslator
Simple PersistenceExceptionTranslator for Cassandra.

Convert the given runtime exception to an appropriate exception from the org.springframework.dao hierarchy. Preserves exception if it's already a DataAccessException and ignores non DriverExceptions returning null. Falls back to CassandraUncategorizedException in case there's no mapping to a more detailed exception.

Author:
Alex Shvid, Matthew T. Adams, Mark Paluch
  • Constructor Details

    • CassandraExceptionTranslator

      public CassandraExceptionTranslator()
  • Method Details

    • translateExceptionIfPossible

      @Nullable public org.springframework.dao.DataAccessException translateExceptionIfPossible(RuntimeException exception)
      Specified by:
      translateExceptionIfPossible in interface org.springframework.dao.support.PersistenceExceptionTranslator
    • translate

      public org.springframework.dao.DataAccessException translate(@Nullable String task, @Nullable String cql, RuntimeException exception)
      Description copied from interface: CqlExceptionTranslator
      Translate the given RuntimeException into a generic DataAccessException.

      The returned DataAccessException is supposed to contain the original DriverException as root cause. However, client code may not generally rely on this due to DataAccessExceptions possibly being caused by other resource APIs as well. That said, a getRootCause() instanceof DataAccessException check (and subsequent cast) is considered reliable when expecting Cassandra-based access to have happened.

      Specified by:
      translate in interface CqlExceptionTranslator
      Parameters:
      task - readable text describing the task being attempted.
      cql - CQL query or update that caused the problem (may be null).
      exception - the offending DriverException.
      Returns:
      the DataAccessException, wrapping the RuntimeException.
      See Also:
      • NestedRuntimeException.getRootCause()
    • buildMessage

      protected String buildMessage(@Nullable String task, @Nullable String cql, RuntimeException ex)
      Build a message String for the given DriverException.

      To be called by translator subclasses when creating an instance of a generic DataAccessException class.

      Parameters:
      task - readable text describing the task being attempted
      cql - the CQL statement that caused the problem (may be null)
      ex - the offending DriverException
      Returns:
      the message String to use