You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Michael Imhof (JIRA)" <ji...@apache.org> on 2007/02/21 14:40:06 UTC

[jira] Created: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Entity declaration: NOT NULL Fields on database
-----------------------------------------------

                 Key: OFBIZ-747
                 URL: https://issues.apache.org/jira/browse/OFBIZ-747
             Project: OFBiz (The Open for Business Project)
          Issue Type: Improvement
          Components: framework
    Affects Versions: SVN trunk
         Environment: SUSE Linux 10.1 & MySQL 5.0.18
            Reporter: Michael Imhof
            Priority: Minor


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.


[jira] Closed: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Posted by "Jacques Le Roux (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux closed OFBIZ-747.
---------------------------------

       Resolution: Fixed
    Fix Version/s: SVN trunk
         Assignee: Jacques Le Roux  (was: Adam Heath)

Thanks Michael,

You patch (after some hand merging) is in trunk revision: 707135  


> 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
>            Assignee: Jacques Le Roux
>            Priority: Minor
>             Fix For: SVN trunk
>
>         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.


[jira] Assigned: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Posted by "Adam Heath (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Adam Heath reassigned OFBIZ-747:
--------------------------------

    Assignee: Adam Heath

> 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
>            Assignee: Adam Heath
>            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.


[jira] Commented: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Posted by "Michael Imhof (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Posted by "Jacopo Cappellato (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527706 ] 

Jacopo Cappellato commented on OFBIZ-747:
-----------------------------------------

What about using the id-ne (or similar) field type instead?

> 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.


[jira] Commented: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Posted by "Jacques Le Roux (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588343#action_12588343 ] 

Jacques Le Roux commented on OFBIZ-747:
---------------------------------------

Why not add this to the trunk ?

> 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
>            Assignee: Adam Heath
>            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.


[jira] Updated: (OFBIZ-747) Entity declaration: NOT NULL Fields on database

Posted by "Anonymous (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]


    Attachment: patch747.txt

> Entity declaration: NOT NULL Fields on database
> -----------------------------------------------
>
>                 Key: OFBIZ-747
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-747
>             Project: OFBiz (The Open for Business Project)
>          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.