Package org.apache.ofbiz.entity.util
Class EntityUtil
java.lang.Object
org.apache.ofbiz.entity.util.EntityUtil
Helper methods when dealing with Entities, especially ones that follow certain conventions
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
delDatedInclusionEntity
(Delegator delegator, String entityName, Map<String, ? extends Object> search) static void
delDatedInclusionEntity
(Delegator delegator, String entityName, Map<String, ? extends Object> search, Timestamp now) static String
For a entityName return the primary keys path that identify it like entityName/pkValue1/pkValue2/../pkValueNstatic String
For a entityName return the primary keys path that identify it like entityName/pkValue1/pkValue2/../pkValueNstatic <T extends GenericEntity>
List<T>filterByAnd
(List<T> values, List<? extends EntityCondition> exprs) returns the values that match all of the exprs in liststatic <T extends GenericEntity>
List<T>filterByAnd
(List<T> values, Map<String, ? extends Object> fields) returns the values that match the values in fieldsstatic <T extends GenericEntity>
List<T>filterByCondition
(List<T> values, EntityCondition condition) static <T extends GenericEntity>
List<T>filterByDate
(List<T> datedValues) returns the values that are currently active.static <T extends GenericEntity>
List<T>filterByDate
(List<T> datedValues, boolean allAreSame) returns the values that are currently active.static <T extends GenericEntity>
List<T>filterByDate
(List<T> datedValues, Timestamp moment) returns the values that are active at the moment.static <T extends GenericEntity>
List<T>filterByDate
(List<T> datedValues, Timestamp moment, String fromDateName, String thruDateName, boolean allAreSame) returns the values that are active at the moment.static <T extends GenericEntity>
List<T>filterByDate
(List<T> datedValues, Date moment) returns the values that are active at the moment.static <T extends GenericEntity>
List<T>filterByOr
(List<T> values, List<? extends EntityCondition> exprs) returns the values that match any of the exprs in liststatic <T extends GenericEntity>
List<T>filterOutByCondition
(List<T> values, EntityCondition condition) static List<GenericValue>
findDatedInclusionEntity
(Delegator delegator, String entityName, Map<String, ? extends Object> search) static List<GenericValue>
findDatedInclusionEntity
(Delegator delegator, String entityName, Map<String, ? extends Object> search, Timestamp now) static <T> List<T>
getFieldListFromEntityList
(List<GenericValue> genericValueList, String fieldName, boolean distinct) static <T> List<T>
getFieldListFromEntityListIterator
(EntityListIterator genericValueEli, String fieldName, boolean distinct) static EntityCondition
static EntityCondition
getFilterByDateExpr
(String fromDateName, String thruDateName) static EntityCondition
getFilterByDateExpr
(Timestamp moment) static EntityCondition
getFilterByDateExpr
(Timestamp moment, String fromDateName, String thruDateName) static EntityCondition
getFilterByDateExpr
(Date moment) static GenericValue
getFirst
(Collection<GenericValue> values) static GenericValue
getFirst
(List<GenericValue> values) static GenericValue
getOnly
(Collection<GenericValue> values) static GenericValue
getOnly
(List<GenericValue> values) static PagedList<GenericValue>
getPagedList
(EntityListIterator iter, int viewIndex, int viewSize) getPkValuesMapFromPath
(ModelEntity modelEntity, String path) Form a entityName and primary keys path convert it to a Map contains all pkValue : entityName/pkValue1/pkValue2/../pkValueN -> [pkName1: pkValue1, pkName2, pkValue2, ..., pkNameN: pkValueN]static List<GenericValue>
getRelated
(String relationName, List<GenericValue> values) Deprecated.static List<GenericValue>
getRelated
(String relationName, Map<String, ? extends Object> fields, List<GenericValue> values, boolean useCache) static List<GenericValue>
getSelectedFieldValueListFromEntityList
(Delegator delegator, List<GenericValue> values, Set<String> selected) returns the values with the matching selected fieldsstatic int
getStartIndexFromViewIndex
(int viewIndex, int viewSize) static boolean
Returnstrue
if multi-tenant has been enabled.static boolean
isValueActive
(GenericValue datedValue, Timestamp moment) static boolean
isValueActive
(GenericValue datedValue, Timestamp moment, String fromDateName, String thruDateName) static <T extends GenericEntity>
List<T>localizedOrderBy
(Collection<T> values, List<String> orderBy, Locale locale) returns the values in the order specified after with localized valuemakeFields
(V... args) static GenericValue
newDatedInclusionEntity
(Delegator delegator, String entityName, Map<String, ? extends Object> search) static GenericValue
newDatedInclusionEntity
(Delegator delegator, String entityName, Map<String, ? extends Object> find, Timestamp now) static <T extends GenericEntity>
List<T>orderBy
(Collection<T> values, List<String> orderBy) returns the values in the order specified
-
Method Details
-
makeFields
-
getFirst
-
getFirst
-
getOnly
-
getOnly
-
getFilterByDateExpr
-
getFilterByDateExpr
-
getFilterByDateExpr
-
getFilterByDateExpr
-
getFilterByDateExpr
public static EntityCondition getFilterByDateExpr(Timestamp moment, String fromDateName, String thruDateName) -
filterByDate
returns the values that are currently active.- Parameters:
datedValues
- GenericValue's that have "fromDate" and "thruDate" fields- Returns:
- List of GenericValue's that are currently active
-
filterByDate
public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues, boolean allAreSame) returns the values that are currently active.- Parameters:
datedValues
- GenericValue's that have "fromDate" and "thruDate" fieldsallAreSame
- Specifies whether all values in the List are of the same entity; this can help speed things up a fair amount since we only have to see if the from and thru date fields are valid once- Returns:
- List of GenericValue's that are currently active
-
filterByDate
returns the values that are active at the moment.- Parameters:
datedValues
- GenericValue's that have "fromDate" and "thruDate" fieldsmoment
- the moment in question- Returns:
- List of GenericValue's that are active at the moment
-
filterByDate
returns the values that are active at the moment.- Parameters:
datedValues
- GenericValue's that have "fromDate" and "thruDate" fieldsmoment
- the moment in question- Returns:
- List of GenericValue's that are active at the moment
-
filterByDate
public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues, Timestamp moment, String fromDateName, String thruDateName, boolean allAreSame) returns the values that are active at the moment.- Parameters:
datedValues
- GenericValue's that have "fromDate" and "thruDate" fieldsmoment
- the moment in questionallAreSame
- Specifies whether all values in the List are of the same entity; this can help speed things up a fair amount since we only have to see if the from and thru date fields are valid once- Returns:
- List of GenericValue's that are active at the moment
-
isValueActive
-
isValueActive
public static boolean isValueActive(GenericValue datedValue, Timestamp moment, String fromDateName, String thruDateName) -
filterByAnd
public static <T extends GenericEntity> List<T> filterByAnd(List<T> values, Map<String, ? extends Object> fields) returns the values that match the values in fields- Parameters:
values
- List of GenericValuesfields
- the field-name/value pairs that must match- Returns:
- List of GenericValue's that match the values in fields
-
filterByAnd
public static <T extends GenericEntity> List<T> filterByAnd(List<T> values, List<? extends EntityCondition> exprs) returns the values that match all of the exprs in list- Parameters:
values
- List of GenericValuesexprs
- the expressions that must validate to true- Returns:
- List of GenericValue's that match the values in fields
-
filterByOr
public static <T extends GenericEntity> List<T> filterByOr(List<T> values, List<? extends EntityCondition> exprs) returns the values that match any of the exprs in list- Parameters:
values
- List of GenericValuesexprs
- the expressions that must validate to true- Returns:
- List of GenericValue's that match the values in fields
-
localizedOrderBy
public static <T extends GenericEntity> List<T> localizedOrderBy(Collection<T> values, List<String> orderBy, Locale locale) returns the values in the order specified after with localized value- Parameters:
values
- List of GenericValuesorderBy
- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descendinglocale
- Locale use to retrieve localized value- Returns:
- List of GenericValue's in the proper order
-
orderBy
returns the values in the order specified- Parameters:
values
- List of GenericValuesorderBy
- 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's in the proper order
-
getRelated
@Deprecated public static List<GenericValue> getRelated(String relationName, List<GenericValue> values) throws GenericEntityException Deprecated.- Throws:
GenericEntityException
-
getRelated
public static List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> fields, List<GenericValue> values, boolean useCache) throws GenericEntityException- Throws:
GenericEntityException
-
filterByCondition
public static <T extends GenericEntity> List<T> filterByCondition(List<T> values, EntityCondition condition) -
filterOutByCondition
public static <T extends GenericEntity> List<T> filterOutByCondition(List<T> values, EntityCondition condition) -
findDatedInclusionEntity
public static List<GenericValue> findDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search) throws GenericEntityException- Throws:
GenericEntityException
-
findDatedInclusionEntity
public static List<GenericValue> findDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search, Timestamp now) throws GenericEntityException- Throws:
GenericEntityException
-
newDatedInclusionEntity
public static GenericValue newDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search) throws GenericEntityException- Throws:
GenericEntityException
-
newDatedInclusionEntity
public static GenericValue newDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> find, Timestamp now) throws GenericEntityException- Throws:
GenericEntityException
-
delDatedInclusionEntity
public static void delDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search) throws GenericEntityException- Throws:
GenericEntityException
-
delDatedInclusionEntity
public static void delDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search, Timestamp now) throws GenericEntityException- Throws:
GenericEntityException
-
getFieldListFromEntityList
public static <T> List<T> getFieldListFromEntityList(List<GenericValue> genericValueList, String fieldName, boolean distinct) -
getFieldListFromEntityListIterator
public static <T> List<T> getFieldListFromEntityListIterator(EntityListIterator genericValueEli, String fieldName, boolean distinct) -
getSelectedFieldValueListFromEntityList
public static List<GenericValue> getSelectedFieldValueListFromEntityList(Delegator delegator, List<GenericValue> values, Set<String> selected) returns the values with the matching selected fields- Parameters:
delegator
-values
- List of GenericValuesselected
- the lit of selected fields- Returns:
- List of GenericValue's with only selected fields
-
isMultiTenantEnabled
public static boolean isMultiTenantEnabled()Returnstrue
if multi-tenant has been enabled.Multi-tenant features are enabled by setting the
multitenant
property ingeneral.properties
to "Y". -
getStartIndexFromViewIndex
public static int getStartIndexFromViewIndex(int viewIndex, int viewSize) - Parameters:
viewIndex
-viewSize
-- Returns:
- the calculated start index based on viewIndex and viewSize
- See Also:
-
getPagedList
public static PagedList<GenericValue> getPagedList(EntityListIterator iter, int viewIndex, int viewSize) throws GenericEntityException - Parameters:
iter
- EntityListIteratorviewIndex
-viewSize
-- Returns:
- PagedList object with a subset of data items from EntityListIterator based on viewIndex and viewSize
- Throws:
GenericEntityException
- See Also:
-
entityToPath
public static String entityToPath(Delegator delegator, String entityName, Map<String, Object> context) For a entityName return the primary keys path that identify it like entityName/pkValue1/pkValue2/../pkValueN- Parameters:
delegator
-entityName
-context
-- Returns:
-
entityToPath
For a entityName return the primary keys path that identify it like entityName/pkValue1/pkValue2/../pkValueN- Parameters:
gv
-- Returns:
-
getPkValuesMapFromPath
public static Map<String,Object> getPkValuesMapFromPath(ModelEntity modelEntity, String path) throws GenericEntityException Form a entityName and primary keys path convert it to a Map contains all pkValue : entityName/pkValue1/pkValue2/../pkValueN -> [pkName1: pkValue1, pkName2, pkValue2, ..., pkNameN: pkValueN]- Parameters:
modelEntity
-path
-- Returns:
- Throws:
GenericEntityException
-
getRelated(String, Map, List, boolean)