Hi King
Thanks for Ur comments. My comments are inline.
King Wang wrote:
> Hi Pramod,
> There are some issues on your changes:
>
> 1. If there is @Column defined and the value is passed from a
> Databasefield object, your change will only set the type name on the
> field definition, but omit all those setter calls(PK, and those you
> just added allowNull, unique) which should be called no matter if
> @Column annotation is defined. The new filed definition would lose
> some data passed through the database field.
>
Yes U are right.
> 2. I am not sure if this setting is right:
> fieldDef.setSize(dbField.getLength());
> dbField.length is the field column name size (in Oracle, the limit
> is 30 for column size). field definition size is the size of the field
> itself (e.g. Varchar2 size 255). Those are two different things.
>
In the EJB3.0 spec the length field deals only with the length Pof a
String field(default being 255), whereas the scale, precision fields are
for decimal fields. So atleast from the code that I saw in
oracle/toplink/essentials/internal/annotations/EJBAnnotationsProcessor.java,
did not think that the dbField.length had to do with the column size.
Tom, can U comment on this.
> 3. We may want to always set the size and subsize passed through the
> database field, regardless the field type. Default value ("-1") would
> be set for some non-applied types, but that should be ok.
Refer to point 2, for the difference in getting the size for a String
and decimal field.
> King
>
I have attached just the changed method below :
private FieldDefinition getFieldDefFromDBField(DatabaseField dbField,
boolean isPrimaryKey) {
FieldDefinition fieldDef = (FieldDefinition)
this.fieldMap.get(dbField);
if (fieldDef == null) {
//not built yet, build one
fieldDef = new FieldDefinition();
fieldDef.setName(dbField.getName());
if (dbField.getColumnDefinition().length() > 0) {
fieldDef.setTypeName(dbField.getColumnDefinition());
} else {
Class fieldType = dbField.getType();
if ((fieldType == null) || (!fieldType.isPrimitive() &&
(new
DatabaseSessionImpl(project).getPlatform().getFieldTypeDefinition(fieldType)
== null))) {
//TODO: log a warning for inaccessiable type or not
convertable type.
AbstractSessionLog.getLog().log(SessionLog.FINEST,
"field_type_set_to_java_lang_string", dbField.getQualifiedName(),
fieldType);
//set the default type (lang.String) to all
un-resolved java type, like null, Number, util.Date, NChar/NType, Calendar
//sql.Blob/Clob, Object, or unknown type). Please
refer to bug 4352820.
fieldDef.setType(ClassConstants.STRING);
} else {
//need to convert the primitive type if applied.
fieldDef.setType(ConversionManager.getObjectClass(fieldType));
}
}
if (fieldType.getName().equals("java.lang.String")) {
fieldDef.setSize(dbField.getLength());
} else if (fieldType.getName().equals("java.math.BigDecimal")) {
fieldDef.setSize(dbField.getPrecision());
fieldDef.setSubSize(dbField.getScale());
}
fieldDef.setIsPrimaryKey(isPrimaryKey);
fieldDef.setShouldAllowNull(dbField.isNullable());
fieldDef.setUnique(dbField.isUnique());
fieldMap.put(dbField, fieldDef);
}
return fieldDef;
}
---------------------------------------
Thanks
Pramod