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()));
}
}
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();
}
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());
}
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()));
}
}
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();
}
Aggregations