isTip
versionId
consistentId
firstEntityInChain
public class ImmutableDatastoreEntity {@IdLong versionId;@ParentKey<T> firstEntityInChain;protected Long consistentId;protected boolean isTip;Key<User> savedByUser;}
ImmutableDatastoreEntity entity = new ImmutableDatastoreEntity();entity.setVersionId(DAO.allocateId(this.getClass()));entity.setConsistentId(entity.getVersionId());entity.setFirstEntityInChain((Key<T>) Key.create(entity.getClass(), entity.versionId));entity.setTip(true);
// start transactionImmutableDatastoreEntity oldVersion = getImmutableEntity(immutableId)oldVersion.setTip(false);ImmutableDatastoreEntity newVersion = oldVersion.clone();// make the user edits needednewVersion.setVersionId(null);newVersion.setConsistentId(this.getConsistentId());newVersion.setFirstEntityInChain(oldVersion.getFirstEntityInChain());// .clone also performs the last two lines but just to be explicit this, just fyinewVersion.setTip(true);ofy().save(oldVersion, newVersion).now();// end transaction
Key ancestorKey = KeyFactory.createKey(ImmutableDatastoreEntity.class, consistentId);ImmutableDatastoreEntity e = ofy().load().kind(ImmutableDatastoreEntity.class).filter("consistentId", consistentId).filter("isTip", true).ancestor(ancestorKey) // this limits our query to just the 1 entity group.list() .first();
// wrap block in transactionImmutableDatastoreEntity oldVersion = getImmutableEntity(immutableId);oldVersion.setTip(false);ofy().save(oldVersion, newVersion).now();
List<ImmutableDatastoreEntity> results = ofy().load().kind(ImmutableDatastoreEntity.class).filter("isTip", true).filter(/** apply other filters here */) .list();
Key ancestorKey = KeyFactory.createKey(ImmutableDatastoreEntity.class, consistentId);List<ImmutableDatastoreEntity> versions = ofy().load().kind(ImmutableDatastoreEntity.class).filter("consistentId", consistentId).ancestor(ancestorKey) .list();
Use promo code NEXT1720 to save $300 off general admission
No comments :
Post a Comment