OPENJPA-1224: Updating DBDictionaries to support setting precision on a BigDecimal column.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@890486 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2009-12-14 21:31:31 +00:00
parent 6cee09c8c9
commit 3067245dac
3 changed files with 10 additions and 18 deletions

View File

@ -29,7 +29,10 @@ public abstract class AbstractDB2Dictionary
public int varcharCastLength = 1000; public int varcharCastLength = 1000;
public AbstractDB2Dictionary() { public AbstractDB2Dictionary() {
numericTypeName = "DOUBLE"; // http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.java.doc
// /doc/rjvjdata.htm
// http://db.apache.org/derby/docs/10.3/ref/rrefsqlj12362.html
numericTypeName = "DECIMAL";
bitTypeName = "SMALLINT"; bitTypeName = "SMALLINT";
smallintTypeName = "SMALLINT"; smallintTypeName = "SMALLINT";
tinyintTypeName = "SMALLINT"; tinyintTypeName = "SMALLINT";
@ -69,6 +72,9 @@ public abstract class AbstractDB2Dictionary
// the equivalent "X JOIN Y ON 1 = 1" // the equivalent "X JOIN Y ON 1 = 1"
crossJoinClause = "JOIN"; crossJoinClause = "JOIN";
requiresConditionForCrossJoin = true; requiresConditionForCrossJoin = true;
// DB2 / Derby allows precision to be set on a DECIMAL column.
fixedSizeTypeNameSet.remove("DECIMAL");
} }
public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,

View File

@ -145,6 +145,8 @@ public class MySQLDictionary
"ZEROFILL" })); "ZEROFILL" }));
delimiter = "`"; delimiter = "`";
fixedSizeTypeNameSet.remove("NUMERIC");
} }
public void connectedConfiguration(Connection conn) throws SQLException { public void connectedConfiguration(Connection conn) throws SQLException {

View File

@ -24,10 +24,6 @@ import javax.persistence.EntityManager;
import junit.textui.TestRunner; import junit.textui.TestRunner;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.jdbc.sql.MySQLDictionary;
import org.apache.openjpa.persistence.test.AllowFailure;
import org.apache.openjpa.persistence.test.SingleEMFTestCase; import org.apache.openjpa.persistence.test.SingleEMFTestCase;
/** /**
@ -48,18 +44,6 @@ public class TestSQLBigDecimalId
e.setId(decimal); e.setId(decimal);
e.setData(1); e.setData(1);
// trigger schema definition
JDBCConfiguration jdbccfg = (JDBCConfiguration) emf.getConfiguration();
DBDictionary dict = jdbccfg.getDBDictionaryInstance();
// currently BigDecimal is mapped to NUMERIC column type. This causes
// truncation error from MySQL. Without knowing the implication of changing the
// mapping of BigDecimal universally to DOUBLE, I will just change the mapping
// for this test case.
if (dict instanceof MySQLDictionary) {
dict.numericTypeName = "DOUBLE";
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();
em.persist(e); em.persist(e);
@ -74,7 +58,6 @@ public class TestSQLBigDecimalId
} }
@AllowFailure
public void testQuery() { public void testQuery() {
int data = 156; int data = 156;
BigDecimal decimal = new BigDecimal(1234); BigDecimal decimal = new BigDecimal(1234);
@ -91,6 +74,7 @@ public class TestSQLBigDecimalId
(SQLBigDecimalIdEntity) em.createQuery("SELECT a FROM SQLBigDecimalIdEntity a WHERE a.data=" + data) (SQLBigDecimalIdEntity) em.createQuery("SELECT a FROM SQLBigDecimalIdEntity a WHERE a.data=" + data)
.getSingleResult(); .getSingleResult();
// This would fail prior to OPENJPA-1224.
assertEquals(e, e2); assertEquals(e, e2);
em.close(); em.close();