Search in sources :

Example 26 with BasicAttributeMapping

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

the class BitSetConverterImmutableTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(Product.class);
    final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("bitSet");
    assertThat(attributeMapping.getJavaType().getJavaTypeClass(), equalTo(BitSet.class));
    assertThat(attributeMapping.getValueConverter(), instanceOf(JpaAttributeConverter.class));
    final JpaAttributeConverter converter = (JpaAttributeConverter) attributeMapping.getValueConverter();
    assertThat(converter.getConverterBean().getBeanClass(), equalTo(BitSetConverter.class));
    Assertions.assertThat(attributeMapping.getExposedMutabilityPlan()).isNotInstanceOf(BitSetMutabilityPlan.class);
    Assertions.assertThat(attributeMapping.getExposedMutabilityPlan()).isInstanceOf(ImmutableMutabilityPlan.class);
    Assertions.assertThat(attributeMapping.getExposedMutabilityPlan().isMutable()).isFalse();
    final BitSet sample = new BitSet();
    Assertions.assertThat(((MutabilityPlan) attributeMapping.getExposedMutabilityPlan()).deepCopy(sample)).isSameAs(sample);
    assertThat(attributeMapping.getJdbcMapping().getJdbcType().getJdbcTypeCode(), isOneOf(Types.VARCHAR, Types.NVARCHAR));
    assertThat(attributeMapping.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass(), equalTo(String.class));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JpaAttributeConverter(org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) BitSet(java.util.BitSet) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) MutabilityPlan(org.hibernate.type.descriptor.java.MutabilityPlan) ImmutableMutabilityPlan(org.hibernate.type.descriptor.java.ImmutableMutabilityPlan) Test(org.junit.jupiter.api.Test)

Example 27 with BasicAttributeMapping

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

the class BigIntegerMappingTests method testMappings.

@Test
public void testMappings(SessionFactoryScope scope) {
    // first, verify the type selections...
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityOfBigIntegers.class);
    final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
        assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(BigInteger.class));
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(BigInteger.class));
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(Types.NUMERIC)));
    }
    // and try to use the mapping
    scope.inTransaction((session) -> session.persist(new EntityOfBigIntegers(1, BigInteger.TEN)));
    scope.inTransaction((session) -> session.get(EntityOfBigIntegers.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 28 with BasicAttributeMapping

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

the class ByteArrayMappingTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityOfByteArrays.class);
    {
        final BasicAttributeMapping primitive = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitive");
        final JdbcMapping jdbcMapping = primitive.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(byte[].class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), equalTo(Types.VARBINARY));
    }
    {
        final BasicAttributeMapping primitive = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
        final JdbcMapping jdbcMapping = primitive.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Byte[].class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), equalTo(Types.VARBINARY));
    }
    {
        final BasicAttributeMapping primitive = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitiveLob");
        final JdbcMapping jdbcMapping = primitive.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(byte[].class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), equalTo(Types.BLOB));
    }
    {
        final BasicAttributeMapping primitive = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapperLob");
        final JdbcMapping jdbcMapping = primitive.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Byte[].class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), equalTo(Types.BLOB));
    }
    scope.inTransaction((session) -> {
        session.persist(new EntityOfByteArrays(1, "abc".getBytes(), new Byte[] { (byte) 1 }));
    });
    scope.inTransaction((session) -> session.get(EntityOfByteArrays.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Example 29 with BasicAttributeMapping

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

the class CharacterArrayNationalizedMappingTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityWithCharArrays.class);
    final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
    final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
    final NationalizationSupport nationalizationSupport = dialect.getNationalizationSupport();
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitiveNVarchar");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode())));
    }
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapperNVarchar");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode())));
    }
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitiveNClob");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode())));
    }
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapperNClob");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode())));
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) Dialect(org.hibernate.dialect.Dialect) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) NationalizationSupport(org.hibernate.dialect.NationalizationSupport) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 30 with BasicAttributeMapping

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

the class BigDecimalMappingTests method testMappings.

@Test
public void testMappings(SessionFactoryScope scope) {
    // first, verify the type selections...
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityOfBigDecimals.class);
    final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
        assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(BigDecimal.class));
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(BigDecimal.class));
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(Types.NUMERIC)));
    }
    // and try to use the mapping
    scope.inTransaction((session) -> session.persist(new EntityOfBigDecimals(1, BigDecimal.TEN)));
    scope.inTransaction((session) -> session.get(EntityOfBigDecimals.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

BasicAttributeMapping (org.hibernate.metamodel.mapping.internal.BasicAttributeMapping)41 Test (org.junit.jupiter.api.Test)40 EntityPersister (org.hibernate.persister.entity.EntityPersister)39 MappingMetamodelImplementor (org.hibernate.metamodel.spi.MappingMetamodelImplementor)36 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)29 JdbcTypeRegistry (org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry)17 BitSet (java.util.BitSet)7 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 JpaAttributeConverter (org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter)4 ZoneOffset (java.time.ZoneOffset)2 Dialect (org.hibernate.dialect.Dialect)2 NationalizationSupport (org.hibernate.dialect.NationalizationSupport)2 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)2 ModelPart (org.hibernate.metamodel.mapping.ModelPart)2 BasicValueConverter (org.hibernate.metamodel.model.convert.spi.BasicValueConverter)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1