Skip to content

Instantly share code, notes, and snippets.

@mp911de
Last active July 21, 2016 06:48
Show Gist options
  • Select an option

  • Save mp911de/a5f26274272da3c3de051a8fd55a62f4 to your computer and use it in GitHub Desktop.

Select an option

Save mp911de/a5f26274272da3c3de051a8fd55a62f4 to your computer and use it in GitHub Desktop.
public class CassandraInQuery {
@Autowired
CassandraOperations cassandraOperations;
@Test
public void query() {
List<String> values = Arrays.asList("one", "two", "three");
List<MyEntity> result = new ArrayList<>();
// one-by-one
for (String value : values) {
Select select = QueryBuilder.select().from("mytable");
select.where(QueryBuilder.eq("a", value)).and(QueryBuilder.eq("b", "a-static-value"));
result.addAll(cassandraOperations.select(select, MyEntity.class));
}
// in-query
Select select = QueryBuilder.select().from("mytable");
select.where(QueryBuilder.in("a", values)).and(QueryBuilder.eq("b", "a-static-value"));
result = cassandraOperations.select(select, MyEntity.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment