Recover PreparedStatements from Connection Loss / Session Reconnect?

As far as I understand the documentation and what I read, a prepared statement is bound to the session. So the question goes, if I close the connection and recreate it or if the session gets killed (how is that even possible?) one has to recreate all prepared statements right?

What would be the Exception one gets if a PreparedStatement is not managed by the underlying session instance (anymore)?

[Update]

I have created my own simple statement class to represent a prepared statement since I create the statement on creation time just before a session exists. Additionally I use a map to map both on demand and I am ready to go... .

Answers


For Cassandra Drivers, the standard way is to prepare a statement once and bind variables multiple times before executing.

You can refer to this post: http://www.datastax.com/dev/blog/4-simple-rules-when-using-the-datastax-drivers-for-cassandra

I am sharing a code snippet that you can use. Session validation and preparing statement is something that you need to do at the beginning of your application execution, before starting mutations.

    if (session == null) {
        session = CassandraUtils.getInstance().getSession();
        psUsers = session.prepare("INSERT INTO users(xx, yy, zz, tt) VALUES (?, ?, ?, ?)");
        psProducts = session.prepare ("INSERT INTO products(aa, bb, cc, dd) VALUES (?, ?, ?, ?)");
    }

From the shared post above:

Use at most one Session per keyspace, or use a single Session and explicitely specify the keyspace in your queries

For the loss of connection part, driver handles it for you, and of course you can use different kind of reconnection policies: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/Policies.html


Need Your Help

FAQ Accordian Collapse on Click

javascript html css accordion collapse

I have an accordion FAQ section on my site. It currently expands when you click the headline, but I'd like it to collapse when you click the headline again.

Script only executing on Edit Mode-Sharepoint Page

javascript jquery sharepoint calendar

I have a script attached to a CEWP which only executes when I am on edit mode and does nothing when I save the page.