Search in sources :

Example 46 with Property

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

the class AuditMetadataGenerator method addProperties.

private void addProperties(Element parent, Iterator<Property> properties, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) {
    while (properties.hasNext()) {
        final Property property = properties.next();
        final String propertyName = property.getName();
        final PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData(propertyName);
        if (propertyAuditingData != null) {
            // and if so, this eliminates the mapping property as it isn't needed.
            if (property instanceof SyntheticProperty) {
                if (property.getValue().isAlternateUniqueKey()) {
                    continue;
                }
            }
            addValue(parent, property.getValue(), currentMapper, entityName, xmlMappingData, propertyAuditingData, isPropertyInsertable(property), firstPass, true);
        }
    }
}
Also used : SyntheticProperty(org.hibernate.mapping.SyntheticProperty) PropertyAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Example 47 with Property

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

the class TestTools method extractModProperties.

public static Set<String> extractModProperties(PersistentClass persistentClass, String suffix) {
    final Set<String> result = new HashSet<String>();
    final Iterator iterator = persistentClass.getPropertyIterator();
    while (iterator.hasNext()) {
        final Property property = (Property) iterator.next();
        final String propertyName = property.getName();
        if (propertyName.endsWith(suffix)) {
            result.add(propertyName);
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) Property(org.hibernate.mapping.Property) HashSet(java.util.HashSet)

Example 48 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 49 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 50 with Property

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

the class Java8DateTimeTests method basicTests.

@Test
public void basicTests() {
    final PersistentClass entityBinding = metadata().getEntityBinding(TheEntity.class.getName());
    final Iterator propertyBindingIterator = entityBinding.getPropertyClosureIterator();
    while (propertyBindingIterator.hasNext()) {
        final Property propertyBinding = (Property) propertyBindingIterator.next();
        assertFalse("Found property bound as Serializable : " + propertyBinding.getName(), propertyBinding.getType() instanceof SerializableType);
    }
    TheEntity theEntity = new TheEntity(1);
    Session s = openSession();
    s.beginTransaction();
    s.save(theEntity);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    theEntity = (TheEntity) s.get(TheEntity.class, 1);
    dump(entityBinding, theEntity);
    assertNotNull(theEntity);
    s.delete(theEntity);
    s.getTransaction().commit();
    s.close();
}
Also used : SerializableType(org.hibernate.type.SerializableType) Iterator(java.util.Iterator) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Session(org.hibernate.Session) Test(org.junit.Test)

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