Author: jleroux
Date: Thu Oct  1 20:24:17 2015
New Revision: 1706316

URL: http://svn.apache.org/viewvc?rev=1706316&view=rev
Log:
A patch from Martin Becker for "data import - nulling fields impossible" 
https://issues.apache.org/jira/browse/OFBIZ-293

In my opinion it would be straight forward, if the entity import would treat 
fields that are mentioned in entity XML files as fields that should be updated 
always, as the GenericDAO does. The current logic ignores fields, if there is 
only an empty string as value.

The enhancement brought by the solution of OFBIZ-4949 makes it possible to 
generally configure an entity-engine-xml file to be interpreted as replacement, 
so that all NOT mentioned fields are set to NULL instead of leaving the old 
value while updating the entity.

Nevertheless I think, that the default (update) behavior, the one with fine 
grained control over which fields are touched, should also give the possibility 
to set field values to NULL by including them in the XML.

The solution with the lowest impact on existing XML files and the most natural 
meaning should be to interpret empty string values in the XML as NULL, as it is 
today. The only difference would be, that they are not longer ignored but set 
as NULL values in the database. The only drawback I see is, that you're still 
not able to set "empty string" values as concrete values to the database (no 
loss of function, because you can't do it today, too).

As far as I can see, there should be no conflict with current existing data 
files. There are some where for example a parentTypeId is contained with empty 
string as value. Interpreting it as NULL and setting in database is exactly 
what is meant by such a definition.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java

Modified: 
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java?rev=1706316&r1=1706315&r2=1706316&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java 
(original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java 
Thu Oct  1 20:24:17 2015
@@ -663,10 +663,11 @@ public class EntitySaxReader implements
                         name = attributes.getQName(i);
                     }
                     try {
-                        // treat empty strings as nulls
-                        if (UtilValidate.isNotEmpty(value)) {
+                        // treat empty strings as nulls, but do NOT ignore 
them, instead set as null and update
+                        if (value != null) {
                             if 
(currentValue.getModelEntity().isField(name.toString())) {
-                                currentValue.setString(name.toString(), 
value.toString());
+                                String valueString = (value.length() > 0 ? 
value.toString() : null);
+                                currentValue.setString(name.toString(), 
valueString);
                                 if (Action.CREATE_REPLACE == currentAction && 
absentFields != null) absentFields.remove(name);
                             } else {
                                 Debug.logWarning("Ignoring invalid field name 
[" + name + "] found for the entity: " + currentValue.getEntityName() + " with 
value=" + value, module);


Reply via email to