Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>1.5.0.BUILD-SNAPSHOT</version>
<version>1.5.0.DATACASS-182-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Cassandra</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-cql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>1.5.0.BUILD-SNAPSHOT</version>
<version>1.5.0.DATACASS-182-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-cassandra-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>1.5.0.BUILD-SNAPSHOT</version>
<version>1.5.0.DATACASS-182-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>1.5.0.BUILD-SNAPSHOT</version>
<version>1.5.0.DATACASS-182-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,10 @@ public void doWithPersistentProperty(CassandraPersistentProperty prop) {
return;
}

if (value != null) {
if (log.isDebugEnabled()) {
log.debug("Adding insert.value [{}] - [{}]", prop.getColumnName().toCql(), value);
}
insert.value(prop.getColumnName().toCql(), value);
if (log.isDebugEnabled()) {
log.debug("Adding insert.value [{}] - [{}]", prop.getColumnName().toCql(), value);
}
insert.value(prop.getColumnName().toCql(), value);
}
});
}
Expand All @@ -303,12 +301,10 @@ public void doWithPersistentProperty(CassandraPersistentProperty prop) {
return;
}

if (value != null) {
if (prop.isIdProperty() || entity.isCompositePrimaryKey() || prop.isPrimaryKeyColumn()) {
update.where(QueryBuilder.eq(prop.getColumnName().toCql(), value));
} else {
update.with(QueryBuilder.set(prop.getColumnName().toCql(), value));
}
if (isPrimaryKeyPart(prop)) {
update.where(QueryBuilder.eq(prop.getColumnName().toCql(), value));
} else {
update.with(QueryBuilder.set(prop.getColumnName().toCql(), value));
}
}
});
Expand Down Expand Up @@ -444,4 +440,14 @@ private ConvertingPropertyAccessor getConvertingAccessor(Object source, Cassandr

return new ConvertingPropertyAccessor(accessor, conversionService);
}

/**
* Returns whether the property is part of the primary key.
*
* @param property
* @return
*/
private boolean isPrimaryKeyPart(CassandraPersistentProperty property) {
return property.isCompositePrimaryKey() || property.isPrimaryKeyColumn() || property.isIdProperty();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2016 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class SimpleCassandraRepository<T, ID extends Serializable> implements TypedIdCassandraRepository<T, ID> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void insertEnumShouldMapToString() {

mappingCassandraConverter.write(withEnumColumns, insert);

assertThat(getValues(insert), contains((Object) "MINT"));
assertThat(getValues(insert), hasItem((Object) "MINT"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
Expand All @@ -34,13 +36,16 @@
import org.springframework.cassandra.core.WriteOptions;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.test.integration.simpletons.Book;
import org.springframework.data.cassandra.test.integration.simpletons.BookCondition;
import org.springframework.data.cassandra.test.integration.simpletons.BookReference;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.datastax.driver.core.querybuilder.Delete;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;

Expand Down Expand Up @@ -691,7 +696,6 @@ public void selectCountTest() {
assertThat(template.count(Book.class), is(equalTo(count)));
}


@Test
public void insertAndSelect() {

Expand All @@ -703,6 +707,90 @@ public void insertAndSelect() {
assertThat(template.count(Book.class), is(equalTo(count)));
}

/**
* @see DATACASS-182
*/
@Test
public void updateShouldRemoveFields() {

Book book = new Book();
book.setIsbn("isbn");
book.setTitle("title");
book.setAuthor("author");

template.insert(book);

book.setTitle(null);
template.update(book);

Book loaded = template.selectOneById(Book.class, book.getIsbn());

assertThat(loaded.getTitle(), is(nullValue()));
assertThat(loaded.getAuthor(), is(equalTo("author")));
}

/**
* @see DATACASS-182
*/
@Test
public void insertShouldRemoveFields() {

Book book = new Book();
book.setIsbn("isbn");
book.setTitle("title");
book.setAuthor("author");

template.insert(book);

book.setTitle(null);
template.insert(book);

Book loaded = template.selectOneById(Book.class, book.getIsbn());

assertThat(loaded.getTitle(), is(nullValue()));
assertThat(loaded.getAuthor(), is(equalTo("author")));
}

/**
* @see DATACASS-182
*/
@Test
public void updateShouldInsertEntity() {

Book book = new Book();
book.setIsbn("isbn");
book.setTitle("title");
book.setAuthor("author");

template.update(book);

Book loaded = template.selectOneById(Book.class, book.getIsbn());

assertThat(loaded, is(notNullValue()));
}

/**
* @see DATACASS-182
*/
@Test
public void insertAndUpdateToEmptyCollection() {

BookReference bookReference = new BookReference();

bookReference.setIsbn("isbn");
bookReference.setBookmarks(Arrays.asList(1, 2, 3, 4));

template.insert(bookReference);

bookReference.setBookmarks(Collections.<Integer> emptyList());
template.update(bookReference);

BookReference loaded = template.selectOneById(BookReference.class, bookReference.getIsbn());

assertThat(loaded.getTitle(), is(nullValue()));
assertThat(loaded.getBookmarks(), is(nullValue()));
}

/**
* @see DATACASS-297
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Assert;
Expand All @@ -32,6 +33,7 @@
* @author Alex Shvid
* @author Matthew T. Adams
* @author David Webb
* @author Mark Paluch
*/
public class UserRepositoryIntegrationTests {

Expand Down Expand Up @@ -150,12 +152,27 @@ public void exists() {

}

/**
* @see DATACASS-182
*/
public void save() {

tom.setPassword(null);
tom.setFriends(Collections.<String>emptySet());

repository.save(tom);

User loadedTom = repository.findOne(tom.getUsername());

assertThat(loadedTom.getPassword(), is(nullValue()));
assertThat(loadedTom.getFriends(), is(nullValue()));
}

private static void assertEquals(User user1, User user2) {
Assert.assertEquals(user1.getUsername(), user2.getUsername());
Assert.assertEquals(user1.getFirstName(), user2.getFirstName());
Assert.assertEquals(user1.getLastName(), user2.getLastName());
Assert.assertEquals(user1.getPlace(), user2.getPlace());
Assert.assertEquals(user1.getPassword(), user2.getPassword());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* @author Matthew T. Adams
* @author David Webb
* @author Mark Paluch
*/
public abstract class UserRepositoryIntegrationTestsDelegator
extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
Expand Down Expand Up @@ -75,4 +76,12 @@ public void deletesUserByIdCorrectly() {
public void exists() {
tests.exists();
}

/**
* @see DATACASS-182
*/
@Test
public void save() {
tests.save();
}
}