HHH-5094 applied some changes as on 3.5 branch

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19740 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Hardy Ferentschik 2010-06-15 14:53:17 +00:00
parent 6d9c10deab
commit c0e94443b1
2 changed files with 114 additions and 7 deletions

View File

@ -5,7 +5,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.lang.reflect.AccessibleObject;
import java.util.ArrayList;
import java.util.HashMap;
@ -24,6 +23,7 @@ import org.hibernate.collection.PersistentCollection;
/**
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
public class PersistenceUtilHelper {
public static LoadState isLoadedWithoutReference(Object proxy, String property, MetadataCache cache) {
@ -112,10 +112,8 @@ public class PersistenceUtilHelper {
}
private static void setAccessibility(Member member) {
if ( !Modifier.isPublic( member.getModifiers() ) ) {
//Sun's ease of use, sigh...
( ( AccessibleObject ) member ).setAccessible( true );
}
//Sun's ease of use, sigh...
( ( AccessibleObject ) member ).setAccessible( true );
}
public static LoadState isLoaded(Object o) {
@ -146,10 +144,10 @@ public class PersistenceUtilHelper {
string[0] = Character.toUpperCase( string[0] );
methodName = new String( string );
try {
return clazz.getMethod( "get" + methodName );
return clazz.getDeclaredMethod( "get" + methodName );
}
catch ( NoSuchMethodException e ) {
return clazz.getMethod( "is" + methodName );
return clazz.getDeclaredMethod( "is" + methodName );
}
}
catch ( NoSuchMethodException e ) {

View File

@ -0,0 +1,109 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
* third-party contributors as indicated by either @author tags or express
* copyright attribution statements applied by the authors. All
* third-party contributions are distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.ejb.test.util;
import javax.persistence.spi.LoadState;
import org.hibernate.ejb.util.PersistenceUtilHelper;
/**
* Tests for HHH-5094
*
* @author Hardy Ferentschik
*/
public class PersistenceUtilHelperTest extends junit.framework.TestCase {
private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache();
public static class FieldAccessBean {
public String publicAccessProperty;
protected String protectedAccessProperty;
private String privateAccessProperty;
}
public static class MethodAccessBean {
private String publicAccessProperty;
private String protectedAccessProperty;
private String privateAccessProperty;
public String getPublicAccessPropertyValue() {
return publicAccessProperty;
}
protected String getProtectedAccessPropertyValue() {
return protectedAccessProperty;
}
private String getPrivateAccessPropertyValue() {
return privateAccessProperty;
}
}
public void testIsLoadedWithReferencePublicField() {
assertEquals(
LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( new FieldAccessBean(), "publicAccessProperty", cache )
);
}
public void testIsLoadedWithReferencePublicMethod() {
assertEquals(
LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference(
new MethodAccessBean(), "publicAccessPropertyValue", cache
)
);
}
public void testIsLoadedWithReferenceProtectedField() {
assertEquals(
LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( new FieldAccessBean(), "protectedAccessProperty", cache )
);
}
public void testIsLoadedWithReferenceProtectedMethod() {
assertEquals(
LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference(
new MethodAccessBean(), "protectedAccessPropertyValue", cache
)
);
}
public void testIsLoadedWithReferencePrivateField() {
assertEquals(
LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( new FieldAccessBean(), "privateAccessProperty", cache )
);
}
public void testIsLoadedWithReferencePrivateMethod() {
assertEquals(
LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference(
new MethodAccessBean(), "privateAccessPropertyValue", cache
)
);
}
}