Search in sources :

Example 26 with SimpleValue

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

the class ModelBinder method bindEntityVersion.

private void bindEntityVersion(MappingDocument sourceDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
    final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource();
    final SimpleValue versionValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
    versionValue.makeVersion();
    bindSimpleValueType(sourceDocument, versionAttributeSource.getTypeInformation(), versionValue);
    relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, versionAttributeSource.getRelationalValueSources(), versionValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {

        @Override
        public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
            return implicitNamingStrategy.determineBasicColumnName(versionAttributeSource);
        }
    });
    Property prop = new Property();
    prop.setValue(versionValue);
    bindProperty(sourceDocument, versionAttributeSource, prop);
    // but just to make sure...
    if (prop.getValueGenerationStrategy() != null) {
        if (prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT) {
            throw new MappingException("'generated' attribute cannot be 'insert' for version/timestamp property", sourceDocument.getOrigin());
        }
    }
    if (versionAttributeSource.getUnsavedValue() != null) {
        versionValue.setNullValue(versionAttributeSource.getUnsavedValue());
    } else {
        versionValue.setNullValue("undefined");
    }
    rootEntityDescriptor.setVersion(prop);
    rootEntityDescriptor.setDeclaredVersion(prop);
    rootEntityDescriptor.addProperty(prop);
}
Also used : VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) Identifier(org.hibernate.boot.model.naming.Identifier) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty) SimpleValue(org.hibernate.mapping.SimpleValue) MappingException(org.hibernate.boot.MappingException)

Example 27 with SimpleValue

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

the class ModelBinder method bindJoinedSubclassEntity.

private void bindJoinedSubclassEntity(JoinedSubclassEntitySourceImpl entitySource, JoinedSubclass entityDescriptor) {
    MappingDocument mappingDocument = entitySource.sourceMappingDocument();
    bindBasicEntityValues(mappingDocument, entitySource, entityDescriptor);
    final Table primaryTable = bindEntityTableSpecification(mappingDocument, entitySource.getPrimaryTable(), null, entitySource, entityDescriptor);
    entityDescriptor.setTable(primaryTable);
    if (log.isDebugEnabled()) {
        log.debugf("Mapping joined-subclass: %s -> %s", entityDescriptor.getEntityName(), primaryTable.getName());
    }
    // KEY
    final SimpleValue keyBinding = new DependantValue(mappingDocument.getMetadataCollector(), primaryTable, entityDescriptor.getIdentifier());
    if (mappingDocument.getBuildingOptions().useNationalizedCharacterData()) {
        keyBinding.makeNationalized();
    }
    entityDescriptor.setKey(keyBinding);
    keyBinding.setCascadeDeleteEnabled(entitySource.isCascadeDeleteEnabled());
    relationalObjectBinder.bindColumns(mappingDocument, entitySource.getPrimaryKeyColumnSources(), keyBinding, false, new RelationalObjectBinder.ColumnNamingDelegate() {

        int count = 0;

        @Override
        public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
            final Column column = primaryTable.getPrimaryKey().getColumn(count++);
            return database.toIdentifier(column.getQuotedName());
        }
    });
    keyBinding.setForeignKeyName(entitySource.getExplicitForeignKeyName());
    // model.getKey().setType( new Type( model.getIdentifier() ) );
    entityDescriptor.createPrimaryKey();
    entityDescriptor.createForeignKey();
    // todo : tooling hints
    bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
    bindJoinedSubclassEntities(entitySource, entityDescriptor);
}
Also used : Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) Identifier(org.hibernate.boot.model.naming.Identifier) DependantValue(org.hibernate.mapping.DependantValue) Column(org.hibernate.mapping.Column) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 28 with SimpleValue

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

the class CollectionCompositeElementExplicitConversionTest method checkComposite.

private void checkComposite(Component composite) throws Exception {
    // check `eyeColor`
    final Property eyeColorProperty = composite.getProperty("eyeColor");
    final SimpleValue eyeColorValueMapping = (SimpleValue) eyeColorProperty.getValue();
    assertThat(simpleValueAttributeConverterDescriptorField.get(eyeColorValueMapping), CoreMatchers.notNullValue());
    // check `hairColor`
    final Property hairColorProperty = composite.getProperty("hairColor");
    final SimpleValue hairColorValueMapping = (SimpleValue) hairColorProperty.getValue();
    assertThat(simpleValueAttributeConverterDescriptorField.get(hairColorValueMapping), CoreMatchers.notNullValue());
}
Also used : Property(org.hibernate.mapping.Property) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 29 with SimpleValue

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

the class AttributeConverterTest method testBasicOrmXmlConverterApplication.

@Test
@TestForIssue(jiraKey = "HHH-8462")
public void testBasicOrmXmlConverterApplication() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).addURL(ConfigHelper.findAsResource("org/hibernate/test/converter/orm.xml")).getMetadataBuilder().build();
        PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
        Property nameProp = tester.getProperty("name");
        SimpleValue nameValue = (SimpleValue) nameProp.getValue();
        Type type = nameValue.getType();
        assertNotNull(type);
        if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
            fail("AttributeConverter not applied");
        }
        AttributeConverterTypeAdapter basicType = assertTyping(AttributeConverterTypeAdapter.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 30 with SimpleValue

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

the class AttributeConverterTest method testBasicConverterDisableApplication.

@Test
public void testBasicConverterDisableApplication() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester2.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
        PersistentClass tester = metadata.getEntityBinding(Tester2.class.getName());
        Property nameProp = tester.getProperty("name");
        SimpleValue nameValue = (SimpleValue) nameProp.getValue();
        Type type = nameValue.getType();
        assertNotNull(type);
        if (AttributeConverterTypeAdapter.class.isInstance(type)) {
            fail("AttributeConverter applied (should not have been)");
        }
        AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hibernate.mapping.Property) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

SimpleValue (org.hibernate.mapping.SimpleValue)42 Property (org.hibernate.mapping.Property)23 PersistentClass (org.hibernate.mapping.PersistentClass)18 Column (org.hibernate.mapping.Column)13 Test (org.junit.Test)12 AnnotationException (org.hibernate.AnnotationException)11 MetadataSources (org.hibernate.boot.MetadataSources)11 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)10 Identifier (org.hibernate.boot.model.naming.Identifier)9 Component (org.hibernate.mapping.Component)8 DependantValue (org.hibernate.mapping.DependantValue)8 BasicType (org.hibernate.type.BasicType)8 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)7 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)7 Table (org.hibernate.mapping.Table)7 RootClass (org.hibernate.mapping.RootClass)6 AssertionFailure (org.hibernate.AssertionFailure)5 Collection (org.hibernate.mapping.Collection)5 ManyToOne (org.hibernate.mapping.ManyToOne)5