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