Package org.ofbiz.core.entity
Class MemoryHelper
java.lang.Object
org.ofbiz.core.entity.MemoryHelper
- All Implemented Interfaces:
GenericHelper
Partial GenericHelper implementation that is entirely memory-based,
to be used for simple unit testing (can't do anything beyond searches
for primary keys, findByOr and findByAnd).
- Author:
- Pat Lightbody
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckDataSource(Map<String, ? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing) Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the serverstatic voidintcount(ModelEntity modelEntity, String fieldName, EntityCondition entityCondition, EntityFindOptions findOptions) Returns the count of the results that matches the specified conditioncreate(GenericValue value) Creates a Entity in the form of a GenericValue and write it to the databasefindAllByPrimaryKeys(List<? extends GenericPK> primaryKeys) Find a number of Generic Value objects by their Primary Keys, all at oncefindByAnd(ModelEntity modelEntity, List<? extends EntityCondition> expressions, List<String> orderBy) Finds Generic Entity records by all of the specified fields (ie: combined using AND)findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.findByLike(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) findByOr(ModelEntity modelEntity, List<? extends EntityCondition> expressions, List<String> orderBy) Finds Generic Entity records by all of the specified fields (ie: combined using OR)findByPrimaryKey(GenericPK primaryKey) Find a Generic Entity by its Primary KeyfindByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) The memory implementation does the *minimum* that it can to allow tests to work.Gets the name of the server configuration that corresponds to this helperintremoveAll(List<? extends GenericEntity> dummyPKs) Remove the Entities from the List from the persistent store.intremoveByAnd(ModelEntity modelEntity, Map<String, ?> fields) Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)intremoveByCondition(ModelEntity modelEntity, EntityCondition whereCondition) Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)intremoveByPrimaryKey(GenericPK primaryKey) Remove a Generic Entity corresponding to the primaryKeyintstore(GenericValue value) Store the Entity from the GenericValue to the persistent storeintstoreAll(List<? extends GenericValue> values) Store the Entities from the List GenericValue instances to the persistent store.transform(ModelEntity modelEntity, EntityCondition entityCondition, List<String> orderBy, String lockField, Transformation transformation) Applies the given transformation to any entities matching the given condition.
-
Constructor Details
-
MemoryHelper
-
-
Method Details
-
clearCache
public static void clearCache() -
getHelperName
Description copied from interface:GenericHelperGets the name of the server configuration that corresponds to this helper- Specified by:
getHelperNamein interfaceGenericHelper- Returns:
- server configuration name
-
create
Description copied from interface:GenericHelperCreates a Entity in the form of a GenericValue and write it to the database- Specified by:
createin interfaceGenericHelper- Returns:
- GenericValue instance containing the new instance
- Throws:
GenericEntityException
-
create
- Throws:
GenericEntityException
-
findByPrimaryKey
Description copied from interface:GenericHelperFind a Generic Entity by its Primary Key- Specified by:
findByPrimaryKeyin interfaceGenericHelper- Parameters:
primaryKey- The primary key to find by.- Returns:
- The GenericValue corresponding to the primaryKey
- Throws:
GenericEntityException
-
findByPrimaryKeyPartial
public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException Description copied from interface:GenericHelperFind a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)- Specified by:
findByPrimaryKeyPartialin interfaceGenericHelper- Parameters:
primaryKey- The primary key to find by.keys- The keys, or names, of the values to retrieve; only these values will be retrieved- Returns:
- The GenericValue corresponding to the primaryKey
- Throws:
GenericEntityException
-
findAllByPrimaryKeys
public List<GenericValue> findAllByPrimaryKeys(List<? extends GenericPK> primaryKeys) throws GenericEntityException Description copied from interface:GenericHelperFind a number of Generic Value objects by their Primary Keys, all at once- Specified by:
findAllByPrimaryKeysin interfaceGenericHelper- Parameters:
primaryKeys- A List of primary keys to find by.- Returns:
- List of GenericValue objects corresponding to the passed primaryKey objects
- Throws:
GenericEntityException
-
removeByPrimaryKey
Description copied from interface:GenericHelperRemove a Generic Entity corresponding to the primaryKey- Specified by:
removeByPrimaryKeyin interfaceGenericHelper- Parameters:
primaryKey- The primary key of the entity to remove.- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
findByAnd
public List<GenericValue> findByAnd(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityExceptionDescription copied from interface:GenericHelperFinds Generic Entity records by all of the specified fields (ie: combined using AND)- Specified by:
findByAndin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filefields- The fields of the named entity to query by with their corresponging valuesorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending- Returns:
- List of GenericValue instances that match the query
- Throws:
GenericEntityException
-
findByAnd
public List<GenericValue> findByAnd(ModelEntity modelEntity, List<? extends EntityCondition> expressions, List<String> orderBy) throws GenericEntityException - Throws:
GenericEntityException
-
findByLike
public List<GenericValue> findByLike(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityException- Throws:
GenericEntityException
-
findByOr
public List<GenericValue> findByOr(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityExceptionDescription copied from interface:GenericHelperFinds Generic Entity records by all of the specified fields (ie: combined using OR)- Specified by:
findByOrin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filefields- The fields of the named entity to query by with their corresponging valuesorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending- Returns:
- List of GenericValue instances that match the query
- Throws:
GenericEntityException
-
findByOr
public List<GenericValue> findByOr(ModelEntity modelEntity, List<? extends EntityCondition> expressions, List<String> orderBy) throws GenericEntityException - Throws:
GenericEntityException
-
findByCondition
public List<GenericValue> findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException Description copied from interface:GenericHelperFinds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.- Specified by:
findByConditionin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML fileentityCondition- The EntityCondition object that specifies how to constrain this queryfieldsToSelect- The fields of the named entity to get from the database; if empty or null all fields will be retreivedorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending- Returns:
- List of GenericValue objects representing the result
- Throws:
GenericEntityException
-
findByMultiRelation
public List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException - Specified by:
findByMultiRelationin interfaceGenericHelper- Throws:
GenericEntityException
-
findListIteratorByCondition
public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException The memory implementation does the *minimum* that it can to allow tests to work. In particular it will return *all* values for a particular entity from this method.- Specified by:
findListIteratorByConditionin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filewhereEntityCondition- The EntityCondition object that specifies how to constrain this query before any groupings are done (if this is a view entity with group-by aliases)havingEntityCondition- The EntityCondition object that specifies how to constrain this query after any groupings are done (if this is a view entity with group-by aliases)fieldsToSelect- The fields of the named entity to get from the database; if empty or null all fields will be retreivedorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descendingfindOptions- An instance of EntityFindOptions that specifies advanced query options. See the EntityFindOptions JavaDoc for more details.- Returns:
- EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BECAUSE IT WILL MAINTAIN A DATABASE CONNECTION.
- Throws:
GenericEntityException
-
removeByAnd
Description copied from interface:GenericHelperRemoves/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)- Specified by:
removeByAndin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filefields- The fields of the named entity to query by with their corresponging values- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
removeByCondition
public int removeByCondition(ModelEntity modelEntity, EntityCondition whereCondition) throws GenericEntityException Description copied from interface:GenericHelperRemoves/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)- Specified by:
removeByConditionin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filewhereCondition- The EntityCondition object that specifies how to constrain this query- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
store
Description copied from interface:GenericHelperStore the Entity from the GenericValue to the persistent store- Specified by:
storein interfaceGenericHelper- Parameters:
value- GenericValue instance containing the entity- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
storeAll
Description copied from interface:GenericHelperStore the Entities from the List GenericValue instances to the persistent store. This is different than the normal store method in that the store method only does an update, while the storeAll method checks to see if each entity exists, then either does an insert or an update as appropriate. These updates all happen in one transaction, so they will either all succeed or all fail, if the data source supports transactions. This is just like to othersToStore feature of the GenericEntity on a create or store.- Specified by:
storeAllin interfaceGenericHelper- Parameters:
values- List of GenericValue instances containing the entities to store- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
removeAll
Description copied from interface:GenericHelperRemove the Entities from the List from the persistent store.
The List contains GenericEntity objects, can be either GenericPK or GenericValue.
If a certain entity contains a complete primary key, the entity in the datasource corresponding to that primary key will be removed, this is like a removeByPrimary Key.
On the other hand, if a certain entity is an incomplete or non primary key, if will behave like the removeByAnd method.
These updates all happen in one transaction, so they will either all succeed or all fail, if the data source supports transactions.- Specified by:
removeAllin interfaceGenericHelper- Parameters:
dummyPKs- List of GenericEntity instances containing the entities or by and fields to remove- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
checkDataSource
public void checkDataSource(Map<String, ? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing) throws GenericEntityExceptionDescription copied from interface:GenericHelperCheck the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server- Specified by:
checkDataSourcein interfaceGenericHelper- Parameters:
modelEntities- Map of entityName names and ModelEntity valuesmessages- Collection to put any result messages inaddMissing- Flag indicating whether or not to add missing entities and fields on the server- Throws:
GenericEntityException
-
count
public int count(ModelEntity modelEntity, String fieldName, EntityCondition entityCondition, EntityFindOptions findOptions) throws GenericEntityException Description copied from interface:GenericHelperReturns the count of the results that matches the specified condition- Specified by:
countin interfaceGenericHelper- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filefieldName- The field of the named entity to count, if null this is equivalent to count(*)entityCondition- The EntityCondition object that specifies how to constrain this query The expressions to use for the lookup, each consisting of at least a field name, an EntityOperator, and a value to compare tofindOptions- An instance of EntityFindOptions that specifies advanced query options. The only option that is used is distinct, in which case a select (distinct fieldname) is issued.If you issue a distinct without a fieldName it will be ignored as select count (distinct *) makes no sense
- Returns:
- the number of rows that match the query
- Throws:
GenericEntityException
-
transform
public List<GenericValue> transform(ModelEntity modelEntity, EntityCondition entityCondition, List<String> orderBy, String lockField, Transformation transformation) throws GenericEntityException Description copied from interface:GenericHelperApplies the given transformation to any entities matching the given condition.- Specified by:
transformin interfaceGenericHelper- Parameters:
modelEntity- the type of entity to transform (required)entityCondition- the condition that selects the entities to transform (null means transform all)orderBy- the order in which the entities should be selected for updating (null means no ordering)lockField- the entity field to use for optimistic locking; the value of this field will be read between the SELECT and the UPDATE to determine whether another process has updated one of the target records in the meantime; if so, the transformation will be reapplied and another UPDATE attemptedtransformation- the transformation to apply (required)- Returns:
- the transformed entities in the order they were selected (never null)
- Throws:
GenericEntityException
-