You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/09/03 22:22:53 UTC

svn commit: r572413 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: transaction/TransactionUtil.java util/EntityDataAssert.java

Author: jonesde
Date: Mon Sep  3 13:22:51 2007
New Revision: 572413

URL: http://svn.apache.org/viewvc?rev=572413&view=rev
Log:
Small format change only in TransactionUtil; in EntityDataAssert fixed a couple of NPE cases and improved to make much more robust

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=572413&r1=572412&r2=572413&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Mon Sep  3 13:22:51 2007
@@ -313,7 +313,7 @@
         try {
             if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
                 TransactionManager txMgr = TransactionFactory.getTransactionManager();
-                if (txMgr != null ) {
+                if (txMgr != null) {
                     pushTransactionBeginStackSave(clearTransactionBeginStack());
                     pushSetRollbackOnlyCauseSave(clearSetRollbackOnlyCause());
                     Transaction trans = txMgr.suspend();

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java?rev=572413&r1=572412&r2=572413&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java Mon Sep  3 13:22:51 2007
@@ -82,31 +82,51 @@
     }
     
     public static void checkSingleValue(GenericValue checkValue, GenericDelegator delegator, List errorMessages) throws GenericEntityException {
-        // to check get the PK, find by that, compare all fields
-        GenericPK checkPK = checkValue.getPrimaryKey();
-        GenericValue currentValue = delegator.findByPrimaryKey(checkPK);
-        if (currentValue == null) {
-            errorMessages.add("Entity [" + checkPK.getEntityName() + "] record not found for pk: " + checkPK);
+        if (checkValue == null) {
+            errorMessages.add("Got a value to check was null");
+            return;
         }
-
-        ModelEntity modelEntity = currentValue.getModelEntity();
-        List nonpkFieldNameList = modelEntity.getNoPkFieldNames();
-        Iterator nonpkFieldNameIter = nonpkFieldNameList.iterator();
-        while (nonpkFieldNameIter.hasNext()) {
-            String nonpkFieldName = (String) nonpkFieldNameIter.next();
-            // skip the fields the entity engine maintains
-            if (ModelEntity.CREATE_STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.CREATE_STAMP_TX_FIELD.equals(nonpkFieldName) ||
-                    ModelEntity.STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.STAMP_TX_FIELD.equals(nonpkFieldName)) {
-                continue;
+        // to check get the PK, find by that, compare all fields
+        GenericPK checkPK = null;
+        
+        try {
+            checkPK = checkValue.getPrimaryKey();
+            GenericValue currentValue = delegator.findByPrimaryKey(checkPK);
+            if (currentValue == null) {
+                errorMessages.add("Entity [" + checkPK.getEntityName() + "] record not found for pk: " + checkPK);
+                return;
             }
-            
-            Object checkField = checkValue.get(nonpkFieldName);
-            Object currentField = currentValue.get(nonpkFieldName);
 
-            if (checkField != null && !checkField.equals(currentField)) {
-                errorMessages.add("Field [" + modelEntity.getEntityName() + "." + nonpkFieldName + 
-                        "] did not match; file value [" + checkField + "], db value [" + currentField + "] pk [" + checkPK + "]");
+            ModelEntity modelEntity = checkValue.getModelEntity();
+            List nonpkFieldNameList = modelEntity.getNoPkFieldNames();
+            Iterator nonpkFieldNameIter = nonpkFieldNameList.iterator();
+            while (nonpkFieldNameIter.hasNext()) {
+                String nonpkFieldName = (String) nonpkFieldNameIter.next();
+                // skip the fields the entity engine maintains
+                if (ModelEntity.CREATE_STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.CREATE_STAMP_TX_FIELD.equals(nonpkFieldName) ||
+                        ModelEntity.STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.STAMP_TX_FIELD.equals(nonpkFieldName)) {
+                    continue;
+                }
+                
+                Object checkField = checkValue.get(nonpkFieldName);
+                Object currentField = currentValue.get(nonpkFieldName);
+
+                if (checkField != null && !checkField.equals(currentField)) {
+                    errorMessages.add("Field [" + modelEntity.getEntityName() + "." + nonpkFieldName + 
+                            "] did not match; file value [" + checkField + "], db value [" + currentField + "] pk [" + checkPK + "]");
+                }
+            }
+        } catch (GenericEntityException e) {
+            throw e;
+        } catch (Throwable t) {
+            String errMsg;
+            if (checkPK == null) {
+                errMsg = "Error checking value [" + checkValue + "]: " + t.toString();
+            } else {
+                errMsg = "Error checking entity [" + checkPK.getEntityName() + "] with pk [" + checkPK.getAllFields() + "]: " + t.toString();
             }
+            errorMessages.add(errMsg);
+            Debug.logError(t, errMsg, module);
         }
     }
 }