Search in sources :

Example 1 with ManyToOneType

use of org.hibernate.type.ManyToOneType 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 ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class MultiplicityType method nullSafeSet.

public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
    Multiplicity o = (Multiplicity) value;
    GlarchProxy g;
    Integer c;
    if (o == null) {
        g = null;
        c = new Integer(0);
    } else {
        g = o.glarch;
        c = new Integer(o.count);
    }
    IntegerType.INSTANCE.nullSafeSet(st, c, index, session);
    new ManyToOneType(NoScope.INSTANCE, Glarch.class.getName()).nullSafeSet(st, g, index + 1, session);
}
Also used : ManyToOneType(org.hibernate.type.ManyToOneType)

Example 3 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsEntityType.

@Test
public void testIsEntityType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertFalse(typeFacade.isEntityType());
    EntityType entityType = new ManyToOneType(null);
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertTrue(entityType.isEntityType());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 4 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsOneToOne.

@Test
public void testIsOneToOne() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertFalse(typeFacade.isOneToOne());
    EntityType entityType = new ManyToOneType(null);
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertFalse(entityType.isOneToOne());
    OneToOneType oneToOneType = new OneToOneType(null, null, null, false, false, false, null, null);
    typeFacade = FACADE_FACTORY.createType(oneToOneType);
    Assert.assertTrue(oneToOneType.isOneToOne());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) OneToOneType(org.hibernate.type.OneToOneType) Test(org.junit.Test)

Example 5 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testGetAssociatedEntityName.

@Test
public void testGetAssociatedEntityName() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertNull(typeFacade.getAssociatedEntityName());
    EntityType entityType = new ManyToOneType("foo");
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertEquals("foo", typeFacade.getAssociatedEntityName());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Aggregations

ManyToOneType (org.hibernate.type.ManyToOneType)35 Test (org.junit.Test)28 ClassType (org.hibernate.type.ClassType)24 EntityType (org.hibernate.type.EntityType)24 IType (org.jboss.tools.hibernate.runtime.spi.IType)24 OneToOneType (org.hibernate.type.OneToOneType)11 Type (org.hibernate.type.Type)9 ComponentType (org.hibernate.type.ComponentType)7 HashMap (java.util.HashMap)4 Query (org.hibernate.Query)4 Session (org.hibernate.Session)4 Transaction (org.hibernate.Transaction)4 DiscriminatorType (org.hibernate.persister.entity.DiscriminatorType)4 TransactionUtil2.inTransaction (org.hibernate.testing.transaction.TransactionUtil2.inTransaction)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 CollectionType (org.hibernate.type.CollectionType)2 SetType (org.hibernate.type.SetType)2 Element (org.dom4j.Element)1