@@ -57,7 +57,7 @@ class BasicConfiguration {
|
||||
public MappingCassandraConverter cassandraConverter(CassandraMappingContext mapping,
|
||||
CassandraCustomConversions conversions, CqlSession session) {
|
||||
|
||||
MappingCassandraConverter converter = new MappingCassandraConverter(mapping);
|
||||
var converter = new MappingCassandraConverter(mapping);
|
||||
|
||||
converter.setCodecRegistry(session.getContext().getCodecRegistry());
|
||||
converter.setCustomConversions(conversions);
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package example.springdata.cassandra.convert;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.springframework.data.cassandra.core.mapping.Element;
|
||||
import org.springframework.data.cassandra.core.mapping.Tuple;
|
||||
|
||||
@@ -27,13 +23,7 @@ import org.springframework.data.cassandra.core.mapping.Tuple;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tuple
|
||||
public class Address {
|
||||
public record Address(@Element(0) String address, @Element(1) String city, @Element(2) String zip) {
|
||||
|
||||
@Element(0) String address;
|
||||
@Element(1) String city;
|
||||
@Element(2) String zip;
|
||||
}
|
||||
|
||||
@@ -15,20 +15,11 @@
|
||||
*/
|
||||
package example.springdata.cassandra.convert;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Sample Contact class.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Contact {
|
||||
public record Contact(String firstname, String lastname) {
|
||||
|
||||
String firstname;
|
||||
String lastname;
|
||||
}
|
||||
|
||||
@@ -93,12 +93,7 @@ class ConverterConfiguration {
|
||||
|
||||
public CustomAddressbook convert(Row source) {
|
||||
|
||||
CustomAddressbook result = new CustomAddressbook();
|
||||
|
||||
result.setTheId(source.getString("id"));
|
||||
result.setMyDetailsAsJson(source.getString("me"));
|
||||
|
||||
return result;
|
||||
return new CustomAddressbook(source.getString("id"), source.getString("me"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,9 @@
|
||||
*/
|
||||
package example.springdata.cassandra.convert;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
public class CustomAddressbook {
|
||||
public record CustomAddressbook(String theId, String myDetailsAsJson) {
|
||||
|
||||
String theId;
|
||||
String myDetailsAsJson;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package example.springdata.cassandra.events;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
|
||||
@@ -27,14 +23,7 @@ import org.springframework.data.cassandra.core.mapping.Table;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(value = "users")
|
||||
public class User {
|
||||
public record User(@PrimaryKey long id, String firstname, String lastname) {
|
||||
|
||||
private @PrimaryKey long id;
|
||||
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package example.springdata.cassandra.optimisticlocking;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
@@ -27,14 +25,10 @@ import org.springframework.data.cassandra.core.mapping.Table;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@Table
|
||||
public class OptimisticPerson {
|
||||
|
||||
@Id Long id;
|
||||
|
||||
@Version long version;
|
||||
|
||||
String name;
|
||||
public record OptimisticPerson(@Id Long id, @Version long version, String name) {
|
||||
|
||||
public OptimisticPerson withName(String name) {
|
||||
return new OptimisticPerson(id, version, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,7 @@ import org.springframework.data.cassandra.core.mapping.Table;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Value
|
||||
@Table
|
||||
class Customer {
|
||||
record Customer(@Id String id, String firstname, String lastname) {
|
||||
|
||||
@Id String id;
|
||||
String firstname, lastname;
|
||||
}
|
||||
|
||||
@@ -15,18 +15,12 @@
|
||||
*/
|
||||
package example.springdata.cassandra.udt;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@UserDefinedType
|
||||
@AllArgsConstructor
|
||||
public class Address {
|
||||
public record Address(String street, String zip, String city) {
|
||||
|
||||
String street, zip, city;
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ class AuditedPersonRepositoryTests {
|
||||
@Test
|
||||
void insertShouldSetCreatedDate() {
|
||||
|
||||
AuditedPerson person = new AuditedPerson();
|
||||
var person = new AuditedPerson();
|
||||
person.setId(42L);
|
||||
person.setNew(true); // Cassandra does not support auto-generation hence we need
|
||||
// to supply whether our object is a new one.
|
||||
AuditedPerson saved = repository.save(person);
|
||||
var saved = repository.save(person);
|
||||
|
||||
assertThat(saved.getCreatedBy()).isEqualTo("Some user");
|
||||
assertThat(saved.getLastModifiedBy()).isEqualTo("Some user");
|
||||
@@ -70,7 +70,7 @@ class AuditedPersonRepositoryTests {
|
||||
@Test
|
||||
void updateShouldSetLastModifiedDate() {
|
||||
|
||||
AuditedPerson person = new AuditedPerson();
|
||||
var person = new AuditedPerson();
|
||||
person.setId(42L);
|
||||
person.setNew(true); // Cassandra does not support auto-generation hence we need
|
||||
// to supply whether our object is a new one.
|
||||
@@ -78,7 +78,7 @@ class AuditedPersonRepositoryTests {
|
||||
|
||||
person.setNew(false);
|
||||
|
||||
AuditedPerson modified = repository.save(person);
|
||||
var modified = repository.save(person);
|
||||
|
||||
assertThat(modified.getCreatedBy()).isEqualTo("Some user");
|
||||
assertThat(modified.getLastModifiedBy()).isEqualTo("Some user");
|
||||
|
||||
@@ -46,14 +46,14 @@ import com.datastax.oss.driver.api.querybuilder.insert.Insert;
|
||||
*/
|
||||
@SpringBootTest(classes = BasicConfiguration.class)
|
||||
@CassandraKeyspace
|
||||
public class CassandraOperationsIntegrationTests {
|
||||
class CassandraOperationsIntegrationTests {
|
||||
|
||||
|
||||
@Autowired CqlSession session;
|
||||
@Autowired CassandraOperations template;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
template.getCqlOperations().execute("TRUNCATE users");
|
||||
}
|
||||
|
||||
@@ -62,9 +62,9 @@ public class CassandraOperationsIntegrationTests {
|
||||
* mapping layer.
|
||||
*/
|
||||
@Test
|
||||
public void insertAndSelect() {
|
||||
void insertAndSelect() {
|
||||
|
||||
Insert insert = QueryBuilder.insertInto("users").value("user_id", QueryBuilder.literal(42L)) //
|
||||
var insert = QueryBuilder.insertInto("users").value("user_id", QueryBuilder.literal(42L)) //
|
||||
.value("uname", QueryBuilder.literal("heisenberg")) //
|
||||
.value("fname", QueryBuilder.literal("Walter")) //
|
||||
.value("lname", QueryBuilder.literal("White")) //
|
||||
@@ -72,10 +72,10 @@ public class CassandraOperationsIntegrationTests {
|
||||
|
||||
template.getCqlOperations().execute(insert.asCql());
|
||||
|
||||
User user = template.selectOneById(42L, User.class);
|
||||
var user = template.selectOneById(42L, User.class);
|
||||
assertThat(user.getUsername()).isEqualTo("heisenberg");
|
||||
|
||||
List<User> users = template.select(QueryBuilder.selectFrom("users").all().asCql(), User.class);
|
||||
var users = template.select(QueryBuilder.selectFrom("users").all().asCql(), User.class);
|
||||
assertThat(users).hasSize(1);
|
||||
assertThat(users.get(0)).isEqualTo(user);
|
||||
}
|
||||
@@ -85,9 +85,9 @@ public class CassandraOperationsIntegrationTests {
|
||||
* {@code select}.
|
||||
*/
|
||||
@Test
|
||||
public void insertAndUpdate() {
|
||||
void insertAndUpdate() {
|
||||
|
||||
User user = new User();
|
||||
var user = new User();
|
||||
user.setId(42L);
|
||||
user.setUsername("heisenberg");
|
||||
user.setFirstname("Walter");
|
||||
@@ -98,7 +98,7 @@ public class CassandraOperationsIntegrationTests {
|
||||
user.setFirstname(null);
|
||||
template.update(user);
|
||||
|
||||
User loaded = template.selectOneById(42L, User.class);
|
||||
var loaded = template.selectOneById(42L, User.class);
|
||||
assertThat(loaded.getUsername()).isEqualTo("heisenberg");
|
||||
assertThat(loaded.getFirstname()).isNull();
|
||||
}
|
||||
@@ -107,25 +107,25 @@ public class CassandraOperationsIntegrationTests {
|
||||
* Asynchronous query execution using callbacks.
|
||||
*/
|
||||
@Test
|
||||
public void insertAsynchronously() throws InterruptedException {
|
||||
void insertAsynchronously() throws InterruptedException {
|
||||
|
||||
User user = new User();
|
||||
var user = new User();
|
||||
user.setId(42L);
|
||||
user.setUsername("heisenberg");
|
||||
user.setFirstname("Walter");
|
||||
user.setLastname("White");
|
||||
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
final var countDownLatch = new CountDownLatch(1);
|
||||
|
||||
AsyncCassandraTemplate asyncTemplate = new AsyncCassandraTemplate(session);
|
||||
var asyncTemplate = new AsyncCassandraTemplate(session);
|
||||
|
||||
ListenableFuture<User> future = asyncTemplate.insert(user);
|
||||
var future = asyncTemplate.insert(user);
|
||||
|
||||
future.addCallback(it -> countDownLatch.countDown(), throwable -> countDownLatch.countDown());
|
||||
|
||||
countDownLatch.await(5, TimeUnit.SECONDS);
|
||||
|
||||
User loaded = template.selectOneById(user.getId(), User.class);
|
||||
var loaded = template.selectOneById(user.getId(), User.class);
|
||||
assertThat(loaded).isEqualTo(user);
|
||||
}
|
||||
|
||||
@@ -135,9 +135,9 @@ public class CassandraOperationsIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void selectProjections() {
|
||||
void selectProjections() {
|
||||
|
||||
User user = new User();
|
||||
var user = new User();
|
||||
user.setId(42L);
|
||||
user.setUsername("heisenberg");
|
||||
user.setFirstname("Walter");
|
||||
@@ -145,10 +145,10 @@ public class CassandraOperationsIntegrationTests {
|
||||
|
||||
template.insert(user);
|
||||
|
||||
Long id = template.selectOne(QueryBuilder.selectFrom("users").column("user_id").asCql(), Long.class);
|
||||
var id = template.selectOne(QueryBuilder.selectFrom("users").column("user_id").asCql(), Long.class);
|
||||
assertThat(id).isEqualTo(user.getId());
|
||||
|
||||
Row row = template.selectOne(QueryBuilder.selectFrom("users").column("user_id").asCql(), Row.class);
|
||||
var row = template.selectOne(QueryBuilder.selectFrom("users").column("user_id").asCql(), Row.class);
|
||||
assertThat(row.getLong(0)).isEqualTo(user.getId());
|
||||
|
||||
Map<String, Object> map = template.selectOne(QueryBuilder.selectFrom("users").all().asCql(), Map.class);
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.datastax.oss.driver.api.core.cql.Row;
|
||||
import com.datastax.oss.driver.api.core.data.TupleValue;
|
||||
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@@ -57,7 +56,7 @@ class ConversionIntegrationTests {
|
||||
@Test
|
||||
void shouldCreateAddressbook() {
|
||||
|
||||
Addressbook addressbook = new Addressbook();
|
||||
var addressbook = new Addressbook();
|
||||
addressbook.setId("private");
|
||||
|
||||
addressbook.setMe(new Contact("Walter", "White"));
|
||||
@@ -65,7 +64,7 @@ class ConversionIntegrationTests {
|
||||
|
||||
operations.insert(addressbook);
|
||||
|
||||
Row row = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(), Row.class);
|
||||
var row = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(), Row.class);
|
||||
|
||||
assertThat(row).isNotNull();
|
||||
|
||||
@@ -81,7 +80,7 @@ class ConversionIntegrationTests {
|
||||
@Test
|
||||
void shouldReadAddressbook() {
|
||||
|
||||
Addressbook addressbook = new Addressbook();
|
||||
var addressbook = new Addressbook();
|
||||
addressbook.setId("private");
|
||||
|
||||
addressbook.setMe(new Contact("Walter", "White"));
|
||||
@@ -89,7 +88,7 @@ class ConversionIntegrationTests {
|
||||
|
||||
operations.insert(addressbook);
|
||||
|
||||
Addressbook loaded = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(), Addressbook.class);
|
||||
var loaded = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(), Addressbook.class);
|
||||
|
||||
assertThat(loaded.getMe()).isEqualTo(addressbook.getMe());
|
||||
assertThat(loaded.getFriends()).isEqualTo(addressbook.getFriends());
|
||||
@@ -103,18 +102,18 @@ class ConversionIntegrationTests {
|
||||
@Test
|
||||
void shouldReadCustomAddressbook() {
|
||||
|
||||
Addressbook addressbook = new Addressbook();
|
||||
var addressbook = new Addressbook();
|
||||
addressbook.setId("private");
|
||||
|
||||
addressbook.setMe(new Contact("Walter", "White"));
|
||||
|
||||
operations.insert(addressbook);
|
||||
|
||||
CustomAddressbook loaded = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(),
|
||||
var loaded = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(),
|
||||
CustomAddressbook.class);
|
||||
|
||||
assertThat(loaded.getTheId()).isEqualTo(addressbook.getId());
|
||||
assertThat(loaded.getMyDetailsAsJson()).contains("\"firstname\":\"Walter\"");
|
||||
assertThat(loaded.theId()).isEqualTo(addressbook.getId());
|
||||
assertThat(loaded.myDetailsAsJson()).contains("\"firstname\":\"Walter\"");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,33 +122,30 @@ class ConversionIntegrationTests {
|
||||
@Test
|
||||
void shouldWriteConvertedMapsAndTuples() {
|
||||
|
||||
Addressbook addressbook = new Addressbook();
|
||||
var addressbook = new Addressbook();
|
||||
addressbook.setId("private");
|
||||
|
||||
Map<Integer, Currency> preferredCurrencies = new HashMap<>();
|
||||
preferredCurrencies.put(1, Currency.getInstance("USD"));
|
||||
preferredCurrencies.put(2, Currency.getInstance("EUR"));
|
||||
|
||||
Address address = new Address();
|
||||
address.setAddress("3828 Piermont Dr");
|
||||
address.setCity("Albuquerque");
|
||||
address.setZip("87111");
|
||||
var address = new Address("3828 Piermont Dr", "Albuquerque", "87111");
|
||||
|
||||
addressbook.setPreferredCurrencies(preferredCurrencies);
|
||||
addressbook.setAddress(address);
|
||||
|
||||
operations.insert(addressbook);
|
||||
|
||||
Row row = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(), Row.class);
|
||||
var row = operations.selectOne(QueryBuilder.selectFrom("addressbook").all().asCql(), Row.class);
|
||||
|
||||
assertThat(row).isNotNull();
|
||||
|
||||
TupleValue tupleValue = row.getTupleValue("address");
|
||||
assertThat(tupleValue.getString(0)).isEqualTo(address.getAddress());
|
||||
assertThat(tupleValue.getString(1)).isEqualTo(address.getCity());
|
||||
assertThat(tupleValue.getString(2)).isEqualTo(address.getZip());
|
||||
var tupleValue = row.getTupleValue("address");
|
||||
assertThat(tupleValue.getString(0)).isEqualTo(address.address());
|
||||
assertThat(tupleValue.getString(1)).isEqualTo(address.city());
|
||||
assertThat(tupleValue.getString(2)).isEqualTo(address.zip());
|
||||
|
||||
Map<Integer, String> rawPreferredCurrencies = row.getMap("preferredCurrencies", Integer.class, String.class);
|
||||
var rawPreferredCurrencies = row.getMap("preferredCurrencies", Integer.class, String.class);
|
||||
|
||||
assertThat(rawPreferredCurrencies).containsEntry(1, "USD").containsEntry(2, "EUR");
|
||||
}
|
||||
|
||||
@@ -35,33 +35,33 @@ import org.springframework.data.cassandra.core.query.Query;
|
||||
*/
|
||||
@SpringBootTest(classes = BasicConfiguration.class)
|
||||
@CassandraKeyspace
|
||||
public class LifecycleEventsTests {
|
||||
class LifecycleEventsTests {
|
||||
|
||||
@Autowired CassandraOperations operations;
|
||||
|
||||
@Test
|
||||
public void shouldStreamEntities() {
|
||||
void shouldStreamEntities() {
|
||||
|
||||
insertEntities();
|
||||
|
||||
Stream<User> userStream = operations.stream(Query.empty(), User.class);
|
||||
var userStream = operations.stream(Query.empty(), User.class);
|
||||
userStream.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEntitiesAsList() {
|
||||
void shouldReturnEntitiesAsList() {
|
||||
|
||||
insertEntities();
|
||||
|
||||
List<User> userStream = operations.select(Query.empty(), User.class);
|
||||
var userStream = operations.select(Query.empty(), User.class);
|
||||
userStream.forEach(System.out::println);
|
||||
}
|
||||
|
||||
private void insertEntities() {
|
||||
|
||||
User walter = new User(1, "Walter", "White");
|
||||
User skyler = new User(2, "Skyler", "White");
|
||||
User jesse = new User(3, "Jesse Pinkman", "Jesse Pinkman");
|
||||
var walter = new User(1, "Walter", "White");
|
||||
var skyler = new User(2, "Skyler", "White");
|
||||
var jesse = new User(3, "Jesse Pinkman", "Jesse Pinkman");
|
||||
|
||||
operations.truncate(User.class);
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.EntityWriteResult;
|
||||
import org.springframework.data.cassandra.core.UpdateOptions;
|
||||
import org.springframework.data.cassandra.core.query.Criteria;
|
||||
|
||||
@@ -51,13 +50,11 @@ public class OptimisticPersonRepositoryTests {
|
||||
@Test
|
||||
public void insertShouldIncrementVersion() {
|
||||
|
||||
OptimisticPerson person = new OptimisticPerson();
|
||||
person.setId(42L);
|
||||
person.setName("Walter White");
|
||||
var person = new OptimisticPerson(42L, 0, "Walter White");
|
||||
|
||||
OptimisticPerson saved = repository.save(person);
|
||||
var saved = repository.save(person);
|
||||
|
||||
assertThat(saved.getVersion()).isGreaterThan(0);
|
||||
assertThat(saved.version()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,23 +63,21 @@ public class OptimisticPersonRepositoryTests {
|
||||
@Test
|
||||
public void updateShouldDetectChangedEntity() {
|
||||
|
||||
OptimisticPerson person = new OptimisticPerson();
|
||||
person.setId(42L);
|
||||
person.setName("Walter White");
|
||||
var person = new OptimisticPerson(42L, 0, "Walter White");
|
||||
|
||||
// Load the person because we intend to change it.
|
||||
OptimisticPerson saved = repository.save(person);
|
||||
var saved = repository.save(person);
|
||||
|
||||
// Another process has changed the person object in the meantime.
|
||||
OptimisticPerson anotherProcess = repository.findById(person.getId()).get();
|
||||
anotherProcess.setName("Heisenberg");
|
||||
var anotherProcess = repository.findById(person.id()).get();
|
||||
anotherProcess = anotherProcess.withName("Heisenberg");
|
||||
repository.save(anotherProcess);
|
||||
|
||||
// Now it's our turn to modify the object...
|
||||
saved.setName("Walter");
|
||||
var ourSaved = saved.withName("Walter");
|
||||
|
||||
// ...which fails with a OptimisticLockingFailureException, using LWT under the hood.
|
||||
assertThatExceptionOfType(OptimisticLockingFailureException.class).isThrownBy(() -> repository.save(saved));
|
||||
assertThatExceptionOfType(OptimisticLockingFailureException.class).isThrownBy(() -> repository.save(ourSaved));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,18 +87,18 @@ public class OptimisticPersonRepositoryTests {
|
||||
@Test
|
||||
public void updateUsingLightWeightTransactions() {
|
||||
|
||||
SimplePerson person = new SimplePerson();
|
||||
var person = new SimplePerson();
|
||||
person.setId(42L);
|
||||
person.setName("Walter White");
|
||||
|
||||
operations.insert(person);
|
||||
|
||||
EntityWriteResult<SimplePerson> success = operations.update(person,
|
||||
var success = operations.update(person,
|
||||
UpdateOptions.builder().ifCondition(Criteria.where("name").is("Walter White")).build());
|
||||
|
||||
assertThat(success.wasApplied()).isTrue();
|
||||
|
||||
EntityWriteResult<SimplePerson> failed = operations.update(person,
|
||||
var failed = operations.update(person,
|
||||
UpdateOptions.builder().ifCondition(Criteria.where("name").is("Heisenberg")).build());
|
||||
|
||||
assertThat(failed.wasApplied()).isFalse();
|
||||
|
||||
@@ -53,7 +53,7 @@ class CustomerRepositoryIntegrationTest {
|
||||
@Test
|
||||
void projectsEntityIntoInterface() {
|
||||
|
||||
Collection<CustomerProjection> result = customers.findAllProjectedBy();
|
||||
var result = customers.findAllProjectedBy();
|
||||
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result.iterator().next().getFirstname()).isEqualTo("Carter");
|
||||
@@ -62,7 +62,7 @@ class CustomerRepositoryIntegrationTest {
|
||||
@Test
|
||||
void projectsDynamically() {
|
||||
|
||||
Collection<CustomerProjection> result = customers.findById("d", CustomerProjection.class);
|
||||
var result = customers.findById("d", CustomerProjection.class);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.iterator().next().getFirstname()).isEqualTo("Dave");
|
||||
@@ -71,7 +71,7 @@ class CustomerRepositoryIntegrationTest {
|
||||
@Test
|
||||
void projectsIndividualDynamically() {
|
||||
|
||||
CustomerSummary result = customers.findProjectedById(dave.getId(), CustomerSummary.class);
|
||||
var result = customers.findProjectedById(dave.id(), CustomerSummary.class);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getFullName()).isEqualTo("Dave Matthews");
|
||||
@@ -83,7 +83,7 @@ class CustomerRepositoryIntegrationTest {
|
||||
@Test
|
||||
void projectIndividualInstance() {
|
||||
|
||||
CustomerProjection result = customers.findProjectedById(dave.getId());
|
||||
var result = customers.findProjectedById(dave.id());
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getFirstname()).isEqualTo("Dave");
|
||||
|
||||
@@ -49,6 +49,16 @@ class UserDefinedTypeIntegrationTest {
|
||||
@Configuration
|
||||
static class Config extends AbstractCassandraConfiguration {
|
||||
|
||||
@Override
|
||||
protected int getPort() {
|
||||
return Integer.getInteger("spring.data.cassandra.port");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getContactPoints() {
|
||||
return System.getProperty("spring.data.cassandra.contact-points");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyspaceName() {
|
||||
return "example";
|
||||
@@ -84,7 +94,7 @@ class UserDefinedTypeIntegrationTest {
|
||||
@Test
|
||||
void insertMappedUdt() {
|
||||
|
||||
Person person = new Person();
|
||||
var person = new Person();
|
||||
person.setId(42);
|
||||
person.setFirstname("Walter");
|
||||
person.setLastname("White");
|
||||
@@ -94,7 +104,7 @@ class UserDefinedTypeIntegrationTest {
|
||||
|
||||
operations.insert(person);
|
||||
|
||||
Person loaded = operations.selectOne("SELECT * FROM person WHERE id = 42", Person.class);
|
||||
var loaded = operations.selectOne("SELECT * FROM person WHERE id = 42", Person.class);
|
||||
|
||||
assertThat(loaded.getCurrent()).isEqualTo(person.getCurrent());
|
||||
assertThat(loaded.getPrevious()).containsAll(person.getPrevious());
|
||||
@@ -106,15 +116,15 @@ class UserDefinedTypeIntegrationTest {
|
||||
@Test
|
||||
void insertRawUdt() {
|
||||
|
||||
KeyspaceMetadata keyspaceMetadata = adminOperations.getKeyspaceMetadata();
|
||||
UserDefinedType address = keyspaceMetadata.getUserDefinedType("address").get();
|
||||
var keyspaceMetadata = adminOperations.getKeyspaceMetadata();
|
||||
var address = keyspaceMetadata.getUserDefinedType("address").get();
|
||||
|
||||
UdtValue udtValue = address.newValue();
|
||||
var udtValue = address.newValue();
|
||||
udtValue.setString("street", "308 Negra Arroyo Lane");
|
||||
udtValue.setString("zip", "87104");
|
||||
udtValue.setString("city", "Albuquerque");
|
||||
|
||||
Person person = new Person();
|
||||
var person = new Person();
|
||||
person.setId(42);
|
||||
person.setFirstname("Walter");
|
||||
person.setLastname("White");
|
||||
@@ -123,7 +133,7 @@ class UserDefinedTypeIntegrationTest {
|
||||
|
||||
operations.insert(person);
|
||||
|
||||
Person loaded = operations.selectOne("SELECT * FROM person WHERE id = 42", Person.class);
|
||||
var loaded = operations.selectOne("SELECT * FROM person WHERE id = 42", Person.class);
|
||||
|
||||
assertThat(loaded.getAlternative().getString("zip")).isEqualTo("87104");
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Java8IntegrationTests {
|
||||
@Test
|
||||
void providesFindOneWithOptional() {
|
||||
|
||||
Person homer = repository.save(new Person("1", "Homer", "Simpson"));
|
||||
var homer = repository.save(new Person("1", "Homer", "Simpson"));
|
||||
|
||||
assertThat(repository.findById(homer.id).isPresent()).isTrue();
|
||||
assertThat(repository.findById(homer.id + 1)).isEqualTo(Optional.<Person> empty());
|
||||
@@ -57,8 +57,8 @@ class Java8IntegrationTests {
|
||||
@Test
|
||||
void invokesDefaultMethod() {
|
||||
|
||||
Person homer = repository.save(new Person("1", "Homer", "Simpson"));
|
||||
Optional<Person> result = repository.findByPerson(homer);
|
||||
var homer = repository.save(new Person("1", "Homer", "Simpson"));
|
||||
var result = repository.findByPerson(homer);
|
||||
|
||||
assertThat(result.isPresent()).isTrue();
|
||||
assertThat(result.get()).isEqualTo(homer);
|
||||
@@ -71,10 +71,10 @@ class Java8IntegrationTests {
|
||||
@Test
|
||||
void useJava8StreamsWithCustomQuery() {
|
||||
|
||||
Person homer = repository.save(new Person("1", "Homer", "Simpson"));
|
||||
Person bart = repository.save(new Person("2", "Bart", "Simpson"));
|
||||
var homer = repository.save(new Person("1", "Homer", "Simpson"));
|
||||
var bart = repository.save(new Person("2", "Bart", "Simpson"));
|
||||
|
||||
try (Stream<Person> stream = repository.findAll()) {
|
||||
try (var stream = repository.findAll()) {
|
||||
assertThat(stream.collect(Collectors.toList())).contains(homer, bart);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class Jsr310IntegrationTests {
|
||||
@Test
|
||||
void findOneByJsr310Types() {
|
||||
|
||||
Order order = new Order("42", LocalDate.now(), ZoneId.systemDefault());
|
||||
var order = new Order("42", LocalDate.now(), ZoneId.systemDefault());
|
||||
|
||||
repository.save(order);
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package example.springdata.cassandra.spel;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
|
||||
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
@@ -24,10 +22,8 @@ import org.springframework.data.cassandra.core.mapping.Table;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Value
|
||||
@Table
|
||||
public class Employee {
|
||||
public record Employee(@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED) String tenantId,
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED) String name) {
|
||||
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED) String tenantId;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED) String name;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AuditingIntegrationTests {
|
||||
@Test
|
||||
public void shouldUpdateAuditor() throws InterruptedException {
|
||||
|
||||
Order order = new Order("4711");
|
||||
var order = new Order("4711");
|
||||
order.setNew(true);
|
||||
|
||||
orderRepository.save(order).as(StepVerifier::create).assertNext(actual -> {
|
||||
|
||||
@@ -47,7 +47,7 @@ class ReactiveCassandraTemplateIntegrationTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
Flux<Person> truncateAndInsert = template.truncate(Person.class) //
|
||||
var truncateAndInsert = template.truncate(Person.class) //
|
||||
.thenMany(Flux.just(new Person("Walter", "White", 50), //
|
||||
new Person("Skyler", "White", 45), //
|
||||
new Person("Saul", "Goodman", 42), //
|
||||
@@ -64,7 +64,7 @@ class ReactiveCassandraTemplateIntegrationTest {
|
||||
@Test
|
||||
void shouldInsertAndCountData() {
|
||||
|
||||
Mono<Long> saveAndCount = template.count(Person.class) //
|
||||
var saveAndCount = template.count(Person.class) //
|
||||
.doOnNext(System.out::println) //
|
||||
.thenMany(Flux.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))
|
||||
@@ -82,7 +82,7 @@ class ReactiveCassandraTemplateIntegrationTest {
|
||||
@Test
|
||||
void convertReactorTypesToRxJava1() throws Exception {
|
||||
|
||||
Flux<Person> flux = template.select("SELECT * FROM person WHERE lastname = 'White'", Person.class);
|
||||
var flux = template.select("SELECT * FROM person WHERE lastname = 'White'", Person.class);
|
||||
|
||||
long count = RxReactiveStreams.toObservable(flux) //
|
||||
.count() //
|
||||
|
||||
@@ -43,7 +43,7 @@ class ReactivePersonRepositoryIntegrationTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
Flux<Person> deleteAndInsert = repository.deleteAll() //
|
||||
var deleteAndInsert = repository.deleteAll() //
|
||||
.thenMany(repository.saveAll(Flux.just(new Person("Walter", "White", 50), //
|
||||
new Person("Skyler", "White", 45), //
|
||||
new Person("Saul", "Goodman", 42), //
|
||||
@@ -58,7 +58,7 @@ class ReactivePersonRepositoryIntegrationTest {
|
||||
@Test
|
||||
void shouldInsertAndCountData() {
|
||||
|
||||
Mono<Long> saveAndCount = repository.count() //
|
||||
var saveAndCount = repository.count() //
|
||||
.doOnNext(System.out::println) //
|
||||
.thenMany(repository.saveAll(Flux.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))) //
|
||||
|
||||
@@ -45,9 +45,9 @@ public class RxJava2PersonRepositoryIntegrationTest {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
Completable deleteAll = repository.deleteAll();
|
||||
var deleteAll = repository.deleteAll();
|
||||
|
||||
Flowable<Person> save = repository.saveAll(Flowable.just(new Person("Walter", "White", 50), //
|
||||
var save = repository.saveAll(Flowable.just(new Person("Walter", "White", 50), //
|
||||
new Person("Skyler", "White", 45), //
|
||||
new Person("Saul", "Goodman", 42), //
|
||||
new Person("Jesse", "Pinkman", 27)));
|
||||
|
||||
Reference in New Issue
Block a user