📄 genericdelegator.java
字号:
*@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
*@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 objects representing the result
*/
public List findByCondition(String entityName, EntityCondition entityCondition, Collection fieldsToSelect, List orderBy) throws GenericEntityException {
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericValue dummyValue = new GenericValue(modelEntity);
Map ecaEventMap = this.getEcaEntityEventMap(entityName);
this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
if (entityCondition != null) entityCondition.checkCondition(modelEntity);
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
GenericHelper helper = getEntityHelper(entityName);
List list = null;
list = helper.findByCondition(modelEntity, entityCondition, fieldsToSelect, orderBy);
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
absorbList(list);
return list;
}
/** 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 before any groupings are done (if this is a view entity with group-by aliases)
*@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@return 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.
*/
public EntityListIterator findListIteratorByCondition(String entityName, EntityCondition entityCondition,
Collection fieldsToSelect, List orderBy) throws GenericEntityException {
return this.findListIteratorByCondition(entityName, entityCondition, null, fieldsToSelect, orderBy, null);
}
/** 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 XML file
*@param 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)
*@param 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)
*@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@param findOptions An instance of EntityFindOptions that specifies advanced query options. See the EntityFindOptions JavaDoc for more details.
*@return 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.
*/
public EntityListIterator findListIteratorByCondition(String entityName, EntityCondition whereEntityCondition,
EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions)
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, ecaEventMap, (ecaEventMap == null), false);
if (whereEntityCondition != null) whereEntityCondition.checkCondition(modelEntity);
if (havingEntityCondition != null) havingEntityCondition.checkCondition(modelEntity);
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
GenericHelper helper = getEntityHelper(modelEntity.getEntityName());
EntityListIterator eli = helper.findListIteratorByCondition(modelEntity, whereEntityCondition,
havingEntityCondition, fieldsToSelect, orderBy, findOptions);
eli.setDelegator(this);
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
return eli;
}
/** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.
*@param dynamicViewEntity The DynamicViewEntity to use for the entity model for this query; generally created on the fly for limited use
*@param 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)
*@param 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)
*@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
*@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
*@param findOptions An instance of EntityFindOptions that specifies advanced query options. See the EntityFindOptions JavaDoc for more details.
*@return 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.
*/
public EntityListIterator findListIteratorByCondition(DynamicViewEntity dynamicViewEntity, EntityCondition whereEntityCondition,
EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions)
throws GenericEntityException {
ModelViewEntity modelViewEntity = dynamicViewEntity.makeModelViewEntity(this);
if (whereEntityCondition != null) whereEntityCondition.checkCondition(modelViewEntity);
if (havingEntityCondition != null) havingEntityCondition.checkCondition(modelViewEntity);
GenericHelper helper = getEntityHelper(dynamicViewEntity.getOneRealEntityName());
EntityListIterator eli = helper.findListIteratorByCondition(modelViewEntity, whereEntityCondition,
havingEntityCondition, fieldsToSelect, orderBy, findOptions);
eli.setDelegator(this);
return eli;
}
public long findCountByAnd(String entityName, Map fields) throws GenericEntityException {
return findCountByCondition(entityName, new EntityFieldMap(fields, EntityOperator.AND), null);
}
public long findCountByCondition(String entityName, EntityCondition whereEntityCondition,
EntityCondition havingEntityCondition) 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, ecaEventMap, (ecaEventMap == null), false);
if (whereEntityCondition != null) whereEntityCondition.checkCondition(modelEntity);
if (havingEntityCondition != null) havingEntityCondition.checkCondition(modelEntity);
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
GenericHelper helper = getEntityHelper(modelEntity.getEntityName());
long count = helper.findCountByCondition(modelEntity, whereEntityCondition, havingEntityCondition);
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false);
return count;
}
protected void saveEntitySyncRemoveInfo(GenericEntity dummyPK) throws GenericEntityException {
// don't store remove info on entities where it is disabled
if (dummyPK.getModelEntity().getNoAutoStamp()) {
return;
}
// don't store remove info on things removed on an entity sync
if (dummyPK.getIsFromEntitySync()) {
return;
}
String serializedPK = null;
try {
serializedPK = XmlSerializer.serialize(dummyPK);
} catch (SerializeException e) {
Debug.logError(e, "Could not serialize primary key to save EntitySyncRemove", module);
} catch (FileNotFoundException e) {
Debug.logError(e, "Could not serialize primary key to save EntitySyncRemove", module);
} catch (IOException e) {
Debug.logError(e, "Could not serialize primary key to save EntitySyncRemove", module);
}
if (serializedPK != null) {
GenericValue entitySyncRemove = this.makeValue("EntitySyncRemove", null);
entitySyncRemove.set("entitySyncRemoveId", this.getNextSeqId("EntitySyncRemove"));
entitySyncRemove.set("primaryKeyRemoved", serializedPK);
entitySyncRemove.create();
}
}
/** Remove a Generic Entity corresponding to the primaryKey
*@param primaryKey The primary key of the entity to remove.
*@return int representing number of rows effected by this operation
*/
public int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException {
int retVal = this.removeByPrimaryKey(primaryKey, true);
return retVal;
}
/** Remove a Generic Entity corresponding to the primaryKey
*@param primaryKey The primary key of the entity to remove.
*@param doCacheClear boolean that specifies whether to clear cache entries for this primaryKey to be removed
*@return int representing number of rows effected by this operation
*/
public int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException {
Map ecaEventMap = this.getEcaEntityEventMap(primaryKey.getEntityName());
this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false);
GenericHelper helper = getEntityHelper(primaryKey.getEntityName());
if (doCacheClear) {
// always clear cache before the operation
this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false);
this.clearCacheLine(primaryKey);
}
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false);
int num = helper.removeByPrimaryKey(primaryKey);
this.saveEntitySyncRemoveInfo(primaryKey);
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false);
return num;
}
/** Remove a Generic Value from the database
*@param value The GenericValue object of the entity to remove.
*@return int representing number of rows effected by this operation
*/
public int removeValue(GenericValue value) throws GenericEntityException {
return this.removeValue(value, true);
}
/** Remove a Generic Value from the database
*@param value The GenericValue object of the entity to remove.
*@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed
*@return int representing number of rows effected by this operation
*/
public int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException {
Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName());
this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false);
GenericHelper helper = getEntityHelper(value.getEntityName());
if (doCacheClear) {
this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false);
this.clearCacheLine(value);
}
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false);
int num = helper.removeByPrimaryKey(value.getPrimaryKey());
this.saveEntitySyncRemoveInfo(value.getPrimaryKey());
this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false);
return num;
}
/** Removes/deletes Generic Entity records found 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 int representing number of rows effected by this operation
*/
public int removeByAnd(String entityName, Map fields) throws GenericEntityException {
return this.removeByAnd(entityName, fields, true);
}
/** Removes/deletes Generic Entity records found 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 doCacheClear boolean that specifies whether to clear cache entries for this value to be removed
*@return int representing number of rows effected by this operation
*/
public int removeByAnd(String entityName, Map fields, boolean doCacheClear) throws GenericEntityException {
GenericValue dummyPK = makeValue(entityName, null);
dummyPK.setFields(fields);
Map ecaEventMap = this.getEcaEntityEventMap(entityName);
this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, dummyPK, ecaEventMap, (ecaEventMap == null), false);
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericHelper helper = getEntityHelper(entityName);
if (doCacheClear) {
// always clear cache before the operation
this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, dummyPK, ecaEventMap, (ecaEventMap == null), false);
this.clearCacheLine(entityName, fields);
}
this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, dummyPK, ecaEventMap, (ecaEventMap == null), false
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -