Class PersistenceServiceImpl

java.lang.Object
org.broadleafcommerce.common.service.PersistenceServiceImpl
All Implemented Interfaces:
PersistenceService, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

@Service("blPersistenceService") public class PersistenceServiceImpl extends Object implements PersistenceService, org.springframework.context.SmartLifecycle
Service to help gather the correct EntityManager or PlatformTransactionManager, based on a class and TargetModeType. This functionality is especially useful when multiple PersistenceUnits are in use.

Note: All "default" items reference blPU, which is used to manage most Broadleaf entities in the Admin.

Author:
Chris Kittrell (ckittrell)
  • Field Details

  • Constructor Details

    • PersistenceServiceImpl

      public PersistenceServiceImpl()
  • Method Details

    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • stop

      public void stop(Runnable callback)
      Specified by:
      stop in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • initializeEntityManagerCache

      protected void initializeEntityManagerCache()
    • populateCaches

      protected void populateCaches(String targetMode, Map<String,Object> managerMap)
    • validateEntityClassName

      public boolean validateEntityClassName(String entityClassName)
      Description copied from interface: PersistenceService
      Determine if a test class name represents a known entity class registered with Hibernate
      Specified by:
      validateEntityClassName in interface PersistenceService
      Returns:
    • identifyEntityManager

      public jakarta.persistence.EntityManager identifyEntityManager(Class entityClass)
      Description copied from interface: PersistenceService
      Identifies the EntityManager for the given entityClass, using the default targetModeType of TargetModeType.SANDBOX
      Specified by:
      identifyEntityManager in interface PersistenceService
      Returns:
      the EntityManager
    • identifyEntityManager

      public jakarta.persistence.EntityManager identifyEntityManager(Class entityClass, TargetModeType targetModeType)
      Description copied from interface: PersistenceService
      Identifies the EntityManager for the given entityClass and targetModeType
      Specified by:
      identifyEntityManager in interface PersistenceService
      Returns:
      the EntityManager
    • identifyTransactionManager

      public org.springframework.transaction.PlatformTransactionManager identifyTransactionManager(String className, TargetModeType targetModeType)
      Description copied from interface: PersistenceService
      Identifies the PlatformTransactionManager for the given className and targetModeType
      Specified by:
      identifyTransactionManager in interface PersistenceService
      Returns:
      the PlatformTransactionManager
    • identifyDefaultEntityManager

      public jakarta.persistence.EntityManager identifyDefaultEntityManager(TargetModeType targetModeType)
      Description copied from interface: PersistenceService
      Identifies the default EntityManager for the given targetModeType

      NOTE: This assumes that the EntityManager is based on blPU

      Specified by:
      identifyDefaultEntityManager in interface PersistenceService
      Returns:
      the EntityManager
    • getEntityManager

      public jakarta.persistence.EntityManager getEntityManager(Map<String,Object> managerMap)
      Description copied from interface: PersistenceService
      Gathers the EntityManager from the provided managerMap
      Specified by:
      getEntityManager in interface PersistenceService
      Returns:
      the EntityManager
    • identifyDefaultTransactionManager

      public org.springframework.transaction.PlatformTransactionManager identifyDefaultTransactionManager(TargetModeType targetModeType)
      Description copied from interface: PersistenceService
      Identifies the default PlatformTransactionManager for the given targetModeType

      NOTE: This assumes that the PlatformTransactionManager is based on blPU

      Specified by:
      identifyDefaultTransactionManager in interface PersistenceService
      Returns:
      the PlatformTransactionManager
    • getTransactionManager

      public org.springframework.transaction.PlatformTransactionManager getTransactionManager(Map<String,Object> managerMap)
      Description copied from interface: PersistenceService
      Gathers the PlatformTransactionManager from the provided managerMap
      Specified by:
      getTransactionManager in interface PersistenceService
      Returns:
      the PlatformTransactionManager
    • getCeilingImplClassFromEntityManagers

      public Class<?> getCeilingImplClassFromEntityManagers(String className)
      Description copied from interface: PersistenceService
      Retrieves the topmost implementation for the given className by checking each registered EntityManager. If this is not found in the entity managers, this returns null
      Specified by:
      getCeilingImplClassFromEntityManagers in interface PersistenceService
    • buildManagerCacheKey

      protected String buildManagerCacheKey(String targetMode, Class<?> clazz)
    • buildManagerCacheKey

      protected String buildManagerCacheKey(String targetMode, String className)
    • buildEJB3ConfigDaoCacheKey

      protected String buildEJB3ConfigDaoCacheKey(Class<?> clazz)
    • getManagedClassName

      protected String getManagedClassName(String className)
    • getClassForName

      protected Class<?> getClassForName(String className)