User: dsundstrom Date: 02/02/11 22:17:16 Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata JDBCCMPFieldMetaData.java JDBCCMPFieldPropertyMetaData.java JDBCRelationshipRoleMetaData.java Log: Added optional not-null element to cmp-fields. Not null is on by by default for primitive types and primary key fields. Revision Changes Path 1.7 +30 -2 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata/JDBCCMPFieldMetaData.java Index: JDBCCMPFieldMetaData.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata/JDBCCMPFieldMetaData.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JDBCCMPFieldMetaData.java 12 Dec 2001 19:48:36 -0000 1.6 +++ JDBCCMPFieldMetaData.java 12 Feb 2002 06:17:16 -0000 1.7 @@ -28,7 +28,7 @@ * @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a> * @author <a href="mailto:[EMAIL PROTECTED]">Dirk Zimmermann</a> * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Harcq</a> - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ public final class JDBCCMPFieldMetaData { /** @@ -79,6 +79,11 @@ private final boolean primaryKeyMember; /** + * Should null values not be allowed for this field. + */ + private final boolean notNull; + + /** * The Field object in the primary key class for this * cmp field, or null if this field is the prim-key-field. */ @@ -153,6 +158,7 @@ primaryKeyMember = pkMember; primaryKeyField = pkField; } + notNull = fieldType.isPrimitive() || primaryKeyMember; } /** @@ -225,6 +231,13 @@ // field object of the primary key primaryKeyField = defaultValues.getPrimaryKeyField(); + // not-null + Element notNullElement = MetaData.getOptionalChild(element, "not-null"); + notNull = + fieldType.isPrimitive() || + primaryKeyMember || + (notNullElement != null); + // property overrides Iterator iterator = MetaData.getChildrenByTagName(element, "property"); while(iterator.hasNext()) { @@ -259,6 +272,7 @@ Element element, JDBCCMPFieldMetaData defaultValues, boolean primaryKeyMember, + boolean notNull, boolean readOnly, int readTimeOut) throws DeploymentException { @@ -300,6 +314,9 @@ // primary key member? this.primaryKeyMember = primaryKeyMember; + // not-null + this.notNull = notNull; + // field object of the primary key primaryKeyField = defaultValues.getPrimaryKeyField(); @@ -340,6 +357,7 @@ JDBCCMPFieldMetaData defaultValues, String columnName, boolean primaryKeyMember, + boolean notNull, boolean readOnly, int readTimeOut) { @@ -370,12 +388,14 @@ // field object of the primary key primaryKeyField = defaultValues.getPrimaryKeyField(); + // not-null + this.notNull = notNull; + // property overrides for(Iterator i=defaultValues.propertyOverrides.iterator(); i.hasNext();) { propertyOverrides.add(new JDBCCMPFieldPropertyMetaData( this, (JDBCCMPFieldPropertyMetaData)i.next())); } - } /** @@ -465,6 +485,14 @@ */ public boolean isPrimaryKeyMember() { return primaryKeyMember; + } + + /** + * Should this field allow null values? + * @return true if this field will not allow a null value. + */ + public boolean isNotNull() { + return notNull; } /** 1.6 +59 -24 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata/JDBCCMPFieldPropertyMetaData.java Index: JDBCCMPFieldPropertyMetaData.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata/JDBCCMPFieldPropertyMetaData.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JDBCCMPFieldPropertyMetaData.java 26 Nov 2001 03:12:27 -0000 1.5 +++ JDBCCMPFieldPropertyMetaData.java 12 Feb 2002 06:17:16 -0000 1.6 @@ -15,7 +15,7 @@ * This immutable class contains information about the an overriden field property. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public final class JDBCCMPFieldPropertyMetaData { /** @@ -42,23 +42,33 @@ * the sql type, used for table creation. */ private final String sqlType; + + /** + * Should null values not be allowed for this property. + */ + private final boolean notNull; /** - * Constructs cmp field property meta data with the data contained in the property xml - * element from a jbosscmp-jdbc xml file. + * Constructs cmp field property meta data with the data contained in the + * property xml element from a jbosscmp-jdbc xml file. * * @param cmpField the JDBCCMPFieldMetaData on which this property is defined - * @param element the xml Element which contains the metadata about this field + * @param element the xml Element which contains the metadata about this + * field * @throws DeploymentException if the xml element is not semantically correct */ - public JDBCCMPFieldPropertyMetaData(JDBCCMPFieldMetaData cmpField, Element element) throws DeploymentException { + public JDBCCMPFieldPropertyMetaData( + JDBCCMPFieldMetaData cmpField, + Element element) throws DeploymentException { + this.cmpField = cmpField; // Property name propertyName = MetaData.getUniqueChildContent(element, "property-name"); // Column name - String columnStr = MetaData.getOptionalChildContent(element, "column-name"); + String columnStr = + MetaData.getOptionalChildContent(element, "column-name"); if(columnStr != null) { columnName = columnStr; } else { @@ -74,19 +84,25 @@ jdbcType = Integer.MIN_VALUE; sqlType = null; } + + // notNull + notNull = (MetaData.getOptionalChild(element, "not-null") != null); } /** - * Constructs cmp field property meta data based on the data contained in the - * defaultValues parameter but defined on the specified cmpField. This is effectly - * a copy constructory, except it can change the cmpField object on which the - * property is defined. + * Constructs cmp field property meta data based on the data contained in + * the defaultValues parameter but defined on the specified cmpField. This + * is effectly a copy constructory, except it can change the cmpField object + * on which the property is defined. * * @param cmpField the JDBCCMPFieldMetaData on which this property is defined * @param defaultValues the defaultValues of this property * @throws DeploymentException if the xml element is not semantically correct */ - public JDBCCMPFieldPropertyMetaData(JDBCCMPFieldMetaData cmpField, JDBCCMPFieldPropertyMetaData defaultValues) { + public JDBCCMPFieldPropertyMetaData( + JDBCCMPFieldMetaData cmpField, + JDBCCMPFieldPropertyMetaData defaultValues) { + this.cmpField = cmpField; // Property name @@ -100,6 +116,9 @@ // sql type sqlType = defaultValues.sqlType; + + // not-null + notNull = defaultValues.notNull; } /** @@ -142,24 +161,36 @@ } /** - * Compares this JDBCCMPFieldPropertyMetaData against the specified object. Returns - * true if the objects are the same. Two JDBCCMPFieldPropertyMetaData are the same - * if they both have the same name and are defined on the same cmpField. + * Should this field allow null values? + * @return true if this field will not allow a null value. + */ + public boolean isNotNull() { + return notNull; + } + + /** + * Compares this JDBCCMPFieldPropertyMetaData against the specified object. + * Returns true if the objects are the same. Two + * JDBCCMPFieldPropertyMetaData are the same if they both have the same name + * and are defined on the same cmpField. * @param o the reference object with which to compare - * @return true if this object is the same as the object argument; false otherwise + * @return true if this object is the same as the object argument; false + * otherwise */ public boolean equals(Object o) { if(o instanceof JDBCCMPFieldPropertyMetaData) { - JDBCCMPFieldPropertyMetaData cmpFieldProperty = (JDBCCMPFieldPropertyMetaData)o; + JDBCCMPFieldPropertyMetaData cmpFieldProperty = + (JDBCCMPFieldPropertyMetaData)o; return propertyName.equals(cmpFieldProperty.propertyName) && - cmpField.equals(cmpFieldProperty.cmpField); + cmpField.equals(cmpFieldProperty.cmpField); } return false; } /** - * Returns a hashcode for this JDBCCMPFieldPropertyMetaData. The hashcode is computed - * based on the hashCode of the declaring entity and the hashCode of the fieldName + * Returns a hashcode for this JDBCCMPFieldPropertyMetaData. The hashcode is + * computed based on the hashCode of the declaring entity and the hashCode + * of the fieldName * @return a hash code value for this object */ public int hashCode() { @@ -168,16 +199,20 @@ result = 37*result + propertyName.hashCode(); return result; } + /** - * Returns a string describing this JDBCCMPFieldPropertyMetaData. The exact details - * of the representation are unspecified and subject to change, but the following - * may be regarded as typical: + * Returns a string describing this JDBCCMPFieldPropertyMetaData. The exact + * details of the representation are unspecified and subject to change, but + * the following may be regarded as typical: * - * "[JDBCCMPFieldPropertyMetaData: propertyName=line1, [JDBCCMPFieldMetaData: fieldName=address, [JDBCEntityMetaData: entityName=UserEJB]]" + * "[JDBCCMPFieldPropertyMetaData: propertyName=line1, + * [JDBCCMPFieldMetaData: fieldName=address, + * [JDBCEntityMetaData: entityName=UserEJB]]" * * @return a string representation of the object */ public String toString() { - return "[JDBCCMPFieldPropertyMetaData : propertyName=" + propertyName + ", " + cmpField + "]"; + return "[JDBCCMPFieldPropertyMetaData : propertyName=" + + propertyName + ", " + cmpField + "]"; } } 1.15 +3 -1 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata/JDBCRelationshipRoleMetaData.java Index: JDBCRelationshipRoleMetaData.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/metadata/JDBCRelationshipRoleMetaData.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- JDBCRelationshipRoleMetaData.java 4 Feb 2002 21:03:20 -0000 1.14 +++ JDBCRelationshipRoleMetaData.java 12 Feb 2002 06:17:16 -0000 1.15 @@ -23,7 +23,7 @@ * the ejb-jar.xml file's ejb-relation elements. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ */ public final class JDBCRelationshipRoleMetaData { /** @@ -319,6 +319,7 @@ cmpField, columnName, false, + relationMetaData.isTableMappingStyle(), relationMetaData.isReadOnly(), relationMetaData.getReadTimeOut()); fields.put(cmpField.getFieldName(), cmpField); @@ -374,6 +375,7 @@ keyElement, cmpField, false, + relationMetaData.isTableMappingStyle(), relationMetaData.isReadOnly(), relationMetaData.getReadTimeOut()); fields.put(cmpField.getFieldName(), cmpField);
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development