Package org.apache.ofbiz.entity.util
Class EntityUtil
- java.lang.Object
-
- org.apache.ofbiz.entity.util.EntityUtil
-
public final class EntityUtil extends java.lang.Object
Helper methods when dealing with Entities, especially ones that follow certain conventions
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
module
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
delDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search)
static void
delDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search, java.sql.Timestamp now)
static <T extends GenericEntity>
java.util.List<T>filterByAnd(java.util.List<T> values, java.util.List<? extends EntityCondition> exprs)
returns the values that match all of the exprs in liststatic <T extends GenericEntity>
java.util.List<T>filterByAnd(java.util.List<T> values, java.util.Map<java.lang.String,? extends java.lang.Object> fields)
returns the values that match the values in fieldsstatic <T extends GenericEntity>
java.util.List<T>filterByCondition(java.util.List<T> values, EntityCondition condition)
static <T extends GenericEntity>
java.util.List<T>filterByDate(java.util.List<T> datedValues)
returns the values that are currently active.static <T extends GenericEntity>
java.util.List<T>filterByDate(java.util.List<T> datedValues, boolean allAreSame)
returns the values that are currently active.static <T extends GenericEntity>
java.util.List<T>filterByDate(java.util.List<T> datedValues, java.sql.Timestamp moment)
returns the values that are active at the moment.static <T extends GenericEntity>
java.util.List<T>filterByDate(java.util.List<T> datedValues, java.sql.Timestamp moment, java.lang.String fromDateName, java.lang.String thruDateName, boolean allAreSame)
returns the values that are active at the moment.static <T extends GenericEntity>
java.util.List<T>filterByDate(java.util.List<T> datedValues, java.util.Date moment)
returns the values that are active at the moment.static <T extends GenericEntity>
java.util.List<T>filterByOr(java.util.List<T> values, java.util.List<? extends EntityCondition> exprs)
returns the values that match any of the exprs in liststatic <T extends GenericEntity>
java.util.List<T>filterOutByCondition(java.util.List<T> values, EntityCondition condition)
static java.util.List<GenericValue>
findDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search)
static java.util.List<GenericValue>
findDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search, java.sql.Timestamp now)
static <T> java.util.List<T>
getFieldListFromEntityList(java.util.List<GenericValue> genericValueList, java.lang.String fieldName, boolean distinct)
static <T> java.util.List<T>
getFieldListFromEntityListIterator(EntityListIterator genericValueEli, java.lang.String fieldName, boolean distinct)
static EntityCondition
getFilterByDateExpr()
static EntityCondition
getFilterByDateExpr(java.lang.String fromDateName, java.lang.String thruDateName)
static EntityCondition
getFilterByDateExpr(java.sql.Timestamp moment)
static EntityCondition
getFilterByDateExpr(java.sql.Timestamp moment, java.lang.String fromDateName, java.lang.String thruDateName)
static EntityCondition
getFilterByDateExpr(java.util.Date moment)
static GenericValue
getFirst(java.util.Collection<GenericValue> values)
static GenericValue
getFirst(java.util.List<GenericValue> values)
static GenericValue
getOnly(java.util.Collection<GenericValue> values)
static GenericValue
getOnly(java.util.List<GenericValue> values)
static PagedList<GenericValue>
getPagedList(EntityListIterator iter, int viewIndex, int viewSize)
static java.util.List<GenericValue>
getRelated(java.lang.String relationName, java.util.List<GenericValue> values)
Deprecated.static java.util.List<GenericValue>
getRelated(java.lang.String relationName, java.util.Map<java.lang.String,? extends java.lang.Object> fields, java.util.List<GenericValue> values, boolean useCache)
static int
getStartIndexFromViewIndex(int viewIndex, int viewSize)
static boolean
isMultiTenantEnabled()
Returnstrue
if multi-tenant has been enabled.static boolean
isValueActive(GenericValue datedValue, java.sql.Timestamp moment)
static boolean
isValueActive(GenericValue datedValue, java.sql.Timestamp moment, java.lang.String fromDateName, java.lang.String thruDateName)
static <T extends GenericEntity>
java.util.List<T>localizedOrderBy(java.util.Collection<T> values, java.util.List<java.lang.String> orderBy, java.util.Locale locale)
returns the values in the order specified after with localized valuestatic <V> java.util.Map<java.lang.String,V>
makeFields(V... args)
static GenericValue
newDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search)
static GenericValue
newDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> find, java.sql.Timestamp now)
static <T extends GenericEntity>
java.util.List<T>orderBy(java.util.Collection<T> values, java.util.List<java.lang.String> orderBy)
returns the values in the order specified
-
-
-
Method Detail
-
makeFields
@SafeVarargs public static <V> java.util.Map<java.lang.String,V> makeFields(V... args)
-
getFirst
public static GenericValue getFirst(java.util.Collection<GenericValue> values)
-
getFirst
public static GenericValue getFirst(java.util.List<GenericValue> values)
-
getOnly
public static GenericValue getOnly(java.util.Collection<GenericValue> values)
-
getOnly
public static GenericValue getOnly(java.util.List<GenericValue> values)
-
getFilterByDateExpr
public static EntityCondition getFilterByDateExpr()
-
getFilterByDateExpr
public static EntityCondition getFilterByDateExpr(java.lang.String fromDateName, java.lang.String thruDateName)
-
getFilterByDateExpr
public static EntityCondition getFilterByDateExpr(java.util.Date moment)
-
getFilterByDateExpr
public static EntityCondition getFilterByDateExpr(java.sql.Timestamp moment)
-
getFilterByDateExpr
public static EntityCondition getFilterByDateExpr(java.sql.Timestamp moment, java.lang.String fromDateName, java.lang.String thruDateName)
-
filterByDate
public static <T extends GenericEntity> java.util.List<T> filterByDate(java.util.List<T> datedValues)
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> java.util.List<T> filterByDate(java.util.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
public static <T extends GenericEntity> java.util.List<T> filterByDate(java.util.List<T> datedValues, java.util.Date moment)
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> java.util.List<T> filterByDate(java.util.List<T> datedValues, java.sql.Timestamp moment)
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> java.util.List<T> filterByDate(java.util.List<T> datedValues, java.sql.Timestamp moment, java.lang.String fromDateName, java.lang.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
public static boolean isValueActive(GenericValue datedValue, java.sql.Timestamp moment)
-
isValueActive
public static boolean isValueActive(GenericValue datedValue, java.sql.Timestamp moment, java.lang.String fromDateName, java.lang.String thruDateName)
-
filterByAnd
public static <T extends GenericEntity> java.util.List<T> filterByAnd(java.util.List<T> values, java.util.Map<java.lang.String,? extends java.lang.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> java.util.List<T> filterByAnd(java.util.List<T> values, java.util.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> java.util.List<T> filterByOr(java.util.List<T> values, java.util.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> java.util.List<T> localizedOrderBy(java.util.Collection<T> values, java.util.List<java.lang.String> orderBy, java.util.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
public static <T extends GenericEntity> java.util.List<T> orderBy(java.util.Collection<T> values, java.util.List<java.lang.String> 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 java.util.List<GenericValue> getRelated(java.lang.String relationName, java.util.List<GenericValue> values) throws GenericEntityException
Deprecated.- Throws:
GenericEntityException
-
getRelated
public static java.util.List<GenericValue> getRelated(java.lang.String relationName, java.util.Map<java.lang.String,? extends java.lang.Object> fields, java.util.List<GenericValue> values, boolean useCache) throws GenericEntityException
- Throws:
GenericEntityException
-
filterByCondition
public static <T extends GenericEntity> java.util.List<T> filterByCondition(java.util.List<T> values, EntityCondition condition)
-
filterOutByCondition
public static <T extends GenericEntity> java.util.List<T> filterOutByCondition(java.util.List<T> values, EntityCondition condition)
-
findDatedInclusionEntity
public static java.util.List<GenericValue> findDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search) throws GenericEntityException
- Throws:
GenericEntityException
-
findDatedInclusionEntity
public static java.util.List<GenericValue> findDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search, java.sql.Timestamp now) throws GenericEntityException
- Throws:
GenericEntityException
-
newDatedInclusionEntity
public static GenericValue newDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search) throws GenericEntityException
- Throws:
GenericEntityException
-
newDatedInclusionEntity
public static GenericValue newDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> find, java.sql.Timestamp now) throws GenericEntityException
- Throws:
GenericEntityException
-
delDatedInclusionEntity
public static void delDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search) throws GenericEntityException
- Throws:
GenericEntityException
-
delDatedInclusionEntity
public static void delDatedInclusionEntity(Delegator delegator, java.lang.String entityName, java.util.Map<java.lang.String,? extends java.lang.Object> search, java.sql.Timestamp now) throws GenericEntityException
- Throws:
GenericEntityException
-
getFieldListFromEntityList
public static <T> java.util.List<T> getFieldListFromEntityList(java.util.List<GenericValue> genericValueList, java.lang.String fieldName, boolean distinct)
-
getFieldListFromEntityListIterator
public static <T> java.util.List<T> getFieldListFromEntityListIterator(EntityListIterator genericValueEli, java.lang.String fieldName, boolean distinct)
-
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(org.apache.ofbiz.entity.util.EntityListIterator, int, int)
-
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:
EntityListIterator
-
-