use of com.google.nigori.common.RevValue in project nigori by ucam-cl-dtg.
the class AppEngineDatabase method getRecord.
@Override
public Collection<RevValue> getRecord(User user, byte[] index) throws IOException {
PersistenceManager pm = pmfInstance.getPersistenceManager();
try {
// TODO(drt24): cleanup this method
Key lookupKey = getLookupKey(user, index);
// If this doesn't exist there is no key so null gets returned by JDOObjectNotFoundException
Lookup lookup = pm.getObjectById(Lookup.class, lookupKey);
List<RevValue> answer = new ArrayList<RevValue>();
Query getRevisionValues = new Query(AppEngineRecord.class.getSimpleName());
getRevisionValues.setAncestor(lookupKey);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
List<Entity> results = datastore.prepare(getRevisionValues).asList(FetchOptions.Builder.withDefaults());
for (Entity result : results) {
ByteArrayInputStream bais = new ByteArrayInputStream(((Blob) result.getProperty("revision")).getBytes());
ObjectInputStream ndis = new ObjectInputStream(bais);
answer.add(new RevValue(((Revision) ndis.readObject()).getBytes(), ((Blob) result.getProperty("value")).getBytes()));
}
if (lookup != null) {
return answer;
} else {
return null;
}
} catch (JDOObjectNotFoundException e) {
return null;
} catch (ClassNotFoundException e) {
throw new IOException(e);
} finally {
pm.close();
}
}
use of com.google.nigori.common.RevValue in project nigori by ucam-cl-dtg.
the class ComparableMergerTest method mergeTwoEquivOneGreater.
@Test
public void mergeTwoEquivOneGreater() throws IOException, NigoriCryptographyException, UnauthorisedException {
Collection<RevValue> heads = new ArrayList<RevValue>();
byte[] test = MessageLibrary.toBytes("test");
byte[] test1 = MessageLibrary.toBytes("test1");
RevValue rv = new RevValue(Revision.EMPTY, test);
RevValue rv1 = new RevValue(Revision.EMPTY, test);
RevValue rv2 = new RevValue(Revision.EMPTY, test1);
heads.add(rv);
heads.add(rv1);
heads.add(rv2);
MigoriDatastore store = createMock(MigoriDatastore.class);
expect(store.put(eq(INDEX), aryEq(test), eq(rv), eq(rv1))).andReturn(rv);
expect(store.put(eq(INDEX), aryEq(test1), eq(rv), eq(rv2))).andReturn(rv2);
replay(store);
RevValue value = merger.merge(store, INDEX, heads);
verify(store);
assertEquals(rv2, value);
}
use of com.google.nigori.common.RevValue in project nigori by ucam-cl-dtg.
the class ComparableMergerTest method mergeTwoDiff.
@Test
public void mergeTwoDiff() throws IOException, NigoriCryptographyException, UnauthorisedException {
Collection<RevValue> heads = new ArrayList<RevValue>();
byte[] test = MessageLibrary.toBytes("test");
byte[] test1 = MessageLibrary.toBytes("test1");
RevValue rv = new RevValue(Revision.EMPTY, test);
RevValue rv1 = new RevValue(Revision.EMPTY, test1);
heads.add(rv);
heads.add(rv1);
MigoriDatastore store = createMock(MigoriDatastore.class);
expect(store.put(eq(INDEX), aryEq(test1), eq(rv), eq(rv1))).andReturn(rv1);
replay(store);
RevValue value = merger.merge(store, INDEX, heads);
verify(store);
assertEquals(rv1, value);
}
Aggregations