Class MergePersistenceUnitManager
java.lang.Object
org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
org.broadleafcommerce.common.extensibility.jpa.MergePersistenceUnitManager
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ResourceLoaderAware
,org.springframework.context.weaving.LoadTimeWeaverAware
,org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager
public class MergePersistenceUnitManager
extends org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
Merges jars, class names and mapping file names from several persistence.xml files. The
MergePersistenceUnitManager will continue to keep track of individual persistence unit
names (including individual data sources). When a specific PersistenceUnitInfo is requested
by unit name, the appropriate PersistenceUnitInfo is returned with modified jar files
urls, class names and mapping file names that include the comprehensive collection of these
values from all persistence.xml files.
- Author:
- jfischer, jjacobs
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContext
protected List<BroadleafClassTransformer>
static String
used in transformers to know from what persistentUnit classes are currently loadedprotected EntityMarkerClassTransformer
protected org.springframework.core.env.Environment
protected org.springframework.jmx.export.MBeanExporter
protected Set<BroadleafClassTransformer>
protected Map<String,
DataSource> protected List<QueryConfiguration>
protected static boolean
This should only be used in a test context to deal with the Spring ApplicationContext refreshing between different test classes but not needing to do a new transformation of classes every time.Fields inherited from class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
DEFAULT_PERSISTENCE_XML_LOCATION, logger, ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME, ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
addNamedQueriesToPersistenceUnits
(boolean weaverRegistered) protected boolean
Adds all of the configuredclassTransformers
to all of the persistence unitsvoid
void
void
If a class happened to be loaded by the ClassLoader before we had a chance to set up our instrumentation, it may not be in a consistent state.protected boolean
Detects whether or not Spring Devtools is on the classpathprotected void
disableSchemaCreateIfApplicable
(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo pui) protected void
Detects the presence of theEntityMarkerClassTransformer
and throws an exception if this is misconfigured.protected void
exceptionIfRootBeanDefinition
(List<String> nonTransformedClasses) Validates whether or not the given nonTransformedClasses are contained in the root ApplicationContext and throws an IllegalStateException if so, else this does nothingprotected void
exceptionWithNonTransformed
(List<String> nonTransformedClasses) protected org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo
getMergedUnit
(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) protected boolean
protected boolean
jakarta.persistence.spi.PersistenceUnitInfo
jakarta.persistence.spi.PersistenceUnitInfo
obtainPersistenceUnitInfo
(String persistenceUnitName) protected void
postProcessPersistenceUnitInfo
(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) void
void
setClassTransformers
(List<BroadleafClassTransformer> classTransformers) Triggers a class load via this class'sClassLoader
for all of the classes in all of the persistence unitsMethods inherited from class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
getDataSourceLookup, getDefaultDataSource, getDefaultJtaDataSource, getLoadTimeWeaver, getPersistenceUnitInfo, getPersistenceUnitPostProcessors, setDataSourceLookup, setDataSources, setDefaultDataSource, setDefaultJtaDataSource, setDefaultPersistenceUnitName, setDefaultPersistenceUnitRootLocation, setLoadTimeWeaver, setManagedClassNameFilter, setManagedTypes, setMappingResources, setPackagesToScan, setPersistenceUnitPostProcessors, setPersistenceXmlLocation, setPersistenceXmlLocations, setResourceLoader, setSharedCacheMode, setValidationMode
-
Field Details
-
currentProcessingPersistenceUnit
used in transformers to know from what persistentUnit classes are currently loaded -
transformed
protected static boolean transformedThis should only be used in a test context to deal with the Spring ApplicationContext refreshing between different test classes but not needing to do a new transformation of classes every time. This bean will get re-initialized but all the classes have already been transformed -
mergedPus
-
classTransformers
-
mergedPersistenceXmlLocations
-
mergedDataSources
-
mergedClassTransformers
-
entityMarkerClassTransformer
-
mBeanExporter
@Autowired(required=false) @Qualifier("blAutoDDLStatusExporter") protected org.springframework.jmx.export.MBeanExporter mBeanExporter -
applicationContext
@Autowired protected org.springframework.context.ApplicationContext applicationContext -
environment
@Autowired protected org.springframework.core.env.Environment environment -
queryConfigurations
-
-
Constructor Details
-
MergePersistenceUnitManager
public MergePersistenceUnitManager()
-
-
Method Details
-
isPersistenceUnitOverrideAllowed
protected boolean isPersistenceUnitOverrideAllowed()- Overrides:
isPersistenceUnitOverrideAllowed
in classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
configureMergedItems
@PostConstruct public void configureMergedItems() -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Overrides:
afterPropertiesSet
in classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
configureClassTransformers
@PostConstruct public void configureClassTransformers() throws InstantiationException, IllegalAccessException, ClassNotFoundException -
getMergedUnit
protected org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo getMergedUnit(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) -
preparePersistenceUnitInfos
public void preparePersistenceUnitInfos()- Overrides:
preparePersistenceUnitInfos
in classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
addTransformersToPersistenceUnits
Adds all of the configuredclassTransformers
to all of the persistence units- Returns:
- whether or not there was a LoadTimeWeaver registered
- Throws:
Exception
- if there was an undetectable problem during transformer addition
-
addNamedQueriesToPersistenceUnits
- Throws:
Exception
-
handleClassTransformerRegistrationProblem
protected boolean handleClassTransformerRegistrationProblem(BroadleafClassTransformer transformer, Exception e) throws Exception - Throws:
Exception
-
exceptionWithNonTransformed
protected void exceptionWithNonTransformed(List<String> nonTransformedClasses) throws ClassNotFoundException - Parameters:
nonTransformedClasses
- the classes that were detected as having not been transformed- Throws:
ClassNotFoundException
-
detectSpringBootDevtools
protected boolean detectSpringBootDevtools()Detects whether or not Spring Devtools is on the classpath -
exceptionIfRootBeanDefinition
protected void exceptionIfRootBeanDefinition(List<String> nonTransformedClasses) throws ClassNotFoundException Validates whether or not the given nonTransformedClasses are contained in the root ApplicationContext and throws an IllegalStateException if so, else this does nothing- Parameters:
nonTransformedClasses
- classes that were not detected as having undergone class transformation- Throws:
IllegalStateException
- if any of the nonTransformedClasses are in the root ApplicationContextClassNotFoundException
-
detectNonTransformedClasses
If a class happened to be loaded by the ClassLoader before we had a chance to set up our instrumentation, it may not be in a consistent state. This verifies with the EntityMarkerClassTransformer that it actually saw the classes loaded by the above process- Returns:
- the list of classes that were detected as not transformed representing an error state
-
triggerClassLoadForManagedClasses
Triggers a class load via this class'sClassLoader
for all of the classes in all of the persistence units- Returns:
- all of the classes that were loaded via this process
- Throws:
ClassNotFoundException
- if there was a problem in the class load
-
exceptionIfEntityMarkerNotFound
protected void exceptionIfEntityMarkerNotFound()Detects the presence of theEntityMarkerClassTransformer
and throws an exception if this is misconfigured. If there are no class transformes withinmergedClassTransformers
then this does nothing -
postProcessPersistenceUnitInfo
protected void postProcessPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) - Overrides:
postProcessPersistenceUnitInfo
in classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
obtainPersistenceUnitInfo
public jakarta.persistence.spi.PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) - Specified by:
obtainPersistenceUnitInfo
in interfaceorg.springframework.orm.jpa.persistenceunit.PersistenceUnitManager
- Overrides:
obtainPersistenceUnitInfo
in classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
obtainDefaultPersistenceUnitInfo
public jakarta.persistence.spi.PersistenceUnitInfo obtainDefaultPersistenceUnitInfo()- Specified by:
obtainDefaultPersistenceUnitInfo
in interfaceorg.springframework.orm.jpa.persistenceunit.PersistenceUnitManager
- Overrides:
obtainDefaultPersistenceUnitInfo
in classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
getClassTransformers
-
setClassTransformers
-
disableSchemaCreateIfApplicable
protected void disableSchemaCreateIfApplicable(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo pui)
-