use of org.hibernate.property.access.spi.PropertyAccess in project hibernate-orm by hibernate.
the class AbstractProducedQuery method setProperties.
@Override
@SuppressWarnings("unchecked")
public QueryImplementor setProperties(Object bean) {
Class clazz = bean.getClass();
String[] params = getNamedParameters();
for (String namedParam : params) {
try {
final PropertyAccess propertyAccess = BuiltInPropertyAccessStrategies.BASIC.getStrategy().buildPropertyAccess(clazz, namedParam);
final Getter getter = propertyAccess.getGetter();
final Class retType = getter.getReturnType();
final Object object = getter.get(bean);
if (Collection.class.isAssignableFrom(retType)) {
setParameterList(namedParam, (Collection) object);
} else if (retType.isArray()) {
setParameterList(namedParam, (Object[]) object);
} else {
Type type = determineType(namedParam, retType);
setParameter(namedParam, object, type);
}
} catch (PropertyNotFoundException pnfe) {
// ignore
}
}
return this;
}
use of org.hibernate.property.access.spi.PropertyAccess in project hibernate-orm by hibernate.
the class PropertyAccessStrategyMapTest method testBasic.
private void testBasic(final Class<?> clazz) {
final String key = "testKey";
final String value = "testValue";
final PropertyAccessStrategyMapImpl accessStrategy = PropertyAccessStrategyMapImpl.INSTANCE;
final PropertyAccess access = accessStrategy.buildPropertyAccess(clazz, key);
final HashMap<String, String> map = new HashMap<>();
access.getSetter().set(map, value, null);
assertEquals(value, map.get(key));
assertEquals(value, access.getGetter().get(map));
}
use of org.hibernate.property.access.spi.PropertyAccess in project hibernate-orm by hibernate.
the class PropertyFactory method getGetter.
private static Getter getGetter(Property mappingProperty) {
if (mappingProperty == null || !mappingProperty.getPersistentClass().hasPojoRepresentation()) {
return null;
}
final PropertyAccessStrategyResolver propertyAccessStrategyResolver = mappingProperty.getPersistentClass().getServiceRegistry().getService(PropertyAccessStrategyResolver.class);
final PropertyAccessStrategy propertyAccessStrategy = propertyAccessStrategyResolver.resolvePropertyAccessStrategy(mappingProperty.getClass(), mappingProperty.getPropertyAccessorName(), EntityMode.POJO);
final PropertyAccess propertyAccess = propertyAccessStrategy.buildPropertyAccess(mappingProperty.getPersistentClass().getMappedClass(), mappingProperty.getName());
return propertyAccess.getGetter();
}
Aggregations