public org.hibernate.bytecode.ReflectionOptimizer | getReflectionOptimizer(java.lang.Class clazz, java.lang.String[] getterNames, java.lang.String[] setterNames, java.lang.Class[] types)
FastClass fastClass;
BulkAccessor bulkAccessor;
try {
fastClass = FastClass.create( clazz );
bulkAccessor = BulkAccessor.create( clazz, getterNames, setterNames, types );
if ( !clazz.isInterface() && !Modifier.isAbstract( clazz.getModifiers() ) ) {
if ( fastClass == null ) {
bulkAccessor = null;
}
else {
//test out the optimizer:
Object instance = fastClass.newInstance();
bulkAccessor.setPropertyValues( instance, bulkAccessor.getPropertyValues( instance ) );
}
}
}
catch ( Throwable t ) {
fastClass = null;
bulkAccessor = null;
String message = "reflection optimizer disabled for: " +
clazz.getName() +
" [" +
StringHelper.unqualify( t.getClass().getName() ) +
": " +
t.getMessage();
if ( t instanceof BulkAccessorException ) {
int index = ( ( BulkAccessorException ) t ).getIndex();
if ( index >= 0 ) {
message += " (property " + setterNames[index] + ")";
}
}
log.debug( message );
}
if ( fastClass != null && bulkAccessor != null ) {
return new ReflectionOptimizerImpl(
new InstantiationOptimizerAdapter( fastClass ),
new AccessOptimizerAdapter( bulkAccessor, clazz )
);
}
else {
return null;
}
|