openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r820050 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/
Date Tue, 29 Sep 2009 18:12:16 GMT
Author: curtisr7
Date: Tue Sep 29 18:12:15 2009
New Revision: 820050

URL: http://svn.apache.org/viewvc?rev=820050&view=rev
Log:
OPENJPA-1224. Updated DBDictionary and AbstractDB2Dictionary to properly support java.math.BigDecimal.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/SQLBigDecimalIdEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java?rev=820050&r1=820049&r2=820050&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
Tue Sep 29 18:12:15 2009
@@ -29,7 +29,6 @@
     public int varcharCastLength = 1000;
 
     public AbstractDB2Dictionary() {
-        numericTypeName = "DOUBLE";
         bitTypeName = "SMALLINT";
         smallintTypeName = "SMALLINT";
         tinyintTypeName = "SMALLINT";

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=820050&r1=820049&r2=820050&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Tue Sep 29 18:12:15 2009
@@ -404,7 +404,7 @@
     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",
         }));

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/SQLBigDecimalIdEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/SQLBigDecimalIdEntity.java?rev=820050&r1=820049&r2=820050&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/SQLBigDecimalIdEntity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/SQLBigDecimalIdEntity.java
Tue Sep 29 18:12:15 2009
@@ -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 @@
 public class SQLBigDecimalIdEntity {
 
     @Id
+    @Column(precision=15)
     private BigDecimal id;
     private int data;
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java?rev=820050&r1=820049&r2=820050&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java
Tue Sep 29 18:12:15 2009
@@ -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 @@
         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 @@
         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) {



Mime
View raw message