Search in sources :

Example 11 with EntityTuplizer

use of org.hibernate.tuple.entity.EntityTuplizer in project hibernate-orm by hibernate.

the class AccessMappingTest method testExplicitPropertyAccessAnnotationsOnProperty.

@Test
public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course2.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Property access should be used.", tuplizer.getIdentifierGetter() instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) Test(org.junit.Test)

Example 12 with EntityTuplizer

use of org.hibernate.tuple.entity.EntityTuplizer in project hibernate-orm by hibernate.

the class AccessMappingTest method testPropertyAnnotationPlacement.

@Test
public void testPropertyAnnotationPlacement() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course7.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Property access should be used.", tuplizer.getIdentifierGetter() instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) Test(org.junit.Test)

Example 13 with EntityTuplizer

use of org.hibernate.tuple.entity.EntityTuplizer in project hibernate-orm by hibernate.

the class AccessMappingTest method testDefaultFieldAccessIsInherited.

@Test
public void testDefaultFieldAccessIsInherited() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = User.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Person.class);
    cfg.addAnnotatedClass(Being.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Field access should be used since the default access mode gets inherited", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 14 with EntityTuplizer

use of org.hibernate.tuple.entity.EntityTuplizer in project hibernate-orm by hibernate.

the class AccessMappingTest method testExplicitPropertyAccessAnnotationsWithJpaStyleOverride.

@Test
public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course5.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Field access should be used.", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
        assertTrue("Property access should be used.", tuplizer.getGetter(0) instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) Test(org.junit.Test)

Example 15 with EntityTuplizer

use of org.hibernate.tuple.entity.EntityTuplizer in project jbosstools-hibernate by jbosstools.

the class EntityMetamodelFacadeTest method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    RootClass rc = new RootClass();
    Table t = new Table("foobar");
    rc.setTable(t);
    Column c = new Column("foo");
    t.addColumn(c);
    ArrayList<Column> keyList = new ArrayList<>();
    keyList.add(c);
    t.createUniqueKey(keyList);
    SimpleValue sv = new SimpleValue(configuration.createMappings());
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.addColumn(c);
    rc.setEntityName("foobar");
    rc.setIdentifier(sv);
    entityMetamodel = new EntityMetamodel(rc, sfi) {

        @Override
        public EntityTuplizer getTuplizer(EntityMode entityMode) {
            return (EntityTuplizer) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { EntityTuplizer.class }, new TestInvocationHandler());
        }

        @Override
        public Integer getPropertyIndexOrNull(String id) {
            methodName = "getPropertyIndexOrNull";
            arguments = new Object[] { id };
            return INDEX;
        }
    };
    entityMetamodelFacade = new EntityMetamodelFacadeImpl(FACADE_FACTORY, entityMetamodel);
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) ArrayList(java.util.ArrayList) SimpleValue(org.hibernate.mapping.SimpleValue) EntityMode(org.hibernate.EntityMode) Column(org.hibernate.mapping.Column) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) Before(org.junit.Before)

Aggregations

Configuration (org.hibernate.cfg.Configuration)15 EntityTuplizer (org.hibernate.tuple.entity.EntityTuplizer)15 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 ArrayList (java.util.ArrayList)8 Column (org.hibernate.mapping.Column)8 RootClass (org.hibernate.mapping.RootClass)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 Table (org.hibernate.mapping.Table)8 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)8 IEntityMetamodel (org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel)8 Before (org.junit.Before)8 Test (org.junit.Test)7 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 AbstractEntityMetamodelFacade (org.jboss.tools.hibernate.runtime.common.AbstractEntityMetamodelFacade)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 GetterFieldImpl (org.hibernate.property.access.spi.GetterFieldImpl)5 GetterMethodImpl (org.hibernate.property.access.spi.GetterMethodImpl)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 EntityMode (org.hibernate.EntityMode)2 SessionFactoryImplementor (org.hibernate.engine.SessionFactoryImplementor)2