Interface CassandraOperations

All Superinterfaces:
ExecutableDeleteOperation, ExecutableInsertOperation, ExecutableSelectOperation, ExecutableUpdateOperation, FluentCassandraOperations
All Known Subinterfaces:
CassandraAdminOperations
All Known Implementing Classes:
CassandraAdminTemplate, CassandraTemplate

public interface CassandraOperations extends FluentCassandraOperations
Interface specifying a basic set of Cassandra operations. Implemented by CassandraTemplate. Not often used directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.
Author:
Alex Shvid, David Webb, Matthew Adams, Mark Paluch, Sam Lightfoot
See Also:
  • Method Details

    • batchOps

      default CassandraBatchOperations batchOps()
      Returns a new CassandraBatchOperations using BatchType.LOGGED. Each CassandraBatchOperations instance can be executed only once, so you need to obtain new CassandraBatchOperations instances for each batch.
      Returns:
      a new CassandraBatchOperations associated with the given entity class.
      See Also:
    • batchOps

      CassandraBatchOperations batchOps(com.datastax.oss.driver.api.core.cql.BatchType batchType)
      Returns a new CassandraBatchOperations. Each CassandraBatchOperations instance can be executed only once, so you need to obtain new CassandraBatchOperations instances for each batch.
      Parameters:
      batchType - must not be null.
      Returns:
      a new ReactiveCassandraBatchOperations associated with the given entity class.
      Since:
      3.2.6
    • getCqlOperations

      CqlOperations getCqlOperations()
      Expose the underlying CqlOperations to allow CQL operations.
      Returns:
      the underlying CqlOperations.
      See Also:
    • getConverter

      CassandraConverter getConverter()
      Returns the underlying CassandraConverter.
      Returns:
      the underlying CassandraConverter.
    • getTableName

      com.datastax.oss.driver.api.core.CqlIdentifier getTableName(Class<?> entityClass)
      The table name used for the specified class by this template.
      Parameters:
      entityClass - The entity type must not be null.
      Returns:
      the CqlIdentifier
    • select

      <T> List<T> select(String cql, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting items to a List of entities.
      Parameters:
      cql - must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted results
      Throws:
      DataAccessException - if there is any problem executing the query.
    • stream

      <T> Stream<T> stream(String cql, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting items to a Iterator of entities.

      Returns a Iterator that wraps the Cassandra ResultSet.

      Type Parameters:
      T - element return type.
      Parameters:
      cql - query to execute. Must not be empty or null.
      entityClass - Class type of the elements in the Iterator stream. Must not be null.
      Returns:
      an Iterator (stream) over the elements in the query result set.
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      1.5
    • selectOne

      @Nullable <T> T selectOne(String cql, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting item to an entity.
      Parameters:
      cql - must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted object or null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • execute

      com.datastax.oss.driver.api.core.cql.ResultSet execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws DataAccessException
      Execute the given Cassandra Statement. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.
      Parameters:
      statement - a Cassandra Statement, must not be null.
      Returns:
      the ResultSet.
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      3.2
    • select

      <T> List<T> select(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting items to a List of entities.
      Parameters:
      statement - must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted results
      Throws:
      DataAccessException - if there is any problem executing the query.
    • slice

      <T> Slice<T> slice(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query with paging and convert the result set to a Slice of entities. A sliced query translates the effective fetch size to the page size.
      Parameters:
      statement - the CQL statement, must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted results
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      2.0
    • stream

      <T> Stream<T> stream(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting items to a Iterator of entities.

      Returns a Iterator that wraps the Cassandra ResultSet.

      Type Parameters:
      T - element return type.
      Parameters:
      statement - query to execute. Must not be empty or null.
      entityClass - Class type of the elements in the Iterator stream. Must not be null.
      Returns:
      an Iterator (stream) over the elements in the query result set.
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      1.5
    • selectOne

      @Nullable <T> T selectOne(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting item to an entity.
      Parameters:
      statement - must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted object or null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • select

      <T> List<T> select(Query query, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting items to a List of entities.
      Parameters:
      query - must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted results
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      2.0
    • slice

      <T> Slice<T> slice(Query query, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query with paging and convert the result set to a Slice of entities.
      Parameters:
      query - the query object used to create a CQL statement, must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted results
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      2.0
      See Also:
    • stream

      <T> Stream<T> stream(Query query, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting items to a Iterator of entities.

      Returns a Iterator that wraps the Cassandra ResultSet.

      Type Parameters:
      T - element return type.
      Parameters:
      query - query to execute. Must not be empty or null.
      entityClass - Class type of the elements in the Iterator stream. Must not be null.
      Returns:
      an Iterator (stream) over the elements in the query result set.
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      2.0
    • selectOne

      @Nullable <T> T selectOne(Query query, Class<T> entityClass) throws DataAccessException
      Execute a SELECT query and convert the resulting item to an entity.
      Parameters:
      query - must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted object or null.
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      2.0
    • update

      boolean update(Query query, Update update, Class<?> entityClass) throws DataAccessException
      Update the queried entities and return true if the update was applied.
      Parameters:
      query - must not be null.
      update - must not be null.
      entityClass - The entity type must not be null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • delete

      boolean delete(Query query, Class<?> entityClass) throws DataAccessException
      Remove entities (rows)/columns from the table by Query.
      Parameters:
      query - must not be null.
      entityClass - The entity type must not be null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • count

      long count(Class<?> entityClass) throws DataAccessException
      Returns the number of rows for the given entity class.
      Parameters:
      entityClass - type of the entity; must not be null.
      Returns:
      the number of existing entities.
      Throws:
      DataAccessException - if any problem occurs while executing the query.
    • count

      long count(Query query, Class<?> entityClass) throws DataAccessException
      Returns the number of rows for the given entity class applying Query. This overridden method allows users to further refine the selection criteria using a Query predicate to determine how many entities of the given type match the criteria.
      Parameters:
      query - user-defined count Query to execute; must not be null.
      entityClass - type of the entity; must not be null.
      Returns:
      the number of existing entities.
      Throws:
      DataAccessException - if any problem occurs while executing the query.
      Since:
      2.1
    • exists

      boolean exists(Object id, Class<?> entityClass) throws DataAccessException
      Determine whether a row of entityClass with the given id exists.
      Parameters:
      id - Id value. For single primary keys it's the plain value. For composite primary keys either, it's an instance of either PrimaryKeyClass or MapId. Must not be null.
      entityClass - type of the entity; must not be null.
      Returns:
      true if the object exists.
      Throws:
      DataAccessException - if any problem occurs while executing the query.
    • exists

      boolean exists(Query query, Class<?> entityClass) throws DataAccessException
      Determine whether the result for entityClass Query yields at least one row.
      Parameters:
      query - user-defined exists Query to execute; must not be null.
      entityClass - type of the entity; must not be null.
      Returns:
      true if the object exists.
      Throws:
      DataAccessException - if any problem occurs while executing the query.
      Since:
      2.1
    • selectOneById

      @Nullable <T> T selectOneById(Object id, Class<T> entityClass) throws DataAccessException
      Execute the Select by id for the given entityClass.
      Parameters:
      id - the Id value. For single primary keys it's the plain value. For composite primary keys either the PrimaryKeyClass or MapId. Must not be null.
      entityClass - The entity type must not be null.
      Returns:
      the converted object or null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • insert

      <T> T insert(T entity) throws DataAccessException
      Insert the given entity and return the entity if the insert was applied.
      Parameters:
      entity - The entity to insert, must not be null.
      Returns:
      the inserted entity.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • insert

      <T> EntityWriteResult<T> insert(T entity, InsertOptions options) throws DataAccessException
      Insert the given entity applying WriteOptions and return the entity if the insert was applied.
      Parameters:
      entity - The entity to insert, must not be null.
      options - must not be null.
      Returns:
      the EntityWriteResult for this operation.
      Throws:
      DataAccessException - if there is any problem executing the query.
      See Also:
    • update

      <T> T update(T entity) throws DataAccessException
      Update the given entity and return the entity if the update was applied.
      Parameters:
      entity - The entity to update, must not be null.
      Returns:
      the updated entity.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • update

      <T> EntityWriteResult<T> update(T entity, UpdateOptions options) throws DataAccessException
      Update the given entity applying WriteOptions and return the entity if the update was applied.
      Parameters:
      entity - The entity to update, must not be null.
      options - must not be null.
      Returns:
      the EntityWriteResult for this operation.
      Throws:
      DataAccessException - if there is any problem executing the query.
      See Also:
    • delete

      void delete(Object entity) throws DataAccessException
      Delete the given entity and return the entity if the delete statement was applied.
      Parameters:
      entity - must not be null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • delete

      WriteResult delete(Object entity, QueryOptions options) throws DataAccessException
      Delete the given entity applying QueryOptions and return the entity if the delete statement was applied.
      Parameters:
      entity - must not be null.
      options - must not be null.
      Returns:
      the WriteResult for this operation.
      Throws:
      DataAccessException - if there is any problem executing the query.
      See Also:
    • delete

      default WriteResult delete(Object entity, DeleteOptions options) throws DataAccessException
      Delete the given entity applying DeleteOptions and return the entity if the delete statement was applied.
      Parameters:
      entity - must not be null.
      options - must not be null.
      Returns:
      the WriteResult for this operation.
      Throws:
      DataAccessException - if there is any problem executing the query.
      Since:
      2.2
      See Also:
    • deleteById

      boolean deleteById(Object id, Class<?> entityClass) throws DataAccessException
      Remove the given object from the table by id.
      Parameters:
      id - the Id value. For single primary keys it's the plain value. For composite primary keys either the PrimaryKeyClass or MapId. Must not be null.
      entityClass - The entity type must not be null.
      Throws:
      DataAccessException - if there is any problem executing the query.
    • truncate

      void truncate(Class<?> entityClass) throws DataAccessException
      Execute a TRUNCATE query to remove all entities of a given class.
      Parameters:
      entityClass - The entity type must not be null.
      Throws:
      DataAccessException - if there is any problem executing the query.