Cassandra BoundStatement with limit

Viewed 2296

I am using PreparedStatement and BoundStatement to execute some Cassandra queries. The problem is, I am trying to use a limit on these. This is what I have:

 selectByDatasetIdAndTimePreparedStatement = getSession().prepare(
                QueryBuilder.select()
                        .all()
                        .from(KEYSPACE_NAME, TABLE_NAME)
                        .where(QueryBuilder.eq(AFFILIATION_ID_COLUMN, QueryBuilder.bindMarker()))
                        .and(QueryBuilder.eq(DATASET_ID_COLUMN, QueryBuilder.bindMarker()))
                        .and(QueryBuilder.lte(TIME_COLUMN, QueryBuilder.bindMarker()))
                        //.limit(QueryBuilder.bindMarker())
        );

Whenever I need to run the query, i call this function:

public Statement buildSelectByDatsetIdAndTimePreparedStatment(String affiliationId, String datasetId, Long time, int limit)
{
    BoundStatement boundStatement = selectByDatasetIdAndTimePreparedStatement
            .bind()
            .setString(AFFILIATION_ID_COLUMN, affiliationId)
            .setString(DATASET_ID_COLUMN, datasetId)
            .setLong(TIME_COLUMN, time);
    databaseManager.applyReadStatementsConfiguration(boundStatement);
    return boundStatement;
}

However, this works only without the limit clause in the first code snippet. I don't know how to specify the limit in the second snippet. I don't want to use string, something like

databaseManager.getSession().execute("SELECT * FROM myTable where ... limit 10);

Is there any way to do this using BoundStatement? I don't see anything like BoundStatement.limit() or setLimit().

Thanks, Serban

1 Answers
Related