persistence@glassfish.java.net

[Fwd: Re: Issue 134 - _at_Column attributes are ignored during java2db]

From: Pramod Gopinath <Pramod.Gopinath_at_Sun.COM>
Date: Tue, 17 Jan 2006 14:38:14 -0800

Hi King
 Not sure if U had received this email that I had sent out last week.
Hence resending it again.

Thanks
Pramod

-------- Original Message --------
Subject: Re: Issue 134 - @Column attributes are ignored during java2db
Date: Fri, 13 Jan 2006 12:04:31 -0800
From: Pramod Gopinath <pramod.gopinath_at_sun.com>
To: persistence_at_glassfish.dev.java.net, Tom Ware <TOM.WARE_at_oracle.com>
CC: Peter Krogh <PETER.KROGH_at_oracle.com>, Robert Campbell
<ROBERT.CAMPBELL_at_oracle.com>
References: <43BAF226.95289B32_at_sun.COM> <43C2B096.2030304_at_sun.com>
<43C2B204.3070209_at_oracle.com> <43C3153E.7090202_at_sun.com>
<43C3BB61.4080405_at_oracle.com> <43C462F8.8010606_at_sun.com>
<43C6BC90.3090908_at_oracle.com>



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