OPENJPA-1466 Fix Junit test failures on Oracle

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@901295 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Catalina Wei 2010-01-20 17:33:59 +00:00
parent 9e73688412
commit 4adf1c68a7
4 changed files with 53 additions and 9 deletions

View File

@ -19,23 +19,20 @@
package org.apache.openjpa.persistence.criteria;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.Parameter;
import javax.persistence.Query;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Fetch;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.ListJoin;
@ -49,6 +46,7 @@ import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Metamodel;
import org.apache.openjpa.jdbc.sql.OracleDictionary;
import org.apache.openjpa.persistence.test.AllowFailure;
/**
@ -1463,8 +1461,12 @@ public class TestTypesafeCriteria extends CriteriaTest {
List result = q.getResultList();
}
public void testCurrentTimeReturnsSQLTypes() {
if (getDictionary() instanceof OracleDictionary) {
// Oracle does not have CURRENT_TIME function, nor does it support DB generated identity
return;
}
em.getTransaction().begin();
Product pc = new Product();
em.persist(pc);
@ -1481,6 +1483,44 @@ public class TestTypesafeCriteria extends CriteriaTest {
Object result = tq.getSingleResult();
assertTrue(result.getClass() + " not instance of Time", result instanceof Time);
}
public void testCurrentDateReturnsSQLTypes() {
em.getTransaction().begin();
Order pc = new Order();
em.persist(pc);
em.getTransaction().commit();
int oid = pc.getId();
CriteriaQuery<Date> cquery = cb.createQuery(Date.class);
Root<Order> order = cquery.from(Order.class);
cquery.select(cb.currentDate());
cquery.where(cb.equal(order.get(Order_.id), oid));
TypedQuery<Date> tq = em.createQuery(cquery);
Object result = tq.getSingleResult();
assertTrue(result.getClass() + " not instance of Date", result instanceof Date);
}
public void testCurrentTimestampReturnsSQLTypes() {
em.getTransaction().begin();
Order pc = new Order();
em.persist(pc);
em.getTransaction().commit();
int oid = pc.getId();
CriteriaQuery<Timestamp> cquery = cb.createQuery(Timestamp.class);
Root<Order> order = cquery.from(Order.class);
cquery.select(cb.currentTimestamp());
cquery.where(cb.equal(order.get(Order_.id), oid));
TypedQuery<Timestamp> tq = em.createQuery(cquery);
Object result = tq.getSingleResult();
assertTrue(result.getClass() + " not instance of Timestamp", result instanceof Timestamp);
}
// public void testInMemoryAccessPath() {

View File

@ -28,7 +28,7 @@ public class TestDetachNoStateField extends SingleEMFTestCase {
@Override
protected void setUp(Object... props) {
super.setUp(CLEAR_TABLES, "openjpa.DetachState", "loaded(DetachedStateField=false)",
super.setUp(DROP_TABLES, "openjpa.DetachState", "loaded(DetachedStateField=false)",
NoDetachedStateEntityPropertyAccess.class, NoDetachedStateEntityFieldAccess.class);
loadDB();
}
@ -78,9 +78,9 @@ public class TestDetachNoStateField extends SingleEMFTestCase {
void loadDB() {
OpenJPAEntityManagerSPI em = emf.createEntityManager();
em.getTransaction().begin();
em.createNativeQuery("INSERT INTO NoDetachedStateEntityPropertyAccess (ID,VERSION) VALUES (1,0)")
em.createNativeQuery("INSERT INTO PropertyAccessNoDetachedState (ID,VERSION) VALUES (1,0)")
.executeUpdate();
em.createNativeQuery("INSERT INTO NoDetachedStateEntityFieldAccess (ID,VERSION) VALUES (1,0)")
em.createNativeQuery("INSERT INTO FieldAccessNoDetachedState (ID,VERSION) VALUES (1,0)")
.executeUpdate();
em.getTransaction().commit();
em.close();

View File

@ -24,9 +24,11 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name="FieldAccessNoDetachedState")
public class NoDetachedStateEntityFieldAccess {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)

View File

@ -23,9 +23,11 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name="PropertyAccessNoDetachedState")
public class NoDetachedStateEntityPropertyAccess {
int id;
int version;