/** 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 *@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); }
/** * Remove all current directories. */ private void removeAllDirectories() throws GenericEntityException { genericDelegator.removeByAnd(DIRECTORY_ATTRIBUTE_ENTITY_NAME, new HashMap()); genericDelegator.removeByAnd(DIRECTORY_OPERATION_ENTITY_NAME, new HashMap()); genericDelegator.removeByAnd(DIRECTORY_ENTITY_NAME, new HashMap()); }
/** * 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 affected by this operation */ public int removeByAnd(final String entityName, final Map<String, ?> fields) throws GenericEntityException { checkIfLocked(); return removeByAnd(entityName, fields, true); }
/** Remove the named Related Entity for the GenericValue from the persistent store *@param relationName String containing the relation name which is the * combination of relation.title and relation.rel-entity-name as * specified in the entity XML definition file *@param value GenericValue instance containing the entity *@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 removeRelated(String relationName, GenericValue value, boolean doCacheClear) throws GenericEntityException { ModelEntity modelEntity = value.getModelEntity(); ModelRelation relation = modelEntity.getRelation(relationName); if (relation == null) { throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value); } Map fields = new HashMap(); for (int i = 0; i < relation.getKeyMapsSize(); i++) { ModelKeyMap keyMap = relation.getKeyMap(i); fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName())); } return this.removeByAnd(relation.getRelEntityName(), fields, doCacheClear); }
/** * Remove the named Related Entity for the GenericValue from the persistent store. * * @param relationName String containing the relation name which is the * combination of relation.title and relation.rel-entity-name as specified * in the entity XML definition file * @param value GenericValue instance containing the entity * @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 removeRelated(final String relationName, final GenericValue value, final boolean doCacheClear) throws GenericEntityException { ModelEntity modelEntity = value.getModelEntity(); ModelRelation relation = modelEntity.getRelation(relationName); if (relation == null) { throw new GenericModelException( "Could not find relation for relationName: " + relationName + " for value " + value); } Map<String, Object> fields = new HashMap<String, Object>(); for (int i = 0; i < relation.getKeyMapsSize(); i++) { ModelKeyMap keyMap = relation.getKeyMap(i); fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName())); } return removeByAnd(relation.getRelEntityName(), fields, doCacheClear); }
/** Remove the named Related Entity for the GenericValue from the persistent store *@param relationName String containing the relation name which is the * combination of relation.title and relation.rel-entity-name as * specified in the entity XML definition file *@param value GenericValue instance containing the entity *@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 removeRelated(String relationName, GenericValue value, boolean doCacheClear) throws GenericEntityException { ModelEntity modelEntity = value.getModelEntity(); ModelRelation relation = modelEntity.getRelation(relationName); if (relation == null) { throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value); } Map fields = new HashMap(); for (int i = 0; i < relation.getKeyMapsSize(); i++) { ModelKeyMap keyMap = relation.getKeyMap(i); fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName())); } return this.removeByAnd(relation.getRelEntityName(), fields, doCacheClear); }
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); } }