svn commit: r707135 - in /ofbiz/trunk/framework/entity: dtd/entitymodel.xsd src/org/ofbiz/entity/jdbc/DatabaseUtil.java src/org/ofbiz/entity/model/ModelField.java

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

svn commit: r707135 - in /ofbiz/trunk/framework/entity: dtd/entitymodel.xsd src/org/ofbiz/entity/jdbc/DatabaseUtil.java src/org/ofbiz/entity/model/ModelField.java

jleroux@apache.org
Author: jleroux
Date: Wed Oct 22 10:03:27 2008
New Revision: 707135

URL: http://svn.apache.org/viewvc?rev=707135&view=rev
Log:
A patch from Michael Imhof "Entity declaration: NOT NULL Fields on database" (https://issues.apache.org/jira/browse/OFBIZ-747) - OFBIZ-747
This is simple, clear and may turn useful in some cases. It can't hurt anything but will only work on a new data base.

Modified:
    ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java

Modified: ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd?rev=707135&r1=707134&r2=707135&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original)
+++ ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Wed Oct 22 10:03:27 2008
@@ -134,7 +134,29 @@
             </xs:simpleType>
         </xs:attribute>
         <xs:attribute name="enable-audit-log" default="false">
-            <xs:annotation><xs:documentation>If this is set to true then whenever the value for this field on a record changes the Entity Engine will record the change in the EntityAuditLog entity. Defaults to false.</xs:documentation></xs:annotation>
+            <xs:annotation>
+                <xs:documentation>
+                    If this is set to true then whenever the value for this field on a record changes the Entity Engine will record the change in the EntityAuditLog entity.
+                    Defaults to false.
+                </xs:documentation>
+            </xs:annotation>
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute name="not-null" default="false">
+            <xs:annotation>
+                <xs:documentation>
+                    This makes the field NOT NULL on the database (like primary key fields).
+                    It's possible to use an id-ne similiar field type.
+                    But rows can be added from outside of ofbiz (e.g. database manager, third party programm, etc).
+                    This patch uses the ability of a database to set not null constraints.
+                    Defaults to false.
+                </xs:documentation>
+            </xs:annotation>
             <xs:simpleType>
                 <xs:restriction base="xs:token">
                     <xs:enumeration value="true"/>

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java?rev=707135&r1=707134&r2=707135&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java Wed Oct 22 10:03:27 2008
@@ -1746,7 +1746,7 @@
                 }
             }
 
-            if (field.getIsPk()) {
+            if (field.getIsNotNull() || field.getIsPk()) {
                 if (this.datasourceInfo.alwaysUseConstraintKeyword) {
                     sqlBuf.append(" CONSTRAINT NOT NULL, ");
                 } else {
@@ -3247,7 +3247,7 @@
                     sqlBuf.append(this.datasourceInfo.collate);
                 }
 
-                if (field.getIsPk()) {
+                if (field.getIsPk()  || field.getIsNotNull()) {
                     if (this.datasourceInfo.alwaysUseConstraintKeyword) {
                         sqlBuf.append(" CONSTRAINT NOT NULL");
                     } else {

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=707135&r1=707134&r2=707135&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 Wed Oct 22 10:03:27 2008
@@ -42,6 +42,7 @@
     /** boolean which specifies whether or not the Field is a Primary Key */
     protected boolean isPk = false;
     protected boolean encrypt = false;
+    protected boolean isNotNull = false;
     protected boolean isAutoCreatedInternal = false;
     protected boolean enableAuditLog = false;
     
@@ -74,6 +75,7 @@
         this.encrypt = UtilXml.checkBoolean(fieldElement.getAttribute("encrypt"), false);
         this.description = UtilXml.childElementValue(fieldElement, "description");
         this.enableAuditLog = UtilXml.checkBoolean(fieldElement.getAttribute("enable-audit-log"), false);
+        this.isNotNull = UtilXml.checkBoolean(fieldElement.getAttribute("not-null"), false);
 
         NodeList validateList = fieldElement.getElementsByTagName("validate");
 
@@ -133,6 +135,14 @@
     public void setIsPk(boolean isPk) {
         this.isPk = isPk;
     }
+    
+    public boolean getIsNotNull() {
+        return this.isNotNull;
+    }
+
+    public void setIsNotNull(boolean isNotNull) {
+        this.isNotNull = isNotNull;
+    }
 
     public boolean getEncrypt() {
         return this.encrypt;
@@ -195,6 +205,9 @@
         if (this.getEncrypt()) {
             root.setAttribute("encrypt", "true");
         }
+        if (this.getIsNotNull()) {
+            root.setAttribute("not-null", "true");
+        }
 
         Iterator<String> valIter = this.validators.iterator();
         if (valIter != null) {