Package org.ofbiz.core.entity
Interface GenericHelper
- All Known Implementing Classes:
GenericHelperDAO,MemoryHelper
public interface GenericHelper
Generic Entity Helper Class
- Author:
- David E. Jones, Chris Maurer
-
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 serverintcount(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 onceFinds 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.findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, 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) Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.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.
-
Method Details
-
getHelperName
String getHelperName()Gets the name of the server configuration that corresponds to this helper- Returns:
- server configuration name
-
create
Creates a Entity in the form of a GenericValue and write it to the database- Returns:
- GenericValue instance containing the new instance
- Throws:
GenericEntityException
-
findByPrimaryKey
Find a Generic Entity by its Primary Key- Parameters:
primaryKey- The primary key to find by.- Returns:
- The GenericValue corresponding to the primaryKey
- Throws:
GenericEntityException
-
findByPrimaryKeyPartial
GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)- 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
List<GenericValue> findAllByPrimaryKeys(List<? extends GenericPK> primaryKeys) throws GenericEntityException Find a number of Generic Value objects by their Primary Keys, all at once- Parameters:
primaryKeys- A List of primary keys to find by.- Returns:
- List of GenericValue objects corresponding to the passed primaryKey objects
- Throws:
GenericEntityException
-
removeByPrimaryKey
Remove a Generic Entity corresponding to the primaryKey- Parameters:
primaryKey- The primary key of the entity to remove.- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
findByAnd
List<GenericValue> findByAnd(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityExceptionFinds Generic Entity records by all of the specified fields (ie: combined using AND)- 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
List<GenericValue> findByOr(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityExceptionFinds Generic Entity records by all of the specified fields (ie: combined using OR)- 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
-
findByCondition
List<GenericValue> findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.- 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
List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException - Throws:
GenericEntityException
-
findListIteratorByCondition
EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.- 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
Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)- 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
int removeByCondition(ModelEntity modelEntity, EntityCondition whereCondition) throws GenericEntityException Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND)- 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
Store the Entity from the GenericValue to the persistent store- Parameters:
value- GenericValue instance containing the entity- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
storeAll
Store 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.- Parameters:
values- List of GenericValue instances containing the entities to store- Returns:
- int representing number of rows effected by this operation
- Throws:
GenericEntityException
-
removeAll
Remove 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.- 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
void checkDataSource(Map<String, ? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing) throws GenericEntityExceptionCheck the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server- 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
int count(ModelEntity modelEntity, String fieldName, EntityCondition entityCondition, EntityFindOptions findOptions) throws GenericEntityException Returns the count of the results that matches the specified condition- 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
List<GenericValue> transform(ModelEntity modelEntity, EntityCondition entityCondition, List<String> orderBy, String lockField, Transformation transformation) throws GenericEntityException Applies the given transformation to any entities matching the given condition.- 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- Since:
- 1.0.41
-