Class AbstractResultSetConverter<T>

java.lang.Object
org.springframework.data.cassandra.core.cql.converter.AbstractResultSetConverter<T>
Type Parameters:
T -
All Implemented Interfaces:
Converter<com.datastax.oss.driver.api.core.cql.ResultSet,T>
Direct Known Subclasses:
AbstractResultSetToBasicFixedTypeConverter, ResultSetToByteBufferConverter, ResultSetToListOfStringConverter, ResultSetToStringConverter

public abstract class AbstractResultSetConverter<T> extends Object implements Converter<com.datastax.oss.driver.api.core.cql.ResultSet,T>
Convenient converter that can be used to convert a single-row-single-column, single-row-multi-column, or multi-row ResultSet into the a value of a given type. The majority of the expected usage is to convert a single-row-single-column result set into the target type.

The algorithm is:

  • if there is one row with one column, convert that value to this converter's type if possible or throw,
  • else if there is one row with multiple columns, convert the columns into this converter's type if possible or throw,
  • else convert the rows into this converter's type (since there are multiple rows) or throw.

If the converter throws due to the inability to convert a given ResultSet, it will throw an IllegalArgumentException.

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

    • AbstractResultSetConverter

      public AbstractResultSetConverter()
  • Method Details

    • doConvertSingleValue

      protected abstract T doConvertSingleValue(Object object)
      Converts the given value to this converter's type or throws IllegalArgumentException.
    • getType

      protected abstract Class<?> getType()
      Returns:
      the target type.
    • getNullResultSetValue

      @Nullable protected T getNullResultSetValue()
      Returns:
      surrogate value if the ResultSet is null.
    • getExhaustedResultSetValue

      @Nullable protected T getExhaustedResultSetValue()
      Returns:
      surrogate value if the ResultSet is PagingIterable.isFullyFetched()}.
    • convert

      public T convert(com.datastax.oss.driver.api.core.cql.ResultSet source)
      Specified by:
      convert in interface Converter<com.datastax.oss.driver.api.core.cql.ResultSet,T>
    • doConvertResultSet

      protected T doConvertResultSet(List<Map<String,Object>> resultSet)
      Converts the given result set (as a List<Map<String,Object>>) to this converter's type or throws IllegalArgumentException. This default implementation simply throws.
    • doConvertSingleRow

      protected T doConvertSingleRow(Map<String,Object> row)
      Converts the given row (as a Map<String,Object>) to this converter's type or throws IllegalArgumentException. This default implementation simply throws.