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.api; 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 if repository exception occurred 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 */ 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}