public void updateTraffic(DateTime observationTime, NodeId nodeId, long inLastMinute, long outLastMinute, long decodedLastMinute) { // we bucket our database by days final DateTime dayBucket = getDayBucket(observationTime); if (LOG.isDebugEnabled()) { LOG.debug("Updating traffic for node {} at {}: in/decoded/out {}/{}/{} bytes", nodeId.toString(), dayBucket, inLastMinute, decodedLastMinute, outLastMinute); } final WriteResult<TrafficDto, ObjectId> update = db.update(DBQuery.is("bucket", dayBucket), // sigh DBUpdate.inc only takes integers, but we have a long. new DBUpdate.Builder() .addOperation("$inc", "input." + nodeId.toString(), new SingleUpdateOperationValue(false, false, inLastMinute)) .addOperation("$inc", "output." + nodeId.toString(), new SingleUpdateOperationValue(false, false, outLastMinute)) .addOperation("$inc", "decoded." + nodeId.toString(), new SingleUpdateOperationValue(false, false, decodedLastMinute)), true, false); if (update.getN() == 0) { LOG.warn("Unable to update traffic of node {}: {}", nodeId, update); } }
@Override public Output update(String id, Map<String, Object> deltas) { DBUpdate.Builder update = new DBUpdate.Builder(); for (Map.Entry<String, Object> fields : deltas.entrySet()) update = update.set(fields.getKey(), fields.getValue()); return coll.findAndModify(DBQuery.is(OutputImpl.FIELD_ID, id), null, null, false, update, true, false); }
/** * Perform two bit operations on the given field * * @param field * The field to perform the operations on * @param operation1 * The first operation to perform * @param value1 * The first value * @param operation2 * The second operation to perform * @param value2 * The second value * @return this object */ public Builder bit(String field, String operation1, int value1, String operation2, int value2) { return addOperation("$bit", field, new ComplexUpdateOperationValue(new BasicDBObject( operation1, value1).append(operation2, value2))); }
public void updateTraffic(DateTime observationTime, NodeId nodeId, long inLastMinute, long outLastMinute, long decodedLastMinute) { // we bucket our database by days final DateTime dayBucket = getDayBucket(observationTime); if (LOG.isDebugEnabled()) { LOG.debug("Updating traffic for node {} at {}: in/decoded/out {}/{}/{} bytes", nodeId.toString(), dayBucket, inLastMinute, decodedLastMinute, outLastMinute); } final WriteResult<TrafficDto, ObjectId> update = db.update(DBQuery.is("bucket", dayBucket), // sigh DBUpdate.inc only takes integers, but we have a long. new DBUpdate.Builder() .addOperation("$inc", "input." + nodeId.toString(), new SingleUpdateOperationValue(false, false, inLastMinute)) .addOperation("$inc", "output." + nodeId.toString(), new SingleUpdateOperationValue(false, false, outLastMinute)) .addOperation("$inc", "decoded." + nodeId.toString(), new SingleUpdateOperationValue(false, false, decodedLastMinute)), true, false); if (update.getN() == 0) { LOG.warn("Unable to update traffic of node {}: {}", nodeId, update); } }
/** * Add a raw operation. This may be useful in case of MongoDB adding new * features that aren't yet available through this interface, or if * something has been left out. Note that no serialisation will be * attempted of the values. * * @param op * The operation * @param field * The field to set the value on * @param value * The value to set * @return this object */ public Builder addRawOperation(String op, String field, Object value) { return addOperation(op, field, new SingleUpdateOperationValue( false, false, value)); }
/** * Perform two bit operations on the given field * * @param field * The field to perform the operations on * @param operation1 * The first operation to perform * @param value1 * The first value * @param operation2 * The second operation to perform * @param value2 * The second value * @return this object */ public static Builder bit(String field, String operation1, int value1, String operation2, int value2) { return new Builder().bit(field, operation1, value1, operation2, value2); }
/** * Perform a bit operation on the given field * * @param field * The field to perform the operation on * @param operation * The operation to perform * @param value * The value * @return this object */ public Builder bit(String field, String operation, int value) { return addOperation("$bit", field, new ComplexUpdateOperationValue( new BasicDBObject(operation, value))); }
/** * Add the given value to the array value if it doesn't already exist in * the specified field atomically * * @param field * The field to add the value to * @param value * The value to add * @return this object */ public Builder addToSet(String field, Object value) { return addOperation("$addToSet", field, new SingleUpdateOperationValue(true, true, value)); }
/** * Add all of the given values to the array value at the specified field * atomically * * @param field * The field to add the values to * @param values * The values to add * @return this object */ public Builder pushAll(String field, Object... values) { return addOperation("$push", field, new MultiUpdateOperationValue(true, true, values)); }
/** * Add the given value to the array value at the specified field * atomically * * @param field * The field to add the value to * @param value * The value to add * @return this object */ public Builder push(String field, Object value) { return addOperation("$push", field, new SingleUpdateOperationValue( true, true, value)); }
/** * Set the given field (can be multiple levels deep) to the given value * atomically * * @param field * The field to set * @param value * The value to set it to * @return this object */ public Builder set(String field, Object value) { return addOperation("$set", field, new SingleUpdateOperationValue( false, true, value)); }
/** * Remove all occurances of the values from the array at field * * @param field * The field to remove the values from * @param values * The values to remove * @return this object */ public Builder pullAll(String field, Object... values) { return addOperation("$pullAll", field, new MultiUpdateOperationValue(true, true, values)); }
/** * Increment the given field atomically by the given value * * @param field * The field to increment * @param by * The value to increment by * @return this object */ public Builder inc(String field, int by) { return addOperation("$inc", field, new SingleUpdateOperationValue( false, false, by)); }
/** * Add the given values to the array value if they don't already exist * in the specified field atomically * * @param field * The field to add the values to * @param values * The values to add * @return this object */ public Builder addToSet(String field, Object... values) { return addOperation("$addToSet", field, new MultiUpdateOperationValue(true, true, values)); }
/** * Remove all occurances of the values from the array at field * * @param field * The field to remove the values from * @param values * The values to remove * @return this object */ public Builder pullAll(String field, List<?> values) { return addOperation("$pullAll", field, new MultiUpdateOperationValue(true, true, values)); }
/** * Remove all occurances of value from the array at field * * @param field * The field to remove the value from * @param value * The value to remove. This may be another query. * @return this object */ public Builder pull(String field, Object value) { return addOperation("$pull", field, new SingleUpdateOperationValue( true, true, value)); }
/** * Add all of the given values to the array value at the specified field * atomically * * @param field * The field to add the values to * @param values * The values to add * @return this object */ public static Builder pushAll(String field, List<?> values) { return new Builder().pushAll(field, values); }
/** * Add the given values to the array value if they don't already exist in * the specified field atomically * * @param field * The field to add the values to * @param values * The values to add * @return this object */ public static Builder addToSet(String field, List<?> values) { return new Builder().addToSet(field, values); }
/** * Add the given values to the array value if they don't already exist in * the specified field atomically * * @param field * The field to add the values to * @param values * The values to add * @return this object */ public static Builder addToSet(String field, Object... values) { return new Builder().addToSet(field, values); }
/** * Add the given value to the array value if it doesn't already exist in the * specified field atomically * * @param field * The field to add the value to * @param value * The value to add * @return this object */ public static Builder addToSet(String field, Object value) { return new Builder().addToSet(field, value); }