HHH-6025 - Remove cglib dependencies

This commit is contained in:
Steve Ebersole 2011-03-18 14:48:17 -05:00
parent 0af3a39c86
commit 82d2ef4b1f
22 changed files with 12 additions and 1825 deletions

View File

@ -36,9 +36,6 @@ libraries = [
commons_annotations: commons_annotations:
'org.hibernate:hibernate-commons-annotations:3.2.0.Final', 'org.hibernate:hibernate-commons-annotations:3.2.0.Final',
// CGLIB
cglib: 'cglib:cglib:2.2',
// Jakarta commons-collections todo : get rid of commons-collections dependency // Jakarta commons-collections todo : get rid of commons-collections dependency
commons_collections: commons_collections:
'commons-collections:commons-collections:3.1', 'commons-collections:commons-collections:3.1',

View File

@ -11,9 +11,6 @@ dependencies {
compile( libraries.jpa ) compile( libraries.jpa )
antlr( libraries.antlr ) antlr( libraries.antlr )
provided( libraries.javassist ) provided( libraries.javassist )
provided( libraries.cglib ) {
transitive = true
}
provided( libraries.ant ) provided( libraries.ant )
provided( libraries.jacc ) provided( libraries.jacc )
provided( libraries.validation ) provided( libraries.validation )
@ -25,9 +22,6 @@ dependencies {
} }
testRuntime( 'jaxen:jaxen:1.1' ) testRuntime( 'jaxen:jaxen:1.1' )
testRuntime( libraries.javassist ) testRuntime( libraries.javassist )
testRuntime( libraries.cglib ) {
transitive = true
}
} }
manifest.mainAttributes( manifest.mainAttributes(

View File

@ -1,101 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.buildtime;
import java.io.ByteArrayInputStream;
import java.util.Set;
import net.sf.cglib.core.ClassNameReader;
import net.sf.cglib.transform.impl.InterceptFieldEnabled;
import org.hibernate.bytecode.ClassTransformer;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
import org.hibernate.bytecode.util.BasicClassFilter;
import org.hibernate.bytecode.util.ClassDescriptor;
import org.objectweb.asm.ClassReader;
/**
* Strategy for performing build-time instrumentation of persistent classes in order to enable
* field-level interception using CGLIB.
*
* @author Steve Ebersole
* @author Gavin King
*/
public class CGLIBInstrumenter extends AbstractInstrumenter {
private static final BasicClassFilter CLASS_FILTER = new BasicClassFilter();
private final BytecodeProviderImpl provider = new BytecodeProviderImpl();
public CGLIBInstrumenter(Logger logger, Options options) {
super( logger, options );
}
@Override
protected ClassDescriptor getClassDescriptor(byte[] byecode) throws Exception {
return new CustomClassDescriptor( byecode );
}
@Override
protected ClassTransformer getClassTransformer(ClassDescriptor descriptor, Set classNames) {
if ( descriptor.isInstrumented() ) {
logger.debug( "class [" + descriptor.getName() + "] already instrumented" );
return null;
}
else {
return provider.getTransformer( CLASS_FILTER, new CustomFieldFilter( descriptor, classNames ) );
}
}
private static class CustomClassDescriptor implements ClassDescriptor {
private final byte[] bytecode;
private final String name;
private final boolean isInstrumented;
public CustomClassDescriptor(byte[] bytecode) throws Exception {
this.bytecode = bytecode;
ClassReader reader = new ClassReader( new ByteArrayInputStream( bytecode ) );
String[] names = ClassNameReader.getClassInfo( reader );
this.name = names[0];
boolean instrumented = false;
for ( int i = 1; i < names.length; i++ ) {
if ( InterceptFieldEnabled.class.getName().equals( names[i] ) ) {
instrumented = true;
break;
}
}
this.isInstrumented = instrumented;
}
public String getName() {
return name;
}
public boolean isInstrumented() {
return isInstrumented;
}
public byte[] getBytes() {
return bytecode;
}
}
}

View File

@ -1,126 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.cglib;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import net.sf.cglib.beans.BulkBean;
import net.sf.cglib.beans.BulkBeanException;
import org.hibernate.PropertyAccessException;
import org.hibernate.bytecode.ReflectionOptimizer;
/**
* The {@link ReflectionOptimizer.AccessOptimizer} implementation for CGLIB
* which simply acts as an adpater to the {@link BulkBean} class.
*
* @author Steve Ebersole
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class AccessOptimizerAdapter implements ReflectionOptimizer.AccessOptimizer, Serializable {
public static final String PROPERTY_GET_EXCEPTION =
"exception getting property value with CGLIB (set hibernate.bytecode.use_reflection_optimizer=false for more info)";
public static final String PROPERTY_SET_EXCEPTION =
"exception setting property value with CGLIB (set hibernate.bytecode.use_reflection_optimizer=false for more info)";
private Class mappedClass;
private BulkBean bulkBean;
public AccessOptimizerAdapter(BulkBean bulkBean, Class mappedClass) {
this.bulkBean = bulkBean;
this.mappedClass = mappedClass;
}
public String[] getPropertyNames() {
return bulkBean.getGetters();
}
public Object[] getPropertyValues(Object object) {
try {
return bulkBean.getPropertyValues( object );
}
catch ( Throwable t ) {
throw new PropertyAccessException(
t,
PROPERTY_GET_EXCEPTION,
false,
mappedClass,
getterName( t, bulkBean )
);
}
}
public void setPropertyValues(Object object, Object[] values) {
try {
bulkBean.setPropertyValues( object, values );
}
catch ( Throwable t ) {
throw new PropertyAccessException(
t,
PROPERTY_SET_EXCEPTION,
true,
mappedClass,
setterName( t, bulkBean )
);
}
}
private static String setterName(Throwable t, BulkBean optimizer) {
if ( t instanceof BulkBeanException ) {
return optimizer.getSetters()[( ( BulkBeanException ) t ).getIndex()];
}
else {
return "?";
}
}
private static String getterName(Throwable t, BulkBean optimizer) {
if ( t instanceof BulkBeanException ) {
return optimizer.getGetters()[( ( BulkBeanException ) t ).getIndex()];
}
else {
return "?";
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject( mappedClass );
out.writeObject( bulkBean.getGetters() );
out.writeObject( bulkBean.getSetters() );
out.writeObject( bulkBean.getPropertyTypes() );
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
Class beanClass = ( Class ) in.readObject();
String[] getters = ( String[] ) in.readObject();
String[] setters = ( String[] ) in.readObject();
Class[] types = ( Class[] ) in.readObject();
bulkBean = BulkBean.create( beanClass, getters, setters, types );
}
}

View File

@ -1,106 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.cglib;
import java.lang.reflect.Modifier;
import net.sf.cglib.beans.BulkBean;
import net.sf.cglib.beans.BulkBeanException;
import net.sf.cglib.reflect.FastClass;
import org.hibernate.HibernateLogger;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.ProxyFactoryFactory;
import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.util.FieldFilter;
import org.hibernate.internal.util.StringHelper;
import org.jboss.logging.Logger;
/**
* Bytecode provider implementation for CGLIB.
*
* @author Steve Ebersole
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class BytecodeProviderImpl implements BytecodeProvider {
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, BytecodeProviderImpl.class.getName());
public BytecodeProviderImpl() {
LOG.deprecated();
}
public ProxyFactoryFactory getProxyFactoryFactory() {
return new ProxyFactoryFactoryImpl();
}
public ReflectionOptimizer getReflectionOptimizer(
Class clazz,
String[] getterNames,
String[] setterNames,
Class[] types) {
FastClass fastClass;
BulkBean bulkBean;
try {
fastClass = FastClass.create( clazz );
bulkBean = BulkBean.create( clazz, getterNames, setterNames, types );
if ( !clazz.isInterface() && !Modifier.isAbstract( clazz.getModifiers() ) ) {
if ( fastClass == null ) {
bulkBean = null;
}
else {
//test out the optimizer:
Object instance = fastClass.newInstance();
bulkBean.setPropertyValues( instance, bulkBean.getPropertyValues( instance ) );
}
}
}
catch( Throwable t ) {
fastClass = null;
bulkBean = null;
if (LOG.isDebugEnabled()) {
int index = 0;
if (t instanceof BulkBeanException) index = ((BulkBeanException)t).getIndex();
if (index >= 0) LOG.debugf("Reflection optimizer disabled for: %s [%s: %s (property %s)",
clazz.getName(),
StringHelper.unqualify(t.getClass().getName()),
t.getMessage(),
setterNames[index]);
else LOG.debugf("Reflection optimizer disabled for: %s [%s: %s",
clazz.getName(),
StringHelper.unqualify(t.getClass().getName()),
t.getMessage());
}
}
if (fastClass != null && bulkBean != null) return new ReflectionOptimizerImpl(new InstantiationOptimizerAdapter(fastClass),
new AccessOptimizerAdapter(bulkBean, clazz));
return null;
}
public org.hibernate.bytecode.ClassTransformer getTransformer(org.hibernate.bytecode.util.ClassFilter classFilter, FieldFilter fieldFilter) {
return new CglibClassTransformer( classFilter, fieldFilter );
}
}

View File

@ -1,136 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.cglib;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.ProtectionDomain;
import net.sf.cglib.core.ClassNameReader;
import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.transform.ClassReaderGenerator;
import net.sf.cglib.transform.ClassTransformer;
import net.sf.cglib.transform.TransformingClassGenerator;
import net.sf.cglib.transform.impl.InterceptFieldEnabled;
import net.sf.cglib.transform.impl.InterceptFieldFilter;
import net.sf.cglib.transform.impl.InterceptFieldTransformer;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.bytecode.AbstractClassTransformerImpl;
import org.hibernate.bytecode.util.ClassFilter;
import org.hibernate.bytecode.util.FieldFilter;
import org.jboss.logging.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
/**
* Enhance the classes allowing them to implements InterceptFieldEnabled
* This interface is then used by Hibernate for some optimizations.
*
* @author Emmanuel Bernard
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class CglibClassTransformer extends AbstractClassTransformerImpl {
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, CglibClassTransformer.class.getName());
public CglibClassTransformer(ClassFilter classFilter, FieldFilter fieldFilter) {
super( classFilter, fieldFilter );
}
@Override
protected byte[] doTransform(
ClassLoader loader,
String className,
Class classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer) {
ClassReader reader;
try {
reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
}
catch (IOException e) {
LOG.unableToReadClass(e.getMessage());
throw new HibernateException( "Unable to read class: " + e.getMessage() );
}
String[] names = ClassNameReader.getClassInfo( reader );
ClassWriter w = new DebuggingClassWriter( ClassWriter.COMPUTE_MAXS );
ClassTransformer t = getClassTransformer( names );
if ( t != null ) {
LOG.debugf("Enhancing %s", className);
ByteArrayOutputStream out;
byte[] result;
try {
reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
new TransformingClassGenerator(
new ClassReaderGenerator( reader, skipDebug() ), t
).generateClass( w );
out = new ByteArrayOutputStream();
out.write( w.toByteArray() );
result = out.toByteArray();
out.close();
}
catch (Exception e) {
LOG.unableToTransformClass(e.getMessage());
throw new HibernateException( "Unable to transform class: " + e.getMessage() );
}
return result;
}
return classfileBuffer;
}
private int skipDebug() {
return ClassReader.SKIP_DEBUG;
}
private ClassTransformer getClassTransformer(final String[] classInfo) {
if ( isAlreadyInstrumented( classInfo ) ) {
return null;
}
return new InterceptFieldTransformer(
new InterceptFieldFilter() {
public boolean acceptRead(Type owner, String name) {
return fieldFilter.shouldTransformFieldAccess( classInfo[0], owner.getClassName(), name );
}
public boolean acceptWrite(Type owner, String name) {
return fieldFilter.shouldTransformFieldAccess( classInfo[0], owner.getClassName(), name );
}
}
);
}
private boolean isAlreadyInstrumented(String[] classInfo) {
for ( int i = 1; i < classInfo.length; i++ ) {
if ( InterceptFieldEnabled.class.getName().equals( classInfo[i] ) ) {
return true;
}
}
return false;
}
}

View File

@ -1,71 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.cglib;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import net.sf.cglib.reflect.FastClass;
import org.hibernate.InstantiationException;
import org.hibernate.bytecode.ReflectionOptimizer;
/**
* The {@link ReflectionOptimizer.InstantiationOptimizer} implementation for CGLIB
* which simply acts as an adapter to the {@link FastClass} class.
*
* @author Steve Ebersole
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class InstantiationOptimizerAdapter implements ReflectionOptimizer.InstantiationOptimizer, Serializable {
private FastClass fastClass;
public InstantiationOptimizerAdapter(FastClass fastClass) {
this.fastClass = fastClass;
}
public Object newInstance() {
try {
return fastClass.newInstance();
}
catch ( Throwable t ) {
throw new InstantiationException(
"Could not instantiate entity with CGLIB optimizer: ",
fastClass.getJavaClass(),
t
);
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject( fastClass.getJavaClass() );
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
Class beanClass = ( Class ) in.readObject();
fastClass = FastClass.create( beanClass );
}
}

View File

@ -1,166 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.cglib;
import java.lang.reflect.Method;
import java.util.HashMap;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.proxy.NoOp;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.bytecode.BasicProxyFactory;
import org.hibernate.bytecode.ProxyFactoryFactory;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory;
/**
* A factory for CGLIB-based {@link ProxyFactory} instances.
*
* @author Steve Ebersole
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class ProxyFactoryFactoryImpl implements ProxyFactoryFactory {
/**
* Builds a CGLIB-based proxy factory.
*
* @return a new CGLIB-based proxy factory.
*/
public ProxyFactory buildProxyFactory() {
return new CGLIBProxyFactory();
}
public BasicProxyFactory buildBasicProxyFactory(Class superClass, Class[] interfaces) {
return new BasicProxyFactoryImpl( superClass, interfaces );
}
public static class BasicProxyFactoryImpl implements BasicProxyFactory {
private final Class proxyClass;
private final Factory factory;
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
}
Enhancer en = new Enhancer();
en.setUseCache( false );
en.setInterceptDuringConstruction( false );
en.setUseFactory( true );
en.setCallbackTypes( CALLBACK_TYPES );
en.setCallbackFilter( FINALIZE_FILTER );
if ( superClass != null ) {
en.setSuperclass( superClass );
}
if ( interfaces != null && interfaces.length > 0 ) {
en.setInterfaces( interfaces );
}
proxyClass = en.createClass();
try {
factory = ( Factory ) proxyClass.newInstance();
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to build CGLIB Factory instance" );
}
}
public Object getProxy() {
try {
return factory.newInstance(
new Callback[] { new PassThroughInterceptor( proxyClass.getName() ), NoOp.INSTANCE }
);
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiate proxy instance" );
}
}
}
private static final CallbackFilter FINALIZE_FILTER = new CallbackFilter() {
public int accept(Method method) {
if ( method.getParameterTypes().length == 0 && method.getName().equals("finalize") ){
return 1;
}
else {
return 0;
}
}
};
private static final Class[] CALLBACK_TYPES = new Class[] { MethodInterceptor.class, NoOp.class };
private static class PassThroughInterceptor implements MethodInterceptor {
private HashMap data = new HashMap();
private final String proxiedClassName;
public PassThroughInterceptor(String proxiedClassName) {
this.proxiedClassName = proxiedClassName;
}
public Object intercept(
Object obj,
Method method,
Object[] args,
MethodProxy proxy) throws Throwable {
String name = method.getName();
if ( "toString".equals( name ) ) {
return proxiedClassName + "@" + System.identityHashCode( obj );
}
else if ( "equals".equals( name ) ) {
return args[0] instanceof Factory && ( ( Factory ) args[0] ).getCallback( 0 ) == this
? Boolean.TRUE
: Boolean.FALSE;
}
else if ( "hashCode".equals( name ) ) {
return new Integer( System.identityHashCode( obj ) );
}
boolean hasGetterSignature = method.getParameterTypes().length == 0 && method.getReturnType() != null;
boolean hasSetterSignature = method.getParameterTypes().length == 1 && ( method.getReturnType() == null || method.getReturnType() == void.class );
if ( name.startsWith( "get" ) && hasGetterSignature ) {
String propName = name.substring( 3 );
return data.get( propName );
}
else if ( name.startsWith( "is" ) && hasGetterSignature ) {
String propName = name.substring( 2 );
return data.get( propName );
}
else if ( name.startsWith( "set" ) && hasSetterSignature) {
String propName = name.substring( 3 );
data.put( propName, args[0] );
return null;
}
else {
// todo : what else to do here?
return null;
}
}
}
}

View File

@ -1,56 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.bytecode.cglib;
import java.io.Serializable;
import org.hibernate.bytecode.ReflectionOptimizer;
/**
* ReflectionOptimizer implementation for CGLIB.
*
* @author Steve Ebersole
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class ReflectionOptimizerImpl implements ReflectionOptimizer, Serializable {
private transient InstantiationOptimizerAdapter instantiationOptimizer;
private transient AccessOptimizerAdapter accessOptimizer;
public ReflectionOptimizerImpl(
InstantiationOptimizerAdapter instantiationOptimizer,
AccessOptimizerAdapter accessOptimizer) {
this.instantiationOptimizer = instantiationOptimizer;
this.accessOptimizer = accessOptimizer;
}
public InstantiationOptimizer getInstantiationOptimizer() {
return instantiationOptimizer;
}
public AccessOptimizer getAccessOptimizer() {
return accessOptimizer;
}
}

View File

@ -594,8 +594,6 @@ public final class Environment {
LOG.version(Version.getVersionString()); LOG.version(Version.getVersionString());
RENAMED_PROPERTIES.put( "hibernate.cglib.use_reflection_optimizer", USE_REFLECTION_OPTIMIZER );
ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_NONE), "NONE" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_NONE), "NONE" );
ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_READ_UNCOMMITTED), "READ_UNCOMMITTED" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_READ_UNCOMMITTED), "READ_UNCOMMITTED" );
ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_READ_COMMITTED), "READ_COMMITTED" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_READ_COMMITTED), "READ_COMMITTED" );
@ -800,9 +798,6 @@ public final class Environment {
if ( "javassist".equals( providerName ) ) { if ( "javassist".equals( providerName ) ) {
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl(); return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
} }
else if ( "cglib".equals( providerName ) ) {
return new org.hibernate.bytecode.cglib.BytecodeProviderImpl();
}
LOG.unknownBytecodeProvider( providerName ); LOG.unknownBytecodeProvider( providerName );
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl(); return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();

View File

@ -252,18 +252,15 @@ public class SettingsFactory implements Serializable {
} }
protected BytecodeProvider buildBytecodeProvider(String providerName) { // protected BytecodeProvider buildBytecodeProvider(String providerName) {
if ( "javassist".equals( providerName ) ) { // if ( "javassist".equals( providerName ) ) {
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl(); // return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
} // }
else if ( "cglib".equals( providerName ) ) { // else {
return new org.hibernate.bytecode.cglib.BytecodeProviderImpl(); // LOG.debugf("Using javassist as bytecode provider by default");
} // return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
else { // }
LOG.debugf("Using javassist as bytecode provider by default"); // }
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
}
}
private static String enabledDisabled(boolean value) { private static String enabledDisabled(boolean value) {
return value ? "enabled" : "disabled"; return value ? "enabled" : "disabled";

View File

@ -25,7 +25,6 @@
package org.hibernate.intercept; package org.hibernate.intercept;
import java.util.Set; import java.util.Set;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.cglib.CGLIBHelper;
import org.hibernate.intercept.javassist.JavassistHelper; import org.hibernate.intercept.javassist.JavassistHelper;
/** /**
@ -66,11 +65,7 @@ public class FieldInterceptionHelper {
} }
Class[] definedInterfaces = entity.getClass().getInterfaces(); Class[] definedInterfaces = entity.getClass().getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) { for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "net.sf.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) ) { if ( "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
// we have a CGLIB enhanced entity
return CGLIBHelper.extractFieldInterceptor( entity );
}
else if ( "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
// we have a Javassist enhanced entity // we have a Javassist enhanced entity
return JavassistHelper.extractFieldInterceptor( entity ); return JavassistHelper.extractFieldInterceptor( entity );
} }
@ -86,11 +81,7 @@ public class FieldInterceptionHelper {
if ( entity != null ) { if ( entity != null ) {
Class[] definedInterfaces = entity.getClass().getInterfaces(); Class[] definedInterfaces = entity.getClass().getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) { for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "net.sf.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) ) { if ( "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
// we have a CGLIB enhanced entity
return CGLIBHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session );
}
else if ( "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
// we have a Javassist enhanced entity // we have a Javassist enhanced entity
return JavassistHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session ); return JavassistHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session );
} }

View File

@ -1,54 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.intercept.cglib;
import java.util.Set;
import net.sf.cglib.transform.impl.InterceptFieldEnabled;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.FieldInterceptor;
/**
* @author Steve Ebersole
*/
public class CGLIBHelper {
private CGLIBHelper() {
}
public static FieldInterceptor extractFieldInterceptor(Object entity) {
return ( FieldInterceptor ) ( ( InterceptFieldEnabled ) entity ).getInterceptFieldCallback();
}
public static FieldInterceptor injectFieldInterceptor(
Object entity,
String entityName,
Set uninitializedFieldNames,
SessionImplementor session) {
FieldInterceptorImpl fieldInterceptor = new FieldInterceptorImpl(
session, uninitializedFieldNames, entityName
);
( ( InterceptFieldEnabled ) entity ).setInterceptFieldCallback( fieldInterceptor );
return fieldInterceptor;
}
}

View File

@ -1,167 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* 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.intercept.cglib;
import java.io.Serializable;
import java.util.Set;
import net.sf.cglib.transform.impl.InterceptFieldCallback;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.AbstractFieldInterceptor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
/**
* A field-level interceptor that initializes lazily fetched properties.
* This interceptor can be attached to classes instrumented by CGLIB.
* Note that this implementation assumes that the instance variable
* name is the same as the name of the persistent property that must
* be loaded.
*
* @author Gavin King
*/
public final class FieldInterceptorImpl extends AbstractFieldInterceptor implements InterceptFieldCallback, Serializable {
/**
* Package-protected constructor
*
* @param session The Hibernate session
* @param uninitializedFields Names of the fields we need to initialize on load
* @param entityName The entity name to which we are being bound
*/
FieldInterceptorImpl(SessionImplementor session, Set uninitializedFields, String entityName) {
super( session, uninitializedFields, entityName );
}
public boolean readBoolean(Object target, String name, boolean oldValue) {
return ( ( Boolean ) intercept( target, name, oldValue ? Boolean.TRUE : Boolean.FALSE ) )
.booleanValue();
}
public byte readByte(Object target, String name, byte oldValue) {
return ( ( Byte ) intercept( target, name, new Byte( oldValue ) ) ).byteValue();
}
public char readChar(Object target, String name, char oldValue) {
return ( ( Character ) intercept( target, name, new Character( oldValue ) ) )
.charValue();
}
public double readDouble(Object target, String name, double oldValue) {
return ( ( Double ) intercept( target, name, new Double( oldValue ) ) )
.doubleValue();
}
public float readFloat(Object target, String name, float oldValue) {
return ( ( Float ) intercept( target, name, new Float( oldValue ) ) )
.floatValue();
}
public int readInt(Object target, String name, int oldValue) {
return ( ( Integer ) intercept( target, name, new Integer( oldValue ) ) )
.intValue();
}
public long readLong(Object target, String name, long oldValue) {
return ( ( Long ) intercept( target, name, new Long( oldValue ) ) ).longValue();
}
public short readShort(Object target, String name, short oldValue) {
return ( ( Short ) intercept( target, name, new Short( oldValue ) ) )
.shortValue();
}
public Object readObject(Object target, String name, Object oldValue) {
Object value = intercept( target, name, oldValue );
if (value instanceof HibernateProxy) {
LazyInitializer li = ( (HibernateProxy) value ).getHibernateLazyInitializer();
if ( li.isUnwrap() ) {
value = li.getImplementation();
}
}
return value;
}
public boolean writeBoolean(Object target, String name, boolean oldValue, boolean newValue) {
dirty();
intercept( target, name, oldValue ? Boolean.TRUE : Boolean.FALSE );
return newValue;
}
public byte writeByte(Object target, String name, byte oldValue, byte newValue) {
dirty();
intercept( target, name, new Byte( oldValue ) );
return newValue;
}
public char writeChar(Object target, String name, char oldValue, char newValue) {
dirty();
intercept( target, name, new Character( oldValue ) );
return newValue;
}
public double writeDouble(Object target, String name, double oldValue, double newValue) {
dirty();
intercept( target, name, new Double( oldValue ) );
return newValue;
}
public float writeFloat(Object target, String name, float oldValue, float newValue) {
dirty();
intercept( target, name, new Float( oldValue ) );
return newValue;
}
public int writeInt(Object target, String name, int oldValue, int newValue) {
dirty();
intercept( target, name, new Integer( oldValue ) );
return newValue;
}
public long writeLong(Object target, String name, long oldValue, long newValue) {
dirty();
intercept( target, name, new Long( oldValue ) );
return newValue;
}
public short writeShort(Object target, String name, short oldValue, short newValue) {
dirty();
intercept( target, name, new Short( oldValue ) );
return newValue;
}
public Object writeObject(Object target, String name, Object oldValue, Object newValue) {
dirty();
intercept( target, name, oldValue );
return newValue;
}
public String toString() {
return "FieldInterceptorImpl(" +
"entityName=" + getEntityName() +
",dirty=" + isDirty() +
",uninitializedFields=" + getUninitializedFields() +
')';
}
}

View File

@ -1,237 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @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.proxy.pojo.cglib;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;
import net.sf.cglib.proxy.NoOp;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.LazyInitializationException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.pojo.BasicLazyInitializer;
import org.hibernate.type.CompositeType;
import org.jboss.logging.Logger;
/**
* A <tt>LazyInitializer</tt> implemented using the CGLIB bytecode generation library
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public final class CGLIBLazyInitializer extends BasicLazyInitializer implements InvocationHandler {
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, CGLIBLazyInitializer.class.getName());
private static final CallbackFilter FINALIZE_FILTER = new CallbackFilter() {
public int accept(Method method) {
if ( method.getParameterTypes().length == 0 && method.getName().equals("finalize") ){
return 1;
}
else {
return 0;
}
}
};
private Class[] interfaces;
private boolean constructed = false;
static HibernateProxy getProxy(
final String entityName,
final Class persistentClass,
final Class[] interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
CompositeType componentIdType,
final Serializable id,
final SessionImplementor session) throws HibernateException {
// note: interfaces is assumed to already contain HibernateProxy.class
try {
final CGLIBLazyInitializer instance = new CGLIBLazyInitializer(
entityName,
persistentClass,
interfaces,
id,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
session
);
final HibernateProxy proxy;
Class factory = getProxyFactory(persistentClass, interfaces);
proxy = getProxyInstance(factory, instance);
instance.constructed = true;
return proxy;
}
catch (Throwable t) {
LOG.error(LOG.cglibEnhancementFailed(entityName), t);
throw new HibernateException(LOG.cglibEnhancementFailed(entityName), t);
}
}
public static HibernateProxy getProxy(
final Class factory,
final String entityName,
final Class persistentClass,
final Class[] interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
final CompositeType componentIdType,
final Serializable id,
final SessionImplementor session) throws HibernateException {
final CGLIBLazyInitializer instance = new CGLIBLazyInitializer(
entityName,
persistentClass,
interfaces,
id,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
session
);
final HibernateProxy proxy;
try {
proxy = getProxyInstance(factory, instance);
}
catch (Exception e) {
throw new HibernateException( "CGLIB Enhancement failed: " + persistentClass.getName(), e );
}
instance.constructed = true;
return proxy;
}
private static HibernateProxy getProxyInstance(Class factory, CGLIBLazyInitializer instance) throws InstantiationException, IllegalAccessException {
HibernateProxy proxy;
try {
Enhancer.registerCallbacks(factory, new Callback[]{ instance, null });
proxy = (HibernateProxy)factory.newInstance();
} finally {
// HHH-2481 make sure the callback gets cleared, otherwise the instance stays in a static thread local.
Enhancer.registerCallbacks(factory, null);
}
return proxy;
}
public static Class getProxyFactory(Class persistentClass, Class[] interfaces)
throws HibernateException {
Enhancer e = new Enhancer();
e.setSuperclass( interfaces.length == 1 ? persistentClass : null );
e.setInterfaces(interfaces);
e.setCallbackTypes(new Class[]{
InvocationHandler.class,
NoOp.class,
});
e.setCallbackFilter(FINALIZE_FILTER);
e.setUseFactory(false);
e.setInterceptDuringConstruction( false );
return e.createClass();
}
private CGLIBLazyInitializer(
final String entityName,
final Class persistentClass,
final Class[] interfaces,
final Serializable id,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
final CompositeType componentIdType,
final SessionImplementor session) {
super(
entityName,
persistentClass,
id,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
session
);
this.interfaces = interfaces;
}
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if ( constructed ) {
Object result = invoke( method, args, proxy );
if ( result == INVOKE_IMPLEMENTATION ) {
Object target = getImplementation();
try {
final Object returnValue;
if ( ReflectHelper.isPublic( persistentClass, method ) ) {
if ( !method.getDeclaringClass().isInstance( target ) ) {
throw new ClassCastException( target.getClass().getName() );
}
returnValue = method.invoke( target, args );
}
else {
if ( !method.isAccessible() ) {
method.setAccessible( true );
}
returnValue = method.invoke( target, args );
}
return returnValue == target ? proxy : returnValue;
}
catch ( InvocationTargetException ite ) {
throw ite.getTargetException();
}
}
else {
return result;
}
}
else {
// while constructor is running
if ( method.getName().equals( "getHibernateLazyInitializer" ) ) {
return this;
}
else {
throw new LazyInitializationException( "unexpected case hit, method=" + method.getName() );
}
}
}
@Override
protected Object serializableProxy() {
return new SerializableProxy(
getEntityName(),
persistentClass,
interfaces,
getIdentifier(),
( isReadOnlySettingAvailable() ? Boolean.valueOf( isReadOnly() ) : isReadOnlyBeforeAttachedToSession() ),
getIdentifierMethod,
setIdentifierMethod,
componentIdType
);
}
}

View File

@ -1,85 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @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.proxy.pojo.cglib;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.type.CompositeType;
/**
* @author Gavin King
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public class CGLIBProxyFactory implements ProxyFactory {
protected static final Class[] NO_CLASSES = new Class[0];
private Class persistentClass;
private String entityName;
private Class[] interfaces;
private Method getIdentifierMethod;
private Method setIdentifierMethod;
private CompositeType componentIdType;
private Class factory;
public void postInstantiate(
final String entityName,
final Class persistentClass,
final Set interfaces,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
CompositeType componentIdType)
throws HibernateException {
this.entityName = entityName;
this.persistentClass = persistentClass;
this.interfaces = (Class[]) interfaces.toArray(NO_CLASSES);
this.getIdentifierMethod = getIdentifierMethod;
this.setIdentifierMethod = setIdentifierMethod;
this.componentIdType = componentIdType;
factory = CGLIBLazyInitializer.getProxyFactory(persistentClass, this.interfaces);
}
public HibernateProxy getProxy(Serializable id, SessionImplementor session)
throws HibernateException {
return CGLIBLazyInitializer.getProxy(
factory,
entityName,
persistentClass,
interfaces,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
id,
session
);
}
}

View File

@ -1,101 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @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.proxy.pojo.cglib;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.hibernate.HibernateException;
import org.hibernate.proxy.AbstractSerializableProxy;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.CompositeType;
/**
* Serializable placeholder for <tt>CGLIB</tt> proxies
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
@Deprecated
public final class SerializableProxy extends AbstractSerializableProxy {
private Class persistentClass;
private Class[] interfaces;
private Class getIdentifierMethodClass;
private Class setIdentifierMethodClass;
private String getIdentifierMethodName;
private String setIdentifierMethodName;
private Class[] setIdentifierMethodParams;
private CompositeType componentIdType;
public SerializableProxy() {
}
public SerializableProxy(
final String entityName,
final Class persistentClass,
final Class[] interfaces,
final Serializable id,
final Boolean readOnly,
final Method getIdentifierMethod,
final Method setIdentifierMethod,
CompositeType componentIdType) {
super( entityName, id, readOnly );
this.persistentClass = persistentClass;
this.interfaces = interfaces;
if (getIdentifierMethod!=null) {
getIdentifierMethodClass = getIdentifierMethod.getDeclaringClass();
getIdentifierMethodName = getIdentifierMethod.getName();
}
if (setIdentifierMethod!=null) {
setIdentifierMethodClass = setIdentifierMethod.getDeclaringClass();
setIdentifierMethodName = setIdentifierMethod.getName();
setIdentifierMethodParams = setIdentifierMethod.getParameterTypes();
}
this.componentIdType = componentIdType;
}
private Object readResolve() {
try {
HibernateProxy proxy = CGLIBLazyInitializer.getProxy(
getEntityName(),
persistentClass,
interfaces,
getIdentifierMethodName==null
? null
: getIdentifierMethodClass.getDeclaredMethod( getIdentifierMethodName, (Class[]) null ),
setIdentifierMethodName==null
? null
: setIdentifierMethodClass.getDeclaredMethod(setIdentifierMethodName, setIdentifierMethodParams),
componentIdType,
getId(),
null
);
setReadOnlyBeforeAttachedToSession( ( CGLIBLazyInitializer ) proxy.getHibernateLazyInitializer() );
return proxy;
}
catch (NoSuchMethodException nsme) {
throw new HibernateException("could not create proxy for entity: " + getEntityName(), nsme);
}
}
}

View File

@ -1,79 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @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.tool.instrument.cglib;
import org.hibernate.bytecode.buildtime.CGLIBInstrumenter;
import org.hibernate.bytecode.buildtime.Instrumenter;
import org.hibernate.bytecode.buildtime.Logger;
import org.hibernate.tool.instrument.BasicInstrumentationTask;
/**
* An Ant task for instrumenting persistent classes in order to enable
* field-level interception using CGLIB.
* <p/>
* In order to use this task, typically you would define a a taskdef
* similar to:<pre>
* <taskdef name="instrument" classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
* <classpath refid="lib.class.path"/>
* </taskdef>
* </pre>
* where <tt>lib.class.path</tt> is an ANT path reference containing all the
* required Hibernate and CGLIB libraries.
* <p/>
* And then use it like:<pre>
* <instrument>
* <fileset dir="${testclasses.dir}/org/hibernate/test">
* <include name="yadda/yadda/**"/>
* ...
* </fileset>
* </instrument>
* </pre>
* where the nested ANT fileset includes the class you would like to have
* instrumented.
* <p/>
* Optionally you can chose to enable "Extended Instrumentation" if desired
* by specifying the extended attribute on the task:<pre>
* <instrument extended="true">
* ...
* </instrument>
* </pre>
* See the Hibernate manual regarding this option.
*
* @author Gavin King
* @author Steve Ebersole
*
* @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated; use
* {@link org.hibernate.tool.instrument.javassist.InstrumentTask} instead
*/
@Deprecated
public class InstrumentTask extends BasicInstrumentationTask {
public InstrumentTask() {
System.err.println( "Per HHH-5451 support for cglib as a bytecode provider has been deprecated." );
}
@Override
protected Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options) {
return new CGLIBInstrumenter( logger, options );
}
}

View File

@ -1,102 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @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.test.bytecode.cglib;
import java.lang.reflect.Field;
import org.hibernate.Session;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
import org.hibernate.cfg.Environment;
import org.hibernate.proxy.HibernateProxy;
import org.junit.Test;
import org.hibernate.testing.Skip;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.bytecode.ProxyBean;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Test that the static thread local callback object is cleared out of the proxy class after instantiated.
* This tests that the memory leak reported by HHH-2481 hasn't been re-introduced.
*
* @author Paul Malolepsy
*/
@TestForIssue(jiraKey = "HHH-2481")
public class CGLIBThreadLocalTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() {
return new String[] {"bytecode/Bean.hbm.xml"};
}
public static class LocalSkipCheck implements Skip.Matcher {
@Override
public boolean isMatch() {
return !BytecodeProviderImpl.class.isInstance( Environment.getBytecodeProvider() );
}
}
@Test
@Skip(
condition = LocalSkipCheck.class,
message = "Environment not configured for CGLIB bytecode provider"
)
public void testCglibClearing() {
//create the object for the test
Session s = openSession();
s.beginTransaction();
ProxyBean proxyBean = new ProxyBean();
proxyBean.setSomeString( "my-bean" );
proxyBean.setSomeLong( 1234 );
s.save( proxyBean );
s.getTransaction().commit();
s.close();
// read the object as a proxy
s = openSession();
s.beginTransaction();
proxyBean = (ProxyBean) s.load( ProxyBean.class, proxyBean.getSomeString() );
assertTrue( proxyBean instanceof HibernateProxy );
try {
//check that the static thread callbacks thread local has been cleared out
Field field = proxyBean.getClass().getDeclaredField( "CGLIB$THREAD_CALLBACKS" );
field.setAccessible( true );
ThreadLocal threadCallbacksThreadLocal = (ThreadLocal) field.get( null );
assertTrue( threadCallbacksThreadLocal.get() == null );
}
catch (NoSuchFieldException e1) {
fail( "unable to find CGLIB$THREAD_CALLBACKS field in proxy." );
}
catch (Throwable t) {
fail( "unexpected exception type : " + t );
}
finally {
//clean up
s.delete( proxyBean );
s.getTransaction().commit();
s.close();
}
}
}

View File

@ -1,93 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @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.test.bytecode.cglib;
import java.text.ParseException;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
import org.hibernate.cfg.Environment;
import org.junit.Test;
import org.hibernate.testing.Skip;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.bytecode.Bean;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
/**
* Test that the Javassist-based lazy initializer properly handles InvocationTargetExceptions
*
* @author Steve Ebersole
*/
@Skip(
condition = InvocationTargetExceptionTest.LocalSkipMatcher.class,
message = "environment not configured for cglib bytecode provider"
)
public class InvocationTargetExceptionTest extends BaseCoreFunctionalTestCase {
public static class LocalSkipMatcher implements Skip.Matcher {
@Override
public boolean isMatch() {
return ! BytecodeProviderImpl.class.isInstance( Environment.getBytecodeProvider() );
}
}
@Override
public String[] getMappings() {
return new String[] { "bytecode/Bean.hbm.xml" };
}
@Test
public void testProxiedInvocationException() {
Session s = openSession();
s.beginTransaction();
Bean bean = new Bean();
bean.setSomeString( "my-bean" );
s.save( bean );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
bean = ( Bean ) s.load( Bean.class, bean.getSomeString() );
assertFalse( Hibernate.isInitialized( bean ) );
try {
bean.throwException();
fail( "exception not thrown" );
}
catch ( ParseException e ) {
// expected behavior
}
catch( Throwable t ) {
fail( "unexpected exception type : " + t );
}
s.delete( bean );
s.getTransaction().commit();
s.close();
}
}

View File

@ -1,71 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @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.test.bytecode.cglib;
import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.bytecode.Bean;
import org.hibernate.test.bytecode.BeanReflectionHelper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Steve Ebersole
*/
public class ReflectionOptimizerTest extends BaseUnitTestCase {
@Test
public void testReflectionOptimization() {
BytecodeProviderImpl provider = new BytecodeProviderImpl();
ReflectionOptimizer optimizer = provider.getReflectionOptimizer(
Bean.class,
BeanReflectionHelper.getGetterNames(),
BeanReflectionHelper.getSetterNames(),
BeanReflectionHelper.getTypes()
);
assertNotNull( optimizer );
assertNotNull( optimizer.getInstantiationOptimizer() );
assertNotNull( optimizer.getAccessOptimizer() );
Object instance = optimizer.getInstantiationOptimizer().newInstance();
assertEquals( instance.getClass(), Bean.class );
Bean bean = ( Bean ) instance;
optimizer.getAccessOptimizer().setPropertyValues( bean, BeanReflectionHelper.TEST_VALUES );
assertEquals( bean.getSomeString(), BeanReflectionHelper.TEST_VALUES[0] );
Object[] values = optimizer.getAccessOptimizer().getPropertyValues( bean );
assertEquivalent( values, BeanReflectionHelper.TEST_VALUES );
}
private void assertEquivalent(Object[] checkValues, Object[] values) {
assertEquals( "Different lengths", checkValues.length, values.length );
for ( int i = 0; i < checkValues.length; i++ ) {
assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] );
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @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.test.instrument.runtime;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
/**
* @author Steve Ebersole
*/
public class CGLIBInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl();
}
}