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.time.Duration; 021import java.time.Instant; 022 023/** 024 * The Fedora Transaction abstraction 025 * 026 * @author mohideen 027 */ 028public interface Transaction { 029 030 /** 031 * Commit the transaction 032 */ 033 void commit(); 034 035 /** 036 * Commit the transaction only if the transaction is shortLived 037 */ 038 void commitIfShortLived(); 039 040 /** 041 * @return returns true if this transaction has already been committed 042 */ 043 boolean isCommitted(); 044 045 /** 046 * Rollback the transaction 047 */ 048 void rollback(); 049 050 /** 051 * @return true if this transaction has been rolled back 052 */ 053 boolean isRolledBack(); 054 055 /** 056 * Get the transaction id 057 * 058 * @return the transaction id. 059 */ 060 String getId(); 061 062 /** 063 * Check if the transaction is short-lived. 064 * 065 * @return is the transaction short-lived. 066 */ 067 boolean isShortLived(); 068 069 /** 070 * Set transaction short-lived state. 071 * 072 * @param shortLived boolean true (short-lived) or false (not short-lived) 073 */ 074 void setShortLived(boolean shortLived); 075 076 /** 077 * Expire a transaction 078 */ 079 public void expire(); 080 081 /** 082 * Has the transaction expired? 083 */ 084 public boolean hasExpired(); 085 086 /** 087 * Update the expiry by the provided amount 088 * @param amountToAdd the amount of time to add 089 * @return the new expiration date 090 */ 091 Instant updateExpiry(Duration amountToAdd); 092 093 /** 094 * Get the date this session expires 095 * @return expiration date, if one exists 096 */ 097 Instant getExpires(); 098 099 /** 100 * Refresh the transaction to extend its expiration window. 101 */ 102 void refresh(); 103 104 /** 105 * Sets the baseUri on the transaction 106 * @param baseUri the baseUri of the requests 107 */ 108 void setBaseUri(String baseUri); 109 110 /** 111 * Sets the user-agent on the transaction 112 * @param userAgent the request's user-agent 113 */ 114 void setUserAgent(String userAgent); 115 116}