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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected EntityConfigurationprotected List<jakarta.persistence.EntityManager>protected static final org.apache.commons.logging.Logprotected static final Stringprotected StreamingTransactionCapableUtilFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildEJB3ConfigDaoCacheKey(Class<?> clazz) protected StringbuildManagerCacheKey(String targetMode, Class<?> clazz) protected StringbuildManagerCacheKey(String targetMode, String className) Class<?>getCeilingImplClassFromEntityManagers(String className) Retrieves the topmost implementation for the given className by checking each registeredEntityManager.protected Class<?>getClassForName(String className) jakarta.persistence.EntityManagergetEntityManager(Map<String, Object> managerMap) Gathers theEntityManagerfrom the provided managerMapprotected StringgetManagedClassName(String className) intgetPhase()org.springframework.transaction.PlatformTransactionManagergetTransactionManager(Map<String, Object> managerMap) Gathers thePlatformTransactionManagerfrom the provided managerMapjakarta.persistence.EntityManageridentifyDefaultEntityManager(TargetModeType targetModeType) Identifies the defaultEntityManagerfor the given targetModeTypeorg.springframework.transaction.PlatformTransactionManageridentifyDefaultTransactionManager(TargetModeType targetModeType) Identifies the defaultPlatformTransactionManagerfor the given targetModeTypejakarta.persistence.EntityManageridentifyEntityManager(Class entityClass) Identifies theEntityManagerfor the given entityClass, using the default targetModeType ofTargetModeType.SANDBOXjakarta.persistence.EntityManageridentifyEntityManager(Class entityClass, TargetModeType targetModeType) Identifies theEntityManagerfor the given entityClass and targetModeTypeorg.springframework.transaction.PlatformTransactionManageridentifyTransactionManager(String className, TargetModeType targetModeType) Identifies thePlatformTransactionManagerfor the given className and targetModeTypeprotected voidbooleanbooleanprotected voidpopulateCaches(String targetMode, Map<String, Object> managerMap) voidstart()voidstop()voidbooleanvalidateEntityClassName(String entityClassName) Determine if a test class name represents a known entity class registered with Hibernate
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOG -
ENTITY_MANAGER_KEY
- See Also:
-
TRANSACTION_MANAGER_KEY
- See Also:
-
entityConfiguration
-
targetModeMaps
-
defaultTargetModeMap
-
transUtil
-
entityManagers
-
-
Constructor Details
-
PersistenceServiceImpl
public PersistenceServiceImpl()
-
-
Method Details
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
initializeEntityManagerCache
protected void initializeEntityManagerCache() -
populateCaches
-
validateEntityClassName
Description copied from interface:PersistenceServiceDetermine if a test class name represents a known entity class registered with Hibernate- Specified by:
validateEntityClassNamein interfacePersistenceService- Returns:
-
identifyEntityManager
Description copied from interface:PersistenceServiceIdentifies theEntityManagerfor the given entityClass, using the default targetModeType ofTargetModeType.SANDBOX- Specified by:
identifyEntityManagerin interfacePersistenceService- Returns:
- the
EntityManager
-
identifyEntityManager
public jakarta.persistence.EntityManager identifyEntityManager(Class entityClass, TargetModeType targetModeType) Description copied from interface:PersistenceServiceIdentifies theEntityManagerfor the given entityClass and targetModeType- Specified by:
identifyEntityManagerin interfacePersistenceService- Returns:
- the
EntityManager
-
identifyTransactionManager
public org.springframework.transaction.PlatformTransactionManager identifyTransactionManager(String className, TargetModeType targetModeType) Description copied from interface:PersistenceServiceIdentifies thePlatformTransactionManagerfor the given className and targetModeType- Specified by:
identifyTransactionManagerin interfacePersistenceService- Returns:
- the
PlatformTransactionManager
-
identifyDefaultEntityManager
public jakarta.persistence.EntityManager identifyDefaultEntityManager(TargetModeType targetModeType) Description copied from interface:PersistenceServiceIdentifies the defaultEntityManagerfor the given targetModeTypeNOTE: This assumes that the
EntityManageris based on blPU- Specified by:
identifyDefaultEntityManagerin interfacePersistenceService- Returns:
- the
EntityManager
-
getEntityManager
Description copied from interface:PersistenceServiceGathers theEntityManagerfrom the provided managerMap- Specified by:
getEntityManagerin interfacePersistenceService- Returns:
- the
EntityManager
-
identifyDefaultTransactionManager
public org.springframework.transaction.PlatformTransactionManager identifyDefaultTransactionManager(TargetModeType targetModeType) Description copied from interface:PersistenceServiceIdentifies the defaultPlatformTransactionManagerfor the given targetModeTypeNOTE: This assumes that the
PlatformTransactionManageris based on blPU- Specified by:
identifyDefaultTransactionManagerin interfacePersistenceService- Returns:
- the
PlatformTransactionManager
-
getTransactionManager
public org.springframework.transaction.PlatformTransactionManager getTransactionManager(Map<String, Object> managerMap) Description copied from interface:PersistenceServiceGathers thePlatformTransactionManagerfrom the provided managerMap- Specified by:
getTransactionManagerin interfacePersistenceService- Returns:
- the
PlatformTransactionManager
-
getCeilingImplClassFromEntityManagers
Description copied from interface:PersistenceServiceRetrieves the topmost implementation for the given className by checking each registeredEntityManager. If this is not found in the entity managers, this returns null- Specified by:
getCeilingImplClassFromEntityManagersin interfacePersistenceService
-
buildManagerCacheKey
-
buildManagerCacheKey
-
buildEJB3ConfigDaoCacheKey
-
getManagedClassName
-
getClassForName
-