Search in sources :

Example 1 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class BaseNonConfigCoreFunctionalTestCase method applyCacheSettings.

protected final void applyCacheSettings(Metadata metadata) {
    if (!overrideCacheStrategy()) {
        return;
    }
    if (getCacheConcurrencyStrategy() == null) {
        return;
    }
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (entityBinding.isInherited()) {
            continue;
        }
        boolean hasLob = false;
        final Iterator props = entityBinding.getPropertyClosureIterator();
        while (props.hasNext()) {
            final Property prop = (Property) props.next();
            if (prop.getValue().isSimpleValue()) {
                if (isLob(((SimpleValue) prop.getValue()).getTypeName())) {
                    hasLob = true;
                    break;
                }
            }
        }
        if (!hasLob) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(getCacheConcurrencyStrategy());
        }
    }
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        boolean isLob = false;
        if (collectionBinding.getElement().isSimpleValue()) {
            isLob = isLob(((SimpleValue) collectionBinding.getElement()).getTypeName());
        }
        if (!isLob) {
            collectionBinding.setCacheConcurrencyStrategy(getCacheConcurrencyStrategy());
        }
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) Iterator(java.util.Iterator) Collection(org.hibernate.mapping.Collection) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 2 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class AbstractFunctionalTest method afterMetadataBuilt.

@Override
protected void afterMetadataBuilt(Metadata metadata) {
    if (addVersions) {
        for (PersistentClass clazz : metadata.getEntityBindings()) {
            if (clazz.getVersion() != null) {
                continue;
            }
            try {
                clazz.getMappedClass().getMethod("getVersion");
                clazz.getMappedClass().getMethod("setVersion", long.class);
            } catch (NoSuchMethodException e) {
                continue;
            }
            RootClass rootClazz = clazz.getRootClass();
            Property versionProperty = new Property();
            versionProperty.setName("version");
            SimpleValue value = new SimpleValue((MetadataImplementor) metadata, rootClazz.getTable());
            value.setTypeName("long");
            Column column = new Column();
            column.setValue(value);
            column.setName("version");
            value.addColumn(column);
            rootClazz.getTable().addColumn(column);
            versionProperty.setValue(value);
            rootClazz.setVersion(versionProperty);
            rootClazz.addProperty(versionProperty);
        }
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) Column(org.hibernate.mapping.Column) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 3 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class ComponentMetadataGenerator method addComponent.

@SuppressWarnings({ "unchecked" })
public void addComponent(Element parent, PropertyAuditingData propertyAuditingData, Value value, CompositeMapperBuilder mapper, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) {
    final Component propComponent = (Component) value;
    final Class componentClass;
    if (propComponent.isDynamic()) {
        componentClass = ReflectionTools.loadClass(Map.class.getCanonicalName(), mainGenerator.getClassLoaderService());
    } else {
        componentClass = ReflectionTools.loadClass(propComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
    }
    final CompositeMapperBuilder componentMapper = mapper.addComponent(propertyAuditingData.getPropertyData(), componentClass);
    // The property auditing data must be for a component.
    final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
    // Adding all properties of the component
    final Iterator<Property> properties = (Iterator<Property>) propComponent.getPropertyIterator();
    while (properties.hasNext()) {
        final Property property = properties.next();
        final PropertyAuditingData componentPropertyAuditingData = componentAuditingData.getPropertyAuditingData(property.getName());
        // Checking if that property is audited
        if (componentPropertyAuditingData != null) {
            mainGenerator.addValue(parent, property.getValue(), componentMapper, entityName, xmlMappingData, componentPropertyAuditingData, property.isInsertable(), firstPass, false);
        }
    }
}
Also used : CompositeMapperBuilder(org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder) ComponentAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData) Iterator(java.util.Iterator) PropertyAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Example 4 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class IdMetadataGenerator method addId.

@SuppressWarnings({ "unchecked" })
IdMappingData addId(PersistentClass pc, boolean audited) {
    // Xml mapping which will be used for relations
    final Element relIdMapping = new DefaultElement("properties");
    // Xml mapping which will be used for the primary key of the versions table
    final Element origIdMapping = new DefaultElement("composite-id");
    final Property idProp = pc.getIdentifierProperty();
    final Component idMapper = pc.getIdentifierMapper();
    // Checking if the id mapping is supported
    if (idMapper == null && idProp == null) {
        return null;
    }
    SimpleIdMapperBuilder mapper;
    if (idMapper != null) {
        // Multiple id
        final Class componentClass = ReflectionTools.loadClass(((Component) pc.getIdentifier()).getComponentClassName(), mainGenerator.getClassLoaderService());
        mapper = new MultipleIdMapper(componentClass, pc.getServiceRegistry());
        if (!addIdProperties(relIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), mapper, false, audited)) {
            return null;
        }
        // null mapper - the mapping where already added the first time, now we only want to generate the xml
        if (!addIdProperties(origIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), null, true, audited)) {
            return null;
        }
    } else if (idProp.isComposite()) {
        // Embedded id
        final Component idComponent = (Component) idProp.getValue();
        final Class embeddableClass = ReflectionTools.loadClass(idComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
        mapper = new EmbeddedIdMapper(getIdPropertyData(idProp), embeddableClass, pc.getServiceRegistry());
        if (!addIdProperties(relIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), mapper, false, audited)) {
            return null;
        }
        // null mapper - the mapping where already added the first time, now we only want to generate the xml
        if (!addIdProperties(origIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), null, true, audited)) {
            return null;
        }
    } else {
        // Single id
        mapper = new SingleIdMapper(pc.getServiceRegistry());
        // Last but one parameter: ids are always insertable
        mainGenerator.getBasicMetadataGenerator().addBasic(relIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), mapper, true, false);
        // null mapper - the mapping where already added the first time, now we only want to generate the xml
        mainGenerator.getBasicMetadataGenerator().addBasic(origIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), null, true, true);
    }
    origIdMapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
    // Adding a relation to the revision entity (effectively: the "revision number" property)
    mainGenerator.addRevisionInfoRelation(origIdMapping);
    return new IdMappingData(mapper, origIdMapping, relIdMapping);
}
Also used : SingleIdMapper(org.hibernate.envers.internal.entities.mapper.id.SingleIdMapper) DefaultElement(org.dom4j.tree.DefaultElement) SimpleIdMapperBuilder(org.hibernate.envers.internal.entities.mapper.id.SimpleIdMapperBuilder) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Iterator(java.util.Iterator) PersistentClass(org.hibernate.mapping.PersistentClass) Component(org.hibernate.mapping.Component) EmbeddedIdMapper(org.hibernate.envers.internal.entities.mapper.id.EmbeddedIdMapper) Property(org.hibernate.mapping.Property) MultipleIdMapper(org.hibernate.envers.internal.entities.mapper.id.MultipleIdMapper) IdMappingData(org.hibernate.envers.internal.entities.IdMappingData)

Example 5 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class AuditedPropertiesReader method createPropertiesGroupMapping.

@SuppressWarnings("unchecked")
private void createPropertiesGroupMapping(Property property) {
    final Component component = (Component) property.getValue();
    final Iterator<Property> componentProperties = component.getPropertyIterator();
    while (componentProperties.hasNext()) {
        final Property componentProperty = componentProperties.next();
        propertiesGroupMapping.put(componentProperty.getName(), property.getName());
    }
}
Also used : Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) XProperty(org.hibernate.annotations.common.reflection.XProperty)

Aggregations

Property (org.hibernate.mapping.Property)94 PersistentClass (org.hibernate.mapping.PersistentClass)53 Component (org.hibernate.mapping.Component)30 Test (org.junit.Test)29 SimpleValue (org.hibernate.mapping.SimpleValue)24 Iterator (java.util.Iterator)23 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)18 MetadataSources (org.hibernate.boot.MetadataSources)17 Column (org.hibernate.mapping.Column)17 AnnotationException (org.hibernate.AnnotationException)14 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)14 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)14 XProperty (org.hibernate.annotations.common.reflection.XProperty)12 Metadata (org.hibernate.boot.Metadata)11 Collection (org.hibernate.mapping.Collection)11 HashMap (java.util.HashMap)10 AssertionFailure (org.hibernate.AssertionFailure)10 MappingException (org.hibernate.MappingException)9 TestForIssue (org.hibernate.testing.TestForIssue)9 Map (java.util.Map)7