@Override protected void setValue(EntityValue from, com.google.datastore.v1.Value.Builder to) { to.setEntityValue(from.get().toPb()); } };
protected List<com.google.datastore.v1.Mutation> toMutationPbList() { List<com.google.datastore.v1.Mutation> mutationsPb = new ArrayList<>(); for (FullEntity<IncompleteKey> entity : toAddAutoId()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setInsert(entity.toPb()).build()); } for (FullEntity<Key> entity : toAdd().values()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setInsert(entity.toPb()).build()); } for (FullEntity<Key> entity : toUpdate().values()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build()); } for (FullEntity<Key> entity : toPut().values()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); } for (Key key : toDelete()) { mutationsPb.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(key.toPb()).build()); } return mutationsPb; }
com.google.datastore.v1.Mutation.newBuilder().setInsert(entity.toPb()).build());
} else { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@Test public void testPutWithDeferredAllocation() throws Exception { List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>(); pbs.add( com.google.datastore.v1.Mutation.newBuilder() .setInsert(INCOMPLETE_ENTITY_1.toPb()) .build()); pbs.add( com.google.datastore.v1.Mutation.newBuilder() .setInsert(INCOMPLETE_ENTITY_2.toPb()) .build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build()); batchWriter.put(ENTITY1); batchWriter.putWithDeferredIdAllocation(INCOMPLETE_ENTITY_1, INCOMPLETE_ENTITY_2); assertEquals(pbs, batchWriter.toMutationPbList()); }
@Test public void testAddWithDeferredAllocation() throws Exception { List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>(); pbs.add( com.google.datastore.v1.Mutation.newBuilder() .setInsert(INCOMPLETE_ENTITY_1.toPb()) .build()); pbs.add( com.google.datastore.v1.Mutation.newBuilder() .setInsert(INCOMPLETE_ENTITY_2.toPb()) .build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setInsert(ENTITY1.toPb()).build()); batchWriter.addWithDeferredIdAllocation(ENTITY1, INCOMPLETE_ENTITY_1); batchWriter.addWithDeferredIdAllocation(INCOMPLETE_ENTITY_2); assertEquals(pbs, batchWriter.toMutationPbList()); }
@Test public void testDeleteAfterAdd() throws Exception { List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>(); pbs.add( com.google.datastore.v1.Mutation.newBuilder() .setInsert(INCOMPLETE_ENTITY_1.toPb()) .build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(KEY1.toPb()).build()); batchWriter.add(ENTITY1); batchWriter.addWithDeferredIdAllocation(INCOMPLETE_ENTITY_1); batchWriter.delete(KEY1); assertEquals(pbs, batchWriter.toMutationPbList()); }
@Override protected void setValue(EntityValue from, com.google.datastore.v1.Value.Builder to) { to.setEntityValue(from.get().toPb()); } };
protected List<com.google.datastore.v1.Mutation> toMutationPbList() { List<com.google.datastore.v1.Mutation> mutationsPb = new ArrayList<>(); for (FullEntity<IncompleteKey> entity : toAddAutoId()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setInsert(entity.toPb()).build()); } for (FullEntity<Key> entity : toAdd().values()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setInsert(entity.toPb()).build()); } for (FullEntity<Key> entity : toUpdate().values()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build()); } for (FullEntity<Key> entity : toPut().values()) { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); } for (Key key : toDelete()) { mutationsPb.add(com.google.datastore.v1.Mutation.newBuilder().setDelete(key.toPb()).build()); } return mutationsPb; }
com.google.datastore.v1.Mutation.newBuilder().setInsert(entity.toPb()).build());
} else { mutationsPb.add( com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());