Search in sources :

Example 16 with GenericHelper

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);
    }
}
Also used : ModelEntity(org.apache.ofbiz.entity.model.ModelEntity) GenericHelper(org.apache.ofbiz.entity.datasource.GenericHelper)

Aggregations

GenericHelper (org.apache.ofbiz.entity.datasource.GenericHelper)16 ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)7 IOException (java.io.IOException)3 SAXException (org.xml.sax.SAXException)3 ExecutionException (java.util.concurrent.ExecutionException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 GeneralRuntimeException (org.apache.ofbiz.base.util.GeneralRuntimeException)2 ModelField (org.apache.ofbiz.entity.model.ModelField)2 SerializeException (org.apache.ofbiz.entity.serialize.SerializeException)2 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)2 NodeModel (freemarker.ext.dom.NodeModel)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 TemplateHashModel (freemarker.template.TemplateHashModel)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1