continue in attempt to clean up EMFBuilderImpl

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-09-03 10:09:38 +02:00
parent 226e85957b
commit 437b59a57d
7 changed files with 560 additions and 482 deletions

View File

@ -207,8 +207,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private boolean orderUpdatesEnabled; private boolean orderUpdatesEnabled;
private boolean orderInsertsEnabled; private boolean orderInsertsEnabled;
private boolean collectionsInDefaultFetchGroupEnabled = true; private boolean collectionsInDefaultFetchGroupEnabled = true;
private boolean UnownedAssociationTransientCheck; private final boolean UnownedAssociationTransientCheck;
private boolean passProcedureParameterNames; private final boolean passProcedureParameterNames;
// JPA callbacks // JPA callbacks
private final boolean callbacksEnabled; private final boolean callbacksEnabled;

View File

@ -0,0 +1,74 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.jpa.boot.internal;
import org.hibernate.boot.CacheRegionDefinition;
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.PropertiesHelper;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import static org.hibernate.cfg.PersistenceSettings.PERSISTENCE_UNIT_NAME;
import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_NAME;
public class MergedSettings {
private final Map<String, Object> configurationValues =
new ConcurrentHashMap<>(16, 0.75f, 1);
private List<CacheRegionDefinition> cacheRegionDefinitions;
/**
* {@code MergedSettings} is initialized with {@code hibernate.properties}
*/
MergedSettings() {
getConfigurationValues().putAll( PropertiesHelper.map( Environment.getProperties() ) );
}
List<CacheRegionDefinition> getCacheRegionDefinitions() {
return cacheRegionDefinitions;
}
void processPersistenceUnitDescriptorProperties(PersistenceUnitDescriptor persistenceUnit) {
final Properties properties = persistenceUnit.getProperties();
if ( properties != null ) {
getConfigurationValues().putAll( PropertiesHelper.map( properties ) );
}
getConfigurationValues().put( PERSISTENCE_UNIT_NAME, persistenceUnit.getName() );
}
void processHibernateConfigXmlResources(LoadedConfig loadedConfig) {
if ( !getConfigurationValues().containsKey( SESSION_FACTORY_NAME) ) {
// there is not already a SF-name in the merged settings
final String sessionFactoryName = loadedConfig.getSessionFactoryName();
if ( sessionFactoryName != null ) {
// but the cfg.xml file we are processing named one
getConfigurationValues().put( SESSION_FACTORY_NAME, sessionFactoryName );
}
}
// else {
// make sure they match?
// }
getConfigurationValues().putAll( loadedConfig.getConfigurationValues() );
}
public Map<String, Object> getConfigurationValues() {
return configurationValues;
}
void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
if ( cacheRegionDefinitions == null ) {
cacheRegionDefinitions = new ArrayList<>();
}
cacheRegionDefinitions.add( cacheRegionDefinition );
}
}

View File

@ -0,0 +1,36 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.boot.internal;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.service.spi.ServiceRegistryImplementor;
class ServiceRegistryCloser implements SessionFactoryObserver {
/**
* Singleton access
*/
public static final ServiceRegistryCloser INSTANCE = new ServiceRegistryCloser();
@Override
public void sessionFactoryCreated(SessionFactory sessionFactory) {
// nothing to do
}
@Override
public void sessionFactoryClosed(SessionFactory sessionFactory) {
final SessionFactoryImplementor factoryImplementor = (SessionFactoryImplementor) sessionFactory;
final ServiceRegistryImplementor serviceRegistry = factoryImplementor.getServiceRegistry();
serviceRegistry.destroy();
final ServiceRegistryImplementor basicRegistry =
(ServiceRegistryImplementor) serviceRegistry.getParentServiceRegistry();
if ( basicRegistry != null ) {
basicRegistry.destroy();
}
}
}

View File

@ -14,6 +14,7 @@ import java.util.function.Consumer;
import org.hibernate.Internal; import org.hibernate.Internal;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.MergedSettings;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor; import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
import jakarta.persistence.spi.PersistenceUnitInfo; import jakarta.persistence.spi.PersistenceUnitInfo;
@ -93,7 +94,7 @@ public final class Bootstrap {
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder( public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitDescriptor persistenceUnitDescriptor, PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration, Map integration,
Consumer<EntityManagerFactoryBuilderImpl.MergedSettings> mergedSettingsBaseline) { Consumer<MergedSettings> mergedSettingsBaseline) {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, mergedSettingsBaseline ); return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, mergedSettingsBaseline );
} }
@ -124,7 +125,7 @@ public final class Bootstrap {
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder( public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitInfo persistenceUnitInfo, PersistenceUnitInfo persistenceUnitInfo,
Map integration, Map integration,
Consumer<EntityManagerFactoryBuilderImpl.MergedSettings> mergedSettingsBaseline) { Consumer<MergedSettings> mergedSettingsBaseline) {
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, mergedSettingsBaseline ); return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, mergedSettingsBaseline );
} }
} }

View File

@ -0,0 +1,26 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.jpa.internal;
import jakarta.persistence.EntityNotFoundException;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.proxy.EntityNotFoundDelegate;
import java.io.Serializable;
public class JpaEntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {
/**
* Singleton access
*/
public static final JpaEntityNotFoundDelegate INSTANCE = new JpaEntityNotFoundDelegate();
public void handleEntityNotFound(String entityName, Object identifier) {
final ObjectNotFoundException exception = new ObjectNotFoundException( entityName, identifier );
throw new EntityNotFoundException( exception.getMessage(), exception );
}
}

View File

@ -7,7 +7,6 @@
package org.hibernate.orm.test.bootstrap.scanning; package org.hibernate.orm.test.bootstrap.scanning;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;