HHH-14290 Adjust HCANNHelper to benefit from HCANN-99
This commit is contained in:
parent
75646309a7
commit
a0e4ab72ec
|
@ -6,12 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.cfg.annotations;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.annotations.common.reflection.XProperty;
|
||||
import org.hibernate.annotations.common.reflection.java.JavaXMember;
|
||||
|
||||
|
@ -20,47 +16,35 @@ import org.hibernate.annotations.common.reflection.java.JavaXMember;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HCANNHelper {
|
||||
private static Method getMemberMethod;
|
||||
static {
|
||||
// The following is in a static block to avoid problems lazy-initializing
|
||||
// and making accessible in a multi-threaded context. See HHH-11289.
|
||||
final Class<?> javaXMemberClass = JavaXMember.class;
|
||||
try {
|
||||
getMemberMethod = javaXMemberClass.getDeclaredMethod( "getMember" );
|
||||
// NOTE : no need to check accessibility here - we know it is protected
|
||||
getMemberMethod.setAccessible( true );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new AssertionFailure(
|
||||
"Could not resolve JavaXMember#getMember method in order to access XProperty member signature",
|
||||
e
|
||||
);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new HibernateException( "Could not access org.hibernate.annotations.common.reflection.java.JavaXMember#getMember method", e );
|
||||
}
|
||||
}
|
||||
public final class HCANNHelper {
|
||||
|
||||
/**
|
||||
* @deprecated Prefer using {@link #annotatedElementSignature(JavaXMember)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static String annotatedElementSignature(XProperty xProperty) {
|
||||
return getUnderlyingMember( xProperty ).toString();
|
||||
}
|
||||
|
||||
public static String annotatedElementSignature(final JavaXMember jxProperty) {
|
||||
return getUnderlyingMember( jxProperty ).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Prefer using {@link #getUnderlyingMember(JavaXMember)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static Member getUnderlyingMember(XProperty xProperty) {
|
||||
try {
|
||||
return (Member) getMemberMethod.invoke( xProperty );
|
||||
if (xProperty instanceof JavaXMember) {
|
||||
JavaXMember jx = (JavaXMember)xProperty;
|
||||
return jx.getMember();
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AssertionFailure(
|
||||
"Could not resolve member signature from XProperty reference",
|
||||
e
|
||||
);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AssertionFailure(
|
||||
"Could not resolve member signature from XProperty reference",
|
||||
e.getCause()
|
||||
);
|
||||
else {
|
||||
throw new org.hibernate.HibernateException( "Can only extract Member from a XProperty which is a JavaXMember" );
|
||||
}
|
||||
}
|
||||
|
||||
public static Member getUnderlyingMember(final JavaXMember jxProperty) {
|
||||
return jxProperty.getMember();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue