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