/** Gets the instance of ModelEntity that corresponds to this delegator and the specified entityName *@param entityName The name of the entity to get *@return ModelEntity that corresponds to this delegator and the specified entityName */ public ModelEntity getModelEntity(String entityName) { try { return getModelReader().getModelEntity(entityName); } catch (GenericEntityException e) { Debug.logError(e, "Error getting entity definition from model", module); return null; } }
/** Gets the instance of ModelEntity that corresponds to this delegator and the specified entityName *@param entityName The name of the entity to get *@return ModelEntity that corresponds to this delegator and the specified entityName */ public ModelEntity getModelEntity(String entityName) { try { return getModelReader().getModelEntity(entityName); } catch (GenericEntityException e) { Debug.logError(e, "Error getting entity definition from model", module); return null; } }
/** 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); }
/** 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 instance of ModelEntity that corresponds to this delegator and the specified entityName. * * @param entityName The name of the entity to get * @return ModelEntity that corresponds to this delegator and the specified entityName */ public ModelEntity getModelEntity(final String entityName) { checkIfLocked(); try { return getModelReader().getModelEntity(entityName); } catch (GenericEntityException e) { Debug.logError(e, "Error getting entity definition from model", module); return null; } }
/** * Finds Generic Entity records by all of the specified fields (i.e. * combined using AND). * * @param entityName The Name of the Entity as defined in the entity XML file * @param fields the names and values of the fields by which to query (can be null) * @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<GenericValue> findByAnd( final String entityName, final Map<String, ?> fields, final List<String> orderBy) throws GenericEntityException { checkIfLocked(); final ModelEntity modelEntity = getModelReader().getModelEntity(entityName); return findByAnd(modelEntity, fields, orderBy); }
/** * Finds Generic Entity records by all of the specified fields (i.e. * 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<GenericValue> findByOr(final String entityName, final Map<String, ?> fields, final List<String> orderBy) throws GenericEntityException { checkIfLocked(); final ModelEntity modelEntity = getModelReader().getModelEntity(entityName); final 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()); } final List<GenericValue> list = helper.findByOr(modelEntity, fields, orderBy); 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); }
/** * Creates a Entity in the form of a GenericValue and write it to the database. * * @param entityName the type of entity to create (if null, this method does nothing) * @param fields the field values to use (if null, this method does nothing) * @return the created instance */ public GenericValue create(final String entityName, final Map<String, ?> fields) throws GenericEntityException { checkIfLocked(); if (entityName == null || fields == null) { return null; } final ModelEntity entity = getModelReader().getModelEntity(entityName); final GenericValue genericValue = new GenericValue(this, entity, fields); return create(genericValue, true); }
public static void deleteAllEntities() throws GenericEntityException { CoreTransactionUtil.setUseTransactions(true); final boolean beganTransaction = CoreTransactionUtil.begin(); try { final GenericDelegator delegator = CoreFactory.getGenericDelegator(); final ModelReader reader = delegator.getModelReader(); final Collection<String> entityNames = reader.getEntityNames(); for (final String entityName : entityNames) { final ModelEntity modelEntity = delegator.getModelReader().getModelEntity(entityName); // Delete only normal (non-view) entities if (!(modelEntity instanceof ModelViewEntity)) { delegator.removeByAnd(entityName, Collections.EMPTY_MAP); } } } finally { CoreTransactionUtil.commit(beganTransaction); } }
@Override public List<GenericValue> transform(final String entityName, final EntityCondition entityCondition, final List<String> orderBy, final String lockField, final Transformation transformation) throws GenericEntityException { checkIfLocked(); final ModelEntity modelEntity = getModelReader().getModelEntity(entityName); final GenericHelper entityHelper = getEntityHelper(entityName); final List<GenericValue> transformedEntities = entityHelper.transform(modelEntity, entityCondition, orderBy, lockField, transformation); for (final GenericValue genericValue : transformedEntities) { genericValue.setDelegator(this); } return transformedEntities; }
/** 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; }
/** * Removes/deletes Generic Entity records found by matching the EntityCondition. * * @param entityName The Name of the Entity as defined in the entity XML file * @param whereCondition The EntityCondition object that specifies how to constrain this query * @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 removeByCondition( final String entityName, final EntityCondition whereCondition, final boolean doCacheClear) throws GenericEntityException { checkIfLocked(); ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericHelper helper = getEntityHelper(entityName); if (doCacheClear) { // always clear cache before the operation Collection<GenericValue> toBeDeleted = helper.findByCondition(modelEntity, whereCondition, null, null); clearAllCacheLinesByValue(toBeDeleted); } return helper.removeByCondition(modelEntity, whereCondition); }
/** * 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 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; }
/** 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; }
/** 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 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; }