use of org.apache.ofbiz.entity.datasource.GenericHelper in project ofbiz-framework by apache.
the class GenericDelegator method removeByCondition.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#removeByCondition(java.lang.String, org.apache.ofbiz.entity.condition.EntityCondition)
*/
@Override
public int removeByCondition(String entityName, EntityCondition condition) throws GenericEntityException {
boolean beganTransaction = false;
try {
if (alwaysUseTransaction) {
beganTransaction = TransactionUtil.begin();
}
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericHelper helper = getEntityHelper(entityName);
List<GenericValue> removedEntities = null;
if (testMode) {
removedEntities = this.findList(entityName, condition, null, null, null, false);
}
int rowsAffected = helper.removeByCondition(this, modelEntity, condition);
if (rowsAffected > 0) {
this.clearCacheLine(entityName);
}
if (testMode) {
for (GenericValue entity : removedEntities) {
storeForTestRollback(new TestOperation(OperationType.DELETE, entity));
}
}
TransactionUtil.commit(beganTransaction);
return rowsAffected;
} catch (IllegalStateException | GenericEntityException e) {
String errMsg = "Failure in removeByCondition operation for entity [" + entityName + "]: " + e.toString() + ". Rolling back transaction.";
Debug.logError(e, errMsg, module);
TransactionUtil.rollback(beganTransaction, errMsg, e);
throw new GenericEntityException(e);
}
}
Aggregations