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 // user-given specifics to override it
int type = tmplate.getType(); int type = tmplate.getType();
int size = tmplate.getSize(); int size = tmplate.getSize();
if (type == Types.OTHER) if (type == Types.OTHER) {
type = dict.getJDBCType(tmplate.getJavaType(), size == -1); 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; boolean ttype = true;
int otype = type; int otype = type;
String typeName = tmplate.getTypeName(); String typeName = tmplate.getTypeName();

View File

@ -1479,12 +1479,21 @@ public class DBDictionary
///////// /////////
// Types // Types
///////// /////////
/** /**
* Return the preferred {@link Types} constant for the given * Return the preferred {@link Types} constant for the given
* {@link JavaTypes} or {@link JavaSQLTypes} constant. * {@link JavaTypes} or {@link JavaSQLTypes} constant.
*/ */
public int getJDBCType(int metaTypeCode, boolean lob) { 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) { if (lob) {
switch (metaTypeCode) { switch (metaTypeCode) {
case JavaTypes.STRING: case JavaTypes.STRING:
@ -1510,10 +1519,20 @@ public class DBDictionary
return getPreferredType(Types.CHAR); return getPreferredType(Types.CHAR);
case JavaTypes.DOUBLE: case JavaTypes.DOUBLE:
case JavaTypes.DOUBLE_OBJ: 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:
case JavaTypes.FLOAT_OBJ: 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:
case JavaTypes.INT_OBJ: case JavaTypes.INT_OBJ:
return getPreferredType(Types.INTEGER); return getPreferredType(Types.INTEGER);

View File

@ -40,18 +40,18 @@ public class TestPrecisionMapping extends SingleEMFTestCase {
testBigDecimalMapping("", Types.NUMERIC, 0, 0); testBigDecimalMapping("", Types.NUMERIC, 0, 0);
} }
public void testPrecisionOnly() { public void testPrecisionOnly() {
// testDoubleMapping("Precis", Types.NUMERIC, 10, 0); testDoubleMapping("Precis", Types.NUMERIC, 10, 0);
testBigDecimalMapping("Precis", Types.NUMERIC, 10, 0); testBigDecimalMapping("Precis", Types.NUMERIC, 10, 0);
} }
public void testScaleOnly() { public void testScaleOnly() {
// testDoubleMapping("Scale", Types.NUMERIC, 0 , 10); testDoubleMapping("Scale", Types.NUMERIC, 0, 10);
testBigDecimalMapping("Scale", Types.NUMERIC, 0, 10); testBigDecimalMapping("Scale", Types.NUMERIC, 0, 10);
} }
public void testPrecisionAndScale() { public void testPrecisionAndScale() {
// testDoubleMapping("PrecisScale", Types.NUMERIC,10,10); testDoubleMapping("PrecisScale", Types.NUMERIC,10,10);
testBigDecimalMapping("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()); assertEquals(expectedScale, cols[0].getDecimalDigits());
} }
} }
} }