[ 
https://issues.apache.org/jira/browse/OFBIZ-747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527946
 ] 

Michael Imhof commented on OFBIZ-747:
-------------------------------------

You're right. It's possible to use an id-ne similiar field type.
But this is just a validation for ofbiz and I will never be sure if this field 
is really not null 
in the database. 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. 


> Entity declaration: NOT NULL Fields on database
> -----------------------------------------------
>
>                 Key: OFBIZ-747
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-747
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>         Environment: SUSE Linux 10.1 & MySQL 5.0.18
>            Reporter: Michael Imhof
>            Priority: Minor
>         Attachments: patch747.txt
>
>
> We added a new attribute: not-null="true|false" to the <entity/> tag.
> Example:
>     <entity entity-name="Archivindex"
>             package-name="ch.nowhow.isgate.archiv"
>             title="Archiv Index Entity" no-auto-stamp="true">
>       <field name="id" type="id-num"></field>
>       <field name="notNullField" type="herkunft" not-null="true"></field>
>       <prim-key field="id"/>
>     </entity>
> This makes the field NOT NULL on the database (like primary key fields).
> Changes:
> =======
> 1.http://www.ofbiz.org/dtds/entitymodel.xsd
> ------------------------------------------------------
> Adding attribute to "attlist.field".
> <xs:attributeGroup name="attlist.field">
>         ...
>         <xs:attribute name="not-null" default="false">
>             <xs:simpleType>
>                 <xs:restriction base="xs:token">
>                     <xs:enumeration value="true"/>
>                     <xs:enumeration value="false"/>
>                 </xs:restriction>
>             </xs:simpleType>
>         </xs:attribute>
> </xs:attributeGroup>
> 2.ModelField.java
> ---------------------
> * New attribute notNull with getter & setter.
>     protected boolean isNotNull = false;
> * Constructor addition:
> public ModelField(Element fieldElement) {
>         this.type = UtilXml.checkEmpty(fieldElement.getAttribute("type"));
>         this.name = UtilXml.checkEmpty(fieldElement.getAttribute("name"));
>         
> this.setColName(UtilXml.checkEmpty(fieldElement.getAttribute("col-name")));
>         this.isPk = false; // is set elsewhere
>         this.encrypt = 
> UtilXml.checkBoolean(fieldElement.getAttribute("encrypt"), false);
>         this.isNotNull = 
> UtilXml.checkBoolean(fieldElement.getAttribute("not-null"), false);
> ..
> }
> * Method #toXmlElement(..)
> public Element toXmlElement(Document document) {
> ..
>         if (this.getIsNotNull()) {
>             root.setAttribute("not-null", "true");
>         }
> ..
> }
> 3.DatabaseUtil.java
> ------------------------
> Add field.getIsNotNull() to NOT NULL statement in method createTable(...)
>            if (field.getIsNotNull() || field.getIsPk()) {
>                 if (this.datasourceInfo.alwaysUseConstraintKeyword) {
>                     sqlBuf.append(" CONSTRAINT NOT NULL, ");
>                 } else {
>                     sqlBuf.append(" NOT NULL, ");
>                 }
>             } else {
>                 sqlBuf.append(", ");
>             }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to