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;
021
022/**
023 * @author bbpennel
024 * @since Feb 20, 2014
025 */
026public interface TransactionService {
027
028    /**
029     * Check for expired transactions and remove them
030     */
031    void removeAndRollbackExpired();
032
033    /**
034     * Create a new Transaction and add it to the currently open ones
035     *
036     * @param sess The session to use for this Transaction
037     * @param userName the user name
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     * with this user
049     */
050    Transaction getTransaction(final String txId, final String userName);
051
052    /**
053     * Get the current Transaction for a session
054     *
055     * @param session the session
056     * @return transaction
057     */
058    Transaction getTransaction(Session session);
059
060    /**
061     * Check if a Transaction exists
062     *
063     * @param txid the Id of the {@link Transaction}
064     * @return the {@link Transaction}
065     */
066    boolean exists(String txid);
067
068    /**
069     * Commit a {@link Transaction} with the given id
070     *
071     * @param txid the id of the {@link Transaction}
072     * @return transaction
073     */
074    Transaction commit(String txid);
075
076    /**
077     * Roll a {@link Transaction} back
078     *
079     * @param txid the id of the {@link Transaction}
080     * @return the {@link Transaction} object
081     */
082    Transaction rollback(String txid);
083
084}