Search in sources :

Example 1 with PropertyAccess

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;
}
Also used : FlushModeType(javax.persistence.FlushModeType) TemporalType(javax.persistence.TemporalType) LockModeType(javax.persistence.LockModeType) Type(org.hibernate.type.Type) PropertyNotFoundException(org.hibernate.PropertyNotFoundException) Getter(org.hibernate.property.access.spi.Getter) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess)

Example 2 with PropertyAccess

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));
}
Also used : HashMap(java.util.HashMap) PropertyAccessStrategyMapImpl(org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess)

Example 3 with PropertyAccess

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();
}
Also used : PropertyAccessStrategy(org.hibernate.property.access.spi.PropertyAccessStrategy) PropertyAccessStrategyResolver(org.hibernate.property.access.spi.PropertyAccessStrategyResolver) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess)

Aggregations

PropertyAccess (org.hibernate.property.access.spi.PropertyAccess)3 HashMap (java.util.HashMap)1 FlushModeType (javax.persistence.FlushModeType)1 LockModeType (javax.persistence.LockModeType)1 TemporalType (javax.persistence.TemporalType)1 PropertyNotFoundException (org.hibernate.PropertyNotFoundException)1 PropertyAccessStrategyMapImpl (org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl)1 Getter (org.hibernate.property.access.spi.Getter)1 PropertyAccessStrategy (org.hibernate.property.access.spi.PropertyAccessStrategy)1 PropertyAccessStrategyResolver (org.hibernate.property.access.spi.PropertyAccessStrategyResolver)1 Type (org.hibernate.type.Type)1