svn commit: r1403870 - /ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1403870 - /ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java

erwan
Author: erwan
Date: Tue Oct 30 21:10:10 2012
New Revision: 1403870

URL: http://svn.apache.org/viewvc?rev=1403870&view=rev
Log:
Applying a patch from Olivier Heintz on branch OFBIZ-4949 add a new attribute for for entity-engine-xml tag, put-other-field-to-null= true, if it exist at the beginning data file, all update will put to null all field not detail in this file

Modified:
    ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java

Modified: ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java?rev=1403870&r1=1403869&r2=1403870&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java Tue Oct 30 21:10:10 2012
@@ -88,6 +88,7 @@ public class EntitySaxReader implements
     protected boolean checkDataOnly = false;
     protected boolean doCacheClear = true;
     protected boolean disableEeca = false;
+    protected boolean setOtherFieldsToNull = false;
     protected List<Object> messageList = null;
 
     protected List<GenericValue> valuesToWrite = new ArrayList<GenericValue>(valuesPerWrite);
@@ -202,6 +203,14 @@ public class EntitySaxReader implements
         }
     }
 
+    public boolean getSetOtherFieldsToNull() {
+        return this.setOtherFieldsToNull;
+    }
+
+    public void setSetOtherFieldsToNull(boolean _setOtherFieldsToNull) {
+        this.setOtherFieldsToNull = _setOtherFieldsToNull;
+    }
+
     public long parse(String content) throws SAXException, java.io.IOException {
         if (content == null) {
             Debug.logWarning("content was null, doing nothing", module);
@@ -493,6 +502,12 @@ public class EntitySaxReader implements
                 this.setCreateDummyFks("true".equalsIgnoreCase(dummyFk.toString()));
             }
 
+            // check if other fields should be set to null
+            CharSequence _setOtherFieldsToNull = attributes.getValue("set-other-fields-to-null");
+            if (_setOtherFieldsToNull != null) {
+                this.setSetOtherFieldsToNull("true".equalsIgnoreCase(_setOtherFieldsToNull.toString()));
+            }
+
             return;
         }
 
@@ -575,6 +590,16 @@ public class EntitySaxReader implements
                         Debug.logWarning(e, "Could not set field " + entityName + "." + name + " to the value " + value, module);
                     }
                 }
+                if (this.getSetOtherFieldsToNull()) {
+                    ModelEntity currentEntity = currentValue.getModelEntity();
+                    for (String fieldName : currentEntity.getAllFieldNames() ){
+                        if (   ! ModelEntity.STAMP_FIELD.equals(fieldName)        && ! ModelEntity.STAMP_TX_FIELD.equals(fieldName)
+                            && ! ModelEntity.CREATE_STAMP_FIELD.equals(fieldName) && ! ModelEntity.CREATE_STAMP_TX_FIELD.equals(fieldName)
+                            && currentValue.get(fieldName) == null ) {
+                                currentValue.set(fieldName, null);
+                        }
+                    }
+                }
             }
         }
     }