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.ApplicationContextprotected List<BroadleafClassTransformer>static Stringused in transformers to know from what persistentUnit classes are currently loadedprotected EntityMarkerClassTransformerprotected org.springframework.core.env.Environmentprotected org.springframework.jmx.export.MBeanExporterprotected Set<BroadleafClassTransformer>protected Map<String,DataSource> protected List<QueryConfiguration>protected static booleanThis 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 booleanaddNamedQueriesToPersistenceUnits(boolean weaverRegistered) protected booleanAdds all of the configuredclassTransformersto all of the persistence unitsvoidvoidvoidIf 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 booleanDetects whether or not Spring Devtools is on the classpathprotected voiddisableSchemaCreateIfApplicable(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo pui) protected voidDetects the presence of theEntityMarkerClassTransformerand throws an exception if this is misconfigured.protected voidexceptionIfRootBeanDefinition(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 voidexceptionWithNonTransformed(List<String> nonTransformedClasses) protected org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfogetMergedUnit(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) protected booleanprotected booleanjakarta.persistence.spi.PersistenceUnitInfojakarta.persistence.spi.PersistenceUnitInfoobtainPersistenceUnitInfo(String persistenceUnitName) protected voidpostProcessPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) voidvoidsetClassTransformers(List<BroadleafClassTransformer> classTransformers) Triggers a class load via this class'sClassLoaderfor 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:
isPersistenceUnitOverrideAllowedin classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
configureMergedItems
@PostConstruct public void configureMergedItems() -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin 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:
preparePersistenceUnitInfosin classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
addTransformersToPersistenceUnits
Adds all of the configuredclassTransformersto 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'sClassLoaderfor 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 theEntityMarkerClassTransformerand throws an exception if this is misconfigured. If there are no class transformes withinmergedClassTransformersthen this does nothing -
postProcessPersistenceUnitInfo
protected void postProcessPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU) - Overrides:
postProcessPersistenceUnitInfoin classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
obtainPersistenceUnitInfo
public jakarta.persistence.spi.PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) - Specified by:
obtainPersistenceUnitInfoin interfaceorg.springframework.orm.jpa.persistenceunit.PersistenceUnitManager- Overrides:
obtainPersistenceUnitInfoin classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
obtainDefaultPersistenceUnitInfo
public jakarta.persistence.spi.PersistenceUnitInfo obtainDefaultPersistenceUnitInfo()- Specified by:
obtainDefaultPersistenceUnitInfoin interfaceorg.springframework.orm.jpa.persistenceunit.PersistenceUnitManager- Overrides:
obtainDefaultPersistenceUnitInfoin classorg.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
-
getClassTransformers
-
setClassTransformers
-
disableSchemaCreateIfApplicable
protected void disableSchemaCreateIfApplicable(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo pui)
-