HHH-6735 Introduces an InstrumentationService that caches isInstrumented per class
This commit is contained in:
parent
fcf402c4af
commit
2357dcc442
|
@ -35,6 +35,7 @@ import org.hibernate.id.factory.internal.MutableIdentifierGeneratorFactoryInitia
|
||||||
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
|
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
|
||||||
import org.hibernate.persister.internal.PersisterFactoryInitiator;
|
import org.hibernate.persister.internal.PersisterFactoryInitiator;
|
||||||
import org.hibernate.service.config.internal.ConfigurationServiceInitiator;
|
import org.hibernate.service.config.internal.ConfigurationServiceInitiator;
|
||||||
|
import org.hibernate.service.instrumentation.internal.InstrumentationServiceInitiator;
|
||||||
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
|
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
|
||||||
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
import org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator;
|
import org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator;
|
||||||
|
@ -80,6 +81,8 @@ public class StandardServiceInitiators {
|
||||||
|
|
||||||
serviceInitiators.add( RegionFactoryInitiator.INSTANCE );
|
serviceInitiators.add( RegionFactoryInitiator.INSTANCE );
|
||||||
|
|
||||||
|
serviceInitiators.add( InstrumentationServiceInitiator.INSTANCE );
|
||||||
|
|
||||||
return Collections.unmodifiableList( serviceInitiators );
|
return Collections.unmodifiableList( serviceInitiators );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
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() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue