persistence@glassfish.java.net

Issue 348 : For Derby java2db generated DECIMAL field instead of DECIMAL(10,2)

From: Pramod Gopinath <Pramod.Gopinath_at_Sun.COM>
Date: Tue, 07 Mar 2006 14:14:37 -0800

Hi Gordon
    The user has provided the @Column annotation for a decimal type of
field and accepts the precision and scale supplied in the entity class
to be used for creating the corresponding field. For Derby this does not
work.

The issue is that in DerbyPlatform when the field types are being built
we are creating FieldTypeDefinition passing in "false". This boolean
property implies that we would be ignoring the user supplied precision
and scale. As part of solving this issue for Derby found that this
problem would also happen for the other platforms. Based on the database
documentation for Mysql, Postgresql and Derby I have changed the
platforms to allow precision and/or scale to be changed based on user
supplied values. I have attached the changed files. I have also
provided links to the database datatype documentations that I referred
to when making these changes.

Thanks
Pramod


Derby Documentation link related to Datatypes :
http://db.apache.org/derby/docs/dev/ref/rrefsqlj41207.html


MYSQL5 link related to Datatypes :
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

PostgreSQL link relaed to Datatypes :
http://www.postgresql.org/docs/8.1/interactive/datatype.html



Index: src/java/oracle/toplink/essentials/platform/database/DerbyPlatform.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/platform/database/DerbyPlatform.java,v
retrieving revision 1.4
diff -r1.4 DerbyPlatform.java
194c194
< fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT", false));
---
>         fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT"));
199,200c199,200
<         fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL", false));
<         fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL", false));
---
>         fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL"));
>         fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL"));
Index: src/java/oracle/toplink/essentials/platform/database/MySQL4Platform.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/platform/database/MySQL4Platform.java,v
retrieving revision 1.3
diff -r1.3 MySQL4Platform.java
119,120c119,120
<         fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT", false));
<         fieldTypeMapping.put(Double.class, new FieldTypeDefinition("DOUBLE", false));
---
>         fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT"));
>         fieldTypeMapping.put(Double.class, new FieldTypeDefinition("DOUBLE"));
124,125c124,125
<         fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL(38)", false));
<         fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL(38)", false));
---
>         fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL(38)"));
>         fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL(38)"));
Index: src/java/oracle/toplink/essentials/platform/database/PostgreSQLPlatform.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/platform/database/PostgreSQLPlatform.java,v
retrieving revision 1.3
diff -r1.3 PostgreSQLPlatform.java
191c191
<         fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT", false));
---
>         fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT"));
196,197c196,197
<         fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL(38)", false));
<         fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL(38)", false));
---
>         fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL(38)"));
>         fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL(38)"));
Index: src/java/oracle/toplink/essentials/tools/schemaframework/TableSequenceDefinition.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/TableSequenceDefinition.java,v
retrieving revision 1.2
diff -r1.2 TableSequenceDefinition.java
156,157c156,157
<         definition.setName(getSequenceTableName());
<         definition.addField(getSequenceNameFieldName(), String.class, 50);
---
>         definition.setName(getSequenceTableName());   
>         definition.addPrimaryKeyField(getSequenceNameFieldName(), String.class, 50); //PG-> 
158a159
>