use of org.hibernate.bytecode.spi.ReflectionOptimizer in project hibernate-orm by hibernate.
the class ReflectionOptimizerTest method testInterface.
@Test
@TestForIssue(jiraKey = "HHH-12584")
public void testInterface() {
BytecodeProvider provider = Environment.getBytecodeProvider();
ReflectionOptimizer reflectionOptimizer = provider.getReflectionOptimizer(Interface.class, new String[] { "getProperty" }, new String[] { "setProperty" }, new Class[] { String.class });
assertNotNull(reflectionOptimizer);
}
use of org.hibernate.bytecode.spi.ReflectionOptimizer in project hibernate-orm by hibernate.
the class ReflectionOptimizerTest method testAbstractClass.
@Test
@TestForIssue(jiraKey = "HHH-12584")
public void testAbstractClass() {
BytecodeProvider provider = Environment.getBytecodeProvider();
ReflectionOptimizer reflectionOptimizer = provider.getReflectionOptimizer(AbstractClass.class, new String[] { "getProperty" }, new String[] { "setProperty" }, new Class[] { String.class });
assertNotNull(reflectionOptimizer);
}
use of org.hibernate.bytecode.spi.ReflectionOptimizer in project hibernate-orm by hibernate.
the class ReflectionOptimizerTest method testReflectionOptimization.
@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);
}
use of org.hibernate.bytecode.spi.ReflectionOptimizer in project micronaut-sql by micronaut-projects.
the class IntrospectedHibernateBytecodeProvider method getReflectionOptimizer.
@Override
public ReflectionOptimizer getReflectionOptimizer(Class clazz, String[] getterNames, String[] setterNames, Class[] types) {
Optional<BeanIntrospection<?>> optionalBeanIntrospection = BeanIntrospector.SHARED.findIntrospection(clazz);
return optionalBeanIntrospection.map(beanIntrospection -> new ReflectionOptimizer() {
@Override
public InstantiationOptimizer getInstantiationOptimizer() {
return beanIntrospection::instantiate;
}
@Override
public AccessOptimizer getAccessOptimizer() {
BeanProperty[] beanProperties = beanIntrospection.getBeanProperties().toArray(new BeanProperty[0]);
return new AccessOptimizer() {
private final String[] propertyNames = Arrays.stream(beanProperties).map(BeanProperty::getName).toArray(String[]::new);
@Override
public String[] getPropertyNames() {
return propertyNames;
}
@Override
public Object[] getPropertyValues(Object object) {
Object[] values = new Object[beanProperties.length];
for (int i = 0; i < beanProperties.length; i++) {
BeanProperty beanProperty = beanProperties[i];
values[i] = beanProperty.get(i);
}
return values;
}
@Override
public void setPropertyValues(Object object, Object[] values) {
for (int i = 0; i < beanProperties.length; i++) {
BeanProperty beanProperty = beanProperties[i];
beanProperty.set(object, values[i]);
}
}
};
}
}).orElse(null);
}
use of org.hibernate.bytecode.spi.ReflectionOptimizer in project hibernate-orm by hibernate.
the class ReflectionOptimizerTest method testReflectionOptimization.
@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);
}
Aggregations