Commit Graph

699 Commits

Author SHA1 Message Date
Mark Paluch
38b8ea4d35 DATACASS-272 - Revise readme.
Reflect requirements. Consolidate configuration bits. Align with other Spring Data readme files.
2016-12-14 00:29:49 -08:00
Mark Paluch
dfe393b060 DATACASS-272 - Explain primary key handling. 2016-12-14 00:29:43 -08:00
Mark Paluch
2ed1b69dc0 DATACASS-272 - Consistently use Spring Data for Apache Cassandra. 2016-12-14 00:29:37 -08:00
Mark Paluch
005c82a3fd DATACASS-360 - Document schema management. 2016-12-14 00:29:30 -08:00
Mark Paluch
1d68c17cae DATACASS-272 - Add composed annotations to what's new section. 2016-12-14 00:29:23 -08:00
Mark Paluch
714e2ba3b6 DATACASS-272 - Extend documentation.
Improve documentation on CassandraTemplate. Explain differences between Spring CQL and Spring Data Cassandra. Add User-Defined-Type mapping example. Fix typos.
2016-12-14 00:29:15 -08:00
Mark Paluch
dcd5e4c05b DATACASS-272 - Add mapping/converter configuration and repository support to documentation. 2016-12-14 00:29:09 -08:00
Mark Paluch
b5ace86df9 DATACASS-272 - Enhance the SD Cassandra Reference Guide.
Align documentation structure with other Spring Data Modules. Add chapters for mapping and supported data types. Add new features chapter. Merge existing documentation into the aligned structure. Add John Blum and Mark Paluch to pom.xml.
2016-12-14 00:29:01 -08:00
John Blum
0834c44770 DATACASS-272 - Review and edit the SD Cassandra Reference Guide. 2016-12-14 00:28:53 -08:00
Mark Paluch
eb19493bc6 DATACASS-364 - Register CassandraRepositoryFactory in spring.factories.
This is required for the switch in support for multi-store detection.

Related ticket: DATACMNS-952.
2016-12-05 16:14:26 +01:00
John Blum
371a1d208f DATACASS-359 - Polish for reactive repository query methods DTO projections support.
Original pull request: #91.
2016-12-05 16:12:31 +01:00
Mark Paluch
c076d835d3 DATACASS-359 - Support DTO projections on reactive repository query methods.
Original pull request: #91.
2016-12-05 16:11:52 +01:00
Mark Paluch
0315e360e7 DATACASS-363 - Add import order config file.
Delete also attic directory since it's not required anymore.
2016-11-30 09:23:35 +01:00
John Blum
8ec905c442 DATACASS-360 - Polish. 2016-11-29 20:15:20 -08:00
Mark Paluch
979a075853 DATACASS-359 - Support DTO projections.
We now support DTO projections for query methods. DTO projection selects records from Cassandra and applies projected results on the DTO. DTOs are plain Java objects that fit to the underlying entity.

@Table
class Person {

  @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) private String lastname;
  @PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1) private String firstname;

  private String nickname;
  private Date birthDate;

  // more columns
}

interface PersonRepository extends CrudRepository<Person, String> {
  Collection<PersonDto> findPersonDtoBy();

  <T> T findDtoByFirstnameStartsWith(String prefix, Class<T> projectionType);
}

class PersonDto {
  public String firstname, lastname;

  public PersonDto(String firstname, String lastname) {

    this.firstname = firstname;
    this.lastname = lastname;
  }
}
2016-11-29 14:11:34 -08:00
Mark Paluch
996275188c DATACASS-360 - Do not require @Table annotation.
We no longer require entities to be annotated with @Table for data mapping and CRUD operations.
Entities without @Table can be still mapped in both directions and will be excluded from schema-management to prevent table creation for unwanted classes.

A class annotated with @Table will participate in schema management and be exposed as a table entity. Classes used as entities without @Table can still be used to query Cassandra but schema management will not create any tables for these classes.

@Table // entity qualified for schema management
class Person {
  @Id private String id;
  private String lastname;
  private String firstname;
}

// entity that can be used for
// select/insert/update/delete operations and repository use
class Person {
  @Id private String id;
  private String lastname;
  private String firstname;
}
2016-11-29 14:10:33 -08:00
John Blum
ff69fb2423 DATACASS-357 - Polish. 2016-11-28 17:40:34 -08:00
Mark Paluch
db7af357f8 DATACASS-357 - Move parameter conversion to MappingCassandraConverter.
Previously, query method parameter conversion was handled separately. This was duplicate code and the code additionally converted arguments into property types regardless the further usage. Collection arguments (e.g. for IN query usage) could be converted into the property type (List of String converted into String).

 We now handle collection conversion and single element conversion separately so collections are no longer converted into the property's type. Collection elements are now inspected individually regarding their type/simple type conversion.

 This change also considers enum types as simple types with a distinct conversion of the enum value into a Cassandra value (numeric, character). The change in enum value handling reduces the scope of the conversion service usage and prevents accidental conversion.

Original pull request: #89.
2016-11-28 17:40:19 -08:00
John Blum
47ebed51f9 DATACASS-259 - Polish. 2016-11-28 16:27:53 -08:00
Mark Paluch
847db1a52b DATACASS-259 - Allow usage of Spring 4.2 @AliasFor for Cassandra annotations.
We now support @AliasFor to build composed annotations with @Table, @UserDefinedType, @PrimaryKey, @PrimaryKeyClass, @PrimaryKeyColumn, @Column, @Query, @CassandraType.

Original pull request: #90.
2016-11-28 16:26:07 -08:00
Mark Paluch
3b717be06a DATACASS-351 - Revert Spring Data Cassandra 1.5 changes in 1.0 schema files.
Revert added features in version 1.0 schema files in favor of version 1.5 schema files. Remove license header. Remove TODOs and fix documentation source names.
2016-11-28 15:30:00 +01:00
Oliver Gierke
9da5afd8c8 DATACASS-342 - Updated changelog. 2016-11-23 14:03:50 +01:00
Oliver Gierke
7b2e8cd989 DATACASS-354 - Added missing changelog entries. 2016-11-23 14:01:12 +01:00
Oliver Gierke
9c7de502b9 DATACASS-354 - After release cleanups. 2016-11-23 10:59:10 +01:00
Oliver Gierke
76e179467b DATACASS-354 - Prepare next development iteration. 2016-11-23 10:59:08 +01:00
Oliver Gierke
c13c6fa4d6 DATACASS-354 - Release version 2.0 M1 (Kay). 2016-11-23 10:35:47 +01:00
Oliver Gierke
08d4d0b279 DATACASS-354 - Prepare 2.0 M1 (Kay). 2016-11-23 10:35:08 +01:00
Oliver Gierke
a4e0bff7fc DATACASS-354 - Updated changelog. 2016-11-23 10:34:58 +01:00
John Blum
542ce24173 DATACASS-292 - Polish. 2016-11-22 21:59:58 -08:00
Mark Paluch
8af23880e9 DATACASS-292 - Provide revised synchronous and asynchronous CQL and Cassandra templates.
We now provide revised CQL and Cassandra templates as central classes to interact with CQL and Cassandra with object mapping. Previously, synchronous and asynchronous methods were exposed inside the same interfaces that made it hard to chose the right method.

The revised Template API consists of:

* CqlTemplate
* AsyncCqlTemplate
* CassandraTemplate
* AsyncCassandraTemplate

CassandraTemplate and AsyncCassandraTemplate reuse CqlTemplate and AsyncCqlTemplate instead of extending from these. This is, to not mix methods using conversion/object mapping with lower level CQL execution methods.

AsyncCqlTemplate and AsyncCassandraTemplate are all new and benefit from ListenableFuture as synchronization aid. They no longer rely on various callback-interfaces.

CassandraTemplate and AsyncCassandraTemplate no longer provide insert/update/delete methods accepting a collection of items. Use CassandraBatchOperations for atomic batches to group operations.
2016-11-22 21:59:47 -08:00
Mark Paluch
636c49e058 DATACASS-335 - Adapt to new changes in reactive repository configuration.
We now use the newly introduced ….useRepositoryConfiguration(…) in the module specific RepositoryConfigurationExtension implementations to distinguish between reactive and non-reactive repositories.

Removed RepositoryType class as it was only used by the previous repository type detection.

Moved to new base class for reactive repository factories.
2016-11-17 21:10:00 +01:00
John Blum
9e115bef2f DATACASS-335 - Additional refactoring based on the polish applied to DATACMNS-836 when merged to Spring Data Commons 2.0.x. 2016-11-16 00:11:48 -08:00
John Blum
1c7413bf1f DATACASS-335 - Polish. 2016-11-11 04:45:23 -08:00
Mark Paluch
e0741a8691 DATACASS-335 - Adopt changes in Spring Data Commons.
- Remove version placeholders for reactor and rxjava
- Adopt type migration of ReactiveWrappers
- Adopt RxJava to RxJava1 repository interface renaming
- Use ReactiveQueryMethod in ReactiveMongoQuery.
- Remove trailing whitespaces.
- Use ReflectionUtils for method iteration in ReactiveType.
2016-11-11 04:45:23 -08:00
Mark Paluch
52f4f570a9 DATACASS-335 - Add support for reactive data access.
We now support reactive data access with Spring Data Cassandra by adopting Datastax' asynchronous driver.

ReactiveCqlTemplate and ReactiveCassandraTemplate use Project Reactor wrapper types Mono and Flux to implement Template API and repository support. Reactive template supports common operations such as:

* Query/Execution methods for static CQL and prepared statements
* Insert/Save/Update/Delete methods
* Exists and Count projections
* Reactive Callback methods

Person person = new Person("Dave", 25);

template.insert(person) //
    .flatMap(p -> template.update(new Person("Sven", 25))) //
    .flatMap(p -> template.selectOneById(person.getId(), Person.class)) //
    .subscribeWith(TestSubscriber.create()) //
    .await() //
    .assertValuesWith(result -> {
        assertThat(result.getFirstName(), is(equalTo("Sven")));
    });

Reactive Repository support is built on top of ReactiveCassandraTemplate using ReactiveCassandraRepository as the store-specific base repository. Reactive repositories are enabled by using @EnableReactiveCassandraRepositories on a @Configuration class to opt-in for reactive support. Reactive repositories can be composed of a reactive base interface such as

* ReactiveCrudRepository
* ReactiveSortingRepository
* RxJava1CrudRepository
* RxJava1SortingRepository

and are identified as reactive repository if one method uses a reactive wrapper type (such as Flux or Observable). If a reactive repository is discovered, it's not implemented by the blocking repository support but with the reactive repository factory. Blocking methods are not (yet) synchronized when using a reactive repository so each repository method must use a reactive wrapper result type. Reactive repository support with Spring Data allows using RxJava1 and Project Reactor types to declare repository methods. Reactive wrapper types are internally converted so the composition library choice on repository level is left up to the user.

There's feature parity between Reactive Cassandra repository support and blocking repository support.

Feature overview:

* Query Methods using String queries and Query Derivation
* Projections

@Configuration
@EnableReactiveCassandraRepositories
class ApplicationConfig extends AbstractReactiveCassandraConfiguration {

  @Override
  protected String getKeyspaceName() {
    return "mykeyspace";
  }

  @Override
  protected String getEntityBasePackages() {
    return new String[] {"com.springdata.cassandra"};
  }
}

public interface PersonRepository extends ReactiveSortingRepository<Person, String> {

  Flux<Person> findByFirstname(String firstname);

  Flux<Person> findByFirstname(Publisher<String> firstname);

  Mono<Person> findByFirstnameAndLastname(String firstname, String lastname);
}

public interface PersonRepository extends RxJava1SortingRepository<Person, String> {

  Observable<Person> findByFirstname(String firstname);

  Observable<Person> findByFirstname(Single<String> firstname);

  Single<Person> findByFirstnameAndLastname(String firstname, String lastname);
}
2016-11-11 04:45:22 -08:00
John Blum
dcc34a284a DATACASS-172 - Polish. 2016-11-11 03:17:09 -08:00
Mark Paluch
cfa8a6177f DATACASS-172 - Support for UDTs.
We now support Cassandra User-defined types. UDTs can be created using CQL generators and used inside of mapped domain classes. User-defined types can be used either raw as UDTValue that is passed through or as mapped object. Mapped UDTs must be annotated with @UserDefinedType. Types are included into schema generation so known and defined UDTs are created before any tables are created. UDTs can be used with set and list collection types and in primary keys. UDTs can also be used in repository query methods as query predicates.
Updating UDTs will update the whole UDT.

@UserDefinedType
public class Address {
  String city;
  String country;
}

@Table
public class Person {

  @Id String id;
  Address address;
  UDTValue genericUdt;
}

The XML namespace support was extended with new schema versions to support provide a User Type resolver so UDTs can be resolved:

<cassandra:mapping>
  <cassandra:user-type-resolver keyspace-name="${cassandra.keyspace}" />
</cassandra:mapping>
2016-11-11 03:16:43 -08:00
Mark Paluch
84f680ee3e DATACASS-172 - Polishing.
Add tests. Add validations to Cql generators. Enhance JavaDoc. Create FieldSpecification for UDT fields.
2016-11-11 03:13:41 -08:00
Fabio Mendes
ac868d2f0a DATACASS-172 - Add CQL specifications/generators and UserDefinedType annotation. 2016-11-11 03:13:32 -08:00
Mark Paluch
3c80b2cb80 DATACASS-329 - Set up 2.0 development. 2016-10-25 09:37:49 +02:00
Mark Paluch
8ff1f0e3fc DATACASS-333 - Switch tests to AssertJ. 2016-10-25 09:37:13 +02:00
Mark Paluch
fcd383ef15 DATACASS-349 - Consider custom write converters for collection types.
We now consider registered custom write converters for top-level collection types (like Map<String, Collection<String>>) to convert properties to Java types. Previously, only collection component types and non-collection top-level types were used to determine a converter.
2016-10-24 15:03:32 +02:00
Mark Paluch
6b683f4346 DATACASS-350 - Add since version to existing deprecations. 2016-10-24 12:17:20 +02:00
Mark Paluch
b7bdd4cd7c DATACASS-350 - Deprecate CassandraTemplate methods accepting collections of entities.
Methods accepting a List of entities perform batching operations (insert/update/delete).
This can be fine for entities sharing a partition key but leads in most cases to distributed batches across a Cassandra cluster which is an anti-pattern. CassandraTemplate exposes CassandraBatchOperations for batching operations. As of Version 1.5, all methods accepting a List of entities are deprecated because there is no alternative of inserting multiple rows in an atomic way that guarantees not to harm Cassandra performance. These methods will be removed in Version 2.0.
2016-10-24 12:17:20 +02:00
John Blum
aee38017ba DATACASS-117 - Polish. 2016-10-18 22:21:01 -07:00
Mark Paluch
1bc460ca0a DATACASS-117 - Support named and expression parameters in String-based repository query methods.
We now support named and expression parameters in String-based repository query methods. Name-based parameters are referenced with :parameter. Expression parameters can reference either parameter names (if provided) with :#{expression}/#{#fieldname} or index-based with ?#{[0]}.

String-based query creation now also serializes parameters using the configured CodecRegistry so escaping and serialization is handled by the driver itself which leads to correct queries.

public interface SampleRepository extends Repository<Person, String> {

  @Query("SELECT * FROM person WHERE lastname = ?0;")
  Person findByLastname(String lastname);

  @Query("SELECT * FROM person WHERE lastname = :lastname;")
  Person findByNamedParameter(@Param("lastname") String lastname);

  @Query("SELECT * FROM person WHERE lastname = ?#{[0]};")
  Person findByIndexExpressionParameter(String lastname);

  @Query("SELECT * FROM person WHERE lastnames IN (?0) AND age = ?1;")
  Person findByLastNamesAndAge(Collection<String> lastname, int age);

  @Query("SELECT * FROM person WHERE lastname = :#{#lastname == 'Matthews' ? 'Admin' : #lastname};")
  Person findByConditionalExpressionParameter(@Param("lastname") String lastname);
}

Related tickets: DATACASS-122, DATACASS-240
2016-10-18 22:20:55 -07:00
John Blum
fac4323372 DATACASS-258 - Polish. 2016-10-17 22:09:07 -07:00
Mark Paluch
c3700eede3 DATACASS-258 - Split metadata verifier for Entities and PrimaryKey types.
We provide now two separate verifiers for Table types and PrimaryKey types. Exception messages are aligned between both verifiers and the checks use simplified code instead to perform checks. VerifierMappingExceptions introduces now immutability and methods introducing mutability are deprecated.
2016-10-17 22:08:59 -07:00
Mark Paluch
8c39fa4787 DATACASS-276 - Polishing.
Truncate table while it contains data to reach a defined state for testing.
2016-10-12 14:42:11 +02:00
Mark Paluch
24ffba5d2f DATACASS-276 - Use Row.getObject(…) instead of deserialization with CodecRegistry and ProtocolVersion.
We now rely on Row.getObject(…) to retrieve data from a Cassandra Column. CodecRegistry and ProtocolVersion are configured on Cluster so there's no need to use a static configured CodecRegistry and ProtocolVersion that might not fit the configured values.
2016-10-12 14:42:06 +02:00