HHH-6026 - Migrate bytecode provider integrations to api/spi/internal split
This commit is contained in:
parent
82d2ef4b1f
commit
19791a6c7d
|
@ -24,14 +24,15 @@
|
|||
package org.hibernate;
|
||||
import java.util.Iterator;
|
||||
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.engine.HibernateIterator;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.engine.jdbc.LobCreationContext;
|
||||
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.LazyInitializer;
|
||||
import org.hibernate.type.AnyType;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -21,18 +21,22 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.bytecode.buildtime;
|
||||
package org.hibernate.bytecode.buildtime.internal;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import javassist.bytecode.ClassFile;
|
||||
import org.hibernate.bytecode.ClassTransformer;
|
||||
import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
|
||||
import org.hibernate.bytecode.javassist.FieldHandled;
|
||||
import org.hibernate.bytecode.util.BasicClassFilter;
|
||||
import org.hibernate.bytecode.util.ClassDescriptor;
|
||||
|
||||
import org.hibernate.bytecode.buildtime.spi.AbstractInstrumenter;
|
||||
import org.hibernate.bytecode.buildtime.spi.BasicClassFilter;
|
||||
import org.hibernate.bytecode.buildtime.spi.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
|
||||
|
@ -81,9 +85,9 @@ public class JavassistInstrumenter extends AbstractInstrumenter {
|
|||
}
|
||||
|
||||
public boolean isInstrumented() {
|
||||
String[] intfs = classFile.getInterfaces();
|
||||
for ( int i = 0; i < intfs.length; i++ ) {
|
||||
if ( FieldHandled.class.getName().equals( intfs[i] ) ) {
|
||||
String[] interfaceNames = classFile.getInterfaces();
|
||||
for ( String interfaceName : interfaceNames ) {
|
||||
if ( FieldHandled.class.getName().equals( interfaceName ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.bytecode.buildtime;
|
||||
package org.hibernate.bytecode.buildtime.spi;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
@ -31,16 +31,14 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import org.hibernate.bytecode.ClassTransformer;
|
||||
import org.hibernate.bytecode.util.ByteCodeHelper;
|
||||
import org.hibernate.bytecode.util.ClassDescriptor;
|
||||
import org.hibernate.bytecode.util.FieldFilter;
|
||||
|
||||
import org.hibernate.bytecode.spi.ByteCodeHelper;
|
||||
import org.hibernate.bytecode.spi.ClassTransformer;
|
||||
|
||||
/**
|
||||
* Provides the basic templating of how instrumentation should occur.
|
||||
|
@ -93,15 +91,14 @@ public abstract class AbstractInstrumenter implements Instrumenter {
|
|||
*
|
||||
* @param files The files.
|
||||
*/
|
||||
public void execute(Set files) {
|
||||
Set classNames = new HashSet();
|
||||
public void execute(Set<File> files) {
|
||||
Set<String> classNames = new HashSet<String>();
|
||||
|
||||
if ( options.performExtendedInstrumentation() ) {
|
||||
logger.debug( "collecting class names for extended instrumentation determination" );
|
||||
try {
|
||||
Iterator itr = files.iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final File file = ( File ) itr.next();
|
||||
for ( Object file1 : files ) {
|
||||
final File file = (File) file1;
|
||||
collectClassNames( file, classNames );
|
||||
}
|
||||
}
|
||||
|
@ -115,9 +112,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
|
|||
|
||||
logger.info( "starting instrumentation" );
|
||||
try {
|
||||
Iterator itr = files.iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final File file = ( File ) itr.next();
|
||||
for ( File file : files ) {
|
||||
processFile( file, classNames );
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +135,7 @@ public abstract class AbstractInstrumenter implements Instrumenter {
|
|||
*
|
||||
* @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 ) ) {
|
||||
byte[] bytes = ByteCodeHelper.readByteCode( file );
|
||||
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.
|
||||
*/
|
||||
protected void processFile(File file, Set classNames) throws Exception {
|
||||
protected void processFile(File file, Set<String> classNames) throws Exception {
|
||||
if ( isClassFile( file ) ) {
|
||||
logger.debug( "processing class file : " + file.getAbsolutePath() );
|
||||
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.
|
||||
*/
|
||||
protected void processClassFile(File file, Set classNames) throws Exception {
|
||||
protected void processClassFile(File file, Set<String> classNames) throws Exception {
|
||||
byte[] bytes = ByteCodeHelper.readByteCode( file );
|
||||
ClassDescriptor descriptor = getClassDescriptor( bytes );
|
||||
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.
|
||||
*/
|
||||
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.getName(),
|
||||
null,
|
||||
|
@ -406,9 +401,9 @@ public abstract class AbstractInstrumenter implements Instrumenter {
|
|||
* Apply strategy to the given archive 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;
|
||||
}
|
|
@ -1,82 +1,72 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.util;
|
||||
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
|
||||
* neither is specified, then no restrictions are applied.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicClassFilter implements ClassFilter {
|
||||
private final String[] includedPackages;
|
||||
private final Set includedClassNames = new HashSet();
|
||||
private final boolean isAllEmpty;
|
||||
|
||||
public BasicClassFilter() {
|
||||
this( null, null );
|
||||
}
|
||||
|
||||
public BasicClassFilter(String[] includedPackages, String[] includedClassNames) {
|
||||
this.includedPackages = includedPackages;
|
||||
if ( includedClassNames != null ) {
|
||||
for ( int i = 0; i < includedClassNames.length; i++ ) {
|
||||
this.includedClassNames.add( includedClassNames[i] );
|
||||
}
|
||||
}
|
||||
|
||||
isAllEmpty = ( this.includedPackages == null || this.includedPackages.length == 0 )
|
||||
&& ( this.includedClassNames.isEmpty() );
|
||||
}
|
||||
|
||||
public boolean shouldInstrumentClass(String className) {
|
||||
if ( isAllEmpty ) {
|
||||
return true;
|
||||
}
|
||||
else if ( includedClassNames.contains( className ) ) {
|
||||
return true;
|
||||
}
|
||||
else if ( isInIncludedPackage( className ) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.buildtime.spi;
|
||||
|
||||
import java.util.Arrays;
|
||||
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
|
||||
* neither is specified, then no restrictions are applied.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicClassFilter implements ClassFilter {
|
||||
private final String[] includedPackages;
|
||||
private final Set<String> includedClassNames = new HashSet<String>();
|
||||
private final boolean isAllEmpty;
|
||||
|
||||
public BasicClassFilter() {
|
||||
this( null, null );
|
||||
}
|
||||
|
||||
public BasicClassFilter(String[] includedPackages, String[] includedClassNames) {
|
||||
this.includedPackages = includedPackages;
|
||||
if ( includedClassNames != null ) {
|
||||
this.includedClassNames.addAll( Arrays.asList( includedClassNames ) );
|
||||
}
|
||||
|
||||
isAllEmpty = ( this.includedPackages == null || this.includedPackages.length == 0 )
|
||||
&& ( this.includedClassNames.isEmpty() );
|
||||
}
|
||||
|
||||
public boolean shouldInstrumentClass(String className) {
|
||||
return isAllEmpty ||
|
||||
includedClassNames.contains( className ) ||
|
||||
isInIncludedPackage( className );
|
||||
}
|
||||
|
||||
private boolean isInIncludedPackage(String className) {
|
||||
if ( includedPackages != null ) {
|
||||
for ( String includedPackage : includedPackages ) {
|
||||
if ( className.startsWith( includedPackage ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,55 +1,53 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.util;
|
||||
|
||||
|
||||
/**
|
||||
* Contract describing the information Hibernate needs in terms of instrumenting
|
||||
* a class, either via ant task or dynamic classloader.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ClassDescriptor {
|
||||
/**
|
||||
* The name of the class.
|
||||
*
|
||||
* @return The class name.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Determine if the class is already instrumented.
|
||||
*
|
||||
* @return True if already instrumented; false otherwise.
|
||||
*/
|
||||
public boolean isInstrumented();
|
||||
|
||||
/**
|
||||
* The bytes making up the class' bytecode.
|
||||
*
|
||||
* @return The bytecode bytes.
|
||||
*/
|
||||
public byte[] getBytes();
|
||||
}
|
||||
/*
|
||||
* 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.buildtime.spi;
|
||||
|
||||
/**
|
||||
* Contract describing the information Hibernate needs in terms of instrumenting
|
||||
* a class, either via ant task or dynamic classloader.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ClassDescriptor {
|
||||
/**
|
||||
* The name of the class.
|
||||
*
|
||||
* @return The class name.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Determine if the class is already instrumented.
|
||||
*
|
||||
* @return True if already instrumented; false otherwise.
|
||||
*/
|
||||
public boolean isInstrumented();
|
||||
|
||||
/**
|
||||
* The bytes making up the class' bytecode.
|
||||
*
|
||||
* @return The bytecode bytes.
|
||||
*/
|
||||
public byte[] getBytes();
|
||||
}
|
|
@ -1,35 +1,40 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.util;
|
||||
|
||||
|
||||
/**
|
||||
* Used to determine whether a class should be instrumented.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ClassFilter {
|
||||
public boolean shouldInstrumentClass(String className);
|
||||
}
|
||||
/*
|
||||
* 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.buildtime.spi;
|
||||
|
||||
/**
|
||||
* Used to determine whether a class should be instrumented.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ClassFilter {
|
||||
/**
|
||||
* Should this class be included in instrumentation
|
||||
*
|
||||
* @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);
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -21,14 +21,14 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.bytecode.buildtime;
|
||||
|
||||
package org.hibernate.bytecode.buildtime.spi;
|
||||
|
||||
/**
|
||||
* Indicates problem performing the instrumentation execution.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
public class ExecutionException extends RuntimeException {
|
||||
public ExecutionException(String message) {
|
||||
super( message );
|
|
@ -1,54 +1,52 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.util;
|
||||
|
||||
|
||||
/**
|
||||
* Used to determine whether a field reference should be instrumented.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface FieldFilter {
|
||||
/**
|
||||
* 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.
|
||||
* @return True if we should instrument this field.
|
||||
*/
|
||||
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
|
||||
* a field.
|
||||
*
|
||||
* @param transformingClassName The class currently being transformed.
|
||||
* @param fieldOwnerClassName The name of the class owning this field being checked.
|
||||
* @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);
|
||||
}
|
||||
/*
|
||||
* 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.buildtime.spi;
|
||||
|
||||
/**
|
||||
* Used to determine whether a field reference should be instrumented.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface FieldFilter {
|
||||
/**
|
||||
* 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.
|
||||
* @return True if we should instrument this field.
|
||||
*/
|
||||
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
|
||||
* a field.
|
||||
*
|
||||
* @param transformingClassName The class currently being transformed.
|
||||
* @param fieldOwnerClassName The name of the class owning this field being checked.
|
||||
* @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);
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -21,18 +21,33 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.bytecode.buildtime;
|
||||
package org.hibernate.bytecode.buildtime.spi;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
* Basic contract for performing instrumentation
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
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 {
|
||||
/**
|
||||
* Should we enhance references to class fields outside the class itself?
|
||||
*
|
||||
* @return {@literal true}/{@literal false}
|
||||
*/
|
||||
public boolean performExtendedInstrumentation();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* 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)
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,14 +20,15 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.intercept.javassist;
|
||||
package org.hibernate.bytecode.instrumentation.internal.javassist;
|
||||
|
||||
import java.io.Serializable;
|
||||
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.intercept.AbstractFieldInterceptor;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
||||
|
@ -45,15 +46,9 @@ import org.hibernate.proxy.LazyInitializer;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings( {"UnnecessaryUnboxing", "UnnecessaryBoxing"})
|
||||
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) {
|
||||
super( session, uninitializedFields, entityName );
|
||||
}
|
||||
|
@ -67,35 +62,35 @@ public final class FieldInterceptorImpl extends AbstractFieldInterceptor impleme
|
|||
}
|
||||
|
||||
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) {
|
||||
return ( ( Character ) intercept( target, name, new Character( oldValue ) ) )
|
||||
return ( ( Character ) intercept( target, name, Character.valueOf( oldValue ) ) )
|
||||
.charValue();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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) {
|
||||
return ( ( Short ) intercept( target, name, new Short( oldValue ) ) )
|
||||
return ( ( Short ) intercept( target, name, Short.valueOf( oldValue ) ) )
|
||||
.shortValue();
|
||||
}
|
||||
|
||||
|
@ -118,43 +113,43 @@ public final class FieldInterceptorImpl extends AbstractFieldInterceptor impleme
|
|||
|
||||
public byte writeByte(Object target, String name, byte oldValue, byte newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Byte( oldValue ) );
|
||||
intercept( target, name, Byte.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public char writeChar(Object target, String name, char oldValue, char newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Character( oldValue ) );
|
||||
intercept( target, name, Character.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public double writeDouble(Object target, String name, double oldValue, double newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Double( oldValue ) );
|
||||
intercept( target, name, Double.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public float writeFloat(Object target, String name, float oldValue, float newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Float( oldValue ) );
|
||||
intercept( target, name, Float.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public int writeInt(Object target, String name, int oldValue, int newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Integer( oldValue ) );
|
||||
intercept( target, name, Integer.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public long writeLong(Object target, String name, long oldValue, long newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Long( oldValue ) );
|
||||
intercept( target, name, Long.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public short writeShort(Object target, String name, short oldValue, short newValue) {
|
||||
dirty();
|
||||
intercept( target, name, new Short( oldValue ) );
|
||||
intercept( target, name, Short.valueOf( oldValue ) );
|
||||
return newValue;
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,13 +20,14 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.intercept.javassist;
|
||||
package org.hibernate.bytecode.instrumentation.internal.javassist;
|
||||
|
||||
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.intercept.FieldInterceptor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
|
@ -1,10 +1,10 @@
|
|||
<!--
|
||||
~ 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
|
||||
~ 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,
|
||||
~ copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,16 +20,13 @@
|
|||
~ Free Software Foundation, Inc.
|
||||
~ 51 Franklin Street, Fifth Floor
|
||||
~ Boston, MA 02110-1301 USA
|
||||
~
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<p>
|
||||
This package implements an interception
|
||||
mechanism for lazy property fetching,
|
||||
based on CGLIB bytecode instrumentation.
|
||||
This package implements an interception mechanism for lazy property fetching, based on bytecode instrumentation.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,9 +20,8 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.intercept;
|
||||
package org.hibernate.bytecode.instrumentation.spi;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import org.hibernate.LazyInitializationException;
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,9 +20,9 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.intercept;
|
||||
package org.hibernate.bytecode.instrumentation.spi;
|
||||
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
|
||||
/**
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,11 +20,11 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.intercept;
|
||||
package org.hibernate.bytecode.instrumentation.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
|
||||
/**
|
||||
|
@ -48,8 +48,13 @@ public interface LazyPropertyInitializer {
|
|||
|
||||
/**
|
||||
* 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)
|
||||
throws HibernateException;
|
||||
public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session);
|
||||
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,16 +20,17 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.PropertyAccessException;
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,11 +20,10 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
import java.io.Serializable;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A JavaBean accessor.
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,10 +20,8 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
/**
|
||||
* An exception thrown while generating a bulk accessor.
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,12 +20,13 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* 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.Modifier;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.bytecode.AccessFlag;
|
||||
import javassist.bytecode.Bytecode;
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,21 +20,22 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
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.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.
|
||||
*
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,9 +20,9 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,9 +20,8 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
|
||||
/**
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,10 +20,8 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* 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
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,10 +20,8 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* 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.
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,9 +20,9 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -30,6 +30,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.bytecode.AccessFlag;
|
||||
import javassist.bytecode.BadBytecode;
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,16 +20,17 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.InstantiationException;
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
|
||||
/**
|
||||
* The {@link ReflectionOptimizer.InstantiationOptimizer} implementation for Javassist
|
||||
* which simply acts as an adpater to the {@link FastClass} class.
|
||||
* The {@link org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer} implementation for Javassist
|
||||
* which simply acts as an adapter to the {@link FastClass} class.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
|
@ -1,132 +1,134 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.ProtectionDomain;
|
||||
import javassist.bytecode.ClassFile;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.bytecode.AbstractClassTransformerImpl;
|
||||
import org.hibernate.bytecode.util.ClassFilter;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Enhance the classes allowing them to implements InterceptFieldEnabled
|
||||
* This interface is then used by Hibernate for some optimizations.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JavassistClassTransformer extends AbstractClassTransformerImpl {
|
||||
|
||||
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class,
|
||||
JavassistClassTransformer.class.getName());
|
||||
|
||||
public JavassistClassTransformer(ClassFilter classFilter, org.hibernate.bytecode.util.FieldFilter fieldFilter) {
|
||||
super( classFilter, fieldFilter );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] doTransform(
|
||||
ClassLoader loader,
|
||||
String className,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer) {
|
||||
ClassFile classfile;
|
||||
try {
|
||||
// WARNING: classfile only
|
||||
classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) );
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.unableToBuildEnhancementMetamodel(className);
|
||||
return classfileBuffer;
|
||||
}
|
||||
FieldTransformer transformer = getFieldTransformer( classfile );
|
||||
if ( transformer != null ) {
|
||||
LOG.debugf("Enhancing %s", className);
|
||||
DataOutputStream out = null;
|
||||
try {
|
||||
transformer.transform( classfile );
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
out = new DataOutputStream( byteStream );
|
||||
classfile.write( out );
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.unableToTransformClass(e.getMessage());
|
||||
throw new HibernateException( "Unable to transform class: " + e.getMessage() );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( out != null ) out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
//swallow
|
||||
}
|
||||
}
|
||||
}
|
||||
return classfileBuffer;
|
||||
}
|
||||
|
||||
protected FieldTransformer getFieldTransformer(final ClassFile classfile) {
|
||||
if ( alreadyInstrumented( classfile ) ) {
|
||||
return null;
|
||||
}
|
||||
return new FieldTransformer(
|
||||
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 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 );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private boolean alreadyInstrumented(ClassFile classfile) {
|
||||
String[] intfs = classfile.getInterfaces();
|
||||
for ( int i = 0; i < intfs.length; i++ ) {
|
||||
if ( FieldHandled.class.getName().equals( intfs[i] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.internal.javassist;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import javassist.bytecode.ClassFile;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
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.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JavassistClassTransformer extends AbstractClassTransformerImpl {
|
||||
|
||||
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class,
|
||||
JavassistClassTransformer.class.getName());
|
||||
|
||||
public JavassistClassTransformer(ClassFilter classFilter, org.hibernate.bytecode.buildtime.spi.FieldFilter fieldFilter) {
|
||||
super( classFilter, fieldFilter );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] doTransform(
|
||||
ClassLoader loader,
|
||||
String className,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer) {
|
||||
ClassFile classfile;
|
||||
try {
|
||||
// WARNING: classfile only
|
||||
classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) );
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.unableToBuildEnhancementMetamodel(className);
|
||||
return classfileBuffer;
|
||||
}
|
||||
FieldTransformer transformer = getFieldTransformer( classfile );
|
||||
if ( transformer != null ) {
|
||||
LOG.debugf("Enhancing %s", className);
|
||||
DataOutputStream out = null;
|
||||
try {
|
||||
transformer.transform( classfile );
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
out = new DataOutputStream( byteStream );
|
||||
classfile.write( out );
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.unableToTransformClass(e.getMessage());
|
||||
throw new HibernateException( "Unable to transform class: " + e.getMessage() );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( out != null ) out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
//swallow
|
||||
}
|
||||
}
|
||||
}
|
||||
return classfileBuffer;
|
||||
}
|
||||
|
||||
protected FieldTransformer getFieldTransformer(final ClassFile classfile) {
|
||||
if ( alreadyInstrumented( classfile ) ) {
|
||||
return null;
|
||||
}
|
||||
return new FieldTransformer(
|
||||
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 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 );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private boolean alreadyInstrumented(ClassFile classfile) {
|
||||
String[] intfs = classfile.getInterfaces();
|
||||
for ( int i = 0; i < intfs.length; i++ ) {
|
||||
if ( FieldHandled.class.getName().equals( intfs[i] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,18 +20,20 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javassist.util.proxy.MethodFilter;
|
||||
import javassist.util.proxy.MethodHandler;
|
||||
import javassist.util.proxy.ProxyObject;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.BasicProxyFactory;
|
||||
import org.hibernate.bytecode.ProxyFactoryFactory;
|
||||
import org.hibernate.bytecode.spi.BasicProxyFactory;
|
||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||
import org.hibernate.proxy.ProxyFactory;
|
||||
import org.hibernate.proxy.pojo.javassist.JavassistProxyFactory;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,11 +20,12 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
|
||||
/**
|
||||
* ReflectionOptimizer implementation for Javassist.
|
|
@ -1,78 +1,80 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode.javassist;
|
||||
import java.io.IOException;
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.NotFoundException;
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TransformingClassLoader extends ClassLoader {
|
||||
private ClassLoader parent;
|
||||
private ClassPool classPool;
|
||||
|
||||
/*package*/ TransformingClassLoader(ClassLoader parent, String[] classpath) {
|
||||
this.parent = parent;
|
||||
classPool = new ClassPool( true );
|
||||
for ( int i = 0; i < classpath.length; i++ ) {
|
||||
try {
|
||||
classPool.appendClassPath( classpath[i] );
|
||||
}
|
||||
catch ( NotFoundException e ) {
|
||||
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 );
|
||||
// todo : modify the class definition if not already transformed...
|
||||
byte[] b = cc.toBytecode();
|
||||
return defineClass( name, b, 0, b.length );
|
||||
}
|
||||
catch ( NotFoundException e ) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
catch ( CannotCompileException e ) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
classPool = null;
|
||||
parent = null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.internal.javassist;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TransformingClassLoader extends ClassLoader {
|
||||
private ClassLoader parent;
|
||||
private ClassPool classPool;
|
||||
|
||||
/*package*/ TransformingClassLoader(ClassLoader parent, String[] classpath) {
|
||||
this.parent = parent;
|
||||
classPool = new ClassPool( true );
|
||||
for ( int i = 0; i < classpath.length; i++ ) {
|
||||
try {
|
||||
classPool.appendClassPath( classpath[i] );
|
||||
}
|
||||
catch ( NotFoundException e ) {
|
||||
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 );
|
||||
// todo : modify the class definition if not already transformed...
|
||||
byte[] b = cc.toBytecode();
|
||||
return defineClass( name, b, 0, b.length );
|
||||
}
|
||||
catch ( NotFoundException e ) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
catch ( CannotCompileException e ) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
classPool = null;
|
||||
parent = null;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
<!--
|
||||
~ 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
|
||||
~ 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,
|
||||
~ copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,7 +20,6 @@
|
|||
~ Free Software Foundation, Inc.
|
||||
~ 51 Franklin Street, Fifth Floor
|
||||
~ Boston, MA 02110-1301 USA
|
||||
~
|
||||
-->
|
||||
|
||||
<html>
|
||||
|
@ -45,9 +44,6 @@
|
|||
</li>
|
||||
</ol>
|
||||
</p>
|
||||
<p>
|
||||
Currently, both CGLIB and Javassist are supported out-of-the-box.
|
||||
</p>
|
||||
<p>
|
||||
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
|
||||
|
|
|
@ -1,68 +1,69 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
import java.security.ProtectionDomain;
|
||||
import org.hibernate.bytecode.util.ClassFilter;
|
||||
import org.hibernate.bytecode.util.FieldFilter;
|
||||
|
||||
/**
|
||||
* Basic implementation of the {@link ClassTransformer} contract.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractClassTransformerImpl implements ClassTransformer {
|
||||
|
||||
protected final ClassFilter classFilter;
|
||||
protected final FieldFilter fieldFilter;
|
||||
|
||||
protected AbstractClassTransformerImpl(ClassFilter classFilter, FieldFilter fieldFilter) {
|
||||
this.classFilter = classFilter;
|
||||
this.fieldFilter = fieldFilter;
|
||||
}
|
||||
|
||||
public byte[] transform(
|
||||
ClassLoader loader,
|
||||
String className,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer) {
|
||||
// to be safe...
|
||||
className = className.replace( '/', '.' );
|
||||
if ( classFilter.shouldInstrumentClass( className ) ) {
|
||||
return doTransform( loader, className, classBeingRedefined, protectionDomain, classfileBuffer );
|
||||
}
|
||||
else {
|
||||
return classfileBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract byte[] doTransform(
|
||||
ClassLoader loader,
|
||||
String className,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer);
|
||||
}
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import org.hibernate.bytecode.buildtime.spi.ClassFilter;
|
||||
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
|
||||
|
||||
/**
|
||||
* Basic implementation of the {@link ClassTransformer} contract.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractClassTransformerImpl implements ClassTransformer {
|
||||
|
||||
protected final ClassFilter classFilter;
|
||||
protected final FieldFilter fieldFilter;
|
||||
|
||||
protected AbstractClassTransformerImpl(ClassFilter classFilter, FieldFilter fieldFilter) {
|
||||
this.classFilter = classFilter;
|
||||
this.fieldFilter = fieldFilter;
|
||||
}
|
||||
|
||||
public byte[] transform(
|
||||
ClassLoader loader,
|
||||
String className,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer) {
|
||||
// to be safe...
|
||||
className = className.replace( '/', '.' );
|
||||
if ( classFilter.shouldInstrumentClass( className ) ) {
|
||||
return doTransform( loader, className, classBeingRedefined, protectionDomain, classfileBuffer );
|
||||
}
|
||||
else {
|
||||
return classfileBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract byte[] doTransform(
|
||||
ClassLoader loader,
|
||||
String className,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer);
|
||||
}
|
|
@ -1,40 +1,38 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
|
||||
|
||||
/**
|
||||
* A proxy factory for "basic proxy" generation
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface BasicProxyFactory {
|
||||
/**
|
||||
* Get a proxy reference.
|
||||
*
|
||||
* @return A proxy reference.
|
||||
*/
|
||||
public Object getProxy();
|
||||
}
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
/**
|
||||
* A proxy factory for "basic proxy" generation
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface BasicProxyFactory {
|
||||
/**
|
||||
* Get a proxy reference.
|
||||
*
|
||||
* @return A proxy reference.
|
||||
*/
|
||||
public Object getProxy();
|
||||
}
|
|
@ -1,125 +1,126 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.bytecode.util;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* A helper for reading byte code from various input sources.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ByteCodeHelper {
|
||||
private ByteCodeHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads class byte array info from the given input stream.
|
||||
* <p/>
|
||||
* The stream is closed within this method!
|
||||
*
|
||||
* @param inputStream The stream containing the class binary; null will lead to an {@link IOException}
|
||||
*
|
||||
* @return The read bytes
|
||||
*
|
||||
* @throws IOException Indicates a problem accessing the given stream.
|
||||
*/
|
||||
public static byte[] readByteCode(InputStream inputStream) throws IOException {
|
||||
if ( inputStream == null ) {
|
||||
throw new IOException( "null input stream" );
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[409600];
|
||||
byte[] classBytes = new byte[0];
|
||||
|
||||
try {
|
||||
int r = inputStream.read( buffer );
|
||||
while ( r >= buffer.length ) {
|
||||
byte[] temp = new byte[ classBytes.length + buffer.length ];
|
||||
// copy any previously read bytes into the temp array
|
||||
System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
|
||||
// copy the just read bytes into the temp array (after the previously read)
|
||||
System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length );
|
||||
classBytes = temp;
|
||||
// read the next set of bytes into buffer
|
||||
r = inputStream.read( buffer );
|
||||
}
|
||||
if ( r != -1 ) {
|
||||
byte[] temp = new byte[ classBytes.length + r ];
|
||||
// copy any previously read bytes into the temp array
|
||||
System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
|
||||
// copy the just read bytes into the temp array (after the previously read)
|
||||
System.arraycopy( buffer, 0, temp, classBytes.length, r );
|
||||
classBytes = temp;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
// intentionally empty
|
||||
}
|
||||
}
|
||||
|
||||
return classBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read class definition from a file.
|
||||
*
|
||||
* @param file The file to read.
|
||||
*
|
||||
* @return The class bytes
|
||||
*
|
||||
* @throws IOException Indicates a problem accessing the given stream.
|
||||
*/
|
||||
public static byte[] readByteCode(File file) throws IOException {
|
||||
return ByteCodeHelper.readByteCode( new FileInputStream( file ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Read class definition a zip (jar) file entry.
|
||||
*
|
||||
* @param zip The zip entry stream.
|
||||
*
|
||||
* @return The class bytes
|
||||
*
|
||||
* @throws IOException Indicates a problem accessing the given stream.
|
||||
*/
|
||||
public static byte[] readByteCode(ZipInputStream zip) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
InputStream in = new BufferedInputStream( zip );
|
||||
int b;
|
||||
while ( ( b = in.read() ) != -1 ) {
|
||||
bout.write( b );
|
||||
}
|
||||
return bout.toByteArray();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.bytecode.spi;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* A helper for reading byte code from various input sources.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ByteCodeHelper {
|
||||
private ByteCodeHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads class byte array info from the given input stream.
|
||||
* <p/>
|
||||
* The stream is closed within this method!
|
||||
*
|
||||
* @param inputStream The stream containing the class binary; null will lead to an {@link IOException}
|
||||
*
|
||||
* @return The read bytes
|
||||
*
|
||||
* @throws IOException Indicates a problem accessing the given stream.
|
||||
*/
|
||||
public static byte[] readByteCode(InputStream inputStream) throws IOException {
|
||||
if ( inputStream == null ) {
|
||||
throw new IOException( "null input stream" );
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[409600];
|
||||
byte[] classBytes = new byte[0];
|
||||
|
||||
try {
|
||||
int r = inputStream.read( buffer );
|
||||
while ( r >= buffer.length ) {
|
||||
byte[] temp = new byte[ classBytes.length + buffer.length ];
|
||||
// copy any previously read bytes into the temp array
|
||||
System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
|
||||
// copy the just read bytes into the temp array (after the previously read)
|
||||
System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length );
|
||||
classBytes = temp;
|
||||
// read the next set of bytes into buffer
|
||||
r = inputStream.read( buffer );
|
||||
}
|
||||
if ( r != -1 ) {
|
||||
byte[] temp = new byte[ classBytes.length + r ];
|
||||
// copy any previously read bytes into the temp array
|
||||
System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
|
||||
// copy the just read bytes into the temp array (after the previously read)
|
||||
System.arraycopy( buffer, 0, temp, classBytes.length, r );
|
||||
classBytes = temp;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
// intentionally empty
|
||||
}
|
||||
}
|
||||
|
||||
return classBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read class definition from a file.
|
||||
*
|
||||
* @param file The file to read.
|
||||
*
|
||||
* @return The class bytes
|
||||
*
|
||||
* @throws IOException Indicates a problem accessing the given stream.
|
||||
*/
|
||||
public static byte[] readByteCode(File file) throws IOException {
|
||||
return ByteCodeHelper.readByteCode( new FileInputStream( file ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Read class definition a zip (jar) file entry.
|
||||
*
|
||||
* @param zip The zip entry stream.
|
||||
*
|
||||
* @return The class bytes
|
||||
*
|
||||
* @throws IOException Indicates a problem accessing the given stream.
|
||||
*/
|
||||
public static byte[] readByteCode(ZipInputStream zip) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
InputStream in = new BufferedInputStream( zip );
|
||||
int b;
|
||||
while ( ( b = in.read() ) != -1 ) {
|
||||
bout.write( b );
|
||||
}
|
||||
return bout.toByteArray();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,20 +20,19 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
import org.hibernate.bytecode.util.ClassFilter;
|
||||
import org.hibernate.bytecode.util.FieldFilter;
|
||||
package org.hibernate.bytecode.spi;
|
||||
|
||||
import org.hibernate.bytecode.buildtime.spi.ClassFilter;
|
||||
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
|
||||
|
||||
/**
|
||||
* Contract for providers of bytecode services to Hibernate.
|
||||
* <p/>
|
||||
* Bytecode requirements break down into basically 3 areas<ol>
|
||||
* <li>proxy generation (both for runtime-lazy-loading and basic proxy generation)
|
||||
* {@link #getProxyFactoryFactory()}
|
||||
* <li>bean reflection optimization {@link #getReflectionOptimizer}
|
||||
* <li>field-access instrumentation {@link #getTransformer}
|
||||
* <li>proxy generation (both for runtime-lazy-loading and basic proxy generation) {@link #getProxyFactoryFactory()}</li>
|
||||
* <li>bean reflection optimization {@link #getReflectionOptimizer}</li>
|
||||
* <li>field-access instrumentation {@link #getTransformer}</li>
|
||||
* </ol>
|
||||
*
|
||||
* @author Steve Ebersole
|
|
@ -1,56 +1,56 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
/**
|
||||
* A persistence provider provides an instance of this interface
|
||||
* to the PersistenceUnitInfo.addTransformer method.
|
||||
* The supplied transformer instance will get called to transform
|
||||
* entity class files when they are loaded and redefined. The transformation
|
||||
* occurs before the class is defined by the JVM
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public interface ClassTransformer
|
||||
{
|
||||
/**
|
||||
* 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 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 protectionDomain ProtectionDomain of the class being (re)-defined
|
||||
* @param classfileBuffer The input byte buffer in class file format
|
||||
* @return A well-formed class file that can be loaded
|
||||
*/
|
||||
public byte[] transform(ClassLoader loader,
|
||||
String classname,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer);
|
||||
}
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
/**
|
||||
* A persistence provider provides an instance of this interface
|
||||
* to the PersistenceUnitInfo.addTransformer method.
|
||||
* The supplied transformer instance will get called to transform
|
||||
* entity class files when they are loaded and redefined. The transformation
|
||||
* occurs before the class is defined by the JVM
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public interface ClassTransformer
|
||||
{
|
||||
/**
|
||||
* 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 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 protectionDomain ProtectionDomain of the class being (re)-defined
|
||||
* @param classfileBuffer The input byte buffer in class file format
|
||||
* @return A well-formed class file that can be loaded
|
||||
*/
|
||||
public byte[] transform(ClassLoader loader,
|
||||
String classname,
|
||||
Class classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer);
|
||||
}
|
|
@ -1,76 +1,75 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
import java.io.InputStream;
|
||||
import org.hibernate.bytecode.util.ByteCodeHelper;
|
||||
|
||||
/**
|
||||
* A specialized classloader which performs bytecode enhancement on class
|
||||
* definitions as they are loaded into the classloader scope.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class InstrumentedClassLoader extends ClassLoader {
|
||||
|
||||
private ClassTransformer classTransformer;
|
||||
|
||||
public InstrumentedClassLoader(ClassLoader parent, ClassTransformer classTransformer) {
|
||||
super( parent );
|
||||
this.classTransformer = classTransformer;
|
||||
}
|
||||
|
||||
public Class loadClass(String name) throws ClassNotFoundException {
|
||||
if ( name.startsWith( "java." ) || classTransformer == null ) {
|
||||
return getParent().loadClass( name );
|
||||
}
|
||||
|
||||
Class c = findLoadedClass( name );
|
||||
if ( c != null ) {
|
||||
return c;
|
||||
}
|
||||
|
||||
InputStream is = this.getResourceAsStream( name.replace( '.', '/' ) + ".class" );
|
||||
if ( is == null ) {
|
||||
throw new ClassNotFoundException( name + " not found" );
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] originalBytecode = ByteCodeHelper.readByteCode( is );
|
||||
byte[] transformedBytecode = classTransformer.transform( getParent(), name, null, null, originalBytecode );
|
||||
if ( originalBytecode == transformedBytecode ) {
|
||||
// no transformations took place, so handle it as we would a
|
||||
// non-instrumented class
|
||||
return getParent().loadClass( name );
|
||||
}
|
||||
else {
|
||||
return defineClass( name, transformedBytecode, 0, transformedBytecode.length );
|
||||
}
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
throw new ClassNotFoundException( name + " not found", t );
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* A specialized classloader which performs bytecode enhancement on class
|
||||
* definitions as they are loaded into the classloader scope.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class InstrumentedClassLoader extends ClassLoader {
|
||||
|
||||
private ClassTransformer classTransformer;
|
||||
|
||||
public InstrumentedClassLoader(ClassLoader parent, ClassTransformer classTransformer) {
|
||||
super( parent );
|
||||
this.classTransformer = classTransformer;
|
||||
}
|
||||
|
||||
public Class loadClass(String name) throws ClassNotFoundException {
|
||||
if ( name.startsWith( "java." ) || classTransformer == null ) {
|
||||
return getParent().loadClass( name );
|
||||
}
|
||||
|
||||
Class c = findLoadedClass( name );
|
||||
if ( c != null ) {
|
||||
return c;
|
||||
}
|
||||
|
||||
InputStream is = this.getResourceAsStream( name.replace( '.', '/' ) + ".class" );
|
||||
if ( is == null ) {
|
||||
throw new ClassNotFoundException( name + " not found" );
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] originalBytecode = ByteCodeHelper.readByteCode( is );
|
||||
byte[] transformedBytecode = classTransformer.transform( getParent(), name, null, null, originalBytecode );
|
||||
if ( originalBytecode == transformedBytecode ) {
|
||||
// no transformations took place, so handle it as we would a
|
||||
// non-instrumented class
|
||||
return getParent().loadClass( name );
|
||||
}
|
||||
else {
|
||||
return defineClass( name, transformedBytecode, 0, transformedBytecode.length );
|
||||
}
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
throw new ClassNotFoundException( name + " not found", t );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,9 +20,9 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
package org.hibernate.bytecode.spi;
|
||||
|
||||
import org.hibernate.proxy.ProxyFactory;
|
||||
|
||||
/**
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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
|
||||
* 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,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
|
@ -20,10 +20,8 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.bytecode;
|
||||
|
||||
package org.hibernate.bytecode.spi;
|
||||
|
||||
/**
|
||||
* Represents reflection optimization for a particular class.
|
|
@ -35,7 +35,7 @@ import java.util.Properties;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.HibernateLogger;
|
||||
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.config.ConfigurationHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -796,10 +796,10 @@ public final class Environment {
|
|||
|
||||
private static BytecodeProvider buildBytecodeProvider(String providerName) {
|
||||
if ( "javassist".equals( providerName ) ) {
|
||||
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
|
||||
return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
|
||||
}
|
||||
|
||||
LOG.unknownBytecodeProvider( providerName );
|
||||
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
|
||||
return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ class PropertyContainer {
|
|||
//TODO make those hardcoded tests more portable (through the bytecode provider?)
|
||||
return property.isAnnotationPresent( Transient.class )
|
||||
|| "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() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.hibernate.ConnectionReleaseMode;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.bytecode.BytecodeProvider;
|
||||
import org.hibernate.cache.QueryCacheFactory;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.impl.NoCachingRegionFactory;
|
||||
|
@ -254,11 +253,11 @@ public class SettingsFactory implements Serializable {
|
|||
|
||||
// protected BytecodeProvider buildBytecodeProvider(String providerName) {
|
||||
// if ( "javassist".equals( providerName ) ) {
|
||||
// return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
|
||||
// return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
|
||||
// }
|
||||
// else {
|
||||
// LOG.debugf("Using javassist as bytecode provider by default");
|
||||
// return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
|
||||
// return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.io.Serializable;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
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.UniqueKeyLoadable;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
|
|
@ -25,7 +25,7 @@ package org.hibernate.engine;
|
|||
import java.io.Serializable;
|
||||
import org.hibernate.HibernateException;
|
||||
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.proxy.HibernateProxy;
|
||||
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)
|
||||
throws HibernateException {
|
||||
|
||||
if (entity==LazyPropertyInitializer.UNFETCHED_PROPERTY) {
|
||||
if (entity== LazyPropertyInitializer.UNFETCHED_PROPERTY) {
|
||||
// an unfetched association can only point to
|
||||
// an entity that already exists in the db
|
||||
return false;
|
||||
|
|
|
@ -25,7 +25,7 @@ package org.hibernate.engine;
|
|||
import java.util.Iterator;
|
||||
import org.hibernate.HibernateException;
|
||||
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.type.CollectionType;
|
||||
import org.hibernate.type.CompositeType;
|
||||
|
@ -90,7 +90,7 @@ public final class Nullability {
|
|||
|
||||
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];
|
||||
if ( !nullability[i] && value == null ) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.hibernate.event.PostLoadEvent;
|
|||
import org.hibernate.event.PostLoadEventListener;
|
||||
import org.hibernate.event.PreLoadEvent;
|
||||
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.pretty.MessageHelper;
|
||||
import org.hibernate.property.BackrefPropertyAccessor;
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.NonUniqueObjectException;
|
||||
import org.hibernate.action.EntityIdentityInsertAction;
|
||||
import org.hibernate.action.EntityInsertAction;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.classic.Validatable;
|
||||
import org.hibernate.engine.Cascade;
|
||||
|
@ -43,8 +44,7 @@ import org.hibernate.engine.Versioning;
|
|||
import org.hibernate.event.EventSource;
|
||||
import org.hibernate.id.IdentifierGenerationException;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.intercept.FieldInterceptor;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.type.Type;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.event.def;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.event.EventSource;
|
||||
import org.hibernate.intercept.LazyPropertyInitializer;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.CollectionType;
|
||||
import org.hibernate.type.CompositeType;
|
||||
|
@ -87,7 +87,7 @@ public abstract class AbstractVisitor {
|
|||
}
|
||||
|
||||
boolean includeProperty(Object[] values, int i) {
|
||||
return values[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY;
|
||||
return values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.hibernate.engine.Versioning;
|
|||
import org.hibernate.event.EventSource;
|
||||
import org.hibernate.event.FlushEntityEvent;
|
||||
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.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.PropertyValueException;
|
|||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.WrongClassException;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.engine.Cascade;
|
||||
import org.hibernate.engine.CascadingAction;
|
||||
import org.hibernate.engine.EntityEntry;
|
||||
|
@ -45,8 +46,7 @@ import org.hibernate.engine.Status;
|
|||
import org.hibernate.event.EventSource;
|
||||
import org.hibernate.event.MergeEvent;
|
||||
import org.hibernate.event.MergeEventListener;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.intercept.FieldInterceptor;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,9 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.QueryException;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
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.access.EntityRegionAccessStrategy;
|
||||
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.InsertGeneratedIdentifierDelegate;
|
||||
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.collections.ArrayHelper;
|
||||
import org.hibernate.jdbc.Expectation;
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
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.type.Type;
|
||||
import org.jboss.logging.Logger;
|
||||
|
|
|
@ -1,135 +1,137 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.tool.instrument;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
import org.hibernate.bytecode.buildtime.Instrumenter;
|
||||
import org.hibernate.bytecode.buildtime.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.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class BasicInstrumentationTask extends Task implements Instrumenter.Options {
|
||||
|
||||
private final LoggerBridge logger = new LoggerBridge();
|
||||
|
||||
private List filesets = new ArrayList();
|
||||
private boolean extended;
|
||||
|
||||
// deprecated option...
|
||||
private boolean verbose;
|
||||
|
||||
public void addFileset(FileSet set) {
|
||||
this.filesets.add( set );
|
||||
}
|
||||
|
||||
protected final Iterator filesets() {
|
||||
return filesets.iterator();
|
||||
}
|
||||
|
||||
public boolean isExtended() {
|
||||
return extended;
|
||||
}
|
||||
|
||||
public void setExtended(boolean extended) {
|
||||
this.extended = extended;
|
||||
}
|
||||
|
||||
public boolean isVerbose() {
|
||||
return verbose;
|
||||
}
|
||||
|
||||
public void setVerbose(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public final boolean performExtendedInstrumentation() {
|
||||
return isExtended();
|
||||
}
|
||||
|
||||
protected abstract Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options);
|
||||
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
try {
|
||||
buildInstrumenter( logger, this )
|
||||
.execute( collectSpecifiedFiles() );
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
throw new BuildException( t );
|
||||
}
|
||||
}
|
||||
|
||||
private Set collectSpecifiedFiles() {
|
||||
HashSet files = new HashSet();
|
||||
Project project = getProject();
|
||||
Iterator filesets = filesets();
|
||||
while ( filesets.hasNext() ) {
|
||||
FileSet fs = ( FileSet ) filesets.next();
|
||||
DirectoryScanner ds = fs.getDirectoryScanner( project );
|
||||
String[] includedFiles = ds.getIncludedFiles();
|
||||
File d = fs.getDir( project );
|
||||
for ( int i = 0; i < includedFiles.length; ++i ) {
|
||||
files.add( new File( d, includedFiles[i] ) );
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
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 info(String message) {
|
||||
log( message, Project.MSG_INFO );
|
||||
}
|
||||
|
||||
public void warn(String message) {
|
||||
log( message, Project.MSG_WARN );
|
||||
}
|
||||
|
||||
public void error(String message) {
|
||||
log( message, Project.MSG_ERR );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
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.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class BasicInstrumentationTask extends Task implements Instrumenter.Options {
|
||||
|
||||
private final LoggerBridge logger = new LoggerBridge();
|
||||
|
||||
private List filesets = new ArrayList();
|
||||
private boolean extended;
|
||||
|
||||
// deprecated option...
|
||||
private boolean verbose;
|
||||
|
||||
public void addFileset(FileSet set) {
|
||||
this.filesets.add( set );
|
||||
}
|
||||
|
||||
protected final Iterator filesets() {
|
||||
return filesets.iterator();
|
||||
}
|
||||
|
||||
public boolean isExtended() {
|
||||
return extended;
|
||||
}
|
||||
|
||||
public void setExtended(boolean extended) {
|
||||
this.extended = extended;
|
||||
}
|
||||
|
||||
public boolean isVerbose() {
|
||||
return verbose;
|
||||
}
|
||||
|
||||
public void setVerbose(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public final boolean performExtendedInstrumentation() {
|
||||
return isExtended();
|
||||
}
|
||||
|
||||
protected abstract Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options);
|
||||
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
try {
|
||||
buildInstrumenter( logger, this )
|
||||
.execute( collectSpecifiedFiles() );
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
throw new BuildException( t );
|
||||
}
|
||||
}
|
||||
|
||||
private Set collectSpecifiedFiles() {
|
||||
HashSet files = new HashSet();
|
||||
Project project = getProject();
|
||||
Iterator filesets = filesets();
|
||||
while ( filesets.hasNext() ) {
|
||||
FileSet fs = ( FileSet ) filesets.next();
|
||||
DirectoryScanner ds = fs.getDirectoryScanner( project );
|
||||
String[] includedFiles = ds.getIncludedFiles();
|
||||
File d = fs.getDir( project );
|
||||
for ( int i = 0; i < includedFiles.length; ++i ) {
|
||||
files.add( new File( d, includedFiles[i] ) );
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
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 info(String message) {
|
||||
log( message, Project.MSG_INFO );
|
||||
}
|
||||
|
||||
public void warn(String message) {
|
||||
log( message, Project.MSG_WARN );
|
||||
}
|
||||
|
||||
public void error(String message) {
|
||||
log( message, Project.MSG_ERR );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
*/
|
||||
package org.hibernate.tool.instrument.javassist;
|
||||
|
||||
import org.hibernate.bytecode.buildtime.Instrumenter;
|
||||
import org.hibernate.bytecode.buildtime.JavassistInstrumenter;
|
||||
import org.hibernate.bytecode.buildtime.Logger;
|
||||
import org.hibernate.bytecode.buildtime.internal.JavassistInstrumenter;
|
||||
import org.hibernate.bytecode.buildtime.spi.Instrumenter;
|
||||
import org.hibernate.bytecode.buildtime.spi.Logger;
|
||||
import org.hibernate.tool.instrument.BasicInstrumentationTask;
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.lang.reflect.Constructor;
|
|||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.InstantiationException;
|
||||
import org.hibernate.PropertyNotFoundException;
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.mapping.Component;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
|
|
@ -1,191 +1,191 @@
|
|||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* 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.tuple.component;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.BasicProxyFactory;
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.mapping.Component;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.property.BackrefPropertyAccessor;
|
||||
import org.hibernate.property.Getter;
|
||||
import org.hibernate.property.PropertyAccessor;
|
||||
import org.hibernate.property.PropertyAccessorFactory;
|
||||
import org.hibernate.property.Setter;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.tuple.PojoInstantiator;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
|
||||
/**
|
||||
* A {@link ComponentTuplizer} specific to the pojo entity mode.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||
private final Class componentClass;
|
||||
private ReflectionOptimizer optimizer;
|
||||
private final Getter parentGetter;
|
||||
private final Setter parentSetter;
|
||||
|
||||
public PojoComponentTuplizer(Component component) {
|
||||
super( component );
|
||||
|
||||
this.componentClass = component.getComponentClass();
|
||||
|
||||
String[] getterNames = new String[propertySpan];
|
||||
String[] setterNames = new String[propertySpan];
|
||||
Class[] propTypes = new Class[propertySpan];
|
||||
for ( int i = 0; i < propertySpan; i++ ) {
|
||||
getterNames[i] = getters[i].getMethodName();
|
||||
setterNames[i] = setters[i].getMethodName();
|
||||
propTypes[i] = getters[i].getReturnType();
|
||||
}
|
||||
|
||||
final String parentPropertyName = component.getParentProperty();
|
||||
if ( parentPropertyName == null ) {
|
||||
parentSetter = null;
|
||||
parentGetter = null;
|
||||
}
|
||||
else {
|
||||
PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( null );
|
||||
parentSetter = pa.getSetter( componentClass, parentPropertyName );
|
||||
parentGetter = pa.getGetter( componentClass, parentPropertyName );
|
||||
}
|
||||
|
||||
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
|
||||
optimizer = null;
|
||||
}
|
||||
else {
|
||||
// TODO: here is why we need to make bytecode provider global :(
|
||||
// TODO : again, fix this after HHH-1907 is complete
|
||||
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
|
||||
componentClass, getterNames, setterNames, propTypes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public Class getMappedClass() {
|
||||
return componentClass;
|
||||
}
|
||||
|
||||
public Object[] getPropertyValues(Object component) throws HibernateException {
|
||||
if ( component == BackrefPropertyAccessor.UNKNOWN ) {
|
||||
return new Object[propertySpan];
|
||||
}
|
||||
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
return optimizer.getAccessOptimizer().getPropertyValues( component );
|
||||
}
|
||||
else {
|
||||
return super.getPropertyValues( component );
|
||||
}
|
||||
}
|
||||
|
||||
public void setPropertyValues(Object component, Object[] values) throws HibernateException {
|
||||
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
optimizer.getAccessOptimizer().setPropertyValues( component, values );
|
||||
}
|
||||
else {
|
||||
super.setPropertyValues( component, values );
|
||||
}
|
||||
}
|
||||
|
||||
public Object getParent(Object component) {
|
||||
return parentGetter.get( component );
|
||||
}
|
||||
|
||||
public boolean hasParentProperty() {
|
||||
return parentGetter != null;
|
||||
}
|
||||
|
||||
public boolean isMethodOf(Method method) {
|
||||
for ( int i = 0; i < propertySpan; i++ ) {
|
||||
final Method getterMethod = getters[i].getMethod();
|
||||
if ( getterMethod != null && getterMethod.equals( method ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setParent(Object component, Object parent, SessionFactoryImplementor factory) {
|
||||
parentSetter.set( component, parent, factory );
|
||||
}
|
||||
|
||||
protected Instantiator buildInstantiator(Component component) {
|
||||
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) {
|
||||
return new ProxiedInstantiator( component );
|
||||
}
|
||||
if ( optimizer == null ) {
|
||||
return new PojoInstantiator( component, null );
|
||||
}
|
||||
else {
|
||||
return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() );
|
||||
}
|
||||
}
|
||||
|
||||
protected Getter buildGetter(Component component, Property prop) {
|
||||
return prop.getGetter( component.getComponentClass() );
|
||||
}
|
||||
|
||||
protected Setter buildSetter(Component component, Property prop) {
|
||||
return prop.getSetter( component.getComponentClass() );
|
||||
}
|
||||
|
||||
private static class ProxiedInstantiator implements Instantiator {
|
||||
private final Class proxiedClass;
|
||||
private final BasicProxyFactory factory;
|
||||
|
||||
public ProxiedInstantiator(Component component) {
|
||||
proxiedClass = component.getComponentClass();
|
||||
if ( proxiedClass.isInterface() ) {
|
||||
factory = Environment.getBytecodeProvider()
|
||||
.getProxyFactoryFactory()
|
||||
.buildBasicProxyFactory( null, new Class[] { proxiedClass } );
|
||||
}
|
||||
else {
|
||||
factory = Environment.getBytecodeProvider()
|
||||
.getProxyFactoryFactory()
|
||||
.buildBasicProxyFactory( proxiedClass, null );
|
||||
}
|
||||
}
|
||||
|
||||
public Object instantiate(Serializable id) {
|
||||
throw new AssertionFailure( "ProxiedInstantiator can only be used to instantiate component" );
|
||||
}
|
||||
|
||||
public Object instantiate() {
|
||||
return factory.getProxy();
|
||||
}
|
||||
|
||||
public boolean isInstance(Object object) {
|
||||
return proxiedClass.isInstance( object );
|
||||
}
|
||||
}
|
||||
}
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.spi.BasicProxyFactory;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.mapping.Component;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.property.BackrefPropertyAccessor;
|
||||
import org.hibernate.property.Getter;
|
||||
import org.hibernate.property.PropertyAccessor;
|
||||
import org.hibernate.property.PropertyAccessorFactory;
|
||||
import org.hibernate.property.Setter;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.tuple.PojoInstantiator;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
|
||||
/**
|
||||
* A {@link ComponentTuplizer} specific to the pojo entity mode.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||
private final Class componentClass;
|
||||
private ReflectionOptimizer optimizer;
|
||||
private final Getter parentGetter;
|
||||
private final Setter parentSetter;
|
||||
|
||||
public PojoComponentTuplizer(Component component) {
|
||||
super( component );
|
||||
|
||||
this.componentClass = component.getComponentClass();
|
||||
|
||||
String[] getterNames = new String[propertySpan];
|
||||
String[] setterNames = new String[propertySpan];
|
||||
Class[] propTypes = new Class[propertySpan];
|
||||
for ( int i = 0; i < propertySpan; i++ ) {
|
||||
getterNames[i] = getters[i].getMethodName();
|
||||
setterNames[i] = setters[i].getMethodName();
|
||||
propTypes[i] = getters[i].getReturnType();
|
||||
}
|
||||
|
||||
final String parentPropertyName = component.getParentProperty();
|
||||
if ( parentPropertyName == null ) {
|
||||
parentSetter = null;
|
||||
parentGetter = null;
|
||||
}
|
||||
else {
|
||||
PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( null );
|
||||
parentSetter = pa.getSetter( componentClass, parentPropertyName );
|
||||
parentGetter = pa.getGetter( componentClass, parentPropertyName );
|
||||
}
|
||||
|
||||
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
|
||||
optimizer = null;
|
||||
}
|
||||
else {
|
||||
// TODO: here is why we need to make bytecode provider global :(
|
||||
// TODO : again, fix this after HHH-1907 is complete
|
||||
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
|
||||
componentClass, getterNames, setterNames, propTypes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public Class getMappedClass() {
|
||||
return componentClass;
|
||||
}
|
||||
|
||||
public Object[] getPropertyValues(Object component) throws HibernateException {
|
||||
if ( component == BackrefPropertyAccessor.UNKNOWN ) {
|
||||
return new Object[propertySpan];
|
||||
}
|
||||
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
return optimizer.getAccessOptimizer().getPropertyValues( component );
|
||||
}
|
||||
else {
|
||||
return super.getPropertyValues( component );
|
||||
}
|
||||
}
|
||||
|
||||
public void setPropertyValues(Object component, Object[] values) throws HibernateException {
|
||||
if ( optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
optimizer.getAccessOptimizer().setPropertyValues( component, values );
|
||||
}
|
||||
else {
|
||||
super.setPropertyValues( component, values );
|
||||
}
|
||||
}
|
||||
|
||||
public Object getParent(Object component) {
|
||||
return parentGetter.get( component );
|
||||
}
|
||||
|
||||
public boolean hasParentProperty() {
|
||||
return parentGetter != null;
|
||||
}
|
||||
|
||||
public boolean isMethodOf(Method method) {
|
||||
for ( int i = 0; i < propertySpan; i++ ) {
|
||||
final Method getterMethod = getters[i].getMethod();
|
||||
if ( getterMethod != null && getterMethod.equals( method ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setParent(Object component, Object parent, SessionFactoryImplementor factory) {
|
||||
parentSetter.set( component, parent, factory );
|
||||
}
|
||||
|
||||
protected Instantiator buildInstantiator(Component component) {
|
||||
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) {
|
||||
return new ProxiedInstantiator( component );
|
||||
}
|
||||
if ( optimizer == null ) {
|
||||
return new PojoInstantiator( component, null );
|
||||
}
|
||||
else {
|
||||
return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() );
|
||||
}
|
||||
}
|
||||
|
||||
protected Getter buildGetter(Component component, Property prop) {
|
||||
return prop.getGetter( component.getComponentClass() );
|
||||
}
|
||||
|
||||
protected Setter buildSetter(Component component, Property prop) {
|
||||
return prop.getSetter( component.getComponentClass() );
|
||||
}
|
||||
|
||||
private static class ProxiedInstantiator implements Instantiator {
|
||||
private final Class proxiedClass;
|
||||
private final BasicProxyFactory factory;
|
||||
|
||||
public ProxiedInstantiator(Component component) {
|
||||
proxiedClass = component.getComponentClass();
|
||||
if ( proxiedClass.isInterface() ) {
|
||||
factory = Environment.getBytecodeProvider()
|
||||
.getProxyFactoryFactory()
|
||||
.buildBasicProxyFactory( null, new Class[] { proxiedClass } );
|
||||
}
|
||||
else {
|
||||
factory = Environment.getBytecodeProvider()
|
||||
.getProxyFactoryFactory()
|
||||
.buildBasicProxyFactory( proxiedClass, null );
|
||||
}
|
||||
}
|
||||
|
||||
public Object instantiate(Serializable id) {
|
||||
throw new AssertionFailure( "ProxiedInstantiator can only be used to instantiate component" );
|
||||
}
|
||||
|
||||
public Object instantiate() {
|
||||
return factory.getProxy();
|
||||
}
|
||||
|
||||
public boolean isInstance(Object object) {
|
||||
return proxiedClass.isInstance( object );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,379 +1,379 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.tuple.entity;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.classic.Validatable;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.intercept.FieldInterceptor;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Subclass;
|
||||
import org.hibernate.property.Getter;
|
||||
import org.hibernate.property.Setter;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.ProxyFactory;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.tuple.PojoInstantiator;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* An {@link EntityTuplizer} specific to the pojo entity mode.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
||||
|
||||
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, PojoEntityTuplizer.class.getName());
|
||||
|
||||
private final Class mappedClass;
|
||||
private final Class proxyInterface;
|
||||
private final boolean lifecycleImplementor;
|
||||
private final boolean validatableImplementor;
|
||||
private final Set lazyPropertyNames = new HashSet();
|
||||
private final ReflectionOptimizer optimizer;
|
||||
|
||||
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
|
||||
super( entityMetamodel, mappedEntity );
|
||||
this.mappedClass = mappedEntity.getMappedClass();
|
||||
this.proxyInterface = mappedEntity.getProxyInterface();
|
||||
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
|
||||
this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );
|
||||
|
||||
Iterator iter = mappedEntity.getPropertyClosureIterator();
|
||||
while ( iter.hasNext() ) {
|
||||
Property property = (Property) iter.next();
|
||||
if ( property.isLazy() ) {
|
||||
lazyPropertyNames.add( property.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
String[] getterNames = new String[propertySpan];
|
||||
String[] setterNames = new String[propertySpan];
|
||||
Class[] propTypes = new Class[propertySpan];
|
||||
for ( int i = 0; i < propertySpan; i++ ) {
|
||||
getterNames[i] = getters[i].getMethodName();
|
||||
setterNames[i] = setters[i].getMethodName();
|
||||
propTypes[i] = getters[i].getReturnType();
|
||||
}
|
||||
|
||||
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
|
||||
optimizer = null;
|
||||
}
|
||||
else {
|
||||
// todo : YUCK!!!
|
||||
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes );
|
||||
// optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
|
||||
// mappedClass, getterNames, setterNames, propTypes
|
||||
// );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
|
||||
// determine the id getter and setter methods from the proxy interface (if any)
|
||||
// determine all interfaces needed by the resulting proxy
|
||||
HashSet<Class> proxyInterfaces = new HashSet<Class>();
|
||||
proxyInterfaces.add( HibernateProxy.class );
|
||||
|
||||
Class mappedClass = persistentClass.getMappedClass();
|
||||
Class proxyInterface = persistentClass.getProxyInterface();
|
||||
|
||||
if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) {
|
||||
if ( !proxyInterface.isInterface() ) {
|
||||
throw new MappingException(
|
||||
"proxy must be either an interface, or the class itself: " + getEntityName()
|
||||
);
|
||||
}
|
||||
proxyInterfaces.add( proxyInterface );
|
||||
}
|
||||
|
||||
if ( mappedClass.isInterface() ) {
|
||||
proxyInterfaces.add( mappedClass );
|
||||
}
|
||||
|
||||
Iterator subclasses = persistentClass.getSubclassIterator();
|
||||
while ( subclasses.hasNext() ) {
|
||||
final Subclass subclass = ( Subclass ) subclasses.next();
|
||||
final Class subclassProxy = subclass.getProxyInterface();
|
||||
final Class subclassClass = subclass.getMappedClass();
|
||||
if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
|
||||
if ( !subclassProxy.isInterface() ) {
|
||||
throw new MappingException(
|
||||
"proxy must be either an interface, or the class itself: " + subclass.getEntityName()
|
||||
);
|
||||
}
|
||||
proxyInterfaces.add( subclassProxy );
|
||||
}
|
||||
}
|
||||
|
||||
Iterator properties = persistentClass.getPropertyIterator();
|
||||
Class clazz = persistentClass.getMappedClass();
|
||||
while ( properties.hasNext() ) {
|
||||
Property property = (Property) properties.next();
|
||||
Method method = property.getGetter(clazz).getMethod();
|
||||
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
|
||||
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
|
||||
}
|
||||
method = property.getSetter(clazz).getMethod();
|
||||
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
|
||||
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Method idGetterMethod = idGetter==null ? null : idGetter.getMethod();
|
||||
Method idSetterMethod = idSetter==null ? null : idSetter.getMethod();
|
||||
|
||||
Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ?
|
||||
null :
|
||||
ReflectHelper.getMethod(proxyInterface, idGetterMethod);
|
||||
Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null ?
|
||||
null :
|
||||
ReflectHelper.getMethod(proxyInterface, idSetterMethod);
|
||||
|
||||
ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
|
||||
try {
|
||||
pf.postInstantiate(
|
||||
getEntityName(),
|
||||
mappedClass,
|
||||
proxyInterfaces,
|
||||
proxyGetIdentifierMethod,
|
||||
proxySetIdentifierMethod,
|
||||
persistentClass.hasEmbeddedIdentifier() ?
|
||||
(CompositeType) persistentClass.getIdentifier().getType() :
|
||||
null
|
||||
);
|
||||
}
|
||||
catch ( HibernateException he ) {
|
||||
LOG.unableToCreateProxyFactory(getEntityName(), he);
|
||||
pf = null;
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
|
||||
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
|
||||
// TODO : YUCK!!! fix after HHH-1907 is complete
|
||||
return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
|
||||
// return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Instantiator buildInstantiator(PersistentClass persistentClass) {
|
||||
if ( optimizer == null ) {
|
||||
return new PojoInstantiator( persistentClass, null );
|
||||
}
|
||||
else {
|
||||
return new PojoInstantiator( persistentClass, optimizer.getInstantiationOptimizer() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
|
||||
if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
setPropertyValuesWithOptimizer( entity, values );
|
||||
}
|
||||
else {
|
||||
super.setPropertyValues( entity, values );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object[] getPropertyValues(Object entity) throws HibernateException {
|
||||
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
return getPropertyValuesWithOptimizer( entity );
|
||||
}
|
||||
else {
|
||||
return super.getPropertyValues( entity );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session) throws HibernateException {
|
||||
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
return getPropertyValuesWithOptimizer( entity );
|
||||
}
|
||||
else {
|
||||
return super.getPropertyValuesToInsert( entity, mergeMap, session );
|
||||
}
|
||||
}
|
||||
|
||||
protected void setPropertyValuesWithOptimizer(Object object, Object[] values) {
|
||||
optimizer.getAccessOptimizer().setPropertyValues( object, values );
|
||||
}
|
||||
|
||||
protected Object[] getPropertyValuesWithOptimizer(Object object) {
|
||||
return optimizer.getAccessOptimizer().getPropertyValues( object );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public EntityMode getEntityMode() {
|
||||
return EntityMode.POJO;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Class getMappedClass() {
|
||||
return mappedClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isLifecycleImplementor() {
|
||||
return lifecycleImplementor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidatableImplementor() {
|
||||
return validatableImplementor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
|
||||
return mappedProperty.getGetter( mappedEntity.getMappedClass() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
|
||||
return mappedProperty.getSetter( mappedEntity.getMappedClass() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Class getConcreteProxyClass() {
|
||||
return proxyInterface;
|
||||
}
|
||||
|
||||
//TODO: need to make the majority of this functionality into a top-level support class for custom impl support
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {
|
||||
if ( isInstrumented() ) {
|
||||
Set lazyProps = lazyPropertiesAreUnfetched && getEntityMetamodel().hasLazyProperties() ?
|
||||
lazyPropertyNames : null;
|
||||
//TODO: if we support multiple fetch groups, we would need
|
||||
// to clone the set of lazy properties!
|
||||
FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean hasUninitializedLazyProperties(Object entity) {
|
||||
if ( getEntityMetamodel().hasLazyProperties() ) {
|
||||
FieldInterceptor callback = FieldInterceptionHelper.extractFieldInterceptor( entity );
|
||||
return callback != null && !callback.isInitialized();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isInstrumented() {
|
||||
return FieldInterceptionHelper.isInstrumented( getMappedClass() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
|
||||
final Class concreteEntityClass = entityInstance.getClass();
|
||||
if ( concreteEntityClass == getMappedClass() ) {
|
||||
return getEntityName();
|
||||
}
|
||||
else {
|
||||
String entityName = getEntityMetamodel().findEntityNameByEntityClass( concreteEntityClass );
|
||||
if ( entityName == null ) {
|
||||
throw new HibernateException(
|
||||
"Unable to resolve entity name from Class [" + concreteEntityClass.getName() + "]"
|
||||
+ " expected instance/subclass of [" + getEntityName() + "]"
|
||||
);
|
||||
}
|
||||
return entityName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public EntityNameResolver[] getEntityNameResolvers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.classic.Validatable;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Subclass;
|
||||
import org.hibernate.property.Getter;
|
||||
import org.hibernate.property.Setter;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.ProxyFactory;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.tuple.PojoInstantiator;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* An {@link EntityTuplizer} specific to the pojo entity mode.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
||||
|
||||
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, PojoEntityTuplizer.class.getName());
|
||||
|
||||
private final Class mappedClass;
|
||||
private final Class proxyInterface;
|
||||
private final boolean lifecycleImplementor;
|
||||
private final boolean validatableImplementor;
|
||||
private final Set lazyPropertyNames = new HashSet();
|
||||
private final ReflectionOptimizer optimizer;
|
||||
|
||||
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
|
||||
super( entityMetamodel, mappedEntity );
|
||||
this.mappedClass = mappedEntity.getMappedClass();
|
||||
this.proxyInterface = mappedEntity.getProxyInterface();
|
||||
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
|
||||
this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );
|
||||
|
||||
Iterator iter = mappedEntity.getPropertyClosureIterator();
|
||||
while ( iter.hasNext() ) {
|
||||
Property property = (Property) iter.next();
|
||||
if ( property.isLazy() ) {
|
||||
lazyPropertyNames.add( property.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
String[] getterNames = new String[propertySpan];
|
||||
String[] setterNames = new String[propertySpan];
|
||||
Class[] propTypes = new Class[propertySpan];
|
||||
for ( int i = 0; i < propertySpan; i++ ) {
|
||||
getterNames[i] = getters[i].getMethodName();
|
||||
setterNames[i] = setters[i].getMethodName();
|
||||
propTypes[i] = getters[i].getReturnType();
|
||||
}
|
||||
|
||||
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
|
||||
optimizer = null;
|
||||
}
|
||||
else {
|
||||
// todo : YUCK!!!
|
||||
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes );
|
||||
// optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
|
||||
// mappedClass, getterNames, setterNames, propTypes
|
||||
// );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
|
||||
// determine the id getter and setter methods from the proxy interface (if any)
|
||||
// determine all interfaces needed by the resulting proxy
|
||||
HashSet<Class> proxyInterfaces = new HashSet<Class>();
|
||||
proxyInterfaces.add( HibernateProxy.class );
|
||||
|
||||
Class mappedClass = persistentClass.getMappedClass();
|
||||
Class proxyInterface = persistentClass.getProxyInterface();
|
||||
|
||||
if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) {
|
||||
if ( !proxyInterface.isInterface() ) {
|
||||
throw new MappingException(
|
||||
"proxy must be either an interface, or the class itself: " + getEntityName()
|
||||
);
|
||||
}
|
||||
proxyInterfaces.add( proxyInterface );
|
||||
}
|
||||
|
||||
if ( mappedClass.isInterface() ) {
|
||||
proxyInterfaces.add( mappedClass );
|
||||
}
|
||||
|
||||
Iterator subclasses = persistentClass.getSubclassIterator();
|
||||
while ( subclasses.hasNext() ) {
|
||||
final Subclass subclass = ( Subclass ) subclasses.next();
|
||||
final Class subclassProxy = subclass.getProxyInterface();
|
||||
final Class subclassClass = subclass.getMappedClass();
|
||||
if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
|
||||
if ( !subclassProxy.isInterface() ) {
|
||||
throw new MappingException(
|
||||
"proxy must be either an interface, or the class itself: " + subclass.getEntityName()
|
||||
);
|
||||
}
|
||||
proxyInterfaces.add( subclassProxy );
|
||||
}
|
||||
}
|
||||
|
||||
Iterator properties = persistentClass.getPropertyIterator();
|
||||
Class clazz = persistentClass.getMappedClass();
|
||||
while ( properties.hasNext() ) {
|
||||
Property property = (Property) properties.next();
|
||||
Method method = property.getGetter(clazz).getMethod();
|
||||
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
|
||||
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
|
||||
}
|
||||
method = property.getSetter(clazz).getMethod();
|
||||
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
|
||||
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Method idGetterMethod = idGetter==null ? null : idGetter.getMethod();
|
||||
Method idSetterMethod = idSetter==null ? null : idSetter.getMethod();
|
||||
|
||||
Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ?
|
||||
null :
|
||||
ReflectHelper.getMethod(proxyInterface, idGetterMethod);
|
||||
Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null ?
|
||||
null :
|
||||
ReflectHelper.getMethod(proxyInterface, idSetterMethod);
|
||||
|
||||
ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
|
||||
try {
|
||||
pf.postInstantiate(
|
||||
getEntityName(),
|
||||
mappedClass,
|
||||
proxyInterfaces,
|
||||
proxyGetIdentifierMethod,
|
||||
proxySetIdentifierMethod,
|
||||
persistentClass.hasEmbeddedIdentifier() ?
|
||||
(CompositeType) persistentClass.getIdentifier().getType() :
|
||||
null
|
||||
);
|
||||
}
|
||||
catch ( HibernateException he ) {
|
||||
LOG.unableToCreateProxyFactory(getEntityName(), he);
|
||||
pf = null;
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
|
||||
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
|
||||
// TODO : YUCK!!! fix after HHH-1907 is complete
|
||||
return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
|
||||
// return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Instantiator buildInstantiator(PersistentClass persistentClass) {
|
||||
if ( optimizer == null ) {
|
||||
return new PojoInstantiator( persistentClass, null );
|
||||
}
|
||||
else {
|
||||
return new PojoInstantiator( persistentClass, optimizer.getInstantiationOptimizer() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
|
||||
if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
setPropertyValuesWithOptimizer( entity, values );
|
||||
}
|
||||
else {
|
||||
super.setPropertyValues( entity, values );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object[] getPropertyValues(Object entity) throws HibernateException {
|
||||
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
return getPropertyValuesWithOptimizer( entity );
|
||||
}
|
||||
else {
|
||||
return super.getPropertyValues( entity );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session) throws HibernateException {
|
||||
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
|
||||
return getPropertyValuesWithOptimizer( entity );
|
||||
}
|
||||
else {
|
||||
return super.getPropertyValuesToInsert( entity, mergeMap, session );
|
||||
}
|
||||
}
|
||||
|
||||
protected void setPropertyValuesWithOptimizer(Object object, Object[] values) {
|
||||
optimizer.getAccessOptimizer().setPropertyValues( object, values );
|
||||
}
|
||||
|
||||
protected Object[] getPropertyValuesWithOptimizer(Object object) {
|
||||
return optimizer.getAccessOptimizer().getPropertyValues( object );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public EntityMode getEntityMode() {
|
||||
return EntityMode.POJO;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Class getMappedClass() {
|
||||
return mappedClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isLifecycleImplementor() {
|
||||
return lifecycleImplementor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidatableImplementor() {
|
||||
return validatableImplementor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
|
||||
return mappedProperty.getGetter( mappedEntity.getMappedClass() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
|
||||
return mappedProperty.getSetter( mappedEntity.getMappedClass() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Class getConcreteProxyClass() {
|
||||
return proxyInterface;
|
||||
}
|
||||
|
||||
//TODO: need to make the majority of this functionality into a top-level support class for custom impl support
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {
|
||||
if ( isInstrumented() ) {
|
||||
Set lazyProps = lazyPropertiesAreUnfetched && getEntityMetamodel().hasLazyProperties() ?
|
||||
lazyPropertyNames : null;
|
||||
//TODO: if we support multiple fetch groups, we would need
|
||||
// to clone the set of lazy properties!
|
||||
FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean hasUninitializedLazyProperties(Object entity) {
|
||||
if ( getEntityMetamodel().hasLazyProperties() ) {
|
||||
FieldInterceptor callback = FieldInterceptionHelper.extractFieldInterceptor( entity );
|
||||
return callback != null && !callback.isInitialized();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isInstrumented() {
|
||||
return FieldInterceptionHelper.isInstrumented( getMappedClass() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
|
||||
final Class concreteEntityClass = entityInstance.getClass();
|
||||
if ( concreteEntityClass == getMappedClass() ) {
|
||||
return getEntityName();
|
||||
}
|
||||
else {
|
||||
String entityName = getEntityMetamodel().findEntityNameByEntityClass( concreteEntityClass );
|
||||
if ( entityName == null ) {
|
||||
throw new HibernateException(
|
||||
"Unable to resolve entity name from Class [" + concreteEntityClass.getName() + "]"
|
||||
+ " expected instance/subclass of [" + getEntityName() + "]"
|
||||
);
|
||||
}
|
||||
return entityName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public EntityNameResolver[] getEntityNameResolvers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
package org.hibernate.type;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.intercept.LazyPropertyInitializer;
|
||||
import org.hibernate.property.BackrefPropertyAccessor;
|
||||
import org.hibernate.tuple.StandardProperty;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.text.ParseException;
|
|||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
|
||||
import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.test.bytecode.javassist;
|
||||
|
||||
import org.hibernate.bytecode.ReflectionOptimizer;
|
||||
import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.test.instrument.buildtime;
|
||||
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package org.hibernate.test.instrument.cases;
|
||||
import java.util.HashSet;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
|
||||
import org.hibernate.test.instrument.domain.Document;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
|
||||
public void execute() {
|
||||
Document doc = new Document();
|
||||
FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
|
||||
doc.getId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
|
||||
public void execute() {
|
||||
Document doc = new Document();
|
||||
FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
|
||||
doc.getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,88 +2,89 @@ package org.hibernate.test.instrument.cases;
|
|||
import java.util.Iterator;
|
||||
import junit.framework.Assert;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
|
||||
import org.hibernate.test.instrument.domain.Problematic;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
|
||||
|
||||
protected String[] getResources() {
|
||||
return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
|
||||
}
|
||||
|
||||
public void execute() throws Exception {
|
||||
Session s = getFactory().openSession();
|
||||
Problematic p = new Problematic();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
p.setName( "whatever" );
|
||||
p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
// this access should be ok because p1 is not a lazy proxy
|
||||
s = getFactory().openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
|
||||
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = getFactory().openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = getFactory().openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.load( Problematic.class, p.getId() );
|
||||
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.setRepresentation( p.getRepresentation() );
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
Session s = getFactory().openSession();
|
||||
s.beginTransaction();
|
||||
Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
Problematic p = (Problematic) itr.next();
|
||||
s.delete( p );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
|
||||
|
||||
protected String[] getResources() {
|
||||
return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
|
||||
}
|
||||
|
||||
public void execute() throws Exception {
|
||||
Session s = getFactory().openSession();
|
||||
Problematic p = new Problematic();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
p.setName( "whatever" );
|
||||
p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
// this access should be ok because p1 is not a lazy proxy
|
||||
s = getFactory().openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
|
||||
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = getFactory().openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = getFactory().openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.load( Problematic.class, p.getId() );
|
||||
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.setRepresentation( p.getRepresentation() );
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
Session s = getFactory().openSession();
|
||||
s.beginTransaction();
|
||||
Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
Problematic p = (Problematic) itr.next();
|
||||
s.delete( p );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
|
@ -26,10 +26,10 @@ package org.hibernate.test.instrument.runtime;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.BytecodeProvider;
|
||||
import org.hibernate.bytecode.InstrumentedClassLoader;
|
||||
import org.hibernate.bytecode.util.BasicClassFilter;
|
||||
import org.hibernate.bytecode.util.FieldFilter;
|
||||
import org.hibernate.bytecode.buildtime.spi.BasicClassFilter;
|
||||
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
|
||||
import org.hibernate.bytecode.spi.BytecodeProvider;
|
||||
import org.hibernate.bytecode.spi.InstrumentedClassLoader;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.instrument.runtime;
|
||||
|
||||
import org.hibernate.bytecode.BytecodeProvider;
|
||||
import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
|
||||
protected BytecodeProvider buildBytecodeProvider() {
|
||||
return new BytecodeProviderImpl();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.instrument.runtime;
|
||||
|
||||
import org.hibernate.bytecode.spi.BytecodeProvider;
|
||||
import org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
|
||||
protected BytecodeProvider buildBytecodeProvider() {
|
||||
return new BytecodeProviderImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ package org.hibernate.test.nonflushedchanges;
|
|||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.criterion.Projections;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -27,10 +27,10 @@ import org.hibernate.Hibernate;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.criterion.Projections;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertSame;
|
||||
|
||||
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.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
|
|
|
@ -24,8 +24,10 @@ import java.lang.instrument.IllegalClassFormatException;
|
|||
import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +37,7 @@ import org.hibernate.cfg.Environment;
|
|||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class InterceptFieldClassFileTransformer implements javax.persistence.spi.ClassTransformer {
|
||||
private org.hibernate.bytecode.ClassTransformer classTransformer;
|
||||
private ClassTransformer classTransformer;
|
||||
|
||||
public InterceptFieldClassFileTransformer(List<String> entities) {
|
||||
final List<String> copyEntities = new ArrayList<String>( entities.size() );
|
||||
|
|
|
@ -14,8 +14,8 @@ import javax.persistence.PersistenceException;
|
|||
import javax.persistence.spi.LoadState;
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.intercept.FieldInterceptionHelper;
|
||||
import org.hibernate.intercept.FieldInterceptor;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class InterceptFieldClassFileTransformerTest extends TestCase {
|
|||
Class clazz = cl.loadClass( entities.get( 0 ) );
|
||||
|
||||
// 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" );
|
||||
assertNotNull( method );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue