Search in sources :

Example 1 with OneToOne

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

the class AuditMetadataGenerator method addValueInSecondPass.

private void addValueInSecondPass(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, boolean insertable, boolean processModifiedFlag) {
    final Type type = value.getType();
    if (type instanceof ComponentType) {
        componentMetadataGenerator.addComponent(parent, propertyAuditingData, value, currentMapper, entityName, xmlMappingData, false);
        // mod flag field has been already generated in first pass
        return;
    } else if (type instanceof ManyToOneType) {
        toOneRelationMetadataGenerator.addToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable);
    } else if (type instanceof OneToOneType) {
        final OneToOne oneToOne = (OneToOne) value;
        if (oneToOne.getReferencedPropertyName() != null) {
            toOneRelationMetadataGenerator.addOneToOneNotOwning(propertyAuditingData, value, currentMapper, entityName);
        } else {
            // @OneToOne relation marked with @PrimaryKeyJoinColumn
            toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn(propertyAuditingData, value, currentMapper, entityName, insertable);
        }
    } else if (type instanceof CollectionType) {
        final CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this, (Collection) value, currentMapper, entityName, xmlMappingData, propertyAuditingData);
        collectionMetadataGenerator.addCollection();
    } else {
        return;
    }
    addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
}
Also used : CollectionType(org.hibernate.type.CollectionType) ManyToOneType(org.hibernate.type.ManyToOneType) ComponentType(org.hibernate.type.ComponentType) OneToOneType(org.hibernate.type.OneToOneType) TimestampType(org.hibernate.type.TimestampType) Type(org.hibernate.type.Type) ComponentType(org.hibernate.type.ComponentType) OneToOne(org.hibernate.mapping.OneToOne) ManyToOneType(org.hibernate.type.ManyToOneType) CollectionType(org.hibernate.type.CollectionType) Collection(org.hibernate.mapping.Collection) OneToOneType(org.hibernate.type.OneToOneType)

Example 2 with OneToOne

use of org.hibernate.mapping.OneToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testIsOneToOne.

@Test
public void testIsOneToOne() {
    valueTarget = new SimpleValue(null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertFalse(valueFacade.isOneToOne());
    OneToOne oneToOne = new OneToOne(null, null, new RootClass());
    valueFacade = FACADE_FACTORY.createValue(oneToOne);
    Assert.assertTrue(valueFacade.isOneToOne());
}
Also used : RootClass(org.hibernate.mapping.RootClass) OneToOne(org.hibernate.mapping.OneToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 3 with OneToOne

use of org.hibernate.mapping.OneToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testIsToOne.

@Test
public void testIsToOne() {
    valueTarget = new SimpleValue();
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertFalse(valueFacade.isToOne());
    ToOne toOne = new OneToOne(null, new RootClass());
    valueFacade = FACADE_FACTORY.createValue(toOne);
    Assert.assertTrue(valueFacade.isToOne());
}
Also used : RootClass(org.hibernate.mapping.RootClass) OneToOne(org.hibernate.mapping.OneToOne) ToOne(org.hibernate.mapping.ToOne) ManyToOne(org.hibernate.mapping.ManyToOne) OneToOne(org.hibernate.mapping.OneToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 4 with OneToOne

use of org.hibernate.mapping.OneToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testIsToOne.

@Test
public void testIsToOne() {
    valueTarget = new SimpleValue(null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertFalse(valueFacade.isToOne());
    ToOne toOne = new OneToOne(null, null, new RootClass());
    valueFacade = FACADE_FACTORY.createValue(toOne);
    Assert.assertTrue(valueFacade.isToOne());
}
Also used : RootClass(org.hibernate.mapping.RootClass) OneToOne(org.hibernate.mapping.OneToOne) ToOne(org.hibernate.mapping.ToOne) ManyToOne(org.hibernate.mapping.ManyToOne) OneToOne(org.hibernate.mapping.OneToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 5 with OneToOne

use of org.hibernate.mapping.OneToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testGetEntityName.

@Test
public void testGetEntityName() {
    SimpleValue simpleValueTarget = new SimpleValue(null);
    valueFacade = FACADE_FACTORY.createValue(simpleValueTarget);
    Assert.assertNull(valueFacade.getEntityName());
    RootClass pc = new RootClass();
    pc.setEntityName("foobar");
    OneToOne oneToOneTarget = new OneToOne(null, null, pc);
    valueFacade = FACADE_FACTORY.createValue(oneToOneTarget);
    Assert.assertEquals("foobar", valueFacade.getEntityName());
}
Also used : RootClass(org.hibernate.mapping.RootClass) OneToOne(org.hibernate.mapping.OneToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

OneToOne (org.hibernate.mapping.OneToOne)35 Test (org.junit.Test)29 SimpleValue (org.hibernate.mapping.SimpleValue)27 RootClass (org.hibernate.mapping.RootClass)25 ManyToOne (org.hibernate.mapping.ManyToOne)13 ToOne (org.hibernate.mapping.ToOne)8 Component (org.hibernate.mapping.Component)4 AssertionFailure (org.hibernate.AssertionFailure)3 Any (org.hibernate.mapping.Any)3 Property (org.hibernate.mapping.Property)3 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)3 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)3 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)3 AnnotationException (org.hibernate.AnnotationException)2 MappingException (org.hibernate.MappingException)2 AttributeSource (org.hibernate.boot.model.source.spi.AttributeSource)2 PluralAttributeElementSourceManyToAny (org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny)2 PluralAttributeSource (org.hibernate.boot.model.source.spi.PluralAttributeSource)2 SingularAttributeSource (org.hibernate.boot.model.source.spi.SingularAttributeSource)2 SingularAttributeSourceAny (org.hibernate.boot.model.source.spi.SingularAttributeSourceAny)2