Search in sources :

Example 6 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class PluralAttributeMappingTests method testLists.

@Test
public void testLists(SessionFactoryScope scope) {
    final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor(EntityOfLists.class);
    assertThat(containerEntityDescriptor.getNumberOfAttributeMappings(), is(8));
    final AttributeMapping listOfBasics = containerEntityDescriptor.findAttributeMapping("listOfBasics");
    assertThat(listOfBasics, notNullValue());
    final AttributeMapping listOfEnums = containerEntityDescriptor.findAttributeMapping("listOfEnums");
    assertThat(listOfEnums, notNullValue());
    final AttributeMapping listOfConvertedBasics = containerEntityDescriptor.findAttributeMapping("listOfConvertedEnums");
    assertThat(listOfConvertedBasics, notNullValue());
    final AttributeMapping listOfComponents = containerEntityDescriptor.findAttributeMapping("listOfComponents");
    assertThat(listOfComponents, notNullValue());
    final AttributeMapping listOfOneToMany = containerEntityDescriptor.findAttributeMapping("listOfOneToMany");
    assertThat(listOfOneToMany, notNullValue());
    final AttributeMapping listOfManyToMany = containerEntityDescriptor.findAttributeMapping("listOfManyToMany");
    assertThat(listOfManyToMany, notNullValue());
}
Also used : MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) Test(org.junit.jupiter.api.Test)

Example 7 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class VirtualIdEmbeddable method forEachDisassembledJdbcValue.

@Override
public int forEachDisassembledJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
    final Object[] values = (Object[]) value;
    int span = 0;
    for (int i = 0; i < attributeMappings.size(); i++) {
        final AttributeMapping mapping = attributeMappings.get(i);
        span += mapping.forEachDisassembledJdbcValue(values[i], clause, span + offset, valuesConsumer, session);
    }
    return span;
}
Also used : PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping)

Example 8 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class VirtualIdEmbeddable method forEachJdbcValue.

@Override
public int forEachJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
    int span = 0;
    for (int i = 0; i < attributeMappings.size(); i++) {
        final AttributeMapping attributeMapping = attributeMappings.get(i);
        if (attributeMapping instanceof PluralAttributeMapping) {
            continue;
        }
        final Object o = attributeMapping.getPropertyAccess().getGetter().get(value);
        span += attributeMapping.forEachJdbcValue(o, clause, span + offset, valuesConsumer, session);
    }
    return span;
}
Also used : PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping)

Example 9 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class IdClassEmbeddable method forEachJdbcValue.

@Override
public int forEachJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
    int span = 0;
    for (int i = 0; i < attributeMappings.size(); i++) {
        final AttributeMapping attributeMapping = attributeMappings.get(i);
        if (attributeMapping instanceof PluralAttributeMapping) {
            continue;
        }
        final Object o = attributeMapping.getPropertyAccess().getGetter().get(value);
        span += attributeMapping.forEachJdbcValue(o, clause, span + offset, valuesConsumer, session);
    }
    return span;
}
Also used : PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping)

Example 10 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class EmbeddableMappingTypeImpl method disassemble.

@Override
public Object disassemble(Object value, SharedSessionContractImplementor session) {
    final List<AttributeMapping> attributeMappings = getAttributeMappings();
    final Object[] result = new Object[attributeMappings.size()];
    for (int i = 0; i < attributeMappings.size(); i++) {
        final AttributeMapping attributeMapping = attributeMappings.get(i);
        Object o = attributeMapping.getPropertyAccess().getGetter().get(value);
        result[i] = attributeMapping.disassemble(o, session);
    }
    return result;
}
Also used : PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping)

Aggregations

AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)56 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)38 SingularAttributeMapping (org.hibernate.metamodel.mapping.SingularAttributeMapping)20 EmbeddedAttributeMapping (org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping)19 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)19 EntityPersister (org.hibernate.persister.entity.EntityPersister)17 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)12 DiscriminatedAssociationAttributeMapping (org.hibernate.metamodel.mapping.internal.DiscriminatedAssociationAttributeMapping)12 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)10 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 EmbeddableMappingType (org.hibernate.metamodel.mapping.EmbeddableMappingType)8 ModelPart (org.hibernate.metamodel.mapping.ModelPart)7 Expression (org.hibernate.sql.ast.tree.expression.Expression)7 ForeignKeyDescriptor (org.hibernate.metamodel.mapping.ForeignKeyDescriptor)6 NonAggregatedIdentifierMapping (org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping)6 Fetchable (org.hibernate.sql.results.graph.Fetchable)6 CascadeStyle (org.hibernate.engine.spi.CascadeStyle)5 NavigablePath (org.hibernate.query.spi.NavigablePath)5