Search in sources :

Example 1 with ConcurrencyMode

use of com.google.appengine.api.datastore.dev.LocalDatastoreService.LiveTxn.ConcurrencyMode 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;
}
Also used : Transaction(com.google.apphosting.datastore.DatastoreV3Pb.Transaction) ConcurrencyMode(com.google.appengine.api.datastore.dev.LocalDatastoreService.LiveTxn.ConcurrencyMode)

Aggregations

ConcurrencyMode (com.google.appengine.api.datastore.dev.LocalDatastoreService.LiveTxn.ConcurrencyMode)1 Transaction (com.google.apphosting.datastore.DatastoreV3Pb.Transaction)1