use of com.google.apphosting.datastore.DatastoreV3Pb.Transaction in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method toProto1.
static Transaction toProto1(com.google.apphosting.datastore.proto2api.DatastoreV3Pb.Transaction txn) {
Transaction txnProto = new Transaction();
txnProto.mergeFrom(txn.toByteArray());
return txnProto;
}
use of com.google.apphosting.datastore.DatastoreV3Pb.Transaction in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method beginTransaction.
// status
@SuppressWarnings("unused")
public Transaction beginTransaction(Status status, BeginTransactionRequest req) {
Profile profile = getOrCreateProfile(req.getApp());
if (req.hasPreviousTransaction()) {
if (req.getModeEnum() == TransactionMode.READ_ONLY) {
throw newError(ErrorCode.BAD_REQUEST, TRANSACTION_RETRY_ON_READ_ONLY);
}
// synchronize to prevent check-remove race on previous transaction
synchronized (profile) {
LiveTxn previousTransaction = profile.getTxnQuietly(req.getPreviousTransaction().getHandle());
if (previousTransaction != null) {
if (previousTransaction.concurrencyMode == ConcurrencyMode.READ_ONLY) {
throw newError(ErrorCode.BAD_REQUEST, TRANSACTION_RETRY_ON_PREVIOUSLY_READ_ONLY);
}
if (previousTransaction.allowMultipleEg != req.isAllowMultipleEg()) {
throw newError(ErrorCode.BAD_REQUEST, TRANSACTION_OPTIONS_CHANGED_ON_RESET);
}
profile.removeTxn(req.getPreviousTransaction().getHandle());
}
}
}
Transaction txn = new Transaction().setApp(req.getApp()).setHandle(transactionHandleProvider.getAndIncrement());
ConcurrencyMode mode = toConcurrencyMode(req.getModeEnum());
profile.addTxn(txn.getHandle(), new LiveTxn(clock, req.isAllowMultipleEg(), req.getModeEnum()));
return txn;
}
use of com.google.apphosting.datastore.DatastoreV3Pb.Transaction in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method addActionsImpl.
// status
@SuppressWarnings("unused")
private void addActionsImpl(Status status, TaskQueueBulkAddRequest request) {
if (request.getAddRequestCount() == 0) {
return;
}
// The transactional tasks need to be associated with the txn.
// When the txn is committed the tasks will be sent back over to
// the taskqueue stub. We need to wipe out their transactions before sending
// so that the tasks actually get added and we don't continue spinning
// around in and infinite loop.
List<TaskQueueAddRequest> addRequests = new ArrayList<>(request.getAddRequestCount());
for (TaskQueueAddRequest addRequest : request.getAddRequestList()) {
addRequests.add(addRequest.toBuilder().clearTransaction().clearDatastoreTransaction().build());
}
Transaction transaction;
if (request.getAddRequestList().get(0).hasDatastoreTransaction()) {
ByteString datastoreTransaction = request.getAddRequestList().get(0).getDatastoreTransaction();
try {
transaction = Transaction.parser().parseFrom(datastoreTransaction);
} catch (InvalidProtocolBufferException e) {
throw newError(ErrorCode.BAD_REQUEST, "Invalid transaction");
}
} else {
transaction = toProto1(request.getAddRequest(0).getTransaction());
}
Profile profile = profiles.get(transaction.getApp());
LiveTxn liveTxn = profile.getTxn(transaction.getHandle());
liveTxn.addActions(addRequests);
}
Aggregations