mirror of https://github.com/apache/openjpa.git
fix test case problem for MySQL (microseconds are not stored in the MySQL Temporal column)
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@812689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
45f79b59af
commit
702a9c6616
|
@ -78,4 +78,26 @@ public class Employee {
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class EmployeePK implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
EmployeePK pk = (EmployeePK) o;
|
EmployeePK pk = (EmployeePK) o;
|
||||||
if (pk.name.equals(name) &&
|
if (pk.name.equals(name) &&
|
||||||
pk.bDay.equals(bDay))
|
pk.bDay.toString().equals(bDay.toString()))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,11 +70,15 @@ public class PhoneNumber {
|
||||||
(Collection<Map.Entry<EmployeePK, Employee>>) emps.entrySet();
|
(Collection<Map.Entry<EmployeePK, Employee>>) emps.entrySet();
|
||||||
for (Map.Entry<EmployeePK, Employee> entry : entries) {
|
for (Map.Entry<EmployeePK, Employee> entry : entries) {
|
||||||
EmployeePK key = entry.getKey();
|
EmployeePK key = entry.getKey();
|
||||||
Employee e0 = map.get(key);
|
Employee e0 = Employee.findEmpl(map, key);
|
||||||
Employee e = emps.get(key);
|
Employee e = Employee.findEmpl(emps, key);
|
||||||
|
if ((e == null && e0 != null) || (e != null && e0 == null))
|
||||||
|
return false;
|
||||||
if (!e.getEmpPK().equals(e0.getEmpPK()))
|
if (!e.getEmpPK().equals(e0.getEmpPK()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase {
|
||||||
public List<EmployeePK> empPKs = new ArrayList<EmployeePK>();
|
public List<EmployeePK> empPKs = new ArrayList<EmployeePK>();
|
||||||
public List<PhonePK> phonePKs = new ArrayList<PhonePK>();
|
public List<PhonePK> phonePKs = new ArrayList<PhonePK>();
|
||||||
|
|
||||||
public Map<EmployeePK, Employee> empMap =
|
public Map<String, Employee> empMap =
|
||||||
new HashMap<EmployeePK, Employee>();
|
new HashMap<String, Employee>();
|
||||||
public Map<PhonePK, PhoneNumber> phoneMap =
|
public Map<PhonePK, PhoneNumber> phoneMap =
|
||||||
new HashMap<PhonePK, PhoneNumber>();
|
new HashMap<PhonePK, PhoneNumber>();
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase {
|
||||||
EntityTransaction tran = em.getTransaction();
|
EntityTransaction tran = em.getTransaction();
|
||||||
for (int i = 0; i < numEmployees; i++) {
|
for (int i = 0; i < numEmployees; i++) {
|
||||||
Employee e = createEmployee(em, empId++);
|
Employee e = createEmployee(em, empId++);
|
||||||
empMap.put(e.getEmpPK(), e);
|
empMap.put(e.getEmpPK().getName(), e);
|
||||||
}
|
}
|
||||||
tran.begin();
|
tran.begin();
|
||||||
em.flush();
|
em.flush();
|
||||||
|
@ -200,7 +200,8 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase {
|
||||||
|
|
||||||
public Employee createEmployee(EntityManager em, int id) {
|
public Employee createEmployee(EntityManager em, int id) {
|
||||||
Employee e = new Employee();
|
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);
|
empPKs.add(empPK);
|
||||||
e.setEmpPK(empPK);
|
e.setEmpPK(empPK);
|
||||||
e.setSalary(1000);
|
e.setSalary(1000);
|
||||||
|
@ -264,7 +265,7 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase {
|
||||||
|
|
||||||
public void assertEmployee(Employee e) throws Exception {
|
public void assertEmployee(Employee e) throws Exception {
|
||||||
EmployeePK empPK = e.getEmpPK();
|
EmployeePK empPK = e.getEmpPK();
|
||||||
Employee e0 = empMap.get(empPK);
|
Employee e0 = empMap.get(empPK.getName());
|
||||||
Map<PhonePK, PhoneNumber> phones = e.getPhoneNumbers();
|
Map<PhonePK, PhoneNumber> phones = e.getPhoneNumbers();
|
||||||
Map<PhonePK, PhoneNumber> phones0 = e0.getPhoneNumbers();
|
Map<PhonePK, PhoneNumber> phones0 = e0.getPhoneNumbers();
|
||||||
Assert.assertEquals(phones0.size(), phones.size());
|
Assert.assertEquals(phones0.size(), phones.size());
|
||||||
|
@ -300,7 +301,8 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase {
|
||||||
for (Map.Entry<EmployeePK, Employee> entry0 : entrySets0) {
|
for (Map.Entry<EmployeePK, Employee> entry0 : entrySets0) {
|
||||||
EmployeePK key0 = entry0.getKey();
|
EmployeePK key0 = entry0.getKey();
|
||||||
Employee e0 = entry0.getValue();
|
Employee e0 = entry0.getValue();
|
||||||
Employee e = es.get(key0);
|
//Employee e = es.get(key0);
|
||||||
|
Employee e = Employee.findEmpl(es, key0);
|
||||||
if (!e0.equals(e))
|
if (!e0.equals(e))
|
||||||
throw new Exception("Assertion failure");
|
throw new Exception("Assertion failure");
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class TestMultipleEntityProjection extends SingleEMFTestCase {
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
mag.setDatePublished(null);
|
mag.setDatePublished(null);
|
||||||
}
|
}
|
||||||
mag.setTsPublished(new Timestamp(System.currentTimeMillis()));
|
mag.setTsPublished(new Timestamp(System.currentTimeMillis() - 100000));
|
||||||
|
|
||||||
em.persist(pub);
|
em.persist(pub);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue