📄 genericdelegator.java
字号:
pksPerHelper.put(helperName, pks);
}
pks.add(curPK);
}
}
Iterator helperIter = pksPerHelper.entrySet().iterator();
while (helperIter.hasNext()) {
Map.Entry curEntry = (Map.Entry) helperIter.next();
String helperName = (String) curEntry.getKey();
GenericHelper helper = GenericHelperFactory.getHelper(helperName);
List values = helper.findAllByPrimaryKeys((List) curEntry.getValue());
this.putAllInPrimaryKeyCache(values);
results.addAll(values);
}
return results;
}
/** Finds all Generic entities
*@param entityName The Name of the Entity as defined in the entity XML file
*@return List containing all Generic entities
*/
public List findAll(String entityName) throws GenericEntityException {
return this.findByAnd(entityName, new HashMap(), null);
}
/** Finds all Generic entities
*@param entityName The Name of the Entity as defined in the entity XML file
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@return List containing all Generic entities
*/
public List findAll(String entityName, List orderBy) throws GenericEntityException {
return this.findByAnd(entityName, new HashMap(), orderBy);
}
/** Finds all Generic entities, looking first in the cache
*@param entityName The Name of the Entity as defined in the entity XML file
*@return List containing all Generic entities
*/
public List findAllCache(String entityName) throws GenericEntityException {
return this.findAllCache(entityName, null);
}
/** Finds all Generic entities, looking first in the cache; uses orderBy for lookup, but only keys results on the entityName and fields
*@param entityName The Name of the Entity as defined in the entity XML file
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@return List containing all Generic entities
*/
public List findAllCache(String entityName, List orderBy) throws GenericEntityException {
GenericValue dummyValue = makeValue(entityName, null);
Map ecaEventMap = this.getEcaEntityEventMap(entityName);
this.evalEcaRules(EntityEcaHandler.EV_CACHE_CHECK, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
List lst = this.getFromAllCache(entityName);
if (lst == null) {
lst = findAll(entityName, orderBy);
if (lst != null) {
this.evalEcaRules(EntityEcaHandler.EV_CACHE_PUT, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
this.putInAllCache(entityName, lst);
}
return lst;
} else {
return EntityUtil.orderBy(lst, orderBy);
}
}
/** Finds Generic Entity records by all of the specified fields (ie: combined using AND)
* @param entityName The Name of the Entity as defined in the entity XML file
* @param fields The fields of the named entity to query by with their corresponging values
* @return List of GenericValue instances that match the query
*/
public List findByAnd(String entityName, Map fields) throws GenericEntityException {
return this.findByAnd(entityName, fields, null);
}
/** Finds Generic Entity records by all of the specified fields (ie: combined using OR)
* @param entityName The Name of the Entity as defined in the entity XML file
* @param fields The fields of the named entity to query by with their corresponging values
* @return List of GenericValue instances that match the query
*/
public List findByOr(String entityName, Map fields) throws GenericEntityException {
return this.findByOr(entityName, fields, null);
}
/** Finds Generic Entity records by all of the specified fields (ie: combined using AND)
* @param entityName The Name of the Entity as defined in the entity XML file
* @param fields The fields of the named entity to query by with their corresponging values
* @param orderBy The fields of the named entity to order the query by;
* optionally add a " ASC" for ascending or " DESC" for descending
* @return List of GenericValue instances that match the query
*/
public List findByAnd(String entityName, Map fields, List orderBy) throws GenericEntityException {
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericValue dummyValue = new GenericValue(modelEntity, fields);
this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_FIND, dummyValue, null, false, false);
return findByAnd(modelEntity, fields, orderBy);
}
public List findByAnd(ModelEntity modelEntity, Map fields, List orderBy) throws GenericEntityException {
GenericValue dummyValue = new GenericValue(modelEntity);
Map ecaEventMap = this.getEcaEntityEventMap(modelEntity.getEntityName());
GenericHelper helper = getEntityHelper(modelEntity);
if (fields != null && !modelEntity.areFields(fields.keySet())) {
throw new GenericModelException("At least one of the passed fields is not valid: " + fields.keySet().toString());
}
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
List list = null;
list = helper.findByAnd(modelEntity, fields, orderBy);
absorbList(list);
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
return list;
}
/** Finds Generic Entity records by all of the specified fields (ie: combined using OR)
* @param entityName The Name of the Entity as defined in the entity XML file
* @param fields The fields of the named entity to query by with their corresponging values
* @param orderBy The fields of the named entity to order the query by;
* optionally add a " ASC" for ascending or " DESC" for descending
* @return List of GenericValue instances that match the query
*/
public List findByOr(String entityName, Map fields, List orderBy) throws GenericEntityException {
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericValue dummyValue = new GenericValue(modelEntity);
Map ecaEventMap = this.getEcaEntityEventMap(modelEntity.getEntityName());
this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_FIND, dummyValue, null, false, false);
GenericHelper helper = getEntityHelper(entityName);
if (fields != null && !modelEntity.areFields(fields.keySet())) {
throw new GenericModelException("[GenericDelegator.findByOr] At least of the passed fields is not valid: " + fields.keySet().toString());
}
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
List list = null;
list = helper.findByOr(modelEntity, fields, orderBy);
absorbList(list);
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
return list;
}
/** Finds Generic Entity records by all of the specified fields (ie: combined using AND), looking first in the cache; uses orderBy for lookup, but only keys results on the entityName and fields
*@param entityName The Name of the Entity as defined in the entity XML file
*@param fields The fields of the named entity to query by with their corresponging values
*@return List of GenericValue instances that match the query
*/
public List findByAndCache(String entityName, Map fields) throws GenericEntityException {
return this.findByAndCache(entityName, fields, null);
}
/** Finds Generic Entity records by all of the specified fields (ie: combined using AND), looking first in the cache; uses orderBy for lookup, but only keys results on the entityName and fields
*@param entityName The Name of the Entity as defined in the entity XML file
*@param fields The fields of the named entity to query by with their corresponging values
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@return List of GenericValue instances that match the query
*/
public List findByAndCache(String entityName, Map fields, List orderBy) throws GenericEntityException {
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericValue dummyValue = new GenericValue(modelEntity);
Map ecaEventMap = this.getEcaEntityEventMap(modelEntity.getEntityName());
this.evalEcaRules(EntityEcaHandler.EV_CACHE_CHECK, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
List lst = this.getFromAndCache(modelEntity, fields);
if (lst == null) {
lst = findByAnd(modelEntity, fields, orderBy);
if (lst != null) {
this.evalEcaRules(EntityEcaHandler.EV_CACHE_PUT, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
this.putInAndCache(modelEntity, fields, lst);
}
return lst;
} else {
// automatically re-order the elements if this didn't come from the datasource directly
return EntityUtil.orderBy(lst, orderBy);
}
}
/** Finds Generic Entity records by all of the specified expressions (ie: combined using AND)
*@param entityName The Name of the Entity as defined in the entity XML file
*@param expressions The expressions to use for the lookup, each consisting of at least a field name, an EntityOperator, and a value to compare to
*@return List of GenericValue instances that match the query
*/
public List findByAnd(String entityName, List expressions) throws GenericEntityException {
EntityConditionList ecl = new EntityConditionList(expressions, EntityOperator.AND);
return findByCondition(entityName, ecl, null, null);
}
/** Finds Generic Entity records by all of the specified expressions (ie: combined using AND)
*@param entityName The Name of the Entity as defined in the entity XML file
*@param expressions The expressions to use for the lookup, each consisting of at least a field name, an EntityOperator, and a value to compare to
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@return List of GenericValue instances that match the query
*/
public List findByAnd(String entityName, List expressions, List orderBy) throws GenericEntityException {
EntityConditionList ecl = new EntityConditionList(expressions, EntityOperator.AND);
return findByCondition(entityName, ecl, null, orderBy);
}
/** Finds Generic Entity records by all of the specified expressions (ie: combined using OR)
*@param entityName The Name of the Entity as defined in the entity XML file
*@param expressions The expressions to use for the lookup, each consisting of at least a field name, an EntityOperator, and a value to compare to
*@return List of GenericValue instances that match the query
*/
public List findByOr(String entityName, List expressions) throws GenericEntityException {
EntityConditionList ecl = new EntityConditionList(expressions, EntityOperator.OR);
return findByCondition(entityName, ecl, null, null);
}
/** Finds Generic Entity records by all of the specified expressions (ie: combined using OR)
*@param entityName The Name of the Entity as defined in the entity XML file
*@param expressions The expressions to use for the lookup, each consisting of at least a field name, an EntityOperator, and a value to compare to
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@return List of GenericValue instances that match the query
*/
public List findByOr(String entityName, List expressions, List orderBy) throws GenericEntityException {
EntityConditionList ecl = new EntityConditionList(expressions, EntityOperator.OR);
return findByCondition(entityName, ecl, null, orderBy);
}
public List findByLike(String entityName, Map fields) throws GenericEntityException {
return findByLike(entityName, fields, null);
}
public List findByLike(String entityName, Map fields, List orderBy) throws GenericEntityException {
List likeExpressions = new LinkedList();
if (fields != null) {
Iterator fieldEntries = fields.entrySet().iterator();
while (fieldEntries.hasNext()) {
Map.Entry fieldEntry = (Map.Entry) fieldEntries.next();
likeExpressions.add(new EntityExpr(fieldEntry.getKey(), EntityOperator.LIKE, fieldEntry.getValue()));
}
}
EntityConditionList ecl = new EntityConditionList(likeExpressions, EntityOperator.AND);
return findByCondition(entityName, ecl, null, orderBy);
}
/** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.
*@param entityName The Name of the Entity as defined in the entity model XML file
*@param entityCondition The EntityCondition object that specifies how to constrain this query
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -