You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2009/07/16 06:57:16 UTC

svn commit: r794524 [1/3] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/

Author: faywang
Date: Thu Jul 16 04:57:15 2009
New Revision: 794524

URL: http://svn.apache.org/viewvc?rev=794524&view=rev
Log:
OPENJPA-1143: clean up test cases

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request_.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account_.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJoinCondition.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestSubqueries.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java Thu Jul 16 04:57:15 2009
@@ -129,7 +129,7 @@
         Val other, ExpState otherState) {
         CoalesceExpState cstate = (CoalesceExpState) state;
         for (int i = 0; i < _vals.length; i++)   
-            _vals[i].calculateValue(sel, ctx, cstate.states[i], null, null);
+            _vals[i].calculateValue(sel, ctx, cstate.states[i], other, otherState);
     }
 
     public void groupBy(Select sel, ExpContext ctx, ExpState state) {
@@ -141,7 +141,7 @@
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
-        calculateValue(sel, ctx, state, null, null);
+        calculateValue(sel, ctx, state, (Val)other, otherState);
         SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
         appendTo(sel, ctx, state, buf, 0);
         return buf;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java Thu Jul 16 04:57:15 2009
@@ -19,8 +19,10 @@
 package org.apache.openjpa.persistence.criteria;
 
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.ManyToOne;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 
@@ -40,6 +42,12 @@
     @OneToOne
     private Person owner;
     
+    @ManyToOne
+    private Customer customer;
+    
+    @ManyToOne(optional = false, fetch = FetchType.LAZY)
+    private Product product;
+    
     private String name;
 
     public long getId() {
@@ -77,4 +85,20 @@
     public void setLoan(Integer loan) {
         this.loan = loan;
     }
+    
+    public Product getProduct() {
+        return product;
+    }
+    
+    public void setProduct(Product product) {
+        this.product = product;
+    }
+
+    public Customer getCustomer() {
+        return customer;
+    }
+    
+    public void setCustomer(Customer customer) {
+        this.customer = customer;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account_.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account_.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account_.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account_.java Thu Jul 16 04:57:15 2009
@@ -14,4 +14,6 @@
     public static volatile SingularAttribute<Account,Integer> loan;
     public static volatile SingularAttribute<Account,String> name;
     public static volatile SingularAttribute<Account,Person> owner;
+    public static volatile SingularAttribute<Account,Customer> customer;
+    public static volatile SingularAttribute<Account,Product> product;
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java Thu Jul 16 04:57:15 2009
@@ -207,7 +207,7 @@
             e.printStackTrace(new PrintWriter(w));
             fail("JPQL " + jpql + " failed to execute\r\n" + w);
         }
-        
+        em.clear();
         try {
             cSQL = executeQueryAndCollectSQL(cQ);
         } catch (Exception e) {
@@ -235,6 +235,31 @@
         }
     }
     
+    void executeAndCompareSQL(String jpql, String expectedSQL) {
+        Query jQ = em.createQuery(jpql);
+
+        List<String> jSQL = null;
+        List<String> cSQL = null;
+        try {
+            jSQL = executeQueryAndCollectSQL(jQ);
+        } catch (Exception e) {
+            StringWriter w = new StringWriter();
+            e.printStackTrace(new PrintWriter(w));
+            fail("JPQL " + jpql + " failed to execute\r\n" + w);
+        }
+        
+        printSQL("Target SQL for JPQL", jSQL);
+        
+        for (int i = 0; i < jSQL.size(); i++) {
+            if (!jSQL.get(i).equals(expectedSQL)) {
+                printSQL("SQL for JPQL", jSQL);
+                printSQL("Expected SQL", cSQL);
+                assertEquals(i + "-th Expected SQL and SQL for JPQL: " + jpql + " are different",
+                     expectedSQL, jSQL.get(i));
+            }
+        }
+    }
+    
     void printSQL(String header, List<String> sqls) {
         System.err.println(header);
         for (int i = 0; sqls != null && i < sqls.size(); i++) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java Thu Jul 16 04:57:15 2009
@@ -43,7 +43,7 @@
 	private String lastName;
 	private String name;
 	
-	@OneToMany
+	@OneToMany(mappedBy="customer")
 	private Set<Order> orders = new HashSet<Order>(); 
 	
 	private int status;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java Thu Jul 16 04:57:15 2009
@@ -38,6 +38,7 @@
     private int quantity;
 	private double totalCost;
 	private int count;
+	private String name;
 	
 	@ManyToOne
 	private Customer customer;
@@ -93,6 +94,14 @@
         this.delivered = delivered;
     }
 
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+
     public Timestamp getOrderTs() {
         return orderTs;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java Thu Jul 16 04:57:15 2009
@@ -15,6 +15,7 @@
     public static volatile SingularAttribute<Order,Customer> customer;
     public static volatile SingularAttribute<Order,Boolean> delivered;
     public static volatile SingularAttribute<Order,Integer> id;
+    public static volatile SingularAttribute<Order,String> name;
     public static volatile ListAttribute<Order,LineItem> lineItems;
     public static volatile SingularAttribute<Order,Timestamp> orderTs;
     public static volatile SingularAttribute<Order,Integer> quantity;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java?rev=794524&r1=794523&r2=794524&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java Thu Jul 16 04:57:15 2009
@@ -20,6 +20,7 @@
 import javax.persistence.*;
 
 @Entity
+@Table(name="CR_PRD")
 public class Product {
 	@Id 
 	@GeneratedValue(strategy=GenerationType.IDENTITY)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request.java?rev=794524&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request.java Thu Jul 16 04:57:15 2009
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.criteria;
+
+import java.sql.Date;
+
+import javax.persistence.*;
+
+@Entity
+public class Request {
+     @Id
+     int id;
+     
+     private short status;
+    
+     @ManyToOne(optional = false, fetch = FetchType.LAZY)
+     private Account account;
+
+     Date requestTime;
+
+     public int getId() {
+         return id;
+     }
+     
+     public void setId(int id) {
+         this.id = id;
+     }
+     
+     public short getStatus() {
+         return status;
+     }
+
+     public void setStatus(short status) {
+         this.status = status;
+     }
+
+     
+     public Account getAccount() {
+         return account;
+     }
+
+     public void setAccount(Account account) {
+         this.account = account;
+     }
+    
+     public Date getRequestTime() {
+         return requestTime;
+     }
+     
+     public void setRequestTime(Date requestTime) {
+         this.requestTime = requestTime;
+     }
+     
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request_.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request_.java?rev=794524&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request_.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Request_.java Thu Jul 16 04:57:15 2009
@@ -0,0 +1,18 @@
+/** 
+ *  Generated by OpenJPA MetaModel Generator Tool.
+**/
+
+package org.apache.openjpa.persistence.criteria;
+
+import java.sql.Date;
+
+import javax.persistence.metamodel.SingularAttribute;
+
+@javax.persistence.metamodel.StaticMetamodel
+(value=org.apache.openjpa.persistence.criteria.Request.class)
+public class Request_ {
+    public static volatile SingularAttribute<Request,Short> status;
+    public static volatile SingularAttribute<Request,Integer> id;
+    public static volatile SingularAttribute<Request,Account> account;
+    public static volatile SingularAttribute<Request,Date> requestTime;
+}