openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r812689 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc: maps/m2mmapex10/ query/
Date Tue, 08 Sep 2009 20:45:07 GMT
Author: faywang
Date: Tue Sep  8 20:45:07 2009
New Revision: 812689

URL: http://svn.apache.org/viewvc?rev=812689&view=rev
Log:
fix test case problem for MySQL (microseconds are not stored in the MySQL Temporal column)

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java?rev=812689&r1=812688&r2=812689&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java
Tue Sep  8 20:45:07 2009
@@ -78,4 +78,26 @@
         }
         return true;
     }    
+
+    /*
+     * The following change is for the comparison of Date object. In MySQL, 
+     * "microseconds cannot be stored into a column of any temporal data type. 
+     * Any microseconds part is discarded. " (http://dev.mysql.com/doc/refman/5.1/en/datetime.html).

+     * As a result, when the value retrieved from the database will be different from the

+     * original value in the memory for the loss of microsecond. The fix is to call toString

+     * (which will strip the microseconds0 on the Date object and compare the String values.
+     */
+    
+    public static Employee findEmpl(Map<EmployeePK, Employee> map, EmployeePK key)
{
+        String name = key.getName();
+        String bDateStr = key.getBDay().toString();
+        Set<EmployeePK> keys = map.keySet();
+        for (EmployeePK thisKey : keys) {
+           if (name.equals(thisKey.getName()) && 
+               bDateStr.equals(thisKey.getBDay().toString())) {
+               return map.get(thisKey);
+           }
+        }
+        return null;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java?rev=812689&r1=812688&r2=812689&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java
Tue Sep  8 20:45:07 2009
@@ -49,7 +49,7 @@
             return false;
         EmployeePK pk = (EmployeePK) o;
         if (pk.name.equals(name) &&
-            pk.bDay.equals(bDay))
+            pk.bDay.toString().equals(bDay.toString()))
             return true;    
         return false;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java?rev=812689&r1=812688&r2=812689&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java
Tue Sep  8 20:45:07 2009
@@ -70,11 +70,15 @@
             (Collection<Map.Entry<EmployeePK, Employee>>) emps.entrySet();
         for (Map.Entry<EmployeePK, Employee> entry : entries) {
             EmployeePK key = entry.getKey();
-            Employee e0 = map.get(key);
-            Employee e = emps.get(key);
+            Employee e0 = Employee.findEmpl(map, key);
+            Employee e = Employee.findEmpl(emps, key);
+            if ((e == null && e0 != null) || (e != null && e0 == null))
+                return false;
             if (!e.getEmpPK().equals(e0.getEmpPK()))
                 return false;
         }
         return true;
     }    
+    
+    
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java?rev=812689&r1=812688&r2=812689&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java
Tue Sep  8 20:45:07 2009
@@ -46,8 +46,8 @@
     public List<EmployeePK> empPKs = new ArrayList<EmployeePK>();
     public List<PhonePK> phonePKs = new ArrayList<PhonePK>();
 
-    public Map<EmployeePK, Employee> empMap = 
-        new HashMap<EmployeePK, Employee>();
+    public Map<String, Employee> empMap = 
+        new HashMap<String, Employee>();
     public Map<PhonePK, PhoneNumber> phoneMap = 
         new HashMap<PhonePK, PhoneNumber>();
 
@@ -190,7 +190,7 @@
         EntityTransaction tran = em.getTransaction();
         for (int i = 0; i < numEmployees; i++) {
             Employee e = createEmployee(em, empId++);
-            empMap.put(e.getEmpPK(), e);
+            empMap.put(e.getEmpPK().getName(), e);
         }
         tran.begin();
         em.flush();
@@ -200,7 +200,8 @@
 
     public Employee createEmployee(EntityManager em, int id) {
         Employee e = new Employee();
-        EmployeePK empPK = new EmployeePK("e" + id, new Date());
+        Date bDay = new Date(System.currentTimeMillis() - 1000000);
+        EmployeePK empPK = new EmployeePK("e" + id, bDay);
         empPKs.add(empPK);
         e.setEmpPK(empPK);
         e.setSalary(1000);
@@ -264,7 +265,7 @@
 
     public void assertEmployee(Employee e) throws Exception {
         EmployeePK empPK = e.getEmpPK();
-        Employee e0 = empMap.get(empPK);
+        Employee e0 = empMap.get(empPK.getName());
         Map<PhonePK, PhoneNumber> phones = e.getPhoneNumbers();
         Map<PhonePK, PhoneNumber> phones0 = e0.getPhoneNumbers();
         Assert.assertEquals(phones0.size(), phones.size());
@@ -300,7 +301,8 @@
         for (Map.Entry<EmployeePK, Employee> entry0 : entrySets0) {
             EmployeePK key0 = entry0.getKey();
             Employee e0 = entry0.getValue();
-            Employee e = es.get(key0);
+            //Employee e = es.get(key0);
+            Employee e = Employee.findEmpl(es, key0);
             if (!e0.equals(e))
                 throw new Exception("Assertion failure");
         }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java?rev=812689&r1=812688&r2=812689&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
Tue Sep  8 20:45:07 2009
@@ -85,7 +85,7 @@
 				} catch (ParseException e) {
 					mag.setDatePublished(null);
 				}
-                mag.setTsPublished(new Timestamp(System.currentTimeMillis()));
+                mag.setTsPublished(new Timestamp(System.currentTimeMillis() - 100000));
 				
 				em.persist(pub);
 			}



Mime
View raw message