0

I try this and work fine.

@Autowired

private CassandraOperations cassandraOperations;

in my method
{
  String cqlAll = "select * from customer where cust_id=123";

  List<Customer> results = cassandraOperations.select(cqlAll, Customer.class);  
  for (Customer p : results) 
  {
    System.out.println(p.getCust_id() + "-"+p.getCust_name()+"-"+p.getCust_password());
  }
}

but I want to pass value to string so I can write my query file separately. something like this,

String cqlAll = "select * from customer where cust_id=?";

objects[] obj = {123};

List<Customer> results = cassandraOperations.select(cqlAll, obj ,Customer.class);

for (Customer p : results) 
{
System.out.println(p.getCust_id() + "-"+p.getCust_name()+"-"+
  p.getCust_password());
}
shilovk
  • 11,718
  • 17
  • 75
  • 74

1 Answers1

0

CassandraOperation select method can be build also with com.datastax.driver.core.querybuilder.Select, as I can see from spring data cassandra documentation.

I do not have much experience with spring data cassandra, since we work directly with datastax java driver, but this should work for select:

final Select select = QueryBuilder.select().all().from("customer")
            .where(QueryBuilder.eq("cust_id", 123)).limit(200);
cassandraOperations.select(select ,Customer.class);

123 can be any dynamic value pulled from object.

Update can be done using CqlOperations:

CqlOperations cqlOperations = new CqlOperations(); //or autowire it
final Statement update = QueryBuilder.update("customer")
                .with(QueryBuilder.set("email", "example@example.com"))
                .where(QueryBuilder.eq("cust_id", 123));
cqlOperations.execute(update);

Some more QueryBuilder examples can be found here.

Nenad Bozic
  • 3,724
  • 19
  • 45
  • heyy @Nenad thanks for reply... then for update, do I need to use Update update = QueryBuilder..... etc? can you show update example please... – nikhil mahajan Jul 08 '15 at 07:50
  • As for update I do not see method in CassandraOperations that accepts Update statement, everything is done with Entity so guess cannot be doen with QueryBuilder http://docs.spring.io/spring-data/cassandra/docs/current/api/org/springframework/data/cassandra/core/CassandraOperations.html – Nenad Bozic Jul 08 '15 at 08:49
  • It can be done it appears with CqlOperations so added example for that http://docs.spring.io/spring-data/cassandra/docs/current/api/org/springframework/cassandra/core/CqlOperations.html – Nenad Bozic Jul 08 '15 at 08:59