@Override public HashedVersion getEndVersion() { // Search the max of delta.getTransformedDelta().getResultingVersion() DBObject query = createWaveletDBQuery(); DBObject sort = new BasicDBObject(); sort.put(MongoDbDeltaStoreUtil.FIELD_TRANSFORMED_RESULTINGVERSION_VERSION, -1); // Descending DBObject field = new BasicDBObject(); field.put(MongoDbDeltaStoreUtil.FIELD_TRANSFORMED_RESULTINGVERSION, 1); DBObject result = deltaDbCollection.findOne(query, field, sort); return result != null ? MongoDbDeltaStoreUtil .deserializeHashedVersion((DBObject) ((DBObject) result .get(MongoDbDeltaStoreUtil.FIELD_TRANSFORMED)) .get(MongoDbDeltaStoreUtil.FIELD_RESULTINGVERSION)) : null; }
@Override public HashedVersion getAppliedAtVersion(long version) throws IOException { DBObject query = createWaveletDBQuery(); query.put(MongoDbDeltaStoreUtil.FIELD_TRANSFORMED_APPLIEDATVERSION, version); DBObject result = deltaDbCollection.findOne(query); if (result != null) return MongoDbDeltaStoreUtil.deserializeHashedVersion((DBObject) result .get(MongoDbDeltaStoreUtil.FIELD_APPLIEDATVERSION)); return null; }
@Override public HashedVersion getResultingVersion(long version) throws IOException { DBObject query = createWaveletDBQuery(); query.put(MongoDbDeltaStoreUtil.FIELD_TRANSFORMED_APPLIEDATVERSION, version); DBObject result = deltaDbCollection.findOne(query); if (result != null) return MongoDbDeltaStoreUtil.deserializeHashedVersion((DBObject) result .get(MongoDbDeltaStoreUtil.FIELD_TRANSFORMED_RESULTINGVERSION)); return null; }
public static WaveletDeltaRecord deserializeWaveletDeltaRecord(DBObject dbObject) throws PersistenceException { try { return new WaveletDeltaRecord( deserializeHashedVersion((DBObject) dbObject.get(FIELD_APPLIEDATVERSION)), ByteStringMessage.parseProtocolAppliedWaveletDelta(ByteString.copyFrom((byte[]) dbObject .get(FIELD_APPLIED))), deserializeTransformedWaveletDelta((DBObject) dbObject.get(FIELD_TRANSFORMED))); } catch (InvalidProtocolBufferException e) { throw new PersistenceException(e); } }
public static TransformedWaveletDelta deserializeTransformedWaveletDelta(DBObject dbObject) throws PersistenceException { ParticipantId author = deserializeParicipantId((DBObject) dbObject.get(FIELD_AUTHOR)); HashedVersion resultingVersion = deserializeHashedVersion((DBObject) dbObject.get(FIELD_RESULTINGVERSION)); long applicationTimestamp = (Long) dbObject.get(FIELD_APPLICATIONTIMESTAMP); BasicDBList dbOps = (BasicDBList) dbObject.get(FIELD_OPS); ImmutableList.Builder<WaveletOperation> operations = ImmutableList.builder(); int numOperations = dbOps.size(); // Code analog to ProtoDeltaStoreDataSerializer.deserialize for (int i = 0; i < numOperations; i++) { WaveletOperationContext context; if (i == numOperations - 1) { context = new WaveletOperationContext(author, applicationTimestamp, 1, resultingVersion); } else { context = new WaveletOperationContext(author, applicationTimestamp, 1); } operations.add(deserializeWaveletOperation((DBObject) dbOps.get(i), context)); } return new TransformedWaveletDelta(author, resultingVersion, applicationTimestamp, operations.build()); }