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;
017
018import java.util.Date;
019
020import javax.jcr.RepositoryException;
021import javax.jcr.Session;
022
023/**
024 * @author bbpennel
025 * @since Feb 18, 2014
026 */
027public interface Transaction {
028
029    public static enum State {
030        DIRTY, NEW, COMMITED, ROLLED_BACK
031    }
032
033    /**
034     * Get the transaction-aware session
035     * @return transaction-aware session
036     */
037    Session getSession();
038
039    /**
040     * Get the date this transaction was created
041     * @return creation date
042     */
043    Date getCreated();
044
045    /**
046     * Get the transaction identifier
047     * @return transaction id
048     */
049    String getId();
050
051    /**
052     * Get the state of this transaction
053     * @return transaction state
054     * @throws RepositoryException
055     */
056    State getState() throws RepositoryException;
057
058    /**
059     * Get the Date when this transaction is expired and can be
060     * garbage-collected
061     * @return transaction expiration date
062     */
063    Date getExpires();
064
065    /**
066     * "Commit" the transaction by saving the backing-session
067     * @throws RepositoryException
068     */
069    void commit();
070
071    /**
072     * End the session, and mark for reaping
073     */
074    void expire();
075
076    /**
077     * Checks if this transaction is associated with a specific user.
078     * If username is null, it is assumed that the transaction is
079     * anonymous and thus not bound to any user.
080     * @param userName the user
081     * @return true if the userName is associated with this transaction
082     */
083    public boolean isAssociatedWithUser(final String userName);
084
085    /**
086     * Discard all unpersisted changes and expire
087     * @throws RepositoryException
088     */
089    void rollback();
090
091    /**
092     * Roll forward the expiration date for recent activity
093     */
094    void updateExpiryDate();
095
096}