Search in sources :

Example 1 with Getter

use of org.hibernate.property.access.spi.Getter in project hibernate-orm by hibernate.

the class MultiPropertyMapper method mapToMapFromEntity.

@Override
public boolean mapToMapFromEntity(SessionImplementor session, Map<String, Object> data, Object newObj, Object oldObj) {
    boolean ret = false;
    for (Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet()) {
        final PropertyData propertyData = entry.getKey();
        final PropertyMapper propertyMapper = entry.getValue();
        // synthetic properties are not part of the entity model; therefore they should be ignored.
        if (propertyData.isSynthetic()) {
            continue;
        }
        Getter getter;
        if (newObj != null) {
            getter = ReflectionTools.getGetter(newObj.getClass(), propertyData, session.getFactory().getServiceRegistry());
        } else if (oldObj != null) {
            getter = ReflectionTools.getGetter(oldObj.getClass(), propertyData, session.getFactory().getServiceRegistry());
        } else {
            return false;
        }
        ret |= propertyMapper.mapToMapFromEntity(session, data, newObj == null ? null : getter.get(newObj), oldObj == null ? null : getter.get(oldObj));
    }
    return ret;
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData) Getter(org.hibernate.property.access.spi.Getter) Map(java.util.Map)

Example 2 with Getter

use of org.hibernate.property.access.spi.Getter in project hibernate-orm by hibernate.

the class MultiPropertyMapper method mapModifiedFlagsToMapFromEntity.

@Override
public void mapModifiedFlagsToMapFromEntity(SessionImplementor session, Map<String, Object> data, Object newObj, Object oldObj) {
    for (Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet()) {
        final PropertyData propertyData = entry.getKey();
        final PropertyMapper propertyMapper = entry.getValue();
        // synthetic properties are not part of the entity model; therefore they should be ignored.
        if (propertyData.isSynthetic()) {
            continue;
        }
        Getter getter;
        if (newObj != null) {
            getter = ReflectionTools.getGetter(newObj.getClass(), propertyData, session.getFactory().getServiceRegistry());
        } else if (oldObj != null) {
            getter = ReflectionTools.getGetter(oldObj.getClass(), propertyData, session.getFactory().getServiceRegistry());
        } else {
            return;
        }
        propertyMapper.mapModifiedFlagsToMapFromEntity(session, data, newObj == null ? null : getter.get(newObj), oldObj == null ? null : getter.get(oldObj));
    }
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData) Getter(org.hibernate.property.access.spi.Getter) Map(java.util.Map)

Example 3 with Getter

use of org.hibernate.property.access.spi.Getter in project hibernate-orm by hibernate.

the class EmbeddedIdMapper method mapToMapFromEntity.

@Override
public void mapToMapFromEntity(Map<String, Object> data, Object obj) {
    if (obj == null) {
        return;
    }
    final Getter getter = ReflectionTools.getGetter(obj.getClass(), idPropertyData, getServiceRegistry());
    mapToMapFromId(data, getter.get(obj));
}
Also used : Getter(org.hibernate.property.access.spi.Getter)

Example 4 with Getter

use of org.hibernate.property.access.spi.Getter in project hibernate-orm by hibernate.

the class EmbeddedIdMapper method mapToEntityFromMap.

@Override
public boolean mapToEntityFromMap(Object obj, Map data) {
    if (data == null || obj == null) {
        return false;
    }
    final Getter getter = ReflectionTools.getGetter(obj.getClass(), idPropertyData, getServiceRegistry());
    final Setter setter = ReflectionTools.getSetter(obj.getClass(), idPropertyData, getServiceRegistry());
    try {
        final Object subObj = ReflectHelper.getDefaultConstructor(getter.getReturnType()).newInstance();
        boolean ret = true;
        for (IdMapper idMapper : ids.values()) {
            ret &= idMapper.mapToEntityFromMap(subObj, data);
        }
        if (ret) {
            setter.set(obj, subObj, null);
        }
        return ret;
    } catch (Exception e) {
        throw new AuditException(e);
    }
}
Also used : Getter(org.hibernate.property.access.spi.Getter) Setter(org.hibernate.property.access.spi.Setter) AuditException(org.hibernate.envers.exception.AuditException) AuditException(org.hibernate.envers.exception.AuditException)

Example 5 with Getter

use of org.hibernate.property.access.spi.Getter 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)

Aggregations

Getter (org.hibernate.property.access.spi.Getter)15 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 Map (java.util.Map)4 Setter (org.hibernate.property.access.spi.Setter)4 AnEntity (org.hibernate.serialization.entity.AnEntity)4 PK (org.hibernate.serialization.entity.PK)4 TestForIssue (org.hibernate.testing.TestForIssue)4 HashMap (java.util.HashMap)2 ClassLoaderServiceImpl (org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl)2 PropertyData (org.hibernate.envers.internal.entities.PropertyData)2 GetterFieldImpl (org.hibernate.property.access.spi.GetterFieldImpl)2 GetterMethodImpl (org.hibernate.property.access.spi.GetterMethodImpl)2 FlushModeType (javax.persistence.FlushModeType)1 LockModeType (javax.persistence.LockModeType)1 TemporalType (javax.persistence.TemporalType)1 MappingException (org.hibernate.MappingException)1