Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
284 views
Welcome To Ask or Share your Answers For Others

1 Answer

See 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;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...