Skip to content

Commit ad37e97

Browse files
authored
JDO-843 JDOQLTypedQuery: issue with candidate("this") method (#96)
* 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
1 parent 6431f93 commit ad37e97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+248
-248
lines changed

tck/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
<dependency>
224224
<groupId>org.datanucleus</groupId>
225225
<artifactId>datanucleus-api-jdo</artifactId>
226-
<version>5.2.9</version>
226+
<version>5.2.11</version>
227227
</dependency>
228228
<dependency>
229229
<groupId>org.datanucleus</groupId>

tck/src/main/java/org/apache/jdo/tck/query/api/SampleReadQueries.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void testQuery01f() {
269269
List<FullTimeEmployee> expected =
270270
getTransientCompanyModelInstancesAsList(FullTimeEmployee.class, "emp1", "emp2", "emp5");
271271
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
272-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
272+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
273273
q.filter(cand.salary.gt(30000.));
274274
List<FullTimeEmployee> emps = q.executeList();
275275
checkQueryResultWithoutOrder(ASSERTION_FAILED, SINGLE_STRING_QUERY_01, emps, expected);
@@ -395,7 +395,7 @@ public void testQuery02f() {
395395
List<FullTimeEmployee> expected =
396396
getTransientCompanyModelInstancesAsList(FullTimeEmployee.class, "emp1", "emp5", "emp2");
397397
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
398-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
398+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
399399
q.filter(cand.salary.gt(30000.)).orderBy(cand.salary.asc());
400400
List<FullTimeEmployee> emps = q.executeList();
401401
checkQueryResultWithOrder(ASSERTION_FAILED, SINGLE_STRING_QUERY_02, emps, expected);
@@ -570,7 +570,7 @@ public void testQuery03f() {
570570
List<FullTimeEmployee> expected =
571571
getTransientCompanyModelInstancesAsList(FullTimeEmployee.class, "emp1");
572572
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
573-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
573+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
574574
NumericExpression<Double> sal = q.numericParameter("sal", Double.class);
575575
StringExpression begin = q.stringParameter("begin");
576576
q.filter(cand.salary.gt(sal).and(cand.firstname.startsWith(begin)));
@@ -735,7 +735,7 @@ public void testQuery04f() {
735735
List<Employee> expected =
736736
getTransientCompanyModelInstancesAsList(Employee.class, "emp1", "emp2", "emp3");
737737
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
738-
QEmployee cand = QEmployee.candidate();
738+
QEmployee cand = QEmployee.candidate("this");
739739
StringExpression dep = q.stringParameter("dep");
740740
q.filter(cand.department.name.eq(dep));
741741
Map<String, Object> paramValues = new HashMap<>();
@@ -897,7 +897,7 @@ public void testQuery05f() {
897897
List<Department> expected =
898898
getTransientCompanyModelInstancesAsList(Department.class, "dept1");
899899
try (JDOQLTypedQuery<Department> q = pm.newJDOQLTypedQuery(Department.class)) {
900-
QDepartment cand = QDepartment.candidate();
900+
QDepartment cand = QDepartment.candidate("this");
901901
QEmployee emp = QEmployee.variable("emp");
902902
NumericExpression<Double> hours = q.numericParameter("hours", double.class);
903903
q.filter(cand.employees.contains(emp).and(emp.weeklyhours.gt(hours)));
@@ -1052,7 +1052,7 @@ public void testQuery06f() {
10521052
List<Department> expected =
10531053
getTransientCompanyModelInstancesAsList(Department.class, "dept1", "dept2", "dept3");
10541054
try (JDOQLTypedQuery<Department> q = pm.newJDOQLTypedQuery(Department.class)) {
1055-
QDepartment cand = QDepartment.candidate();
1055+
QDepartment cand = QDepartment.candidate("this");
10561056
CollectionExpression<Collection<String>, String> depts =
10571057
q.collectionParameter("depts", String.class);
10581058
q.filter(depts.contains(cand.name));
@@ -1199,7 +1199,7 @@ public void testQuery07f() {
11991199
tx.begin();
12001200
List<String> expected = Arrays.asList("Joe", "Craig", "Michael");
12011201
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
1202-
QEmployee cand = QEmployee.candidate();
1202+
QEmployee cand = QEmployee.candidate("this");
12031203
StringExpression deptName = q.stringParameter("deptName");
12041204
q.filter(cand.department.name.eq(deptName)).result(false, cand.firstname);
12051205
Map<String, Object> paramValues = new HashMap<>();
@@ -1354,7 +1354,7 @@ public void testQuery08f() {
13541354
tx.begin();
13551355
List<Info> expected = testQuery08Helper();
13561356
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
1357-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
1357+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
13581358
StringExpression deptName = q.stringParameter("deptName");
13591359
q.result(false, cand.firstname, cand.salary, cand.manager.as("reportsTo"))
13601360
.filter(cand.department.name.eq(deptName));
@@ -1555,7 +1555,7 @@ public void testQuery09f() {
15551555
new Info("Michael", 40000., getTransientCompanyModelInstance(Employee.class, "emp2")),
15561556
new Info("Craig", 50000., null));
15571557
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
1558-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
1558+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
15591559
StringExpression deptName = q.stringParameter("deptName");
15601560
q.result(false, cand.firstname, cand.salary, cand.manager)
15611561
.filter(cand.department.name.eq(deptName));
@@ -1707,7 +1707,7 @@ public void testQuery10f() {
17071707
tx.begin();
17081708
Double expected = 45000.;
17091709
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
1710-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
1710+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
17111711
StringExpression deptName = q.stringParameter("deptName");
17121712
q.result(false, cand.salary.avg()).filter(cand.department.name.eq(deptName));
17131713
Map<String, Object> paramValues = new HashMap<>();
@@ -1853,7 +1853,7 @@ public void testQuery11f() {
18531853
tx.begin();
18541854
Double[] expected = new Double[] {45000., 90000.};
18551855
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
1856-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
1856+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
18571857
StringExpression deptName = q.stringParameter("deptName");
18581858
q.result(false, cand.salary.avg(), cand.salary.sum())
18591859
.filter(cand.department.name.eq(deptName));
@@ -2020,7 +2020,7 @@ public void testQuery12f() {
20202020
tx.begin();
20212021
Object[] expectedRow = new Object[] {45000., 90000., "R&D"};
20222022
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
2023-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
2023+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
20242024
q.result(false, cand.salary.avg(), cand.salary.sum(), cand.department.name)
20252025
.groupBy(cand.department.name)
20262026
.having(cand.department.name.count().gt(1L));
@@ -2167,7 +2167,7 @@ public void testQuery13f() {
21672167
tx.begin();
21682168
Employee expectedEmp = getTransientCompanyModelInstance(Employee.class, "emp1");
21692169
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
2170-
QEmployee cand = QEmployee.candidate();
2170+
QEmployee cand = QEmployee.candidate("this");
21712171
StringExpression empName = q.stringParameter("empName");
21722172
q.filter(cand.firstname.eq(empName));
21732173
Map<String, Object> paramValues = new HashMap<>();
@@ -2321,7 +2321,7 @@ public void testQuery14f() {
23212321
tx.begin();
23222322
Double expectedSalary = 40000.;
23232323
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
2324-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
2324+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
23252325
StringExpression empName = q.stringParameter("empName");
23262326
q.result(false, cand.salary).filter(cand.firstname.eq(empName));
23272327
Map<String, Object> paramValues = new HashMap<>();
@@ -2476,7 +2476,7 @@ public void testQuery15f() {
24762476
tx.begin();
24772477
List<EmpWrapper> expected = testQuery15Helper();
24782478
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
2479-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
2479+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
24802480
NumericExpression<Double> sal = q.numericParameter("sal", Double.class);
24812481
q.result(true, cand.as("FullTimeEmployee")).filter(cand.salary.gt(sal));
24822482
Map<String, Object> paramValues = new HashMap<>();
@@ -2625,7 +2625,7 @@ public void testQuery16f() {
26252625
tx.begin();
26262626
List<EmpInfo> expected = testQuery16Helper();
26272627
try (JDOQLTypedQuery<FullTimeEmployee> q = pm.newJDOQLTypedQuery(FullTimeEmployee.class)) {
2628-
QFullTimeEmployee cand = QFullTimeEmployee.candidate();
2628+
QFullTimeEmployee cand = QFullTimeEmployee.candidate("this");
26292629
NumericExpression<Double> sal = q.numericParameter("sal", Double.class);
26302630
q.result(true, cand.as("FullTimeEmployee")).filter(cand.salary.gt(sal));
26312631
Map<String, Object> paramValues = new HashMap<>();
@@ -2765,7 +2765,7 @@ public void testQuery17f() {
27652765
tx.begin();
27662766
List<String> expected = Arrays.asList("Michael", "Craig", "Joe");
27672767
try (JDOQLTypedQuery<Department> q = pm.newJDOQLTypedQuery(Department.class)) {
2768-
QDepartment cand = QDepartment.candidate();
2768+
QDepartment cand = QDepartment.candidate("this");
27692769
QEmployee e = QEmployee.variable("e");
27702770
q.filter(cand.name.startsWith("R&D").and(cand.employees.contains(e)))
27712771
.result(false, e.firstname);
@@ -2881,7 +2881,7 @@ public void testQuery18f() {
28812881
tx.begin();
28822882
List<String> expected = Arrays.asList("Michael", "Craig");
28832883
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
2884-
QEmployee cand = QEmployee.candidate();
2884+
QEmployee cand = QEmployee.candidate("this");
28852885
JDOQLTypedSubquery<Employee> subquery = q.subquery("e");
28862886
QEmployee candsub = QEmployee.candidate("e");
28872887
q.result(false, cand.firstname)
@@ -3013,7 +3013,7 @@ public void testQuery19f() {
30133013
tx.begin();
30143014
List<String> expected = Arrays.asList("Michael");
30153015
try (JDOQLTypedQuery<Employee> q = pm.newJDOQLTypedQuery(Employee.class)) {
3016-
QEmployee cand = QEmployee.candidate();
3016+
QEmployee cand = QEmployee.candidate("this");
30173017
JDOQLTypedSubquery<Employee> subquery =
30183018
q.subquery(cand.department.employees, Employee.class, "e");
30193019
QEmployee candsub = QEmployee.candidate("e");
@@ -3146,7 +3146,7 @@ public String toString() {
31463146
builder.append("EmpWrapper(");
31473147
builder
31483148
.append("FullTimeEmployee:")
3149-
.append(FullTimeEmployee == null ? "null" : FullTimeEmployee.getFirstname());
3149+
.append(FullTimeEmployee == null ? "null" : "name = " + FullTimeEmployee.getFirstname());
31503150
builder.append(")");
31513151
return builder.toString();
31523152
}

tck/src/main/java/org/apache/jdo/tck/query/jdoql/Cast.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void testPositive0() {
5656
PersistenceManager pm = getPMF().getPersistenceManager();
5757
try {
5858
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
59-
QEmployee cand = QEmployee.candidate();
59+
QEmployee cand = QEmployee.candidate("this");
6060
// DataNucleus: java.lang.ClassCastException:
6161
// org.datanucleus.api.jdo.query.PersistableExpressionImpl
6262
// cannot be cast to org.apache.jdo.tck.pc.company.QFullTimeEmployee
@@ -100,7 +100,7 @@ public void testPositive1() {
100100
PersistenceManager pm = getPMF().getPersistenceManager();
101101
try {
102102
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
103-
QDepartment cand = QDepartment.candidate();
103+
QDepartment cand = QDepartment.candidate("this");
104104
QEmployee e = QEmployee.variable("e");
105105
// DataNucleus: java.lang.ClassCastException:
106106
// org.datanucleus.api.jdo.query.PersistableExpressionImpl

tck/src/main/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void testPositive1() {
8989
PersistenceManager pm = getPMF().getPersistenceManager();
9090
try {
9191
JDOQLTypedQuery<PrimitiveTypes> query = pm.newJDOQLTypedQuery(PrimitiveTypes.class);
92-
QPrimitiveTypes cand = QPrimitiveTypes.candidate();
92+
QPrimitiveTypes cand = QPrimitiveTypes.candidate("this");
9393
query.filter(cand.stringNull.startsWith("Even").or(cand.charNotNull.eq('0')));
9494

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

132132
QueryElementHolder<PrimitiveTypes> holder =

tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ComparingCollectionFieldToNull extends QueryTest {
4848
@Test
4949
public void testPositive() {
5050
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
51-
QEmployee cand = QEmployee.candidate();
51+
QEmployee cand = QEmployee.candidate("this");
5252
query.filter(cand.personid.eq(1L).and(cand.projects.eq(null)));
5353

5454
QueryElementHolder<Employee> holder =

tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testPositive0() {
5757
PersistenceManager pm = getPMF().getPersistenceManager();
5858
try {
5959
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
60-
QEmployee cand = QEmployee.candidate();
60+
QEmployee cand = QEmployee.candidate("this");
6161
Expression<Employee> empParam = query.parameter("param", Employee.class);
6262
query.filter(cand.eq(empParam));
6363

@@ -98,7 +98,7 @@ public void testPositive1() {
9898
PersistenceManager pm = getPMF().getPersistenceManager();
9999
try {
100100
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
101-
QEmployee cand = QEmployee.candidate();
101+
QEmployee cand = QEmployee.candidate("this");
102102
Expression<Employee> empParamExpression = query.parameter("param", Employee.class);
103103
QEmployee empParam = QEmployee.parameter("param");
104104
query.filter(cand.personid.eq(empParam.personid));

tck/src/main/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testPositive0() {
6565
List<Department> expected = getTransientCompanyModelInstancesAsList(Department.class, "dept1");
6666

6767
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
68-
QDepartment cand = QDepartment.candidate();
68+
QDepartment cand = QDepartment.candidate("this");
6969
QEmployee e1 = QEmployee.variable("e1");
7070
QEmployee e2 = QEmployee.variable("e2");
7171
query.filter(
@@ -109,7 +109,7 @@ public void testPositive1() {
109109
PersistenceManager pm = getPMF().getPersistenceManager();
110110
try {
111111
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
112-
QDepartment cand = QDepartment.candidate();
112+
QDepartment cand = QDepartment.candidate("this");
113113
QEmployee e1 = QEmployee.variable("e1");
114114
QEmployee e2 = QEmployee.variable("e2");
115115
query.filter(
@@ -163,7 +163,7 @@ public void testPositive2() {
163163
PersistenceManager pm = getPMF().getPersistenceManager();
164164
try {
165165
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
166-
QDepartment cand = QDepartment.candidate();
166+
QDepartment cand = QDepartment.candidate("this");
167167
QEmployee e1 = QEmployee.variable("e1");
168168
QEmployee e2 = QEmployee.variable("e2");
169169
query.filter(

tck/src/main/java/org/apache/jdo/tck/query/jdoql/Having.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testPositive0() {
9999
PersistenceManager pm = getPMF().getPersistenceManager();
100100
try {
101101
JDOQLTypedQuery<Employee> query = pm.newJDOQLTypedQuery(Employee.class);
102-
QEmployee cand = QEmployee.candidate();
102+
QEmployee cand = QEmployee.candidate("this");
103103
query.groupBy(cand.department).having(cand.department.count().gt(0L));
104104
query.result(false, cand.department, cand.weeklyhours.avg());
105105

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

tck/src/main/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void testPositive0() {
5656
PersistenceManager pm = getPMF().getPersistenceManager();
5757
try {
5858
JDOQLTypedQuery<Person> query = pm.newJDOQLTypedQuery(Person.class);
59-
QPerson cand = QPerson.candidate();
59+
QPerson cand = QPerson.candidate("this");
6060
query.filter(cand.firstname.eq("emp1First"));
6161

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

101101
QueryElementHolder<Person> holder =
@@ -133,7 +133,7 @@ public void testPositive2() {
133133
PersistenceManager pm = getPMF().getPersistenceManager();
134134
try {
135135
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
136-
QDepartment cand = QDepartment.candidate();
136+
QDepartment cand = QDepartment.candidate("this");
137137
query.filter(
138138
cand.employees
139139
.size()
@@ -175,7 +175,7 @@ public void testPositive3() {
175175
try {
176176

177177
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
178-
QDepartment cand = QDepartment.candidate();
178+
QDepartment cand = QDepartment.candidate("this");
179179
query.filter(cand.employees.size().gt(Department.RECOMMENDED_NO_OF_EMPS));
180180

181181
QueryElementHolder<Department> holder =
@@ -214,7 +214,7 @@ public void testPositive4() {
214214
try {
215215

216216
JDOQLTypedQuery<Department> query = pm.newJDOQLTypedQuery(Department.class);
217-
QDepartment cand = QDepartment.candidate();
217+
QDepartment cand = QDepartment.candidate("this");
218218
query.filter(cand.employees.size().gt(Department.RECOMMENDED_NO_OF_EMPS));
219219

220220
QueryElementHolder<Department> holder =

0 commit comments

Comments
 (0)