@PooledConnection public JSONArray getRowsWithQuery( String keyspace, String columnFamily, String queryStr, ConsistencyLevel consistencyLevel) throws InvalidRequestException, UnavailableException, TimedOutException, TException, CharacterCodingException { Query query = QueryParser.parse(queryStr); SlicePredicate predicate = new SlicePredicate(); SliceRange range = new SliceRange(ByteBufferUtil.bytes(""), ByteBufferUtil.bytes(""), false, MAX_COLUMNS); predicate.setSlice_range(range); ColumnParent parent = new ColumnParent(columnFamily); IndexClause indexClause = new IndexClause(); indexClause.setCount(MAX_ROWS); indexClause.setStart_key(new byte[0]); for (String keyName : query.getEqStmt().keySet()) { indexClause.addToExpressions( new IndexExpression( ByteBufferUtil.bytes(keyName), IndexOperator.EQ, ByteBufferUtil.bytes(query.getEqStmt().get(keyName)))); } List<KeySlice> rows = getConnection(keyspace) .get_indexed_slices(parent, indexClause, predicate, ConsistencyLevel.QUORUM); return JsonMarshaller.marshallRows(rows, true); }
@PooledConnection public JSONObject getSlice( String keyspace, String columnFamily, String key, ConsistencyLevel consistencyLevel) throws InvalidRequestException, UnavailableException, TimedOutException, TException, UnsupportedEncodingException { SlicePredicate predicate = new SlicePredicate(); SliceRange range = new SliceRange(ByteBufferUtil.bytes(""), ByteBufferUtil.bytes(""), false, MAX_COLUMNS); predicate.setSlice_range(range); ColumnParent parent = new ColumnParent(columnFamily); List<ColumnOrSuperColumn> slice = getConnection(keyspace) .get_slice(ByteBufferUtil.bytes(key), parent, predicate, consistencyLevel); if (slice.size() > 0) return JsonMarshaller.marshallSlice(slice); else return null; }
@PooledConnection public JSONArray getRows( String keyspace, String columnFamily, String queryStr, ConsistencyLevel consistencyLevel) throws InvalidRequestException, UnavailableException, TimedOutException, TException, CharacterCodingException { if (StringUtils.isNotBlank(queryStr)) { return getRowsWithQuery(keyspace, columnFamily, queryStr, consistencyLevel); } SlicePredicate predicate = new SlicePredicate(); SliceRange range = new SliceRange(ByteBufferUtil.bytes(""), ByteBufferUtil.bytes(""), false, MAX_COLUMNS); predicate.setSlice_range(range); KeyRange keyRange = new KeyRange(MAX_ROWS); keyRange.setStart_key(ByteBufferUtil.bytes("")); keyRange.setEnd_key(ByteBufferUtil.EMPTY_BYTE_BUFFER); ColumnParent parent = new ColumnParent(columnFamily); List<KeySlice> rows = getConnection(keyspace).get_range_slices(parent, predicate, keyRange, consistencyLevel); return JsonMarshaller.marshallRows(rows, true); }
@PooledConnection public JSONArray getKeyspaces() throws InvalidRequestException, TException, UnsupportedEncodingException { List<KsDef> keyspaces = getConnection(null).describe_keyspaces(); return JsonMarshaller.marshallKeyspaces(keyspaces, true); }