#250 - Polishing.

Use Cassandra streaming query with query derivation instead of a String-based query.
This commit is contained in:
Mark Paluch
2017-01-25 12:13:08 +01:00
committed by Oliver Gierke
parent 54ab8178b7
commit 319d3e1a17
4 changed files with 7 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ package example.springdata.cassandra.udt;
import static org.assertj.core.api.Assertions.*;
import example.springdata.cassandra.util.RequiresCassandraKeyspace;
import example.springdata.cassandra.util.CassandraKeyspace;
import java.util.Collections;
@@ -42,12 +42,13 @@ import com.datastax.driver.core.UserType;
* Integration test to show User-Defined type support.
*
* @author Mark Paluch
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserDefinedTypeIntegrationTest {
@ClassRule public final static RequiresCassandraKeyspace CASSANDRA_KEYSPACE = RequiresCassandraKeyspace.onLocalhost();
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
@Configuration
static class Config extends AbstractCassandraConfiguration {

View File

@@ -12,9 +12,8 @@ public interface PersonRepository extends CrudRepository<Person, String> {
@Override
List<Person> findAll();
//Custom Query method returning a Java 8 Stream
@Query("SELECT * FROM person")
Stream<Person> findAllByCustomQueryWithStream();
// Derived query method returning a Java 8 Stream
Stream<Person> findAll();
}
```

View File

@@ -37,8 +37,7 @@ public interface PersonRepository extends Repository<Person, String> {
*/
Optional<Person> findOne(String id);
@Query("select * from person")
Stream<Person> streamAllPeople();
Stream<Person> findAll();
/**
* Sample method to derive a query from using JDK 8's {@link Optional} as return type.

View File

@@ -81,7 +81,7 @@ public class Java8IntegrationTests {
Person homer = repository.save(new Person("1", "Homer", "Simpson"));
Person bart = repository.save(new Person("2", "Bart", "Simpson"));
try (Stream<Person> stream = repository.streamAllPeople()) {
try (Stream<Person> stream = repository.findAll()) {
assertThat(stream.collect(Collectors.toList()), hasItems(homer, bart));
}
}