Class DynamicEntityDaoImpl
java.lang.Object
org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl
- All Implemented Interfaces:
DynamicEntityDao
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
@Component("blDynamicEntityDao")
@Scope("prototype")
public class DynamicEntityDaoImpl
extends Object
implements DynamicEntityDao, org.springframework.context.ApplicationContextAware
- Author:
- jfischer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContext
protected BasicFieldMetadataProvider
protected int
protected FieldMetadataProvider
protected DynamicDaoHelper
protected EntityConfiguration
protected FieldManager
protected List<FieldMetadataProvider>
protected long
protected Metadata
protected static final Map<String,
Map<String, FieldMetadata>> Lifetime cache for the existence of DynamicEntityDaoImpl that just stores how many properties we have cached in METADATA_CACHE over the lifetime of the application.protected jakarta.persistence.EntityManager
protected boolean
Whether or not we should useMETADATA_CACHE_SIZES
in the normal runtime of the application -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addClassToTree
(Class<?> clazz, ClassTree tree) protected void
applyForeignKeyPrecedence
(ForeignKey foreignField, ForeignKey[] additionalForeignFields, Map<String, FieldMetadata> mergedProperties) protected void
applyIncludesAndExcludes
(String[] includeFields, String[] excludeFields, String prefix, Boolean isParentExcluded, Map<String, FieldMetadata> mergedProperties) protected void
buildBasicProperty
(Field field, Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<org.hibernate.mapping.Property> componentProperties, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String propertyName, org.hibernate.type.Type type, boolean propertyForeignKey, int additionalForeignKeyIndexPosition, Boolean isComponentPrefix, String parentPrefix) protected void
buildComponentProperties
(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, org.hibernate.type.Type type, Class<?> returnedClass, List<Class<?>> parentClasses, Boolean isParentExcluded, String prefix, String parentPrefix) protected void
buildEntityProperties
(Map<String, FieldMetadata> fields, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, Class<?> returnedClass, Class<?> targetClass, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) protected void
buildProperties
(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<org.hibernate.mapping.Property> componentProperties, Map<String, FieldMetadata> fields, List<String> propertyNames, List<org.hibernate.type.Type> propertyTypes, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, Boolean isComponentPrefix, String parentPrefix) protected void
buildPropertiesFromPolymorphicEntities
(Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, Map<String, FieldMetadata> mergedProperties, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) void
clear()
protected void
createClassTreeFromAnnotation
(Class<?> clazz, ClassTree myTree) org.hibernate.Criteria
createCriteria
(Class<?> entityClass) void
detach
(Serializable entity) protected Boolean
determineExclusionForField
(List<Class<?>> parentClasses, Class<?> targetClass, Field testField) protected int
findAdditionalForeignKeyIndex
(ForeignKey[] additionalForeignFields, String prefix, String propertyName) void
flush()
Field[]
getAllFields
(Class<?> targetClass) Class<?>[]
getAllPolymorphicEntitiesFromCeiling
(Class<?> ceilingClass) Class<?>[]
getAllPolymorphicEntitiesFromCeiling
(Class<?> ceilingClass, boolean includeUnqualifiedPolymorphicEntities) protected String
getCacheKey
(String ceilingEntityFullyQualifiedClassname, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, Class<?> clazz, String configurationKey, Boolean isParentExcluded) Class<?>
getCeilingImplClass
(String className) getClassTree
(Class<?>[] polymorphicClasses) getClassTreeFromCeiling
(Class<?> ceilingClass) getFieldManager
(boolean cleanFieldManager) getIdentifier
(Object entity) Retrieve the identifier from the Hibernate entity (the entity must reside in the current session)protected Field
getIdField
(Class<?> clazz) getIdMetadata
(Class<?> entityClass) Class<?>
getImplClass
(String className) getMergedProperties
(Class<?> cls) Convenience method that obtains all of theMergedPropertyType.PRIMARY
properties for a given class.getMergedProperties
(String ceilingEntityFullyQualifiedClassname, Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String prefix) protected Map<String,
FieldMetadata> getMergedPropertiesRecursively
(String ceilingEntityFullyQualifiedClassname, Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) org.hibernate.mapping.PersistentClass
getPersistentClass
(String targetClassName) Get the Hibernate PersistentClass instance associated with the fully-qualified class name.protected Map<String,
FieldMetadata> getPropertiesForEntityClass
(Class<?> targetClass, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) getPropertiesForPrimitiveClass
(String propertyName, String friendlyPropertyName, Class<?> targetClass, Class<?> parentClass, MergedPropertyType mergedPropertyType) getPropertyNames
(Class<?> entityClass) List<org.hibernate.type.Type>
getPropertyTypes
(Class<?> entityClass) getSimpleMergedProperties
(String entityName, PersistencePerspective persistencePerspective) jakarta.persistence.EntityManager
Class<?>[]
getSuperClassHierarchy
(Class<?> ceilingEntity) getTabAndGroupMetadata
(Class<?>[] entities, ClassMetadata cmd) Class<?>[]
getUpDownInheritance
(Class<?> testClass) protected boolean
isExcludeClassFromPolymorphism
(Class<?> clazz) protected boolean
isForeignKey
(FieldMetadata fieldMetadata) <T> T
merge
(T entity) protected String
<T> T
persist
(T entity) readOtherEntitiesWithPropertyValue
(Serializable instance, String propertyName, String value) Returns a list of ids for entities that share the property value of the entity passed invoid
refresh
(Serializable entity) void
void
remove
(Serializable entity) void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) void
setDefaultFieldMetadataProvider
(FieldMetadataProvider defaultFieldMetadataProvider) void
setDynamicDaoHelper
(DynamicDaoHelper dynamicDaoHelper) void
setEntityConfiguration
(EntityConfiguration entityConfiguration) protected void
setExcludedBasedOnShowIfProperty
(FieldMetadata fieldMetadata) void
setFieldMetadataProviders
(List<FieldMetadataProvider> fieldMetadataProviders) void
setMetadata
(Metadata metadata) protected void
setOriginatingFieldForForeignKey
(String propertyName, String key, FieldMetadata fieldMetadata) void
setStandardEntityManager
(jakarta.persistence.EntityManager entityManager) Class<?>[]
sortEntities
(Class<?> ceilingClass, List<Class<?>> entities) protected boolean
testForeignProperty
(ForeignKey foreignField, String prefix, String propertyName) protected Boolean
testMultiLevelEmbeddableRecursion
(String prefix, Boolean isComponentPrefix, String parentPrefix, String propertyName) testPropertyInclusion
(FieldMetadata presentationAttribute) protected Boolean
testPropertyRecursion
(String prefix, List<Class<?>> parentClasses, String propertyName, Class<?> targetClass, String ceilingEntityFullyQualifiedClassname, Boolean isComponentPrefix, String parentPrefix) protected Boolean
testStandardPropertyRecursion
(String prefix, List<Class<?>> parentClasses, String propertyName, Class<?> targetClass, String ceilingEntityFullyQualifiedClassname, Boolean isComponentPrefix) boolean
useCache()
-
Field Details
-
METADATA_CACHE
-
METADATA_CACHE_SIZES
Lifetime cache for the existence of DynamicEntityDaoImpl that just stores how many properties we have cached in METADATA_CACHE over the lifetime of the application. This should survive evictions from METADATA_CACHE because it is for the purpose of diagnosing when we store different property counts in METADATA_CACHE as a result of cache eviction -
standardEntityManager
protected jakarta.persistence.EntityManager standardEntityManager -
metadata
-
entityConfiguration
-
fieldMetadataProviders
-
defaultFieldMetadataProvider
-
basicFieldMetadataProvider
-
propertyConfigurations
-
dynamicDaoHelper
-
cacheEntityMetaDataTtl
@Value("${cache.entity.dao.metadata.ttl}") protected int cacheEntityMetaDataTtl -
validateMetadataCacheSizes
@Value("${validate.metadata.cache.sizes:false}") protected boolean validateMetadataCacheSizesWhether or not we should useMETADATA_CACHE_SIZES
in the normal runtime of the application -
lastCacheFlushTime
protected long lastCacheFlushTime -
applicationContext
protected org.springframework.context.ApplicationContext applicationContext -
fieldManager
-
-
Constructor Details
-
DynamicEntityDaoImpl
public DynamicEntityDaoImpl()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
createCriteria
- Specified by:
createCriteria
in interfaceDynamicEntityDao
-
persist
public <T> T persist(T entity) - Specified by:
persist
in interfaceDynamicEntityDao
-
find
- Specified by:
find
in interfaceDynamicEntityDao
-
merge
public <T> T merge(T entity) - Specified by:
merge
in interfaceDynamicEntityDao
-
flush
public void flush()- Specified by:
flush
in interfaceDynamicEntityDao
-
detach
- Specified by:
detach
in interfaceDynamicEntityDao
-
refresh
- Specified by:
refresh
in interfaceDynamicEntityDao
-
retrieve
- Specified by:
retrieve
in interfaceDynamicEntityDao
-
remove
- Specified by:
remove
in interfaceDynamicEntityDao
-
clear
public void clear()- Specified by:
clear
in interfaceDynamicEntityDao
-
getPersistentClass
Description copied from interface:DynamicEntityDao
Get the Hibernate PersistentClass instance associated with the fully-qualified class name. Will return null if no persistent class is associated with this name.- Specified by:
getPersistentClass
in interfaceDynamicEntityDao
- Returns:
- The PersistentClass instance
-
useCache
public boolean useCache()- Specified by:
useCache
in interfaceDynamicEntityDao
-
getAllPolymorphicEntitiesFromCeiling
- Specified by:
getAllPolymorphicEntitiesFromCeiling
in interfaceDynamicEntityDao
-
getAllPolymorphicEntitiesFromCeiling
public Class<?>[] getAllPolymorphicEntitiesFromCeiling(Class<?> ceilingClass, boolean includeUnqualifiedPolymorphicEntities) - Specified by:
getAllPolymorphicEntitiesFromCeiling
in interfaceDynamicEntityDao
-
getUpDownInheritance
- Specified by:
getUpDownInheritance
in interfaceDynamicEntityDao
-
getImplClass
- Specified by:
getImplClass
in interfaceDynamicEntityDao
-
getCeilingImplClass
- Specified by:
getCeilingImplClass
in interfaceDynamicEntityDao
-
readOtherEntitiesWithPropertyValue
public List<Long> readOtherEntitiesWithPropertyValue(Serializable instance, String propertyName, String value) Description copied from interface:DynamicEntityDao
Returns a list of ids for entities that share the property value of the entity passed in- Specified by:
readOtherEntitiesWithPropertyValue
in interfaceDynamicEntityDao
- Returns:
-
getIdentifier
Description copied from interface:DynamicEntityDao
Retrieve the identifier from the Hibernate entity (the entity must reside in the current session)- Specified by:
getIdentifier
in interfaceDynamicEntityDao
- Returns:
-
getIdField
-
sortEntities
-
addClassToTree
-
createClassTreeFromAnnotation
-
getClassTree
- Specified by:
getClassTree
in interfaceDynamicEntityDao
-
getClassTreeFromCeiling
- Specified by:
getClassTreeFromCeiling
in interfaceDynamicEntityDao
-
getSimpleMergedProperties
public Map<String,FieldMetadata> getSimpleMergedProperties(String entityName, PersistencePerspective persistencePerspective) - Specified by:
getSimpleMergedProperties
in interfaceDynamicEntityDao
-
getMergedProperties
Description copied from interface:DynamicEntityDao
Convenience method that obtains all of theMergedPropertyType.PRIMARY
properties for a given class. Delegates toDynamicEntityDao.getMergedProperties(String, Class[], ForeignKey, String[], ForeignKey[], MergedPropertyType, Boolean, String[], String[], String, String)
- Specified by:
getMergedProperties
in interfaceDynamicEntityDao
- Returns:
-
getMergedProperties
public Map<String,FieldMetadata> getMergedProperties(String ceilingEntityFullyQualifiedClassname, Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String prefix) - Specified by:
getMergedProperties
in interfaceDynamicEntityDao
-
getMergedPropertiesRecursively
protected Map<String,FieldMetadata> getMergedPropertiesRecursively(String ceilingEntityFullyQualifiedClassname, Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) -
applyForeignKeyPrecedence
protected void applyForeignKeyPrecedence(ForeignKey foreignField, ForeignKey[] additionalForeignFields, Map<String, FieldMetadata> mergedProperties) -
applyIncludesAndExcludes
-
pad
-
getCacheKey
protected String getCacheKey(String ceilingEntityFullyQualifiedClassname, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, Class<?> clazz, String configurationKey, Boolean isParentExcluded) -
buildPropertiesFromPolymorphicEntities
protected void buildPropertiesFromPolymorphicEntities(Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, Map<String, FieldMetadata> mergedProperties, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) -
refreshDecimalDefaultValue
-
getAllFields
- Specified by:
getAllFields
in interfaceDynamicEntityDao
-
getPropertiesForPrimitiveClass
public Map<String,FieldMetadata> getPropertiesForPrimitiveClass(String propertyName, String friendlyPropertyName, Class<?> targetClass, Class<?> parentClass, MergedPropertyType mergedPropertyType) - Specified by:
getPropertiesForPrimitiveClass
in interfaceDynamicEntityDao
-
getIdMetadata
- Specified by:
getIdMetadata
in interfaceDynamicEntityDao
-
getPropertyNames
- Specified by:
getPropertyNames
in interfaceDynamicEntityDao
-
getPropertyTypes
- Specified by:
getPropertyTypes
in interfaceDynamicEntityDao
-
getTabAndGroupMetadata
- Specified by:
getTabAndGroupMetadata
in interfaceDynamicEntityDao
-
getSuperClassHierarchy
-
getPropertiesForEntityClass
protected Map<String,FieldMetadata> getPropertiesForEntityClass(Class<?> targetClass, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) -
buildProperties
protected void buildProperties(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<org.hibernate.mapping.Property> componentProperties, Map<String, FieldMetadata> fields, List<String> propertyNames, List<org.hibernate.type.Type> propertyTypes, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, Boolean isComponentPrefix, String parentPrefix) -
testPropertyInclusion
-
setExcludedBasedOnShowIfProperty
-
testPropertyRecursion
-
testMultiLevelEmbeddableRecursion
-
testStandardPropertyRecursion
-
determineExclusionForField
-
buildBasicProperty
protected void buildBasicProperty(Field field, Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<org.hibernate.mapping.Property> componentProperties, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String propertyName, org.hibernate.type.Type type, boolean propertyForeignKey, int additionalForeignKeyIndexPosition, Boolean isComponentPrefix, String parentPrefix) -
testForeignProperty
-
findAdditionalForeignKeyIndex
protected int findAdditionalForeignKeyIndex(ForeignKey[] additionalForeignFields, String prefix, String propertyName) -
buildEntityProperties
protected void buildEntityProperties(Map<String, FieldMetadata> fields, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, Class<?> returnedClass, Class<?> targetClass, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) -
isForeignKey
-
setOriginatingFieldForForeignKey
protected void setOriginatingFieldForForeignKey(String propertyName, String key, FieldMetadata fieldMetadata) -
buildComponentProperties
protected void buildComponentProperties(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, org.hibernate.type.Type type, Class<?> returnedClass, List<Class<?>> parentClasses, Boolean isParentExcluded, String prefix, String parentPrefix) -
getStandardEntityManager
public jakarta.persistence.EntityManager getStandardEntityManager()- Specified by:
getStandardEntityManager
in interfaceDynamicEntityDao
-
setStandardEntityManager
public void setStandardEntityManager(jakarta.persistence.EntityManager entityManager) - Specified by:
setStandardEntityManager
in interfaceDynamicEntityDao
-
getFieldManager
- Specified by:
getFieldManager
in interfaceDynamicEntityDao
-
getFieldManager
- Specified by:
getFieldManager
in interfaceDynamicEntityDao
-
getEntityConfiguration
- Specified by:
getEntityConfiguration
in interfaceDynamicEntityDao
-
setEntityConfiguration
- Specified by:
setEntityConfiguration
in interfaceDynamicEntityDao
-
getMetadata
- Specified by:
getMetadata
in interfaceDynamicEntityDao
-
setMetadata
- Specified by:
setMetadata
in interfaceDynamicEntityDao
-
getFieldMetadataProviders
-
setFieldMetadataProviders
-
getDefaultFieldMetadataProvider
- Specified by:
getDefaultFieldMetadataProvider
in interfaceDynamicEntityDao
-
setDefaultFieldMetadataProvider
-
isExcludeClassFromPolymorphism
-
getDynamicDaoHelper
- Specified by:
getDynamicDaoHelper
in interfaceDynamicEntityDao
-
setDynamicDaoHelper
-