mirror of
https://github.com/apache/openjpa.git
synced 2025-02-21 09:35:40 +00:00
OPENJPA-1224. Updated DBDictionary and AbstractDB2Dictionary to properly support java.math.BigDecimal.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@820050 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c8d1003612
commit
c06481b452
@ -29,7 +29,6 @@ public abstract class AbstractDB2Dictionary
|
||||
public int varcharCastLength = 1000;
|
||||
|
||||
public AbstractDB2Dictionary() {
|
||||
numericTypeName = "DOUBLE";
|
||||
bitTypeName = "SMALLINT";
|
||||
smallintTypeName = "SMALLINT";
|
||||
tinyintTypeName = "SMALLINT";
|
||||
|
@ -404,7 +404,7 @@ public class DBDictionary
|
||||
public DBDictionary() {
|
||||
fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{
|
||||
"BIGINT", "BIT", "BLOB", "CLOB", "DATE", "DECIMAL", "DISTINCT",
|
||||
"DOUBLE", "FLOAT", "INTEGER", "JAVA_OBJECT", "NULL", "NUMERIC",
|
||||
"DOUBLE", "FLOAT", "INTEGER", "JAVA_OBJECT", "NULL",
|
||||
"OTHER", "REAL", "REF", "SMALLINT", "STRUCT", "TIME", "TIMESTAMP",
|
||||
"TINYINT",
|
||||
}));
|
||||
|
@ -19,6 +19,8 @@
|
||||
package org.apache.openjpa.persistence.identity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@ -29,6 +31,7 @@ import javax.persistence.Id;
|
||||
public class SQLBigDecimalIdEntity {
|
||||
|
||||
@Id
|
||||
@Column(precision=15)
|
||||
private BigDecimal id;
|
||||
private int data;
|
||||
|
||||
|
@ -19,16 +19,11 @@
|
||||
package org.apache.openjpa.persistence.identity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
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.OpenJPAEntityManagerFactorySPI;
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
|
||||
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
|
||||
/**
|
||||
@ -48,17 +43,6 @@ public class TestSQLBigDecimalId
|
||||
SQLBigDecimalIdEntity e = new SQLBigDecimalIdEntity();
|
||||
e.setId(decimal);
|
||||
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();
|
||||
em.getTransaction().begin();
|
||||
@ -71,6 +55,29 @@ public class TestSQLBigDecimalId
|
||||
e = em.find(SQLBigDecimalIdEntity.class, decimal);
|
||||
assertEquals(1, e.getData());
|
||||
em.close();
|
||||
|
||||
}
|
||||
|
||||
public void testQuery() {
|
||||
int data = 156;
|
||||
BigDecimal decimal = new BigDecimal(1234);
|
||||
SQLBigDecimalIdEntity e = new SQLBigDecimalIdEntity();
|
||||
e.setId(decimal);
|
||||
e.setData(data);
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist(e);
|
||||
em.getTransaction().commit();
|
||||
|
||||
SQLBigDecimalIdEntity e2 =
|
||||
(SQLBigDecimalIdEntity) em.createQuery("SELECT a FROM SQLBigDecimalIdEntity a WHERE a.data=" + data)
|
||||
.getSingleResult();
|
||||
|
||||
// This would fail prior to OPENJPA-1224.
|
||||
assertEquals(e, e2);
|
||||
em.close();
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user