use of com.google.apphosting.datastore.DatastoreV3Pb.DeleteResponse in project appengine-java-standard by GoogleCloudPlatform.
the class AsyncDatastoreServiceImpl method doBatchDelete.
@Override
protected Future<Void> doBatchDelete(@Nullable Transaction txn, Collection<Key> keys) {
DeleteRequest baseReq = new DeleteRequest();
if (txn != null) {
TransactionImpl.ensureTxnActive(txn);
baseReq.setTransaction(InternalTransactionV3.toProto(txn));
}
// Do not group inside a transaction.
boolean group = !baseReq.hasTransaction();
Iterator<DeleteRequest> batches = deleteBatcher.getBatches(keys, baseReq, baseReq.getSerializedSize(), group);
List<Future<DeleteResponse>> futures = deleteBatcher.makeCalls(batches);
return registerInTransaction(txn, new MultiFuture<DeleteResponse, Void>(futures) {
@Override
public Void get() throws InterruptedException, ExecutionException {
for (Future<DeleteResponse> future : futures) {
future.get();
}
return null;
}
@Override
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
for (Future<DeleteResponse> future : futures) {
future.get(timeout, unit);
}
return null;
}
});
}
use of com.google.apphosting.datastore.DatastoreV3Pb.DeleteResponse in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method deleteImpl.
// status
@SuppressWarnings("unused")
public DeleteResponse deleteImpl(Status status, DeleteRequest request) {
DeleteResponse response = new DeleteResponse();
if (request.keySize() == 0) {
return response;
}
Cost totalCost = response.getMutableCost();
// We don't support requests that span apps, so the app for the first key
// is the app for all keys.
String app = request.keys().get(0).getApp();
final Profile profile = getOrCreateProfile(app);
LiveTxn liveTxn = null;
// Maintain a mapping of keys by entity group so that we can apply one job
// per entity group.
Map<Path, List<Reference>> keysByEntityGroup = new LinkedHashMap<>();
Map<Reference, Long> writtenVersions = new HashMap<>();
synchronized (profile) {
for (final Reference key : request.keys()) {
validatePathComplete(key);
Path group = getGroup(key);
if (request.hasTransaction()) {
if (liveTxn == null) {
liveTxn = profile.getTxn(request.getTransaction().getHandle());
}
checkRequest(!liveTxn.isReadOnly(), "Cannot modify entities in a read-only transaction.");
Profile.EntityGroup eg = profile.getGroup(group);
// this will throw an exception if we attempt to modify
// the wrong entity group
eg.addTransaction(liveTxn).addDeletedEntity(key);
} else {
List<Reference> keysToDelete = keysByEntityGroup.get(group);
if (keysToDelete == null) {
keysToDelete = new ArrayList<>();
keysByEntityGroup.put(group, keysToDelete);
}
keysToDelete.add(key);
}
}
// does all the work for each entity group.
for (final Map.Entry<Path, List<Reference>> entry : keysByEntityGroup.entrySet()) {
Profile.EntityGroup eg = profile.getGroup(entry.getKey());
eg.incrementVersion();
LocalDatastoreJob job = new WriteJob(highRepJobPolicy, eg, profile, Collections.<EntityProto>emptyList(), entry.getValue());
addTo(totalCost, job.calculateJobCost());
eg.addJob(job);
for (Reference deletedKey : entry.getValue()) {
writtenVersions.put(deletedKey, job.getMutationTimestamp(deletedKey));
}
}
}
if (!request.hasTransaction()) {
for (Reference key : request.keys()) {
response.addVersion(writtenVersions.get(key));
}
}
return response;
}
Aggregations