org.hibernate.jpa.event.internal.EntityCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
Hibernate's core ORM functionality
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.jpa.event.internal;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.hibernate.jpa.event.spi.CallbackType;
/**
* Represents a JPA callback on the entity itself
*
* @author Kabir Khan
* @author Steve Ebersole
*/
final class EntityCallback extends AbstractCallback {
private final Method callbackMethod;
EntityCallback(Method callbackMethod, CallbackType callbackType) {
super( callbackType );
this.callbackMethod = callbackMethod;
}
@Override
public boolean performCallback(Object entity) {
try {
callbackMethod.invoke( entity );
return true;
}
catch (InvocationTargetException e) {
//keep runtime exceptions as is
if ( e.getTargetException() instanceof RuntimeException ) {
throw (RuntimeException) e.getTargetException();
}
else {
throw new RuntimeException( e.getTargetException() );
}
}
catch (Exception e) {
throw new RuntimeException( e );
}
}
}