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