All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.transaction.AbstractTransaction Maven / Gradle / Ivy

Go to download

Library for use in Java components of Vespa. Shared code which do not fit anywhere else.

There is a newer version: 8.409.18
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.transaction;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * A convenience base transaction class for multi-operation transactions
 * which maintains the ordered list of operations to commit and provides a default
 * implementation of rollbackOrLog which logs a SEVERE message.
 * 
 * @author bratseth
 */
public abstract class AbstractTransaction implements Transaction {

    private static final Logger log = Logger.getLogger(AbstractTransaction.class.getName());
    private final List operations = new ArrayList<>();

    protected AbstractTransaction() { }

    @Override
    public Transaction add(Operation operation) {
        this.operations.add(operation);
        return this;
    }

    @Override
    public Transaction add(List operations) {
        this.operations.addAll(operations);
        return this;
    }

    @Override
    public List operations() { return operations; }

    /** Default implementations which logs a severe message. Operations should implement toString to use this. */
    @Override
    public void rollbackOrLog() {
        log.severe("The following operations were incorrectly committed and probably require " +
                   "manual correction: " + operations());
    }

    /** Default implementation which only clears operations */
    @Override
    public void close() {
        operations.clear();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy