mirror of https://github.com/apache/openjpa.git
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
This commit is contained in:
parent
3213665811
commit
c0bf7e40d6
|
@ -30,14 +30,50 @@ import javax.persistence.Table;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_ACCOUNT")
|
@Table(name="CR_ACCT")
|
||||||
public class Account {
|
public class Account {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private int balance;
|
private int balance;
|
||||||
private Integer loan;
|
private Integer loan;
|
||||||
private String owner;
|
private String owner;
|
||||||
private String name;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,69 @@ import javax.persistence.Table;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_ADDRESS")
|
@Table(name="CR_ADDR")
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class Address {
|
public class Address {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
|
private String street;
|
||||||
|
private String city;
|
||||||
private String state;
|
private String state;
|
||||||
private String county;
|
private String county;
|
||||||
|
private String country;
|
||||||
private String zipCode;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Address,String> city;
|
||||||
|
public static volatile Attribute<Address,String> country;
|
||||||
|
public static volatile Attribute<Address,String> county;
|
||||||
|
public static volatile Attribute<Address,Long> id;
|
||||||
|
public static volatile Attribute<Address,String> state;
|
||||||
|
public static volatile Attribute<Address,String> street;
|
||||||
|
public static volatile Attribute<Address,String> zipCode;
|
||||||
|
}
|
|
@ -31,4 +31,20 @@ public class Contact {
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private List<Phone> phones;
|
private List<Phone> phones;
|
||||||
|
|
||||||
|
public List<Phone> getPhones() {
|
||||||
|
return phones;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPhone(Phone phone) {
|
||||||
|
phones.add(phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(Address address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Contact,Address> address;
|
||||||
|
public static volatile List<Contact,Phone> phones;
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Contractor extends Person {
|
public class Contractor extends Person {
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_ {
|
||||||
|
}
|
|
@ -21,17 +21,47 @@ package org.apache.openjpa.persistence.criteria;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OrderBy;
|
import javax.persistence.OrderBy;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_COURSE")
|
@Table(name="CR_CRSE")
|
||||||
|
|
||||||
public class Course {
|
public class Course {
|
||||||
private String name;
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
@OneToMany
|
private long id;
|
||||||
@OrderBy
|
|
||||||
private List<Student> studentWaitList;
|
private String name;
|
||||||
|
|
||||||
|
@OneToMany
|
||||||
|
@OrderBy
|
||||||
|
private List<Student> studentWaitList;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Student> getStudentWaitList() {
|
||||||
|
return studentWaitList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStudentWaitList(List<Student> studentWaitList) {
|
||||||
|
this.studentWaitList = studentWaitList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStudentToWaitList(Student student) {
|
||||||
|
studentWaitList.add(student);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Course,Long> id;
|
||||||
|
public static volatile Attribute<Course,String> name;
|
||||||
|
public static volatile List<Course,Student> studentWaitList;
|
||||||
|
}
|
|
@ -21,19 +21,48 @@ package org.apache.openjpa.persistence.criteria;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.OrderBy;
|
import javax.persistence.OrderBy;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_CREDITCARD")
|
@Table(name="CR_CRDTC")
|
||||||
|
|
||||||
public class CreditCard {
|
public class CreditCard {
|
||||||
@OneToOne
|
@Id
|
||||||
private Employee holder;
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
private Customer customer;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
@OrderBy
|
@OrderBy
|
||||||
private List<Transaction> transactionHistory;
|
private List<TransactionHistory> transactionHistory;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TransactionHistory> getTransactionHistory() {
|
||||||
|
return transactionHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransactionHistory(List<TransactionHistory> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<CreditCard,Customer> customer;
|
||||||
|
public static volatile Attribute<CreditCard,Long> id;
|
||||||
|
public static volatile List<CreditCard,TransactionHistory> transactionHistory;
|
||||||
|
}
|
|
@ -18,38 +18,131 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_CUSTOMER")
|
@Table(name="CR_CUST")
|
||||||
|
|
||||||
public class Customer {
|
public class Customer {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
private String name;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private Set<Order> orders;
|
private Set<Order> orders = new HashSet<Order>();
|
||||||
|
|
||||||
private int status;
|
private int status;
|
||||||
private int balanceOwned;
|
private int balanceOwed;
|
||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
private Address address;
|
private Address address;
|
||||||
|
|
||||||
private int filledOrderCount;
|
private int filledOrderCount;
|
||||||
private String country;
|
|
||||||
|
private long accountNum;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private List<Account> accounts;
|
private List<Account> accounts = new ArrayList<Account>();
|
||||||
|
|
||||||
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<Order> getOrders() {
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrders(Set<Order> 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<Account> getAccounts() {
|
||||||
|
return accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccounts(List<Account> accounts) {
|
||||||
|
this.accounts = accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Customer(long id, int status, int count) {
|
public Customer(long id, int status, int count) {
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -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<Customer,Long> accountNum;
|
||||||
|
public static volatile List<Customer,Account> accounts;
|
||||||
|
public static volatile Attribute<Customer,Address> address;
|
||||||
|
public static volatile Attribute<Customer,Integer> balanceOwed;
|
||||||
|
public static volatile Attribute<Customer,Integer> filledOrderCount;
|
||||||
|
public static volatile Attribute<Customer,String> firstName;
|
||||||
|
public static volatile Attribute<Customer,Long> id;
|
||||||
|
public static volatile Attribute<Customer,String> lastName;
|
||||||
|
public static volatile Attribute<Customer,String> name;
|
||||||
|
public static volatile Set<Customer,Order> orders;
|
||||||
|
public static volatile Attribute<Customer,Integer> status;
|
||||||
|
}
|
|
@ -21,15 +21,44 @@ package org.apache.openjpa.persistence.criteria;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_DEPARTMENT")
|
@Table(name="CR_DEPT")
|
||||||
|
|
||||||
public class Department {
|
public class Department {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
private int deptNo;
|
private int deptNo;
|
||||||
private String name;
|
private String name;
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private Set<Employee> employees;
|
private Set<Employee> 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<Employee> getEmployees() {
|
||||||
|
return employees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmployees(Set<Employee> employees){
|
||||||
|
this.employees = employees;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Department,Integer> deptNo;
|
||||||
|
public static volatile Set<Department,Employee> employees;
|
||||||
|
public static volatile Attribute<Department,String> name;
|
||||||
|
}
|
|
@ -18,29 +18,104 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.DiscriminatorColumn;
|
||||||
import javax.persistence.Embedded;
|
import javax.persistence.Embedded;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Inheritance;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_EMPLOYEE")
|
@Table(name="CR_EMP")
|
||||||
|
@Inheritance
|
||||||
|
@DiscriminatorColumn(name="EMP_TYPE")
|
||||||
public class Employee {
|
public class Employee {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int empId;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
@Embedded
|
@Embedded
|
||||||
private Contact contactInfo;
|
private Contact contactInfo;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Department department;
|
private Department department;
|
||||||
private int rating;
|
|
||||||
private float salary;
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
private Employee spouse;
|
private Employee spouse;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Manager manager;
|
private Manager manager;
|
||||||
|
|
||||||
@OneToOne
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Employee,Contact> contactInfo;
|
||||||
|
public static volatile Attribute<Employee,Department> department;
|
||||||
|
public static volatile Attribute<Employee,Integer> empId;
|
||||||
|
public static volatile Attribute<Employee,FrequentFlierPlan> frequentFlierPlan;
|
||||||
|
public static volatile Attribute<Employee,Manager> manager;
|
||||||
|
public static volatile Attribute<Employee,String> name;
|
||||||
|
public static volatile Attribute<Employee,Integer> rating;
|
||||||
|
public static volatile Attribute<Employee,Long> salary;
|
||||||
|
public static volatile Attribute<Employee,Employee> spouse;
|
||||||
|
}
|
|
@ -18,17 +18,22 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_EXEMPT")
|
public class Exempt extends Employee {
|
||||||
|
@Basic
|
||||||
public class Exempt {
|
private Date hireDate;
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
public void setHireDate(Date hireDate) {
|
||||||
private String id;
|
this.hireDate = hireDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getHireDate() {
|
||||||
|
return hireDate;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Exempt,Date> hireDate;
|
||||||
|
}
|
|
@ -21,15 +21,50 @@ package org.apache.openjpa.persistence.criteria;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_ITEM")
|
@Table(name="CR_ITEM")
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
@OneToMany
|
|
||||||
|
@OneToMany
|
||||||
private Map<String, Photo> photos;
|
private Map<String, Photo> photos;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Photo> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Item,Integer> id;
|
||||||
|
public static volatile Attribute<Item,String> name;
|
||||||
|
public static volatile Map<Item,String,Photo> photos;
|
||||||
|
}
|
|
@ -19,14 +19,74 @@
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_LINEITEM")
|
@Table(name="CR_LI")
|
||||||
|
|
||||||
public class LineItem {
|
public class LineItem {
|
||||||
private int price;
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private double price;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Order order;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<LineItem,Double> cost;
|
||||||
|
public static volatile Attribute<LineItem,Integer> id;
|
||||||
|
public static volatile Attribute<LineItem,Order> order;
|
||||||
|
public static volatile Attribute<LineItem,Double> price;
|
||||||
|
public static volatile Attribute<LineItem,Product> product;
|
||||||
|
public static volatile Attribute<LineItem,Integer> quantity;
|
||||||
|
}
|
|
@ -18,11 +18,54 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Manager,Department> department;
|
||||||
|
public static volatile Attribute<Manager,Integer> id;
|
||||||
|
public static volatile Attribute<Manager,String> name;
|
||||||
|
public static volatile Attribute<Manager,BigDecimal> salary;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Movie,Integer> id;
|
||||||
|
public static volatile Attribute<Movie,String> title;
|
||||||
|
}
|
|
@ -21,21 +21,64 @@ package org.apache.openjpa.persistence.criteria;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_ORDER")
|
@Table(name="CR_ODR")
|
||||||
public class Order {
|
public class Order {
|
||||||
private int quantity;
|
@Id
|
||||||
private int cost;
|
@GeneratedValue
|
||||||
private int totalcost;
|
private int id;
|
||||||
|
|
||||||
|
private int quantity;
|
||||||
|
private double totalCost;
|
||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Customer customer;
|
private Customer customer;
|
||||||
|
|
||||||
@OneToMany(mappedBy="order")
|
@OneToMany(mappedBy="order")
|
||||||
private List<LineItem> lineItems;
|
private List<LineItem> 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<LineItem> getLineItems() {
|
||||||
|
return lineItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLineitems(List<LineItem> lineItems) {
|
||||||
|
this.lineItems = lineItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(int quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Order,Integer> count;
|
||||||
|
public static volatile Attribute<Order,Customer> customer;
|
||||||
|
public static volatile Attribute<Order,Integer> id;
|
||||||
|
public static volatile List<Order,LineItem> lineItems;
|
||||||
|
public static volatile Attribute<Order,Integer> quantity;
|
||||||
|
public static volatile Attribute<Order,Double> totalCost;
|
||||||
|
}
|
|
@ -18,22 +18,48 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
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.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.apache.openjpa.persistence.PersistentCollection;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_PERSON")
|
@Table(name="CR_PSN")
|
||||||
|
|
||||||
public class Person {
|
public class Person {
|
||||||
@Id
|
@Id
|
||||||
private long ssn;
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
@PersistentCollection
|
@ElementCollection
|
||||||
private List<String> nicknames;
|
private Set<String> nickNames;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getNickNames() {
|
||||||
|
return nickNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNickNames(Set<String> nickNames) {
|
||||||
|
this.nickNames = nickNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNickName(String nickName) {
|
||||||
|
nickNames.add(nickName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Person,Integer> id;
|
||||||
|
public static volatile Attribute<Person,String> name;
|
||||||
|
public static volatile Set<Person,String> nickNames;
|
||||||
|
}
|
|
@ -18,12 +18,44 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_PHONE")
|
@Table(name="CR_PHN")
|
||||||
|
|
||||||
public class Phone {
|
public class Phone {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
private Collection<Employee> employees = new ArrayList<Employee>();
|
||||||
|
|
||||||
private String vendor;
|
private String vendor;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Employee> getEmployees() {
|
||||||
|
return employees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEmployees(Employee employee) {
|
||||||
|
employees.add(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVendor() {
|
||||||
|
return vendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVendor(String vendor) {
|
||||||
|
this.vendor = vendor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Phone,Employee> employees;
|
||||||
|
public static volatile Attribute<Phone,Integer> id;
|
||||||
|
public static volatile Attribute<Phone,String> vendor;
|
||||||
|
}
|
|
@ -19,11 +19,29 @@
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_PHOTO")
|
@Table(name="CR_PHT")
|
||||||
|
|
||||||
public class Photo {
|
public class Photo {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Photo,Integer> id;
|
||||||
|
public static volatile Attribute<Photo,String> label;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Product,Integer> pid;
|
||||||
|
public static volatile Attribute<Product,String> productType;
|
||||||
|
public static volatile Attribute<Product,Long> version;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Semester,Integer> id;
|
||||||
|
public static volatile Attribute<Semester,String> name;
|
||||||
|
}
|
|
@ -18,16 +18,54 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinTable;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
|
import javax.persistence.MapKeyJoinColumn;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_STUDENT")
|
@Table(name="CR_STU")
|
||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@JoinTable(name="ENROLLMENTS",
|
||||||
|
joinColumns=@JoinColumn(name="STUDENT"),
|
||||||
|
inverseJoinColumns=@JoinColumn(name="SEMESTER"))
|
||||||
|
@MapKeyJoinColumn(name="COURSE")
|
||||||
|
private Map<Course, Semester> enrollment =
|
||||||
|
new HashMap<Course, Semester>();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Student,Course,Semester> enrollment;
|
||||||
|
public static volatile Attribute<Student,Integer> id;
|
||||||
|
public static volatile Attribute<Student,String> name;
|
||||||
|
}
|
|
@ -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> account_ = null;
|
||||||
|
protected Embeddable<Address> address_ = null;
|
||||||
|
protected Embeddable<Contact> contact_ = null;
|
||||||
|
protected Entity<Course> course_ = null;
|
||||||
|
protected Entity<CreditCard> creditCard_ = null;
|
||||||
|
protected Entity<Customer> customer_ = null;
|
||||||
|
protected Entity<Department> department_ = null;
|
||||||
|
protected Entity<Employee> employee_ = null;
|
||||||
|
protected Entity<Exempt> exempt_ = null;
|
||||||
|
protected Entity<Item> item_ = null;
|
||||||
|
protected Entity<LineItem> lineItem_ = null;
|
||||||
|
protected Entity<Manager> manager_ = null;
|
||||||
|
protected Entity<Movie> movie_ = null;
|
||||||
|
protected Entity<Order> order_ = null;
|
||||||
|
protected Entity<Person> person_ = null;
|
||||||
|
protected Entity<Phone> phone_ = null;
|
||||||
|
protected Entity<Photo> photo_ = null;
|
||||||
|
protected Entity<Product> product_ = null;
|
||||||
|
protected Entity<Semester> semester_ = null;
|
||||||
|
protected Entity<Student> student_ = null;
|
||||||
|
protected Entity<TransactionHistory> transactionHistory_ = null;
|
||||||
|
protected Entity<VideoStore> 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> 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<Customer> cust = q.from(Customer.class);
|
||||||
|
Join<Customer, Order> order = cust.join(customer_.getSet("orders",
|
||||||
|
Order.class));
|
||||||
|
Join<Order, LineItem> 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<Customer> cust1 = q.from(Customer.class);
|
||||||
|
Join<Customer, Order> 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<Department> 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<Employee> emp = q.from(Employee.class);
|
||||||
|
Join<Contact, Phone> 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> item = q.from(Item.class);
|
||||||
|
MapJoin<Item, String, Photo> 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<CreditCard> c = q.from(CreditCard.class);
|
||||||
|
ListJoin<CreditCard, TransactionHistory> 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> order = q.from(Order.class);
|
||||||
|
Join<Order,LineItem> 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<Customer> cust = q.from(Customer.class);
|
||||||
|
Join<Customer, Order> order = cust.join(customer_.getSet("orders",
|
||||||
|
Order.class));
|
||||||
|
Join<Customer, Address> 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<Employee> 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> course = q.from(Course.class);
|
||||||
|
ListJoin<Course, Student> 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<Order> o = q.from(Order.class);
|
||||||
|
Join<Order, LineItem> i = o.join(order_.getList("lineItems",
|
||||||
|
LineItem.class));
|
||||||
|
Join<Order, Customer> 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<Department> 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<Employee> 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<Person> 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<Customer> c = q.from(Customer.class);
|
||||||
|
Parameter<Integer> 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<VideoStore> v = q.from(VideoStore.class);
|
||||||
|
MapJoin<VideoStore, Movie, Integer> 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<Customer> c = q.from(Customer.class);
|
||||||
|
Join<Customer, Order> 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<Customer> goodCustomer = q.from(Customer.class);
|
||||||
|
Subquery<Double> sq = q.subquery(Double.class);
|
||||||
|
Root<Customer> 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<Employee> emp = q.from(Employee.class);
|
||||||
|
Subquery<Employee> sq1 = q.subquery(Employee.class);
|
||||||
|
Root<Employee> 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<Employee> emp1 = q.from(Employee.class);
|
||||||
|
q.select(emp1);
|
||||||
|
Subquery<BigDecimal> sq2 = q.subquery(BigDecimal.class);
|
||||||
|
Root<Manager> 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<Customer> c1 = q.from(Customer.class);
|
||||||
|
q.select(c1);
|
||||||
|
Subquery<Long> sq3 = q.subquery(Long.class);
|
||||||
|
Root<Customer> c2 = sq3.correlate(c1);
|
||||||
|
Join<Customer,Order> 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<Order> o1 = q.from(Order.class);
|
||||||
|
q.select(o1);
|
||||||
|
Subquery<Integer> sq4 = q.subquery(Integer.class);
|
||||||
|
Root<Order> o2 = sq4.correlate(o1);
|
||||||
|
Join<Order,Customer> c3 = o2.join(order_.getAttribute("customer",
|
||||||
|
Customer.class));
|
||||||
|
Join<Customer,Account> 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<Order> o3 = q.from(Order.class);
|
||||||
|
q.select(o3);
|
||||||
|
Join<Order,Customer> c4 = o3.join(Order_.customer);
|
||||||
|
Subquery<Integer> sq5 = q.subquery(Integer.class);
|
||||||
|
Join<Order,Customer> c5 = sq5.correlate(c4);
|
||||||
|
Join<Customer,Account> 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<Customer> 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<Customer> c = q.from(Customer.class);
|
||||||
|
Join<Customer,Order> o = c.join(customer_.getSet("orders",
|
||||||
|
Order.class));
|
||||||
|
Join<Customer,Address> 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<Customer> c1 = q.from(Customer.class);
|
||||||
|
Join<Customer,Order> o1 = c1.join(customer_.getSet("orders",
|
||||||
|
Order.class));
|
||||||
|
Join<Customer,Address> 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<Customer> c2 = q.from(Customer.class);
|
||||||
|
Join<Customer,Order> o2 = c2.join(customer_.getSet("orders",
|
||||||
|
Order.class));
|
||||||
|
Join<Customer,Address> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,13 +1,22 @@
|
||||||
package org.apache.openjpa.persistence.criteria;
|
package org.apache.openjpa.persistence.criteria;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.Parameter;
|
||||||
|
import javax.persistence.Query;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
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.Root;
|
||||||
|
import javax.persistence.criteria.Subquery;
|
||||||
|
|
||||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||||
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
||||||
|
import org.apache.openjpa.persistence.test.AllowFailure;
|
||||||
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +38,32 @@ public class TestTypesafeCriteria extends SQLListenerTestCase {
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
public void setUp() {
|
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();
|
setDictionary();
|
||||||
cb = (CriteriaBuilder)emf.getQueryBuilder();
|
cb = (CriteriaBuilder)emf.getQueryBuilder();
|
||||||
em = emf.createEntityManager();
|
em = emf.createEntityManager();
|
||||||
|
@ -154,6 +188,393 @@ public class TestTypesafeCriteria extends SQLListenerTestCase {
|
||||||
// c.from(Account.class).join(Account_.history)
|
// 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<Customer> cust = c.from(Customer.class);
|
||||||
|
Join<Customer, Order> order = cust.join(Customer_.orders);
|
||||||
|
Join<Order, LineItem> 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<Customer> cust1 = c.from(Customer.class);
|
||||||
|
Join<Customer, Order> 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<Department> 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<Employee> emp = q.from(Employee.class);
|
||||||
|
Join<Contact, Phone> 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> item = q.from(Item.class);
|
||||||
|
MapJoin<Item, String, Photo> 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<CreditCard> c = q.from(CreditCard.class);
|
||||||
|
ListJoin<CreditCard, TransactionHistory> 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> 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<Customer> cust = q.from(Customer.class);
|
||||||
|
Join<Customer, Order> order = cust.join(Customer_.orders);
|
||||||
|
Join<Customer, Address> 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<Employee> 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> course = q.from(Course.class);
|
||||||
|
ListJoin<Course, Student> 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<Order> o = q.from(Order.class);
|
||||||
|
Join<Order, LineItem> i = o.join(Order_.lineItems);
|
||||||
|
Join<Order, Customer> 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<Department> 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<Employee> 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<Person> 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<Customer> c = q.from(Customer.class);
|
||||||
|
Parameter<Integer> 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<VideoStore> v = q.from(VideoStore.class);
|
||||||
|
MapJoin<VideoStore, Movie, Integer> 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<Customer> c = q.from(Customer.class);
|
||||||
|
Join<Customer, Order> 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<Customer> goodCustomer = q.from(Customer.class);
|
||||||
|
Subquery<Double> sq = q.subquery(Double.class);
|
||||||
|
Root<Customer> 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<Employee> emp = q.from(Employee.class);
|
||||||
|
Subquery<Employee> sq1 = q.subquery(Employee.class);
|
||||||
|
Root<Employee> 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<Employee> emp1 = q.from(Employee.class);
|
||||||
|
q.select(emp1);
|
||||||
|
Subquery<BigDecimal> sq2 = q.subquery(BigDecimal.class);
|
||||||
|
Root<Manager> 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<Customer> c1 = q.from(Customer.class);
|
||||||
|
q.select(c1);
|
||||||
|
Subquery<Long> sq3 = q.subquery(Long.class);
|
||||||
|
Root<Customer> c2 = sq3.correlate(c1);
|
||||||
|
Join<Customer,Order> 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<Order> o1 = q.from(Order.class);
|
||||||
|
q.select(o1);
|
||||||
|
Subquery<Integer> sq4 = q.subquery(Integer.class);
|
||||||
|
Root<Order> o2 = sq4.correlate(o1);
|
||||||
|
Join<Order,Customer> c3 = o2.join(Order_.customer);
|
||||||
|
Join<Customer,Account> 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<Order> o3 = q.from(Order.class);
|
||||||
|
q.select(o3);
|
||||||
|
Join<Order,Customer> c4 = o3.join(Order_.customer);
|
||||||
|
Subquery<Integer> sq5 = q.subquery(Integer.class);
|
||||||
|
Join<Order,Customer> c5 = sq5.correlate(c4);
|
||||||
|
Join<Customer,Account> 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<Customer> 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<Customer> c = q.from(Customer.class);
|
||||||
|
Join<Customer,Order> o = c.join(Customer_.orders);
|
||||||
|
Join<Customer,Address> 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<Customer> c1 = q.from(Customer.class);
|
||||||
|
Join<Customer,Order> o1 = c1.join(Customer_.orders);
|
||||||
|
Join<Customer,Address> 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<Customer> c2 = q.from(Customer.class);
|
||||||
|
Join<Customer,Order> o2 = c2.join(Customer_.orders);
|
||||||
|
Join<Customer,Address> 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) {
|
void assertEquivalence(CriteriaQuery c, String jpql) {
|
||||||
sql.clear();
|
sql.clear();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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<TransactionHistory,String> details;
|
||||||
|
public static volatile Attribute<TransactionHistory,Integer> id;
|
||||||
|
public static volatile Attribute<TransactionHistory,Timestamp> transDate;
|
||||||
|
}
|
|
@ -18,9 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.criteria;
|
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.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.MapKeyJoinColumn;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,9 +38,54 @@ import javax.persistence.Table;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="CR_VIDEOSTORE")
|
@Table(name="CR_VSTR")
|
||||||
public class VideoStore {
|
public class VideoStore {
|
||||||
@Id
|
@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<Movie, Integer> videoInventory = new HashMap<Movie, Integer>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<VideoStore,Integer> id;
|
||||||
|
public static volatile Attribute<VideoStore,Address> location;
|
||||||
|
public static volatile Attribute<VideoStore,String> name;
|
||||||
|
public static volatile Map<VideoStore,Movie,Integer> videoInventory;
|
||||||
|
}
|
Loading…
Reference in New Issue