Skip to content

Commit

Permalink
JDO-843 JDOQLTypedQuery: issue with candidate("this") method (#96)
Browse files Browse the repository at this point in the history
* JDO-843: Test case reproducing the query issue

* JDO-843: Different test cases for success and failure

* JDO-843: run both test cases for success and failure

* JDO-843: replace candidate() by candidate(„this“)

* JDO-843: Update datanucleus-api-jdo version 5.2.11

* JDO-843: remove test case duplicating test methods

* JDO-843: removed unused import
  • Loading branch information
mboapache authored Oct 22, 2024
1 parent 6431f93 commit ad37e97
Show file tree
Hide file tree
Showing 51 changed files with 248 additions and 248 deletions.
2 changes: 1 addition & 1 deletion tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>5.2.9</version>
<version>5.2.11</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void testQuery01f() {
List<FullTimeEmployee> expected =
getTransientCompanyModelInstancesAsList(FullTimeEmployee.class, "emp1", "emp2", "emp5");
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
q.filter(cand.salary.gt(30000.));
List<FullTimeEmployee> emps = q.executeList();
checkQueryResultWithoutOrder(ASSERTION_FAILED, SINGLE_STRING_QUERY_01, emps, expected);
Expand Down Expand Up @@ -395,7 +395,7 @@ public void testQuery02f() {
List<FullTimeEmployee> expected =
getTransientCompanyModelInstancesAsList(FullTimeEmployee.class, "emp1", "emp5", "emp2");
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
q.filter(cand.salary.gt(30000.)).orderBy(cand.salary.asc());
List<FullTimeEmployee> emps = q.executeList();
checkQueryResultWithOrder(ASSERTION_FAILED, SINGLE_STRING_QUERY_02, emps, expected);
Expand Down Expand Up @@ -570,7 +570,7 @@ public void testQuery03f() {
List<FullTimeEmployee> expected =
getTransientCompanyModelInstancesAsList(FullTimeEmployee.class, "emp1");
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
NumericExpression<Double> sal = q.numericParameter("sal", Double.class);
StringExpression begin = q.stringParameter("begin");
q.filter(cand.salary.gt(sal).and(cand.firstname.startsWith(begin)));
Expand Down Expand Up @@ -735,7 +735,7 @@ public void testQuery04f() {
List<Employee> expected =
getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3");
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
StringExpression dep = q.stringParameter("dep");
q.filter(cand.department.name.eq(dep));
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -897,7 +897,7 @@ public void testQuery05f() {
List<Department> expected =
getTransientCompanyModelInstancesAsList(Department.class, "dept1");
try (JDOQLTypedQuery<Department> q = pm.newJDOQLTypedQuery(Department.class)) {
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
QEmployee emp = QEmployee.variable("emp");
NumericExpression<Double> hours = q.numericParameter("hours", double.class);
q.filter(cand.employees.contains(emp).and(emp.weeklyhours.gt(hours)));
Expand Down Expand Up @@ -1052,7 +1052,7 @@ public void testQuery06f() {
List<Department> expected =
getTransientCompanyModelInstancesAsList(Department.class, "dept1", "dept2", "dept3");
try (JDOQLTypedQuery<Department> q = pm.newJDOQLTypedQuery(Department.class)) {
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
CollectionExpression<Collection<String>, String> depts =
q.collectionParameter("depts", String.class);
q.filter(depts.contains(cand.name));
Expand Down Expand Up @@ -1199,7 +1199,7 @@ public void testQuery07f() {
tx.begin();
List<String> expected = Arrays.asList("Joe", "Craig", "Michael");
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
StringExpression deptName = q.stringParameter("deptName");
q.filter(cand.department.name.eq(deptName)).result(false, cand.firstname);
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -1354,7 +1354,7 @@ public void testQuery08f() {
tx.begin();
List<Info> expected = testQuery08Helper();
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
StringExpression deptName = q.stringParameter("deptName");
q.result(false, cand.firstname, cand.salary, cand.manager.as("reportsTo"))
.filter(cand.department.name.eq(deptName));
Expand Down Expand Up @@ -1555,7 +1555,7 @@ public void testQuery09f() {
new Info("Michael", 40000., getTransientCompanyModelInstance(Employee.class, "emp2")),
new Info("Craig", 50000., null));
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
StringExpression deptName = q.stringParameter("deptName");
q.result(false, cand.firstname, cand.salary, cand.manager)
.filter(cand.department.name.eq(deptName));
Expand Down Expand Up @@ -1707,7 +1707,7 @@ public void testQuery10f() {
tx.begin();
Double expected = 45000.;
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
StringExpression deptName = q.stringParameter("deptName");
q.result(false, cand.salary.avg()).filter(cand.department.name.eq(deptName));
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -1853,7 +1853,7 @@ public void testQuery11f() {
tx.begin();
Double[] expected = new Double[] {45000., 90000.};
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
StringExpression deptName = q.stringParameter("deptName");
q.result(false, cand.salary.avg(), cand.salary.sum())
.filter(cand.department.name.eq(deptName));
Expand Down Expand Up @@ -2020,7 +2020,7 @@ public void testQuery12f() {
tx.begin();
Object[] expectedRow = new Object[] {45000., 90000., "R&D"};
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
q.result(false, cand.salary.avg(), cand.salary.sum(), cand.department.name)
.groupBy(cand.department.name)
.having(cand.department.name.count().gt(1L));
Expand Down Expand Up @@ -2167,7 +2167,7 @@ public void testQuery13f() {
tx.begin();
Employee expectedEmp = getTransientCompanyModelInstance(Employee.class, "emp1");
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
StringExpression empName = q.stringParameter("empName");
q.filter(cand.firstname.eq(empName));
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -2321,7 +2321,7 @@ public void testQuery14f() {
tx.begin();
Double expectedSalary = 40000.;
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
StringExpression empName = q.stringParameter("empName");
q.result(false, cand.salary).filter(cand.firstname.eq(empName));
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -2476,7 +2476,7 @@ public void testQuery15f() {
tx.begin();
List<EmpWrapper> expected = testQuery15Helper();
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
NumericExpression<Double> sal = q.numericParameter("sal", Double.class);
q.result(true, cand.as("FullTimeEmployee")).filter(cand.salary.gt(sal));
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -2625,7 +2625,7 @@ public void testQuery16f() {
tx.begin();
List<EmpInfo> expected = testQuery16Helper();
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
NumericExpression<Double> sal = q.numericParameter("sal", Double.class);
q.result(true, cand.as("FullTimeEmployee")).filter(cand.salary.gt(sal));
Map<String, Object> paramValues = new HashMap<>();
Expand Down Expand Up @@ -2765,7 +2765,7 @@ public void testQuery17f() {
tx.begin();
List<String> expected = Arrays.asList("Michael", "Craig", "Joe");
try (JDOQLTypedQuery<Department> q = pm.newJDOQLTypedQuery(Department.class)) {
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
QEmployee e = QEmployee.variable("e");
q.filter(cand.name.startsWith("R&D").and(cand.employees.contains(e)))
.result(false, e.firstname);
Expand Down Expand Up @@ -2881,7 +2881,7 @@ public void testQuery18f() {
tx.begin();
List<String> expected = Arrays.asList("Michael", "Craig");
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
JDOQLTypedSubquery<Employee> subquery = q.subquery("e");
QEmployee candsub = QEmployee.candidate("e");
q.result(false, cand.firstname)
Expand Down Expand Up @@ -3013,7 +3013,7 @@ public void testQuery19f() {
tx.begin();
List<String> expected = Arrays.asList("Michael");
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
JDOQLTypedSubquery<Employee> subquery =
q.subquery(cand.department.employees, Employee.class, "e");
QEmployee candsub = QEmployee.candidate("e");
Expand Down Expand Up @@ -3146,7 +3146,7 @@ public String toString() {
builder.append("EmpWrapper(");
builder
.append("FullTimeEmployee:")
.append(FullTimeEmployee == null ? "null" : FullTimeEmployee.getFirstname());
.append(FullTimeEmployee == null ? "null" : "name = " + FullTimeEmployee.getFirstname());
builder.append(")");
return builder.toString();
}
Expand Down
4 changes: 2 additions & 2 deletions tck/src/main/java/org/apache/jdo/tck/query/jdoql/Cast.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testPositive0() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
// DataNucleus: java.lang.ClassCastException:
// org.datanucleus.api.jdo.query.PersistableExpressionImpl
// cannot be cast to org.apache.jdo.tck.pc.company.QFullTimeEmployee
Expand Down Expand Up @@ -100,7 +100,7 @@ public void testPositive1() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
QEmployee e = QEmployee.variable("e");
// DataNucleus: java.lang.ClassCastException:
// org.datanucleus.api.jdo.query.PersistableExpressionImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testPositive1() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<PrimitiveTypes> query = pm.newJDOQLTypedQuery(PrimitiveTypes.class);
QPrimitiveTypes cand = QPrimitiveTypes.candidate();
QPrimitiveTypes cand = QPrimitiveTypes.candidate("this");
query.filter(cand.stringNull.startsWith("Even").or(cand.charNotNull.eq('0')));

QueryElementHolder<PrimitiveTypes> holder =
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testPositive2() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<PrimitiveTypes> query = pm.newJDOQLTypedQuery(PrimitiveTypes.class);
QPrimitiveTypes cand = QPrimitiveTypes.candidate();
QPrimitiveTypes cand = QPrimitiveTypes.candidate("this");
query.filter(cand.stringNull.startsWith("Even").or(cand.charNotNull.eq('0')));

QueryElementHolder<PrimitiveTypes> holder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ComparingCollectionFieldToNull extends QueryTest {
@Test
public void testPositive() {
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
query.filter(cand.personid.eq(1L).and(cand.projects.eq(null)));

QueryElementHolder<Employee> holder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testPositive0() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
Expression<Employee> empParam = query.parameter("param", Employee.class);
query.filter(cand.eq(empParam));

Expand Down Expand Up @@ -98,7 +98,7 @@ public void testPositive1() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
Expression<Employee> empParamExpression = query.parameter("param", Employee.class);
QEmployee empParam = QEmployee.parameter("param");
query.filter(cand.personid.eq(empParam.personid));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testPositive0() {
List<Department> expected = getTransientCompanyModelInstancesAsList(Department.class, "dept1");

JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
QEmployee e1 = QEmployee.variable("e1");
QEmployee e2 = QEmployee.variable("e2");
query.filter(
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testPositive1() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
QEmployee e1 = QEmployee.variable("e1");
QEmployee e2 = QEmployee.variable("e2");
query.filter(
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testPositive2() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
QEmployee e1 = QEmployee.variable("e1");
QEmployee e2 = QEmployee.variable("e2");
query.filter(
Expand Down
4 changes: 2 additions & 2 deletions tck/src/main/java/org/apache/jdo/tck/query/jdoql/Having.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void testPositive0() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
query.groupBy(cand.department).having(cand.department.count().gt(0L));
query.result(false, cand.department, cand.weeklyhours.avg());

Expand Down Expand Up @@ -147,7 +147,7 @@ public void testPositive1() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
QEmployee cand = QEmployee.candidate();
QEmployee cand = QEmployee.candidate("this");
query.groupBy(cand.department).having(cand.personid.count().gt(1L));
query.result(false, cand.department, cand.weeklyhours.avg());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testPositive0() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Person> query = pm.newJDOQLTypedQuery(Person.class);
QPerson cand = QPerson.candidate();
QPerson cand = QPerson.candidate("this");
query.filter(cand.firstname.eq("emp1First"));

QueryElementHolder<Person> holder =
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testPositive1() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Person> query = pm.newJDOQLTypedQuery(Person.class);
QPerson cand = QPerson.candidate();
QPerson cand = QPerson.candidate("this");
query.filter(cand.personid.lt((long) Byte.MAX_VALUE));

QueryElementHolder<Person> holder =
Expand Down Expand Up @@ -133,7 +133,7 @@ public void testPositive2() {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
query.filter(
cand.employees
.size()
Expand Down Expand Up @@ -175,7 +175,7 @@ public void testPositive3() {
try {

JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
query.filter(cand.employees.size().gt(Department.RECOMMENDED_NO_OF_EMPS));

QueryElementHolder<Department> holder =
Expand Down Expand Up @@ -214,7 +214,7 @@ public void testPositive4() {
try {

JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
QDepartment cand = QDepartment.candidate();
QDepartment cand = QDepartment.candidate("this");
query.filter(cand.employees.size().gt(Department.RECOMMENDED_NO_OF_EMPS));

QueryElementHolder<Department> holder =
Expand Down
Loading

0 comments on commit ad37e97

Please sign in to comment.