Author: jleroux
Date: Thu Nov 12 08:49:27 2009
New Revision: 835303

URL: http://svn.apache.org/viewvc?rev=835303&view=rev
Log:
A patch from Bob Morley "When an entityModel has a field marked as a primary 
key, it should also be set to NotNull" 
(https://issues.apache.org/jira/browse/OFBIZ-3154) - OFBIZ-3154

We were doing some work with the ModelField and noticed that when a field is 
marked as a primary key it can still have its "NotNull" property set to "false" 
(the default). Because we were doing work based on if a field was nullable it 
was causing a bug on primary keys. The suggestion is to set NotNull = "true" 
when a field is marked as a primary key. This should have no impact to current 
code as (in most places) a redundant check was being done (see creation of 
tables where it will add "NOT NULL" based on both isNotNull and isPk – ideally 
it should be just based on the former).

This change makes minor modifications to two files ModelField and ModelEntity. 
ModelField.setIsPk() will call setIsNotNull(true) when the primary key 
indicator is true. ModelEntity will call field.isNotNull = true when it is 
reading the primary key elements in the entity definition.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java

Modified: 
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=835303&r1=835302&r2=835303&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java 
(original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java 
Thu Nov 12 08:49:27 2009
@@ -197,6 +197,7 @@
             if (field != null) {
                 this.pks.add(field);
                 field.isPk = true;
+                field.isNotNull = true;
             } else {
                 Debug.logError("[ModelReader.createModelEntity] ERROR: Could 
not find field \"" +
                         pkElement.getAttribute("field") + "\" specified in a 
prim-key", module);

Modified: 
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java?rev=835303&r1=835302&r2=835303&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java 
(original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java Thu 
Nov 12 08:49:27 2009
@@ -134,6 +134,9 @@
 
     public void setIsPk(boolean isPk) {
         this.isPk = isPk;
+        if (isPk) {
+            setIsNotNull(true);
+        }
     }
 
     public boolean getIsNotNull() {


Reply via email to