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/01/29 17:43:44 UTC
svn commit: r738918 - in
/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache:
Invoice.java InvoiceKey.java LineItem.java
TestNonPrimaryKeyQueryParameters.java
Author: faywang
Date: Thu Jan 29 16:43:44 2009
New Revision: 738918
URL: http://svn.apache.org/viewvc?rev=738918&view=rev
Log:
OPENJPA-838: check in testcase
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java?rev=738918&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Invoice.java Thu Jan 29 16:43:44 2009
@@ -0,0 +1,80 @@
+/**
+ * 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.jdbc.query.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.*;
+/**
+ * @version $Revision$ $Date$
+ */
+@Entity
+@IdClass(InvoiceKey.class)
+public class Invoice {
+
+ @Id
+ private int id;
+ @Id
+ private String brandName;
+
+ private double price;
+
+ @OneToMany(cascade={CascadeType.ALL})
+ private List<LineItem> lineItems = new ArrayList<LineItem>();
+
+ public Invoice() {
+ }
+
+ public Invoice(int id, String brandName, double price) {
+ this.id = id;
+ this.brandName = brandName;
+ this.price = price;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getBrandName() {
+ return brandName;
+ }
+
+ public void setBrandName(String brandName) {
+ this.brandName = brandName;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ public List<LineItem> getLineItems() {
+ return lineItems;
+ }
+
+ public void setLineItems(List<LineItem> lineItems) {
+ this.lineItems = lineItems;
+ }
+}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java?rev=738918&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/InvoiceKey.java Thu Jan 29 16:43:44 2009
@@ -0,0 +1,54 @@
+/**
+ * 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.jdbc.query.cache;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class InvoiceKey {
+
+ private int id;
+ private String brandName;
+
+ public InvoiceKey() {
+ }
+
+ public InvoiceKey(int id, String brandName) {
+ this.id = id;
+ this.brandName = brandName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ InvoiceKey invoiceKey = (InvoiceKey) o;
+
+ if (id != invoiceKey.id) return false;
+ if (!brandName.equals(invoiceKey.brandName)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + brandName.hashCode();
+ return result;
+ }
+}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java?rev=738918&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/LineItem.java Thu Jan 29 16:43:44 2009
@@ -0,0 +1,65 @@
+/**
+ * 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.jdbc.query.cache;
+import javax.persistence.*;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@Entity
+public class LineItem {
+
+ @Id
+ private String id;
+ private int quantity;
+
+ @ManyToOne
+ private Invoice invoice;
+
+ public LineItem() {
+ }
+
+ public LineItem(String id, int quantity) {
+ this.id = id;
+ this.quantity = quantity;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ public Invoice getInvoice() {
+ return invoice;
+ }
+
+ public void setInvoice(Invoice invoice) {
+ this.invoice = invoice;
+ }
+}
+
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java?rev=738918&r1=738917&r2=738918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestNonPrimaryKeyQueryParameters.java Thu Jan 29 16:43:44 2009
@@ -18,10 +18,10 @@
*/
package org.apache.openjpa.persistence.jdbc.query.cache;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.List;
import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
@@ -45,18 +45,21 @@
*
* @author Pinaki Poddar
* @author Vikram Bhatia
- *
+ * @author David Blevins
*/
public class TestNonPrimaryKeyQueryParameters extends SQLListenerTestCase {
private static final int FULLTIME_EMPLOYEE_COUNT = 3;
private static final int PARTTIME_EMPLOYEE_COUNT = 2;
+ private static final int LINEITEM_PER_INVOICE = 1;
private static final String DEPT_NAME = "ENGINEERING";
public void setUp() {
super.setUp(CLEAR_TABLES, Department.class, Employee.class,
FullTimeEmployee.class, PartTimeEmployee.class,
+ Invoice.class, LineItem.class,
"openjpa.jdbc.QuerySQLCache", "true");
createDepartment(DEPT_NAME);
+ createInvoice();
sql.clear();
}
@@ -80,6 +83,7 @@
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("SELECT d from Department d");
+
Department dept = (Department) query.getSingleResult();
assertEquals(FULLTIME_EMPLOYEE_COUNT, dept.getFullTimeEmployees()
@@ -102,6 +106,10 @@
.size());
assertSQL(".* AND t0.TYPE = .*");
+
+ Invoice invoice = em.find(Invoice.class, new InvoiceKey(1, "Red"));
+ List<LineItem> list = invoice.getLineItems();
+ assertEquals(LINEITEM_PER_INVOICE, list.size());
em.close();
}
@@ -153,4 +161,20 @@
em.close();
}
+
+ private void createInvoice() {
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tran = em.getTransaction();
+ tran.begin();
+ Invoice invoice = new Invoice(1, "Red", 1.30);
+ for (int i = 1; i <= LINEITEM_PER_INVOICE; i++) {
+ LineItem item = new LineItem(String.valueOf(i), 10);
+ item.setInvoice(invoice);
+ invoice.getLineItems().add(item);
+ em.persist(invoice);
+ }
+ em.flush();
+ tran.commit();
+ em.close();
+ }
}