HHH-6923 - Remove org.hibernate.service.instrumentation.spi.InstrumentationService
This commit is contained in:
parent
d50a66bc20
commit
537481adbd
|
@ -24,15 +24,21 @@
|
|||
package org.hibernate.bytecode.internal.javassist;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.bytecode.buildtime.spi.ClassFilter;
|
||||
import org.hibernate.bytecode.buildtime.spi.FieldFilter;
|
||||
import org.hibernate.bytecode.instrumentation.internal.javassist.JavassistHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.bytecode.spi.BytecodeProvider;
|
||||
import org.hibernate.bytecode.spi.ClassTransformer;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.bytecode.spi.NotInstrumentedException;
|
||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
|
@ -45,10 +51,12 @@ public class BytecodeProviderImpl implements BytecodeProvider {
|
|||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, BytecodeProviderImpl.class.getName());
|
||||
|
||||
@Override
|
||||
public ProxyFactoryFactory getProxyFactoryFactory() {
|
||||
return new ProxyFactoryFactoryImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReflectionOptimizer getReflectionOptimizer(
|
||||
Class clazz,
|
||||
String[] getterNames,
|
||||
|
@ -97,7 +105,71 @@ public class BytecodeProviderImpl implements BytecodeProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassTransformer getTransformer(ClassFilter classFilter, FieldFilter fieldFilter) {
|
||||
return new JavassistClassTransformer( classFilter, fieldFilter );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityInstrumentationMetadata getEntityInstrumentationMetadata(Class entityClass) {
|
||||
return new EntityInstrumentationMetadataImpl( entityClass );
|
||||
}
|
||||
|
||||
private class EntityInstrumentationMetadataImpl implements EntityInstrumentationMetadata {
|
||||
private final Class entityClass;
|
||||
private final boolean isInstrumented;
|
||||
|
||||
private EntityInstrumentationMetadataImpl(Class entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
this.isInstrumented = FieldHandled.class.isAssignableFrom( entityClass );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityName() {
|
||||
return entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstrumented() {
|
||||
return isInstrumented;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldInterceptor extractInterceptor(Object entity) throws NotInstrumentedException {
|
||||
if ( !entityClass.isInstance( entity ) ) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Passed entity instance [%s] is not of expected type [%s]",
|
||||
entity,
|
||||
getEntityName()
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( ! isInstrumented() ) {
|
||||
throw new NotInstrumentedException( String.format( "Entity class [%s] is not instrumented", getEntityName() ) );
|
||||
}
|
||||
return JavassistHelper.extractFieldInterceptor( entity );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldInterceptor injectInterceptor(
|
||||
Object entity,
|
||||
String entityName,
|
||||
Set uninitializedFieldNames,
|
||||
SessionImplementor session) throws NotInstrumentedException {
|
||||
if ( !entityClass.isInstance( entity ) ) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Passed entity instance [%s] is not of expected type [%s]",
|
||||
entity,
|
||||
getEntityName()
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( ! isInstrumented() ) {
|
||||
throw new NotInstrumentedException( String.format( "Entity class [%s] is not instrumented", getEntityName() ) );
|
||||
}
|
||||
return JavassistHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,4 +68,14 @@ public interface BytecodeProvider {
|
|||
* @return The appropriate ClassTransformer.
|
||||
*/
|
||||
public ClassTransformer getTransformer(ClassFilter classFilter, FieldFilter fieldFilter);
|
||||
|
||||
/**
|
||||
* Retrieve the interception metadata for the particular entity type.
|
||||
*
|
||||
* @param entityClass The entity class. Note: we pass class here instead of the usual "entity name" because
|
||||
* only real classes can be instrumented.
|
||||
*
|
||||
* @return The metadata
|
||||
*/
|
||||
public EntityInstrumentationMetadata getEntityInstrumentationMetadata(Class entityClass);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, 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.util.Set;
|
||||
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
||||
/**
|
||||
* Encapsulates bytecode instrumentation information about a particular entity.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EntityInstrumentationMetadata {
|
||||
/**
|
||||
* The name of the entity to which this metadata applies.
|
||||
*
|
||||
* @return The entity name
|
||||
*/
|
||||
public String getEntityName();
|
||||
|
||||
/**
|
||||
* Has the entity class been bytecode instrumented?
|
||||
*
|
||||
* @return {@code true} indicates the entity class is instrumented for Hibernate use; {@code false}
|
||||
* indicates it is not
|
||||
*/
|
||||
public boolean isInstrumented();
|
||||
|
||||
/**
|
||||
* Build and inject a field interceptor instance into the instrumented entity.
|
||||
*
|
||||
* @param entity The entity into which built interceptor should be injected
|
||||
* @param entityName The name of the entity
|
||||
* @param uninitializedFieldNames The name of fields marked as lazy
|
||||
* @param session The session to which the entity instance belongs.
|
||||
*
|
||||
* @return The built and injected interceptor
|
||||
*
|
||||
* @throws NotInstrumentedException Thrown if {@link #isInstrumented()} returns {@code false}
|
||||
*/
|
||||
public FieldInterceptor injectInterceptor(
|
||||
Object entity,
|
||||
String entityName,
|
||||
Set uninitializedFieldNames,
|
||||
SessionImplementor session) throws NotInstrumentedException;
|
||||
|
||||
/**
|
||||
* Extract the field interceptor instance from the instrumented entity.
|
||||
*
|
||||
* @param entity The entity from which to extract the interceptor
|
||||
*
|
||||
* @return The extracted interceptor
|
||||
*
|
||||
* @throws NotInstrumentedException Thrown if {@link #isInstrumented()} returns {@code false}
|
||||
*/
|
||||
public FieldInterceptor extractInterceptor(Object entity) throws NotInstrumentedException;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, 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 org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NotInstrumentedException extends HibernateException {
|
||||
public NotInstrumentedException(String message) {
|
||||
super( message );
|
||||
}
|
||||
|
||||
public NotInstrumentedException(String message, Throwable root) {
|
||||
super( message, root );
|
||||
}
|
||||
}
|
|
@ -31,11 +31,10 @@ import java.io.Serializable;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.UniqueKeyLoadable;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
|
||||
/**
|
||||
* We need an entry to tell us all about the current state of an object with respect to its persistent state
|
||||
|
@ -228,8 +227,11 @@ public final class EntityEntry implements Serializable {
|
|||
this.version = nextVersion;
|
||||
getPersister().setPropertyValue( entity, getPersister().getVersionProperty(), nextVersion );
|
||||
}
|
||||
if ( getPersister().getFactory().getServiceRegistry().getService( InstrumentationService.class ).isInstrumented( entity ) ) {
|
||||
FieldInterceptionHelper.clearDirty( entity );
|
||||
if ( getPersister().getInstrumentationMetadata().isInstrumented() ) {
|
||||
final FieldInterceptor interceptor = getPersister().getInstrumentationMetadata().extractInterceptor( entity );
|
||||
if ( interceptor != null ) {
|
||||
interceptor.clearDirty();
|
||||
}
|
||||
}
|
||||
|
||||
notifyLoadedStateUpdated();
|
||||
|
@ -270,8 +272,8 @@ public final class EntityEntry implements Serializable {
|
|||
public boolean requiresDirtyCheck(Object entity) {
|
||||
return isModifiableEntity() && (
|
||||
getPersister().hasMutableProperties() ||
|
||||
!getPersister().getFactory().getServiceRegistry().getService( InstrumentationService.class ).isInstrumented(entity) ||
|
||||
FieldInterceptionHelper.extractFieldInterceptor(entity).isDirty()
|
||||
!getPersister().getInstrumentationMetadata().isInstrumented() ||
|
||||
getPersister().getInstrumentationMetadata().extractInterceptor( entity ).isDirty()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.hibernate.NonUniqueObjectException;
|
|||
import org.hibernate.action.internal.AbstractEntityInsertAction;
|
||||
import org.hibernate.action.internal.EntityIdentityInsertAction;
|
||||
import org.hibernate.action.internal.EntityInsertAction;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
|
@ -50,7 +49,6 @@ import org.hibernate.id.IdentifierGeneratorHelper;
|
|||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
|
||||
|
@ -61,7 +59,7 @@ import org.hibernate.type.TypeHelper;
|
|||
*/
|
||||
public abstract class AbstractSaveEventListener extends AbstractReassociateEventListener {
|
||||
public enum EntityState{
|
||||
PERSISTENT, TRANSIENT, DETACHED, DELETED;
|
||||
PERSISTENT, TRANSIENT, DETACHED, DELETED
|
||||
}
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
|
@ -333,11 +331,8 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
}
|
||||
|
||||
private void markInterceptorDirty(Object entity, EntityPersister persister, EventSource source) {
|
||||
InstrumentationService instrumentationService = persister.getFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( InstrumentationService.class );
|
||||
if ( instrumentationService.isInstrumented( entity ) ) {
|
||||
FieldInterceptor interceptor = FieldInterceptionHelper.injectFieldInterceptor(
|
||||
if ( persister.getInstrumentationMetadata().isInstrumented() ) {
|
||||
FieldInterceptor interceptor = persister.getInstrumentationMetadata().injectInterceptor(
|
||||
entity,
|
||||
persister.getEntityName(),
|
||||
null,
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.action.internal.DelayedPostInsertIdentifier;
|
||||
import org.hibernate.action.internal.EntityUpdateAction;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.engine.internal.Nullability;
|
||||
import org.hibernate.engine.internal.Versioning;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
|
@ -46,7 +45,6 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
|
@ -244,12 +242,12 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
InstrumentationService instrumentationService = event.getSession()
|
||||
.getFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( InstrumentationService.class );
|
||||
if ( instrumentationService.isInstrumented( event.getEntity() ) ) {
|
||||
FieldInterceptionHelper.clearDirty( event.getEntity() );
|
||||
if ( event.getEntityEntry().getPersister().getInstrumentationMetadata().isInstrumented() ) {
|
||||
event.getEntityEntry()
|
||||
.getPersister()
|
||||
.getInstrumentationMetadata()
|
||||
.extractInterceptor( event.getEntity() )
|
||||
.clearDirty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,13 +33,11 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.ObjectDeletedException;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.WrongClassException;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.spi.CascadingAction;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.MergeEvent;
|
||||
|
@ -48,7 +46,6 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
import org.hibernate.type.ForeignKeyDirection;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
|
||||
|
@ -312,19 +309,16 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
copyValues(persister, entity, target, source, copyCache);
|
||||
|
||||
//copyValues works by reflection, so explicitly mark the entity instance dirty
|
||||
markInterceptorDirty( entity, target, persister.getFactory() );
|
||||
markInterceptorDirty( entity, target, persister );
|
||||
|
||||
event.setResult(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void markInterceptorDirty(final Object entity, final Object target, SessionFactoryImplementor factory) {
|
||||
InstrumentationService instrumentationService = factory
|
||||
.getServiceRegistry()
|
||||
.getService( InstrumentationService.class );
|
||||
if ( instrumentationService.isInstrumented( entity ) ) {
|
||||
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( target );
|
||||
private void markInterceptorDirty(final Object entity, final Object target, EntityPersister persister) {
|
||||
if ( persister.getInstrumentationMetadata().isInstrumented() ) {
|
||||
FieldInterceptor interceptor = persister.getInstrumentationMetadata().extractInterceptor( target );
|
||||
if ( interceptor != null ) {
|
||||
interceptor.dirty();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.FetchMode;
|
||||
|
@ -47,9 +49,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.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.cache.spi.CacheKey;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.entry.CacheEntry;
|
||||
|
@ -102,7 +104,6 @@ import org.hibernate.metamodel.relational.DerivedValue;
|
|||
import org.hibernate.metamodel.relational.Value;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.property.BackrefPropertyAccessor;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
import org.hibernate.sql.Alias;
|
||||
import org.hibernate.sql.Delete;
|
||||
import org.hibernate.sql.Insert;
|
||||
|
@ -113,7 +114,6 @@ import org.hibernate.sql.SelectFragment;
|
|||
import org.hibernate.sql.SimpleSelect;
|
||||
import org.hibernate.sql.Template;
|
||||
import org.hibernate.sql.Update;
|
||||
import org.hibernate.tuple.StandardProperty;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
import org.hibernate.type.AssociationType;
|
||||
|
@ -122,7 +122,6 @@ import org.hibernate.type.EntityType;
|
|||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
import org.hibernate.type.VersionType;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Basic functionality for persisting an entity via JDBC
|
||||
|
@ -3964,16 +3963,13 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
public void afterReassociate(Object entity, SessionImplementor session) {
|
||||
//if ( hasLazyProperties() ) {
|
||||
InstrumentationService instrumentationService = session.getFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( InstrumentationService.class );
|
||||
if ( instrumentationService.isInstrumented( entity ) ) {
|
||||
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
|
||||
if ( getEntityMetamodel().getInstrumentationMetadata().isInstrumented() ) {
|
||||
FieldInterceptor interceptor = getEntityMetamodel().getInstrumentationMetadata().extractInterceptor( entity );
|
||||
if ( interceptor != null ) {
|
||||
interceptor.setSession( session );
|
||||
}
|
||||
else {
|
||||
FieldInterceptor fieldInterceptor = FieldInterceptionHelper.injectFieldInterceptor(
|
||||
FieldInterceptor fieldInterceptor = getEntityMetamodel().getInstrumentationMetadata().injectInterceptor(
|
||||
entity,
|
||||
getEntityName(),
|
||||
null,
|
||||
|
@ -4153,7 +4149,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
public boolean isInstrumented() {
|
||||
return getEntityTuplizer().isInstrumented();
|
||||
return entityMetamodel.isInstrumented();
|
||||
}
|
||||
|
||||
public boolean hasInsertGeneratedProperties() {
|
||||
|
@ -4618,4 +4614,9 @@ public abstract class AbstractEntityPersister
|
|||
public EntityTuplizer getEntityTuplizer() {
|
||||
return entityTuplizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityInstrumentationMetadata getInstrumentationMetadata() {
|
||||
return entityMetamodel.getInstrumentationMetadata();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.cache.spi.OptimisticCacheSource;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.entry.CacheEntryStructure;
|
||||
|
@ -733,4 +734,6 @@ public interface EntityPersister extends OptimisticCacheSource {
|
|||
|
||||
public EntityMode getEntityMode();
|
||||
public EntityTuplizer getEntityTuplizer();
|
||||
|
||||
public EntityInstrumentationMetadata getInstrumentationMetadata();
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.id.factory.internal.MutableIdentifierGeneratorFactoryInitia
|
|||
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
|
||||
import org.hibernate.persister.internal.PersisterFactoryInitiator;
|
||||
import org.hibernate.service.config.internal.ConfigurationServiceInitiator;
|
||||
import org.hibernate.service.instrumentation.internal.InstrumentationServiceInitiator;
|
||||
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
|
||||
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||
import org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator;
|
||||
|
@ -59,6 +58,7 @@ public class StandardServiceInitiators {
|
|||
final List<BasicServiceInitiator> serviceInitiators = new ArrayList<BasicServiceInitiator>();
|
||||
|
||||
serviceInitiators.add( ConfigurationServiceInitiator.INSTANCE );
|
||||
serviceInitiators.add( ImportSqlCommandExtractorInitiator.INSTANCE );
|
||||
|
||||
serviceInitiators.add( JndiServiceInitiator.INSTANCE );
|
||||
serviceInitiators.add( JmxServiceInitiator.INSTANCE );
|
||||
|
@ -82,10 +82,6 @@ public class StandardServiceInitiators {
|
|||
|
||||
serviceInitiators.add( RegionFactoryInitiator.INSTANCE );
|
||||
|
||||
serviceInitiators.add( InstrumentationServiceInitiator.INSTANCE );
|
||||
|
||||
serviceInitiators.add( ImportSqlCommandExtractorInitiator.INSTANCE );
|
||||
|
||||
return Collections.unmodifiableList( serviceInitiators );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package org.hibernate.service.instrumentation.internal;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard <emmanuel@hibernate.org>
|
||||
*/
|
||||
public class CachingInstrumentationService implements InstrumentationService {
|
||||
|
||||
private final ConcurrentHashMap<Class<?>, Boolean> isInstrumentedCache = new ConcurrentHashMap<Class<?>, Boolean>( );
|
||||
|
||||
@Override
|
||||
public boolean isInstrumented(Class<?> entityType) {
|
||||
Boolean isInstrumented = isInstrumentedCache.get( entityType );
|
||||
if ( isInstrumented == null ) {
|
||||
isInstrumented = FieldInterceptionHelper.isInstrumented( entityType );
|
||||
isInstrumentedCache.put( entityType, isInstrumented );
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
return isInstrumented;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstrumented(Object entity) {
|
||||
return entity != null && isInstrumented( entity.getClass() );
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package org.hibernate.service.instrumentation.internal;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
import org.hibernate.service.spi.BasicServiceInitiator;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
/**
|
||||
* Simple ServiceInitiator for InstrumentationService
|
||||
*
|
||||
* @author Emmanuel Bernard <emmanuel@hibernate.org>
|
||||
*/
|
||||
public class InstrumentationServiceInitiator implements BasicServiceInitiator<InstrumentationService> {
|
||||
public static final InstrumentationServiceInitiator INSTANCE = new InstrumentationServiceInitiator();
|
||||
|
||||
@Override
|
||||
public InstrumentationService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
return new CachingInstrumentationService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<InstrumentationService> getServiceInitiated() {
|
||||
return InstrumentationService.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package org.hibernate.service.instrumentation.spi;
|
||||
|
||||
import org.hibernate.service.Service;
|
||||
|
||||
/**
|
||||
* Service caching instrumentation information
|
||||
*
|
||||
* @author Emmanuel Bernard <emmanuel@hibernate.org>
|
||||
*/
|
||||
public interface InstrumentationService extends Service {
|
||||
/**
|
||||
* Is entityType instrumented
|
||||
*/
|
||||
public boolean isInstrumented(Class<?> entityType);
|
||||
|
||||
/**
|
||||
* Is entity instrumented
|
||||
*/
|
||||
public boolean isInstrumented(Object entity);
|
||||
}
|
|
@ -37,6 +37,8 @@ import org.jboss.logging.Logger;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
import org.hibernate.engine.internal.Versioning;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
|
@ -54,7 +56,6 @@ import org.hibernate.metamodel.binding.BasicAttributeBinding;
|
|||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||
import org.hibernate.tuple.IdentifierProperty;
|
||||
import org.hibernate.tuple.PropertyFactory;
|
||||
import org.hibernate.tuple.StandardProperty;
|
||||
|
@ -131,7 +132,7 @@ public class EntityMetamodel implements Serializable {
|
|||
|
||||
private final EntityMode entityMode;
|
||||
private final EntityTuplizer entityTuplizer;
|
||||
private boolean lazyAvailable;
|
||||
private final EntityInstrumentationMetadata instrumentationMetadata;
|
||||
|
||||
public EntityMetamodel(PersistentClass persistentClass, SessionFactoryImplementor sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
|
@ -147,9 +148,10 @@ public class EntityMetamodel implements Serializable {
|
|||
|
||||
versioned = persistentClass.isVersioned();
|
||||
|
||||
InstrumentationService instrumentationService = sessionFactory.getServiceRegistry().getService( InstrumentationService.class );
|
||||
lazyAvailable = persistentClass.hasPojoRepresentation() &&
|
||||
instrumentationService.isInstrumented( persistentClass.getMappedClass() );
|
||||
instrumentationMetadata = persistentClass.hasPojoRepresentation()
|
||||
? Environment.getBytecodeProvider().getEntityInstrumentationMetadata( persistentClass.getMappedClass() )
|
||||
: new NonPojoInstrumentationMetadata( persistentClass.getEntityName() );
|
||||
|
||||
boolean hasLazy = false;
|
||||
|
||||
propertySpan = persistentClass.getPropertyClosureSpan();
|
||||
|
@ -187,10 +189,10 @@ public class EntityMetamodel implements Serializable {
|
|||
|
||||
if ( prop == persistentClass.getVersion() ) {
|
||||
tempVersionProperty = i;
|
||||
properties[i] = PropertyFactory.buildVersionProperty( prop, lazyAvailable );
|
||||
properties[i] = PropertyFactory.buildVersionProperty( prop, instrumentationMetadata.isInstrumented() );
|
||||
}
|
||||
else {
|
||||
properties[i] = PropertyFactory.buildStandardProperty( prop, lazyAvailable );
|
||||
properties[i] = PropertyFactory.buildStandardProperty( prop, instrumentationMetadata.isInstrumented() );
|
||||
}
|
||||
|
||||
if ( prop.isNaturalIdentifier() ) {
|
||||
|
@ -205,7 +207,7 @@ public class EntityMetamodel implements Serializable {
|
|||
}
|
||||
|
||||
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
boolean lazy = prop.isLazy() && lazyAvailable;
|
||||
boolean lazy = prop.isLazy() && instrumentationMetadata.isInstrumented();
|
||||
if ( lazy ) hasLazy = true;
|
||||
propertyLaziness[i] = lazy;
|
||||
|
||||
|
@ -375,15 +377,12 @@ public class EntityMetamodel implements Serializable {
|
|||
boolean hasPojoRepresentation = false;
|
||||
Class<?> mappedClass = null;
|
||||
Class<?> proxyInterfaceClass = null;
|
||||
lazyAvailable = false;
|
||||
if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) {
|
||||
hasPojoRepresentation = true;
|
||||
mappedClass = entityBinding.getEntity().getClassReference();
|
||||
proxyInterfaceClass = entityBinding.getProxyInterfaceType().getValue();
|
||||
InstrumentationService instrumentationService = sessionFactory.getServiceRegistry()
|
||||
.getService( InstrumentationService.class );
|
||||
lazyAvailable = instrumentationService.isInstrumented( mappedClass );
|
||||
}
|
||||
instrumentationMetadata = Environment.getBytecodeProvider().getEntityInstrumentationMetadata( mappedClass );
|
||||
|
||||
boolean hasLazy = false;
|
||||
|
||||
|
@ -432,11 +431,12 @@ public class EntityMetamodel implements Serializable {
|
|||
if ( attributeBinding == entityBinding.getHierarchyDetails().getVersioningAttributeBinding() ) {
|
||||
tempVersionProperty = i;
|
||||
properties[i] = PropertyFactory.buildVersionProperty(
|
||||
entityBinding.getHierarchyDetails().getVersioningAttributeBinding(), lazyAvailable
|
||||
entityBinding.getHierarchyDetails().getVersioningAttributeBinding(),
|
||||
instrumentationMetadata.isInstrumented()
|
||||
);
|
||||
}
|
||||
else {
|
||||
properties[i] = PropertyFactory.buildStandardProperty( attributeBinding, lazyAvailable );
|
||||
properties[i] = PropertyFactory.buildStandardProperty( attributeBinding, instrumentationMetadata.isInstrumented() );
|
||||
}
|
||||
|
||||
// TODO: fix when natural IDs are added (HHH-6354)
|
||||
|
@ -452,7 +452,7 @@ public class EntityMetamodel implements Serializable {
|
|||
}
|
||||
|
||||
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
boolean lazy = attributeBinding.isLazy() && lazyAvailable;
|
||||
boolean lazy = attributeBinding.isLazy() && instrumentationMetadata.isInstrumented();
|
||||
if ( lazy ) hasLazy = true;
|
||||
propertyLaziness[i] = lazy;
|
||||
|
||||
|
@ -944,6 +944,10 @@ public class EntityMetamodel implements Serializable {
|
|||
* Whether or not this class can be lazy (ie intercepted)
|
||||
*/
|
||||
public boolean isInstrumented() {
|
||||
return lazyAvailable;
|
||||
return instrumentationMetadata.isInstrumented();
|
||||
}
|
||||
|
||||
public EntityInstrumentationMetadata getInstrumentationMetadata() {
|
||||
return instrumentationMetadata;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, 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.util.Set;
|
||||
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.bytecode.spi.NotInstrumentedException;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NonPojoInstrumentationMetadata implements EntityInstrumentationMetadata {
|
||||
private final String entityName;
|
||||
private final String errorMsg;
|
||||
|
||||
public NonPojoInstrumentationMetadata(String entityName) {
|
||||
this.entityName = entityName;
|
||||
this.errorMsg = "Entity [" + entityName + "] is non-pojo, and therefore not instrumented";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstrumented() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldInterceptor extractInterceptor(Object entity) throws NotInstrumentedException {
|
||||
throw new NotInstrumentedException( errorMsg );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldInterceptor injectInterceptor(
|
||||
Object entity, String entityName, Set uninitializedFieldNames, SessionImplementor session)
|
||||
throws NotInstrumentedException {
|
||||
throw new NotInstrumentedException( errorMsg );
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.entry.CacheEntryStructure;
|
||||
|
@ -52,6 +53,7 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
import org.hibernate.persister.spi.PersisterClassResolver;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
import org.hibernate.tuple.entity.NonPojoInstrumentationMetadata;
|
||||
import org.hibernate.type.CollectionType;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.VersionType;
|
||||
|
@ -99,6 +101,11 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityInstrumentationMetadata getInstrumentationMetadata() {
|
||||
return new NonPojoInstrumentationMetadata( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInstantiate() throws MappingException {
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.entry.CacheEntryStructure;
|
||||
import org.hibernate.cache.spi.entry.UnstructuredCacheEntry;
|
||||
|
@ -30,6 +31,7 @@ import org.hibernate.metadata.ClassMetadata;
|
|||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
import org.hibernate.tuple.entity.NonPojoInstrumentationMetadata;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.VersionType;
|
||||
|
@ -627,4 +629,9 @@ public class CustomPersister implements EntityPersister {
|
|||
public EntityTuplizer getEntityTuplizer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityInstrumentationMetadata getInstrumentationMetadata() {
|
||||
return new NonPojoInstrumentationMetadata( getEntityName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.entry.CacheEntryStructure;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -54,6 +55,7 @@ import org.hibernate.persister.internal.PersisterClassResolverInitiator;
|
|||
import org.hibernate.persister.spi.PersisterClassResolver;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
import org.hibernate.tuple.entity.NonPojoInstrumentationMetadata;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.VersionType;
|
||||
|
||||
|
@ -121,6 +123,11 @@ public class PersisterClassProviderTest {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityInstrumentationMetadata getInstrumentationMetadata() {
|
||||
return new NonPojoInstrumentationMetadata( getEntityName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInstantiate() throws MappingException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue