/** 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 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; }
public void putInAndCache( final String entityName, final Map<String, ?> fields, final List<? extends GenericValue> values) { checkIfLocked(); if (entityName == null || fields == null || values == null) { return; } final ModelEntity entity = getModelEntity(entityName); putInAndCache(entity, fields, values); }
public void putInAllCache(String entityName, List values) { if (entityName == null || values == null) return; ModelEntity entity = this.getModelEntity(entityName); this.putInAllCache(entity, values); }
public void putInAllCache(final String entityName, final List<? extends GenericValue> values) { checkIfLocked(); if (entityName == null || values == null) { return; } final ModelEntity entity = getModelEntity(entityName); putInAllCache(entity, values); }
/** 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; }
/** * 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 affected by this operation */ public int removeByAnd(final String entityName, final Map<String, ?> fields, final boolean doCacheClear) throws GenericEntityException { checkIfLocked(); final GenericValue dummyValue = makeValue(entityName, fields); final ModelEntity modelEntity = getModelReader().getModelEntity(entityName); final GenericHelper helper = getEntityHelper(entityName); if (doCacheClear) { // always clear cache before the operation clearCacheLine(entityName, fields); } return helper.removeByAnd(modelEntity, dummyValue.getAllFields()); }
/** * 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 by which to order the * query; optionally add " ASC" for ascending or " DESC" for descending * @return all Generic entities */ public List<GenericValue> findAllCache(final String entityName, final List<String> orderBy) throws GenericEntityException { checkIfLocked(); List<GenericValue> lst = getFromAllCache(entityName); if (lst == null) { lst = findAll(entityName, orderBy); if (lst != null) { putInAllCache(entityName, lst); } } return lst; }
/** 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); }
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; }
/** 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; }
/** Store the Entities from the List GenericValue instances to the persistent store. * <br>This is different than the normal store method in that the store method only does * an update, while the storeAll method checks to see if each entity exists, then * either does an insert or an update as appropriate. * <br>These updates all happen in one transaction, so they will either all succeed or all fail, * if the data source supports transactions. This is just like to othersToStore feature * of the GenericEntity on a create or store. *@param values List of GenericValue instances containing the entities to store *@return int representing number of rows effected by this operation */ public int storeAll(List values) throws GenericEntityException { return this.storeAll(values, true); }
public static void setupMockSequenceUtil() { String helperName = CoreFactory.getGenericDelegator().getEntityHelperName("SequenceValueItem"); ModelEntity seqEntity = CoreFactory.getGenericDelegator().getModelEntity("SequenceValueItem"); CoreFactory.getGenericDelegator().setSequencer(new MockSequenceUtil(helperName, seqEntity, "seqName", "seqId")); }
public Collection<Message> doUpgrade() throws Exception { final GenericDelegator genericDelegator = ComponentLocator.getComponent(GenericDelegator.class); final List<GenericValue> services = genericDelegator.findByAnd("ServiceConfig", EasyMap.build("clazz", OLD_CLASS_NAME)); if (services.isEmpty()) { log.info("No JiraPluginSchedulerService found. No classname fixing required"); } for (final GenericValue service : services) { service.set("clazz", NEW_CLASS_NAME); log.info("Fixing classname for service " + service.getString("name")); } genericDelegator.storeAll(services); return null; }
/** 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); }
public ModelEntity getModelEntity() { if (modelEntity == null) { if (entityName != null) modelEntity = this.getDelegator().getModelEntity(entityName); if (modelEntity == null) { throw new IllegalStateException("[GenericEntity.getModelEntity] could not find modelEntity for entityName " + entityName); } } return modelEntity; }
/** * 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<GenericValue> findByAnd(final String entityName, final Map<String, ?> fields) throws GenericEntityException { checkIfLocked(); return findByAnd(entityName, fields, null); }
/** Creates a Entity in the form of a GenericValue and write it to the datasource *@param primaryKey The GenericPK to create a value in the datasource from *@return GenericValue instance containing the new instance */ public GenericValue create(GenericPK primaryKey) throws GenericEntityException { return this.create(primaryKey, true); }
/** Creates a Entity in the form of a GenericValue and write it to the database *@return GenericValue instance containing the new instance */ public GenericValue create(String entityName, Map fields) throws GenericEntityException { if (entityName == null || fields == null) { return null; } ModelEntity entity = this.getModelReader().getModelEntity(entityName); GenericValue genericValue = new GenericValue(entity, fields); return this.create(genericValue, true); }
/** Gets the helper name that corresponds to this delegator and the specified entity *@param entity The entity to get the helper for *@return String with the helper name that corresponds to this delegator and the specified entity */ public String getEntityHelperName(ModelEntity entity) { if (entity == null) return null; return getEntityHelperName(entity.getEntityName()); }