From c0bf7e40d6ff57df1c5679c813192e0a8c82de28 Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Sun, 10 May 2009 08:25:24 +0000 Subject: [PATCH] OPENJPA-1013: check in strictly-typed criteria test cases. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@773314 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/persistence/criteria/Account.java | 54 +- .../openjpa/persistence/criteria/Address.java | 59 +- .../persistence/criteria/Address_.java | 19 + .../openjpa/persistence/criteria/Contact.java | 16 + .../persistence/criteria/Contact_.java | 15 + .../persistence/criteria/Contractor.java | 1 + .../persistence/criteria/Contractor_.java | 11 + .../openjpa/persistence/criteria/Course.java | 42 +- .../openjpa/persistence/criteria/Course_.java | 16 + .../persistence/criteria/CreditCard.java | 39 +- .../persistence/criteria/CreditCard_.java | 16 + .../persistence/criteria/Customer.java | 113 +++- .../persistence/criteria/CustomerDetails.java | 53 ++ .../persistence/criteria/Customer_.java | 25 + .../persistence/criteria/Department.java | 31 +- .../persistence/criteria/Department_.java | 16 + .../persistence/criteria/Employee.java | 85 ++- .../persistence/criteria/Employee_.java | 21 + .../openjpa/persistence/criteria/Exempt.java | 25 +- .../openjpa/persistence/criteria/Exempt_.java | 14 + .../openjpa/persistence/criteria/Item.java | 41 +- .../openjpa/persistence/criteria/Item_.java | 16 + .../persistence/criteria/LineItem.java | 64 +- .../persistence/criteria/LineItem_.java | 18 + .../openjpa/persistence/criteria/Manager.java | 47 +- .../persistence/criteria/Manager_.java | 17 + .../openjpa/persistence/criteria/Movie.java | 43 ++ .../openjpa/persistence/criteria/Movie_.java | 14 + .../openjpa/persistence/criteria/Order.java | 51 +- .../openjpa/persistence/criteria/Order_.java | 19 + .../openjpa/persistence/criteria/Person.java | 42 +- .../openjpa/persistence/criteria/Person_.java | 16 + .../openjpa/persistence/criteria/Phone.java | 36 +- .../openjpa/persistence/criteria/Phone_.java | 16 + .../openjpa/persistence/criteria/Photo.java | 20 +- .../openjpa/persistence/criteria/Photo_.java | 14 + .../openjpa/persistence/criteria/Product.java | 44 ++ .../persistence/criteria/Product_.java | 15 + .../persistence/criteria/Semester.java | 46 ++ .../persistence/criteria/Semester_.java | 14 + .../openjpa/persistence/criteria/Student.java | 40 +- .../persistence/criteria/Student_.java | 16 + .../TestMetaModelTypesafeCriteria.java | 606 ++++++++++++++++++ .../criteria/TestTypesafeCriteria.java | 423 +++++++++++- .../criteria/TransactionHistory.java | 61 ++ .../criteria/TransactionHistory_.java | 16 + .../persistence/criteria/VideoStore.java | 58 +- .../persistence/criteria/VideoStore_.java | 17 + 48 files changed, 2427 insertions(+), 74 deletions(-) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory_.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore_.java diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java index 92851704a..edf130350 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Account.java @@ -30,14 +30,50 @@ import javax.persistence.Table; * */ @Entity -@Table(name="CR_ACCOUNT") +@Table(name="CR_ACCT") public class Account { - @Id - @GeneratedValue - private long id; - - private int balance; - private Integer loan; - private String owner; - private String name; + @Id + @GeneratedValue + private long id; + + private int balance; + private Integer loan; + private String owner; + private String name; + + public long getId() { + return id; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getBalance() { + return balance; + } + + public void setBalancey(int balance) { + this.balance = balance; + } + + public Integer getLoan() { + return loan; + } + + public void setLoan(Integer loan) { + this.loan = loan; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java index 928e8f90a..f7056a792 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java @@ -33,14 +33,69 @@ import javax.persistence.Table; * */ @Entity -@Table(name="CR_ADDRESS") +@Table(name="CR_ADDR") @Embeddable public class Address { @Id @GeneratedValue private long id; - + + private String street; + private String city; private String state; private String county; + private String country; private String zipCode; + + public long getId() { + return id; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getCounty() { + return county; + } + + public void setCounty(String county) { + this.county = county; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getZipcode() { + return zipCode; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public void setZipcode(String zipCode) { + this.zipCode = zipCode; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address_.java new file mode 100644 index 000000000..573f879d4 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address_.java @@ -0,0 +1,19 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Address.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Address_ { + public static volatile Attribute city; + public static volatile Attribute country; + public static volatile Attribute county; + public static volatile Attribute id; + public static volatile Attribute state; + public static volatile Attribute street; + public static volatile Attribute zipCode; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact.java index 95bd36372..248ab5d1d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact.java @@ -31,4 +31,20 @@ public class Contact { @OneToMany private List phones; + + public List getPhones() { + return phones; + } + + public void addPhone(Phone phone) { + phones.add(phone); + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact_.java new file mode 100644 index 000000000..14aa07bdb --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contact_.java @@ -0,0 +1,15 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.List; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Contact.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Contact_ { + public static volatile Attribute address; + public static volatile List phones; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor.java index dbaa685e6..4072733bf 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor.java @@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.criteria; import javax.persistence.Entity; + @Entity public class Contractor extends Person { } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor_.java new file mode 100644 index 000000000..0d065ea58 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Contractor_.java @@ -0,0 +1,11 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Contractor.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Contractor_ extends Person_ { +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java index 6a417c455..4533b1bcf 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java @@ -21,17 +21,47 @@ package org.apache.openjpa.persistence.criteria; import java.util.List; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; @Entity -@Table(name="CR_COURSE") +@Table(name="CR_CRSE") public class Course { - private String name; - - @OneToMany - @OrderBy - private List studentWaitList; + @Id + @GeneratedValue + private long id; + + private String name; + + @OneToMany + @OrderBy + private List studentWaitList; + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getStudentWaitList() { + return studentWaitList; + } + + public void setStudentWaitList(List studentWaitList) { + this.studentWaitList = studentWaitList; + } + + public void addStudentToWaitList(Student student) { + studentWaitList.add(student); + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course_.java new file mode 100644 index 000000000..63a9dab12 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.List; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Course.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Course_ { + public static volatile Attribute id; + public static volatile Attribute name; + public static volatile List studentWaitList; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard.java index 54d0964d5..1885762b9 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard.java @@ -21,19 +21,48 @@ package org.apache.openjpa.persistence.criteria; import java.util.List; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.OrderBy; import javax.persistence.Table; @Entity -@Table(name="CR_CREDITCARD") - +@Table(name="CR_CRDTC") public class CreditCard { - @OneToOne - private Employee holder; + @Id + @GeneratedValue + private long id; + + @OneToOne + private Customer customer; @OneToMany @OrderBy - private List transactionHistory; + private List transactionHistory; + + public long getId() { + return id; + } + + public List getTransactionHistory() { + return transactionHistory; + } + + public void setTransactionHistory(List transactionHistory) { + this.transactionHistory = transactionHistory; + } + + public void addTransactionHistory(TransactionHistory transaction) { + transactionHistory.add(transaction); + } + + public Customer getCustomer() { + return customer; + } + + public void setCustomerr(Customer customer) { + this.customer = customer; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard_.java new file mode 100644 index 000000000..961174d79 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CreditCard_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.List; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.CreditCard.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class CreditCard_ { + public static volatile Attribute customer; + public static volatile Attribute id; + public static volatile List transactionHistory; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java index 83e0d74bf..1df88ac63 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer.java @@ -18,38 +18,131 @@ */ package org.apache.openjpa.persistence.criteria; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.Entity; -import javax.persistence.ManyToOne; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity -@Table(name="CR_CUSTOMER") - +@Table(name="CR_CUST") public class Customer { + @Id + @GeneratedValue private long id; + private String firstName; private String lastName; + private String name; + @OneToMany - private Set orders; + private Set orders = new HashSet(); + private int status; - private int balanceOwned; + private int balanceOwed; + @OneToOne private Address address; private int filledOrderCount; - private String country; + + private long accountNum; @OneToMany - private List accounts; + private List accounts = new ArrayList(); - public Customer() { - - } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Set getOrders() { + return orders; + } + + public void setOrders(Set orders) { + this.orders = orders; + } + + public long getId() { + return id; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public long getAccountNum() { + return accountNum; + } + + public void setAccountNum(long accountNum) { + this.accountNum = accountNum; + } + + public int getBalanceOwed() { + return balanceOwed; + } + + public void setBalanceOwed(int balanceOwed) { + this.balanceOwed = balanceOwed; + } + + public int getFilledOrderCount() { + return filledOrderCount; + } + + public void setFilledOrderCount(int filledOrderCount) { + this.filledOrderCount = filledOrderCount; + } + + public List getAccounts() { + return accounts; + } + + public void setAccounts(List accounts) { + this.accounts = accounts; + } + + + public Customer(long id, int status, int count) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java new file mode 100644 index 000000000..8755f2750 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java @@ -0,0 +1,53 @@ +/* + * 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; + +public class CustomerDetails { + int id; + + int status; + + int quantity; + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + +} + diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer_.java new file mode 100644 index 000000000..2db57eaef --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Customer_.java @@ -0,0 +1,25 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.List; +import javax.persistence.metamodel.Set; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Customer.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Customer_ { + public static volatile Attribute accountNum; + public static volatile List accounts; + public static volatile Attribute address; + public static volatile Attribute balanceOwed; + public static volatile Attribute filledOrderCount; + public static volatile Attribute firstName; + public static volatile Attribute id; + public static volatile Attribute lastName; + public static volatile Attribute name; + public static volatile Set orders; + public static volatile Attribute status; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department.java index eab7bee71..0ac34aef9 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department.java @@ -21,15 +21,44 @@ package org.apache.openjpa.persistence.criteria; import java.util.Set; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; + @Entity -@Table(name="CR_DEPARTMENT") +@Table(name="CR_DEPT") public class Department { + @Id + @GeneratedValue private int deptNo; private String name; @OneToMany private Set employees; + + public int getDeptno() { + return deptNo; + } + + public void setDeptno(int deptNo) { + this.deptNo = deptNo; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getEmployees() { + return employees; + } + + public void setEmployees(Set employees){ + this.employees = employees; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department_.java new file mode 100644 index 000000000..609c63efc --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Department_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Set; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Department.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Department_ { + public static volatile Attribute deptNo; + public static volatile Set employees; + public static volatile Attribute name; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee.java index dbe5478bf..014177f8d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee.java @@ -18,29 +18,104 @@ */ package org.apache.openjpa.persistence.criteria; +import javax.persistence.Basic; +import javax.persistence.DiscriminatorColumn; import javax.persistence.Embedded; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity -@Table(name="CR_EMPLOYEE") - +@Table(name="CR_EMP") +@Inheritance +@DiscriminatorColumn(name="EMP_TYPE") public class Employee { + @Id + @GeneratedValue + private int empId; + private String name; @Embedded private Contact contactInfo; @ManyToOne private Department department; - private int rating; - private float salary; + @OneToOne private Employee spouse; @ManyToOne private Manager manager; @OneToOne - FrequentFlierPlan frequentFlierPlan; + private FrequentFlierPlan frequentFlierPlan; + @Basic + private long salary; + + @Basic + private int rating; + + + public int getEmpId() { + return empId; + } + + public void setContactInfo(Contact contactInfo) { + this.contactInfo = contactInfo; + } + + public Contact getContactInfo() { + return contactInfo; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public Department getDepartment() { + return department; + } + + public void setSpouse(Employee spouse) { + this.spouse = spouse; + } + + public Employee getSpouse() { + return spouse; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setManager(Manager manager) { + this.manager = manager; + } + + public Manager getManager() { + return manager; + } + + public void setSalary(long salary) { + this.salary = salary; + } + + public long getSalary() { + return salary; + } + + public void setRating(int rating) { + this.rating = rating; + } + + public long getRating() { + return rating; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee_.java new file mode 100644 index 000000000..5b96e91e5 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Employee_.java @@ -0,0 +1,21 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Employee.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Employee_ { + public static volatile Attribute contactInfo; + public static volatile Attribute department; + public static volatile Attribute empId; + public static volatile Attribute frequentFlierPlan; + public static volatile Attribute manager; + public static volatile Attribute name; + public static volatile Attribute rating; + public static volatile Attribute salary; + public static volatile Attribute spouse; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt.java index 63e03fe4a..b5e4150f5 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt.java @@ -18,17 +18,22 @@ */ package org.apache.openjpa.persistence.criteria; +import java.util.Date; + +import javax.persistence.Basic; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; @Entity -@Table(name="CR_EXEMPT") - -public class Exempt { - @Id - @GeneratedValue - private String id; - +public class Exempt extends Employee { + @Basic + private Date hireDate; + + public void setHireDate(Date hireDate) { + this.hireDate = hireDate; + } + + public Date getHireDate() { + return hireDate; + } + } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt_.java new file mode 100644 index 000000000..3b5c34df4 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Exempt_.java @@ -0,0 +1,14 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import java.util.Date; +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Exempt.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Exempt_ extends Employee_ { + public static volatile Attribute hireDate; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item.java index bd9e376ad..31c44c4bd 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item.java @@ -21,15 +21,50 @@ package org.apache.openjpa.persistence.criteria; import java.util.Map; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.OneToMany; -import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name="CR_ITEM") - public class Item { + @Id + @GeneratedValue + private int id; + private String name; - @OneToMany + + @OneToMany private Map photos; + + public long getId() { + return id; + } + + public Map getPhotos() { + return photos; + } + + public void addPhoto(String name, Photo photo) { + photos.put(name, photo); + } + + public void removePhoto(String name) { + photos.remove(name); + } + + public Photo getPhoto(String name) { + return photos.get(name); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item_.java new file mode 100644 index 000000000..c3effc415 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Item_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Map; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Item.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Item_ { + public static volatile Attribute id; + public static volatile Attribute name; + public static volatile Map photos; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem.java index 37e4b3551..0d7f5aed4 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem.java @@ -19,14 +19,74 @@ 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.Table; @Entity -@Table(name="CR_LINEITEM") +@Table(name="CR_LI") public class LineItem { - private int price; + @Id + @GeneratedValue + private int id; + + private double price; + @ManyToOne private Order order; + + private int quantity; + + private double cost; + + @ManyToOne (fetch=FetchType.EAGER) + Product product; + + public long getId() { + return id; + } + + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public double getCost() { + return cost; + } + + public void setCost(double cost) { + this.cost = cost; + } + + public Product getProduct() { + return product; + } + + public void setProduct(Product product) { + this.product = product; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem_.java new file mode 100644 index 000000000..08d39b790 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/LineItem_.java @@ -0,0 +1,18 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.LineItem.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class LineItem_ { + public static volatile Attribute cost; + public static volatile Attribute id; + public static volatile Attribute order; + public static volatile Attribute price; + public static volatile Attribute product; + public static volatile Attribute quantity; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager.java index 3db9c919a..98bd7a7af 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager.java @@ -18,11 +18,54 @@ */ package org.apache.openjpa.persistence.criteria; +import java.math.BigDecimal; + import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity +@Table(name="CR_MGR") +public class Manager { + @Id + @GeneratedValue + private int id; + + private String name; + + private BigDecimal salary; + + @ManyToOne + private Department department; + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public Department getDepartment() { + return department; + } + + public BigDecimal getSalary() { + return salary; + } + + public void setSalary(BigDecimal salary) { + this.salary = salary; + } -public class Manager extends Employee { - private String cabin; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager_.java new file mode 100644 index 000000000..a9152c347 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Manager_.java @@ -0,0 +1,17 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import java.math.BigDecimal; +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Manager.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Manager_ { + public static volatile Attribute department; + public static volatile Attribute id; + public static volatile Attribute name; + public static volatile Attribute salary; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie.java new file mode 100644 index 000000000..43223d042 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie.java @@ -0,0 +1,43 @@ +/* + * 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 javax.persistence.*; + +@Entity +@Table(name="CR_MV") +public class Movie { + @Id + @GeneratedValue + private int id; + + private String title; + + public long getId() { + return id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie_.java new file mode 100644 index 000000000..d9cd69283 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Movie_.java @@ -0,0 +1,14 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Movie.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Movie_ { + public static volatile Attribute id; + public static volatile Attribute title; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java index da938ecbb..055fa8e07 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order.java @@ -21,21 +21,64 @@ package org.apache.openjpa.persistence.criteria; import java.util.List; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity -@Table(name="CR_ORDER") +@Table(name="CR_ODR") public class Order { - private int quantity; - private int cost; - private int totalcost; + @Id + @GeneratedValue + private int id; + + private int quantity; + private double totalCost; private int count; + @ManyToOne private Customer customer; @OneToMany(mappedBy="order") private List lineItems; + + public double getTotalCost() { + return totalCost; + } + + public void setTotalCost(double totalCost) { + this.totalCost = totalCost; + } + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public int getId() { + return id; + } + + public List getLineItems() { + return lineItems; + } + + public void setLineitems(List lineItems) { + this.lineItems = lineItems; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java new file mode 100644 index 000000000..70efc3723 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Order_.java @@ -0,0 +1,19 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.List; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Order.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Order_ { + public static volatile Attribute count; + public static volatile Attribute customer; + public static volatile Attribute id; + public static volatile List lineItems; + public static volatile Attribute quantity; + public static volatile Attribute totalCost; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person.java index 8e80928c2..8b05cc7de 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person.java @@ -18,22 +18,48 @@ */ package org.apache.openjpa.persistence.criteria; -import java.util.List; +import java.util.Set; +import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; import javax.persistence.Id; -import javax.persistence.OneToMany; import javax.persistence.Table; -import org.apache.openjpa.persistence.PersistentCollection; - @Entity -@Table(name="CR_PERSON") +@Table(name="CR_PSN") public class Person { @Id - private long ssn; + @GeneratedValue + private int id; + + private String name; - @PersistentCollection - private List nicknames; + @ElementCollection + private Set nickNames; + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getNickNames() { + return nickNames; + } + + public void setNickNames(Set nickNames) { + this.nickNames = nickNames; + } + + public void addNickName(String nickName) { + nickNames.add(nickName); + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person_.java new file mode 100644 index 000000000..4be439b4c --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Person_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Set; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Person.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Person_ { + public static volatile Attribute id; + public static volatile Attribute name; + public static volatile Set nickNames; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone.java index 23c10384d..45f4fb97d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone.java @@ -18,12 +18,44 @@ */ package org.apache.openjpa.persistence.criteria; +import java.util.ArrayList; +import java.util.Collection; + import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; import javax.persistence.Table; @Entity -@Table(name="CR_PHONE") - +@Table(name="CR_PHN") public class Phone { + @Id + @GeneratedValue + private int id; + + @ManyToMany + private Collection employees = new ArrayList(); + private String vendor; + + public int getId() { + return id; + } + + public Collection getEmployees() { + return employees; + } + + public void addEmployees(Employee employee) { + employees.add(employee); + } + + public String getVendor() { + return vendor; + } + + public void setVendor(String vendor) { + this.vendor = vendor; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone_.java new file mode 100644 index 000000000..60b284d52 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Phone_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Collection; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Phone.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Phone_ { + public static volatile Collection employees; + public static volatile Attribute id; + public static volatile Attribute vendor; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo.java index 65161530c..e6e50917c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo.java @@ -19,11 +19,29 @@ package org.apache.openjpa.persistence.criteria; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.Table; @Entity -@Table(name="CR_PHOTO") +@Table(name="CR_PHT") public class Photo { + @Id + @GeneratedValue + private int id; + private String label; + + public int getId() { + return id; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo_.java new file mode 100644 index 000000000..c8c6e1118 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Photo_.java @@ -0,0 +1,14 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Photo.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Photo_ { + public static volatile Attribute id; + public static volatile Attribute label; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java new file mode 100644 index 000000000..b19c1a544 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product.java @@ -0,0 +1,44 @@ +/* + * 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 javax.persistence.*; + +@Entity +public class Product { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + private int pid; + + private String productType; + + @Version + private long version; + + public String getProductType() { + return productType; + } + + public void setProductType(String productType) { + this.productType = productType; + } + + public int getPid() { + return pid; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product_.java new file mode 100644 index 000000000..db9867a12 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Product_.java @@ -0,0 +1,15 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Product.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Product_ { + public static volatile Attribute pid; + public static volatile Attribute productType; + public static volatile Attribute version; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester.java new file mode 100644 index 000000000..92d4d2a78 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester.java @@ -0,0 +1,46 @@ +/* + * 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 javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="CR_SMT") +public class Semester { + @Id + @GeneratedValue + private int id; + + private String name; + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester_.java new file mode 100644 index 000000000..84453aafa --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Semester_.java @@ -0,0 +1,14 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Semester.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Semester_ { + public static volatile Attribute id; + public static volatile Attribute name; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student.java index 98a83cf44..52e3731f8 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student.java @@ -18,16 +18,54 @@ */ package org.apache.openjpa.persistence.criteria; +import java.util.HashMap; +import java.util.Map; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.MapKeyJoinColumn; import javax.persistence.Table; @Entity -@Table(name="CR_STUDENT") +@Table(name="CR_STU") public class Student { @Id + @GeneratedValue + private int id; + private String name; + + @ManyToMany + @JoinTable(name="ENROLLMENTS", + joinColumns=@JoinColumn(name="STUDENT"), + inverseJoinColumns=@JoinColumn(name="SEMESTER")) + @MapKeyJoinColumn(name="COURSE") + private Map enrollment = + new HashMap(); + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Map getEnrollment() { + return enrollment; + } + + public void addToEnrollment(Course course, Semester semester) { + enrollment.put(course, semester); + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student_.java new file mode 100644 index 000000000..25afe150a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Student_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Map; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Student.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class Student_ { + public static volatile Map enrollment; + public static volatile Attribute id; + public static volatile Attribute name; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java new file mode 100644 index 000000000..2eea63ff5 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java @@ -0,0 +1,606 @@ +package org.apache.openjpa.persistence.criteria; +import java.math.BigDecimal; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.Parameter; +import javax.persistence.Query; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.MapJoin; +import javax.persistence.criteria.Root; +import javax.persistence.criteria.Subquery; +import javax.persistence.metamodel.Embeddable; +import javax.persistence.metamodel.Entity; +import javax.persistence.metamodel.Metamodel; + +import org.apache.openjpa.jdbc.conf.JDBCConfiguration; +import org.apache.openjpa.jdbc.sql.DBDictionary; +import org.apache.openjpa.persistence.test.AllowFailure; +import org.apache.openjpa.persistence.test.SQLListenerTestCase; + +public class TestMetaModelTypesafeCriteria extends SQLListenerTestCase { + protected Entity account_ = null; + protected Embeddable
address_ = null; + protected Embeddable contact_ = null; + protected Entity course_ = null; + protected Entity creditCard_ = null; + protected Entity customer_ = null; + protected Entity department_ = null; + protected Entity employee_ = null; + protected Entity exempt_ = null; + protected Entity item_ = null; + protected Entity lineItem_ = null; + protected Entity manager_ = null; + protected Entity movie_ = null; + protected Entity order_ = null; + protected Entity person_ = null; + protected Entity phone_ = null; + protected Entity photo_ = null; + protected Entity product_ = null; + protected Entity semester_ = null; + protected Entity student_ = null; + protected Entity transactionHistory_ = null; + protected Entity videoStore_ = null; + CriteriaBuilder cb; + EntityManager em; + + + public void setUp() { + super.setUp(DROP_TABLES, + Account.class, + Address.class, + Contact.class, + Contractor.class, + Course.class, + CreditCard.class, + Customer.class, + Department.class, + Employee.class, + Exempt.class, + FrequentFlierPlan.class, + Item.class, + LineItem.class, + Manager.class, + Movie.class, + Person.class, + Product.class, + Order.class, + Phone.class, + Photo.class, + Semester.class, + Student.class, + TransactionHistory.class, + VideoStore.class); + + setDictionary(); + cb = (CriteriaBuilder)emf.getQueryBuilder(); + em = emf.createEntityManager(); + Metamodel mm = em.getMetamodel(); + account_ = mm.entity(Account.class); + address_ = mm.embeddable(Address.class); + contact_ = mm.embeddable(Contact.class); + course_ = mm.entity(Course.class); + creditCard_ = mm.entity(CreditCard.class); + customer_ = mm.entity(Customer.class); + department_ = mm.entity(Department.class); + employee_ = mm.entity(Employee.class); + exempt_ = mm.entity(Exempt.class); + item_ = mm.entity(Item.class); + lineItem_ = mm.entity(LineItem.class); + manager_ = mm.entity(Manager.class); + movie_ = mm.entity(Movie.class); + order_ = mm.entity(Order.class); + person_ = mm.entity(Person.class); + phone_ = mm.entity(Phone.class); + photo_ = mm.entity(Photo.class); + product_ = mm.entity(Product.class); + semester_ = mm.entity(Semester.class); + student_ = mm.entity(Student.class); + transactionHistory_ = mm.entity(TransactionHistory.class); + videoStore_ = mm.entity(VideoStore.class); + + } + + void setDictionary() { + JDBCConfiguration conf = (JDBCConfiguration)emf.getConfiguration(); + DBDictionary dict = conf.getDBDictionaryInstance(); + dict.requiresCastForComparisons = false; + dict.requiresCastForMathFunctions = false; + } + + public void createObj() { + } + + @AllowFailure + public void testCriteria() { + String jpql = "select c from Customer c where c.name='Autowest Toyota'"; + CriteriaQuery q = cb.create(); + Root customer = q.from(Customer.class); + q = cb.create(); + q.select(customer).where(cb.equal( + customer.get(customer_.getAttribute("name", String.class)), + "Autowest Toyota")); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testJoins() { + String jpql = "SELECT c.name FROM Customer c JOIN c.orders o " + + "JOIN o.lineItems i WHERE i.product.productType = 'printer'"; + CriteriaQuery q = cb.create(); + Root cust = q.from(Customer.class); + Join order = cust.join(customer_.getSet("orders", + Order.class)); + Join item = order.join(order_.getList("lineItems", + LineItem.class)); + q.select(cust.get(Customer_.name)) + .where(cb.equal( + item.get(lineItem_.getAttribute("product", Product.class)). + get(product_.getAttribute("productType", String.class)), + "printer")); + + assertEquivalence(q, jpql); + + jpql = "SELECT c FROM Customer c LEFT JOIN c.orders o WHERE " + + "c.status = 1"; + q = cb.create(); + Root cust1 = q.from(Customer.class); + Join order1 = cust1.join(customer_.getSet("orders", + Order.class), JoinType.LEFT); + q.where(cb.equal(cust1.get(customer_.getAttribute("status", + Integer.class)), 1)).select(cust1); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testFetchJoins() { + String jpql = "SELECT d FROM Department LEFT JOIN FETCH d.employees " + + "WHERE d.deptNo = 1"; + CriteriaQuery q = cb.create(); + Root d = q.from(Department.class); + d.fetch(department_.getSet("employees", Employee.class), JoinType.LEFT); + q.where(cb.equal(d.get(department_.getAttribute("deptNo", + Integer.class)), 1)).select(d); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testPathNavigation() { + String jpql = "SELECT p.vendor FROM Employee e " + + "JOIN e.contactInfo.phones p WHERE e.contactInfo.address.zipCode =" + + " '95054'"; + CriteriaQuery q = cb.create(); + Root emp = q.from(Employee.class); + Join phone = emp.join( + employee_.getAttribute("contactInfo", Contact.class)). + join(contact_.getList("phones", Phone.class)); + q.where(cb.equal(emp.get(employee_.getAttribute("contactInfo", + Contact.class)). + get(contact_.getAttribute("address", Address.class)). + get(address_.getAttribute("zipCode", String.class)), "95054")); + q.select(phone.get(phone_.getAttribute("vendor", String.class))); + + assertEquivalence(q, jpql); + + jpql = "SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) " + + "LIKE '%egret%'"; + + q = cb.create(); + Root item = q.from(Item.class); + MapJoin photo = item.join(item_.getMap("photos", + String.class, Photo.class)); + q.select(item.get(item_.getAttribute("name", String.class)), photo). + where(cb.like(photo.key(), "%egret%")); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testRestrictQueryResult() { + String jpql = "SELECT t FROM CreditCard c JOIN c.transactionHistory t " + + "WHERE c.customer.accountNum = 321987 AND INDEX(t) BETWEEN 0 " + + "AND 9"; + CriteriaQuery q = cb.create(); + Root c = q.from(CreditCard.class); + ListJoin t = + c.join(creditCard_.getList("transactionHistory", + TransactionHistory.class)); + q.select(t).where(cb.equal( + c.get(creditCard_.getAttribute("customer", Customer.class)). + get(customer_.getAttribute("accountNum", Long.class)), 321987), + cb.between(t.index(), 0, 9)); + + assertEquivalence(q, jpql); + +/* + + jpql = "SELECT o FROM Order o WHERE o.lineItems IS EMPTY"; + q = cb.create(); + Root order = q.from(Order.class); + Join lineItems = order.join(order_.getList("lineItems", + LineItem.class)); + q.where(cb.isEmpty(lineItems)); + q.select(order); + + assertEquivalence(q, jpql); +*/ + } + + @AllowFailure + public void testExpressions() { + String jpql = "SELECT o.quantity, o.totalCost*1.08 AS taxedCost, " + + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a " + + "WHERE a.state = 'CA' AND a.county = 'Santa Clara"; + CriteriaQuery q = cb.create(); + Root cust = q.from(Customer.class); + Join order = cust.join(customer_.getSet("orders", + Order.class)); + Join address = cust.join(customer_.getAttribute( + "address", Address.class)); + q.where(cb.equal(address.get(address_.getAttribute("state", + String.class)), "CA"), + cb.equal(address.get(address_.getAttribute("county", + String.class)), "Santa Clara")); + q.select(order.get(order_.getAttribute("quantity", Integer.class)), + cb.prod(order.get(order_.getAttribute("totalCost", Double.class)), + 1.08), + address.get(address_.getAttribute("zipCode", String.class))); + + assertEquivalence(q, jpql); + + jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt"; + q = cb.create(); + Root emp = q.from(Employee.class); + q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class)); + + assertEquivalence(q, jpql); + + jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w " + + "WHERE c.name = 'Calculus' AND INDEX(w) = 0"; + q = cb.create(); + Root course = q.from(Course.class); + ListJoin w = course.join(course_.getList( + "studentWaitList", Student.class)); + q.where(cb.equal(course.get(course_.getAttribute("name", + String.class)), "Calculus"), + cb.equal(w.index(), 0)).select(w.get(student_.getAttribute("name", + String.class))); + + assertEquivalence(q, jpql); + + jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN " + + "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'"; + q = cb.create(); + Root o = q.from(Order.class); + Join i = o.join(order_.getList("lineItems", + LineItem.class)); + Join c = o.join(order_.getAttribute("customer", + Customer.class)); + q.where(cb.equal(c.get(customer_.getAttribute("lastName", + String.class)), "Smith"), + cb.equal(c.get(customer_.getAttribute("firstName", + String.class)), "John")); + q.select(cb.sum(i.get(lineItem_.getAttribute("price", + Double.class)))); + + assertEquivalence(q, jpql); +/* + jpql = "SELECT SIZE(d.employees) FROM Department d " + + "WHERE d.name = 'Sales'"; + q = cb.create(); + Root d = q.from(Department.class); + q.where(cb.equal(d.get(department_.getAttribute("name", + String.class)), "Sales")); + q.select(cb.size(d.get(department_.getSet("employees", + Employee.class)))); + + assertEquivalence(q, jpql); +*/ + jpql = "SELECT e.name, CASE WHEN e.rating = 1 THEN e.salary * 1.1 " + + "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * 1.01 END " + + "FROM Employee e WHERE e.department.name = 'Engineering'"; + q = cb.create(); + Root e = q.from(Employee.class); + q.where(cb.equal(e.get(employee_.getAttribute("department", + Department.class)). + get(department_.getAttribute("name", String.class)), + "Engineering")); + q.select(e.get(employee_.getAttribute("name", String.class)), + cb.selectCase() + .when(cb.equal(e.get(employee_.getAttribute("rating", + Integer.class)), 1), + cb.prod(e.get(employee_.getAttribute("salary", + Long.class)), 1.1)) + .when(cb.equal(e.get(employee_.getAttribute("rating", + Integer.class)), 2), + cb.prod(e.get(employee_.getAttribute("salary", + Long.class)), 1.2)) + .otherwise(cb.prod(e.get(employee_.getAttribute("salary", + Long.class)), 1.01))); + + assertEquivalence(q, jpql); + } +/* + @AllowFailure + public void testLiterals() { + String jpql = "SELECT p FROM Person p where 'Joe' MEMBER OF " + + "p.nickNames"; + CriteriaQuery q = cb.create(); + Root p = q.from(Person.class); + q.select(p).where(cb.isMember(cb.literal("Joe"), p.get(person_. + getSet("nickNames", String.class)))); + + assertEquivalence(q, jpql); + } +*/ + + @AllowFailure + public void testParameters() { + String jpql = "SELECT c FROM Customer c Where c.status = :stat"; + CriteriaQuery q = cb.create(); + Root c = q.from(Customer.class); + Parameter param = cb.parameter(Integer.class); + q.select(c).where(cb.equal(c.get(customer_.getAttribute("status", + Integer.class)), param)); + + assertEquivalence(q, jpql, new String[]{"stat"}, new Object[] {1}); + } + + @AllowFailure + public void testSelectList() { + String jpql = "SELECT v.location.street, KEY(i).title, VALUE(i) FROM " + + "VideoStore v JOIN v.videoInventory i WHERE v.location.zipCode = " + + "'94301' AND VALUE(i) > 0"; + CriteriaQuery q = cb.create(); + Root v = q.from(VideoStore.class); + MapJoin inv = v.join(videoStore_.getMap( + "videoInventory", Movie.class, Integer.class)); + q.where(cb.equal(v.get(videoStore_.getAttribute("location", + Address.class)). + get(address_.getAttribute("zipCode", String.class)), "94301"), + cb.gt(inv.value(), 0)); + q.select(v.get(videoStore_.getAttribute("location", Address.class)). + get(address_.getAttribute("street", String.class)), + inv.key().get(movie_.getAttribute("title", String.class)), + inv.value()); + + assertEquivalence(q, jpql); + + jpql = "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM " + + "Customer c JOIN c.orders o WHERE o.quantity > 100"; + q = cb.create(); + Root c = q.from(Customer.class); + Join o = c.join(customer_.getSet("orders", Order.class)); + q.where(cb.gt(o.get(order_.getAttribute("quantity", Integer.class)), + 100)); + q.select(cb.select(CustomerDetails.class, + c.get(customer_.getAttribute("id", Integer.class)), + c.get(customer_.getAttribute("status", Integer.class)), + o.get(order_.getAttribute("quantity", Integer.class)))); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testSubqueries() { + String jpql = "SELECT goodCustomer FROM Customer goodCustomer WHERE " + + "goodCustomer.balanceOwed < (SELECT AVG(c.balanceOwed) FROM " + + "Customer c)"; + CriteriaQuery q = cb.create(); + Root goodCustomer = q.from(Customer.class); + Subquery sq = q.subquery(Double.class); + Root c = sq.from(Customer.class); + q.where(cb.lt(goodCustomer.get(customer_.getAttribute("balanceOwed", + Integer.class)), + sq.select(cb.avg(c.get(customer_.getAttribute("balanceOwed", + Integer.class)))))); + q.select(goodCustomer); + + assertEquivalence(q, jpql); + + jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS (" + + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = " + + "emp.spouse)"; + q = cb.create(); + Root emp = q.from(Employee.class); + Subquery sq1 = q.subquery(Employee.class); + Root spouseEmp = sq1.from(Employee.class); + sq1.select(spouseEmp); + sq1.where(cb.equal(spouseEmp, emp.get(employee_.getAttribute("spouse", + Employee.class)))); + q.where(cb.exists(sq)); + q.select(emp).distinct(true); + + assertEquivalence(q, jpql); + + jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL (" + + "SELECT m.salary FROM Manager m WHERE m.department = emp.department)"; + q = cb.create(); + Root emp1 = q.from(Employee.class); + q.select(emp1); + Subquery sq2 = q.subquery(BigDecimal.class); + Root m = sq2.from(Manager.class); + sq2.select(m.get(manager_.getAttribute("salary", BigDecimal.class))); + sq2.where(cb.equal(m.get(manager_.getAttribute("department", + Department.class)), + emp1.get(employee_.getAttribute("department", + Department.class)))); + q.where(cb.gt(emp.get(employee_.getAttribute("salary", Long.class)), + cb.all(sq))); + + assertEquivalence(q, jpql); + + jpql = "SELECT c FROM Customer c WHERE " + + "(SELECT COUNT(o) FROM c.orders o) > 10"; + q = cb.create(); + Root c1 = q.from(Customer.class); + q.select(c1); + Subquery sq3 = q.subquery(Long.class); + Root c2 = sq3.correlate(c1); + Join o = c2.join(customer_.getSet("orders", + Order.class)); + q.where(cb.gt(sq3.select(cb.count(o)), 10)); + + assertEquivalence(q, jpql); + + jpql = "SELECT o FROM Order o WHERE 10000 < ALL (" + + "SELECT a.balance FROM o.customer c JOIN c.accounts a)"; + q = cb.create(); + Root o1 = q.from(Order.class); + q.select(o1); + Subquery sq4 = q.subquery(Integer.class); + Root o2 = sq4.correlate(o1); + Join c3 = o2.join(order_.getAttribute("customer", + Customer.class)); + Join a = c3.join(customer_.getList("accounts", + Account.class)); + sq4.select(a.get(account_.getAttribute("balance", Integer.class))); + q.where(cb.lt(cb.literal(10000), cb.all(sq4))); + + assertEquivalence(q, jpql); + + jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < " + + "ALL (SELECT a.balance FROM c.accounts a)"; + q = cb.create(); + Root o3 = q.from(Order.class); + q.select(o3); + Join c4 = o3.join(Order_.customer); + Subquery sq5 = q.subquery(Integer.class); + Join c5 = sq5.correlate(c4); + Join a2 = c5.join(customer_.getList("accounts", + Account.class)); + sq5.select(a.get(account_.getAttribute("balance", Integer.class))); + q.where(cb.lt(cb.literal(10000), cb.all(sq5))); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testGroupByAndHaving() { + String jpql = "SELECT c.status, AVG(c.filledOrderCount), COUNT(c) FROM " + + "Customer c GROUP BY c.status HAVING c.status IN (1, 2)"; + CriteriaQuery q = cb.create(); + Root c = q.from(Customer.class); + q.groupBy(c.get(customer_.getAttribute("status", Integer.class))); + q.having(cb.in(c.get(customer_.getAttribute("status", Integer.class))). + value(1).value(2)); + q.select(c.get(customer_.getAttribute("status", Integer.class)), + cb.avg(c.get(customer_.getAttribute("filledOrderCount", + Integer.class))), + cb.count(c)); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testOrdering() { + String jpql = "SELECT o FROM Customer c JOIN c.orders o " + + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity DESC, " + + "o.totalCost"; + CriteriaQuery q = cb.create(); + Root c = q.from(Customer.class); + Join o = c.join(customer_.getSet("orders", + Order.class)); + Join a = c.join(customer_.getAttribute("address", + Address.class)); + q.where(cb.equal(a.get(address_.getAttribute("state", String.class)), + "CA")); + q.orderBy(cb.desc(o.get(order_.getAttribute("quantity", + Integer.class))), + cb.asc(o.get(order_.getAttribute("totalCost", Double.class)))); + q.select(o); + + assertEquivalence(q, jpql); + + jpql = "SELECT o.quantity, a.zipCode FROM Customer c JOIN c.orders " + + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity, " + + "a.zipCode"; + q = cb.create(); + Root c1 = q.from(Customer.class); + Join o1 = c1.join(customer_.getSet("orders", + Order.class)); + Join a1 = c1.join(customer_.getAttribute("address", + Address.class)); + q.where(cb.equal(a1.get(address_.getAttribute("state", String.class)), + "CA")); + q.orderBy(cb.asc(o1.get(order_.getAttribute("quantity", + Integer.class))), + cb.asc(a1.get(address_.getAttribute("zipCode", + String.class)))); + q.select(o1.get(order_.getAttribute("quantity", + Integer.class)), + a1.get(address_.getAttribute("zipCode", String.class))); + + assertEquivalence(q, jpql); + + jpql = "SELECT o.quantity, o.cost * 1.08 AS taxedCost, a.zipCode " + + "FROM Customer c JOIN c.orders o JOIN c.address a " + + "WHERE a.state = 'CA' AND a.county = 'Santa Clara' " + + "ORDER BY o.quantity, taxedCost, a.zipCode"; + q = cb.create(); + Root c2 = q.from(Customer.class); + Join o2 = c2.join(customer_.getSet("orders", + Order.class)); + Join a2 = c2.join(customer_.getAttribute("address", + Address.class)); + q.where(cb.equal(a.get(address_.getAttribute("state", String.class)), + "CA"), + cb.equal(a.get(address_.getAttribute("county", String.class)), + "Santa Clara")); + q.orderBy(cb.asc(o.get(order_.getAttribute("quantity", + Integer.class))), + cb.asc(cb.prod(o.get(order_.getAttribute("totalCost", + Double.class)), 1.08)), + cb.asc(a.get(address_.getAttribute("zipCode", String.class)))); + q.select(o.get(order_.getAttribute("quantity", Integer.class)), + cb.prod(o.get(order_.getAttribute("totalCost", Double.class)), + 1.08), + a.get(address_.getAttribute("zipCode", String.class))); + + assertEquivalence(q, jpql); + } + + void assertEquivalence(CriteriaQuery c, String jpql) { + sql.clear(); + List cList = em.createQuery(c).getResultList(); + assertEquals(1, sql.size()); + String cSQL = sql.get(0); + + sql.clear(); + List jList = em.createQuery(jpql).getResultList(); + assertEquals(1, sql.size()); + String jSQL = sql.get(0); + + assertEquals(jSQL, cSQL); + } + + void assertEquivalence(CriteriaQuery c, String jpql, String[] paramNames, + Object[] params) { + sql.clear(); + Query q = em.createQuery(c); + for (int i = 0; i < paramNames.length; i++) { + q.setParameter(paramNames[i], params[i]); + } + List cList = q.getResultList(); + assertEquals(1, sql.size()); + String cSQL = sql.get(0); + + sql.clear(); + q = em.createQuery(jpql); + for (int i = 0; i < paramNames.length; i++) { + q.setParameter(paramNames[i], params[i]); + } + List jList = q.getResultList(); + assertEquals(1, sql.size()); + String jSQL = sql.get(0); + + assertEquals(jSQL, cSQL); + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java index 097cde7a8..de3ed0596 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java @@ -1,13 +1,22 @@ package org.apache.openjpa.persistence.criteria; +import java.math.BigDecimal; import java.util.List; import javax.persistence.EntityManager; +import javax.persistence.Parameter; +import javax.persistence.Query; import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.MapJoin; import javax.persistence.criteria.Root; +import javax.persistence.criteria.Subquery; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.sql.DBDictionary; +import org.apache.openjpa.persistence.test.AllowFailure; import org.apache.openjpa.persistence.test.SQLListenerTestCase; /** @@ -29,7 +38,32 @@ public class TestTypesafeCriteria extends SQLListenerTestCase { EntityManager em; public void setUp() { - super.setUp(Account.class); + super.setUp(DROP_TABLES, + Account.class, + Address.class, + Contact.class, + Contractor.class, + Course.class, + CreditCard.class, + Customer.class, + Department.class, + Employee.class, + Exempt.class, + FrequentFlierPlan.class, + Item.class, + LineItem.class, + Manager.class, + Movie.class, + Person.class, + Order.class, + Phone.class, + Photo.class, + Product.class, + Semester.class, + Student.class, + TransactionHistory.class, + VideoStore.class); + setDictionary(); cb = (CriteriaBuilder)emf.getQueryBuilder(); em = emf.createEntityManager(); @@ -154,6 +188,393 @@ public class TestTypesafeCriteria extends SQLListenerTestCase { // c.from(Account.class).join(Account_.history) } + @AllowFailure + public void testJoins() { + String jpql = "SELECT c.name FROM Customer c JOIN c.orders o " + + "JOIN o.lineItems i WHERE i.product.productType = 'printer'"; + CriteriaQuery c = cb.create(); + Root cust = c.from(Customer.class); + Join order = cust.join(Customer_.orders); + Join item = order.join(Order_.lineItems); + c.select(cust.get(Customer_.name)) + .where(cb.equal(item.get(LineItem_.product). + get(Product_.productType), "printer")); + + assertEquivalence(c, jpql); + + jpql = "SELECT c FROM Customer c LEFT JOIN c.orders o " + + "WHERE c.status = 1"; + c = cb.create(); + Root cust1 = c.from(Customer.class); + Join order1 = cust1.join(Customer_.orders, + JoinType.LEFT); + c.where(cb.equal(cust1.get(Customer_.status), 1)).select(cust1); + + assertEquivalence(c, jpql); + } + + @AllowFailure + public void testFetchJoins() { + String jpql = "SELECT d FROM Department LEFT JOIN FETCH d.employees " + + "WHERE d.deptNo = 1"; + CriteriaQuery q = cb.create(); + Root d = q.from(Department.class); + d.fetch(Department_.employees, JoinType.LEFT); + q.where(cb.equal(d.get(Department_.deptNo), 1)).select(d); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testPathNavigation() { + String jpql = "SELECT p.vendor FROM Employee e JOIN " + + "e.contactInfo.phones p " + + "WHERE e.contactInfo.address.zipCode = '95054'"; + CriteriaQuery q = cb.create(); + Root emp = q.from(Employee.class); + Join phone = emp.join(Employee_.contactInfo). + join(Contact_.phones); + q.where(cb.equal(emp.get(Employee_.contactInfo).get(Contact_.address). + get(Address_.zipCode), "95054")); + q.select(phone.get(Phone_.vendor)); + + assertEquivalence(q, jpql); + + jpql = "SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) " + + "LIKE '%egret%'"; + + q = cb.create(); + Root item = q.from(Item.class); + MapJoin photo = item.join(Item_.photos); + q.select(item.get(Item_.name), photo). + where(cb.like(photo.key(), "%egret%")); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testRestrictQueryResult() { + String jpql = "SELECT t FROM CreditCard c JOIN c.transactionHistory t " + + "WHERE c.customer.accountNum = 321987 AND INDEX(t) BETWEEN 0 " + + "AND 9"; + CriteriaQuery q = cb.create(); + Root c = q.from(CreditCard.class); + ListJoin t = + c.join(CreditCard_.transactionHistory); + q.select(t).where(cb.equal( + c.get(CreditCard_.customer).get(Customer_.accountNum), 321987), + cb.between(t.index(), 0, 9)); + + assertEquivalence(q, jpql); + + jpql = "SELECT o FROM Order o WHERE o.lineItems IS EMPTY"; + q = cb.create(); + Root order = q.from(Order.class); + q.where(cb.isEmpty(order.get(Order_.lineItems))).select(order); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testExpressions() { + String jpql = "SELECT o.quantity, o.totalCost*1.08 AS taxedCost, " + + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a " + + "WHERE a.state = 'CA' AND a.county = 'Santa Clara"; + CriteriaQuery q = cb.create(); + Root cust = q.from(Customer.class); + Join order = cust.join(Customer_.orders); + Join address = cust.join(Customer_.address); + q.where(cb.equal(address.get(Address_.state), "CA"), + cb.equal(address.get(Address_.county), "Santa Clara")); + q.select(order.get(Order_.quantity), + cb.prod(order.get(Order_.totalCost), 1.08), + address.get(Address_.zipCode)); + + assertEquivalence(q, jpql); + + jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt"; + q = cb.create(); + Root emp = q.from(Employee.class); + q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class)); + + assertEquivalence(q, jpql); + + jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w " + + "WHERE c.name = 'Calculus' AND INDEX(w) = 0"; + q = cb.create(); + Root course = q.from(Course.class); + ListJoin w = course.join(Course_.studentWaitList); + q.where(cb.equal(course.get(Course_.name), "Calculus"), + cb.equal(w.index(), 0)).select(w.get(Student_.name)); + + assertEquivalence(q, jpql); + + jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN " + + "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'"; + q = cb.create(); + Root o = q.from(Order.class); + Join i = o.join(Order_.lineItems); + Join c = o.join(Order_.customer); + q.where(cb.equal(c.get(Customer_.lastName), "Smith"), + cb.equal(c.get(Customer_.firstName),"John")); + q.select(cb.sum(i.get(LineItem_.price))); + + assertEquivalence(q, jpql); + + jpql = "SELECT SIZE(d.employees) FROM Department d " + + "WHERE d.name = 'Sales'"; + q = cb.create(); + Root d = q.from(Department.class); + q.where(cb.equal(d.get(Department_.name), "Sales")); + q.select(cb.size(d.get(Department_.employees))); + + assertEquivalence(q, jpql); + + jpql = "SELECT e.name, CASE WHEN e.rating = 1 THEN e.salary * 1.1 " + + "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * 1.01 END " + + "FROM Employee e WHERE e.department.name = 'Engineering'"; + q = cb.create(); + Root e = q.from(Employee.class); + q.where(cb.equal(e.get(Employee_.department).get(Department_.name), + "Engineering")); + q.select(e.get(Employee_.name), + cb.selectCase() + .when(cb.equal(e.get(Employee_.rating), 1), + cb.prod(e.get(Employee_.salary), 1.1)) + .when(cb.equal(e.get(Employee_.rating), 2), + cb.prod(e.get(Employee_.salary), 1.2)) + .otherwise(cb.prod(e.get(Employee_.salary), 1.01))); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testLiterals() { + String jpql = "SELECT p FROM Person p where 'Joe' MEMBER OF p.nickNames"; + CriteriaQuery q = cb.create(); + Root p = q.from(Person.class); + q.select(p).where(cb.isMember(cb.literal("Joe"), p.get( + Person_.nickNames))); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testParameters() { + String jpql = "SELECT c FROM Customer c Where c.status = :stat"; + CriteriaQuery q = cb.create(); + Root c = q.from(Customer.class); + Parameter param = cb.parameter(Integer.class); + q.select(c).where(cb.equal(c.get(Customer_.status), param)); + + assertEquivalence(q, jpql, new String[]{"stat"}, new Object[] {1}); + } + + @AllowFailure + public void testSelectList() { + String jpql = "SELECT v.location.street, KEY(i).title, VALUE(i) FROM " + + "VideoStore v JOIN v.videoInventory i WHERE v.location.zipCode = " + + "'94301' AND VALUE(i) > 0"; + CriteriaQuery q = cb.create(); + Root v = q.from(VideoStore.class); + MapJoin inv = v.join( + VideoStore_.videoInventory); + q.where(cb.equal(v.get(VideoStore_.location).get(Address_.zipCode), + "94301"), + cb.gt(inv.value(), 0)); + q.select(v.get(VideoStore_.location).get(Address_.street), + inv.key().get(Movie_.title), inv.value()); + + assertEquivalence(q, jpql); + + jpql = "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM " + + "Customer c JOIN c.orders o WHERE o.quantity > 100"; + q = cb.create(); + Root c = q.from(Customer.class); + Join o = c.join(Customer_.orders); + q.where(cb.gt(o.get(Order_.quantity), 100)); + q.select(cb.select(CustomerDetails.class, + c.get(Customer_.id), + c.get(Customer_.status), + o.get(Order_.quantity))); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testSubqueries() { + String jpql = "SELECT goodCustomer FROM Customer goodCustomer WHERE " + + "goodCustomer.balanceOwed < (SELECT AVG(c.balanceOwed) FROM " + + "Customer c)"; + CriteriaQuery q = cb.create(); + Root goodCustomer = q.from(Customer.class); + Subquery sq = q.subquery(Double.class); + Root c = sq.from(Customer.class); + q.where(cb.lt(goodCustomer.get(Customer_.balanceOwed), + sq.select(cb.avg(c.get(Customer_.balanceOwed))))); + q.select(goodCustomer); + + assertEquivalence(q, jpql); + + jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS (" + + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = " + + "emp.spouse)"; + q = cb.create(); + Root emp = q.from(Employee.class); + Subquery sq1 = q.subquery(Employee.class); + Root spouseEmp = sq1.from(Employee.class); + sq1.select(spouseEmp); + sq1.where(cb.equal(spouseEmp, emp.get(Employee_.spouse))); + q.where(cb.exists(sq)); + q.select(emp).distinct(true); + + assertEquivalence(q, jpql); + + jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL (" + + "SELECT m.salary FROM Manager m WHERE m.department = " + + "emp.department)"; + q = cb.create(); + Root emp1 = q.from(Employee.class); + q.select(emp1); + Subquery sq2 = q.subquery(BigDecimal.class); + Root m = sq2.from(Manager.class); + sq2.select(m.get(Manager_.salary)); + sq2.where(cb.equal(m.get(Manager_.department), emp1.get( + Employee_.department))); + q.where(cb.gt(emp.get(Employee_.salary), cb.all(sq))); + + assertEquivalence(q, jpql); + + jpql = "SELECT c FROM Customer c WHERE " + + "(SELECT COUNT(o) FROM c.orders o) > 10"; + q = cb.create(); + Root c1 = q.from(Customer.class); + q.select(c1); + Subquery sq3 = q.subquery(Long.class); + Root c2 = sq3.correlate(c1); + Join o = c2.join(Customer_.orders); + q.where(cb.gt(sq3.select(cb.count(o)), 10)); + + assertEquivalence(q, jpql); + + jpql = "SELECT o FROM Order o WHERE 10000 < ALL (" + + "SELECT a.balance FROM o.customer c JOIN c.accounts a)"; + q = cb.create(); + Root o1 = q.from(Order.class); + q.select(o1); + Subquery sq4 = q.subquery(Integer.class); + Root o2 = sq4.correlate(o1); + Join c3 = o2.join(Order_.customer); + Join a = c3.join(Customer_.accounts); + sq4.select(a.get(Account_.balance)); + q.where(cb.lt(cb.literal(10000), cb.all(sq4))); + + assertEquivalence(q, jpql); + + jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < " + + "ALL (SELECT a.balance FROM c.accounts a)"; + q = cb.create(); + Root o3 = q.from(Order.class); + q.select(o3); + Join c4 = o3.join(Order_.customer); + Subquery sq5 = q.subquery(Integer.class); + Join c5 = sq5.correlate(c4); + Join a2 = c5.join(Customer_.accounts); + sq5.select(a.get(Account_.balance)); + q.where(cb.lt(cb.literal(10000), cb.all(sq5))); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testGroupByAndHaving() { + String jpql = "SELECT c.status, AVG(c.filledOrderCount), COUNT(c) FROM " + + "Customer c GROUP BY c.status HAVING c.status IN (1, 2)"; + CriteriaQuery q = cb.create(); + Root c = q.from(Customer.class); + q.groupBy(c.get(Customer_.status)); + q.having(cb.in(c.get(Customer_.status)).value(1).value(2)); + q.select(c.get(Customer_.status), + cb.avg(c.get(Customer_.filledOrderCount)), + cb.count(c)); + + assertEquivalence(q, jpql); + } + + @AllowFailure + public void testOrdering() { + String jpql = "SELECT o FROM Customer c JOIN c.orders o " + + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity DESC, " + + "o.totalCost"; + CriteriaQuery q = cb.create(); + Root c = q.from(Customer.class); + Join o = c.join(Customer_.orders); + Join a = c.join(Customer_.address); + q.where(cb.equal(a.get(Address_.state), "CA")); + q.orderBy(cb.desc(o.get(Order_.quantity)), + cb.asc(o.get(Order_.totalCost))); + q.select(o); + + assertEquivalence(q, jpql); + + jpql = "SELECT o.quantity, a.zipCode FROM Customer c JOIN c.orders " + + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity, " + + "a.zipCode"; + q = cb.create(); + Root c1 = q.from(Customer.class); + Join o1 = c1.join(Customer_.orders); + Join a1 = c1.join(Customer_.address); + q.where(cb.equal(a1.get(Address_.state), "CA")); + q.orderBy(cb.asc(o1.get(Order_.quantity)), cb.asc(a1.get( + Address_.zipCode))); + q.select(o1.get(Order_.quantity), a1.get(Address_.zipCode)); + + assertEquivalence(q, jpql); + + jpql = "SELECT o.quantity, o.cost * 1.08 AS taxedCost, a.zipCode " + + "FROM Customer c JOIN c.orders o JOIN c.address a " + + "WHERE a.state = 'CA' AND a.county = 'Santa Clara' " + + "ORDER BY o.quantity, taxedCost, a.zipCode"; + q = cb.create(); + Root c2 = q.from(Customer.class); + Join o2 = c2.join(Customer_.orders); + Join a2 = c2.join(Customer_.address); + q.where(cb.equal(a.get(Address_.state), "CA"), + cb.equal(a.get(Address_.county), "Santa Clara")); + q.orderBy(cb.asc(o.get(Order_.quantity)), + cb.asc(cb.prod(o.get(Order_.totalCost), 1.08)), + cb.asc(a.get(Address_.zipCode))); + q.select(o.get(Order_.quantity), + cb.prod(o.get(Order_.totalCost), 1.08), + a.get(Address_.zipCode)); + + assertEquivalence(q, jpql); + } + + @AllowFailure + void assertEquivalence(CriteriaQuery c, String jpql, + String[] paramNames, Object[] params) { + sql.clear(); + Query q = em.createQuery(c); + for (int i = 0; i < paramNames.length; i++) { + q.setParameter(paramNames[i], params[i]); + } + List cList = q.getResultList(); + assertEquals(1, sql.size()); + String cSQL = sql.get(0); + + sql.clear(); + q = em.createQuery(jpql); + for (int i = 0; i < paramNames.length; i++) { + q.setParameter(paramNames[i], params[i]); + } + List jList = q.getResultList(); + assertEquals(1, sql.size()); + String jSQL = sql.get(0); + + assertEquals(jSQL, cSQL); + } + void assertEquivalence(CriteriaQuery c, String jpql) { sql.clear(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory.java new file mode 100644 index 000000000..f7edfc05a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory.java @@ -0,0 +1,61 @@ +/* + * 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.Timestamp; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="CR_TRS") +public class TransactionHistory { + @Id + @GeneratedValue + private int id; + + private Timestamp transDate; + + private String details; + + public int getId() { + return id; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public Timestamp getTimestamp() { + return transDate; + } + + public void setTimestamp(Timestamp transDate) { + this.transDate = transDate; + } + + + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory_.java new file mode 100644 index 000000000..3a6af2a50 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TransactionHistory_.java @@ -0,0 +1,16 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import java.sql.Timestamp; +import javax.persistence.metamodel.Attribute; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.TransactionHistory.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class TransactionHistory_ { + public static volatile Attribute details; + public static volatile Attribute id; + public static volatile Attribute transDate; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore.java index eecfbd306..abb82c9f8 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore.java @@ -18,9 +18,18 @@ */ package org.apache.openjpa.persistence.criteria; +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.MapKeyJoinColumn; import javax.persistence.Table; /** @@ -29,9 +38,54 @@ import javax.persistence.Table; * */ @Entity -@Table(name="CR_VIDEOSTORE") +@Table(name="CR_VSTR") public class VideoStore { @Id - private String name; + @GeneratedValue + private int id; + private String name; + + @Embedded + private Address location; + + @ElementCollection + @CollectionTable(name="INVENTORY", + joinColumns=@JoinColumn(name="STORE")) + @Column(name="COPIES_IN_STOCK") + @MapKeyJoinColumn(name="MOVIE", referencedColumnName="ID") + private Map videoInventory = new HashMap(); + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Map getVideoInventory() { + return videoInventory; + } + + public void addToVideoInventory(Movie movie, Integer inventory) { + videoInventory.put(movie, inventory); + } + + public Address getLocation() { + return location; + } + + public void setLocation(Address location) { + this.location = location; + } + } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore_.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore_.java new file mode 100644 index 000000000..e3fd517cb --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/VideoStore_.java @@ -0,0 +1,17 @@ +/** + * Generated by OpenJPA MetaModel Generator Tool. +**/ + +package org.apache.openjpa.persistence.criteria; + +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Map; + +@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.VideoStore.class) +@javax.annotation.Generated(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Sat May 09 23:22:02 PDT 2009") +public class VideoStore_ { + public static volatile Attribute id; + public static volatile Attribute location; + public static volatile Attribute name; + public static volatile Map videoInventory; +}