I need Prepared Statement / instead of Query Builder using Cassandra Operations Interface and session Any Example or recent docs. for Cassandra using java
See Question&Answers more detail:osI need Prepared Statement / instead of Query Builder using Cassandra Operations Interface and session Any Example or recent docs. for Cassandra using java
See Question&Answers more detail:osSee this to check how to use prepared statment while using java datastax driver.
However i would recommend to store all preparedstatments in a cache (for example a map) while application initializes and reuse the same whenever requreid by creating boundstatment out of it. For example :
//Here Key is query string
private static final Map<String, PreparedStatement> psMap = new ConcurrentHashMap<String, PreparedStatement>();
//Will be invoked @ initialization
public void init(Session session) {
this.session = session;
for (QuerySetEnum cql : QuerySetEnum.values()) {
psMap.put(cql.getStatement(), session.prepare(cql.getStatement()));
}
//In Dao Impl class
//Get bounded statment + execute by passing the value
@Override
public void decreaseStats(long size, long count, String mapname,
int bucketId) {
BoundStatement boundStatement = getBoundStatement(QuerySetEnum.DECREASE_STATS);
metaTemplate.execute(boundStatement.bind(size, count, mapname,
bucketId));
}
//Below is the implementation how to get BoundStatement out to prepared statment cache
private BoundStatement getBoundStatement(QuerySetEnum query) {
PreparedStatement preparedStatement = queryPool
.getPreparedStatement(query);
BoundStatement boundStatement = new BoundStatement(preparedStatement);
return boundStatement;
}