HHH-7919 : Miscellaneous bugfixes

This commit is contained in:
Strong Liu 2013-06-10 14:18:35 +08:00
parent 1b9ca7df6c
commit 77e555ff05
22 changed files with 490 additions and 528 deletions

View File

@ -29,7 +29,7 @@ import java.io.Serializable;
* A JavaBean bulk accessor, which provides methods capable of getting/setting multiple properties
* of a JavaBean at once.
*
* IMPORTANT NOTE!!! Apparently the order of the methods here is important as I think BulkAccessorFactory
* IMPORTANT NOTE!!! Apparently the order of the methods here is important as I think {@link BulkAccessorFactory}
* makes use of that information in terms of accessing the constructor. Anyway, when I tried to re-arrange them
* the BulkAccessor creation failed and tests started to fail.
*

View File

@ -72,7 +72,7 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
@Override
public boolean isInIdClass() {
return isInIdClass != null ? isInIdClass : parent != null ? parent.isInIdClass() : false;
return isInIdClass != null ? isInIdClass : parent != null && parent.isInIdClass();
}
@Override

View File

@ -55,6 +55,7 @@ public class BackrefPropertyAccessor implements PropertyAccessor {
* we don't know the value of the back reference
*/
public static final Serializable UNKNOWN = new Serializable() {
@Override
public String toString() {
return "<unknown>";
}
@ -78,16 +79,12 @@ public class BackrefPropertyAccessor implements PropertyAccessor {
this.getter = new BackrefGetter();
}
/**
* {@inheritDoc}
*/
@Override
public Setter getSetter(Class theClass, String propertyName) {
return setter;
}
/**
* {@inheritDoc}
*/
@Override
public Getter getGetter(Class theClass, String propertyName) {
return getter;
}
@ -98,23 +95,17 @@ public class BackrefPropertyAccessor implements PropertyAccessor {
*/
public static final class BackrefSetter implements Setter {
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory) {
// this page intentionally left blank :)
}
@ -127,9 +118,7 @@ public class BackrefPropertyAccessor implements PropertyAccessor {
*/
public class BackrefGetter implements Getter {
/**
* {@inheritDoc}
*/
@Override
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) {
if ( session == null ) {
return UNKNOWN;
@ -139,37 +128,27 @@ public class BackrefPropertyAccessor implements PropertyAccessor {
}
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Object get(Object target) {
return UNKNOWN;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return Object.class;
}

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.property;
import java.beans.Introspector;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
@ -46,33 +47,37 @@ import org.hibernate.internal.util.ReflectHelper;
*/
public class BasicPropertyAccessor implements PropertyAccessor {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, BasicPropertyAccessor.class.getName());
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
BasicPropertyAccessor.class.getName()
);
public static final class BasicSetter implements Setter {
private Class clazz;
private final Class clazz;
private final transient Method method;
private final String propertyName;
private BasicSetter(Class clazz, Method method, String propertyName) {
this.clazz=clazz;
this.method=method;
this.propertyName=propertyName;
this.clazz = clazz;
this.method = method;
this.propertyName = propertyName;
}
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory)
throws HibernateException {
throws HibernateException {
try {
method.invoke( target, value );
}
catch (NullPointerException npe) {
if ( value==null && method.getParameterTypes()[0].isPrimitive() ) {
catch ( NullPointerException npe ) {
if ( value == null && method.getParameterTypes()[0].isPrimitive() ) {
throw new PropertyAccessException(
npe,
"Null value was assigned to a property of primitive type",
true,
clazz,
propertyName
);
);
}
else {
throw new PropertyAccessException(
@ -81,66 +86,71 @@ public class BasicPropertyAccessor implements PropertyAccessor {
true,
clazz,
propertyName
);
);
}
}
catch (InvocationTargetException ite) {
catch ( InvocationTargetException ite ) {
throw new PropertyAccessException(
ite,
"Exception occurred inside",
true,
clazz,
propertyName
);
);
}
catch (IllegalAccessException iae) {
catch ( IllegalAccessException iae ) {
throw new PropertyAccessException(
iae,
"IllegalAccessException occurred while calling",
true,
clazz,
propertyName
);
);
//cannot occur
}
catch (IllegalArgumentException iae) {
if ( value==null && method.getParameterTypes()[0].isPrimitive() ) {
catch ( IllegalArgumentException iae ) {
if ( value == null && method.getParameterTypes()[0].isPrimitive() ) {
throw new PropertyAccessException(
iae,
"Null value was assigned to a property of primitive type",
true,
clazz,
propertyName
);
);
}
else {
LOG.illegalPropertySetterArgument(clazz.getName(), propertyName);
LOG.expectedType(method.getParameterTypes()[0].getName(), value == null ? null : value.getClass().getName());
LOG.illegalPropertySetterArgument( clazz.getName(), propertyName );
LOG.expectedType(
method.getParameterTypes()[0].getName(),
value == null ? null : value.getClass().getName()
);
throw new PropertyAccessException(
iae,
"IllegalArgumentException occurred while calling",
true,
clazz,
propertyName
);
);
}
}
}
@Override
public Method getMethod() {
return method;
}
@Override
public String getMethodName() {
return method.getName();
}
Object readResolve() {
return createSetter(clazz, propertyName);
return createSetter( clazz, propertyName );
}
@Override
public String toString() {
public String toString() {
return "BasicSetter(" + clazz.getName() + '.' + propertyName + ')';
}
}
@ -151,130 +161,122 @@ public class BasicPropertyAccessor implements PropertyAccessor {
private final String propertyName;
private BasicGetter(Class clazz, Method method, String propertyName) {
this.clazz=clazz;
this.method=method;
this.propertyName=propertyName;
this.clazz = clazz;
this.method = method;
this.propertyName = propertyName;
}
/**
* {@inheritDoc}
*/
@Override
public Object get(Object target) throws HibernateException {
try {
return method.invoke( target, (Object[]) null );
}
catch (InvocationTargetException ite) {
catch ( InvocationTargetException ite ) {
throw new PropertyAccessException(
ite,
"Exception occurred inside",
false,
clazz,
propertyName
);
);
}
catch (IllegalAccessException iae) {
catch ( IllegalAccessException iae ) {
throw new PropertyAccessException(
iae,
"IllegalAccessException occurred while calling",
false,
clazz,
propertyName
);
);
//cannot occur
}
catch (IllegalArgumentException iae) {
LOG.illegalPropertyGetterArgument(clazz.getName(), propertyName);
catch ( IllegalArgumentException iae ) {
LOG.illegalPropertyGetterArgument( clazz.getName(), propertyName );
throw new PropertyAccessException(
iae,
"IllegalArgumentException occurred calling",
false,
clazz,
propertyName
);
);
}
}
/**
* {@inheritDoc}
*/
@Override
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) {
return get( target );
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return method.getReturnType();
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return method;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return method;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return method.getName();
}
@Override
public String toString() {
public String toString() {
return "BasicGetter(" + clazz.getName() + '.' + propertyName + ')';
}
Object readResolve() {
return createGetter(clazz, propertyName);
return createGetter( clazz, propertyName );
}
}
public Setter getSetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return createSetter(theClass, propertyName);
throws PropertyNotFoundException {
return createSetter( theClass, propertyName );
}
private static Setter createSetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
BasicSetter result = getSetterOrNull(theClass, propertyName);
if (result==null) {
throws PropertyNotFoundException {
BasicSetter result = getSetterOrNull( theClass, propertyName );
if ( result == null ) {
throw new PropertyNotFoundException(
"Could not find a setter for property " +
propertyName +
" in class " +
theClass.getName()
);
propertyName +
" in class " +
theClass.getName()
);
}
return result;
}
private static BasicSetter getSetterOrNull(Class theClass, String propertyName) {
if (theClass==Object.class || theClass==null) return null;
if ( theClass == Object.class || theClass == null ) {
return null;
}
Method method = setterMethod(theClass, propertyName);
Method method = setterMethod( theClass, propertyName );
if (method!=null) {
if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
return new BasicSetter(theClass, method, propertyName);
if ( method != null ) {
if ( !ReflectHelper.isPublic( theClass, method ) ) {
method.setAccessible( true );
}
return new BasicSetter( theClass, method, propertyName );
}
else {
BasicSetter setter = getSetterOrNull( theClass.getSuperclass(), propertyName );
if (setter==null) {
if ( setter == null ) {
Class[] interfaces = theClass.getInterfaces();
for ( int i=0; setter==null && i<interfaces.length; i++ ) {
setter=getSetterOrNull( interfaces[i], propertyName );
for ( int i = 0; setter == null && i < interfaces.length; i++ ) {
setter = getSetterOrNull( interfaces[i], propertyName );
}
}
return setter;
@ -284,8 +286,8 @@ public class BasicPropertyAccessor implements PropertyAccessor {
private static Method setterMethod(Class theClass, String propertyName) {
BasicGetter getter = getGetterOrNull(theClass, propertyName);
Class returnType = (getter==null) ? null : getter.getReturnType();
BasicGetter getter = getGetterOrNull( theClass, propertyName );
Class returnType = ( getter == null ) ? null : getter.getReturnType();
Method[] methods = theClass.getDeclaredMethods();
Method potentialSetter = null;
@ -306,42 +308,43 @@ public class BasicPropertyAccessor implements PropertyAccessor {
return potentialSetter;
}
@Override
public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
return createGetter(theClass, propertyName);
return createGetter( theClass, propertyName );
}
public static Getter createGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
BasicGetter result = getGetterOrNull(theClass, propertyName);
if (result==null) {
BasicGetter result = getGetterOrNull( theClass, propertyName );
if ( result == null ) {
throw new PropertyNotFoundException(
"Could not find a getter for " +
propertyName +
" in class " +
theClass.getName()
propertyName +
" in class " +
theClass.getName()
);
}
return result;
}
private static BasicGetter getGetterOrNull(Class theClass, String propertyName) {
if (theClass==Object.class || theClass==null) {
if ( theClass == Object.class || theClass == null ) {
return null;
}
Method method = getterMethod(theClass, propertyName);
Method method = getterMethod( theClass, propertyName );
if (method!=null) {
if ( method != null ) {
if ( !ReflectHelper.isPublic( theClass, method ) ) {
method.setAccessible(true);
method.setAccessible( true );
}
return new BasicGetter(theClass, method, propertyName);
return new BasicGetter( theClass, method, propertyName );
}
else {
BasicGetter getter = getGetterOrNull( theClass.getSuperclass(), propertyName );
if (getter==null) {
if ( getter == null ) {
Class[] interfaces = theClass.getInterfaces();
for ( int i=0; getter==null && i<interfaces.length; i++ ) {
getter=getGetterOrNull( interfaces[i], propertyName );
for ( int i = 0; getter == null && i < interfaces.length; i++ ) {
getter = getGetterOrNull( interfaces[i], propertyName );
}
}
return getter;

View File

@ -35,32 +35,28 @@ public class ChainedPropertyAccessor implements PropertyAccessor {
public ChainedPropertyAccessor(PropertyAccessor[] chain) {
this.chain = chain;
}
@Override
public Getter getGetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
Getter result = null;
for (int i = 0; i < chain.length; i++) {
PropertyAccessor candidate = chain[i];
for ( PropertyAccessor candidate : chain ) {
try {
result = candidate.getGetter(theClass, propertyName);
return result;
} catch (PropertyNotFoundException pnfe) {
return candidate.getGetter( theClass, propertyName );
}
catch ( PropertyNotFoundException pnfe ) {
// ignore
}
}
throw new PropertyNotFoundException("Could not find getter for " + propertyName + " on " + theClass);
}
@Override
public Setter getSetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
Setter result = null;
for (int i = 0; i < chain.length; i++) {
PropertyAccessor candidate = chain[i];
for ( PropertyAccessor candidate : chain ) {
try {
result = candidate.getSetter(theClass, propertyName);
return result;
} catch (PropertyNotFoundException pnfe) {
//
return candidate.getSetter( theClass, propertyName );
}
catch ( PropertyNotFoundException pnfe ) {
// ignore
}
}
throw new PropertyNotFoundException("Could not find setter for " + propertyName + " on " + theClass);

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.property;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
@ -36,6 +37,7 @@ import org.hibernate.internal.util.ReflectHelper;
/**
* Accesses fields directly.
*
* @author Gavin King
*/
public class DirectPropertyAccessor implements PropertyAccessor {
@ -51,57 +53,46 @@ public class DirectPropertyAccessor implements PropertyAccessor {
this.name = name;
}
/**
* {@inheritDoc}
*/
@Override
public Object get(Object target) throws HibernateException {
try {
return field.get(target);
return field.get( target );
}
catch (Exception e) {
throw new PropertyAccessException(e, "could not get a field value by reflection", false, clazz, name);
catch ( Exception e ) {
throw new PropertyAccessException( e, "could not get a field value by reflection", false, clazz, name );
}
}
/**
* {@inheritDoc}
*/
@Override
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) {
return get( target );
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return field;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return field.getType();
}
Object readResolve() {
return new DirectGetter( getField(clazz, name), clazz, name );
return new DirectGetter( getField( clazz, name ), clazz, name );
}
@Override
public String toString() {
return "DirectGetter(" + clazz.getName() + '.' + name + ')';
}
@ -111,95 +102,90 @@ public class DirectPropertyAccessor implements PropertyAccessor {
private final transient Field field;
private final Class clazz;
private final String name;
DirectSetter(Field field, Class clazz, String name) {
this.field = field;
this.clazz = clazz;
this.name = name;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException {
try {
field.set(target, value);
field.set( target, value );
}
catch (Exception e) {
if(value == null && field.getType().isPrimitive()) {
throw new PropertyAccessException(
e,
"Null value was assigned to a property of primitive type",
true,
clazz,
name
);
} else {
throw new PropertyAccessException(e, "could not set a field value by reflection", true, clazz, name);
}
catch ( Exception e ) {
String errorMsg = ( value == null && field.getType().isPrimitive() ) ?
"Null value was assigned to a property of primitive type"
: "could not set a field value by reflection";
throw new PropertyAccessException( e, errorMsg, true, clazz, name );
}
}
@Override
public String toString() {
return "DirectSetter(" + clazz.getName() + '.' + name + ')';
}
Object readResolve() {
return new DirectSetter( getField(clazz, name), clazz, name );
return new DirectSetter( getField( clazz, name ), clazz, name );
}
}
private static Field getField(Class clazz, String name) throws PropertyNotFoundException {
if ( clazz==null || clazz==Object.class ) {
throw new PropertyNotFoundException("field not found: " + name);
if ( clazz == null || clazz == Object.class ) {
throw new PropertyNotFoundException( "field not found: " + name );
}
Field field;
try {
field = clazz.getDeclaredField(name);
field = clazz.getDeclaredField( name );
}
catch (NoSuchFieldException nsfe) {
catch ( NoSuchFieldException nsfe ) {
field = getField( clazz, clazz.getSuperclass(), name );
}
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
if ( !ReflectHelper.isPublic( clazz, field ) ) {
field.setAccessible( true );
}
return field;
}
private static Field getField(Class root, Class clazz, String name) throws PropertyNotFoundException {
if ( clazz==null || clazz==Object.class ) {
throw new PropertyNotFoundException("field [" + name + "] not found on " + root.getName());
if ( clazz == null || clazz == Object.class ) {
throw new PropertyNotFoundException( "field [" + name + "] not found on " + root.getName() );
}
Field field;
try {
field = clazz.getDeclaredField(name);
field = clazz.getDeclaredField( name );
}
catch (NoSuchFieldException nsfe) {
catch ( NoSuchFieldException nsfe ) {
field = getField( root, clazz.getSuperclass(), name );
}
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
if ( !ReflectHelper.isPublic( clazz, field ) ) {
field.setAccessible( true );
}
return field;
}
@Override
public Getter getGetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return new DirectGetter( getField(theClass, propertyName), theClass, propertyName );
throws PropertyNotFoundException {
return new DirectGetter( getField( theClass, propertyName ), theClass, propertyName );
}
@Override
public Setter getSetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return new DirectSetter( getField(theClass, propertyName), theClass, propertyName );
throws PropertyNotFoundException {
return new DirectSetter( getField( theClass, propertyName ), theClass, propertyName );
}
}

View File

@ -42,49 +42,37 @@ public class EmbeddedPropertyAccessor implements PropertyAccessor {
EmbeddedGetter(Class clazz) {
this.clazz = clazz;
}
/**
* {@inheritDoc}
*/
@Override
public Object get(Object target) throws HibernateException {
return target;
}
/**
* {@inheritDoc}
*/
@Override
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) {
return get( target );
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return clazz;
}
@Override
public String toString() {
return "EmbeddedGetter(" + clazz.getName() + ')';
}
@ -96,43 +84,37 @@ public class EmbeddedPropertyAccessor implements PropertyAccessor {
EmbeddedSetter(Class clazz) {
this.clazz = clazz;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory) {
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "EmbeddedSetter(" + clazz.getName() + ')';
}
}
@Override
public Getter getGetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return new EmbeddedGetter(theClass);
throws PropertyNotFoundException {
return new EmbeddedGetter( theClass );
}
@Override
public Setter getSetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return new EmbeddedSetter(theClass);
throws PropertyNotFoundException {
return new EmbeddedSetter( theClass );
}
}

View File

@ -50,10 +50,11 @@ public class IndexPropertyAccessor implements PropertyAccessor {
this.entityName = entityName;
}
@Override
public Setter getSetter(Class theClass, String propertyName) {
return new IndexSetter();
}
@Override
public Getter getGetter(Class theClass, String propertyName) {
return new IndexGetter();
}
@ -63,23 +64,17 @@ public class IndexPropertyAccessor implements PropertyAccessor {
* The Setter implementation for index backrefs.
*/
public static final class IndexSetter implements Setter {
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory) {
// do nothing...
}
@ -91,47 +86,38 @@ public class IndexPropertyAccessor implements PropertyAccessor {
* The Getter implementation for index backrefs.
*/
public class IndexGetter implements Getter {
@Override
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) throws HibernateException {
if (session==null) {
if ( session == null ) {
return BackrefPropertyAccessor.UNKNOWN;
}
else {
return session.getPersistenceContext()
.getIndexInOwner(entityName, propertyName, target, mergeMap);
.getIndexInOwner( entityName, propertyName, target, mergeMap );
}
}
/**
* {@inheritDoc}
*/
@Override
public Object get(Object target) {
return BackrefPropertyAccessor.UNKNOWN;
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return Object.class;
}

View File

@ -35,98 +35,77 @@ import org.hibernate.engine.spi.SessionImplementor;
* @author Gavin King
*/
public class MapAccessor implements PropertyAccessor {
/**
* {@inheritDoc}
*/
@Override
public Getter getGetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return new MapGetter(propertyName);
}
/**
* {@inheritDoc}
*/
@Override
public Setter getSetter(Class theClass, String propertyName)
throws PropertyNotFoundException {
return new MapSetter(propertyName);
}
@SuppressWarnings("unchecked")
public static final class MapSetter implements Setter {
private String name;
private final String name;
MapSetter(String name) {
this.name = name;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory)
throws HibernateException {
( (Map) target ).put(name, value);
throws HibernateException {
( (Map) target ).put( name, value );
}
}
public static final class MapGetter implements Getter {
private String name;
private final String name;
MapGetter(String name) {
this.name = name;
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Object get(Object target) throws HibernateException {
return ( (Map) target ).get(name);
return ( (Map) target ).get( name );
}
/**
* {@inheritDoc}
*/
@Override
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) {
return get( target );
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return Object.class;
}

View File

@ -37,16 +37,12 @@ import org.hibernate.engine.spi.SessionImplementor;
* @author Michael Bartmann
*/
public class NoopAccessor implements PropertyAccessor {
/**
* {@inheritDoc}
*/
@Override
public Getter getGetter(Class arg0, String arg1) throws PropertyNotFoundException {
return new NoopGetter();
}
/**
* {@inheritDoc}
*/
@Override
public Setter getSetter(Class arg0, String arg1) throws PropertyNotFoundException {
return new NoopSetter();
}
@ -56,46 +52,35 @@ public class NoopAccessor implements PropertyAccessor {
*/
private static class NoopGetter implements Getter {
/**
* {@inheritDoc}
* <p/>
* Here we always return <tt>null</tt>
*/
@Override
public Object get(Object target) throws HibernateException {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Object getForInsert(Object target, Map map, SessionImplementor arg1)
throws HibernateException {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Class getReturnType() {
return Object.class;
}
/**
* {@inheritDoc}
*/
@Override
public Member getMember() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}
@ -105,23 +90,17 @@ public class NoopAccessor implements PropertyAccessor {
* A Setter which will just do nothing.
*/
private static class NoopSetter implements Setter {
/**
* {@inheritDoc}
*/
@Override
public void set(Object target, Object value, SessionFactoryImplementor arg2) {
// nothing to do
}
/**
* {@inheritDoc}
*/
@Override
public String getMethodName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Method getMethod() {
return null;
}

View File

@ -1,6 +1,9 @@
package org.hibernate.test.instrument.cases;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.metamodel.MetadataSources;
@ -17,8 +20,22 @@ public abstract class AbstractExecutable implements Executable {
private SessionFactory factory;
@Override
public final void prepare() {
prepare( null );
}
@Override
public final void prepare(ClassLoader instrumentedClassLoader) {
Configuration cfg = new Configuration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder = new BootstrapServiceRegistryBuilder();
if ( instrumentedClassLoader != null ) // old metamodel case
{
bootstrapServiceRegistryBuilder.with( instrumentedClassLoader );
}
BootstrapServiceRegistry bootstrapServiceRegistry = bootstrapServiceRegistryBuilder.build();
StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapServiceRegistry);
serviceRegistry = standardServiceRegistryBuilder.applySettings( cfg.getProperties() ).build();
String[] resources = getResources();
if( BaseUnitTestCase.isMetadataUsed()){
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
@ -34,7 +51,8 @@ public abstract class AbstractExecutable implements Executable {
}
}
@Override
@Override
public final void complete() {
try {
cleanup();

View File

@ -1,11 +1,21 @@
package org.hibernate.test.instrument.cases;
/**
* @author Steve Ebersole
*/
public interface Executable {
public void prepare();
public void execute() throws Exception;
public void complete();
void prepare();
/**
* The reason that we need this method in the metamodel branch is because in this branch,
* we use {@link org.hibernate.boot.registry.classloading.spi.ClassLoaderService} to load entity classes
* (well, every classes), and by default, this service uses default hibernate classloader first, then
* it will bypass the instrument classloader, so here we have to explicitly provide this classloader to the
* {@link org.hibernate.boot.registry.classloading.spi.ClassLoaderService}.
*
* @param instrumentedClassLoader
*/
void prepare(ClassLoader instrumentedClassLoader);
void execute() throws Exception;
void complete();
}

View File

@ -1,4 +1,5 @@
package org.hibernate.test.instrument.cases;
import junit.framework.TestCase;
import org.hibernate.CacheMode;
@ -15,6 +16,7 @@ import org.hibernate.test.instrument.domain.Owner;
* @author Steve Ebersole
*/
public class TestLazyExecutable extends AbstractExecutable {
@Override
public void execute() {
// The following block is repeated 100 times to reproduce HHH-2627.
// Without the fix, Oracle will run out of cursors using 10g with
@ -22,183 +24,183 @@ public class TestLazyExecutable extends AbstractExecutable {
// The number of loops may need to be adjusted depending on the how
// Oracle is configured.
// Note: The block is not indented to avoid a lot of irrelevant differences.
for ( int i=0; i<100; i++ ) {
for ( int i = 0; i < 100; i++ ) {
SessionFactory factory = getFactory();
Session s = factory.openSession();
Transaction t = s.beginTransaction();
Owner o = new Owner();
Document doc = new Document();
Folder fol = new Folder();
o.setName("gavin");
doc.setName("Hibernate in Action");
doc.setSummary("blah");
doc.updateText("blah blah");
fol.setName("books");
doc.setOwner(o);
doc.setFolder(fol);
fol.getDocuments().add(doc);
s.save(o);
s.save(fol);
t.commit();
s.close();
SessionFactory factory = getFactory();
Session s = factory.openSession();
Transaction t = s.beginTransaction();
Owner o = new Owner();
Document doc = new Document();
Folder fol = new Folder();
o.setName( "gavin" );
doc.setName( "Hibernate in Action" );
doc.setSummary( "blah" );
doc.updateText( "blah blah" );
fol.setName( "books" );
doc.setOwner( o );
doc.setFolder( fol );
fol.getDocuments().add( doc );
s.save( o );
s.save( fol );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = ( Document ) s.get( Document.class, doc.getId() );
TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
doc.getUpperCaseName(); // should force initialization
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.get( Document.class, doc.getId() );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "name" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "folder" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
doc.getUpperCaseName(); // should force initialization
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "folder" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
doc.getName();
TestCase.assertEquals( doc.getText(), "blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
doc.getName();
TestCase.assertEquals( doc.getText(), "blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
doc.getName();
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
doc.getName();
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
doc.setName("HiA");
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
doc.setName( "HiA" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
TestCase.assertEquals( doc.getName(), "HiA" );
TestCase.assertEquals( doc.getText(), "blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
TestCase.assertEquals( doc.getName(), "HiA" );
TestCase.assertEquals( doc.getText(), "blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
doc.getText();
doc.setName("HiA second edition");
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
doc.getText();
doc.setName( "HiA second edition" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
TestCase.assertEquals( doc.getName(), "HiA second edition" );
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "name" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
TestCase.assertEquals( doc.getName(), "HiA second edition" );
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "weirdProperty" ) );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
t.commit();
s.close();
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
s.lock(doc, LockMode.NONE);
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
s.lock( doc, LockMode.NONE );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
t.commit();
s.close();
doc.setName("HiA2");
doc.setName( "HiA2" );
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
s.saveOrUpdate(doc);
s.flush();
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
doc.updateText("blah blah blah blah");
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
s.saveOrUpdate( doc );
s.flush();
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertEquals( doc.getText(), "blah blah" );
TestCase.assertTrue( Hibernate.isPropertyInitialized( doc, "text" ) );
doc.updateText( "blah blah blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = ( Document ) s.createQuery("from Document").uniqueResult();
TestCase.assertEquals( doc.getName(), "HiA2" );
TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
TestCase.assertEquals( doc.getName(), "HiA2" );
TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.load( Document.class, doc.getId() );
doc.getName();
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.load( Document.class, doc.getId() );
doc.getName();
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "text" ) );
TestCase.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery("from Document").uniqueResult();
//s.delete(doc);
s.delete( doc.getFolder() );
s.delete( doc.getOwner() );
s.flush();
t.commit();
s.close();
s = factory.openSession();
s.setCacheMode( CacheMode.IGNORE );
t = s.beginTransaction();
doc = (Document) s.createQuery( "from Document" ).uniqueResult();
//s.delete(doc);
s.delete( doc.getFolder() );
s.delete( doc.getOwner() );
s.flush();
t.commit();
s.close();
}

View File

@ -13,11 +13,11 @@ import org.hibernate.test.instrument.domain.Problematic;
* @author Steve Ebersole
*/
public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
@Override
protected String[] getResources() {
return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
}
@Override
public void execute() throws Exception {
Session s = getFactory().openSession();
Problematic p = new Problematic();
@ -76,7 +76,7 @@ public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
s.close();
}
}
@Override
protected void cleanup() {
Session s = getFactory().openSession();
s.beginTransaction();

View File

@ -34,6 +34,7 @@ import org.hibernate.bytecode.buildtime.spi.FieldFilter;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.spi.InstrumentedClassLoader;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.junit4.ClassLoadingIsolater;
@ -136,8 +137,10 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends
// reflection code to ensure isolation into the created classloader ~~~~~~~
private static final Class[] SIG = new Class[] {};
private static final Object[] ARGS = new Object[] {};
private static final Class[] SIG_METAMODEL = new Class[]{ClassLoader.class};
private static final String PREPARE = "prepare";
private static final String EXECUTE = "execute";
private static final String COMPLETE = "complete";
public void executeExecutable(String name) {
Class execClass = null;
@ -150,8 +153,14 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends
throw new HibernateException( "could not load executable", t );
}
try {
execClass.getMethod( "prepare", SIG ).invoke( executable, ARGS );
execClass.getMethod( "execute", SIG ).invoke( executable, ARGS );
if ( BaseUnitTestCase.isMetadataUsed() ) {
execClass.getMethod( PREPARE, SIG_METAMODEL )
.invoke( executable, new ClassLoader[] { Thread.currentThread().getContextClassLoader() } );
}
else {
execClass.getMethod( PREPARE, ReflectHelper.NO_PARAM_SIGNATURE ).invoke( executable, ReflectHelper.NO_PARAMS );
}
execClass.getMethod( EXECUTE, ReflectHelper.NO_PARAM_SIGNATURE ).invoke( executable, ReflectHelper.NO_PARAMS );
}
catch ( NoSuchMethodException e ) {
throw new HibernateException( "could not exeucte executable", e );
@ -164,7 +173,7 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends
}
finally {
try {
execClass.getMethod( "complete", SIG ).invoke( executable, ARGS );
execClass.getMethod( COMPLETE, ReflectHelper.NO_PARAM_SIGNATURE ).invoke( executable, ReflectHelper.NO_PARAMS );
}
catch ( Throwable ignore ) {
}

View File

@ -23,14 +23,47 @@
*/
package org.hibernate.test.instrument.runtime;
import org.junit.Test;
import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
/**
* @author Steve Ebersole
*/
public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
@Override
protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl();
}
@FailureExpectedWithNewMetamodel
@Test
@Override
public void testLazy() {
super.testLazy();
}
@FailureExpectedWithNewMetamodel
@Test
@Override
public void testLazyManyToOne() {
super.testLazyManyToOne();
}
@FailureExpectedWithNewMetamodel
@Test
@Override
public void testSharedPKOneToOne() {
super.testSharedPKOneToOne();
}
@FailureExpectedWithNewMetamodel
@Test
@Override
public void testManyToOneProxy() {
super.testManyToOneProxy();
}
}

View File

@ -28,14 +28,12 @@ import javax.persistence.EntityManagerFactory;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import static org.junit.Assert.assertNotNull;
/**
* @author Emmanuel Bernard
*/
@FailureExpectedWithNewMetamodel
public class SecondMetadataTest extends BaseEntityManagerFunctionalTestCase {
@Test
public void testBaseOfService() throws Exception {

View File

@ -508,7 +508,6 @@ public class InfinispanRegionFactory extends AbstractRegionFactory {
TypeOverrides regionOverride = typeOverrides.get(regionName);
if (!definedConfigurations.contains(regionName)) {
String templateCacheName;
Configuration regionCacheCfg;
ConfigurationBuilder builder = new ConfigurationBuilder();
if (regionOverride != null) {
if (log.isDebugEnabled()) log.debug("Cache region specific configuration exists: " + regionOverride);
@ -556,8 +555,7 @@ public class InfinispanRegionFactory extends AbstractRegionFactory {
.getGlobalComponentRegistry();
Map<Byte, ModuleCommandFactory> factories =
(Map<Byte, ModuleCommandFactory>) globalCr
.getComponent("org.infinispan.modules.command.factories");
globalCr.getComponent("org.infinispan.modules.command.factories");
for (ModuleCommandFactory factory : factories.values()) {
if (factory instanceof CacheCommandFactory)

View File

@ -71,15 +71,17 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory {
}
public static void clearCacheManagers() {
for ( EmbeddedCacheManager manager : cacheManagers.values() ) {
try {
try {
for ( EmbeddedCacheManager manager : cacheManagers.values() ) {
manager.stop();
}
catch ( Exception e ) {
log.error( "Exception cleaning up CacheManager " + manager, e );
}
}
cacheManagers.clear();
catch ( Exception e ) {
log.error( "Exception cleaning up CacheManager ", e );
}
finally {
cacheManagers.clear();
}
}
@Override
@ -109,11 +111,11 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory {
delegate.setCacheManager( existing );
}
}
@Override
public void start(Settings settings, Properties properties) throws CacheException {
start();
}
@Override
public void stop() {
if ( locallyAdded ) {
cacheManagers.remove( cacheManagerName );
@ -121,11 +123,12 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory {
delegate.stop();
}
@Override
public CollectionRegion buildCollectionRegion(String regionName, Properties properties,
CacheDataDescription metadata) throws CacheException {
return delegate.buildCollectionRegion( regionName, properties, metadata );
}
@Override
public EntityRegion buildEntityRegion(String regionName, Properties properties,
CacheDataDescription metadata) throws CacheException {
return delegate.buildEntityRegion( regionName, properties, metadata );
@ -136,17 +139,17 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory {
throws CacheException {
return delegate.buildNaturalIdRegion( regionName, properties, metadata );
}
@Override
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties)
throws CacheException {
return delegate.buildQueryResultsRegion( regionName, properties );
}
@Override
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties)
throws CacheException {
return delegate.buildTimestampsRegion( regionName, properties );
}
@Override
public boolean isMinimalPutsEnabledByDefault() {
return delegate.isMinimalPutsEnabledByDefault();
}
@ -155,7 +158,7 @@ public class ClusterAwareRegionFactory extends AbstractRegionFactory {
public AccessType getDefaultAccessType() {
return AccessType.TRANSACTIONAL;
}
@Override
public long nextTimestamp() {
return delegate.nextTimestamp();
}

View File

@ -90,6 +90,7 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
protected void cleanupTransactionManagement() {
DualNodeJtaTransactionManagerImpl.cleanupTransactions();
DualNodeJtaTransactionManagerImpl.cleanupTransactionManagers();
ClusterAwareRegionFactory.clearCacheManagers();
}
@Before

View File

@ -42,6 +42,10 @@ public class ClassLoadingIsolater implements MethodRule {
this.provider = provider;
}
public IsolatedClassLoaderProvider getProvider() {
return provider;
}
@Override
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
return new Statement() {

View File

@ -84,7 +84,6 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
private Boolean isAllTestsIgnored = null;
private Object testInstance;
private List<FrameworkMethod> computedTestMethods;
private Boolean useNewMetamodel;
private boolean beforeClassMethodFailed;
public CustomRunner(Class<?> clazz) throws InitializationError {
@ -268,10 +267,7 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
}
boolean useNewMetamodel() {
if ( useNewMetamodel == null ) {
useNewMetamodel = Boolean.valueOf( System.getProperty( BaseCoreFunctionalTestCase.USE_NEW_METADATA_MAPPINGS, "true" ) );
}
return useNewMetamodel;
return BaseUnitTestCase.isMetadataUsed();
}
protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) {