Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

add delegator batch to store or remove list #11

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ public void clear() {
// clear the list
if (autoSaveListId != null) {
try {
org.ofbiz.order.shoppinglist.ShoppingListEvents.clearListInfo(this.getDelegator(), autoSaveListId);
org.ofbiz.order.shoppinglist.ShoppingListEvents.clearListInfoBatch(this.getDelegator(), autoSaveListId);
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.order.shoppingcart.CartItemModifyException;
Expand Down Expand Up @@ -546,6 +548,28 @@ public static int clearListInfo(Delegator delegator, String shoppingListId) thro
// next remove the items
return delegator.removeByAnd("ShoppingListItem", UtilMisc.toMap("shoppingListId", shoppingListId));
}

/**
* Remove all items from the given list by batch.
*/
public static int clearListInfoBatch(Delegator delegator, String shoppingListId) throws GenericEntityException {
// remove the survey responses first
ModelEntity shoppingListItemSurveyModelEntity = delegator.getModelReader().getModelEntity("ShoppingListItemSurvey");
List<EntityCondition> toBeRemovedCondition = new LinkedList<EntityCondition>();
EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toMap("shoppingListId", shoppingListId));
toBeRemovedCondition.add(condition);
delegator.removeAllByAndBatch(shoppingListItemSurveyModelEntity, toBeRemovedCondition);

// next remove the items
delegator.removeByAnd("ShoppingListItem", UtilMisc.toMap("shoppingListId", shoppingListId));
ModelEntity shoppingListItemModelEntity = delegator.getModelReader().getModelEntity("ShoppingListItemSurvey");
List<EntityCondition> toBeRemovedShoppingListItemCondition = new LinkedList<EntityCondition>();
EntityCondition shoppingListItemCondition = EntityCondition.makeCondition(UtilMisc.toMap("shoppingListId", shoppingListId));
toBeRemovedShoppingListItemCondition.add(shoppingListItemCondition);
return delegator.removeAllByAndBatch(shoppingListItemModelEntity, toBeRemovedShoppingListItemCondition);
}



/**
* Creates records for survey responses on survey items
Expand Down
125 changes: 124 additions & 1 deletion framework/entity/src/org/ofbiz/entity/Delegator.java
Original file line number Diff line number Diff line change
Expand Up @@ -913,5 +913,128 @@ enum OperationType {INSERT, UPDATE, DELETE}
* Get use of Distributed Cache Clear mechanism status
* @return boolean true if this delegator uses a Distributed Cache Clear mechanism
*/
boolean useDistributedCacheClear();
boolean useDistributedCacheClear();

/**
* 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. <br/> This is defferent from the normal
* storeAll method in that the store method use jdbc batch does updates or inserts.
*
* @param values
* List of GenericValue instances containing the entities to
* store
* @return int representing number of rows effected by this operation
*/
public int storeAllBatch(List<GenericValue> toBeStored) throws GenericEntityException;

/**
* 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. <br/> This is defferent from the normal
* storeAll method in that the store method use jdbc batch does updates or inserts.
*
* @param values
* List of GenericValue instances containing the entities to
* store
* @param doCacheClear
* boolean that specifies whether or not to automatically clear
* cache entries related to this operation. This should always be
* <code>true</code> - otherwise you will lose data integrity.
* @return int representing number of rows effected by this operation
*/
public int storeAllBatch(List<GenericValue> toBeStored,boolean doCacheClear) throws GenericEntityException;

/**
* 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. <br/> This is defferent from the normal
* storeAll method in that the store method use jdbc batch does updates or inserts.
*
* @param values
* List of GenericValue instances containing the entities to
* store
* @param doCacheClear
* boolean that specifies whether or not to automatically clear
* cache entries related to this operation. This should always be
* <code>true</code> - otherwise you will lose data integrity.
* @param createDummyFks
* boolean that specifies whether or not to automatically create
* "dummy" place holder FKs
* @return int representing number of rows effected by this operation
*/
public int storeAllBatch(List<GenericValue> toBeStored,boolean doCacheClear ,boolean createDummyFks) throws GenericEntityException;


/**
* Remove the Entities from the List GenericValue instances to the persistent
* store.
*
* @param toBeRemoved
* List of GenericEntity instances containing the primary key of the entity list to remove.
* @return int representing number of rows effected by this operation
*/
public int removeAllByPrimaryKeyBatch(List<GenericEntity> toBeRemoved) throws GenericEntityException;


/**
* Remove the Entities from the List EntityCondition instances to the persistent
* store.
*
* @param modelEntity
* The modelEntity of the entity list to remove.
* @param toBeRemovedCondition
* List of EntityCondition instances containing the condition of the entity list to remove.
* @return int representing number of rows effected by this operation
*/
public int removeAllByAndBatch(ModelEntity modelEntity, List<EntityCondition> toBeRemovedCondition) throws GenericEntityException;

/**
* Remove the Entities from the List GenericValue instances to the persistent
* store.
*
* @param toBeRemoved
* List of GenericEntity instances containing the primary key of the entity list to remove.
* @param doCacheClear
* boolean that specifies whether or not to automatically clear
* cache entries related to this operation. This should always be
* <code>true</code> - otherwise you will lose data integrity.
*
* @return int representing number of rows effected by this operation
*/
public int removeAllByPrimaryKeyBatch(List<GenericEntity> toBeRemoved,boolean doCacheClear) throws GenericEntityException;

/**
* Remove the Entities from the List GenericValue instances to the persistent
* store.
*
* @param modelEntity
* The modelEntity of the entity list to remove.
* @param toBeRemovedCondition
* List of EntityCondition instances containing the condition of the entity list to remove.
* @param doCacheClear
* boolean that specifies whether or not to automatically clear
* cache entries related to this operation. This should always be
* <code>true</code> - otherwise you will lose data integrity.
*
* @return int representing number of rows effected by this operation
*/
public int removeAllByAndBatch(ModelEntity modelEntity, List<EntityCondition> toBeRemovedCondition,boolean doCacheClear) throws GenericEntityException;


}
Loading