public Object instantiate() { if ( isAbstract ) { throw new InstantiationException( "Cannot instantiate abstract class or interface: ", mappedClass ); } else if ( optimizer != null ) { return optimizer.newInstance(); } else if ( constructor == null ) { throw new InstantiationException( "No default constructor for entity: ", mappedClass ); } else { try { return applyInterception( constructor.newInstance( (Object[]) null ) ); } catch ( Exception e ) { throw new InstantiationException( "Could not instantiate entity: ", mappedClass, e ); } } }
@Test public void testReflectionOptimization() { BytecodeProvider provider = Environment.getBytecodeProvider(); ReflectionOptimizer optimizer = provider.getReflectionOptimizer( Bean.class, BeanReflectionHelper.getGetterNames(), BeanReflectionHelper.getSetterNames(), BeanReflectionHelper.getTypes() ); assertNotNull( optimizer ); assertNotNull( optimizer.getInstantiationOptimizer() ); assertNotNull( optimizer.getAccessOptimizer() ); Object instance = optimizer.getInstantiationOptimizer().newInstance(); assertEquals( instance.getClass(), Bean.class ); Bean bean = ( Bean ) instance; optimizer.getAccessOptimizer().setPropertyValues( bean, BeanReflectionHelper.TEST_VALUES ); assertEquals( bean.getSomeString(), BeanReflectionHelper.TEST_VALUES[0] ); Object[] values = optimizer.getAccessOptimizer().getPropertyValues( bean ); assertEquivalent( values, BeanReflectionHelper.TEST_VALUES ); }
public Object instantiate() { if ( isAbstract ) { throw new InstantiationException( "Cannot instantiate abstract class or interface: ", mappedClass ); } else if ( optimizer != null ) { return optimizer.newInstance(); } else if ( constructor == null ) { throw new InstantiationException( "No default constructor for entity: ", mappedClass ); } else { try { return constructor.newInstance( (Object[]) null ); } catch ( Exception e ) { throw new InstantiationException( "Could not instantiate entity: ", mappedClass, e ); } } }
public Object instantiate() { if ( isAbstract ) { throw new InstantiationException( "Cannot instantiate abstract class or interface: ", mappedClass ); } else if ( optimizer != null ) { return optimizer.newInstance(); } else if ( constructor == null ) { throw new InstantiationException( "No default constructor for entity: ", mappedClass ); } else { try { return constructor.newInstance( (Object[]) null ); } catch ( Exception e ) { throw new InstantiationException( "Could not instantiate entity: ", mappedClass, e ); } } }
@Override public Object instantiate(SharedSessionContractImplementor session) { return instantiationOptimizer.newInstance(); } }