Search in sources :

Example 51 with Property

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

the class CollectionMetadataGenerator method searchMappedByKey.

@SuppressWarnings({ "unchecked" })
private String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) {
    final Iterator<Value> assocIdClassProps = referencedClass.getKeyClosureIterator();
    while (assocIdClassProps.hasNext()) {
        final Value value = assocIdClassProps.next();
        // make sure its a 'Component' because IdClass is registered as this type.
        if (value instanceof Component) {
            final Component component = (Component) value;
            final Iterator<Property> componentPropertyIterator = component.getPropertyIterator();
            while (componentPropertyIterator.hasNext()) {
                final Property property = componentPropertyIterator.next();
                final Iterator<Selectable> propertySelectables = property.getValue().getColumnIterator();
                final Iterator<Selectable> collectionSelectables = collectionValue.getKey().getColumnIterator();
                if (Tools.iteratorsContentEqual(propertySelectables, collectionSelectables)) {
                    return property.getName();
                }
            }
        }
    }
    return null;
}
Also used : Selectable(org.hibernate.mapping.Selectable) Value(org.hibernate.mapping.Value) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Example 52 with Property

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

the class EntityMetamodel method interpretPartialCompositeValueGeneration.

private static void interpretPartialCompositeValueGeneration(SessionFactoryImplementor sessionFactory, Component composite, CompositeGenerationStrategyPairBuilder builder) {
    Iterator subProperties = composite.getPropertyIterator();
    while (subProperties.hasNext()) {
        final Property subProperty = (Property) subProperties.next();
        builder.addPair(buildGenerationStrategyPair(sessionFactory, subProperty));
    }
}
Also used : Iterator(java.util.Iterator) Property(org.hibernate.mapping.Property) IdentifierProperty(org.hibernate.tuple.IdentifierProperty)

Example 53 with Property

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

the class EntityMetamodel method mapPropertyToIndex.

private void mapPropertyToIndex(Property prop, int i) {
    propertyIndexes.put(prop.getName(), i);
    if (prop.getValue() instanceof Component) {
        Iterator iter = ((Component) prop.getValue()).getPropertyIterator();
        while (iter.hasNext()) {
            Property subprop = (Property) iter.next();
            propertyIndexes.put(prop.getName() + '.' + subprop.getName(), i);
        }
    }
}
Also used : Iterator(java.util.Iterator) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) IdentifierProperty(org.hibernate.tuple.IdentifierProperty)

Example 54 with Property

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

the class AbstractJPAIndexTest method testCollectionTableIndex.

@Test
public void testCollectionTableIndex() {
    PersistentClass entity = metadata().getEntityBinding(Car.class.getName());
    Property property = entity.getProperty("otherDealers");
    Set set = (Set) property.getValue();
    Table collectionTable = set.getCollectionTable();
    Iterator<Index> itr = collectionTable.getIndexIterator();
    assertTrue(itr.hasNext());
    Index index = itr.next();
    assertFalse(itr.hasNext());
    assertTrue("index name is not generated", StringHelper.isNotEmpty(index.getName()));
    assertEquals(1, index.getColumnSpan());
    Iterator<Column> columnIterator = index.getColumnIterator();
    Column column = columnIterator.next();
    assertEquals("name", column.getName());
    assertSame(collectionTable, index.getTable());
}
Also used : Set(org.hibernate.mapping.Set) Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) Index(org.hibernate.mapping.Index) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 55 with Property

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

the class AbstractJPAIndexTest method testJoinTableIndex.

@Test
public void testJoinTableIndex() {
    PersistentClass entity = metadata().getEntityBinding(Importer.class.getName());
    Property property = entity.getProperty("cars");
    Bag set = (Bag) property.getValue();
    Table collectionTable = set.getCollectionTable();
    Iterator<Index> itr = collectionTable.getIndexIterator();
    assertTrue(itr.hasNext());
    Index index = itr.next();
    assertFalse(itr.hasNext());
    assertTrue("index name is not generated", StringHelper.isNotEmpty(index.getName()));
    assertEquals(1, index.getColumnSpan());
    Iterator<Column> columnIterator = index.getColumnIterator();
    Column column = columnIterator.next();
    assertEquals("importers_id", column.getName());
    assertSame(collectionTable, index.getTable());
}
Also used : Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) Bag(org.hibernate.mapping.Bag) Index(org.hibernate.mapping.Index) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) 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