org.ofbiz.entity.datasource
Class MemoryHelper

java.lang.Object
  extended by org.ofbiz.entity.datasource.MemoryHelper
All Implemented Interfaces:
GenericHelper

public class MemoryHelper
extends java.lang.Object
implements 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).


Field Summary
static java.lang.String module
           
 
Constructor Summary
MemoryHelper(java.lang.String helperName)
           
 
Method Summary
 void checkDataSource(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages, boolean addMissing)
          Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server
static void clearCache()
           
 GenericValue create(GenericPK primaryKey)
           
 GenericValue create(GenericValue value)
          Creates a Entity in the form of a GenericValue and write it to the database
 java.util.List<GenericValue> findAllByPrimaryKeys(java.util.List<GenericPK> primaryKeys)
          Find a number of Generic Value objects by their Primary Keys, all at once
 java.util.List<GenericValue> findByAnd(ModelEntity modelEntity, java.util.List<EntityCondition> expressions, java.util.List<java.lang.String> orderBy)
           
 java.util.List<GenericValue> findByAnd(ModelEntity modelEntity, java.util.Map<java.lang.String,java.lang.Object> fields, java.util.List<java.lang.String> orderBy)
           
 java.util.List<GenericValue> findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, java.util.Collection<java.lang.String> fieldsToSelect, java.util.List<java.lang.String> orderBy)
           
 java.util.List<GenericValue> findByLike(ModelEntity modelEntity, java.util.Map<java.lang.String,java.lang.Object> fields, java.util.List<java.lang.String> orderBy)
           
 java.util.List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, java.util.List<java.lang.String> orderBy)
           
 java.util.List<GenericValue> findByOr(ModelEntity modelEntity, java.util.List<EntityCondition> expressions, java.util.List<java.lang.String> orderBy)
           
 java.util.List<GenericValue> findByOr(ModelEntity modelEntity, java.util.Map<java.lang.String,java.lang.Object> fields, java.util.List<java.lang.String> orderBy)
           
 GenericValue findByPrimaryKey(GenericPK primaryKey)
          Find a Generic Entity by its Primary Key
 GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, java.util.Set<java.lang.String> keys)
          Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)
 long findCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions)
           
 EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, java.util.Collection<java.lang.String> fieldsToSelect, java.util.List<java.lang.String> orderBy, EntityFindOptions findOptions)
          Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.
 java.lang.String getHelperName()
          Gets the name of the server configuration that corresponds to this helper
 int removeAll(java.util.List<GenericPK> dummyPKs)
           
 int removeByAnd(ModelEntity modelEntity, java.util.Map<java.lang.String,java.lang.Object> fields)
           
 int removeByCondition(ModelEntity modelEntity, EntityCondition condition)
          Removes/deletes Generic Entity records found by all the specified condition
 int removeByPrimaryKey(GenericPK primaryKey)
          Remove a Generic Entity corresponding to the primaryKey
 int store(GenericValue value)
          Store the Entity from the GenericValue to the persistent store
 int storeAll(java.util.List<GenericValue> values)
           
 int storeByCondition(ModelEntity modelEntity, java.util.Map<java.lang.String,? extends java.lang.Object> fieldsToSet, EntityCondition condition)
          Stores a group of values in a single query
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

module

public static final java.lang.String module
Constructor Detail

MemoryHelper

public MemoryHelper(java.lang.String helperName)
Method Detail

clearCache

public static void clearCache()

getHelperName

public java.lang.String getHelperName()
Description copied from interface: GenericHelper
Gets the name of the server configuration that corresponds to this helper

Specified by:
getHelperName in interface GenericHelper
Returns:
server configuration name

create

public GenericValue create(GenericValue value)
                    throws GenericEntityException
Description copied from interface: GenericHelper
Creates a Entity in the form of a GenericValue and write it to the database

Specified by:
create in interface GenericHelper
Returns:
GenericValue instance containing the new instance
Throws:
GenericEntityException

create

public GenericValue create(GenericPK primaryKey)
                    throws GenericEntityException
Throws:
GenericEntityException

findByPrimaryKey

public GenericValue findByPrimaryKey(GenericPK primaryKey)
                              throws GenericEntityException
Description copied from interface: GenericHelper
Find a Generic Entity by its Primary Key

Specified by:
findByPrimaryKey in interface GenericHelper
Parameters:
primaryKey - The primary key to find by.
Returns:
The GenericValue corresponding to the primaryKey
Throws:
GenericEntityException

findByPrimaryKeyPartial

public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey,
                                            java.util.Set<java.lang.String> keys)
                                     throws GenericEntityException
Description copied from interface: GenericHelper
Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)

Specified by:
findByPrimaryKeyPartial in interface GenericHelper
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 java.util.List<GenericValue> findAllByPrimaryKeys(java.util.List<GenericPK> primaryKeys)
                                                  throws GenericEntityException
Description copied from interface: GenericHelper
Find a number of Generic Value objects by their Primary Keys, all at once

Specified by:
findAllByPrimaryKeys in interface GenericHelper
Parameters:
primaryKeys - A List of primary keys to find by.
Returns:
List of GenericValue objects corresponding to the passed primaryKey objects
Throws:
GenericEntityException

removeByPrimaryKey

public int removeByPrimaryKey(GenericPK primaryKey)
                       throws GenericEntityException
Description copied from interface: GenericHelper
Remove a Generic Entity corresponding to the primaryKey

Specified by:
removeByPrimaryKey in interface GenericHelper
Parameters:
primaryKey - The primary key of the entity to remove.
Returns:
int representing number of rows effected by this operation
Throws:
GenericEntityException

findByAnd

public java.util.List<GenericValue> findByAnd(ModelEntity modelEntity,
                                              java.util.Map<java.lang.String,java.lang.Object> fields,
                                              java.util.List<java.lang.String> orderBy)
                                       throws GenericEntityException
Throws:
GenericEntityException

findByAnd

public java.util.List<GenericValue> findByAnd(ModelEntity modelEntity,
                                              java.util.List<EntityCondition> expressions,
                                              java.util.List<java.lang.String> orderBy)
                                       throws GenericEntityException
Throws:
GenericEntityException

findByLike

public java.util.List<GenericValue> findByLike(ModelEntity modelEntity,
                                               java.util.Map<java.lang.String,java.lang.Object> fields,
                                               java.util.List<java.lang.String> orderBy)
                                        throws GenericEntityException
Throws:
GenericEntityException

findByOr

public java.util.List<GenericValue> findByOr(ModelEntity modelEntity,
                                             java.util.Map<java.lang.String,java.lang.Object> fields,
                                             java.util.List<java.lang.String> orderBy)
                                      throws GenericEntityException
Throws:
GenericEntityException

findByOr

public java.util.List<GenericValue> findByOr(ModelEntity modelEntity,
                                             java.util.List<EntityCondition> expressions,
                                             java.util.List<java.lang.String> orderBy)
                                      throws GenericEntityException
Throws:
GenericEntityException

findByCondition

public java.util.List<GenericValue> findByCondition(ModelEntity modelEntity,
                                                    EntityCondition entityCondition,
                                                    java.util.Collection<java.lang.String> fieldsToSelect,
                                                    java.util.List<java.lang.String> orderBy)
                                             throws GenericEntityException
Throws:
GenericEntityException

findByMultiRelation

public java.util.List<GenericValue> findByMultiRelation(GenericValue value,
                                                        ModelRelation modelRelationOne,
                                                        ModelEntity modelEntityOne,
                                                        ModelRelation modelRelationTwo,
                                                        ModelEntity modelEntityTwo,
                                                        java.util.List<java.lang.String> orderBy)
                                                 throws GenericEntityException
Specified by:
findByMultiRelation in interface GenericHelper
Throws:
GenericEntityException

findListIteratorByCondition

public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity,
                                                      EntityCondition whereEntityCondition,
                                                      EntityCondition havingEntityCondition,
                                                      java.util.Collection<java.lang.String> fieldsToSelect,
                                                      java.util.List<java.lang.String> orderBy,
                                                      EntityFindOptions findOptions)
                                               throws GenericEntityException
Description copied from interface: GenericHelper
Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.

Specified by:
findListIteratorByCondition in interface GenericHelper
Parameters:
modelEntity - The ModelEntity of the Entity as defined in the entity XML file
whereEntityCondition - 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 retreived
orderBy - The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
findOptions - 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 BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION.
Throws:
GenericEntityException

findCountByCondition

public long findCountByCondition(ModelEntity modelEntity,
                                 EntityCondition whereEntityCondition,
                                 EntityCondition havingEntityCondition,
                                 EntityFindOptions findOptions)
                          throws GenericEntityException
Specified by:
findCountByCondition in interface GenericHelper
Throws:
GenericEntityException

removeByAnd

public int removeByAnd(ModelEntity modelEntity,
                       java.util.Map<java.lang.String,java.lang.Object> fields)
                throws GenericEntityException
Throws:
GenericEntityException

removeByCondition

public int removeByCondition(ModelEntity modelEntity,
                             EntityCondition condition)
                      throws GenericEntityException
Description copied from interface: GenericHelper
Removes/deletes Generic Entity records found by all the specified condition

Specified by:
removeByCondition in interface GenericHelper
Parameters:
modelEntity - The ModelEntity of the Entity as defined in the entity XML file
condition - The condition that restricts the list of removed values
Returns:
int representing number of rows effected by this operation
Throws:
GenericEntityException

storeByCondition

public int storeByCondition(ModelEntity modelEntity,
                            java.util.Map<java.lang.String,? extends java.lang.Object> fieldsToSet,
                            EntityCondition condition)
                     throws GenericEntityException
Description copied from interface: GenericHelper
Stores a group of values in a single query

Specified by:
storeByCondition in interface GenericHelper
Parameters:
modelEntity - The ModelEntity of the Entity as defined in the entity XML file
fieldsToSet - The fields of the named entity to set in the database
condition - The condition that restricts the list of updated values
Returns:
int representing number of rows effected by this operation
Throws:
GenericEntityException

store

public int store(GenericValue value)
          throws GenericEntityException
Description copied from interface: GenericHelper
Store the Entity from the GenericValue to the persistent store

Specified by:
store in interface GenericHelper
Parameters:
value - GenericValue instance containing the entity
Returns:
int representing number of rows effected by this operation
Throws:
GenericEntityException

storeAll

public int storeAll(java.util.List<GenericValue> values)
             throws GenericEntityException
Throws:
GenericEntityException

removeAll

public int removeAll(java.util.List<GenericPK> dummyPKs)
              throws GenericEntityException
Throws:
GenericEntityException

checkDataSource

public void checkDataSource(java.util.Map<java.lang.String,ModelEntity> modelEntities,
                            java.util.List<java.lang.String> messages,
                            boolean addMissing)
                     throws GenericEntityException
Description copied from interface: GenericHelper
Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server

Specified by:
checkDataSource in interface GenericHelper
Parameters:
modelEntities - Map of entityName names and ModelEntity values
messages - List to put any result messages in
addMissing - Flag indicating whether or not to add missing entities and fields on the server
Throws:
GenericEntityException