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 PersistenceUnit
s 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 String
protected EntityConfiguration
protected List<jakarta.persistence.EntityManager>
protected static final org.apache.commons.logging.Log
protected static final String
protected StreamingTransactionCapableUtil
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
buildEJB3ConfigDaoCacheKey
(Class<?> clazz) protected String
buildManagerCacheKey
(String targetMode, Class<?> clazz) protected String
buildManagerCacheKey
(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.EntityManager
getEntityManager
(Map<String, Object> managerMap) Gathers theEntityManager
from the provided managerMapprotected String
getManagedClassName
(String className) int
getPhase()
org.springframework.transaction.PlatformTransactionManager
getTransactionManager
(Map<String, Object> managerMap) Gathers thePlatformTransactionManager
from the provided managerMapjakarta.persistence.EntityManager
identifyDefaultEntityManager
(TargetModeType targetModeType) Identifies the defaultEntityManager
for the given targetModeTypeorg.springframework.transaction.PlatformTransactionManager
identifyDefaultTransactionManager
(TargetModeType targetModeType) Identifies the defaultPlatformTransactionManager
for the given targetModeTypejakarta.persistence.EntityManager
identifyEntityManager
(Class entityClass) Identifies theEntityManager
for the given entityClass, using the default targetModeType ofTargetModeType.SANDBOX
jakarta.persistence.EntityManager
identifyEntityManager
(Class entityClass, TargetModeType targetModeType) Identifies theEntityManager
for the given entityClass and targetModeTypeorg.springframework.transaction.PlatformTransactionManager
identifyTransactionManager
(String className, TargetModeType targetModeType) Identifies thePlatformTransactionManager
for the given className and targetModeTypeprotected void
boolean
boolean
protected void
populateCaches
(String targetMode, Map<String, Object> managerMap) void
start()
void
stop()
void
boolean
validateEntityClassName
(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:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
stop
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
-
initializeEntityManagerCache
protected void initializeEntityManagerCache() -
populateCaches
-
validateEntityClassName
Description copied from interface:PersistenceService
Determine if a test class name represents a known entity class registered with Hibernate- Specified by:
validateEntityClassName
in interfacePersistenceService
- Returns:
-
identifyEntityManager
Description copied from interface:PersistenceService
Identifies theEntityManager
for the given entityClass, using the default targetModeType ofTargetModeType.SANDBOX
- Specified by:
identifyEntityManager
in interfacePersistenceService
- Returns:
- the
EntityManager
-
identifyEntityManager
public jakarta.persistence.EntityManager identifyEntityManager(Class entityClass, TargetModeType targetModeType) Description copied from interface:PersistenceService
Identifies theEntityManager
for the given entityClass and targetModeType- Specified by:
identifyEntityManager
in interfacePersistenceService
- Returns:
- the
EntityManager
-
identifyTransactionManager
public org.springframework.transaction.PlatformTransactionManager identifyTransactionManager(String className, TargetModeType targetModeType) Description copied from interface:PersistenceService
Identifies thePlatformTransactionManager
for the given className and targetModeType- Specified by:
identifyTransactionManager
in interfacePersistenceService
- Returns:
- the
PlatformTransactionManager
-
identifyDefaultEntityManager
public jakarta.persistence.EntityManager identifyDefaultEntityManager(TargetModeType targetModeType) Description copied from interface:PersistenceService
Identifies the defaultEntityManager
for the given targetModeTypeNOTE: This assumes that the
EntityManager
is based on blPU- Specified by:
identifyDefaultEntityManager
in interfacePersistenceService
- Returns:
- the
EntityManager
-
getEntityManager
Description copied from interface:PersistenceService
Gathers theEntityManager
from the provided managerMap- Specified by:
getEntityManager
in interfacePersistenceService
- Returns:
- the
EntityManager
-
identifyDefaultTransactionManager
public org.springframework.transaction.PlatformTransactionManager identifyDefaultTransactionManager(TargetModeType targetModeType) Description copied from interface:PersistenceService
Identifies the defaultPlatformTransactionManager
for the given targetModeTypeNOTE: This assumes that the
PlatformTransactionManager
is based on blPU- Specified by:
identifyDefaultTransactionManager
in interfacePersistenceService
- Returns:
- the
PlatformTransactionManager
-
getTransactionManager
public org.springframework.transaction.PlatformTransactionManager getTransactionManager(Map<String, Object> managerMap) Description copied from interface:PersistenceService
Gathers thePlatformTransactionManager
from the provided managerMap- Specified by:
getTransactionManager
in interfacePersistenceService
- Returns:
- the
PlatformTransactionManager
-
getCeilingImplClassFromEntityManagers
Description copied from interface:PersistenceService
Retrieves 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:
getCeilingImplClassFromEntityManagers
in interfacePersistenceService
-
buildManagerCacheKey
-
buildManagerCacheKey
-
buildEJB3ConfigDaoCacheKey
-
getManagedClassName
-
getClassForName
-