001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.kernel.services;
017
018import javax.jcr.Session;
019
020import org.fcrepo.kernel.Transaction;
021import org.fcrepo.kernel.exception.TransactionMissingException;
022
023/**
024 * @author bbpennel
025 * @since Feb 20, 2014
026 */
027public interface TransactionService {
028
029    /**
030     * Check for expired transactions and remove them
031     */
032    void removeAndRollbackExpired();
033
034    /**
035     * Create a new Transaction and add it to the currently open ones
036     *
037     * @param sess The session to use for this Transaction
038     * @return the {@link Transaction}
039     */
040    Transaction beginTransaction(Session sess, String userName);
041
042    /**
043     * Receive an open {@link Transaction} for a given user
044     *
045     * @param txId the Id of the {@link Transaction}
046     * @param userName the name  of the {@link java.security.Principal}
047     * @return the {@link Transaction}
048     * @throws TransactionMissingException if the transaction could not be found or is not associated
049     * with this user
050     */
051    Transaction getTransaction(final String txId, final String userName) throws TransactionMissingException;
052
053    /**
054     * Get the current Transaction for a session
055     *
056     * @param session
057     * @return transaction
058     * @throws TransactionMissingException
059     */
060    Transaction getTransaction(Session session) throws TransactionMissingException;
061
062    /**
063     * Check if a Transaction exists
064     *
065     * @param txid the Id of the {@link Transaction}
066     * @return the {@link Transaction}
067     */
068    boolean exists(String txid);
069
070    /**
071     * Commit a {@link Transaction} with the given id
072     *
073     * @param txid the id of the {@link Transaction}
074     */
075    Transaction commit(String txid);
076
077    /**
078     * Roll a {@link Transaction} back
079     *
080     * @param txid the id of the {@link Transaction}
081     * @return the {@link Transaction} object
082     */
083    Transaction rollback(String txid);
084
085}