@PooledConnection public void setColumn( String keyspace, String column_family, String key, JSONObject json, ConsistencyLevel consistency_level, boolean index, long timestamp) throws InvalidRequestException, UnavailableException, TimedOutException, TException, HttpException, IOException { List<Mutation> slice = new ArrayList<Mutation>(); for (Object field : json.keySet()) { String name = (String) field; String value = (String) json.get(name); Column c = new Column(); c.setName(ByteBufferUtil.bytes(name)); c.setValue(ByteBufferUtil.bytes(value)); c.setTimestamp(timestamp); Mutation m = new Mutation(); ColumnOrSuperColumn cc = new ColumnOrSuperColumn(); cc.setColumn(c); m.setColumn_or_supercolumn(cc); slice.add(m); } Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>(); Map<String, List<Mutation>> cfMutations = new HashMap<String, List<Mutation>>(); cfMutations.put(column_family, slice); mutationMap.put(ByteBufferUtil.bytes(key), cfMutations); getConnection(keyspace).batch_mutate(mutationMap, consistency_level); if (config.isIndexingEnabled() && index) indexer.index(column_family, key, json); }
@PooledConnection public void deleteColumn( String keyspace, String column_family, String key, String column, ConsistencyLevel consistency_level, boolean purgeIndex) throws InvalidRequestException, UnavailableException, TimedOutException, TException, HttpException, IOException { ColumnPath path = new ColumnPath(column_family); path.setColumn(ByteBufferUtil.bytes(column)); getConnection(keyspace) .remove( ByteBufferUtil.bytes(key), path, System.currentTimeMillis() * 1000, consistency_level); // TODO: Revisit deleting a single field because it requires a fetch // first. // Evidently it is impossible to remove just a field from a document in // SOLR // http://stackoverflow.com/questions/4802620/can-you-delete-a-field-from-a-document-in-solr-index if (config.isIndexingEnabled() && purgeIndex) { indexer.delete(column_family, key); JSONObject json = this.getSlice(keyspace, column_family, key, consistency_level); json.remove(column); indexer.index(column_family, key, json); } }
@SuppressWarnings("unchecked") @PooledConnection public void addColumn( String keyspace, String column_family, String rowkey, String column_name, String value, ConsistencyLevel consistency_level, boolean index) throws InvalidRequestException, UnavailableException, TimedOutException, TException, HttpException, IOException { JSONObject json = new JSONObject(); json.put(column_name, value); this.setColumn(keyspace, column_family, rowkey, json, consistency_level, index); // TODO: Revisit adding a single field because it requires a fetch // first. if (this.config.isIndexingEnabled() && index) { JSONObject indexJson = this.getSlice(keyspace, column_family, rowkey, consistency_level); indexJson.put(column_name, value); indexer.index(column_family, rowkey, indexJson); } }