List<Blob> putList = new ArrayList<Blob>();
List<Key> deleteList = new ArrayList<Key>();
for (Key key : journalMap.keySet()) {
Entity targetEntity = journalMap.get(key);
boolean put = targetEntity != null;
EntityProto targetProto =
put ? EntityTranslator.convertToPb(targetEntity) : null;
int size = put ? targetProto.encodingSize() : 0;
if (totalSize != 0
&& totalSize + size + DatastoreUtil.EXTRA_SIZE > DatastoreUtil.MAX_ENTITY_SIZE) {
entity.setUnindexedProperty(PUT_LIST_PROPERTY, putList);
entity.setUnindexedProperty(DELETE_LIST_PROPERTY, deleteList);
DatastoreUtil.put(ds, null, entity);
entities.add(entity);
entity = createEntity(ds, globalTransactionKey);
putList = new ArrayList<Blob>();
deleteList = new ArrayList<Key>();
totalSize = 0;
}
if (put) {
byte[] content = new byte[targetProto.encodingSize()];
targetProto.outputTo(content, 0);
putList.add(new Blob(content));
} else {
deleteList.add(key);
}
totalSize += size + DatastoreUtil.EXTRA_SIZE;