Class BasicPersistenceModule
java.lang.Object
org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule
- All Implemented Interfaces:
DataFormatProvider,PersistenceModule,RecordHelper,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
AdornedTargetListPersistenceModule,MapStructurePersistenceModule
@Primary
@Component("blBasicPersistenceModule")
@Scope("prototype")
public class BasicPersistenceModule
extends Object
implements PersistenceModule, RecordHelper, org.springframework.context.ApplicationContextAware
- Author:
- jfischer
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected org.springframework.context.ApplicationContextprotected CriteriaTranslatorprotected FieldPersistenceProviderprotected EntityValidatorServiceprotected BasicPersistenceModuleExtensionManagerprotected FetchWrapperprotected List<FieldPersistenceProvider>protected LocaleServicestatic final Stringprotected PersistenceManagerprotected List<PopulateValueRequestValidator>protected RestrictionFactoryprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(PersistencePackage persistencePackage) add(PersistencePackage persistencePackage, boolean includeRealEntityObject) protected voidaddTranslationSearchIfNeeded(CriteriaTransferObject cto, Map<String, FieldMetadata> mergedProperties) protected booleanattemptToPopulateValue(Property property, FieldManager fieldManager, Serializable instance, Boolean setId, BasicFieldMetadata metadata, Entity entity, String value) protected List<TQRestriction>buildSpecialRestrictions(String specialExpression, List<FilterMapping> filterMappings) Generate EQUALS restrictions for any filter property specified on the entity member of the collection field in the @Embeddable objectprotected List<TQRestriction>buildStandardRestrictions(FieldPath embeddedCollectionPath, List<FilterMapping> filterMappings) Generate LIKE or EQUALS restrictions for any filter property specified on the root entity (not the collection field in the @Embeddable object)protected voidcleanupFailedPersistenceAttempt(Serializable instance) createPopulatedInstance(Serializable instance, Entity entity, Map<String, FieldMetadata> unfilteredProperties, Boolean setId) Delegates to the overloaded method with validateUnsubmittedProperties set to true.createPopulatedInstance(Serializable instance, Entity entity, Map<String, FieldMetadata> unfilteredProperties, Boolean setId, Boolean validateUnsubmittedProperties) Populates a Hibernate entity instance based on the values from entity (the DTO representation of instance) and the metadata from mergedProperties.voidextractProperties(Class<?>[] inheritanceLine, Map<MergedPropertyType, Map<String, FieldMetadata>> mergedProperties, List<Property> properties) protected voidextractPropertiesFromMetadata(Class<?>[] inheritanceLine, Map<String, FieldMetadata> mergedProperties, List<Property> properties, Boolean isHiddenOverride, MergedPropertyType type) protected voidextractPropertiesFromPersistentEntity(Map<String, FieldMetadata> mergedProperties, Serializable entity, List<Property> props, String[] customCriteria) fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) protected Map<String,FieldMetadata> filterOutCollectionMetadata(Map<String, FieldMetadata> metadata) formatValue(Object value) Formats a aw value from an entity into its string representation used by the system.protected Class<?>getBasicBroadleafType(SupportedFieldType fieldType) getCompatibleModule(OperationType operationType) getFieldManager(boolean cleanFieldManger) getFilterMappings(PersistencePerspective persistencePerspective, CriteriaTransferObject cto, String ceilingEntityFullyQualifiedClassname, Map<String, FieldMetadata> mergedUnfilteredProperties) getFilterMappings(PersistencePerspective persistencePerspective, CriteriaTransferObject cto, String ceilingEntityFullyQualifiedClassname, Map<String, FieldMetadata> mergedUnfilteredProperties, RestrictionFactory customRestrictionFactory) getIdPropertyName(String entityClass) For the fully qualified entity class name, find the primary key property name.getIdPropertyName(Map<String, FieldMetadata> mergedUnfilteredProperties) protected Class<?>getMapFieldType(Serializable instance, FieldManager fieldManager, Property property) getMaxValue(String ceilingEntity, List<FilterMapping> filterMappings, String maxField) getMergedProperties(PersistencePackage persistencePackage, CriteriaTransferObject cto) getPersistentRecords(String ceilingEntity, List<FilterMapping> filterMappings, Integer firstResult, Integer maxResults) Retrieve a paged list of persistent entity instances given some basic metadata and restrictions.getPersistentRecords(FetchRequest fetchRequest) Retrieve a paged list of persistent entity instances given some basic metadata and restrictions.getPrimaryKey(Entity entity, Map<String, FieldMetadata> mergedUnfilteredProperties) getRecord(Class<?> ceilingEntityClass, PersistencePerspective persistencePerspective, Serializable record) getRecord(Map<String, FieldMetadata> primaryMergedProperties, Serializable record, Map<String, FieldMetadata> alternateMergedProperties, String pathToTargetObject) Entity[]getRecords(Class<?> ceilingEntityClass, PersistencePerspective persistencePerspective, List<? extends Serializable> records) Entity[]getRecords(Map<String, FieldMetadata> primaryMergedProperties, List<? extends Serializable> records) Entity[]getRecords(Map<String, FieldMetadata> primaryUnfilteredMergedProperties, List<? extends Serializable> records, Map<String, FieldMetadata> alternateUnfilteredMergedProperties, String pathToTargetObject) Entity[]getRecords(Map<String, FieldMetadata> primaryUnfilteredMergedProperties, List<? extends Serializable> records, Map<String, FieldMetadata> alternateUnfilteredMergedProperties, String pathToTargetObject, String[] customCriteria) Entity[]getRecords(FetchExtractionRequest fetchExtractionRequest) Based on retrieved persistent entities and entity metadata, construct data transfer object instances to represent these records to the caller.getSimpleMergedProperties(String entityName, PersistencePerspective persistencePerspective) protected TypedQueryBuildergetSpecialCaseQueryBuilder(FieldPath embeddedCollectionPath, List<FilterMapping> filterMappings, String collectionClass) Use an alternate approach to generating a fetch query for a collection located inside of an @Embeddable object.getStringValueFromGetter(Serializable instance, String propertyName) Returns a string representation of the field on the given instance specified by the property name.getTotalRecords(String ceilingEntity, List<FilterMapping> filterMappings) Retrieve a total count of persistent entities given some basic metadata and restrictionsgetTotalRecords(FetchRequest fetchRequest) Retrieve a total count of persistent entities given some basic metadata and restrictionsvoidinit()booleanisCompatible(OperationType operationType) protected booleanisLate(BasicFieldMetadata metadata, String name) voidremove(PersistencePackage persistencePackage) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetCriteriaTranslator(CriteriaTranslator criteriaTranslator) voidsetDefaultFieldPersistenceProvider(FieldPersistenceProvider defaultFieldPersistenceProvider) voidsetEntityValidatorService(EntityValidatorService entityValidatorService) voidsetFieldPersistenceProviders(List<FieldPersistenceProvider> fieldPersistenceProviders) voidsetPersistenceManager(PersistenceManager persistenceManager) voidsetRestrictionFactory(RestrictionFactory restrictionFactory) update(PersistencePackage persistencePackage) update(PersistencePackage persistencePackage, boolean includeRealEntityObject) protected EntityResultupdate(PersistencePackage persistencePackage, Object primaryKey, boolean includeRealEntity) voidupdateMergedProperties(PersistencePackage persistencePackage, Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties) booleanvalidate(Entity entity, Serializable populatedInstance, Map<String, FieldMetadata> mergedProperties) Delegates to the overloaded method with validateUnsubmittedProperties set to true.booleanvalidate(Entity entity, Serializable populatedInstance, Map<String, FieldMetadata> mergedProperties, boolean validateUnsubmittedProperties) Validates theEntitybased on the validators associated with each property
-
Field Details
-
MAIN_ENTITY_NAME_PROPERTY
- See Also:
-
ALTERNATE_ID_PROPERTY
- See Also:
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext -
persistenceManager
-
entityValidatorService
-
fieldPersistenceProviders
-
populateValidators
-
defaultFieldPersistenceProvider
-
criteriaTranslator
-
restrictionFactory
-
extensionManager
-
fetchWrapper
-
useTranslationSearch
@Value("${use.translation.search:false}") protected boolean useTranslationSearch -
localeService
-
-
Constructor Details
-
BasicPersistenceModule
public BasicPersistenceModule()
-
-
Method Details
-
init
@PostConstruct public void init() -
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
isCompatible
- Specified by:
isCompatiblein interfacePersistenceModule
-
getFieldManager
- Specified by:
getFieldManagerin interfaceRecordHelper
-
getFieldManager
- Specified by:
getFieldManagerin interfaceRecordHelper
-
getDecimalFormatter
- Specified by:
getDecimalFormatterin interfaceDataFormatProvider
-
getSimpleDateFormatter
- Specified by:
getSimpleDateFormatterin interfaceDataFormatProvider
-
filterOutCollectionMetadata
-
getBasicBroadleafType
-
createPopulatedInstance
public Serializable createPopulatedInstance(Serializable instance, Entity entity, Map<String, FieldMetadata> unfilteredProperties, Boolean setId) throws ValidationExceptionDescription copied from interface:RecordHelperDelegates to the overloaded method with validateUnsubmittedProperties set to true.- Specified by:
createPopulatedInstancein interfaceRecordHelper- Throws:
ValidationException- See Also:
-
createPopulatedInstance
public Serializable createPopulatedInstance(Serializable instance, Entity entity, Map<String, FieldMetadata> unfilteredProperties, Boolean setId, Boolean validateUnsubmittedProperties) throws ValidationExceptionDescription copied from interface:RecordHelperPopulates a Hibernate entity instance based on the values from entity (the DTO representation of instance) and the metadata from mergedProperties.
While populating instance, validation is also performed using the
EntityValidatorService. If this validation fails, then the instance is left unchanged and aValidationExceptionis thrown. In the common case, this exception bubbles up to theDynamicRemoteServicewhich catches the exception and communicates appropriately to the invoker- Specified by:
createPopulatedInstancein interfaceRecordHelpervalidateUnsubmittedProperties- if set to true, will ignore validation for properties that weren't submitted along with the entity- Returns:
- instance populated with the property values from entity according to the metadata specified in mergedProperties
- Throws:
ValidationException- if after populating instance via the values in entity thenEntityValidatorService#validate(Entity, Serializable, Map)returns false
-
isLate
-
attemptToPopulateValue
protected boolean attemptToPopulateValue(Property property, FieldManager fieldManager, Serializable instance, Boolean setId, BasicFieldMetadata metadata, Entity entity, String value) throws IllegalAccessException - Throws:
IllegalAccessException
-
getRecord
public Entity getRecord(Map<String, FieldMetadata> primaryMergedProperties, Serializable record, Map<String, FieldMetadata> alternateMergedProperties, String pathToTargetObject) - Specified by:
getRecordin interfaceRecordHelper
-
getRecord
public Entity getRecord(Class<?> ceilingEntityClass, PersistencePerspective persistencePerspective, Serializable record) - Specified by:
getRecordin interfaceRecordHelper
-
getRecords
public Entity[] getRecords(Class<?> ceilingEntityClass, PersistencePerspective persistencePerspective, List<? extends Serializable> records) - Specified by:
getRecordsin interfaceRecordHelper
-
getSimpleMergedProperties
public Map<String,FieldMetadata> getSimpleMergedProperties(String entityName, PersistencePerspective persistencePerspective) - Specified by:
getSimpleMergedPropertiesin interfaceRecordHelper
-
getRecords
public Entity[] getRecords(Map<String, FieldMetadata> primaryMergedProperties, List<? extends Serializable> records) - Specified by:
getRecordsin interfaceRecordHelper- Returns:
-
getRecords
public Entity[] getRecords(Map<String, FieldMetadata> primaryUnfilteredMergedProperties, List<? extends Serializable> records, Map<String, FieldMetadata> alternateUnfilteredMergedProperties, String pathToTargetObject) - Specified by:
getRecordsin interfaceRecordHelper- Returns:
-
getRecords
public Entity[] getRecords(Map<String, FieldMetadata> primaryUnfilteredMergedProperties, List<? extends Serializable> records, Map<String, FieldMetadata> alternateUnfilteredMergedProperties, String pathToTargetObject, String[] customCriteria) - Specified by:
getRecordsin interfaceRecordHelper- Returns:
-
getRecords
Description copied from interface:RecordHelperBased on retrieved persistent entities and entity metadata, construct data transfer object instances to represent these records to the caller.- Specified by:
getRecordsin interfaceRecordHelper- Returns:
-
extractPropertiesFromPersistentEntity
protected void extractPropertiesFromPersistentEntity(Map<String, FieldMetadata> mergedProperties, Serializable entity, List<Property> props, String[] customCriteria) -
getStringValueFromGetter
public String getStringValueFromGetter(Serializable instance, String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Description copied from interface:RecordHelperReturns a string representation of the field on the given instance specified by the property name. The propertyName should start from the root of the given instance- Specified by:
getStringValueFromGetterin interfaceRecordHelper- Returns:
- Throws:
IllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
formatValue
Description copied from interface:DataFormatProviderFormats a aw value from an entity into its string representation used by the system. For instance, this might use theDataFormatProvider.getDecimalFormatter()to ensure that BigDecimals only show 2 decimal places or dates are formatted a certain way.- Specified by:
formatValuein interfaceDataFormatProvider- Returns:
-
update
protected EntityResult update(PersistencePackage persistencePackage, Object primaryKey, boolean includeRealEntity) throws ServiceException - Throws:
ServiceException
-
getIdPropertyName
Description copied from interface:RecordHelperFor the fully qualified entity class name, find the primary key property name.- Specified by:
getIdPropertyNamein interfaceRecordHelper- Returns:
-
getIdPropertyName
-
getPrimaryKey
- Specified by:
getPrimaryKeyin interfaceRecordHelper
-
getFilterMappings
public List<FilterMapping> getFilterMappings(PersistencePerspective persistencePerspective, CriteriaTransferObject cto, String ceilingEntityFullyQualifiedClassname, Map<String, FieldMetadata> mergedUnfilteredProperties, RestrictionFactory customRestrictionFactory) - Specified by:
getFilterMappingsin interfaceRecordHelper
-
getFilterMappings
public List<FilterMapping> getFilterMappings(PersistencePerspective persistencePerspective, CriteriaTransferObject cto, String ceilingEntityFullyQualifiedClassname, Map<String, FieldMetadata> mergedUnfilteredProperties) - Specified by:
getFilterMappingsin interfaceRecordHelper
-
extractProperties
public void extractProperties(Class<?>[] inheritanceLine, Map<MergedPropertyType, Map<String, FieldMetadata>> mergedProperties, List<Property> properties) - Specified by:
extractPropertiesin interfacePersistenceModule
-
extractPropertiesFromMetadata
protected void extractPropertiesFromMetadata(Class<?>[] inheritanceLine, Map<String, FieldMetadata> mergedProperties, List<Property> properties, Boolean isHiddenOverride, MergedPropertyType type) -
updateMergedProperties
public void updateMergedProperties(PersistencePackage persistencePackage, Map<MergedPropertyType, Map<String, throws ServiceExceptionFieldMetadata>> allMergedProperties) - Specified by:
updateMergedPropertiesin interfacePersistenceModule- Throws:
ServiceException
-
update
public EntityResult update(PersistencePackage persistencePackage, boolean includeRealEntityObject) throws ServiceException - Specified by:
updatein interfaceRecordHelper- Throws:
ServiceException
-
update
- Specified by:
updatein interfacePersistenceModule- Throws:
ServiceException
-
add
- Specified by:
addin interfacePersistenceModule- Throws:
ServiceException
-
add
public EntityResult add(PersistencePackage persistencePackage, boolean includeRealEntityObject) throws ServiceException - Specified by:
addin interfaceRecordHelper- Throws:
ServiceException
-
remove
- Specified by:
removein interfacePersistenceModule- Throws:
ServiceException
-
getMergedProperties
public Map<String,FieldMetadata> getMergedProperties(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException - Throws:
ServiceException
-
fetch
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException - Specified by:
fetchin interfacePersistenceModule- Throws:
ServiceException
-
addTranslationSearchIfNeeded
protected void addTranslationSearchIfNeeded(CriteriaTransferObject cto, Map<String, FieldMetadata> mergedProperties) -
getTotalRecords
Description copied from interface:RecordHelperRetrieve a total count of persistent entities given some basic metadata and restrictions- Specified by:
getTotalRecordsin interfaceRecordHelper- Returns:
-
getTotalRecords
Description copied from interface:RecordHelperRetrieve a total count of persistent entities given some basic metadata and restrictions- Specified by:
getTotalRecordsin interfaceRecordHelper- Returns:
-
getMaxValue
public Serializable getMaxValue(String ceilingEntity, List<FilterMapping> filterMappings, String maxField) - Specified by:
getMaxValuein interfaceRecordHelper
-
getPersistentRecords
Description copied from interface:RecordHelperRetrieve a paged list of persistent entity instances given some basic metadata and restrictions.- Specified by:
getPersistentRecordsin interfaceRecordHelper- Returns:
-
getPersistentRecords
public List<Serializable> getPersistentRecords(String ceilingEntity, List<FilterMapping> filterMappings, Integer firstResult, Integer maxResults) Description copied from interface:RecordHelperRetrieve a paged list of persistent entity instances given some basic metadata and restrictions.- Specified by:
getPersistentRecordsin interfaceRecordHelper- Returns:
-
validate
public boolean validate(Entity entity, Serializable populatedInstance, Map<String, FieldMetadata> mergedProperties) Description copied from interface:RecordHelperDelegates to the overloaded method with validateUnsubmittedProperties set to true.- Specified by:
validatein interfaceRecordHelper- See Also:
-
validate
public boolean validate(Entity entity, Serializable populatedInstance, Map<String, FieldMetadata> mergedProperties, boolean validateUnsubmittedProperties) Description copied from interface:RecordHelperValidates theEntitybased on the validators associated with each property- Specified by:
validatein interfaceRecordHelper- Parameters:
entity- the instance that is attempted to be saved from. Implementers should setEntity.isValidationFailure()accordingly as a result of the validationvalidateUnsubmittedProperties- if set to true, will ignore validation for properties that weren't submitted along with the entity- Returns:
- whether or not the entity passed validation. This yields the same result as calling !
Entity.isValidationFailure()after invoking this method
-
getCompatibleModule
- Specified by:
getCompatibleModulein interfaceRecordHelper
-
getDefaultFieldPersistenceProvider
-
setDefaultFieldPersistenceProvider
public void setDefaultFieldPersistenceProvider(FieldPersistenceProvider defaultFieldPersistenceProvider) -
getFieldPersistenceProviders
-
setFieldPersistenceProviders
-
getCriteriaTranslator
-
setCriteriaTranslator
-
getEntityValidatorService
-
setEntityValidatorService
-
getRestrictionFactory
-
setRestrictionFactory
-
getPersistenceManager
-
setPersistenceManager
- Specified by:
setPersistenceManagerin interfacePersistenceModule
-
getSpecialCaseQueryBuilder
protected TypedQueryBuilder getSpecialCaseQueryBuilder(FieldPath embeddedCollectionPath, List<FilterMapping> filterMappings, String collectionClass) Use an alternate approach to generating a fetch query for a collection located inside of an @Embeddable object. Related to https://hibernate.atlassian.net/browse/HHH-8802. The alternate approach leverages HQL rather than JPA criteria, which seems to alleviate the problem.- Parameters:
embeddedCollectionPath- the path to the collection field itselffilterMappings- all the fetch restrictions for this requestcollectionClass- the type of the collection members- Returns:
- the builder capable of generating an appropriate HQL query
-
buildStandardRestrictions
protected List<TQRestriction> buildStandardRestrictions(FieldPath embeddedCollectionPath, List<FilterMapping> filterMappings) Generate LIKE or EQUALS restrictions for any filter property specified on the root entity (not the collection field in the @Embeddable object)- Parameters:
embeddedCollectionPath- the path for the collection field in the @Embeddable object - this is what caused the whole thingfilterMappings- all the fetch restrictions for this request- Returns:
- the list of restrictions on the root entity
- See Also:
-
buildSpecialRestrictions
protected List<TQRestriction> buildSpecialRestrictions(String specialExpression, List<FilterMapping> filterMappings) Generate EQUALS restrictions for any filter property specified on the entity member of the collection field in the @Embeddable object- Parameters:
specialExpression- the String representation of the path for the collection field in the @Embeddable objectfilterMappings- all the fetch restrictions for this request- Returns:
- the list of restrictions on the collection in the @Embeddable object
- See Also:
-
cleanupFailedPersistenceAttempt
- Throws:
IllegalAccessException
-
getMapFieldType
protected Class<?> getMapFieldType(Serializable instance, FieldManager fieldManager, Property property)
-