Search in sources :

Example 1 with MappingMetamodelImpl

use of org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeImpl method initializeAllCollectionMetadata.

protected void initializeAllCollectionMetadata() {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getTarget();
    MappingMetamodelImpl metamodel = (MappingMetamodelImpl) 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) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MappingMetamodelImpl(org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl)

Example 2 with MappingMetamodelImpl

use of org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl in project hibernate-orm by hibernate.

the class RuntimeMetamodelsImpl method finishInitialization.

/**
 * Chicken-and-egg because things try to use the SessionFactory (specifically the MappingMetamodel)
 * before it is ready.  So we do this fugly code...
 */
public void finishInitialization(MetadataImplementor bootMetamodel, BootstrapContext bootstrapContext, SessionFactoryImpl sessionFactory) {
    final MappingMetamodelImpl mappingMetamodel = bootstrapContext.getTypeConfiguration().scope(sessionFactory);
    this.mappingMetamodel = mappingMetamodel;
    mappingMetamodel.finishInitialization(bootMetamodel, bootstrapContext, sessionFactory);
    this.jpaMetamodel = mappingMetamodel.getJpaMetamodel();
}
Also used : MappingMetamodelImpl(org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl)

Example 3 with MappingMetamodelImpl

use of org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl in project hibernate-orm by hibernate.

the class MetamodelBoundedCacheTest method testMemoryConsumptionOfFailedImportsCache.

@Test
@TestForIssue(jiraKey = "HHH-14948")
public void testMemoryConsumptionOfFailedImportsCache() throws NoSuchFieldException, IllegalAccessException {
    MappingMetamodel mappingMetamodel = sessionFactory().getMappingMetamodel();
    MappingMetamodelImpl mImpl = (MappingMetamodelImpl) mappingMetamodel;
    final JpaMetamodel jpaMetamodel = mImpl.getJpaMetamodel();
    for (int i = 0; i < 1001; i++) {
        jpaMetamodel.qualifyImportableName("nonexistend" + i);
    }
    Field field = JpaMetamodelImpl.class.getDeclaredField("nameToImportMap");
    field.setAccessible(true);
    // noinspection unchecked
    Map<String, String> imports = (Map<String, String>) field.get(jpaMetamodel);
    // VERY hard-coded, but considering the possibility of a regression of a memory-related issue,
    // it should be worth it
    assertEquals(1000, imports.size());
}
Also used : Field(java.lang.reflect.Field) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) MappingMetamodelImpl(org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl) JpaMetamodel(org.hibernate.metamodel.model.domain.JpaMetamodel) Map(java.util.Map) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 4 with MappingMetamodelImpl

use of org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeImpl method initializeAllClassMetadata.

@Override
protected void initializeAllClassMetadata() {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getTarget();
    MappingMetamodelImpl metamodel = (MappingMetamodelImpl) 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) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) MappingMetamodelImpl(org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl)

Example 5 with MappingMetamodelImpl

use of org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl in project hibernate-orm by hibernate.

the class SessionFactoryImpl method close.

/**
 * Closes the session factory, releasing all held resources.
 *
 * <ol>
 * <li>cleans up used cache regions and "stops" the cache provider.
 * <li>close the JDBC connection
 * <li>remove the JNDI binding
 * </ol>
 *
 * Note: Be aware that the sessionFactory instance still can
 * be a "heavy" object memory wise after close() has been called.  Thus
 * it is important to not keep referencing the instance to let the garbage
 * collector release the memory.
 */
@Override
public void close() throws HibernateException {
    synchronized (this) {
        if (status != Status.OPEN) {
            if (getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled()) {
                throw new IllegalStateException("EntityManagerFactory is already closed");
            }
            LOG.trace("Already closed");
            return;
        }
        status = Status.CLOSING;
    }
    try {
        LOG.closing();
        observer.sessionFactoryClosing(this);
        if (cacheAccess != null) {
            cacheAccess.close();
        }
        if (runtimeMetamodels != null && runtimeMetamodels.getMappingMetamodel() != null) {
            final JdbcConnectionAccess jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
            runtimeMetamodels.getMappingMetamodel().forEachEntityDescriptor(entityPersister -> {
                if (entityPersister.getSqmMultiTableMutationStrategy() != null) {
                    entityPersister.getSqmMultiTableMutationStrategy().release(this, jdbcConnectionAccess);
                }
                if (entityPersister.getSqmMultiTableInsertStrategy() != null) {
                    entityPersister.getSqmMultiTableInsertStrategy().release(this, jdbcConnectionAccess);
                }
            });
            ((MappingMetamodelImpl) runtimeMetamodels.getMappingMetamodel()).close();
        }
        if (queryEngine != null) {
            queryEngine.close();
        }
        if (delayedDropAction != null) {
            delayedDropAction.perform(serviceRegistry);
        }
        SessionFactoryRegistry.INSTANCE.removeSessionFactory(getUuid(), name, sessionFactoryOptions.isSessionFactoryNameAlsoJndiName(), serviceRegistry.getService(JndiService.class));
    } finally {
        status = Status.CLOSED;
    }
    observer.sessionFactoryClosed(this);
    serviceRegistry.destroy();
}
Also used : JndiService(org.hibernate.engine.jndi.spi.JndiService) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) MappingMetamodelImpl(org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl)

Aggregations

MappingMetamodelImpl (org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl)5 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)1 JndiService (org.hibernate.engine.jndi.spi.JndiService)1 MappingMetamodel (org.hibernate.metamodel.MappingMetamodel)1 JpaMetamodel (org.hibernate.metamodel.model.domain.JpaMetamodel)1 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 TestForIssue (org.hibernate.testing.TestForIssue)1 IClassMetadata (org.jboss.tools.hibernate.runtime.spi.IClassMetadata)1 ICollectionMetadata (org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata)1 Test (org.junit.Test)1