src/applications/h2/src/main/org/h2/mvstore/db/TransactionStore.java
/**
         * Try to set or remove the value. When updating only unchanged entries,
         * then the value is only changed if it was not changed after opening
         * the map.
         *
         * @param key the key
         * @param value the new value (null to remove the value)
         * @param onlyIfUnchanged only set the value if it was not changed (by
         *            this or another transaction) since the map was opened
         * @return true if the value was set, false if there was a concurrent
         *         update
         */
Try to set or remove the value. When updating only unchanged entries,
then the value is only changed if it was not changed after opening
the map.

@param key the key
@param value the new value (null to remove the value)
@param onlyIfUnchanged only set the value if it was not changed (by
this or another transaction) since the map was opened
@return true if the value was set, false if there was a concurrent
update
Try to set or remove the value . When updating only unchanged entries then the value is only changed if it was not changed after opening the map . @param key the key @param value the new value ( null to remove the value ) @param onlyIfUnchanged only set the value if it was not changed ( by this or another transaction ) since the map was opened @return true if the value was set false if there was a concurrent update
public boolean trySet(K key, V value, boolean onlyIfUnchanged) {
            VersionedValue current = map.get(key);
            if (onlyIfUnchanged) {
                VersionedValue old = getValue(key, readLogId);
                if (!map.areValuesEqual(old, current)) {
                    long tx = getTransactionId(current.operationId);
                    if (tx == transaction.transactionId) {
                        if (value == null) {
                            return true;
                        } else if (current.value == null) {
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                }
            }
            VersionedValue newValue = new VersionedValue();
            newValue.operationId = getOperationId(
                    transaction.transactionId, transaction.logId);
            newValue.value = value;
            if (current == null) {
                transaction.log(mapId, key, current);
                VersionedValue old = map.putIfAbsent(key, newValue);
                if (old != null) {
                    transaction.logUndo();
                    return false;
                }
                return true;
            }
            long id = current.operationId;
            if (id == 0) {
                transaction.log(mapId, key, current);
                if (!map.replace(key, current, newValue)) {
                    transaction.logUndo();
                    return false;
                }
                return true;
            }
            int tx = getTransactionId(current.operationId);
            if (tx == transaction.transactionId) {
                transaction.log(mapId, key, current);
                if (!map.replace(key, current, newValue)) {
                    transaction.logUndo();
                    return false;
                }
                return true;
            }
            return false;
        }
public boolean trySet ( K key , V value , boolean onlyIfUnchanged ) { VersionedValue current = map . get ( key ) ; if ( onlyIfUnchanged ) { VersionedValue old = getValue ( key , readLogId ) ; if ( ! map . areValuesEqual ( old , current ) ) { long tx = getTransactionId ( current . operationId ) ; if ( tx == transaction . transactionId ) { if ( value == null ) { return true ; } else if ( current . value == null ) { } else { return false ; } } else { return false ; } } } VersionedValue newValue = new VersionedValue ( ) ; newValue . operationId = getOperationId ( transaction . transactionId , transaction . logId ) ; newValue . value = value ; if ( current == null ) { transaction . log ( mapId , key , current ) ; VersionedValue old = map . putIfAbsent ( key , newValue ) ; if ( old != null ) { transaction . logUndo ( ) ; return false ; } return true ; } long id = current . operationId ; if ( id == 0 ) { transaction . log ( mapId , key , current ) ; if ( ! map . replace ( key , current , newValue ) ) { transaction . logUndo ( ) ; return false ; } return true ; } int tx = getTransactionId ( current . operationId ) ; if ( tx == transaction . transactionId ) { transaction . log ( mapId , key , current ) ; if ( ! map . replace ( key , current , newValue ) ) { transaction . logUndo ( ) ; return false ; } return true ; } return false ; }
Try to set or remove the value.
Try to set or remove the value .
// ignore removing an entry // if it was added or changed // in the same statement // add an entry that was removed // in the same statement // a new value // committed // the transaction is committed: // overwrite the value // somebody else was faster // added or updated by this transaction // strange, somebody overwrote the value // even though the change was not committed // the transaction is not yet committed