org.apache.causeway.persistence.jdo.spring.exceptions.ObjectOptimisticLockingFailureException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of causeway-persistence-jdo-spring Show documentation
Show all versions of causeway-persistence-jdo-spring Show documentation
JDO Spring integration.
This is a fork of the Spring ORM JDO sources at github,
for which support had been dropped back in 2016 [1].
Credits to the original authors. See also docs [2].
[1] https://github.com/spring-projects/spring-framework/issues/18702
[2] https://docs.spring.io/spring-framework/docs/3.0.0.RC2/reference/html/ch13s04.html
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.causeway.persistence.jdo.spring.exceptions;
import org.springframework.dao.OptimisticLockingFailureException;
/**
* Exception thrown on an optimistic locking violation for a mapped object.
* Provides information about the persistent class and the identifier.
*/
@SuppressWarnings("serial")
public class ObjectOptimisticLockingFailureException extends OptimisticLockingFailureException {
private Object persistentClass;
private Object identifier;
/**
* Create a general ObjectOptimisticLockingFailureException with the given message,
* without any information on the affected object.
* @param msg the detail message
* @param cause the source exception
*/
public ObjectOptimisticLockingFailureException(String msg, Throwable cause) {
super(msg, cause);
}
/**
* Create a new ObjectOptimisticLockingFailureException for the given object,
* with the default "optimistic locking failed" message.
* @param persistentClass the persistent class
* @param identifier the ID of the object for which the locking failed
*/
public ObjectOptimisticLockingFailureException(Class persistentClass, Object identifier) {
this(persistentClass, identifier, null);
}
/**
* Create a new ObjectOptimisticLockingFailureException for the given object,
* with the default "optimistic locking failed" message.
* @param persistentClass the persistent class
* @param identifier the ID of the object for which the locking failed
* @param cause the source exception
*/
public ObjectOptimisticLockingFailureException(
Class persistentClass, Object identifier, Throwable cause) {
this(persistentClass, identifier,
"Object of class [" + persistentClass.getName() + "] with identifier [" + identifier +
"]: optimistic locking failed", cause);
}
/**
* Create a new ObjectOptimisticLockingFailureException for the given object,
* with the given explicit message.
* @param persistentClass the persistent class
* @param identifier the ID of the object for which the locking failed
* @param msg the detail message
* @param cause the source exception
*/
public ObjectOptimisticLockingFailureException(
Class persistentClass, Object identifier, String msg, Throwable cause) {
super(msg, cause);
this.persistentClass = persistentClass;
this.identifier = identifier;
}
/**
* Create a new ObjectOptimisticLockingFailureException for the given object,
* with the default "optimistic locking failed" message.
* @param persistentClassName the name of the persistent class
* @param identifier the ID of the object for which the locking failed
*/
public ObjectOptimisticLockingFailureException(String persistentClassName, Object identifier) {
this(persistentClassName, identifier, null);
}
/**
* Create a new ObjectOptimisticLockingFailureException for the given object,
* with the default "optimistic locking failed" message.
* @param persistentClassName the name of the persistent class
* @param identifier the ID of the object for which the locking failed
* @param cause the source exception
*/
public ObjectOptimisticLockingFailureException(
String persistentClassName, Object identifier, Throwable cause) {
this(persistentClassName, identifier,
"Object of class [" + persistentClassName + "] with identifier [" + identifier +
"]: optimistic locking failed", cause);
}
/**
* Create a new ObjectOptimisticLockingFailureException for the given object,
* with the given explicit message.
* @param persistentClassName the name of the persistent class
* @param identifier the ID of the object for which the locking failed
* @param msg the detail message
* @param cause the source exception
*/
public ObjectOptimisticLockingFailureException(
String persistentClassName, Object identifier, String msg, Throwable cause) {
super(msg, cause);
this.persistentClass = persistentClassName;
this.identifier = identifier;
}
/**
* Return the persistent class of the object for which the locking failed.
* If no Class was specified, this method returns null.
*/
public Class getPersistentClass() {
return (this.persistentClass instanceof Class ? (Class) this.persistentClass : null);
}
/**
* Return the name of the persistent class of the object for which the locking failed.
* Will work for both Class objects and String names.
*/
public String getPersistentClassName() {
if (this.persistentClass instanceof Class) {
return ((Class) this.persistentClass).getName();
}
return (this.persistentClass != null ? this.persistentClass.toString() : null);
}
/**
* Return the identifier of the object for which the locking failed.
*/
public Object getIdentifier() {
return identifier;
}
}