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