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 Details

    • currentProcessingPersistenceUnit

      public static String currentProcessingPersistenceUnit
      used in transformers to know from what persistentUnit classes are currently loaded
    • transformed

      protected static boolean transformed
      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. This bean will get re-initialized but all the classes have already been transformed
    • mergedPus

      protected HashMap<String,jakarta.persistence.spi.PersistenceUnitInfo> mergedPus
    • classTransformers

      protected List<BroadleafClassTransformer> classTransformers
    • mergedPersistenceXmlLocations

      protected Set<String> mergedPersistenceXmlLocations
    • mergedDataSources

      protected Map<String,DataSource> mergedDataSources
    • mergedClassTransformers

      protected Set<BroadleafClassTransformer> mergedClassTransformers
    • entityMarkerClassTransformer

      protected EntityMarkerClassTransformer 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

      @Autowired(required=false) protected List<QueryConfiguration> queryConfigurations
  • Constructor Details

    • MergePersistenceUnitManager

      public MergePersistenceUnitManager()
  • Method Details

    • isPersistenceUnitOverrideAllowed

      protected boolean isPersistenceUnitOverrideAllowed()
      Overrides:
      isPersistenceUnitOverrideAllowed in class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
    • configureMergedItems

      @PostConstruct public void configureMergedItems()
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Overrides:
      afterPropertiesSet in class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
    • configureClassTransformers

      @PostConstruct public void configureClassTransformers() throws InstantiationException, IllegalAccessException, ClassNotFoundException
      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 class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
    • addTransformersToPersistenceUnits

      protected boolean addTransformersToPersistenceUnits() throws Exception
      Adds all of the configured classTransformers 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

      protected boolean addNamedQueriesToPersistenceUnits(boolean weaverRegistered) throws Exception
      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 ApplicationContext
      ClassNotFoundException
    • detectNonTransformedClasses

      protected List<String> 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

      protected List<String> triggerClassLoadForManagedClasses() throws ClassNotFoundException
      Triggers a class load via this class's ClassLoader 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 the EntityMarkerClassTransformer and throws an exception if this is misconfigured. If there are no class transformes within mergedClassTransformers then this does nothing
    • postProcessPersistenceUnitInfo

      protected void postProcessPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo newPU)
      Overrides:
      postProcessPersistenceUnitInfo in class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
    • obtainPersistenceUnitInfo

      public jakarta.persistence.spi.PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName)
      Specified by:
      obtainPersistenceUnitInfo in interface org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager
      Overrides:
      obtainPersistenceUnitInfo in class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
    • obtainDefaultPersistenceUnitInfo

      public jakarta.persistence.spi.PersistenceUnitInfo obtainDefaultPersistenceUnitInfo()
      Specified by:
      obtainDefaultPersistenceUnitInfo in interface org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager
      Overrides:
      obtainDefaultPersistenceUnitInfo in class org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
    • getClassTransformers

      public List<BroadleafClassTransformer> getClassTransformers()
    • setClassTransformers

      public void setClassTransformers(List<BroadleafClassTransformer> classTransformers)
    • disableSchemaCreateIfApplicable

      protected void disableSchemaCreateIfApplicable(String persistenceUnitName, org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo pui)