OPENJPA-213. Scale and precision specified for doubles upgrade column type to NUMERIC.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@749090 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-03-01 20:38:21 +00:00
parent efc6ba4735
commit f3d1704863
3 changed files with 40 additions and 12 deletions

View File

@ -654,8 +654,18 @@ public abstract class MappingInfo
// user-given specifics to override it
int type = tmplate.getType();
int size = tmplate.getSize();
if (type == Types.OTHER)
type = dict.getJDBCType(tmplate.getJavaType(), size == -1);
if (type == Types.OTHER) {
int precis = 0;
int scale = 0;
if(given != null) {
precis = given.getSize();
scale = given.getDecimalDigits();
}
type =
dict.getJDBCType(tmplate.getJavaType(), size == -1, precis,
scale);
}
boolean ttype = true;
int otype = type;
String typeName = tmplate.getTypeName();

View File

@ -1485,6 +1485,15 @@ public class DBDictionary
* {@link JavaTypes} or {@link JavaSQLTypes} constant.
*/
public int getJDBCType(int metaTypeCode, boolean lob) {
return getJDBCType(metaTypeCode, lob, 0, 0);
}
/**
* Return the preferred {@link Types} constant for the given
* {@link JavaTypes} or {@link JavaSQLTypes} constant.
*/
public int getJDBCType(int metaTypeCode, boolean lob, int precis,
int scale) {
if (lob) {
switch (metaTypeCode) {
case JavaTypes.STRING:
@ -1510,10 +1519,20 @@ public class DBDictionary
return getPreferredType(Types.CHAR);
case JavaTypes.DOUBLE:
case JavaTypes.DOUBLE_OBJ:
return getPreferredType(Types.DOUBLE);
if(precis > 0 || scale > 0) {
return getPreferredType(Types.NUMERIC);
}
else {
return getPreferredType(Types.DOUBLE);
}
case JavaTypes.FLOAT:
case JavaTypes.FLOAT_OBJ:
return getPreferredType(Types.REAL);
if(precis > 0 || scale > 0) {
return getPreferredType(Types.NUMERIC);
}
else {
return getPreferredType(Types.REAL);
}
case JavaTypes.INT:
case JavaTypes.INT_OBJ:
return getPreferredType(Types.INTEGER);

View File

@ -41,17 +41,17 @@ public class TestPrecisionMapping extends SingleEMFTestCase {
}
public void testPrecisionOnly() {
// testDoubleMapping("Precis", Types.NUMERIC, 10, 0);
testDoubleMapping("Precis", Types.NUMERIC, 10, 0);
testBigDecimalMapping("Precis", Types.NUMERIC, 10, 0);
}
public void testScaleOnly() {
// testDoubleMapping("Scale", Types.NUMERIC, 0 , 10);
testDoubleMapping("Scale", Types.NUMERIC, 0, 10);
testBigDecimalMapping("Scale", Types.NUMERIC, 0, 10);
}
public void testPrecisionAndScale() {
// testDoubleMapping("PrecisScale", Types.NUMERIC,10,10);
testDoubleMapping("PrecisScale", Types.NUMERIC,10,10);
testBigDecimalMapping("PrecisScale", Types.NUMERIC, 10, 10);
}
@ -83,5 +83,4 @@ public class TestPrecisionMapping extends SingleEMFTestCase {
assertEquals(expectedScale, cols[0].getDecimalDigits());
}
}
}