OPENJPA-1015. Enforce column width for testcases

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@779361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-05-28 00:22:33 +00:00
parent fcebb24e61
commit 3464d8e9b8
31 changed files with 3083 additions and 2978 deletions

View File

@ -52,9 +52,10 @@ public class XMLDefPropMixedFieldAccess2 {
public boolean equals(Object obj) {
if (obj instanceof XMLDefPropMixedFieldAccess2) {
XMLDefPropMixedFieldAccess2 dpmfa = (XMLDefPropMixedFieldAccess2)obj;
return getId() == dpmfa.getId() &&
getStrField().equals(dpmfa.getStrProp());
XMLDefPropMixedFieldAccess2 dpmfa =
(XMLDefPropMixedFieldAccess2) obj;
return getId() == dpmfa.getId()
&& getStrField().equals(dpmfa.getStrProp());
}
return false;
}

View File

@ -7,12 +7,14 @@ 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.CompUser.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.criteria.CompUser.class)
public class CompUser_ {
public static volatile Attribute<CompUser,Address> address;
public static volatile Attribute<CompUser,Integer> age;
public static volatile Attribute<CompUser,String> computerName;
public static volatile Attribute<CompUser,CompUser.CreditRating> creditRating;
public static volatile Attribute<CompUser,
CompUser.CreditRating> creditRating;
public static volatile Attribute<CompUser,String> name;
public static volatile List<CompUser,String> nicknames;
public static volatile Attribute<CompUser,Integer> userid;

View File

@ -50,7 +50,8 @@ public class CreditCard {
return transactionHistory;
}
public void setTransactionHistory(List<TransactionHistory> transactionHistory) {
public void setTransactionHistory(List<TransactionHistory>
transactionHistory) {
this.transactionHistory = transactionHistory;
}

View File

@ -22,5 +22,6 @@ public class Customer_ {
public static volatile Attribute<Customer,String> name;
public static volatile Set<Customer,Order> orders;
public static volatile Attribute<Customer,Integer> status;
public static volatile Attribute<Customer,Customer.CreditRating> creditRating;
public static volatile Attribute<Customer,Customer.CreditRating>
creditRating;
}

View File

@ -12,7 +12,8 @@ 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,FrequentFlierPlan>
frequentFlierPlan;
public static volatile Attribute<Employee,Manager> manager;
public static volatile Attribute<Employee,String> name;
public static volatile Attribute<Employee,Integer> rating;

View File

@ -5,6 +5,7 @@
package org.apache.openjpa.persistence.criteria;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.FemaleUser.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.criteria.FemaleUser.class)
public class FemaleUser_ extends CompUser_ {
}

View File

@ -6,7 +6,8 @@ package org.apache.openjpa.persistence.criteria;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.FrequentFlierPlan.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.criteria.FrequentFlierPlan.class)
public class FrequentFlierPlan_ {
public static volatile Attribute<FrequentFlierPlan,Integer> annualMiles;
public static volatile Attribute<FrequentFlierPlan,String> id;

View File

@ -5,6 +5,7 @@
package org.apache.openjpa.persistence.criteria;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.MaleUser.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.criteria.MaleUser.class)
public class MaleUser_ extends CompUser_ {
}

View File

@ -153,8 +153,9 @@ public class TestMetaModelTypesafeCriteria extends CriteriaTest {
@AllowFailure
public void testFetchJoins() {
String jpql = "SELECT d FROM Department LEFT JOIN FETCH d.employees " +
"WHERE d.deptNo = 1";
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);
@ -174,10 +175,10 @@ public class TestMetaModelTypesafeCriteria extends CriteriaTest {
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.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);
@ -348,9 +349,10 @@ public class TestMetaModelTypesafeCriteria extends CriteriaTest {
@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";
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(
@ -370,7 +372,8 @@ public class TestMetaModelTypesafeCriteria extends CriteriaTest {
"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));
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,
@ -413,8 +416,10 @@ public class TestMetaModelTypesafeCriteria extends CriteriaTest {
assertEquivalence(q, jpql);
jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL (" +
"SELECT m.salary FROM Manager m WHERE m.department = emp.department)";
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);

View File

@ -297,7 +297,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
CriteriaQuery q = cb.create();
Root<CompUser> c = q.from(CompUser.class);
Parameter<String> param = cb.parameter(String.class);
q.where(cb.equal(c.get(CompUser_.address).get(Address_.country), null));
q.where(cb.equal(c.get(CompUser_.address).get(Address_.country),
null));
q.select(c.get(CompUser_.name));
assertEquivalence(q, query);
List result = em.createQuery(q).getResultList();
@ -534,7 +535,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testTrimFunc1() {
String query = "select Trim(e.computerName) From CompUser e WHERE e.name='Shannon '";
String query = "select Trim(e.computerName) From CompUser e " +
"WHERE e.name='Shannon '";
CriteriaQuery q = cb.create();
q = cb.create();
Root<CompUser> e = q.from(CompUser.class);
@ -572,7 +574,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testLowerFunc2() {
String query = "select e.age From CompUser e where LOWER(e.name) ='ugo'";
String query = "select e.age From CompUser e where LOWER(e.name)" +
" ='ugo'";
CriteriaQuery q = cb.create();
q = cb.create();
Root<CompUser> e = q.from(CompUser.class);
@ -815,7 +818,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
// can not do TYPE with parameter in the IN clause
@AllowFailure
public void testTypeExpression1() {
String query = "SELECT e FROM CompUser e where TYPE(e) in (?1, ?2) ORDER By e.name";
String query = "SELECT e FROM CompUser e where TYPE(e) in (?1, ?2) " +
"ORDER By e.name";
CriteriaQuery q = cb.create();
q = cb.create();
Root<CompUser> e = q.from(CompUser.class);
@ -883,7 +887,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testTypeExpression6() {
String query = "SELECT e FROM CompUser e where TYPE(e) not in (MaleUser, FemaleUser)";
String query = "SELECT e FROM CompUser e where TYPE(e) not in " +
"(MaleUser, FemaleUser)";
CriteriaQuery q = cb.create();
q = cb.create();
Root<CompUser> e = q.from(CompUser.class);
@ -1115,11 +1120,14 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
public void testGeneralCaseExpression3() {
String query = " select e.name, "
+ "CASE WHEN e.age = 11 THEN "
+ "org.apache.openjpa.persistence.criteria.CompUser$CreditRating.POOR"
+ "org.apache.openjpa.persistence.criteria.CompUser$" +
"CreditRating.POOR"
+ " WHEN e.age = 35 THEN "
+ "org.apache.openjpa.persistence.criteria.CompUser$CreditRating.GOOD"
+ "org.apache.openjpa.persistence.criteria.CompUser$" +
"CreditRating.GOOD"
+ " ELSE "
+ "org.apache.openjpa.persistence.criteria.CompUser$CreditRating.EXCELLENT"
+ "org.apache.openjpa.persistence.criteria.CompUser$" +
"CreditRating.EXCELLENT"
+ " END FROM CompUser e ORDER BY e.age";
CriteriaQuery q = cb.create();
Root<CompUser> e = q.from(CompUser.class);
@ -1145,11 +1153,14 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
+ "where e.creditRating = "
+ "(select "
+ "CASE WHEN e1.age = 11 THEN "
+ "org.apache.openjpa.persistence.criteria.CompUser$CreditRating.POOR"
+ "org.apache.openjpa.persistence.criteria.CompUser$" +
"CreditRating.POOR"
+ " WHEN e1.age = 35 THEN "
+ "org.apache.openjpa.persistence.criteria.CompUser$CreditRating.GOOD"
+ "org.apache.openjpa.persistence.criteria.CompUser$" +
"CreditRating.GOOD"
+ " ELSE "
+ "org.apache.openjpa.persistence.criteria.CompUser$CreditRating.EXCELLENT"
+ "org.apache.openjpa.persistence.criteria.CompUser$" +
"CreditRating.EXCELLENT"
+ " END from CompUser e1"
+ " where e.userid = e1.userid) ORDER BY e.age";
CriteriaQuery q = cb.create();
@ -1340,7 +1351,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testSubquery10() {
String query = "select o.id from Order o where o.quantity >"
+ " (select sum(o2.quantity) from Customer c, in(c.orders) o2) ";
+ " (select sum(o2.quantity) from Customer c, "
+ "in(c.orders) o2) ";
CriteriaQuery q = cb.create();
Root<Order> o = q.from(Order.class);
q.select(o.get(Order_.id));
@ -1358,7 +1370,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
public void testSubquery11() {
String query = "select o.id from Order o where o.quantity between"
+ " (select avg(o2.quantity) from Customer c, in(c.orders) o2)"
+ " and (select min(o2.quantity) from Customer c, in(c.orders) o2)";
+ " and (select min(o2.quantity) from Customer c, in(c.orders)"
+ " o2)";
CriteriaQuery q = cb.create();
Root<Order> o = q.from(Order.class);
q.select(o.get(Order_.id));
@ -1380,8 +1393,10 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testSubquery12() {
String query = "select o.id from Customer c, in(c.orders)o "
+ "where o.quantity > (select sum(o2.quantity) from c.orders o2)";
String query =
"select o.id from Customer c, in(c.orders)o "
+ "where o.quantity > (select sum(o2.quantity)"
+ " from c.orders o2)";
CriteriaQuery q = cb.create();
Root<Customer> c = q.from(Customer.class);
SetJoin<Customer, Order> o = c.join(Customer_.orders);
@ -1431,7 +1446,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
Subquery<Integer> sq = q.subquery(Integer.class);
Root<Magazine> m2 = sq.from(Magazine.class);
q.where(cb.equal(m.get(Magazine_.id), sq.select(cb.max(m2.get(Magazine_.id)))));
q.where(cb.equal(m.get(Magazine_.id), sq.select(cb.max(m2
.get(Magazine_.id)))));
Subquery<Integer> sq2 = q.subquery(Integer.class);
Root<Magazine> m3 = sq2.from(Magazine.class);
@ -1439,18 +1455,17 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
sq2.where(cb.equal(m3.get(Magazine_.idPublisher).get(Publisher_.id),
p.get(Publisher_.id)));
sq.where(
cb.and(
cb.equal(m2.get(Magazine_.idPublisher).get(Publisher_.id), p.get(Publisher_.id)),
cb.equal(m2.get(Magazine_.datePublished), sq2.select(cb.max(m3.get(Magazine_.id))))
)
);
sq.where(cb.and(cb.equal(m2.get(Magazine_.idPublisher).get(
Publisher_.id), p.get(Publisher_.id)), cb.equal(m2
.get(Magazine_.datePublished), sq2.select(cb.max(m3
.get(Magazine_.id))))));
assertEquivalence(q, query);
}
// outstanding problem subqueries:
// "select o from Order o where o.amount > (select count(o) from Order o)",
// "select o from Order o where o.amount > (select count(o2) from Order o2)",
// "select o from Order o where o.amount > (select count(o2) from Order o2)
//",
// "select c from Customer c left join c.orders p where not exists"
// + " (select o2 from c.orders o2 where o2 = o",
@ -1486,7 +1501,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
public void testSubquery16() {
String query = "select o1.oid from Order o1 where o1.quantity > "
+ " (select o.quantity*2 from LineItem i, Order o"
+ " where i.quantity > 10 and o.quantity > 1000 and i.id = o.id)";
+ " where i.quantity > 10 and o.quantity > 1000 and i.id = " +
"o.id)";
CriteriaQuery q = cb.create();
Root<Order> o1 = q.from(Order.class);
q.select(o1.get(Order_.id));
@ -1546,7 +1562,8 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testSubquery19() {
String query = "select o.id from Order o where o.quantity >"
+ " (select SQRT(o.quantity) from Order o where o.delivered = true)";
+ " (select SQRT(o.quantity) from Order o where o.delivered" +
" = true)";
CriteriaQuery q = cb.create();
Root<Order> o = q.from(Order.class);
q.select(o.get(Order_.id));
@ -1584,11 +1601,14 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
String query = "select c from Customer c where c.creditRating ="
+ " (select "
+ " CASE WHEN o2.quantity > 10 THEN "
+ "org.apache.openjpa.persistence.criteria.Customer$CreditRating.POOR"
+ "org.apache.openjpa.persistence.criteria.Customer$" +
"CreditRating.POOR"
+ " WHEN o2.quantity = 10 THEN "
+ "org.apache.openjpa.persistence.criteria.Customer$CreditRating.GOOD "
+ "org.apache.openjpa.persistence.criteria.Customer$" +
"CreditRating.GOOD "
+ " ELSE "
+ "org.apache.openjpa.persistence.criteria.Customer$CreditRating.EXCELLENT "
+ "org.apache.openjpa.persistence.criteria.Customer$" +
"CreditRating.EXCELLENT "
+ " END from Order o2"
+ " where c.id = o2.customer.id)";
CriteriaQuery q = cb.create();
@ -1597,16 +1617,18 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
Subquery<String> sq = q.subquery(String.class);
Root<Order> o2 = sq.from(Order.class);
sq.where(cb.equal(c.get(Customer_.id), o2.get(Order_.customer).get(Customer_.id)));
sq.where(cb.equal(c.get(Customer_.id), o2.get(Order_.customer).get(
Customer_.id)));
q.where(cb.equal(c.get(Customer_.creditRating),
//sq.select(
cb.selectCase()
.when(cb.gt(o2.get(Order_.quantity), 10), Customer.CreditRating.POOR)
.when(cb.equal(o2.get(Order_.quantity), 10), Customer.CreditRating.GOOD)
.otherwise(Customer.CreditRating.EXCELLENT)
//)
));
cb.selectCase().when(cb.gt(o2.get(Order_.quantity), 10),
Customer.CreditRating.POOR).when(
cb.equal(o2.get(Order_.quantity), 10),
Customer.CreditRating.GOOD).otherwise(
Customer.CreditRating.EXCELLENT)
// )
));
assertEquivalence(q, query);
}
@ -1615,14 +1637,17 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
public void testSubquery22() {
String query = "select c from Customer c "
+ "where c.creditRating = (select COALESCE (c1.creditRating, "
+ "org.apache.openjpa.persistence.criteria.Customer$CreditRating.POOR) "
+ "from Customer c1 where c1.name = 'Famzy') order by c.name DESC";
+ "org.apache.openjpa.persistence.criteria.Customer$" +
"CreditRating.POOR) "
+ "from Customer c1 where c1.name = 'Famzy') order by c.name " +
"DESC";
CriteriaQuery q = cb.create();
Root<Customer> c = q.from(Customer.class);
q.select(c);
q.orderBy(cb.desc(c.get(Customer_.name)));
Subquery<Customer.CreditRating> sq = q.subquery(Customer.CreditRating.class);
Subquery<Customer.CreditRating> sq =
q.subquery(Customer.CreditRating.class);
Root<Customer> c1 = sq.from(Customer.class);
sq.where(cb.equal(c1.get(Customer_.name), "Famzy"));
@ -1634,16 +1659,20 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
@AllowFailure
public void testSubquery23() {
String query = "select c from Customer c "
+ "where c.creditRating = (select NULLIF (c1.creditRating, "
+ "org.apache.openjpa.persistence.criteria.Customer$CreditRating.POOR) "
+ "from Customer c1 where c1.name = 'Famzy') order by c.name DESC";
String query =
"select c from Customer c "
+ "where c.creditRating = (select NULLIF (c1.creditRating, "
+ "org.apache.openjpa.persistence.criteria."
+ "Customer$CreditRating.POOR) "
+ "from Customer c1 where c1.name = 'Famzy') "
+ "order by c.name DESC";
CriteriaQuery q = cb.create();
Root<Customer> c = q.from(Customer.class);
q.select(c);
q.orderBy(cb.desc(c.get(Customer_.name)));
Subquery<Customer.CreditRating> sq = q.subquery(Customer.CreditRating.class);
Subquery<Customer.CreditRating> sq =
q.subquery(Customer.CreditRating.class);
Root<Customer> c1 = sq.from(Customer.class);
sq.where(cb.equal(c1.get(Customer_.name), "Famzy"));

View File

@ -121,7 +121,8 @@ public class TestTypesafeCriteria extends CriteriaTest {
}
public void testInPredicateWithPath() {
String jpql = "select a from Account a where a.owner.name in ('X','Y','Z')";
String jpql =
"select a from Account a where a.owner.name in ('X','Y','Z')";
CriteriaQuery c = cb.create();
Root<Account> account = c.from(Account.class);
c.where(cb.in(account.get(Account_.owner).get(Person_.name)).value("X")
@ -130,7 +131,8 @@ public class TestTypesafeCriteria extends CriteriaTest {
}
public void testBinaryPredicate() {
String jpql = "select a from Account a where a.balance>100 and a.balance<200";
String jpql =
"select a from Account a where a.balance>100 and a.balance<200";
CriteriaQuery c = cb.create();
Root<Account> account = c.from(Account.class);
@ -154,7 +156,8 @@ public class TestTypesafeCriteria extends CriteriaTest {
}
public void testBetweenExpression() {
String jpql = "select a from Account a where a.balance between 100 and 200";
String jpql =
"select a from Account a where a.balance between 100 and 200";
CriteriaQuery c = cb.create();
Root<Account> account = c.from(Account.class);
@ -238,7 +241,8 @@ public class TestTypesafeCriteria extends CriteriaTest {
@AllowFailure(message = "Key expression not implemented")
public void testKeyExpression() {
String jpql = "SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) "
String jpql =
"SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) "
+ "LIKE '%egret%'";
CriteriaQuery q = cb.create();
Root<Item> item = q.from(Item.class);
@ -274,60 +278,61 @@ public class TestTypesafeCriteria extends CriteriaTest {
assertEquivalence(q, jpql);
}
@AllowFailure(message = "broken")
public void testExpressionInProjection() {
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));
// @AllowFailure(message = "broken")
// public void testExpressionInProjection() {
// 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);
// }
assertEquivalence(q, jpql);
}
// @AllowFailure(message =
// "Type expression was working with Fay. Now refactored and broken")
// public void testTypeExpression() {
// String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
// CriteriaQuery q = cb.create();
// Root<Employee> emp = q.from(Employee.class);
// q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
//
// assertEquivalence(q, jpql);
// }
@AllowFailure(message = "Type expression was working with Fay. Now refactored and broken")
public void testTypeExpression() {
String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
CriteriaQuery q = cb.create();
Root<Employee> emp = q.from(Employee.class);
q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
// @AllowFailure(message = "Index expression not implemented")
// public void testIndexExpressionAndLietral() {
// String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
// + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
// CriteriaQuery 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);
// }
assertEquivalence(q, jpql);
}
@AllowFailure(message = "Index expression not implemented")
public void testIndexExpressionAndLietral() {
String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
+ "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
CriteriaQuery 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);
}
@AllowFailure(message = "SQL for Criteria has extra join")
public void testAggregateInProjection() {
String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN "
+ "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
CriteriaQuery 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);
}
// @AllowFailure(message = "SQL for Criteria has extra join")
// public void testAggregateInProjection() {
// String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN "
// + "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
// CriteriaQuery 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);
// }
public void testSizeExpression() {
String jpql = "SELECT SIZE(d.employees) FROM Department d "
@ -341,8 +346,10 @@ public class TestTypesafeCriteria extends CriteriaTest {
}
public void testCaseExpression() {
String 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 "
String 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'";
CriteriaQuery q = cb.create();
Root<Employee> e = q.from(Employee.class);
@ -358,60 +365,60 @@ public class TestTypesafeCriteria extends CriteriaTest {
assertEquivalence(q, jpql);
}
@AllowFailure(message = "Extra Joins created")
public void testExpression1() {
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);
}
@AllowFailure(message = "Type expression in projection not implemented")
public void testExpression2() {
String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
CriteriaQuery q = cb.create();
Root<Employee> emp = q.from(Employee.class);
q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
assertEquivalence(q, jpql);
}
@AllowFailure(message = "Index expression not implemented")
public void testExpression3() {
String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
+ "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
CriteriaQuery 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);
}
@AllowFailure(message = "Generates extra Join")
public void testExpression4() {
String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN "
+ "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
CriteriaQuery 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);
}
// @AllowFailure(message = "Extra Joins created")
// public void testExpression1() {
// 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);
// }
//
// @AllowFailure(message = "Type expression in projection not implemented")
// public void testExpression2() {
// String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
// CriteriaQuery q = cb.create();
// Root<Employee> emp = q.from(Employee.class);
// q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
//
// assertEquivalence(q, jpql);
// }
//
// @AllowFailure(message = "Index expression not implemented")
// public void testExpression3() {
// String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
// + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
// CriteriaQuery 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);
// }
//
// @AllowFailure(message = "Generates extra Join")
// public void testExpression4() {
// String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN "
// + "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
// CriteriaQuery 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);
// }
public void testExpression5() {
String jpql = "SELECT SIZE(d.employees) FROM Department d "
@ -427,7 +434,8 @@ public class TestTypesafeCriteria extends CriteriaTest {
public void testGeneralCaseExpression() {
String 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 "
+ "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * "
+ "1.01 END "
+ "FROM Employee e WHERE e.department.name = 'Engineering'";
CriteriaQuery q = cb.create();
Root<Employee> e = q.from(Employee.class);
@ -519,21 +527,21 @@ public class TestTypesafeCriteria extends CriteriaTest {
assertEquivalence(q, jpql, new Object[] { 1 });
}
@AllowFailure(message="add QuotedNumbersInQueries=true otherwise AbstractExpressionBuilder.convertTypes() compliants")
public void testParameters4() {
String jpql = "SELECT c FROM Customer c Where c.status = ?1 AND "
+ "c.name = ?2";
CriteriaQuery q = cb.create();
Root<Customer> c = q.from(Customer.class);
Parameter<Integer> param1 = cb.parameter(Integer.class);
Parameter<Integer> param2 = cb.parameter(Integer.class);
q.select(c).where(
cb.and(cb.equal(c.get(Customer_.status), param1), cb.equal(c
.get(Customer_.name), param2)));
assertEquivalence(q, jpql, new Object[] { 1, "test" });
}
// @AllowFailure(message="add QuotedNumbersInQueries=true otherwise " +
// "AbstractExpressionBuilder.convertTypes() compliants")
// public void testParameters4() {
// String jpql = "SELECT c FROM Customer c Where c.status = ?1 AND "
// + "c.name = ?2";
// CriteriaQuery q = cb.create();
// Root<Customer> c = q.from(Customer.class);
// Parameter<Integer> param1 = cb.parameter(Integer.class);
// Parameter<Integer> param2 = cb.parameter(Integer.class);
// q.select(c).where(
// cb.and(cb.equal(c.get(Customer_.status), param1), cb.equal(c
// .get(Customer_.name), param2)));
// assertEquivalence(q, jpql, new Object[] { 1, "test" });
// }
// @AllowFailure(message = "")
public void testParameters5() {
String jpql = "SELECT c FROM Customer c Where c.status IN (:coll)";
CriteriaQuery q = cb.create();
@ -548,136 +556,138 @@ public class TestTypesafeCriteria extends CriteriaTest {
// {vals});
}
@AllowFailure(message="Value() expression not implemented")
public void testSelectList1() {
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());
// @AllowFailure(message="Value() expression not implemented")
// public void testSelectList1() {
// 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);
// }
//
// @AllowFailure(message="new() in projection is broken")
// public void testSelectList2() {
// String jpql =
// "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM "
// + "Customer c JOIN c.orders o WHERE o.quantity > 100";
// CriteriaQuery 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);
// }
assertEquivalence(q, jpql);
}
@AllowFailure(message="new() in projection is broken")
public void testSelectList2() {
String jpql = "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM "
+ "Customer c JOIN c.orders o WHERE o.quantity > 100";
CriteriaQuery 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(message="Subqueries not implemented")
public void testSubqueries1() {
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);
}
@AllowFailure(message="Subqueries not implemented")
public void testSubqueries2() {
String jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS ("
+ "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = "
+ "emp.spouse)";
CriteriaQuery q = cb.create();
Root<Employee> emp = q.from(Employee.class);
Subquery<Employee> sq = q.subquery(Employee.class);
Root<Employee> spouseEmp = sq.from(Employee.class);
sq.select(spouseEmp);
sq.where(cb.equal(spouseEmp, emp.get(Employee_.spouse)));
q.where(cb.exists(sq));
q.select(emp).distinct(true);
assertEquivalence(q, jpql);
}
@AllowFailure(message="Subqueries not implemented")
public void testSubqueries3() {
String jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL ("
+ "SELECT m.salary FROM Manager m WHERE m.department = "
+ "emp.department)";
CriteriaQuery q = cb.create();
Root<Employee> emp = q.from(Employee.class);
q.select(emp);
Subquery<BigDecimal> sq = q.subquery(BigDecimal.class);
Root<Manager> m = sq.from(Manager.class);
sq.select(m.get(Manager_.salary));
sq.where(cb.equal(m.get(Manager_.department), emp
.get(Employee_.department)));
q.where(cb.gt(emp.get(Employee_.salary), cb.all(sq)));
assertEquivalence(q, jpql);
}
@AllowFailure(message="Subqueries not implemented")
public void testSubqueries4() {
String jpql = "SELECT c FROM Customer c WHERE "
+ "(SELECT COUNT(o) FROM c.orders o) > 10";
CriteriaQuery 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);
}
@AllowFailure(message="Subqueries not implemented")
public void testSubqueries5() {
String jpql = "SELECT o FROM Order o WHERE 10000 < ALL ("
+ "SELECT a.balance FROM o.customer c JOIN c.accounts a)";
CriteriaQuery q = cb.create();
Root<Order> o = q.from(Order.class);
q.select(o);
Subquery<Integer> sq = q.subquery(Integer.class);
Root<Order> osq = sq.correlate(o);
Join<Order, Customer> c = osq.join(Order_.customer);
Join<Customer, Account> a = c.join(Customer_.accounts);
sq.select(a.get(Account_.balance));
q.where(cb.lt(cb.literal(10000), cb.all(sq)));
assertEquivalence(q, jpql);
}
@AllowFailure(message="Subqueries not implemented")
public void testSubqueries6() {
String jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < "
+ "ALL (SELECT a.balance FROM c.accounts a)";
CriteriaQuery q = cb.create();
Root<Order> o = q.from(Order.class);
q.select(o);
Join<Order, Customer> c = o.join(Order_.customer);
Subquery<Integer> sq = q.subquery(Integer.class);
Join<Order, Customer> csq = sq.correlate(c);
Join<Customer, Account> a = csq.join(Customer_.accounts);
sq.select(a.get(Account_.balance));
q.where(cb.lt(cb.literal(10000), cb.all(sq)));
assertEquivalence(q, jpql);
}
// @AllowFailure(message="Subqueries not implemented")
// public void testSubqueries1() {
// 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);
// }
//
// @AllowFailure(message="Subqueries not implemented")
// public void testSubqueries2() {
// String jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS ("
// + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp ="
// + " emp.spouse)";
// CriteriaQuery q = cb.create();
// Root<Employee> emp = q.from(Employee.class);
// Subquery<Employee> sq = q.subquery(Employee.class);
// Root<Employee> spouseEmp = sq.from(Employee.class);
// sq.select(spouseEmp);
// sq.where(cb.equal(spouseEmp, emp.get(Employee_.spouse)));
// q.where(cb.exists(sq));
// q.select(emp).distinct(true);
//
// assertEquivalence(q, jpql);
// }
//
// @AllowFailure(message="Subqueries not implemented")
// public void testSubqueries3() {
// String jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL ("
// + "SELECT m.salary FROM Manager m WHERE m.department = "
// + "emp.department)";
// CriteriaQuery q = cb.create();
// Root<Employee> emp = q.from(Employee.class);
// q.select(emp);
// Subquery<BigDecimal> sq = q.subquery(BigDecimal.class);
// Root<Manager> m = sq.from(Manager.class);
// sq.select(m.get(Manager_.salary));
// sq.where(cb.equal(m.get(Manager_.department), emp
// .get(Employee_.department)));
// q.where(cb.gt(emp.get(Employee_.salary), cb.all(sq)));
//
// assertEquivalence(q, jpql);
// }
//
// @AllowFailure(message="Subqueries not implemented")
// public void testSubqueries4() {
// String jpql = "SELECT c FROM Customer c WHERE "
// + "(SELECT COUNT(o) FROM c.orders o) > 10";
// CriteriaQuery 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);
// }
//
// @AllowFailure(message="Subqueries not implemented")
// public void testSubqueries5() {
// String jpql = "SELECT o FROM Order o WHERE 10000 < ALL ("
// + "SELECT a.balance FROM o.customer c JOIN c.accounts a)";
// CriteriaQuery q = cb.create();
// Root<Order> o = q.from(Order.class);
// q.select(o);
// Subquery<Integer> sq = q.subquery(Integer.class);
// Root<Order> osq = sq.correlate(o);
// Join<Order, Customer> c = osq.join(Order_.customer);
// Join<Customer, Account> a = c.join(Customer_.accounts);
// sq.select(a.get(Account_.balance));
// q.where(cb.lt(cb.literal(10000), cb.all(sq)));
//
// assertEquivalence(q, jpql);
// }
//
// @AllowFailure(message="Subqueries not implemented")
// public void testSubqueries6() {
// String jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < "
// + "ALL (SELECT a.balance FROM c.accounts a)";
// CriteriaQuery q = cb.create();
// Root<Order> o = q.from(Order.class);
// q.select(o);
// Join<Order, Customer> c = o.join(Order_.customer);
// Subquery<Integer> sq = q.subquery(Integer.class);
// Join<Order, Customer> csq = sq.correlate(c);
// Join<Customer, Account> a = csq.join(Customer_.accounts);
// sq.select(a.get(Account_.balance));
// q.where(cb.lt(cb.literal(10000), cb.all(sq)));
//
// assertEquivalence(q, jpql);
// }
public void testGroupByAndHaving() {
String jpql = "SELECT c.status, AVG(c.filledOrderCount), COUNT(c) FROM "
@ -692,135 +702,137 @@ public class TestTypesafeCriteria extends CriteriaTest {
assertEquivalence(q, jpql);
}
@AllowFailure(message="AbstractExpressionExecutor.assertNotContainer() not happy")
public void testOrdering() {
String jpql = "SELECT c 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(message="AbstractExpressionExecutor.assertNotContainer() not happy")
public void testOrdering1() {
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);
}
@AllowFailure(message="The JPQL is broken!")
public void testOrdering2() {
String 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";
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.asc(o.get(Order_.quantity)), cb.asc(a
.get(Address_.zipCode)));
q.select(o.get(Order_.quantity), a.get(Address_.zipCode));
assertEquivalence(q, jpql);
}
@AllowFailure(message="QueryExpression.ordering not initialized")
public void testOrdering3() {
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' "
+ "ORDER BY o.quantity, taxedCost, a.zipCode";
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"), 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(message="QueryExpression.ordering not initialized")
public void testOrdering4() {
String jpql = "SELECT c FROM Customer c "
+ "ORDER BY c.name DESC, c.status";
CriteriaQuery q = cb.create();
Root<Customer> c = q.from(Customer.class);
q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
.get(Customer_.status)));
q.select(c);
assertEquivalence(q, jpql);
}
@AllowFailure(message="QueryExpression.ordering not initialized")
public void testOrdering5() {
String jpql = "SELECT c.firstName, c.lastName, c.balanceOwed "
+ "FROM Customer c ORDER BY c.name DESC, c.status";
CriteriaQuery q = cb.create();
Root<Customer> c = q.from(Customer.class);
q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
.get(Customer_.status)));
q.select(c.get(Customer_.firstName), c.get(Customer_.lastName), c
.get(Customer_.balanceOwed));
assertEquivalence(q, jpql);
}
// @AllowFailure(message="AbstractExpressionExecutor.assertNotContainer()
// not happy")
// public void testOrdering() {
// String jpql = "SELECT c 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(message="AbstractExpressionExecutor.assertNotContainer()"+
// "not happy")
// public void testOrdering1() {
// 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);
// }
//
// @AllowFailure(message="The JPQL is broken!")
// public void testOrdering2() {
// String 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";
// 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.asc(o.get(Order_.quantity)), cb.asc(a
// .get(Address_.zipCode)));
// q.select(o.get(Order_.quantity), a.get(Address_.zipCode));
//
// assertEquivalence(q, jpql);
// }
//
// @AllowFailure(message="QueryExpression.ordering not initialized")
// public void testOrdering3() {
// 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' "
// + "ORDER BY o.quantity, taxedCost, a.zipCode";
// 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"), 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(message="QueryExpression.ordering not initialized")
// public void testOrdering4() {
// String jpql = "SELECT c FROM Customer c "
// + "ORDER BY c.name DESC, c.status";
// CriteriaQuery q = cb.create();
// Root<Customer> c = q.from(Customer.class);
// q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
// .get(Customer_.status)));
// q.select(c);
//
// assertEquivalence(q, jpql);
// }
//
// @AllowFailure(message="QueryExpression.ordering not initialized")
// public void testOrdering5() {
// String jpql = "SELECT c.firstName, c.lastName, c.balanceOwed "
// + "FROM Customer c ORDER BY c.name DESC, c.status";
// CriteriaQuery q = cb.create();
// Root<Customer> c = q.from(Customer.class);
// q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
// .get(Customer_.status)));
// q.select(c.get(Customer_.firstName), c.get(Customer_.lastName), c
// .get(Customer_.balanceOwed));
//
// assertEquivalence(q, jpql);
// }
}

View File

@ -5,6 +5,7 @@
package org.apache.openjpa.persistence.criteria;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.criteria.Transaction.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.criteria.Transaction.class)
public class Transaction_ {
}

View File

@ -60,8 +60,9 @@ public class EntityF {
private Map<String, String> collectionMap = new HashMap<String, String>();
@ElementCollection
@MapKeyColumn(name="\"mapKey\"")
private Map<String, String> delimCollectionMap = new HashMap<String, String>();
@MapKeyColumn(name = "\"mapKey\"")
private Map<String, String> delimCollectionMap =
new HashMap<String, String>();
public EntityF(String name) {
this.name = name;

View File

@ -335,8 +335,10 @@ public class TestFieldRange extends BaseKernelTest {
System.out.println("i1 : " + i1 + "\ni2 : " + i2);
//CR346162. In this CR, it was stated that @Temporal(DATE) fields will be equal for year, month, day but not for hours,
//minutes, seconds. So, we removed the time check and checked only for the equality of day, month and year
// CR346162. In this CR, it was stated that @Temporal(DATE) fields will
// be equal for year, month, day but not for hours,
// minutes, seconds. So, we removed the time check and checked only for
// the equality of day, month and year
/* assertEquals("Field type Date: "
+ testDate.getTime() + "!="
@ -349,11 +351,12 @@ public class TestFieldRange extends BaseKernelTest {
if ((testDateDay != retrievedObjectDay) ||
(testDateMonth != retrievedObjectMonth) ||
(testDateYear != retrievedObjectYear)) {
Assert.fail(
"Field type Date not stored properly. One or more of the components of the date (day, month or year) do not match. \n" +
" Value that should be stored : " + testDate.toGMTString() +
". \nValue that is actually" +
"stored : " + retrievedObject.getTestDate().toGMTString());
Assert
.fail("Field type Date not stored properly. One or more of "
+ "the components of the date (day, month or year) "
+ "do not match. \n" + " Value that should be stored : "
+ testDate.toGMTString() + ". \nValue that is actually"
+ "stored : " + retrievedObject.getTestDate().toGMTString());
}
//assertEquals ("Field type Object", testObject,
//retrievedObject.getTestObject ());

View File

@ -6,7 +6,8 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ArrayMember.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.ArrayMember.class)
public class ArrayMember_ {
public static volatile Attribute<ArrayMember,Byte[]> Array;
public static volatile Attribute<ArrayMember,byte[]> array;

View File

@ -6,8 +6,10 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.Embed0.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.Embed0.class)
public class Embed0_ {
public static volatile Attribute<Embed0,ImplicitFieldAccessSubclass> entity1;
public static volatile Attribute<Embed0,ImplicitFieldAccessSubclass>
entity1;
public static volatile Attribute<Embed0,Long> f1;
}

View File

@ -6,7 +6,8 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.Embed1.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value = org.apache.openjpa.persistence.meta.Embed1.class)
public class Embed1_ {
public static volatile Attribute<Embed1,ImplicitFieldAccessBase> entity0;
public static volatile Attribute<Embed1,String> f1;

View File

@ -36,51 +36,51 @@ import javax.persistence.Transient;
@Entity
@Access(AccessType.FIELD)
public class ExplicitFieldAccess {
private long f1;
private int f2;
@Transient private short f3;
@OneToOne
private ImplicitFieldAccessBase f4;
@OneToOne
private ImplicitFieldAccessBase f5;
private transient ImplicitFieldAccessBase f6;
private long f1;
private int f2;
@Transient private short f3;
@OneToOne
private ImplicitFieldAccessBase f4;
@OneToOne
private ImplicitFieldAccessBase f5;
private transient ImplicitFieldAccessBase f6;
public long getF1() {
return f1;
}
public void setF1(long f1) {
this.f1 = f1;
}
public int getF2() {
return f2;
}
public void setF2(int f2) {
this.f2 = f2;
}
public short getF3() {
return f3;
}
public void setF3(short f3) {
this.f3 = f3;
}
public ImplicitFieldAccessBase getF4() {
return f4;
}
public void setF4(ImplicitFieldAccessBase f4) {
this.f4 = f4;
}
public long getF1() {
return f1;
}
public void setF1(long f1) {
this.f1 = f1;
}
public int getF2() {
return f2;
}
public void setF2(int f2) {
this.f2 = f2;
}
public short getF3() {
return f3;
}
public void setF3(short f3) {
this.f3 = f3;
}
public ImplicitFieldAccessBase getF4() {
return f4;
}
public void setF4(ImplicitFieldAccessBase f4) {
this.f4 = f4;
}
public ImplicitFieldAccessBase getF5() {
return f5;
}
public void setF5(ImplicitFieldAccessBase f5) {
this.f5 = f5;
}
public ImplicitFieldAccessBase getF5() {
return f5;
}
public void setF5(ImplicitFieldAccessBase f5) {
this.f5 = f5;
}
public ImplicitFieldAccessBase getF6() {
return f6;
}
public void setF6(ImplicitFieldAccessBase f6) {
this.f6 = f6;
}
public ImplicitFieldAccessBase getF6() {
return f6;
}
public void setF6(ImplicitFieldAccessBase f6) {
this.f6 = f6;
}
}

View File

@ -6,10 +6,13 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ExplicitFieldAccessMixed.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.ExplicitFieldAccessMixed.class)
public class ExplicitFieldAccessMixed_ {
public static volatile Attribute<ExplicitFieldAccessMixed,Long> f1;
public static volatile Attribute<ExplicitFieldAccessMixed,Integer> f2;
public static volatile Attribute<ExplicitFieldAccessMixed,ImplicitFieldAccessBase> f4;
public static volatile Attribute<ExplicitFieldAccessMixed,ImplicitFieldAccessBase> f5;
public static volatile Attribute<ExplicitFieldAccessMixed,
ImplicitFieldAccessBase> f4;
public static volatile Attribute<ExplicitFieldAccessMixed,
ImplicitFieldAccessBase> f5;
}

View File

@ -6,10 +6,13 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ExplicitFieldAccess.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.ExplicitFieldAccess.class)
public class ExplicitFieldAccess_ {
public static volatile Attribute<ExplicitFieldAccess,Long> f1;
public static volatile Attribute<ExplicitFieldAccess,Integer> f2;
public static volatile Attribute<ExplicitFieldAccess,ImplicitFieldAccessBase> f4;
public static volatile Attribute<ExplicitFieldAccess,ImplicitFieldAccessBase> f5;
public static volatile Attribute<ExplicitFieldAccess,
ImplicitFieldAccessBase> f4;
public static volatile Attribute<ExplicitFieldAccess,
ImplicitFieldAccessBase> f5;
}

View File

@ -6,11 +6,14 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ExplicitPropertyAccessMixed.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.ExplicitPropertyAccessMixed.class)
public class ExplicitPropertyAccessMixed_ {
public static volatile Attribute<ExplicitPropertyAccessMixed,String> f1;
public static volatile Attribute<ExplicitPropertyAccessMixed,ImplicitFieldAccessBase> f3;
public static volatile Attribute<ExplicitPropertyAccessMixed,
ImplicitFieldAccessBase> f3;
public static volatile Attribute<ExplicitPropertyAccessMixed,Integer> f4;
public static volatile Attribute<ExplicitPropertyAccessMixed,Short> f5;
public static volatile Attribute<ExplicitPropertyAccessMixed,ImplicitFieldAccessBase> f6;
public static volatile Attribute<ExplicitPropertyAccessMixed,
ImplicitFieldAccessBase> f6;
}

View File

@ -6,11 +6,14 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ExplicitPropertyAccess.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value = org.apache.openjpa.persistence.meta.ExplicitPropertyAccess.class)
public class ExplicitPropertyAccess_ {
public static volatile Attribute<ExplicitPropertyAccess,String> f1;
public static volatile Attribute<ExplicitPropertyAccess,String> f3;
public static volatile Attribute<ExplicitPropertyAccess,String> f4;
public static volatile Attribute<ExplicitPropertyAccess,ImplicitFieldAccessBase> f5;
public static volatile Attribute<ExplicitPropertyAccess,ImplicitFieldAccessBase> f6;
public static volatile Attribute<ExplicitPropertyAccess, String> f1;
public static volatile Attribute<ExplicitPropertyAccess, String> f3;
public static volatile Attribute<ExplicitPropertyAccess, String> f4;
public static volatile Attribute<ExplicitPropertyAccess,
ImplicitFieldAccessBase> f5;
public static volatile Attribute<ExplicitPropertyAccess,
ImplicitFieldAccessBase> f6;
}

View File

@ -42,7 +42,8 @@ import javax.persistence.Transient;
*
*/
@Entity
public class ImplicitFieldAccessBase extends ImplicitFieldAccessMappedSuperclass {
public class ImplicitFieldAccessBase extends
ImplicitFieldAccessMappedSuperclass {
private String f0;
private int primitiveInt;
private Integer boxedInt;

View File

@ -10,15 +10,24 @@ import javax.persistence.metamodel.List;
import javax.persistence.metamodel.Map;
import javax.persistence.metamodel.Set;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ImplicitFieldAccessBase.class)
public class ImplicitFieldAccessBase_ extends ImplicitFieldAccessMappedSuperclass_ {
public static volatile Attribute<ImplicitFieldAccessBase,Integer> boxedInt;
public static volatile Collection<ImplicitFieldAccessBase,ExplicitFieldAccess> collectionRelation;
public static volatile Attribute<ImplicitFieldAccessBase,String> f0;
public static volatile List<ImplicitFieldAccessBase,ExplicitFieldAccess> listRelation;
public static volatile Map<ImplicitFieldAccessBase,Integer,ExplicitFieldAccess> mapRelationKeyBasic;
public static volatile Map<ImplicitFieldAccessBase,ExplicitPropertyAccess,ExplicitFieldAccess> mapRelationKeyPC;
public static volatile Attribute<ImplicitFieldAccessBase,ExplicitFieldAccess> one2oneRelation;
public static volatile Attribute<ImplicitFieldAccessBase,Integer> primitiveInt;
public static volatile Set<ImplicitFieldAccessBase,ExplicitFieldAccess> setRelation;
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.ImplicitFieldAccessBase.class)
public class ImplicitFieldAccessBase_ extends
ImplicitFieldAccessMappedSuperclass_ {
public static volatile Attribute<ImplicitFieldAccessBase, Integer> boxedInt;
public static volatile Collection<ImplicitFieldAccessBase,
ExplicitFieldAccess> collectionRelation;
public static volatile Attribute<ImplicitFieldAccessBase, String> f0;
public static volatile List<ImplicitFieldAccessBase, ExplicitFieldAccess>
listRelation;
public static volatile Map<ImplicitFieldAccessBase, Integer,
ExplicitFieldAccess> mapRelationKeyBasic;
public static volatile Map<ImplicitFieldAccessBase, ExplicitPropertyAccess,
ExplicitFieldAccess> mapRelationKeyPC;
public static volatile Attribute<ImplicitFieldAccessBase,
ExplicitFieldAccess> one2oneRelation;
public static volatile Attribute<ImplicitFieldAccessBase,
Integer> primitiveInt;
public static volatile Set<ImplicitFieldAccessBase,
ExplicitFieldAccess> setRelation;
}

View File

@ -7,8 +7,12 @@ package org.apache.openjpa.persistence.meta;
import java.util.Date;
import javax.persistence.metamodel.Attribute;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ImplicitFieldAccessMappedSuperclass.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.
ImplicitFieldAccessMappedSuperclass.class)
public class ImplicitFieldAccessMappedSuperclass_ {
public static volatile Attribute<ImplicitFieldAccessMappedSuperclass,Date> createTime;
public static volatile Attribute<ImplicitFieldAccessMappedSuperclass,Long> id;
public static volatile Attribute<ImplicitFieldAccessMappedSuperclass,Date>
createTime;
public static volatile Attribute<ImplicitFieldAccessMappedSuperclass,Long>
id;
}

View File

@ -37,23 +37,23 @@ import javax.persistence.OneToOne;
public class ImplicitFieldAccessSubclass extends ImplicitFieldAccessBase {
@OneToOne
private ImplicitFieldAccessBase base;
@ManyToMany
@ManyToMany
private Map<Embed0, ExplicitPropertyAccess> mapRelationKeyEmbedded;
public ImplicitFieldAccessBase getBase() {
return base;
}
public ImplicitFieldAccessBase getBase() {
return base;
}
public void setBase(ImplicitFieldAccessBase base) {
this.base = base;
}
public void setBase(ImplicitFieldAccessBase base) {
this.base = base;
}
public Map<Embed0, ExplicitPropertyAccess> getMapRelationKeyEmbedded() {
return mapRelationKeyEmbedded;
}
public Map<Embed0, ExplicitPropertyAccess> getMapRelationKeyEmbedded() {
return mapRelationKeyEmbedded;
}
public void setMapRelationKeyEmbedded(
public void setMapRelationKeyEmbedded(
Map<Embed0, ExplicitPropertyAccess> map) {
this.mapRelationKeyEmbedded = map;
}
this.mapRelationKeyEmbedded = map;
}
}

View File

@ -7,8 +7,11 @@ package org.apache.openjpa.persistence.meta;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.Map;
@javax.persistence.metamodel.TypesafeMetamodel(value=org.apache.openjpa.persistence.meta.ImplicitFieldAccessSubclass.class)
@javax.persistence.metamodel.TypesafeMetamodel(
value=org.apache.openjpa.persistence.meta.ImplicitFieldAccessSubclass.class)
public class ImplicitFieldAccessSubclass_ extends ImplicitFieldAccessBase_ {
public static volatile Attribute<ImplicitFieldAccessSubclass,ImplicitFieldAccessBase> base;
public static volatile Map<ImplicitFieldAccessSubclass,Embed0,ExplicitPropertyAccess> mapRelationKeyEmbedded;
public static volatile Attribute<ImplicitFieldAccessSubclass,
ImplicitFieldAccessBase> base;
public static volatile Map<ImplicitFieldAccessSubclass,Embed0,
ExplicitPropertyAccess> mapRelationKeyEmbedded;
}

View File

@ -280,7 +280,8 @@ public class TestQuery extends SliceTestCase {
assertEquals("Even", SlicePersistence.getSlice(c));
// While all Manufacturers are stored in "Odd" slice.
List makers = em.createQuery("select m from Manufacturer m").getResultList();
List makers =
em.createQuery("select m from Manufacturer m").getResultList();
assertFalse(makers.isEmpty());
for (Object m : makers)
assertEquals("Odd", SlicePersistence.getSlice(m));

View File

@ -44,115 +44,115 @@ import javax.persistence.Query;
*/
public class TestQueryMultiThreaded extends SliceTestCase {
private int POBJECT_COUNT = 25;
private int VALUE_MIN = 100;
private int VALUE_MAX = VALUE_MIN + POBJECT_COUNT - 1;
private static int THREADS = 5;
private ExecutorService group;
private Future[] futures;
private int POBJECT_COUNT = 25;
private int VALUE_MIN = 100;
private int VALUE_MAX = VALUE_MIN + POBJECT_COUNT - 1;
private static int THREADS = 5;
private ExecutorService group;
private Future[] futures;
protected String getPersistenceUnitName() {
return "ordering";
}
protected String getPersistenceUnitName() {
return "ordering";
}
public void setUp() throws Exception {
public void setUp() throws Exception {
super.setUp(PObject.class, Person.class, Address.class, Country.class,
CLEAR_TABLES, "openjpa.Multithreaded", "true");
int count = count(PObject.class);
if (count == 0) {
create(POBJECT_COUNT);
}
group = new ThreadPoolExecutor(THREADS, THREADS,
CLEAR_TABLES, "openjpa.Multithreaded", "true");
int count = count(PObject.class);
if (count == 0) {
create(POBJECT_COUNT);
}
group = new ThreadPoolExecutor(THREADS, THREADS,
60, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(), new ThreadFactory() {
public Thread newThread(Runnable r) {
return new Thread(r);
}
public Thread newThread(Runnable r) {
return new Thread(r);
}
});
futures = new Future[THREADS];
}
});
futures = new Future[THREADS];
}
public void tearDown() throws Exception {
group.shutdown();
}
public void tearDown() throws Exception {
group.shutdown();
}
void create(int N) {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
for (int i = 0; i < POBJECT_COUNT; i++) {
PObject pc = new PObject();
pc.setValue(VALUE_MIN + i);
em.persist(pc);
String slice = SlicePersistence.getSlice(pc);
void create(int N) {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
for (int i = 0; i < POBJECT_COUNT; i++) {
PObject pc = new PObject();
pc.setValue(VALUE_MIN + i);
em.persist(pc);
String slice = SlicePersistence.getSlice(pc);
String expected = (pc.getValue() % 2 == 0) ? "Even" : "Odd";
assertEquals(expected, slice);
}
Person p1 = new Person();
Person p2 = new Person();
Address a1 = new Address();
Address a2 = new Address();
p1.setName("Even");
p2.setName("Odd");
a1.setCity("San Francisco");
a2.setCity("Rome");
p1.setAddress(a1);
p2.setAddress(a2);
em.persist(p1);
em.persist(p2);
assertEquals("Even", SlicePersistence.getSlice(p1));
assertEquals("Odd", SlicePersistence.getSlice(p2));
assertEquals(expected, slice);
}
Person p1 = new Person();
Person p2 = new Person();
Address a1 = new Address();
Address a2 = new Address();
p1.setName("Even");
p2.setName("Odd");
a1.setCity("San Francisco");
a2.setCity("Rome");
p1.setAddress(a1);
p2.setAddress(a2);
em.persist(p1);
em.persist(p2);
assertEquals("Even", SlicePersistence.getSlice(p1));
assertEquals("Odd", SlicePersistence.getSlice(p2));
em.getTransaction().commit();
}
em.getTransaction().commit();
}
public void testQueryResultIsOrderedAcrossSlice() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
public void testQueryResultIsOrderedAcrossSlice() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query query = em.createQuery(
"SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
List result = query.getResultList();
Integer old = Integer.MIN_VALUE;
for (Object row : result) {
Object[] line = (Object[]) row;
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
List result = query.getResultList();
Integer old = Integer.MIN_VALUE;
for (Object row : result) {
Object[] line = (Object[]) row;
int value = ((Integer) line[0]).intValue();
PObject pc = (PObject) line[1];
assertTrue(value >= old);
old = value;
PObject pc = (PObject) line[1];
assertTrue(value >= old);
old = value;
assertEquals(value, pc.getValue());
}
return null;
}
});
}
}
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
waitForTermination();
em.getTransaction().rollback();
}
public void testAggregateQuery() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
public void testAggregateQuery() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query countQ = em.createQuery("SELECT COUNT(p) FROM PObject p");
final Query maxQ = em.createQuery("SELECT MAX(p.value) FROM PObject p");
final Query minQ = em.createQuery("SELECT MIN(p.value) FROM PObject p");
final Query sumQ = em.createQuery("SELECT SUM(p.value) FROM PObject p");
final Query minmaxQ = em.createQuery(
"SELECT MIN(p.value),MAX(p.value) FROM PObject p");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
Object count = countQ.getSingleResult();
Object max = maxQ.getSingleResult();
Object min = minQ.getSingleResult();
Object sum = sumQ.getSingleResult();
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
Object count = countQ.getSingleResult();
Object max = maxQ.getSingleResult();
Object min = minQ.getSingleResult();
Object sum = sumQ.getSingleResult();
Object minmax = minmaxQ.getSingleResult();
Object min1 = ((Object[]) minmax)[0];
Object max1 = ((Object[]) minmax)[1];
Object min1 = ((Object[]) minmax)[0];
Object max1 = ((Object[]) minmax)[1];
assertEquals(POBJECT_COUNT, ((Number) count).intValue());
@ -163,173 +163,174 @@ public class TestQueryMultiThreaded extends SliceTestCase {
assertEquals(min, min1);
assertEquals(max, max1);
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
public void testAggregateQueryWithMissingValueFromSlice() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
public void testAggregateQueryWithMissingValueFromSlice() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query maxQ = em.createQuery(
"SELECT MAX(p.value) FROM PObject p WHERE MOD(p.value,2)=0");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
Object max = maxQ.getSingleResult();
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
Object max = maxQ.getSingleResult();
assertEquals(VALUE_MAX, ((Number) max).intValue());
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
public void testSetMaxResult() {
final EntityManager em = emf.createEntityManager();
final int limit = 3;
em.getTransaction().begin();
public void testSetMaxResult() {
final EntityManager em = emf.createEntityManager();
final int limit = 3;
em.getTransaction().begin();
final Query q = em.createQuery(
"SELECT p.value,p FROM PObject p ORDER BY p.value ASC");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
List result = q.setMaxResults(limit).getResultList();
int i = 0;
for (Object row : result) {
Object[] line = (Object[]) row;
int i = 0;
for (Object row : result) {
Object[] line = (Object[]) row;
int value = ((Integer) line[0]).intValue();
PObject pc = (PObject) line[1];
}
assertEquals(limit, result.size());
return null;
}
PObject pc = (PObject) line[1];
}
assertEquals(limit, result.size());
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
public void testHint() {
final List<String> targets = new ArrayList<String>();
targets.add("Even");
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query query = em.createQuery("SELECT p FROM PObject p");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public void testHint() {
final List<String> targets = new ArrayList<String>();
targets.add("Even");
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query query = em.createQuery("SELECT p FROM PObject p");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
public Object call() {
query.setHint(ProductDerivation.HINT_TARGET, "Even");
List result = query.getResultList();
for (Object pc : result) {
List result = query.getResultList();
for (Object pc : result) {
String slice = SlicePersistence.getSlice(pc);
assertTrue(targets.contains(slice));
}
return null;
}
}
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
public void testInMemoryOrderBy() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
public void testInMemoryOrderBy() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query query =
em.createQuery("SELECT p FROM PObject p ORDER BY p.value");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
List result = query.getResultList();
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
List result = query.getResultList();
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
public void testQueryParameter() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
public void testQueryParameter() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query query =
em.createQuery("SELECT p FROM PObject p WHERE p.value > :v");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
query.setParameter("v", 200);
List result = query.getResultList();
return null;
}
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
query.setParameter("v", 200);
List result = query.getResultList();
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
/**
* This test is currently retired.
*
* @see <A HREF="https://issues.apache.org/jira/browse/OPENJPA-1044">OPENJPA-1044</A>
* for details.
*/
public void xtestQueryParameterEntity() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
/**
* This test is currently retired.
*
* @see <A HREF="https://issues.apache.org/jira/browse/OPENJPA-1044">
* OPENJPA-1044</A>
* for details.
*/
public void xtestQueryParameterEntity() {
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
final Query addressQ =
em.createQuery("select a from Address a where a.city = :city");
final Query personQ =
em.createQuery("SELECT p FROM Person p WHERE p.address = :a");
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
for (int i = 0; i < THREADS; i++) {
futures[i] = group.submit(new Callable<Object>() {
public Object call() {
Address a = (Address) addressQ.setParameter("city", "Rome")
.getSingleResult();
assertNotNull(a);
.getSingleResult();
assertNotNull(a);
assertEquals("Odd", SlicePersistence.getSlice(a));
List<Person> result =
personQ.setParameter("a", a).getResultList();
assertEquals(1, result.size());
Person p = result.get(0);
assertEquals(1, result.size());
Person p = result.get(0);
assertEquals("Odd", SlicePersistence.getSlice(p));
assertEquals("Rome", p.getAddress().getCity());
return null;
}
return null;
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
});
}
waitForTermination();
em.getTransaction().rollback();
}
void waitForTermination() {
try {
for (Future f : futures)
try {
f.get(60, TimeUnit.SECONDS);
} catch (TimeoutException te) {
void waitForTermination() {
try {
for (Future f : futures)
try {
f.get(60, TimeUnit.SECONDS);
} catch (TimeoutException te) {
fail("Failed " + te + "\r\n" + getStackDump(te));
} catch (ExecutionException e) {
} catch (ExecutionException e) {
fail("Failed " + "\r\n" + getStackDump(e.getCause()));
}
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {
}
}
}
}
String getStackDump(Throwable t) {
String getStackDump(Throwable t) {
StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
return writer.toString();
}
}
}

View File

@ -706,6 +706,7 @@
<configLocation>${checkstyle.config.location}</configLocation>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</execution>
</executions>
@ -744,6 +745,7 @@
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${checkstyle.config.location}</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>