com.squeakysand.commons.valueobjects.UnsynchronizedValueObjectException Maven / Gradle / Ivy
Show all versions of squeakysand-commons Show documentation
/*
* Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squeakysand.commons.valueobjects;
/**
* Exception thrown by a service when a {@link MutableValueObject} is passed to an update or delete method and it is not
* synchronized with the underlying persistence model.
*
* Services in a distributed system often implement a "soft-locking" mechanism, where each VO contains a timestamp
* and each time the underlying data model is updated the timestamp is also updated. When a client attempts to update
* the data model using a VO, the timestamp in the VO and the current timestamp in the underlying data model are
* compared. If the timestamps are not equal, the VO is said to be unsynchronized and this exception will be thrown. In
* general, this situation will occur when 2 users attempt to update the same object in a short interval, the second
* client that attempts to update will receive this exception. The second client will then have to use the updated data
* in the valid VO contained in the exception to attempt to update again. The soft-locking model allows for many clients
* to access the same data model without having to implement a complicated hard-locking system, whose overhead may not
* be viable or warranted.
*/
public class UnsynchronizedValueObjectException extends InvalidValueObjectException {
private static final long serialVersionUID = 917103448668230754L;
private final MutableValueObject validVO;
/**
* Creates a new UnsynchronizedValueObjectException object.
*
* @param invalidVO the VO that was used and caused the exception to be thrown.
* @param validVO the current valid VO that has the current data from the persistent store.
*/
public UnsynchronizedValueObjectException(MutableValueObject invalidVO, MutableValueObject validVO) {
super(invalidVO);
this.validVO = (MutableValueObject) validVO.clone();
}
/**
* Accessor to the valid ValueObject.
*
* @return the valid ValueObject.
*/
public MutableValueObject getValidValueObject() {
return (MutableValueObject) validVO.clone();
}
}