/** 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.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); return num; }
/** 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.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. *@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.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); return num; }
/** 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.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 *@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 dummyValue = makeValue(entityName, fields); Map ecaEventMap = this.getEcaEntityEventMap(entityName); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, dummyValue, 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, dummyValue, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(entityName, fields); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByAnd(modelEntity, dummyValue.getAllFields()); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); return num; }
/** Store the Entity from the GenericValue to the persistent store *@param value GenericValue instance containing the entity *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation *@return int representing number of rows effected by this operation */ public int store(GenericValue value, boolean doCacheClear) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(value.getEntityName()); if (doCacheClear) { // always clear cache before the operation this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(value); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); int retVal = helper.store(value); // refresh the valueObject to get the new version if (value.lockEnabled()) { refresh(value, doCacheClear); } this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); return retVal; }
/** 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 dummyValue = makeValue(entityName, fields); Map ecaEventMap = this.getEcaEntityEventMap(entityName); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, dummyValue, 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, dummyValue, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(entityName, fields); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByAnd(modelEntity, dummyValue.getAllFields()); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); return num; }
/** 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 order 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 IllegalArgumentException("[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; }
/** Find a Generic Entity by its Primary Key *@param primaryKey The primary key to find by. *@return The GenericValue corresponding to the primaryKey */ public GenericValue findByPrimaryKey(GenericPK primaryKey) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(primaryKey.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(primaryKey.getEntityName()); GenericValue value = null; if (!primaryKey.isPrimaryKey()) { throw new IllegalArgumentException("[GenericDelegator.findByPrimaryKey] Passed primary key is not a valid primary key: " + primaryKey); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); try { value = helper.findByPrimaryKey(primaryKey); } catch (GenericEntityNotFoundException e) { value = null; } if (value != null) value.setDelegator(this); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); return value; }
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; }
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; }
/** Find a CACHED Generic Entity by its Primary Key *@param primaryKey The primary key to find by. *@return The GenericValue corresponding to the primaryKey */ public GenericValue findByPrimaryKeyCache(GenericPK primaryKey) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(primaryKey.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_CACHE_CHECK, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); GenericValue value = this.getFromPrimaryKeyCache(primaryKey); if (value == null) { value = findByPrimaryKey(primaryKey); if (value != null) { this.evalEcaRules(EntityEcaHandler.EV_CACHE_PUT, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); this.putInPrimaryKeyCache(primaryKey, value); } } return value; }
/** Find a CACHED Generic Entity by its Primary Key *@param primaryKey The primary key to find by. *@return The GenericValue corresponding to the primaryKey */ public GenericValue findByPrimaryKeyCache(GenericPK primaryKey) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(primaryKey.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_CACHE_CHECK, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); GenericValue value = this.getFromPrimaryKeyCache(primaryKey); if (value == null) { value = findByPrimaryKey(primaryKey); if (value != null) { this.evalEcaRules(EntityEcaHandler.EV_CACHE_PUT, EntityEcaHandler.OP_FIND, primaryKey, ecaEventMap, (ecaEventMap == null), false); this.putInPrimaryKeyCache(primaryKey, value); } } return value; }
/** 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; }
/** 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; }
/** 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 *@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 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); }
/** 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); }
/** 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, null, false, 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, null, false, false); this.putInAndCache(modelEntity, fields, lst); } } return lst; }
/** 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, null, false, 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, null, false, false); this.putInAndCache(modelEntity, fields, lst); } } return lst; }