Search in sources :

Example 6 with PropertyData

use of org.hibernate.envers.internal.entities.PropertyData in project hibernate-orm by hibernate.

the class MultipleIdMapper method prefixMappedProperties.

@Override
public IdMapper prefixMappedProperties(String prefix) {
    final MultipleIdMapper ret = new MultipleIdMapper(compositeIdClass, getServiceRegistry());
    for (PropertyData propertyData : ids.keySet()) {
        final String propertyName = propertyData.getName();
        ret.ids.put(propertyData, new SingleIdMapper(getServiceRegistry(), new PropertyData(prefix + propertyName, propertyData)));
    }
    return ret;
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData)

Example 7 with PropertyData

use of org.hibernate.envers.internal.entities.PropertyData in project hibernate-orm by hibernate.

the class RevisionInfoConfiguration method searchForRevisionInfoCfgInProperties.

private void searchForRevisionInfoCfgInProperties(XClass clazz, ReflectionManager reflectionManager, MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound, MutableBoolean modifiedEntityNamesFound, String accessType) {
    for (XProperty property : clazz.getDeclaredProperties(accessType)) {
        final RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
        final RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
        final ModifiedEntityNames modifiedEntityNames = property.getAnnotation(ModifiedEntityNames.class);
        if (revisionNumber != null) {
            if (revisionNumberFound.isSet()) {
                throw new MappingException("Only one property may be annotated with @RevisionNumber!");
            }
            final XClass revisionNumberClass = property.getType();
            if (reflectionManager.equals(revisionNumberClass, Integer.class) || reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
                revisionInfoIdData = new PropertyData(property.getName(), property.getName(), accessType, null);
                revisionNumberFound.set();
            } else if (reflectionManager.equals(revisionNumberClass, Long.class) || reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
                revisionInfoIdData = new PropertyData(property.getName(), property.getName(), accessType, null);
                revisionNumberFound.set();
                // The default is integer
                revisionPropType = "long";
            } else {
                throw new MappingException("The field annotated with @RevisionNumber must be of type " + "int, Integer, long or Long");
            }
            // Getting the @Column definition of the revision number property, to later use that info to
            // generate the same mapping for the relation from an audit table's revision number to the
            // revision entity revision number.
            final Column revisionPropColumn = property.getAnnotation(Column.class);
            if (revisionPropColumn != null) {
                revisionPropSqlType = revisionPropColumn.columnDefinition();
            }
        }
        if (revisionTimestamp != null) {
            if (revisionTimestampFound.isSet()) {
                throw new MappingException("Only one property may be annotated with @RevisionTimestamp!");
            }
            final XClass revisionTimestampClass = property.getType();
            if (reflectionManager.equals(revisionTimestampClass, Long.class) || reflectionManager.equals(revisionTimestampClass, Long.TYPE) || reflectionManager.equals(revisionTimestampClass, Date.class) || reflectionManager.equals(revisionTimestampClass, java.sql.Date.class)) {
                revisionInfoTimestampData = new PropertyData(property.getName(), property.getName(), accessType, null);
                revisionTimestampFound.set();
            } else {
                throw new MappingException("The field annotated with @RevisionTimestamp must be of type " + "long, Long, java.util.Date or java.sql.Date");
            }
        }
        if (modifiedEntityNames != null) {
            if (modifiedEntityNamesFound.isSet()) {
                throw new MappingException("Only one property may be annotated with @ModifiedEntityNames!");
            }
            final XClass modifiedEntityNamesClass = property.getType();
            if (reflectionManager.equals(modifiedEntityNamesClass, Set.class) && reflectionManager.equals(property.getElementClass(), String.class)) {
                modifiedEntityNamesData = new PropertyData(property.getName(), property.getName(), accessType, null);
                modifiedEntityNamesFound.set();
            } else {
                throw new MappingException("The field annotated with @ModifiedEntityNames must be of Set<String> type.");
            }
        }
    }
}
Also used : XProperty(org.hibernate.annotations.common.reflection.XProperty) ModifiedEntityNames(org.hibernate.envers.ModifiedEntityNames) PropertyData(org.hibernate.envers.internal.entities.PropertyData) Set(java.util.Set) RevisionTimestamp(org.hibernate.envers.RevisionTimestamp) RevisionNumber(org.hibernate.envers.RevisionNumber) XClass(org.hibernate.annotations.common.reflection.XClass) Date(java.util.Date) MappingException(org.hibernate.MappingException) Column(javax.persistence.Column)

Example 8 with PropertyData

use of org.hibernate.envers.internal.entities.PropertyData in project hibernate-orm by hibernate.

the class MultiDynamicComponentMapper 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();
        if (newObj == null && oldObj == null) {
            return;
        }
        Object newValue = newObj == null ? null : getValue(newObj, propertyData);
        Object oldValue = oldObj == null ? null : getValue(oldObj, propertyData);
        propertyMapper.mapModifiedFlagsToMapFromEntity(session, data, newValue, oldValue);
    }
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData) Map(java.util.Map)

Example 9 with PropertyData

use of org.hibernate.envers.internal.entities.PropertyData in project hibernate-orm by hibernate.

the class MultiDynamicComponentMapper 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();
        if (newObj == null && oldObj == null) {
            return false;
        }
        Object newValue = newObj == null ? null : getValue(newObj, propertyData);
        Object oldValue = oldObj == null ? null : getValue(oldObj, propertyData);
        ret |= propertyMapper.mapToMapFromEntity(session, data, newValue, oldValue);
    }
    return ret;
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData) Map(java.util.Map)

Example 10 with PropertyData

use of org.hibernate.envers.internal.entities.PropertyData in project hibernate-orm by hibernate.

the class MiddleEmbeddableComponentMapper method addMiddleEqualToQuery.

protected void addMiddleEqualToQuery(CompositeMapperBuilder compositeMapper, Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) {
    for (final Map.Entry<PropertyData, PropertyMapper> entry : compositeMapper.getProperties().entrySet()) {
        final String propertyName = entry.getKey().getName();
        final PropertyMapper nestedMapper = entry.getValue();
        if (nestedMapper instanceof CompositeMapperBuilder) {
            addMiddleEqualToQuery((CompositeMapperBuilder) nestedMapper, parameters, idPrefix1, prefix1, idPrefix2, prefix2);
        } else if (nestedMapper instanceof ToOneIdMapper) {
            ((ToOneIdMapper) nestedMapper).addMiddleEqualToQuery(parameters, idPrefix1, prefix1, idPrefix2, prefix2);
        } else {
            parameters.addWhereOrNullRestriction(prefix1 + '.' + propertyName, false, "=", prefix2 + '.' + propertyName, false);
        }
    }
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData) CompositeMapperBuilder(org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder) ToOneIdMapper(org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper) PropertyMapper(org.hibernate.envers.internal.entities.mapper.PropertyMapper) MultiPropertyMapper(org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper) Map(java.util.Map)

Aggregations

PropertyData (org.hibernate.envers.internal.entities.PropertyData)16 Map (java.util.Map)6 ToOneIdMapper (org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper)5 IdMappingData (org.hibernate.envers.internal.entities.IdMappingData)4 IdMapper (org.hibernate.envers.internal.entities.mapper.id.IdMapper)4 Element (org.dom4j.Element)3 OneToOne (org.hibernate.mapping.OneToOne)3 MappingException (org.hibernate.MappingException)2 MultiPropertyMapper (org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper)2 PropertyMapper (org.hibernate.envers.internal.entities.mapper.PropertyMapper)2 ToOne (org.hibernate.mapping.ToOne)2 Getter (org.hibernate.property.access.spi.Getter)2 BasicType (org.hibernate.type.BasicType)2 Type (org.hibernate.type.Type)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Column (javax.persistence.Column)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 XProperty (org.hibernate.annotations.common.reflection.XProperty)1