001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.kernel.api.exception; 007 008/** 009 * This exception indicates that a resource could not be modified because it is currently being modified by another 010 * transaction. 011 * 012 * @author pwinckles 013 */ 014public class ConcurrentUpdateException extends RepositoryRuntimeException { 015 016 private static final String LOG_MESSAGE = 017 "Cannot update %s because it is being updated by another transaction (%s)."; 018 private static final String HTTP_MESSAGE = "Cannot update %s because it is being updated by another transaction"; 019 020 private final String resource; 021 private final String existingTx; 022 private final String conflictingTx; 023 024 /** 025 * Constructor 026 * 027 * @param resource the Fedora response 028 * @param conflictingTx the transaction id attempting to lock the resource 029 * @param existingTx the transaction id holding the resource 030 */ 031 public ConcurrentUpdateException(final String resource, final String conflictingTx, final String existingTx) { 032 super(String.format(LOG_MESSAGE, resource, existingTx)); 033 this.resource = resource; 034 this.conflictingTx = conflictingTx; 035 this.existingTx = existingTx; 036 } 037 038 public String getResponseMessage() { 039 return String.format(HTTP_MESSAGE, resource); 040 } 041 042 public String getExistingTransactionId() { 043 return existingTx; 044 } 045 046 public String getConflictingTransactionId() { 047 return conflictingTx; 048 } 049}