HHH-6026 - Migrate bytecode provider integrations to api/spi/internal split

This commit is contained in:
Steve Ebersole 2011-03-18 15:51:43 -05:00
parent 82d2ef4b1f
commit 19791a6c7d
78 changed files with 3351 additions and 3297 deletions

View File

@ -24,14 +24,15 @@
package org.hibernate; package org.hibernate;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.collection.PersistentCollection; import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.HibernateIterator; import org.hibernate.engine.HibernateIterator;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.intercept.FieldInterceptor;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.AnyType; import org.hibernate.type.AnyType;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,18 +21,22 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.bytecode.buildtime; package org.hibernate.bytecode.buildtime.internal;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
import javassist.bytecode.ClassFile; import javassist.bytecode.ClassFile;
import org.hibernate.bytecode.ClassTransformer;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl; import org.hibernate.bytecode.buildtime.spi.AbstractInstrumenter;
import org.hibernate.bytecode.javassist.FieldHandled; import org.hibernate.bytecode.buildtime.spi.BasicClassFilter;
import org.hibernate.bytecode.util.BasicClassFilter; import org.hibernate.bytecode.buildtime.spi.ClassDescriptor;
import org.hibernate.bytecode.util.ClassDescriptor; import org.hibernate.bytecode.buildtime.spi.Logger;
import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
import org.hibernate.bytecode.internal.javassist.FieldHandled;
import org.hibernate.bytecode.spi.ClassTransformer;
/** /**
* Strategy for performing build-time instrumentation of persistent classes in order to enable * Strategy for performing build-time instrumentation of persistent classes in order to enable
@ -81,9 +85,9 @@ public class JavassistInstrumenter extends AbstractInstrumenter {
} }
public boolean isInstrumented() { public boolean isInstrumented() {
String[] intfs = classFile.getInterfaces(); String[] interfaceNames = classFile.getInterfaces();
for ( int i = 0; i < intfs.length; i++ ) { for ( String interfaceName : interfaceNames ) {
if ( FieldHandled.class.getName().equals( intfs[i] ) ) { if ( FieldHandled.class.getName().equals( interfaceName ) ) {
return true; return true;
} }
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.bytecode.buildtime; package org.hibernate.bytecode.buildtime.spi;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -31,16 +31,14 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.hibernate.bytecode.ClassTransformer;
import org.hibernate.bytecode.util.ByteCodeHelper; import org.hibernate.bytecode.spi.ByteCodeHelper;
import org.hibernate.bytecode.util.ClassDescriptor; import org.hibernate.bytecode.spi.ClassTransformer;
import org.hibernate.bytecode.util.FieldFilter;
/** /**
* Provides the basic templating of how instrumentation should occur. * Provides the basic templating of how instrumentation should occur.
@ -93,15 +91,14 @@ public abstract class AbstractInstrumenter implements Instrumenter {
* *
* @param files The files. * @param files The files.
*/ */
public void execute(Set files) { public void execute(Set<File> files) {
Set classNames = new HashSet(); Set<String> classNames = new HashSet<String>();
if ( options.performExtendedInstrumentation() ) { if ( options.performExtendedInstrumentation() ) {
logger.debug( "collecting class names for extended instrumentation determination" ); logger.debug( "collecting class names for extended instrumentation determination" );
try { try {
Iterator itr = files.iterator(); for ( Object file1 : files ) {
while ( itr.hasNext() ) { final File file = (File) file1;
final File file = ( File ) itr.next();
collectClassNames( file, classNames ); collectClassNames( file, classNames );
} }
} }
@ -115,9 +112,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
logger.info( "starting instrumentation" ); logger.info( "starting instrumentation" );
try { try {
Iterator itr = files.iterator(); for ( File file : files ) {
while ( itr.hasNext() ) {
final File file = ( File ) itr.next();
processFile( file, classNames ); processFile( file, classNames );
} }
} }
@ -140,7 +135,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
* *
* @throws Exception indicates problems accessing the file or its contents. * @throws Exception indicates problems accessing the file or its contents.
*/ */
private void collectClassNames(File file, final Set classNames) throws Exception { private void collectClassNames(File file, final Set<String> classNames) throws Exception {
if ( isClassFile( file ) ) { if ( isClassFile( file ) ) {
byte[] bytes = ByteCodeHelper.readByteCode( file ); byte[] bytes = ByteCodeHelper.readByteCode( file );
ClassDescriptor descriptor = getClassDescriptor( bytes ); ClassDescriptor descriptor = getClassDescriptor( bytes );
@ -211,7 +206,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
* *
* @throws Exception Indicates an issue either access files or applying the transformations. * @throws Exception Indicates an issue either access files or applying the transformations.
*/ */
protected void processFile(File file, Set classNames) throws Exception { protected void processFile(File file, Set<String> classNames) throws Exception {
if ( isClassFile( file ) ) { if ( isClassFile( file ) ) {
logger.debug( "processing class file : " + file.getAbsolutePath() ); logger.debug( "processing class file : " + file.getAbsolutePath() );
processClassFile( file, classNames ); processClassFile( file, classNames );
@ -234,7 +229,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
* *
* @throws Exception Indicates an issue either access files or applying the transformations. * @throws Exception Indicates an issue either access files or applying the transformations.
*/ */
protected void processClassFile(File file, Set classNames) throws Exception { protected void processClassFile(File file, Set<String> classNames) throws Exception {
byte[] bytes = ByteCodeHelper.readByteCode( file ); byte[] bytes = ByteCodeHelper.readByteCode( file );
ClassDescriptor descriptor = getClassDescriptor( bytes ); ClassDescriptor descriptor = getClassDescriptor( bytes );
ClassTransformer transformer = getClassTransformer( descriptor, classNames ); ClassTransformer transformer = getClassTransformer( descriptor, classNames );
@ -276,7 +271,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
* *
* @throws Exception Indicates an issue either access files or applying the transformations. * @throws Exception Indicates an issue either access files or applying the transformations.
*/ */
protected void processJarFile(final File file, final Set classNames) throws Exception { protected void processJarFile(final File file, final Set<String> classNames) throws Exception {
File tempFile = File.createTempFile( File tempFile = File.createTempFile(
file.getName(), file.getName(),
null, null,
@ -406,9 +401,9 @@ public abstract class AbstractInstrumenter implements Instrumenter {
* Apply strategy to the given archive entry. * Apply strategy to the given archive entry.
* *
* @param entry The archive file entry. * @param entry The archive file entry.
* @param byteCode * @param byteCode The bytes making up the entry
* *
* @throws Exception * @throws Exception Problem handling entry
*/ */
public void handleEntry(ZipEntry entry, byte[] byteCode) throws Exception; public void handleEntry(ZipEntry entry, byte[] byteCode) throws Exception;
} }

View File

@ -1,82 +1,72 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.buildtime.spi;
package org.hibernate.bytecode.util;
import java.util.HashSet; import java.util.Arrays;
import java.util.Set; import java.util.HashSet;
import java.util.Set;
/**
* BasicClassFilter provides class filtering based on a series of packages to /**
* be included and/or a series of explicit class names to be included. If * BasicClassFilter provides class filtering based on a series of packages to
* neither is specified, then no restrictions are applied. * be included and/or a series of explicit class names to be included. If
* * neither is specified, then no restrictions are applied.
* @author Steve Ebersole *
*/ * @author Steve Ebersole
public class BasicClassFilter implements ClassFilter { */
private final String[] includedPackages; public class BasicClassFilter implements ClassFilter {
private final Set includedClassNames = new HashSet(); private final String[] includedPackages;
private final boolean isAllEmpty; private final Set<String> includedClassNames = new HashSet<String>();
private final boolean isAllEmpty;
public BasicClassFilter() {
this( null, null ); public BasicClassFilter() {
} this( null, null );
}
public BasicClassFilter(String[] includedPackages, String[] includedClassNames) {
this.includedPackages = includedPackages; public BasicClassFilter(String[] includedPackages, String[] includedClassNames) {
if ( includedClassNames != null ) { this.includedPackages = includedPackages;
for ( int i = 0; i < includedClassNames.length; i++ ) { if ( includedClassNames != null ) {
this.includedClassNames.add( includedClassNames[i] ); this.includedClassNames.addAll( Arrays.asList( includedClassNames ) );
} }
}
isAllEmpty = ( this.includedPackages == null || this.includedPackages.length == 0 )
isAllEmpty = ( this.includedPackages == null || this.includedPackages.length == 0 ) && ( this.includedClassNames.isEmpty() );
&& ( this.includedClassNames.isEmpty() ); }
}
public boolean shouldInstrumentClass(String className) {
public boolean shouldInstrumentClass(String className) { return isAllEmpty ||
if ( isAllEmpty ) { includedClassNames.contains( className ) ||
return true; isInIncludedPackage( className );
} }
else if ( includedClassNames.contains( className ) ) {
return true; private boolean isInIncludedPackage(String className) {
} if ( includedPackages != null ) {
else if ( isInIncludedPackage( className ) ) { for ( String includedPackage : includedPackages ) {
return true; if ( className.startsWith( includedPackage ) ) {
} return true;
else { }
return false; }
} }
} return false;
}
private boolean isInIncludedPackage(String className) { }
if ( includedPackages != null ) {
for ( int i = 0; i < includedPackages.length; i++ ) {
if ( className.startsWith( includedPackages[i] ) ) {
return true;
}
}
}
return false;
}
}

View File

@ -1,55 +1,53 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.buildtime.spi;
package org.hibernate.bytecode.util;
/**
* Contract describing the information Hibernate needs in terms of instrumenting
/** * a class, either via ant task or dynamic classloader.
* Contract describing the information Hibernate needs in terms of instrumenting *
* a class, either via ant task or dynamic classloader. * @author Steve Ebersole
* */
* @author Steve Ebersole public interface ClassDescriptor {
*/ /**
public interface ClassDescriptor { * The name of the class.
/** *
* The name of the class. * @return The class name.
* */
* @return The class name. public String getName();
*/
public String getName(); /**
* Determine if the class is already instrumented.
/** *
* Determine if the class is already instrumented. * @return True if already instrumented; false otherwise.
* */
* @return True if already instrumented; false otherwise. public boolean isInstrumented();
*/
public boolean isInstrumented(); /**
* The bytes making up the class' bytecode.
/** *
* The bytes making up the class' bytecode. * @return The bytecode bytes.
* */
* @return The bytecode bytes. public byte[] getBytes();
*/ }
public byte[] getBytes();
}

View File

@ -1,35 +1,40 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.buildtime.spi;
package org.hibernate.bytecode.util;
/**
* Used to determine whether a class should be instrumented.
/** *
* Used to determine whether a class should be instrumented. * @author Steve Ebersole
* */
* @author Steve Ebersole public interface ClassFilter {
*/ /**
public interface ClassFilter { * Should this class be included in instrumentation
public boolean shouldInstrumentClass(String className); *
} * @param className The name of the class to check
*
* @return {@literal true} to include class in instrumentation; {@literal false} otherwise.
*/
public boolean shouldInstrumentClass(String className);
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,14 +21,14 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.bytecode.buildtime; package org.hibernate.bytecode.buildtime.spi;
/** /**
* Indicates problem performing the instrumentation execution. * Indicates problem performing the instrumentation execution.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings( {"UnusedDeclaration"})
public class ExecutionException extends RuntimeException { public class ExecutionException extends RuntimeException {
public ExecutionException(String message) { public ExecutionException(String message) {
super( message ); super( message );

View File

@ -1,54 +1,52 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.buildtime.spi;
package org.hibernate.bytecode.util;
/**
* Used to determine whether a field reference should be instrumented.
/** *
* Used to determine whether a field reference should be instrumented. * @author Steve Ebersole
* */
* @author Steve Ebersole public interface FieldFilter {
*/ /**
public interface FieldFilter { * Should this field definition be instrumented?
/** *
* Should this field definition be instrumented? * @param className The name of the class currently being processed
* * @param fieldName The name of the field being checked.
* @param className The name of the class currently being processed * @return True if we should instrument this field.
* @param fieldName The name of the field being checked. */
* @return True if we should instrument this field. public boolean shouldInstrumentField(String className, String fieldName);
*/
public boolean shouldInstrumentField(String className, String fieldName); /**
* Should we instrument *access to* the given field. This differs from
/** * {@link #shouldInstrumentField} in that here we are talking about a particular usage of
* Should we instrument *access to* the given field. This differs from * a field.
* {@link #shouldInstrumentField} in that here we are talking about a particular usage of *
* a field. * @param transformingClassName The class currently being transformed.
* * @param fieldOwnerClassName The name of the class owning this field being checked.
* @param transformingClassName The class currently being transformed. * @param fieldName The name of the field being checked.
* @param fieldOwnerClassName The name of the class owning this field being checked. * @return True if this access should be transformed.
* @param fieldName The name of the field being checked. */
* @return True if this access should be transformed. public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName);
*/ }
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName);
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,18 +21,33 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.bytecode.buildtime; package org.hibernate.bytecode.buildtime.spi;
import java.io.File;
import java.util.Set; import java.util.Set;
/** /**
* TODO : javadoc * Basic contract for performing instrumentation
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface Instrumenter { public interface Instrumenter {
public void execute(Set files); /**
* Perform the instrumentation
*
* @param files The file on which to perform instrumentation
*/
public void execute(Set<File> files);
/**
* Instrumentation options
*/
public static interface Options { public static interface Options {
/**
* Should we enhance references to class fields outside the class itself?
*
* @return {@literal true}/{@literal false}
*/
public boolean performExtendedInstrumentation(); public boolean performExtendedInstrumentation();
} }
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.bytecode.buildtime; package org.hibernate.bytecode.buildtime.spi;
/** /**
* Provides an abstraction for how instrumentation does logging because it is usually run in environments (Ant/Maven) * Provides an abstraction for how instrumentation does logging because it is usually run in environments (Ant/Maven)

View File

@ -0,0 +1,154 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008-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.bytecode.instrumentation.internal;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.bytecode.instrumentation.internal.javassist.JavassistHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.engine.SessionImplementor;
/**
* Helper class for dealing with enhanced entity classes.
*
* @author Steve Ebersole
*/
public class FieldInterceptionHelper {
private static final Set<Delegate> INSTRUMENTATION_DELEGATES = buildInstrumentationDelegates();
private static Set<Delegate> buildInstrumentationDelegates() {
HashSet<Delegate> delegates = new HashSet<Delegate>();
delegates.add( JavassistDelegate.INSTANCE );
return delegates;
}
private FieldInterceptionHelper() {
}
public static boolean isInstrumented(Class entityClass) {
for ( Delegate delegate : INSTRUMENTATION_DELEGATES ) {
if ( delegate.isInstrumented( entityClass ) ) {
return true;
}
}
return false;
}
public static boolean isInstrumented(Object entity) {
return entity != null && isInstrumented( entity.getClass() );
}
public static FieldInterceptor extractFieldInterceptor(Object entity) {
if ( entity == null ) {
return null;
}
FieldInterceptor interceptor = null;
for ( Delegate delegate : INSTRUMENTATION_DELEGATES ) {
interceptor = delegate.extractInterceptor( entity );
if ( interceptor != null ) {
break;
}
}
return interceptor;
}
public static FieldInterceptor injectFieldInterceptor(
Object entity,
String entityName,
Set uninitializedFieldNames,
SessionImplementor session) {
if ( entity == null ) {
return null;
}
FieldInterceptor interceptor = null;
for ( Delegate delegate : INSTRUMENTATION_DELEGATES ) {
interceptor = delegate.injectInterceptor( entity, entityName, uninitializedFieldNames, session );
if ( interceptor != null ) {
break;
}
}
return interceptor;
}
public static void clearDirty(Object entity) {
FieldInterceptor interceptor = extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.clearDirty();
}
}
public static void markDirty(Object entity) {
FieldInterceptor interceptor = extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.dirty();
}
}
private static interface Delegate {
public boolean isInstrumented(Class classToCheck);
public FieldInterceptor extractInterceptor(Object entity);
public FieldInterceptor injectInterceptor(Object entity, String entityName, Set uninitializedFieldNames, SessionImplementor session);
}
private static class JavassistDelegate implements Delegate {
public static final JavassistDelegate INSTANCE = new JavassistDelegate();
public static final String MARKER = "org.hibernate.bytecode.internal.javassist.FieldHandled";
@Override
public boolean isInstrumented(Class classToCheck) {
for ( Class definedInterface : classToCheck.getInterfaces() ) {
if ( MARKER.equals( definedInterface.getName() ) ) {
return true;
}
}
return false;
}
@Override
public FieldInterceptor extractInterceptor(Object entity) {
for ( Class definedInterface : entity.getClass().getInterfaces() ) {
if ( MARKER.equals( definedInterface.getName() ) ) {
return JavassistHelper.extractFieldInterceptor( entity );
}
}
return null;
}
@Override
public FieldInterceptor injectInterceptor(
Object entity,
String entityName,
Set uninitializedFieldNames,
SessionImplementor session) {
for ( Class definedInterface : entity.getClass().getInterfaces() ) {
if ( MARKER.equals( definedInterface.getName() ) ) {
return JavassistHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session );
}
}
return null;
}
}
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,14 +20,15 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.intercept.javassist; package org.hibernate.bytecode.instrumentation.internal.javassist;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import org.hibernate.bytecode.javassist.FieldHandler;
import org.hibernate.bytecode.instrumentation.spi.AbstractFieldInterceptor;
import org.hibernate.bytecode.internal.javassist.FieldHandler;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.AbstractFieldInterceptor;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
@ -45,15 +46,9 @@ import org.hibernate.proxy.LazyInitializer;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings( {"UnnecessaryUnboxing", "UnnecessaryBoxing"})
public final class FieldInterceptorImpl extends AbstractFieldInterceptor implements FieldHandler, Serializable { public final class FieldInterceptorImpl extends AbstractFieldInterceptor implements FieldHandler, Serializable {
/**
* Package-protected constructor.
*
* @param session
* @param uninitializedFields
* @param entityName
*/
FieldInterceptorImpl(SessionImplementor session, Set uninitializedFields, String entityName) { FieldInterceptorImpl(SessionImplementor session, Set uninitializedFields, String entityName) {
super( session, uninitializedFields, entityName ); super( session, uninitializedFields, entityName );
} }
@ -67,35 +62,35 @@ public final class FieldInterceptorImpl extends AbstractFieldInterceptor impleme
} }
public byte readByte(Object target, String name, byte oldValue) { public byte readByte(Object target, String name, byte oldValue) {
return ( ( Byte ) intercept( target, name, new Byte( oldValue ) ) ).byteValue(); return ( ( Byte ) intercept( target, name, Byte.valueOf( oldValue ) ) ).byteValue();
} }
public char readChar(Object target, String name, char oldValue) { public char readChar(Object target, String name, char oldValue) {
return ( ( Character ) intercept( target, name, new Character( oldValue ) ) ) return ( ( Character ) intercept( target, name, Character.valueOf( oldValue ) ) )
.charValue(); .charValue();
} }
public double readDouble(Object target, String name, double oldValue) { public double readDouble(Object target, String name, double oldValue) {
return ( ( Double ) intercept( target, name, new Double( oldValue ) ) ) return ( ( Double ) intercept( target, name, Double.valueOf( oldValue ) ) )
.doubleValue(); .doubleValue();
} }
public float readFloat(Object target, String name, float oldValue) { public float readFloat(Object target, String name, float oldValue) {
return ( ( Float ) intercept( target, name, new Float( oldValue ) ) ) return ( ( Float ) intercept( target, name, Float.valueOf( oldValue ) ) )
.floatValue(); .floatValue();
} }
public int readInt(Object target, String name, int oldValue) { public int readInt(Object target, String name, int oldValue) {
return ( ( Integer ) intercept( target, name, new Integer( oldValue ) ) ) return ( ( Integer ) intercept( target, name, Integer.valueOf( oldValue ) ) )
.intValue(); .intValue();
} }
public long readLong(Object target, String name, long oldValue) { public long readLong(Object target, String name, long oldValue) {
return ( ( Long ) intercept( target, name, new Long( oldValue ) ) ).longValue(); return ( ( Long ) intercept( target, name, Long.valueOf( oldValue ) ) ).longValue();
} }
public short readShort(Object target, String name, short oldValue) { public short readShort(Object target, String name, short oldValue) {
return ( ( Short ) intercept( target, name, new Short( oldValue ) ) ) return ( ( Short ) intercept( target, name, Short.valueOf( oldValue ) ) )
.shortValue(); .shortValue();
} }
@ -118,43 +113,43 @@ public final class FieldInterceptorImpl extends AbstractFieldInterceptor impleme
public byte writeByte(Object target, String name, byte oldValue, byte newValue) { public byte writeByte(Object target, String name, byte oldValue, byte newValue) {
dirty(); dirty();
intercept( target, name, new Byte( oldValue ) ); intercept( target, name, Byte.valueOf( oldValue ) );
return newValue; return newValue;
} }
public char writeChar(Object target, String name, char oldValue, char newValue) { public char writeChar(Object target, String name, char oldValue, char newValue) {
dirty(); dirty();
intercept( target, name, new Character( oldValue ) ); intercept( target, name, Character.valueOf( oldValue ) );
return newValue; return newValue;
} }
public double writeDouble(Object target, String name, double oldValue, double newValue) { public double writeDouble(Object target, String name, double oldValue, double newValue) {
dirty(); dirty();
intercept( target, name, new Double( oldValue ) ); intercept( target, name, Double.valueOf( oldValue ) );
return newValue; return newValue;
} }
public float writeFloat(Object target, String name, float oldValue, float newValue) { public float writeFloat(Object target, String name, float oldValue, float newValue) {
dirty(); dirty();
intercept( target, name, new Float( oldValue ) ); intercept( target, name, Float.valueOf( oldValue ) );
return newValue; return newValue;
} }
public int writeInt(Object target, String name, int oldValue, int newValue) { public int writeInt(Object target, String name, int oldValue, int newValue) {
dirty(); dirty();
intercept( target, name, new Integer( oldValue ) ); intercept( target, name, Integer.valueOf( oldValue ) );
return newValue; return newValue;
} }
public long writeLong(Object target, String name, long oldValue, long newValue) { public long writeLong(Object target, String name, long oldValue, long newValue) {
dirty(); dirty();
intercept( target, name, new Long( oldValue ) ); intercept( target, name, Long.valueOf( oldValue ) );
return newValue; return newValue;
} }
public short writeShort(Object target, String name, short oldValue, short newValue) { public short writeShort(Object target, String name, short oldValue, short newValue) {
dirty(); dirty();
intercept( target, name, new Short( oldValue ) ); intercept( target, name, Short.valueOf( oldValue ) );
return newValue; return newValue;
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,13 +20,14 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.intercept.javassist; package org.hibernate.bytecode.instrumentation.internal.javassist;
import java.util.Set; import java.util.Set;
import org.hibernate.bytecode.javassist.FieldHandled;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.bytecode.internal.javassist.FieldHandled;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.FieldInterceptor;
/** /**
* @author Steve Ebersole * @author Steve Ebersole

View File

@ -1,10 +1,10 @@
<!-- <!--
~ Hibernate, Relational Persistence for Idiomatic Java ~ Hibernate, Relational Persistence for Idiomatic Java
~ ~
~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as ~ Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution ~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are ~ statements applied by the authors. All third-party contributions are
~ distributed under license by Red Hat Middleware LLC. ~ distributed under license by Red Hat Inc.
~ ~
~ This copyrighted material is made available to anyone wishing to use, modify, ~ 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 ~ copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,16 +20,13 @@
~ Free Software Foundation, Inc. ~ Free Software Foundation, Inc.
~ 51 Franklin Street, Fifth Floor ~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA ~ Boston, MA 02110-1301 USA
~
--> -->
<html> <html>
<head></head> <head></head>
<body> <body>
<p> <p>
This package implements an interception This package implements an interception mechanism for lazy property fetching, based on bytecode instrumentation.
mechanism for lazy property fetching,
based on CGLIB bytecode instrumentation.
</p> </p>
</body> </body>
</html> </html>

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,9 +20,8 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.intercept; package org.hibernate.bytecode.instrumentation.spi;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import org.hibernate.LazyInitializationException; import org.hibernate.LazyInitializationException;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,9 +20,9 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.intercept; package org.hibernate.bytecode.instrumentation.spi;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
/** /**

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,11 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.intercept; package org.hibernate.bytecode.instrumentation.spi;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
/** /**
@ -48,8 +48,13 @@ public interface LazyPropertyInitializer {
/** /**
* Initialize the property, and return its new value * Initialize the property, and return its new value
*
* @param fieldName The name of the field being initialized
* @param entity The entity on which the initialization is occurring
* @param session The session from which the initialization originated.
*
* @return ?
*/ */
public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session) public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session);
throws HibernateException;
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,16 +20,17 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.PropertyAccessException; import org.hibernate.PropertyAccessException;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
/** /**
* The {@link ReflectionOptimizer.AccessOptimizer} implementation for Javassist * The {@link ReflectionOptimizer.AccessOptimizer} implementation for Javassist
* which simply acts as an adpater to the {@link BulkAccessor} class. * which simply acts as an adapter to the {@link BulkAccessor} class.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,10 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.io.Serializable;
import java.io.Serializable;
/** /**
* A JavaBean accessor. * A JavaBean accessor.

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,10 +20,8 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
/** /**
* An exception thrown while generating a bulk accessor. * An exception thrown while generating a bulk accessor.

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,12 +20,13 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.bytecode.AccessFlag; import javassist.bytecode.AccessFlag;
import javassist.bytecode.Bytecode; import javassist.bytecode.Bytecode;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,21 +20,22 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import org.hibernate.HibernateLogger;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.ClassTransformer;
import org.hibernate.bytecode.ProxyFactoryFactory;
import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.util.ClassFilter;
import org.hibernate.bytecode.util.FieldFilter;
import org.hibernate.internal.util.StringHelper;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.HibernateLogger;
import org.hibernate.bytecode.buildtime.spi.ClassFilter;
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.spi.ClassTransformer;
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.internal.util.StringHelper;
/** /**
* Bytecode provider implementation for Javassist. * Bytecode provider implementation for Javassist.
* *

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,9 +20,9 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,9 +20,8 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
/** /**

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,10 +20,8 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
/** /**
* Interface introduced to the enhanced class in order to be able to * Interface introduced to the enhanced class in order to be able to

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,10 +20,8 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
/** /**
* The interface defining how interception of a field should be handled. * The interface defining how interception of a field should be handled.

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,9 +20,9 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
@ -30,6 +30,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.bytecode.AccessFlag; import javassist.bytecode.AccessFlag;
import javassist.bytecode.BadBytecode; import javassist.bytecode.BadBytecode;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,16 +20,17 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.InstantiationException; import org.hibernate.InstantiationException;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
/** /**
* The {@link ReflectionOptimizer.InstantiationOptimizer} implementation for Javassist * The {@link org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer} implementation for Javassist
* which simply acts as an adpater to the {@link FastClass} class. * which simply acts as an adapter to the {@link FastClass} class.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */

View File

@ -1,132 +1,134 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.internal.javassist;
package org.hibernate.bytecode.javassist;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import javassist.bytecode.ClassFile;
import org.hibernate.HibernateException; import javassist.bytecode.ClassFile;
import org.hibernate.HibernateLogger; import org.jboss.logging.Logger;
import org.hibernate.bytecode.AbstractClassTransformerImpl;
import org.hibernate.bytecode.util.ClassFilter; import org.hibernate.HibernateException;
import org.jboss.logging.Logger; import org.hibernate.HibernateLogger;
import org.hibernate.bytecode.buildtime.spi.ClassFilter;
/** import org.hibernate.bytecode.spi.AbstractClassTransformerImpl;
* Enhance the classes allowing them to implements InterceptFieldEnabled
* This interface is then used by Hibernate for some optimizations. /**
* * Enhance the classes allowing them to implements InterceptFieldEnabled
* @author Emmanuel Bernard * This interface is then used by Hibernate for some optimizations.
* @author Steve Ebersole *
*/ * @author Emmanuel Bernard
public class JavassistClassTransformer extends AbstractClassTransformerImpl { * @author Steve Ebersole
*/
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, public class JavassistClassTransformer extends AbstractClassTransformerImpl {
JavassistClassTransformer.class.getName());
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class,
public JavassistClassTransformer(ClassFilter classFilter, org.hibernate.bytecode.util.FieldFilter fieldFilter) { JavassistClassTransformer.class.getName());
super( classFilter, fieldFilter );
} public JavassistClassTransformer(ClassFilter classFilter, org.hibernate.bytecode.buildtime.spi.FieldFilter fieldFilter) {
super( classFilter, fieldFilter );
@Override }
protected byte[] doTransform(
ClassLoader loader, @Override
String className, protected byte[] doTransform(
Class classBeingRedefined, ClassLoader loader,
ProtectionDomain protectionDomain, String className,
byte[] classfileBuffer) { Class classBeingRedefined,
ClassFile classfile; ProtectionDomain protectionDomain,
try { byte[] classfileBuffer) {
// WARNING: classfile only ClassFile classfile;
classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) ); try {
} // WARNING: classfile only
catch (IOException e) { classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) );
LOG.unableToBuildEnhancementMetamodel(className); }
return classfileBuffer; catch (IOException e) {
} LOG.unableToBuildEnhancementMetamodel(className);
FieldTransformer transformer = getFieldTransformer( classfile ); return classfileBuffer;
if ( transformer != null ) { }
LOG.debugf("Enhancing %s", className); FieldTransformer transformer = getFieldTransformer( classfile );
DataOutputStream out = null; if ( transformer != null ) {
try { LOG.debugf("Enhancing %s", className);
transformer.transform( classfile ); DataOutputStream out = null;
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try {
out = new DataOutputStream( byteStream ); transformer.transform( classfile );
classfile.write( out ); ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
return byteStream.toByteArray(); out = new DataOutputStream( byteStream );
} classfile.write( out );
catch (Exception e) { return byteStream.toByteArray();
LOG.unableToTransformClass(e.getMessage()); }
throw new HibernateException( "Unable to transform class: " + e.getMessage() ); catch (Exception e) {
} LOG.unableToTransformClass(e.getMessage());
finally { throw new HibernateException( "Unable to transform class: " + e.getMessage() );
try { }
if ( out != null ) out.close(); finally {
} try {
catch (IOException e) { if ( out != null ) out.close();
//swallow }
} catch (IOException e) {
} //swallow
} }
return classfileBuffer; }
} }
return classfileBuffer;
protected FieldTransformer getFieldTransformer(final ClassFile classfile) { }
if ( alreadyInstrumented( classfile ) ) {
return null; protected FieldTransformer getFieldTransformer(final ClassFile classfile) {
} if ( alreadyInstrumented( classfile ) ) {
return new FieldTransformer( return null;
new FieldFilter() { }
public boolean handleRead(String desc, String name) { return new FieldTransformer(
return fieldFilter.shouldInstrumentField( classfile.getName(), name ); new FieldFilter() {
} public boolean handleRead(String desc, String name) {
return fieldFilter.shouldInstrumentField( classfile.getName(), name );
public boolean handleWrite(String desc, String name) { }
return fieldFilter.shouldInstrumentField( classfile.getName(), name );
} public boolean handleWrite(String desc, String name) {
return fieldFilter.shouldInstrumentField( classfile.getName(), name );
public boolean handleReadAccess(String fieldOwnerClassName, String fieldName) { }
return fieldFilter.shouldTransformFieldAccess( classfile.getName(), fieldOwnerClassName, fieldName );
} public boolean handleReadAccess(String fieldOwnerClassName, String fieldName) {
return fieldFilter.shouldTransformFieldAccess( classfile.getName(), fieldOwnerClassName, fieldName );
public boolean handleWriteAccess(String fieldOwnerClassName, String fieldName) { }
return fieldFilter.shouldTransformFieldAccess( classfile.getName(), fieldOwnerClassName, fieldName );
} public boolean handleWriteAccess(String fieldOwnerClassName, String fieldName) {
} return fieldFilter.shouldTransformFieldAccess( classfile.getName(), fieldOwnerClassName, fieldName );
); }
} }
);
private boolean alreadyInstrumented(ClassFile classfile) { }
String[] intfs = classfile.getInterfaces();
for ( int i = 0; i < intfs.length; i++ ) { private boolean alreadyInstrumented(ClassFile classfile) {
if ( FieldHandled.class.getName().equals( intfs[i] ) ) { String[] intfs = classfile.getInterfaces();
return true; for ( int i = 0; i < intfs.length; i++ ) {
} if ( FieldHandled.class.getName().equals( intfs[i] ) ) {
} return true;
return false; }
} }
} return false;
}
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,18 +20,20 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import javassist.util.proxy.MethodFilter; import javassist.util.proxy.MethodFilter;
import javassist.util.proxy.MethodHandler; import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyObject; import javassist.util.proxy.ProxyObject;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.BasicProxyFactory; import org.hibernate.bytecode.spi.BasicProxyFactory;
import org.hibernate.bytecode.ProxyFactoryFactory; import org.hibernate.bytecode.spi.ProxyFactoryFactory;
import org.hibernate.proxy.ProxyFactory; import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.pojo.javassist.JavassistProxyFactory; import org.hibernate.proxy.pojo.javassist.JavassistProxyFactory;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,12 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode.javassist; package org.hibernate.bytecode.internal.javassist;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
/** /**
* ReflectionOptimizer implementation for Javassist. * ReflectionOptimizer implementation for Javassist.

View File

@ -1,78 +1,80 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.internal.javassist;
package org.hibernate.bytecode.javassist;
import java.io.IOException; import java.io.IOException;
import javassist.CannotCompileException;
import javassist.ClassPool; import javassist.CannotCompileException;
import javassist.CtClass; import javassist.ClassPool;
import javassist.NotFoundException; import javassist.CtClass;
import org.hibernate.HibernateException; import javassist.NotFoundException;
/** import org.hibernate.HibernateException;
* @author Steve Ebersole
*/ /**
public class TransformingClassLoader extends ClassLoader { * @author Steve Ebersole
private ClassLoader parent; */
private ClassPool classPool; public class TransformingClassLoader extends ClassLoader {
private ClassLoader parent;
/*package*/ TransformingClassLoader(ClassLoader parent, String[] classpath) { private ClassPool classPool;
this.parent = parent;
classPool = new ClassPool( true ); /*package*/ TransformingClassLoader(ClassLoader parent, String[] classpath) {
for ( int i = 0; i < classpath.length; i++ ) { this.parent = parent;
try { classPool = new ClassPool( true );
classPool.appendClassPath( classpath[i] ); for ( int i = 0; i < classpath.length; i++ ) {
} try {
catch ( NotFoundException e ) { classPool.appendClassPath( classpath[i] );
throw new HibernateException( }
"Unable to resolve requested classpath for transformation [" + catch ( NotFoundException e ) {
classpath[i] + "] : " + e.getMessage() throw new HibernateException(
); "Unable to resolve requested classpath for transformation [" +
} classpath[i] + "] : " + e.getMessage()
} );
} }
}
protected Class findClass(String name) throws ClassNotFoundException { }
try {
CtClass cc = classPool.get( name ); protected Class findClass(String name) throws ClassNotFoundException {
// todo : modify the class definition if not already transformed... try {
byte[] b = cc.toBytecode(); CtClass cc = classPool.get( name );
return defineClass( name, b, 0, b.length ); // todo : modify the class definition if not already transformed...
} byte[] b = cc.toBytecode();
catch ( NotFoundException e ) { return defineClass( name, b, 0, b.length );
throw new ClassNotFoundException(); }
} catch ( NotFoundException e ) {
catch ( IOException e ) { throw new ClassNotFoundException();
throw new ClassNotFoundException(); }
} catch ( IOException e ) {
catch ( CannotCompileException e ) { throw new ClassNotFoundException();
throw new ClassNotFoundException(); }
} catch ( CannotCompileException e ) {
} throw new ClassNotFoundException();
}
public void release() { }
classPool = null;
parent = null; public void release() {
} classPool = null;
} parent = null;
}
}

View File

@ -1,10 +1,10 @@
<!-- <!--
~ Hibernate, Relational Persistence for Idiomatic Java ~ Hibernate, Relational Persistence for Idiomatic Java
~ ~
~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as ~ Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution ~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are ~ statements applied by the authors. All third-party contributions are
~ distributed under license by Red Hat Middleware LLC. ~ distributed under license by Red Hat Inc.
~ ~
~ This copyrighted material is made available to anyone wishing to use, modify, ~ 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 ~ copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,7 +20,6 @@
~ Free Software Foundation, Inc. ~ Free Software Foundation, Inc.
~ 51 Franklin Street, Fifth Floor ~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA ~ Boston, MA 02110-1301 USA
~
--> -->
<html> <html>
@ -45,9 +44,6 @@
</li> </li>
</ol> </ol>
</p> </p>
<p>
Currently, both CGLIB and Javassist are supported out-of-the-box.
</p>
<p> <p>
Note that for field-level interception, simply plugging in a new {@link BytecodeProvider} Note that for field-level interception, simply plugging in a new {@link BytecodeProvider}
is not enough for Hibernate to be able to recognize new providers. You would additionally is not enough for Hibernate to be able to recognize new providers. You would additionally

View File

@ -1,68 +1,69 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.spi;
package org.hibernate.bytecode;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import org.hibernate.bytecode.util.ClassFilter;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.buildtime.spi.ClassFilter;
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
/**
* Basic implementation of the {@link ClassTransformer} contract. /**
* * Basic implementation of the {@link ClassTransformer} contract.
* @author Emmanuel Bernard *
* @author Steve Ebersole * @author Emmanuel Bernard
*/ * @author Steve Ebersole
public abstract class AbstractClassTransformerImpl implements ClassTransformer { */
public abstract class AbstractClassTransformerImpl implements ClassTransformer {
protected final ClassFilter classFilter;
protected final FieldFilter fieldFilter; protected final ClassFilter classFilter;
protected final FieldFilter fieldFilter;
protected AbstractClassTransformerImpl(ClassFilter classFilter, FieldFilter fieldFilter) {
this.classFilter = classFilter; protected AbstractClassTransformerImpl(ClassFilter classFilter, FieldFilter fieldFilter) {
this.fieldFilter = fieldFilter; this.classFilter = classFilter;
} this.fieldFilter = fieldFilter;
}
public byte[] transform(
ClassLoader loader, public byte[] transform(
String className, ClassLoader loader,
Class classBeingRedefined, String className,
ProtectionDomain protectionDomain, Class classBeingRedefined,
byte[] classfileBuffer) { ProtectionDomain protectionDomain,
// to be safe... byte[] classfileBuffer) {
className = className.replace( '/', '.' ); // to be safe...
if ( classFilter.shouldInstrumentClass( className ) ) { className = className.replace( '/', '.' );
return doTransform( loader, className, classBeingRedefined, protectionDomain, classfileBuffer ); if ( classFilter.shouldInstrumentClass( className ) ) {
} return doTransform( loader, className, classBeingRedefined, protectionDomain, classfileBuffer );
else { }
return classfileBuffer; else {
} return classfileBuffer;
} }
}
protected abstract byte[] doTransform(
ClassLoader loader, protected abstract byte[] doTransform(
String className, ClassLoader loader,
Class classBeingRedefined, String className,
ProtectionDomain protectionDomain, Class classBeingRedefined,
byte[] classfileBuffer); ProtectionDomain protectionDomain,
} byte[] classfileBuffer);
}

View File

@ -1,40 +1,38 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.spi;
package org.hibernate.bytecode;
/**
* A proxy factory for "basic proxy" generation
/** *
* A proxy factory for "basic proxy" generation * @author Steve Ebersole
* */
* @author Steve Ebersole public interface BasicProxyFactory {
*/ /**
public interface BasicProxyFactory { * Get a proxy reference.
/** *
* Get a proxy reference. * @return A proxy reference.
* */
* @return A proxy reference. public Object getProxy();
*/ }
public Object getProxy();
}

View File

@ -1,125 +1,126 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.bytecode.util; package org.hibernate.bytecode.spi;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream; import java.io.File;
import java.io.IOException; import java.io.FileInputStream;
import java.io.InputStream; import java.io.IOException;
import java.util.zip.ZipInputStream; import java.io.InputStream;
import java.util.zip.ZipInputStream;
/**
* A helper for reading byte code from various input sources. /**
* * A helper for reading byte code from various input sources.
* @author Steve Ebersole *
*/ * @author Steve Ebersole
public class ByteCodeHelper { */
private ByteCodeHelper() { public class ByteCodeHelper {
} private ByteCodeHelper() {
}
/**
* Reads class byte array info from the given input stream. /**
* <p/> * Reads class byte array info from the given input stream.
* The stream is closed within this method! * <p/>
* * The stream is closed within this method!
* @param inputStream The stream containing the class binary; null will lead to an {@link IOException} *
* * @param inputStream The stream containing the class binary; null will lead to an {@link IOException}
* @return The read bytes *
* * @return The read bytes
* @throws IOException Indicates a problem accessing the given stream. *
*/ * @throws IOException Indicates a problem accessing the given stream.
public static byte[] readByteCode(InputStream inputStream) throws IOException { */
if ( inputStream == null ) { public static byte[] readByteCode(InputStream inputStream) throws IOException {
throw new IOException( "null input stream" ); if ( inputStream == null ) {
} throw new IOException( "null input stream" );
}
byte[] buffer = new byte[409600];
byte[] classBytes = new byte[0]; byte[] buffer = new byte[409600];
byte[] classBytes = new byte[0];
try {
int r = inputStream.read( buffer ); try {
while ( r >= buffer.length ) { int r = inputStream.read( buffer );
byte[] temp = new byte[ classBytes.length + buffer.length ]; while ( r >= buffer.length ) {
// copy any previously read bytes into the temp array byte[] temp = new byte[ classBytes.length + buffer.length ];
System.arraycopy( classBytes, 0, temp, 0, classBytes.length ); // copy any previously read bytes into the temp array
// copy the just read bytes into the temp array (after the previously read) System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length ); // copy the just read bytes into the temp array (after the previously read)
classBytes = temp; System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length );
// read the next set of bytes into buffer classBytes = temp;
r = inputStream.read( buffer ); // read the next set of bytes into buffer
} r = inputStream.read( buffer );
if ( r != -1 ) { }
byte[] temp = new byte[ classBytes.length + r ]; if ( r != -1 ) {
// copy any previously read bytes into the temp array byte[] temp = new byte[ classBytes.length + r ];
System.arraycopy( classBytes, 0, temp, 0, classBytes.length ); // copy any previously read bytes into the temp array
// copy the just read bytes into the temp array (after the previously read) System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
System.arraycopy( buffer, 0, temp, classBytes.length, r ); // copy the just read bytes into the temp array (after the previously read)
classBytes = temp; System.arraycopy( buffer, 0, temp, classBytes.length, r );
} classBytes = temp;
} }
finally { }
try { finally {
inputStream.close(); try {
} inputStream.close();
catch (IOException ignore) { }
// intentionally empty catch (IOException ignore) {
} // intentionally empty
} }
}
return classBytes;
} return classBytes;
}
/**
* Read class definition from a file. /**
* * Read class definition from a file.
* @param file The file to read. *
* * @param file The file to read.
* @return The class bytes *
* * @return The class bytes
* @throws IOException Indicates a problem accessing the given stream. *
*/ * @throws IOException Indicates a problem accessing the given stream.
public static byte[] readByteCode(File file) throws IOException { */
return ByteCodeHelper.readByteCode( new FileInputStream( file ) ); public static byte[] readByteCode(File file) throws IOException {
} return ByteCodeHelper.readByteCode( new FileInputStream( file ) );
}
/**
* Read class definition a zip (jar) file entry. /**
* * Read class definition a zip (jar) file entry.
* @param zip The zip entry stream. *
* * @param zip The zip entry stream.
* @return The class bytes *
* * @return The class bytes
* @throws IOException Indicates a problem accessing the given stream. *
*/ * @throws IOException Indicates a problem accessing the given stream.
public static byte[] readByteCode(ZipInputStream zip) throws IOException { */
ByteArrayOutputStream bout = new ByteArrayOutputStream(); public static byte[] readByteCode(ZipInputStream zip) throws IOException {
InputStream in = new BufferedInputStream( zip ); ByteArrayOutputStream bout = new ByteArrayOutputStream();
int b; InputStream in = new BufferedInputStream( zip );
while ( ( b = in.read() ) != -1 ) { int b;
bout.write( b ); while ( ( b = in.read() ) != -1 ) {
} bout.write( b );
return bout.toByteArray(); }
} return bout.toByteArray();
} }
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,20 +20,19 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode; package org.hibernate.bytecode.spi;
import org.hibernate.bytecode.util.ClassFilter;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.buildtime.spi.ClassFilter;
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
/** /**
* Contract for providers of bytecode services to Hibernate. * Contract for providers of bytecode services to Hibernate.
* <p/> * <p/>
* Bytecode requirements break down into basically 3 areas<ol> * Bytecode requirements break down into basically 3 areas<ol>
* <li>proxy generation (both for runtime-lazy-loading and basic proxy generation) * <li>proxy generation (both for runtime-lazy-loading and basic proxy generation) {@link #getProxyFactoryFactory()}</li>
* {@link #getProxyFactoryFactory()} * <li>bean reflection optimization {@link #getReflectionOptimizer}</li>
* <li>bean reflection optimization {@link #getReflectionOptimizer} * <li>field-access instrumentation {@link #getTransformer}</li>
* <li>field-access instrumentation {@link #getTransformer}
* </ol> * </ol>
* *
* @author Steve Ebersole * @author Steve Ebersole

View File

@ -1,56 +1,56 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.spi;
package org.hibernate.bytecode;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
/** /**
* A persistence provider provides an instance of this interface * A persistence provider provides an instance of this interface
* to the PersistenceUnitInfo.addTransformer method. * to the PersistenceUnitInfo.addTransformer method.
* The supplied transformer instance will get called to transform * The supplied transformer instance will get called to transform
* entity class files when they are loaded and redefined. The transformation * entity class files when they are loaded and redefined. The transformation
* occurs before the class is defined by the JVM * occurs before the class is defined by the JVM
* *
* *
* @author <a href="mailto:bill@jboss.org">Bill Burke</a> * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public interface ClassTransformer public interface ClassTransformer
{ {
/** /**
* Invoked when a class is being loaded or redefined to add hooks for persistence bytecode manipulation * Invoked when a class is being loaded or redefined to add hooks for persistence bytecode manipulation
* *
* @param loader the defining class loaderof the class being transformed. It may be null if using bootstrap loader * @param loader the defining class loaderof the class being transformed. It may be null if using bootstrap loader
* @param classname The name of the class being transformed * @param classname The name of the class being transformed
* @param classBeingRedefined If an already loaded class is being redefined, then pass this as a parameter * @param classBeingRedefined If an already loaded class is being redefined, then pass this as a parameter
* @param protectionDomain ProtectionDomain of the class being (re)-defined * @param protectionDomain ProtectionDomain of the class being (re)-defined
* @param classfileBuffer The input byte buffer in class file format * @param classfileBuffer The input byte buffer in class file format
* @return A well-formed class file that can be loaded * @return A well-formed class file that can be loaded
*/ */
public byte[] transform(ClassLoader loader, public byte[] transform(ClassLoader loader,
String classname, String classname,
Class classBeingRedefined, Class classBeingRedefined,
ProtectionDomain protectionDomain, ProtectionDomain protectionDomain,
byte[] classfileBuffer); byte[] classfileBuffer);
} }

View File

@ -1,76 +1,75 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* */
*/ package org.hibernate.bytecode.spi;
package org.hibernate.bytecode;
import java.io.InputStream; import java.io.InputStream;
import org.hibernate.bytecode.util.ByteCodeHelper;
/**
/** * A specialized classloader which performs bytecode enhancement on class
* A specialized classloader which performs bytecode enhancement on class * definitions as they are loaded into the classloader scope.
* definitions as they are loaded into the classloader scope. *
* * @author Emmanuel Bernard
* @author Emmanuel Bernard * @author Steve Ebersole
* @author Steve Ebersole */
*/ public class InstrumentedClassLoader extends ClassLoader {
public class InstrumentedClassLoader extends ClassLoader {
private ClassTransformer classTransformer;
private ClassTransformer classTransformer;
public InstrumentedClassLoader(ClassLoader parent, ClassTransformer classTransformer) {
public InstrumentedClassLoader(ClassLoader parent, ClassTransformer classTransformer) { super( parent );
super( parent ); this.classTransformer = classTransformer;
this.classTransformer = classTransformer; }
}
public Class loadClass(String name) throws ClassNotFoundException {
public Class loadClass(String name) throws ClassNotFoundException { if ( name.startsWith( "java." ) || classTransformer == null ) {
if ( name.startsWith( "java." ) || classTransformer == null ) { return getParent().loadClass( name );
return getParent().loadClass( name ); }
}
Class c = findLoadedClass( name );
Class c = findLoadedClass( name ); if ( c != null ) {
if ( c != null ) { return c;
return c; }
}
InputStream is = this.getResourceAsStream( name.replace( '.', '/' ) + ".class" );
InputStream is = this.getResourceAsStream( name.replace( '.', '/' ) + ".class" ); if ( is == null ) {
if ( is == null ) { throw new ClassNotFoundException( name + " not found" );
throw new ClassNotFoundException( name + " not found" ); }
}
try {
try { byte[] originalBytecode = ByteCodeHelper.readByteCode( is );
byte[] originalBytecode = ByteCodeHelper.readByteCode( is ); byte[] transformedBytecode = classTransformer.transform( getParent(), name, null, null, originalBytecode );
byte[] transformedBytecode = classTransformer.transform( getParent(), name, null, null, originalBytecode ); if ( originalBytecode == transformedBytecode ) {
if ( originalBytecode == transformedBytecode ) { // no transformations took place, so handle it as we would a
// no transformations took place, so handle it as we would a // non-instrumented class
// non-instrumented class return getParent().loadClass( name );
return getParent().loadClass( name ); }
} else {
else { return defineClass( name, transformedBytecode, 0, transformedBytecode.length );
return defineClass( name, transformedBytecode, 0, transformedBytecode.length ); }
} }
} catch( Throwable t ) {
catch( Throwable t ) { throw new ClassNotFoundException( name + " not found", t );
throw new ClassNotFoundException( name + " not found", t ); }
} }
} }
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,9 +20,9 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode; package org.hibernate.bytecode.spi;
import org.hibernate.proxy.ProxyFactory; import org.hibernate.proxy.ProxyFactory;
/** /**

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,10 +20,8 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.bytecode; package org.hibernate.bytecode.spi;
/** /**
* Represents reflection optimization for a particular class. * Represents reflection optimization for a particular class.

View File

@ -35,7 +35,7 @@ import java.util.Properties;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.Version; import org.hibernate.Version;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.internal.util.ConfigHelper; import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -796,10 +796,10 @@ public final class Environment {
private static BytecodeProvider buildBytecodeProvider(String providerName) { private static BytecodeProvider buildBytecodeProvider(String providerName) {
if ( "javassist".equals( providerName ) ) { if ( "javassist".equals( providerName ) ) {
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl(); return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
} }
LOG.unknownBytecodeProvider( providerName ); LOG.unknownBytecodeProvider( providerName );
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl(); return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
} }
} }

View File

@ -272,7 +272,7 @@ class PropertyContainer {
//TODO make those hardcoded tests more portable (through the bytecode provider?) //TODO make those hardcoded tests more portable (through the bytecode provider?)
return property.isAnnotationPresent( Transient.class ) return property.isAnnotationPresent( Transient.class )
|| "net.sf.cglib.transform.impl.InterceptFieldCallback".equals( property.getType().getName() ) || "net.sf.cglib.transform.impl.InterceptFieldCallback".equals( property.getType().getName() )
|| "org.hibernate.bytecode.javassist.FieldHandler".equals( property.getType().getName() ); || "org.hibernate.bytecode.internal.javassist.FieldHandler".equals( property.getType().getName() );
} }
} }

View File

@ -30,7 +30,6 @@ import org.hibernate.ConnectionReleaseMode;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.cache.QueryCacheFactory; import org.hibernate.cache.QueryCacheFactory;
import org.hibernate.cache.RegionFactory; import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.impl.NoCachingRegionFactory; import org.hibernate.cache.impl.NoCachingRegionFactory;
@ -254,11 +253,11 @@ 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.internal.javassist.BytecodeProviderImpl();
// } // }
// else { // else {
// LOG.debugf("Using javassist as bytecode provider by default"); // LOG.debugf("Using javassist as bytecode provider by default");
// return new org.hibernate.bytecode.javassist.BytecodeProviderImpl(); // return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
// } // }
// } // }

View File

@ -29,7 +29,7 @@ import java.io.Serializable;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;

View File

@ -25,7 +25,7 @@ package org.hibernate.engine;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.TransientObjectException; import org.hibernate.TransientObjectException;
import org.hibernate.intercept.LazyPropertyInitializer; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
@ -186,7 +186,7 @@ public final class ForeignKeys {
public static boolean isTransient(String entityName, Object entity, Boolean assumed, SessionImplementor session) public static boolean isTransient(String entityName, Object entity, Boolean assumed, SessionImplementor session)
throws HibernateException { throws HibernateException {
if (entity==LazyPropertyInitializer.UNFETCHED_PROPERTY) { if (entity== LazyPropertyInitializer.UNFETCHED_PROPERTY) {
// an unfetched association can only point to // an unfetched association can only point to
// an entity that already exists in the db // an entity that already exists in the db
return false; return false;

View File

@ -25,7 +25,7 @@ package org.hibernate.engine;
import java.util.Iterator; import java.util.Iterator;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.PropertyValueException; import org.hibernate.PropertyValueException;
import org.hibernate.intercept.LazyPropertyInitializer; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
@ -90,7 +90,7 @@ public final class Nullability {
for ( int i = 0; i < values.length; i++ ) { for ( int i = 0; i < values.length; i++ ) {
if ( checkability[i] && values[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY ) { if ( checkability[i] && values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
final Object value = values[i]; final Object value = values[i];
if ( !nullability[i] && value == null ) { if ( !nullability[i] && value == null ) {

View File

@ -34,7 +34,7 @@ import org.hibernate.event.PostLoadEvent;
import org.hibernate.event.PostLoadEventListener; import org.hibernate.event.PostLoadEventListener;
import org.hibernate.event.PreLoadEvent; import org.hibernate.event.PreLoadEvent;
import org.hibernate.event.PreLoadEventListener; import org.hibernate.event.PreLoadEventListener;
import org.hibernate.intercept.LazyPropertyInitializer; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.property.BackrefPropertyAccessor; import org.hibernate.property.BackrefPropertyAccessor;

View File

@ -29,6 +29,7 @@ import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException; import org.hibernate.NonUniqueObjectException;
import org.hibernate.action.EntityIdentityInsertAction; import org.hibernate.action.EntityIdentityInsertAction;
import org.hibernate.action.EntityInsertAction; import org.hibernate.action.EntityInsertAction;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.classic.Lifecycle; import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable; import org.hibernate.classic.Validatable;
import org.hibernate.engine.Cascade; import org.hibernate.engine.Cascade;
@ -43,8 +44,7 @@ import org.hibernate.engine.Versioning;
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.hibernate.id.IdentifierGenerationException; import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.id.IdentifierGeneratorHelper; import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.intercept.FieldInterceptor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type; import org.hibernate.type.Type;

View File

@ -23,8 +23,8 @@
*/ */
package org.hibernate.event.def; package org.hibernate.event.def;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.hibernate.intercept.LazyPropertyInitializer;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
@ -87,7 +87,7 @@ public abstract class AbstractVisitor {
} }
boolean includeProperty(Object[] values, int i) { boolean includeProperty(Object[] values, int i) {
return values[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY; return values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY;
} }
/** /**

View File

@ -42,7 +42,7 @@ import org.hibernate.engine.Versioning;
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.hibernate.event.FlushEntityEvent; import org.hibernate.event.FlushEntityEvent;
import org.hibernate.event.FlushEntityEventListener; import org.hibernate.event.FlushEntityEventListener;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;

View File

@ -36,6 +36,7 @@ import org.hibernate.PropertyValueException;
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
import org.hibernate.TransientObjectException; import org.hibernate.TransientObjectException;
import org.hibernate.WrongClassException; import org.hibernate.WrongClassException;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.engine.Cascade; import org.hibernate.engine.Cascade;
import org.hibernate.engine.CascadingAction; import org.hibernate.engine.CascadingAction;
import org.hibernate.engine.EntityEntry; import org.hibernate.engine.EntityEntry;
@ -45,8 +46,7 @@ import org.hibernate.engine.Status;
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.hibernate.event.MergeEvent; import org.hibernate.event.MergeEvent;
import org.hibernate.event.MergeEventListener; import org.hibernate.event.MergeEventListener;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.intercept.FieldInterceptor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;

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.intercept;
import java.util.Set;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.javassist.JavassistHelper;
/**
* Helper class for dealing with enhanced entity classes.
*
* @author Steve Ebersole
*/
public class FieldInterceptionHelper {
// VERY IMPORTANT!!!! - This class needs to be free of any static references
// to any CGLIB or Javassist classes. Otherwise, users will always need both
// on their classpaths no matter which (if either) they use.
//
// Another option here would be to remove the Hibernate.isPropertyInitialized()
// method and have the users go through the SessionFactory to get this information.
private FieldInterceptionHelper() {
}
public static boolean isInstrumented(Class entityClass) {
Class[] definedInterfaces = entityClass.getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "net.sf.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() )
|| "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
return true;
}
}
return false;
}
public static boolean isInstrumented(Object entity) {
return entity != null && isInstrumented( entity.getClass() );
}
public static FieldInterceptor extractFieldInterceptor(Object entity) {
if ( entity == null ) {
return null;
}
Class[] definedInterfaces = entity.getClass().getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
// we have a Javassist enhanced entity
return JavassistHelper.extractFieldInterceptor( entity );
}
}
return null;
}
public static FieldInterceptor injectFieldInterceptor(
Object entity,
String entityName,
Set uninitializedFieldNames,
SessionImplementor session) {
if ( entity != null ) {
Class[] definedInterfaces = entity.getClass().getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
// we have a Javassist enhanced entity
return JavassistHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session );
}
}
}
return null;
}
public static void clearDirty(Object entity) {
FieldInterceptor interceptor = extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.clearDirty();
}
}
public static void markDirty(Object entity) {
FieldInterceptor interceptor = extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.dirty();
}
}
}

View File

@ -46,6 +46,9 @@ import org.hibernate.MappingException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException; import org.hibernate.StaleStateException;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.cache.CacheKey; import org.hibernate.cache.CacheKey;
import org.hibernate.cache.access.EntityRegionAccessStrategy; import org.hibernate.cache.access.EntityRegionAccessStrategy;
import org.hibernate.cache.entry.CacheEntry; import org.hibernate.cache.entry.CacheEntry;
@ -71,9 +74,6 @@ import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.id.insert.Binder; import org.hibernate.id.insert.Binder;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.impl.FilterHelper; import org.hibernate.impl.FilterHelper;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.intercept.FieldInterceptor;
import org.hibernate.intercept.LazyPropertyInitializer;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectation;

View File

@ -33,7 +33,7 @@ import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.TypedValue; import org.hibernate.engine.TypedValue;
import org.hibernate.intercept.LazyPropertyInitializer; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;

View File

@ -1,135 +1,137 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.tool.instrument; package org.hibernate.tool.instrument;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.Task;
import org.hibernate.bytecode.buildtime.Instrumenter; import org.apache.tools.ant.types.FileSet;
import org.hibernate.bytecode.buildtime.Logger;
import org.hibernate.bytecode.buildtime.spi.Instrumenter;
/** import org.hibernate.bytecode.buildtime.spi.Logger;
* Super class for all Hibernate instrumentation tasks. Provides the basic templating of how instrumentation
* should occur; subclasses simply plug in to that process appropriately for the given bytecode provider. /**
* * Super class for all Hibernate instrumentation tasks. Provides the basic templating of how instrumentation
* @author Steve Ebersole * should occur; subclasses simply plug in to that process appropriately for the given bytecode provider.
*/ *
public abstract class BasicInstrumentationTask extends Task implements Instrumenter.Options { * @author Steve Ebersole
*/
private final LoggerBridge logger = new LoggerBridge(); public abstract class BasicInstrumentationTask extends Task implements Instrumenter.Options {
private List filesets = new ArrayList(); private final LoggerBridge logger = new LoggerBridge();
private boolean extended;
private List filesets = new ArrayList();
// deprecated option... private boolean extended;
private boolean verbose;
// deprecated option...
public void addFileset(FileSet set) { private boolean verbose;
this.filesets.add( set );
} public void addFileset(FileSet set) {
this.filesets.add( set );
protected final Iterator filesets() { }
return filesets.iterator();
} protected final Iterator filesets() {
return filesets.iterator();
public boolean isExtended() { }
return extended;
} public boolean isExtended() {
return extended;
public void setExtended(boolean extended) { }
this.extended = extended;
} public void setExtended(boolean extended) {
this.extended = extended;
public boolean isVerbose() { }
return verbose;
} public boolean isVerbose() {
return verbose;
public void setVerbose(boolean verbose) { }
this.verbose = verbose;
} public void setVerbose(boolean verbose) {
this.verbose = verbose;
public final boolean performExtendedInstrumentation() { }
return isExtended();
} public final boolean performExtendedInstrumentation() {
return isExtended();
protected abstract Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options); }
@Override protected abstract Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options);
public void execute() throws BuildException {
try { @Override
buildInstrumenter( logger, this ) public void execute() throws BuildException {
.execute( collectSpecifiedFiles() ); try {
} buildInstrumenter( logger, this )
catch ( Throwable t ) { .execute( collectSpecifiedFiles() );
throw new BuildException( t ); }
} catch ( Throwable t ) {
} throw new BuildException( t );
}
private Set collectSpecifiedFiles() { }
HashSet files = new HashSet();
Project project = getProject(); private Set collectSpecifiedFiles() {
Iterator filesets = filesets(); HashSet files = new HashSet();
while ( filesets.hasNext() ) { Project project = getProject();
FileSet fs = ( FileSet ) filesets.next(); Iterator filesets = filesets();
DirectoryScanner ds = fs.getDirectoryScanner( project ); while ( filesets.hasNext() ) {
String[] includedFiles = ds.getIncludedFiles(); FileSet fs = ( FileSet ) filesets.next();
File d = fs.getDir( project ); DirectoryScanner ds = fs.getDirectoryScanner( project );
for ( int i = 0; i < includedFiles.length; ++i ) { String[] includedFiles = ds.getIncludedFiles();
files.add( new File( d, includedFiles[i] ) ); File d = fs.getDir( project );
} for ( int i = 0; i < includedFiles.length; ++i ) {
} files.add( new File( d, includedFiles[i] ) );
return files; }
} }
return files;
protected class LoggerBridge implements Logger { }
public void trace(String message) {
log( message, Project.MSG_VERBOSE ); protected class LoggerBridge implements Logger {
} public void trace(String message) {
log( message, Project.MSG_VERBOSE );
public void debug(String message) { }
log( message, Project.MSG_DEBUG );
} public void debug(String message) {
log( message, Project.MSG_DEBUG );
public void info(String message) { }
log( message, Project.MSG_INFO );
} public void info(String message) {
log( message, Project.MSG_INFO );
public void warn(String message) { }
log( message, Project.MSG_WARN );
} public void warn(String message) {
log( message, Project.MSG_WARN );
public void error(String message) { }
log( message, Project.MSG_ERR );
} public void error(String message) {
} log( message, Project.MSG_ERR );
}
} }
}

View File

@ -23,9 +23,9 @@
*/ */
package org.hibernate.tool.instrument.javassist; package org.hibernate.tool.instrument.javassist;
import org.hibernate.bytecode.buildtime.Instrumenter; import org.hibernate.bytecode.buildtime.internal.JavassistInstrumenter;
import org.hibernate.bytecode.buildtime.JavassistInstrumenter; import org.hibernate.bytecode.buildtime.spi.Instrumenter;
import org.hibernate.bytecode.buildtime.Logger; import org.hibernate.bytecode.buildtime.spi.Logger;
import org.hibernate.tool.instrument.BasicInstrumentationTask; import org.hibernate.tool.instrument.BasicInstrumentationTask;
/** /**

View File

@ -30,7 +30,7 @@ import java.lang.reflect.Constructor;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.InstantiationException; import org.hibernate.InstantiationException;
import org.hibernate.PropertyNotFoundException; import org.hibernate.PropertyNotFoundException;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;

View File

@ -1,191 +1,191 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Middleware LLC.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* *
*/ */
package org.hibernate.tuple.component; package org.hibernate.tuple.component;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.BasicProxyFactory; import org.hibernate.bytecode.spi.BasicProxyFactory;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.property.BackrefPropertyAccessor; import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.property.Getter; import org.hibernate.property.Getter;
import org.hibernate.property.PropertyAccessor; import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory; import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.property.Setter; import org.hibernate.property.Setter;
import org.hibernate.tuple.Instantiator; import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.PojoInstantiator; import org.hibernate.tuple.PojoInstantiator;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
/** /**
* A {@link ComponentTuplizer} specific to the pojo entity mode. * A {@link ComponentTuplizer} specific to the pojo entity mode.
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class PojoComponentTuplizer extends AbstractComponentTuplizer { public class PojoComponentTuplizer extends AbstractComponentTuplizer {
private final Class componentClass; private final Class componentClass;
private ReflectionOptimizer optimizer; private ReflectionOptimizer optimizer;
private final Getter parentGetter; private final Getter parentGetter;
private final Setter parentSetter; private final Setter parentSetter;
public PojoComponentTuplizer(Component component) { public PojoComponentTuplizer(Component component) {
super( component ); super( component );
this.componentClass = component.getComponentClass(); this.componentClass = component.getComponentClass();
String[] getterNames = new String[propertySpan]; String[] getterNames = new String[propertySpan];
String[] setterNames = new String[propertySpan]; String[] setterNames = new String[propertySpan];
Class[] propTypes = new Class[propertySpan]; Class[] propTypes = new Class[propertySpan];
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
getterNames[i] = getters[i].getMethodName(); getterNames[i] = getters[i].getMethodName();
setterNames[i] = setters[i].getMethodName(); setterNames[i] = setters[i].getMethodName();
propTypes[i] = getters[i].getReturnType(); propTypes[i] = getters[i].getReturnType();
} }
final String parentPropertyName = component.getParentProperty(); final String parentPropertyName = component.getParentProperty();
if ( parentPropertyName == null ) { if ( parentPropertyName == null ) {
parentSetter = null; parentSetter = null;
parentGetter = null; parentGetter = null;
} }
else { else {
PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( null ); PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( null );
parentSetter = pa.getSetter( componentClass, parentPropertyName ); parentSetter = pa.getSetter( componentClass, parentPropertyName );
parentGetter = pa.getGetter( componentClass, parentPropertyName ); parentGetter = pa.getGetter( componentClass, parentPropertyName );
} }
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) { if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
optimizer = null; optimizer = null;
} }
else { else {
// TODO: here is why we need to make bytecode provider global :( // TODO: here is why we need to make bytecode provider global :(
// TODO : again, fix this after HHH-1907 is complete // TODO : again, fix this after HHH-1907 is complete
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
componentClass, getterNames, setterNames, propTypes componentClass, getterNames, setterNames, propTypes
); );
} }
} }
public Class getMappedClass() { public Class getMappedClass() {
return componentClass; return componentClass;
} }
public Object[] getPropertyValues(Object component) throws HibernateException { public Object[] getPropertyValues(Object component) throws HibernateException {
if ( component == BackrefPropertyAccessor.UNKNOWN ) { if ( component == BackrefPropertyAccessor.UNKNOWN ) {
return new Object[propertySpan]; return new Object[propertySpan];
} }
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
return optimizer.getAccessOptimizer().getPropertyValues( component ); return optimizer.getAccessOptimizer().getPropertyValues( component );
} }
else { else {
return super.getPropertyValues( component ); return super.getPropertyValues( component );
} }
} }
public void setPropertyValues(Object component, Object[] values) throws HibernateException { public void setPropertyValues(Object component, Object[] values) throws HibernateException {
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
optimizer.getAccessOptimizer().setPropertyValues( component, values ); optimizer.getAccessOptimizer().setPropertyValues( component, values );
} }
else { else {
super.setPropertyValues( component, values ); super.setPropertyValues( component, values );
} }
} }
public Object getParent(Object component) { public Object getParent(Object component) {
return parentGetter.get( component ); return parentGetter.get( component );
} }
public boolean hasParentProperty() { public boolean hasParentProperty() {
return parentGetter != null; return parentGetter != null;
} }
public boolean isMethodOf(Method method) { public boolean isMethodOf(Method method) {
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
final Method getterMethod = getters[i].getMethod(); final Method getterMethod = getters[i].getMethod();
if ( getterMethod != null && getterMethod.equals( method ) ) { if ( getterMethod != null && getterMethod.equals( method ) ) {
return true; return true;
} }
} }
return false; return false;
} }
public void setParent(Object component, Object parent, SessionFactoryImplementor factory) { public void setParent(Object component, Object parent, SessionFactoryImplementor factory) {
parentSetter.set( component, parent, factory ); parentSetter.set( component, parent, factory );
} }
protected Instantiator buildInstantiator(Component component) { protected Instantiator buildInstantiator(Component component) {
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) { if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) {
return new ProxiedInstantiator( component ); return new ProxiedInstantiator( component );
} }
if ( optimizer == null ) { if ( optimizer == null ) {
return new PojoInstantiator( component, null ); return new PojoInstantiator( component, null );
} }
else { else {
return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() ); return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() );
} }
} }
protected Getter buildGetter(Component component, Property prop) { protected Getter buildGetter(Component component, Property prop) {
return prop.getGetter( component.getComponentClass() ); return prop.getGetter( component.getComponentClass() );
} }
protected Setter buildSetter(Component component, Property prop) { protected Setter buildSetter(Component component, Property prop) {
return prop.getSetter( component.getComponentClass() ); return prop.getSetter( component.getComponentClass() );
} }
private static class ProxiedInstantiator implements Instantiator { private static class ProxiedInstantiator implements Instantiator {
private final Class proxiedClass; private final Class proxiedClass;
private final BasicProxyFactory factory; private final BasicProxyFactory factory;
public ProxiedInstantiator(Component component) { public ProxiedInstantiator(Component component) {
proxiedClass = component.getComponentClass(); proxiedClass = component.getComponentClass();
if ( proxiedClass.isInterface() ) { if ( proxiedClass.isInterface() ) {
factory = Environment.getBytecodeProvider() factory = Environment.getBytecodeProvider()
.getProxyFactoryFactory() .getProxyFactoryFactory()
.buildBasicProxyFactory( null, new Class[] { proxiedClass } ); .buildBasicProxyFactory( null, new Class[] { proxiedClass } );
} }
else { else {
factory = Environment.getBytecodeProvider() factory = Environment.getBytecodeProvider()
.getProxyFactoryFactory() .getProxyFactoryFactory()
.buildBasicProxyFactory( proxiedClass, null ); .buildBasicProxyFactory( proxiedClass, null );
} }
} }
public Object instantiate(Serializable id) { public Object instantiate(Serializable id) {
throw new AssertionFailure( "ProxiedInstantiator can only be used to instantiate component" ); throw new AssertionFailure( "ProxiedInstantiator can only be used to instantiate component" );
} }
public Object instantiate() { public Object instantiate() {
return factory.getProxy(); return factory.getProxy();
} }
public boolean isInstance(Object object) { public boolean isInstance(Object object) {
return proxiedClass.isInstance( object ); return proxiedClass.isInstance( object );
} }
} }
} }

View File

@ -1,379 +1,379 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.tuple.entity; package org.hibernate.tuple.entity;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver; import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.classic.Lifecycle; import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable; import org.hibernate.classic.Validatable;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.intercept.FieldInterceptor; import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Subclass;
import org.hibernate.property.Getter; import org.hibernate.property.Getter;
import org.hibernate.property.Setter; import org.hibernate.property.Setter;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory; import org.hibernate.proxy.ProxyFactory;
import org.hibernate.tuple.Instantiator; import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.PojoInstantiator; import org.hibernate.tuple.PojoInstantiator;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
/** /**
* An {@link EntityTuplizer} specific to the pojo entity mode. * An {@link EntityTuplizer} specific to the pojo entity mode.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Gavin King * @author Gavin King
*/ */
public class PojoEntityTuplizer extends AbstractEntityTuplizer { public class PojoEntityTuplizer extends AbstractEntityTuplizer {
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, PojoEntityTuplizer.class.getName()); private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, PojoEntityTuplizer.class.getName());
private final Class mappedClass; private final Class mappedClass;
private final Class proxyInterface; private final Class proxyInterface;
private final boolean lifecycleImplementor; private final boolean lifecycleImplementor;
private final boolean validatableImplementor; private final boolean validatableImplementor;
private final Set lazyPropertyNames = new HashSet(); private final Set lazyPropertyNames = new HashSet();
private final ReflectionOptimizer optimizer; private final ReflectionOptimizer optimizer;
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) { public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
super( entityMetamodel, mappedEntity ); super( entityMetamodel, mappedEntity );
this.mappedClass = mappedEntity.getMappedClass(); this.mappedClass = mappedEntity.getMappedClass();
this.proxyInterface = mappedEntity.getProxyInterface(); this.proxyInterface = mappedEntity.getProxyInterface();
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass ); this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass ); this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );
Iterator iter = mappedEntity.getPropertyClosureIterator(); Iterator iter = mappedEntity.getPropertyClosureIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Property property = (Property) iter.next(); Property property = (Property) iter.next();
if ( property.isLazy() ) { if ( property.isLazy() ) {
lazyPropertyNames.add( property.getName() ); lazyPropertyNames.add( property.getName() );
} }
} }
String[] getterNames = new String[propertySpan]; String[] getterNames = new String[propertySpan];
String[] setterNames = new String[propertySpan]; String[] setterNames = new String[propertySpan];
Class[] propTypes = new Class[propertySpan]; Class[] propTypes = new Class[propertySpan];
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
getterNames[i] = getters[i].getMethodName(); getterNames[i] = getters[i].getMethodName();
setterNames[i] = setters[i].getMethodName(); setterNames[i] = setters[i].getMethodName();
propTypes[i] = getters[i].getReturnType(); propTypes[i] = getters[i].getReturnType();
} }
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) { if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
optimizer = null; optimizer = null;
} }
else { else {
// todo : YUCK!!! // todo : YUCK!!!
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes ); optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes );
// optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer( // optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
// mappedClass, getterNames, setterNames, propTypes // mappedClass, getterNames, setterNames, propTypes
// ); // );
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// determine the id getter and setter methods from the proxy interface (if any) // determine the id getter and setter methods from the proxy interface (if any)
// determine all interfaces needed by the resulting proxy // determine all interfaces needed by the resulting proxy
HashSet<Class> proxyInterfaces = new HashSet<Class>(); HashSet<Class> proxyInterfaces = new HashSet<Class>();
proxyInterfaces.add( HibernateProxy.class ); proxyInterfaces.add( HibernateProxy.class );
Class mappedClass = persistentClass.getMappedClass(); Class mappedClass = persistentClass.getMappedClass();
Class proxyInterface = persistentClass.getProxyInterface(); Class proxyInterface = persistentClass.getProxyInterface();
if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) { if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) {
if ( !proxyInterface.isInterface() ) { if ( !proxyInterface.isInterface() ) {
throw new MappingException( throw new MappingException(
"proxy must be either an interface, or the class itself: " + getEntityName() "proxy must be either an interface, or the class itself: " + getEntityName()
); );
} }
proxyInterfaces.add( proxyInterface ); proxyInterfaces.add( proxyInterface );
} }
if ( mappedClass.isInterface() ) { if ( mappedClass.isInterface() ) {
proxyInterfaces.add( mappedClass ); proxyInterfaces.add( mappedClass );
} }
Iterator subclasses = persistentClass.getSubclassIterator(); Iterator subclasses = persistentClass.getSubclassIterator();
while ( subclasses.hasNext() ) { while ( subclasses.hasNext() ) {
final Subclass subclass = ( Subclass ) subclasses.next(); final Subclass subclass = ( Subclass ) subclasses.next();
final Class subclassProxy = subclass.getProxyInterface(); final Class subclassProxy = subclass.getProxyInterface();
final Class subclassClass = subclass.getMappedClass(); final Class subclassClass = subclass.getMappedClass();
if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) { if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
if ( !subclassProxy.isInterface() ) { if ( !subclassProxy.isInterface() ) {
throw new MappingException( throw new MappingException(
"proxy must be either an interface, or the class itself: " + subclass.getEntityName() "proxy must be either an interface, or the class itself: " + subclass.getEntityName()
); );
} }
proxyInterfaces.add( subclassProxy ); proxyInterfaces.add( subclassProxy );
} }
} }
Iterator properties = persistentClass.getPropertyIterator(); Iterator properties = persistentClass.getPropertyIterator();
Class clazz = persistentClass.getMappedClass(); Class clazz = persistentClass.getMappedClass();
while ( properties.hasNext() ) { while ( properties.hasNext() ) {
Property property = (Property) properties.next(); Property property = (Property) properties.next();
Method method = property.getGetter(clazz).getMethod(); Method method = property.getGetter(clazz).getMethod();
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) { if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName()); LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
} }
method = property.getSetter(clazz).getMethod(); method = property.getSetter(clazz).getMethod();
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) { if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName()); LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
} }
} }
Method idGetterMethod = idGetter==null ? null : idGetter.getMethod(); Method idGetterMethod = idGetter==null ? null : idGetter.getMethod();
Method idSetterMethod = idSetter==null ? null : idSetter.getMethod(); Method idSetterMethod = idSetter==null ? null : idSetter.getMethod();
Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ? Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ?
null : null :
ReflectHelper.getMethod(proxyInterface, idGetterMethod); ReflectHelper.getMethod(proxyInterface, idGetterMethod);
Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null ? Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null ?
null : null :
ReflectHelper.getMethod(proxyInterface, idSetterMethod); ReflectHelper.getMethod(proxyInterface, idSetterMethod);
ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter ); ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
try { try {
pf.postInstantiate( pf.postInstantiate(
getEntityName(), getEntityName(),
mappedClass, mappedClass,
proxyInterfaces, proxyInterfaces,
proxyGetIdentifierMethod, proxyGetIdentifierMethod,
proxySetIdentifierMethod, proxySetIdentifierMethod,
persistentClass.hasEmbeddedIdentifier() ? persistentClass.hasEmbeddedIdentifier() ?
(CompositeType) persistentClass.getIdentifier().getType() : (CompositeType) persistentClass.getIdentifier().getType() :
null null
); );
} }
catch ( HibernateException he ) { catch ( HibernateException he ) {
LOG.unableToCreateProxyFactory(getEntityName(), he); LOG.unableToCreateProxyFactory(getEntityName(), he);
pf = null; pf = null;
} }
return pf; return pf;
} }
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// TODO : YUCK!!! fix after HHH-1907 is complete // TODO : YUCK!!! fix after HHH-1907 is complete
return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
// return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); // return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected Instantiator buildInstantiator(PersistentClass persistentClass) { protected Instantiator buildInstantiator(PersistentClass persistentClass) {
if ( optimizer == null ) { if ( optimizer == null ) {
return new PojoInstantiator( persistentClass, null ); return new PojoInstantiator( persistentClass, null );
} }
else { else {
return new PojoInstantiator( persistentClass, optimizer.getInstantiationOptimizer() ); return new PojoInstantiator( persistentClass, optimizer.getInstantiationOptimizer() );
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void setPropertyValues(Object entity, Object[] values) throws HibernateException { public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) {
setPropertyValuesWithOptimizer( entity, values ); setPropertyValuesWithOptimizer( entity, values );
} }
else { else {
super.setPropertyValues( entity, values ); super.setPropertyValues( entity, values );
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Object[] getPropertyValues(Object entity) throws HibernateException { public Object[] getPropertyValues(Object entity) throws HibernateException {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
return getPropertyValuesWithOptimizer( entity ); return getPropertyValuesWithOptimizer( entity );
} }
else { else {
return super.getPropertyValues( entity ); return super.getPropertyValues( entity );
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session) throws HibernateException { public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session) throws HibernateException {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
return getPropertyValuesWithOptimizer( entity ); return getPropertyValuesWithOptimizer( entity );
} }
else { else {
return super.getPropertyValuesToInsert( entity, mergeMap, session ); return super.getPropertyValuesToInsert( entity, mergeMap, session );
} }
} }
protected void setPropertyValuesWithOptimizer(Object object, Object[] values) { protected void setPropertyValuesWithOptimizer(Object object, Object[] values) {
optimizer.getAccessOptimizer().setPropertyValues( object, values ); optimizer.getAccessOptimizer().setPropertyValues( object, values );
} }
protected Object[] getPropertyValuesWithOptimizer(Object object) { protected Object[] getPropertyValuesWithOptimizer(Object object) {
return optimizer.getAccessOptimizer().getPropertyValues( object ); return optimizer.getAccessOptimizer().getPropertyValues( object );
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public EntityMode getEntityMode() { public EntityMode getEntityMode() {
return EntityMode.POJO; return EntityMode.POJO;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public Class getMappedClass() { public Class getMappedClass() {
return mappedClass; return mappedClass;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isLifecycleImplementor() { public boolean isLifecycleImplementor() {
return lifecycleImplementor; return lifecycleImplementor;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isValidatableImplementor() { public boolean isValidatableImplementor() {
return validatableImplementor; return validatableImplementor;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
return mappedProperty.getGetter( mappedEntity.getMappedClass() ); return mappedProperty.getGetter( mappedEntity.getMappedClass() );
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
return mappedProperty.getSetter( mappedEntity.getMappedClass() ); return mappedProperty.getSetter( mappedEntity.getMappedClass() );
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public Class getConcreteProxyClass() { public Class getConcreteProxyClass() {
return proxyInterface; return proxyInterface;
} }
//TODO: need to make the majority of this functionality into a top-level support class for custom impl support //TODO: need to make the majority of this functionality into a top-level support class for custom impl support
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) { public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {
if ( isInstrumented() ) { if ( isInstrumented() ) {
Set lazyProps = lazyPropertiesAreUnfetched && getEntityMetamodel().hasLazyProperties() ? Set lazyProps = lazyPropertiesAreUnfetched && getEntityMetamodel().hasLazyProperties() ?
lazyPropertyNames : null; lazyPropertyNames : null;
//TODO: if we support multiple fetch groups, we would need //TODO: if we support multiple fetch groups, we would need
// to clone the set of lazy properties! // to clone the set of lazy properties!
FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session ); FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session );
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean hasUninitializedLazyProperties(Object entity) { public boolean hasUninitializedLazyProperties(Object entity) {
if ( getEntityMetamodel().hasLazyProperties() ) { if ( getEntityMetamodel().hasLazyProperties() ) {
FieldInterceptor callback = FieldInterceptionHelper.extractFieldInterceptor( entity ); FieldInterceptor callback = FieldInterceptionHelper.extractFieldInterceptor( entity );
return callback != null && !callback.isInitialized(); return callback != null && !callback.isInitialized();
} }
else { else {
return false; return false;
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public boolean isInstrumented() { public boolean isInstrumented() {
return FieldInterceptionHelper.isInstrumented( getMappedClass() ); return FieldInterceptionHelper.isInstrumented( getMappedClass() );
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) { public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
final Class concreteEntityClass = entityInstance.getClass(); final Class concreteEntityClass = entityInstance.getClass();
if ( concreteEntityClass == getMappedClass() ) { if ( concreteEntityClass == getMappedClass() ) {
return getEntityName(); return getEntityName();
} }
else { else {
String entityName = getEntityMetamodel().findEntityNameByEntityClass( concreteEntityClass ); String entityName = getEntityMetamodel().findEntityNameByEntityClass( concreteEntityClass );
if ( entityName == null ) { if ( entityName == null ) {
throw new HibernateException( throw new HibernateException(
"Unable to resolve entity name from Class [" + concreteEntityClass.getName() + "]" "Unable to resolve entity name from Class [" + concreteEntityClass.getName() + "]"
+ " expected instance/subclass of [" + getEntityName() + "]" + " expected instance/subclass of [" + getEntityName() + "]"
); );
} }
return entityName; return entityName;
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public EntityNameResolver[] getEntityNameResolvers() { public EntityNameResolver[] getEntityNameResolvers() {
return null; return null;
} }
} }

View File

@ -24,8 +24,9 @@
package org.hibernate.type; package org.hibernate.type;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.intercept.LazyPropertyInitializer;
import org.hibernate.property.BackrefPropertyAccessor; import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.tuple.StandardProperty; import org.hibernate.tuple.StandardProperty;

View File

@ -26,7 +26,7 @@ import java.text.ParseException;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl; import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.junit.Test; import org.junit.Test;

View File

@ -23,8 +23,8 @@
*/ */
package org.hibernate.test.bytecode.javassist; package org.hibernate.test.bytecode.javassist;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl; import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
import org.junit.Test; import org.junit.Test;

View File

@ -23,7 +23,7 @@
*/ */
package org.hibernate.test.instrument.buildtime; package org.hibernate.test.instrument.buildtime;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.junit.Test; import org.junit.Test;

View File

@ -1,15 +1,17 @@
package org.hibernate.test.instrument.cases; package org.hibernate.test.instrument.cases;
import java.util.HashSet; import java.util.HashSet;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.test.instrument.domain.Document; import org.hibernate.test.instrument.domain.Document;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class TestInjectFieldInterceptorExecutable extends AbstractExecutable { public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
public void execute() { public void execute() {
Document doc = new Document(); Document doc = new Document();
FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null ); FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
doc.getId(); doc.getId();
} }
} }

View File

@ -2,88 +2,89 @@ package org.hibernate.test.instrument.cases;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.Assert; import junit.framework.Assert;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.test.instrument.domain.Problematic; import org.hibernate.test.instrument.domain.Problematic;
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable { public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
protected String[] getResources() { protected String[] getResources() {
return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" }; return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
} }
public void execute() throws Exception { public void execute() throws Exception {
Session s = getFactory().openSession(); Session s = getFactory().openSession();
Problematic p = new Problematic(); Problematic p = new Problematic();
try { try {
s.beginTransaction(); s.beginTransaction();
p.setName( "whatever" ); p.setName( "whatever" );
p.setBytes( new byte[] { 1, 0, 1, 1, 0 } ); p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
s.save( p ); s.save( p );
s.getTransaction().commit(); s.getTransaction().commit();
} catch (Exception e) { } catch (Exception e) {
s.getTransaction().rollback(); s.getTransaction().rollback();
throw e; throw e;
} finally { } finally {
s.close(); s.close();
} }
// this access should be ok because p1 is not a lazy proxy // this access should be ok because p1 is not a lazy proxy
s = getFactory().openSession(); s = getFactory().openSession();
try { try {
s.beginTransaction(); s.beginTransaction();
Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() ); Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) ); Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
p1.getRepresentation(); p1.getRepresentation();
s.getTransaction().commit(); s.getTransaction().commit();
} catch (Exception e) { } catch (Exception e) {
s.getTransaction().rollback(); s.getTransaction().rollback();
throw e; throw e;
} finally { } finally {
s.close(); s.close();
} }
s = getFactory().openSession(); s = getFactory().openSession();
try { try {
s.beginTransaction(); s.beginTransaction();
Problematic p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 ); Problematic p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
p1.getRepresentation(); p1.getRepresentation();
s.getTransaction().commit(); s.getTransaction().commit();
} catch (Exception e) { } catch (Exception e) {
s.getTransaction().rollback(); s.getTransaction().rollback();
throw e; throw e;
} finally { } finally {
s.close(); s.close();
} }
s = getFactory().openSession(); s = getFactory().openSession();
try { try {
s.beginTransaction(); s.beginTransaction();
Problematic p1 = (Problematic) s.load( Problematic.class, p.getId() ); Problematic p1 = (Problematic) s.load( Problematic.class, p.getId() );
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) ); Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
p1.setRepresentation( p.getRepresentation() ); p1.setRepresentation( p.getRepresentation() );
s.getTransaction().commit(); s.getTransaction().commit();
} catch (Exception e) { } catch (Exception e) {
s.getTransaction().rollback(); s.getTransaction().rollback();
throw e; throw e;
} finally { } finally {
s.close(); s.close();
} }
} }
protected void cleanup() { protected void cleanup() {
Session s = getFactory().openSession(); Session s = getFactory().openSession();
s.beginTransaction(); s.beginTransaction();
Iterator itr = s.createQuery( "from Problematic" ).list().iterator(); Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
while ( itr.hasNext() ) { while ( itr.hasNext() ) {
Problematic p = (Problematic) itr.next(); Problematic p = (Problematic) itr.next();
s.delete( p ); s.delete( p );
} }
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
} }
} }

View File

@ -26,10 +26,10 @@ package org.hibernate.test.instrument.runtime;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.buildtime.spi.BasicClassFilter;
import org.hibernate.bytecode.InstrumentedClassLoader; import org.hibernate.bytecode.buildtime.spi.FieldFilter;
import org.hibernate.bytecode.util.BasicClassFilter; import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.spi.InstrumentedClassLoader;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;

View File

@ -1,36 +1,36 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.instrument.runtime; package org.hibernate.test.instrument.runtime;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl; import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase { public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
protected BytecodeProvider buildBytecodeProvider() { protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl(); return new BytecodeProviderImpl();
} }
} }

View File

@ -28,7 +28,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.junit.Test; import org.junit.Test;

View File

@ -29,7 +29,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.junit.Test; import org.junit.Test;

View File

@ -26,10 +26,10 @@ package org.hibernate.test.nonflushedchanges;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.junit.Test; import org.junit.Test;

View File

@ -27,10 +27,10 @@ import org.hibernate.Hibernate;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
import org.hibernate.intercept.FieldInterceptionHelper;
import org.junit.Test; import org.junit.Test;

View File

@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.bytecode.util.ByteCodeHelper; import org.hibernate.bytecode.spi.ByteCodeHelper;
import org.hibernate.internal.util.SerializationHelper; import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;

View File

@ -24,8 +24,10 @@ import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.bytecode.util.ClassFilter;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.buildtime.spi.ClassFilter;
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
import org.hibernate.bytecode.spi.ClassTransformer;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
/** /**
@ -35,7 +37,7 @@ import org.hibernate.cfg.Environment;
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class InterceptFieldClassFileTransformer implements javax.persistence.spi.ClassTransformer { public class InterceptFieldClassFileTransformer implements javax.persistence.spi.ClassTransformer {
private org.hibernate.bytecode.ClassTransformer classTransformer; private ClassTransformer classTransformer;
public InterceptFieldClassFileTransformer(List<String> entities) { public InterceptFieldClassFileTransformer(List<String> entities) {
final List<String> copyEntities = new ArrayList<String>( entities.size() ); final List<String> copyEntities = new ArrayList<String>( entities.size() );

View File

@ -14,8 +14,8 @@ import javax.persistence.PersistenceException;
import javax.persistence.spi.LoadState; import javax.persistence.spi.LoadState;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.collection.PersistentCollection; import org.hibernate.collection.PersistentCollection;
import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.intercept.FieldInterceptor; import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;

View File

@ -33,7 +33,7 @@ public class InterceptFieldClassFileTransformerTest extends TestCase {
Class clazz = cl.loadClass( entities.get( 0 ) ); Class clazz = cl.loadClass( entities.get( 0 ) );
// javassist is our default byte code enhancer. Enhancing will eg add the method getFieldHandler() // javassist is our default byte code enhancer. Enhancing will eg add the method getFieldHandler()
// see org.hibernate.bytecode.javassist.FieldTransformer // see org.hibernate.bytecode.internal.javassist.FieldTransformer
Method method = clazz.getDeclaredMethod( "getFieldHandler" ); Method method = clazz.getDeclaredMethod( "getFieldHandler" );
assertNotNull( method ); assertNotNull( method );
} }