Hi,
Some databases, such as firebird/interbase, require that columns used in
primary keys be defined not null. In order to make JAWS automatic table
creation useful for such databases, I suggest we add a nullable element to
JAWS.xml, inside the cmp-field element.
An example is:
<cmp-field>
<field-name>n</field-name>
<column-name>n</column-name>
<sql-type>numeric(18, 0)</sql-type>
<jdbc-type>INTEGER</jdbc-type>
<nullable>false</nullable>
</cmp-field>
two patches to do this follow. I have not updated jaws.dtd since it
appears to be woefully incomplete as it is.
I am considering adding JAWS support for creating foreign keys from ejb
references, although this is obviously much more work. It might make JAWS
into a usable schema generation tool. Is this an interesting project? (If
I do it, will it get into the source?)
Thanks
David Jencks
Index: jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/CMPFieldMetaData.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/CMPFieldMetaData.java,v
retrieving revision 1.4
diff -c -r1.4 CMPFieldMetaData.java
*** jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/CMPFieldMetaData.java
2001/02/12
12:50:12 1.4
--- jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/CMPFieldMetaData.java
2001/03/06
17:24:40
***************
*** 57,62 ****
--- 57,65 ----
// the column name in the table
private String columnName;
+
+ //for table creation, whether to include not null constraint on
column
+ private boolean nullable = true;
private boolean isAPrimaryKeyField;
***************
*** 127,132 ****
--- 130,144 ----
}
return sqlType;
}
+
+ public String getNullable() {
+ if (nullable) {
+ return "";
+ }
+ else {
+ return " NOT NULL";
+ }
+ }
public String getColumnName() { return columnName; }
***************
*** 331,336 ****
--- 343,354 ----
sqlType = getElementContent(getUniqueChild(element,
"sql-type"));
}
+
+ String nullableStr = getElementContent(getOptionalChild(element,
"nullable"));
+
+ if (nullableStr != null) {
+ nullable = Boolean.valueOf(nullableStr).booleanValue();
+ }
}
Index: jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java,v
retrieving revision 1.12
diff -c -r1.12 JDBCInitCommand.java
*** jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java 2001/01/24
20:36:24 1.12
--- jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java 2001/03/06
17:24:44
***************
*** 53,59 ****
sql += (first ? "" : ",") +
cmpField.getColumnName() + " " +
! cmpField.getSQLType();
first = false;
--- 53,60 ----
sql += (first ? "" : ",") +
cmpField.getColumnName() + " " +
! cmpField.getSQLType() +
! cmpField.getNullable();
first = false;