Migration Guide from 1.x to 2.x
Spring Data for Apache Cassandra 2.0 introduces a set of breaking changes when upgrading from earlier versions:
-
Merged the
spring-cqlandspring-data-cassandramodules into a single module. -
Separated asynchronous and synchronous operations in
CqlOperationsandCassandraOperationsinto dedicated interfaces and templates. -
Revised the
CqlTemplateAPI to align withJdbcTemplate. -
Removed the
CassandraOperations.selectBySimpleIdsmethod. -
Used better names for
CassandraRepository. -
Removed SD Cassandra
ConsistencyLevelandRetryPolicytypes in favor of DataStaxConsistencyLevelandRetryPolicytypes. -
Refactored CQL specifications to value objects and configurators.
-
Refactored
QueryOptionsto be immutable objects. -
Refactored
CassandraPersistentPropertyto single-column.
Deprecations
-
Deprecated
QueryOptionsBuilder.readTimeout(long, TimeUnit)in favor ofQueryOptionsBuilder.readTimeout(Duration). -
Deprecated
CustomConversionsin favor ofCassandraCustomConversions. -
Deprecated
BasicCassandraMappingContextin favor ofCassandraMappingContext. -
Deprecated
o.s.d.c.core.cql.CachedPreparedStatementCreatorin favor ofo.s.d.c.core.cql.support.CachedPreparedStatementCreator. -
Deprecated
CqlTemplate.getSession()in favor ofgetSessionFactory(). -
Deprecated
CqlIdentifier.cqlId(…)andKeyspaceIdentifier.ksId(…)in favor of the.of(…)methods. -
Deprecated constructors of
QueryOptionsin favor of their builders. -
Deprecated
TypedIdCassandraRepositoryin favor ofCassandraRepository
Merged Spring CQL and Spring Data Cassandra Modules
Spring CQL and Spring Data Cassandra are now merged into a single module.
The standalone spring-cql module is no longer available.
You can find all types merged into spring-data-cassandra.
The following listing shows how to include spring-data-cassandra in your maven dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>
With the merge, we merged all CQL packages into Spring Data Cassandra:
-
Moved
o.s.d.cqlintoo.s.d.cassandra.core.cql. -
Merged
o.s.d.cqlwitho.s.d.cassandra.configand flattened the XML and Java subpackages. -
Moved
CassandraExceptionTranslatorandCqlExceptionTranslatortoo.s.d.c.core.cql. -
Moved Cassandra exceptions
o.s.d.c.support.exceptiontoo.s.d.cassandra. -
Moved
o.s.d.c.converttoo.s.d.c.core.convert(affects converters). -
Moved
o.s.d.c.mappingtoo.s.d.c.core.mapping(affects mapping annotations). -
Moved
MapIdfromo.s.d.c.repositorytoo.s.d.c.core.mapping.
[[revised-cqltemplate/cassandratemplate]]
== Revised CqlTemplate/CassandraTemplate
We split CqlTemplate and CassandraTemplate in three ways:
-
CassandraTemplateis no longer aCqlTemplatebut uses an instance that allows reuse and fine-grained control over fetch size, consistency levels, and retry policies. You can obtain theCqlOperationsthroughCassandraTemplate.getCqlOperations(). Because of the change, dependency injection ofCqlTemplaterequires additional bean setup. -
CqlTemplatenow reflects basic CQL operations instead of mixing high-level and low-level API calls (such ascount(…)versusexecute(…)) and the reduced method set is aligned with Spring Frameworks’sJdbcTemplatewith its convenient callback interfaces. -
Asynchronous methods are re-implemented on
AsyncCqlTemplateandAsyncCassandraTemplateby usingListenableFuture. We removedCancellableand the various async callback listeners.ListenableFutureis a flexible approach and allows transition into aCompletableFuture.
Removed CassandraOperations.selectBySimpleIds()
The method was removed because it did not support complex IDs. The newly introduced query DSL allows mapped and complex id’s for single column Id’s, as the following example shows:
cassandraTemplate.select(Query.query(Criteria.where("id").in(…)), Person.class)
Better names for CassandraRepository
We renamed CassandraRepository and TypedIdCassandraRepository to align Spring Data Cassandra naming with other Spring Data modules:
-
Renamed
CassandraRepositorytoMapIdCassandraRepository -
Renamed
TypedIdCassandraRepositorytoCassandraRepository -
Introduced
TypedIdCassandraRepository, extendingCassandraRepositoryas a deprecated type to ease migration
Removed SD Cassandra ConsistencyLevel and RetryPolicy types in favor of DataStax ConsistencyLevel and RetryPolicy types
Spring Data Cassandra ConsistencyLevel and RetryPolicy have been removed.
Please use the types provided by the DataStax driver.
The Spring Data Cassandra types restricted usage of available features provided in and allowed by the Cassandra native driver. As a result, the Spring Data Cassandra’s types required an update each time newer functionality was introduced by the driver.
Refactored CQL Specifications to Value Objects and Configurators
As much as possible, CQL specification types are now value types (such as FieldSpecification, AlterColumnSpecification), and objects are constructed by static factory methods.
This allows immutability for simple value objects.
Configurator objects (such as AlterTableSpecification) that operate on mandatory properties (such as a table name or keyspace name) are initially constructed through a a static factory method and allow further configuration until the desired state is created.
Refactored QueryOptions to be Immutable Objects
QueryOptions and WriteOptions are now immutable and can be created through builders.
Methods accepting
QueryOptions enforce non-null objects, which are available from static empty() factory methods.
The following example shows how to use QueryOptions.builder():
QueryOptions queryOptions = QueryOptions.builder()
.consistencyLevel(ConsistencyLevel.ANY)
.retryPolicy(FallthroughRetryPolicy.INSTANCE)
.readTimeout(Duration.ofSeconds(10))
.fetchSize(10)
.tracing(true)
.build();
Refactored CassandraPersistentProperty to Single-column
This change affects You only if you operate directly on the mapping model.
CassandraPersistentProperty allowed previously multiple column names to be bound for composite primary key use.
Columns of a CassandraPersistentProperty are now reduced to a single column.
Resolved composite primary keys map to a class through MappingContext.getRequiredPersistentEntity(…).