Java Code Examples for com.datastax.driver.core.PreparedStatement#getQueryString()

The following examples show how to use com.datastax.driver.core.PreparedStatement#getQueryString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Session.java    From glowroot with Apache License 2.0 6 votes vote down vote up
public ResultSet update(Statement statement) throws Exception {
    if (statement instanceof BoundStatement) {
        BoundStatement boundStatement = (BoundStatement) statement;
        PreparedStatement preparedStatement = boundStatement.preparedStatement();
        String queryString = preparedStatement.getQueryString();
        if (!queryString.contains(" if ")) {
            throw new IllegalStateException("Unexpected update query: " + queryString);
        }
        if (!queryString.startsWith("update ") && !queryString.startsWith("insert ")) {
            throw new IllegalStateException("Unexpected update query: " + queryString);
        }
    }
    // do not use session.execute() because that calls getUninterruptibly() which can cause
    // central shutdown to timeout while waiting for executor service to shutdown
    return updateAsync(statement).get();
}
 
Example 2
Source File: Session.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public ResultSet read(Statement statement) throws Exception {
    if (statement instanceof BoundStatement) {
        BoundStatement boundStatement = (BoundStatement) statement;
        PreparedStatement preparedStatement = boundStatement.preparedStatement();
        String queryString = preparedStatement.getQueryString();
        if (!queryString.startsWith("select ")) {
            throw new IllegalStateException("Unexpected read query: " + queryString);
        }
    }
    // do not use session.execute() because that calls getUninterruptibly() which can cause
    // central shutdown to timeout while waiting for executor service to shutdown
    return readAsync(statement).get();
}
 
Example 3
Source File: Session.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public void write(Statement statement) throws Exception {
    if (statement instanceof BoundStatement) {
        BoundStatement boundStatement = (BoundStatement) statement;
        PreparedStatement preparedStatement = boundStatement.preparedStatement();
        String queryString = preparedStatement.getQueryString();
        if (!queryString.startsWith("insert ") && !queryString.startsWith("delete ")) {
            throw new IllegalStateException("Unexpected write query: " + queryString);
        }
    }
    // do not use session.execute() because that calls getUninterruptibly() which can cause
    // central shutdown to timeout while waiting for executor service to shutdown
    writeAsync(statement).get();
}