Search in sources :

Example 1 with MetamodelImplementor

use of org.hibernate.metamodel.spi.MetamodelImplementor in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeImpl method initializeAllCollectionMetadata.

protected void initializeAllCollectionMetadata() {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getTarget();
    MetamodelImplementor metamodel = sessionFactory.getMetamodel();
    Map<String, CollectionPersister> collectionPersisters = metamodel.collectionPersisters();
    allCollectionMetadata = new HashMap<String, ICollectionMetadata>(collectionPersisters.size());
    for (Entry<String, CollectionPersister> entry : collectionPersisters.entrySet()) {
        allCollectionMetadata.put((String) entry.getKey(), getFacadeFactory().createCollectionMetadata(entry.getValue()));
    }
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor)

Example 2 with MetamodelImplementor

use of org.hibernate.metamodel.spi.MetamodelImplementor in project hibernate-orm by hibernate.

the class ExplicitJavaTypeDescriptorTest method testIt.

@Test
@TestForIssue(jiraKey = "HHH-11098")
public void testIt() {
    // set up test data
    Session session = openSession();
    ((MetamodelImplementor) session.getMetamodel()).getTypeConfiguration().getJavaTypeDescriptorRegistry().addDescriptor(new JavaTypeDescriptorRegistry.FallbackJavaTypeDescriptor(MutableState2.class) {

        @Override
        public MutabilityPlan getMutabilityPlan() {
            return ImmutableMutabilityPlan.INSTANCE;
        }
    });
    session.beginTransaction();
    session.persist(new TheEntity(1));
    session.getTransaction().commit();
    session.close();
    // assertions based on the persist call
    // 1 instead of 0 because of the deep copy call
    assertThat(mutableToDomainCallCount, is(1));
    // 2 instead of 1 because of the deep copy call
    assertThat(mutableToDatabaseCallCount, is(2));
    // logical
    assertThat(immutableToDomainCallCount, is(0));
    // logical
    assertThat(immutableToDatabaseCallCount, is(1));
    // was 1 (like mutable) before the JavaTypeDescriptor registration
    assertThat(immutableMutableToDomainCallCount, is(0));
    // was 2 (like mutable) before the JavaTypeDescriptor registration
    assertThat(immutableMutableToDatabaseCallCount, is(1));
    // clean up test data
    session = openSession();
    session.beginTransaction();
    session.delete(session.byId(TheEntity.class).getReference(1));
    session.getTransaction().commit();
    session.close();
}
Also used : MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) JavaTypeDescriptorRegistry(org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry) MutabilityPlan(org.hibernate.type.descriptor.java.MutabilityPlan) ImmutableMutabilityPlan(org.hibernate.type.descriptor.java.ImmutableMutabilityPlan) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with MetamodelImplementor

use of org.hibernate.metamodel.spi.MetamodelImplementor in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeImpl method initializeAllClassMetadata.

@Override
protected void initializeAllClassMetadata() {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getTarget();
    MetamodelImplementor metamodel = sessionFactory.getMetamodel();
    Map<String, EntityPersister> entityPersisters = metamodel.entityPersisters();
    allClassMetadata = new HashMap<String, IClassMetadata>(entityPersisters.size());
    for (Entry<String, EntityPersister> entry : entityPersisters.entrySet()) {
        allClassMetadata.put((String) entry.getKey(), getFacadeFactory().createClassMetadata(entry.getValue()));
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata)

Example 4 with MetamodelImplementor

use of org.hibernate.metamodel.spi.MetamodelImplementor in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeImpl method initializeAllCollectionMetadata.

protected void initializeAllCollectionMetadata() {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getTarget();
    MetamodelImplementor metamodel = sessionFactory.getMetamodel();
    Map<String, CollectionPersister> collectionPersisters = metamodel.collectionPersisters();
    allCollectionMetadata = new HashMap<String, ICollectionMetadata>(collectionPersisters.size());
    for (Entry<String, CollectionPersister> entry : collectionPersisters.entrySet()) {
        allCollectionMetadata.put((String) entry.getKey(), getFacadeFactory().createCollectionMetadata(entry.getValue()));
    }
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor)

Example 5 with MetamodelImplementor

use of org.hibernate.metamodel.spi.MetamodelImplementor in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeImpl method initializeAllClassMetadata.

@Override
protected void initializeAllClassMetadata() {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getTarget();
    MetamodelImplementor metamodel = sessionFactory.getMetamodel();
    Map<String, EntityPersister> entityPersisters = metamodel.entityPersisters();
    allClassMetadata = new HashMap<String, IClassMetadata>(entityPersisters.size());
    for (Entry<String, EntityPersister> entry : entityPersisters.entrySet()) {
        allClassMetadata.put((String) entry.getKey(), getFacadeFactory().createClassMetadata(entry.getValue()));
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata)

Aggregations

MetamodelImplementor (org.hibernate.metamodel.spi.MetamodelImplementor)5 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 IClassMetadata (org.jboss.tools.hibernate.runtime.spi.IClassMetadata)2 ICollectionMetadata (org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata)2 Session (org.hibernate.Session)1 TestForIssue (org.hibernate.testing.TestForIssue)1 ImmutableMutabilityPlan (org.hibernate.type.descriptor.java.ImmutableMutabilityPlan)1 JavaTypeDescriptorRegistry (org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry)1 MutabilityPlan (org.hibernate.type.descriptor.java.MutabilityPlan)1 Test (org.junit.Test)1