View Javadoc
1   package org.synchronoss.cpo.jdbc.adapter;
2   
3   /*-
4    * [[
5    * jdbc
6    * ==
7    * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8    * ==
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ]]
23   */
24  
25  import static org.testng.Assert.*;
26  
27  import java.math.BigInteger;
28  import java.util.ArrayList;
29  import java.util.Collection;
30  import java.util.stream.Stream;
31  import org.synchronoss.cpo.core.CpoAdapter;
32  import org.synchronoss.cpo.core.CpoAdapterFactoryManager;
33  import org.synchronoss.cpo.core.CpoOrderBy;
34  import org.synchronoss.cpo.core.CpoQuery;
35  import org.synchronoss.cpo.core.CpoWhere;
36  import org.synchronoss.cpo.core.enums.Comparison;
37  import org.synchronoss.cpo.core.enums.Logical;
38  import org.synchronoss.cpo.jdbc.ValueObject;
39  import org.testng.annotations.AfterClass;
40  import org.testng.annotations.BeforeClass;
41  import org.testng.annotations.Test;
42  
43  /**
44   * BlobTest is a test class for testing the JdbcAdapter class Constructors
45   *
46   * @author david berry
47   */
48  public class WhereTest {
49  
50    // unique id base so this class's rows never collide with another test class's
51    private static final int IDB = 2400000;
52  
53    private CpoAdapter cpoAdapter = null;
54    private ArrayList<ValueObject> al = new ArrayList<>();
55  
56    public WhereTest() {}
57  
58    /**
59     * <code>setUp</code> Load the datasource from the properties in the property file
60     * jdbc_en_US.properties
61     */
62    @BeforeClass
63    public void setUp() {
64      String method = "setUp:";
65  
66      try {
67        cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
68        assertNotNull(cpoAdapter, method + "cpoAdapter is null");
69      } catch (Exception e) {
70        fail(method + e.getMessage());
71      }
72      ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
73      vo.setAttrVarChar("Test");
74      vo.setAttrSmallInt((short) 1);
75      vo.setAttrInteger(IDB + 1);
76      vo.setAttrBigInt(BigInteger.valueOf(IDB + 1));
77      vo.setAttrDate(new java.sql.Date(new java.util.Date().getTime()));
78      al.add(vo);
79      al.add(ValueObjectFactory.createValueObject(IDB + 2));
80      al.add(ValueObjectFactory.createValueObject(IDB + 3));
81      al.add(ValueObjectFactory.createValueObject(IDB + 4));
82      al.add(ValueObjectFactory.createValueObject(IDB + 5));
83      al.add(ValueObjectFactory.createValueObject(-(IDB + 6)));
84      try {
85        cpoAdapter.insertBeans(ValueObject.FG_CREATE_TESTORDERBYINSERT, al);
86      } catch (Exception e) {
87        fail(method + e.getMessage());
88      }
89    }
90  
91    /** DOCUMENT ME! */
92    @AfterClass
93    public void tearDown() {
94      String method = "tearDown:";
95      try {
96        cpoAdapter.deleteBeans(ValueObject.FG_DELETE_TESTORDERBYDELETE, al);
97  
98      } catch (Exception e) {
99        fail(method + e.getMessage());
100     }
101     cpoAdapter = null;
102   }
103 
104   /** DOCUMENT ME! */
105   @Test
106   public void testStaticWhere() {
107     String method = "testStaticWhere:";
108     Collection<ValueObject> col;
109     CpoWhere cw;
110 
111     try {
112       ValueObject valObj = ValueObjectFactory.createValueObject();
113       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.GT, null);
114       cw.setStaticValue(String.valueOf(IDB + 3));
115       ArrayList<CpoWhere> wheres = new ArrayList<>();
116       wheres.add(cw);
117       try (Stream<ValueObject> beans =
118           cpoAdapter.retrieveBeans(
119               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
120         long count =
121             beans
122                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
123                 .count();
124         assertEquals(count, 2, "Number of beans is " + count);
125       }
126     } catch (Exception e) {
127       fail(method + e.getMessage());
128     }
129   }
130 
131   @Test
132   public void testSetObjectWhere() {
133     String method = "testSetObjectWhere:";
134     Collection<ValueObject> col;
135     CpoWhere cw;
136 
137     try {
138       BigInteger bigInt = BigInteger.valueOf(IDB + 1);
139       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRBIGINT, Comparison.EQ, bigInt);
140 
141       ArrayList<CpoWhere> wheres = new ArrayList<>();
142       wheres.add(cw);
143       try (Stream<ValueObject> beans =
144           cpoAdapter.retrieveBeans(
145               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres),
146               ValueObjectFactory.createValueObject())) {
147         long count =
148             beans
149                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
150                 .count();
151         assertEquals(count, 1, "Number of beans is " + count);
152       }
153     } catch (Exception e) {
154       fail(method + e.getMessage());
155     }
156   }
157 
158   @Test
159   public void testValueWhere() {
160     String method = "testValueWhere:";
161     Collection<ValueObject> col;
162     CpoWhere cw;
163 
164     try {
165       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 3);
166       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.GT, valObj);
167 
168       ArrayList<CpoWhere> wheres = new ArrayList<>();
169       wheres.add(cw);
170       try (Stream<ValueObject> beans =
171           cpoAdapter.retrieveBeans(
172               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
173         long count =
174             beans
175                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
176                 .count();
177         assertEquals(count, 2, "Number of beans is " + count);
178       }
179     } catch (Exception e) {
180       fail(method + e.getMessage());
181     }
182   }
183 
184   @Test
185   public void testNoMarkerWhere() {
186     String method = "testNoMarkerWhere:";
187     Collection<ValueObject> col;
188     CpoWhere cw;
189 
190     try {
191       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 3);
192       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.GT, valObj);
193 
194       ArrayList<CpoWhere> wheres = new ArrayList<>();
195       wheres.add(cw);
196       try (Stream<ValueObject> beans =
197           cpoAdapter.retrieveBeans(
198               CpoQuery.group(ValueObject.FG_LIST_NULL).wheres(wheres), valObj)) {
199         long count =
200             beans
201                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
202                 .count();
203         assertEquals(count, 2, "Number of beans is " + count);
204       }
205     } catch (Exception e) {
206       fail(method + e.getMessage());
207     }
208   }
209 
210   /*
211    * This test is because retrieveBeans was not honoring the old functionality of passing null for cpo_where should
212    * ignore the where clause.
213    */
214   @Test
215   public void testNoWhere() {
216     String method = "testNoWhere:";
217     Collection<ValueObject> col = null;
218 
219     ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 3);
220     try (Stream<ValueObject> beans =
221         cpoAdapter.retrieveBeans(ValueObject.FG_LIST_TESTWHERERETRIEVE, valObj)) {
222       long count =
223           beans
224               .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
225               .count();
226       assertEquals(count, 6, "Number of beans is " + count);
227     } catch (Exception e) {
228       fail(method + e.getMessage());
229     }
230   }
231 
232   @Test
233   public void testNestedWhere() {
234     String method = "testNestedWhere:";
235     Collection<ValueObject> col;
236     CpoWhere cw;
237     ArrayList<CpoWhere> wheres = new ArrayList<>();
238 
239     try {
240       ValueObject valObj = ValueObjectFactory.createValueObject(-(IDB + 6));
241       cw = cpoAdapter.newWhere();
242       cw.addWhere(cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, valObj));
243 
244       CpoWhere cwAnd = cpoAdapter.newWhere();
245       cwAnd.setLogical(Logical.OR);
246       valObj = ValueObjectFactory.createValueObject(IDB + 2);
247       cwAnd.addWhere(cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, valObj));
248       valObj = ValueObjectFactory.createValueObject(IDB + 3);
249       cwAnd.addWhere(cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.EQ, valObj));
250 
251       cw.addWhere(cwAnd);
252       wheres.add(cw);
253       try (Stream<ValueObject> beans =
254           cpoAdapter.retrieveBeans(
255               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
256         long count =
257             beans
258                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
259                 .count();
260         assertEquals(count, 3, "Number of beans is " + count);
261       }
262     } catch (Exception e) {
263       fail(method + e.getMessage());
264     }
265   }
266 
267   @Test
268   public void testIsNullWhere() {
269     String method = "testIsNullWhere:";
270     Collection<ValueObject> col;
271     CpoWhere cw;
272 
273     try {
274       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 3);
275       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRCHAR, Comparison.ISNULL, null);
276 
277       ArrayList<CpoWhere> wheres = new ArrayList<>();
278       wheres.add(cw);
279       try (Stream<ValueObject> beans =
280           cpoAdapter.retrieveBeans(
281               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
282         long count =
283             beans
284                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
285                 .count();
286         assertEquals(count, 6, "Number of beans is " + count);
287       }
288     } catch (Exception e) {
289       fail(method + e.getMessage());
290     }
291   }
292 
293   @Test
294   public void testAttributeFunction() {
295     String method = "testAttributeFunction:";
296     Collection<ValueObject> col;
297     CpoWhere cw;
298 
299     try {
300       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 6);
301       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, valObj);
302       cw.setAttributeFunction("ABS(id)");
303 
304       ArrayList<CpoWhere> wheres = new ArrayList<>();
305       wheres.add(cw);
306       try (Stream<ValueObject> beans =
307           cpoAdapter.retrieveBeans(
308               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
309         var list =
310             beans
311                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
312                 .toList();
313         assertEquals(list.size(), 1, "Number of beans is " + list.size());
314         var rvo = list.getFirst();
315         assertEquals(rvo.getId(), -(IDB + 6), "-6 != " + rvo.getId());
316       }
317     } catch (Exception e) {
318       fail(method + e.getMessage());
319     }
320   }
321 
322   @Test
323   public void testValueFunction() {
324     String method = "testValueFunction:";
325     Collection<ValueObject> col;
326     CpoWhere cw;
327 
328     try {
329       ValueObject valObj = ValueObjectFactory.createValueObject(-(IDB + 1));
330       cw = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, valObj, false);
331       cw.setValueFunction("abs(id)");
332 
333       ArrayList<CpoWhere> wheres = new ArrayList<>();
334       wheres.add(cw);
335       try (Stream<ValueObject> beans =
336           cpoAdapter.retrieveBeans(
337               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
338         var list =
339             beans
340                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
341                 .toList();
342         assertEquals(list.size(), 1, "Number of beans is " + list.size());
343         var rvo = list.getFirst();
344         assertEquals(rvo.getId(), IDB + 1, "1 != " + rvo.getId());
345       }
346     } catch (Exception e) {
347       fail(method + e.getMessage());
348     }
349   }
350 
351   @Test
352   public void testAndWhere() {
353     String method = "testAndWhere:";
354 
355     try {
356       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 3);
357       CpoWhere cw = cpoAdapter.newWhere();
358       CpoWhere cw1 =
359           cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRCHAR, Comparison.ISNULL, null);
360       CpoWhere cw2 =
361           cpoAdapter.newWhere(
362               Logical.AND, ValueObject.ATTR_ATTRCHAR, Comparison.ISNULL, null, true);
363 
364       cw.addWhere(cw1);
365       cw.addWhere(cw2);
366 
367       ArrayList<CpoWhere> wheres = new ArrayList<>();
368       wheres.add(cw);
369       try (Stream<ValueObject> beans =
370           cpoAdapter.retrieveBeans(
371               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
372         long count =
373             beans
374                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
375                 .count();
376         assertEquals(count, 0, "Number of beans is " + count);
377       }
378 
379       cw = cpoAdapter.newWhere();
380       cw1 = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRCHAR, Comparison.ISNULL, null);
381       cw2 = cpoAdapter.newWhere(Logical.AND, ValueObject.ATTR_ID, Comparison.EQ, valObj);
382 
383       cw.addWhere(cw1);
384       cw.addWhere(cw2);
385 
386       wheres.clear();
387       wheres.add(cw);
388       try (Stream<ValueObject> beans =
389           cpoAdapter.retrieveBeans(
390               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
391         long count =
392             beans
393                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
394                 .count();
395         assertEquals(count, 1, "Number of beans is " + count);
396       }
397     } catch (Exception e) {
398       fail(method + e.getMessage());
399     }
400   }
401 
402   @Test
403   public void testOrWhere() {
404     String method = "testOrWhere:";
405 
406     try {
407       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 3);
408       CpoWhere cw = cpoAdapter.newWhere();
409       CpoWhere cw1 = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, null);
410       CpoWhere cw2 = cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.EQ, valObj);
411 
412       cw1.setStaticValue(String.valueOf(IDB + 2));
413       cw.addWhere(cw1);
414       cw.addWhere(cw2);
415 
416       ArrayList<CpoWhere> wheres = new ArrayList<>();
417       wheres.add(cw);
418       try (Stream<ValueObject> beans =
419           cpoAdapter.retrieveBeans(
420               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
421         long count =
422             beans
423                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
424                 .count();
425         assertEquals(count, 2, "Number of beans is " + count);
426       }
427 
428       cw = cpoAdapter.newWhere();
429       cw1 = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, null);
430       cw2 = cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.EQ, valObj, true);
431 
432       cw1.setStaticValue(String.valueOf(IDB + 3));
433       cw.addWhere(cw1);
434       cw.addWhere(cw2);
435 
436       wheres.clear();
437       wheres.add(cw);
438       try (Stream<ValueObject> beans =
439           cpoAdapter.retrieveBeans(
440               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
441         long count =
442             beans
443                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
444                 .count();
445         assertEquals(count, 6, "Number of beans is " + count);
446       }
447     } catch (Exception e) {
448       fail(method + e.getMessage());
449     }
450   }
451 
452   @Test
453   public void testRightAttributeFunction() {
454     String method = "testRightAttributeFunction:";
455 
456     try {
457       ValueObject valObj = ValueObjectFactory.createValueObject(-(IDB + 1));
458       CpoWhere cw = cpoAdapter.newWhere();
459       cw.setAttribute("id");
460       cw.setRightAttribute("attrBigInt");
461       cw.setAttributeFunction("ABS(id)");
462       cw.setComparison(Comparison.EQ);
463       cw.setRightAttributeFunction("ABS(attrBigInt)");
464       cw.setLogical(Logical.NONE);
465 
466       ArrayList<CpoWhere> wheres = new ArrayList<>();
467       wheres.add(cw);
468       try (Stream<ValueObject> beans =
469           cpoAdapter.retrieveBeans(
470               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
471         var list =
472             beans
473                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
474                 .toList();
475         assertEquals(list.size(), 1, "Number of beans is " + list.size());
476         var rvo = list.getFirst();
477         assertEquals(rvo.getId(), IDB + 1, "1 != " + rvo.getId());
478       }
479     } catch (Exception e) {
480       fail(method + e.getMessage());
481     }
482   }
483 
484   @Test
485   public void testRightAttribute() {
486     String method = "testRightAttribute:";
487 
488     try {
489       ValueObject valObj = ValueObjectFactory.createValueObject(-(IDB + 1));
490       CpoWhere cw = cpoAdapter.newWhere();
491       cw.setAttribute("id");
492       cw.setRightAttribute("attrBigInt");
493       cw.setComparison(Comparison.EQ);
494       cw.setLogical(Logical.NONE);
495 
496       try (Stream<ValueObject> beans =
497           cpoAdapter.retrieveBeans(
498               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).where(cw), valObj, valObj)) {
499         var list =
500             beans
501                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
502                 .toList();
503         assertEquals(list.size(), 1, "Number of beans is " + list.size());
504         var rvo = list.getFirst();
505         assertEquals(rvo.getId(), IDB + 1, "1 != " + rvo.getId());
506       }
507     } catch (Exception e) {
508       fail(method + e.getMessage());
509     }
510   }
511 
512   @Test
513   public void testMultipleBindWhere() {
514     String method = "testMultipleBindWhere:";
515 
516     try {
517       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
518       valObj.setAttrVarChar("Test");
519 
520       CpoWhere cw = cpoAdapter.newWhere();
521       CpoWhere cw1 =
522           cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRVARCHAR, Comparison.EQ, valObj);
523       CpoWhere cw2 = cpoAdapter.newWhere(Logical.AND, ValueObject.ATTR_ID, Comparison.EQ, valObj);
524 
525       cw.addWhere(cw1);
526       cw.addWhere(cw2);
527 
528       ArrayList<CpoWhere> wheres = new ArrayList<>();
529       wheres.add(cw);
530       try (Stream<ValueObject> beans =
531           cpoAdapter.retrieveBeans(
532               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
533         long count =
534             beans
535                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
536                 .count();
537         assertEquals(count, 1, "Number of beans is " + count);
538       }
539     } catch (Exception e) {
540       fail(method + e.getMessage());
541     }
542   }
543 
544   @Test
545   public void testLikeWhere() {
546     String method = "testLikeWhere:";
547 
548     try {
549       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
550       valObj.setAttrVarChar("T%");
551 
552       CpoWhere cw = cpoAdapter.newWhere();
553       CpoWhere cw1 =
554           cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRVARCHAR, Comparison.LIKE, valObj);
555       CpoWhere cw2 = cpoAdapter.newWhere(Logical.AND, ValueObject.ATTR_ID, Comparison.EQ, valObj);
556 
557       cw.addWhere(cw1);
558       cw.addWhere(cw2);
559 
560       ArrayList<CpoWhere> wheres = new ArrayList<>();
561       wheres.add(cw);
562       try (Stream<ValueObject> beans =
563           cpoAdapter.retrieveBeans(
564               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
565         long count =
566             beans
567                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
568                 .count();
569         assertEquals(count, 1, "Number of beans is " + count);
570       }
571     } catch (Exception e) {
572       fail(method + e.getMessage());
573     }
574   }
575 
576   @Test
577   public void testLikeWhereStrings() {
578     String method = "testLikeWhereStrings:";
579 
580     try {
581       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
582       valObj.setAttrVarChar("T%");
583 
584       CpoWhere cw = cpoAdapter.newWhere();
585       CpoWhere cw1 =
586           cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ATTRVARCHAR, Comparison.LIKE, "T%");
587       CpoWhere cw2 = cpoAdapter.newWhere(Logical.AND, ValueObject.ATTR_ID, Comparison.EQ, IDB + 1);
588 
589       cw.addWhere(cw1);
590       cw.addWhere(cw2);
591 
592       ArrayList<CpoWhere> wheres = new ArrayList<>();
593       wheres.add(cw);
594       try (Stream<ValueObject> beans =
595           cpoAdapter.retrieveBeans(
596               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
597         long count =
598             beans
599                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
600                 .count();
601         assertEquals(count, 1, "Number of beans is " + count);
602       }
603     } catch (Exception e) {
604       fail(method + e.getMessage());
605     }
606   }
607 
608   @Test
609   public void testNonAttributeWhere() {
610     String method = "testNonAttributeWhere:";
611 
612     try {
613       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
614 
615       CpoWhere cw = cpoAdapter.newWhere();
616       CpoWhere cw1 = cpoAdapter.newWhere(Logical.NONE, "value_object.id", Comparison.LT, IDB + 1);
617 
618       cw.addWhere(cw1);
619 
620       ArrayList<CpoWhere> wheres = new ArrayList<>();
621       wheres.add(cw);
622       try (Stream<ValueObject> beans =
623           cpoAdapter.retrieveBeans(
624               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
625         long count =
626             beans
627                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
628                 .count();
629         assertEquals(count, 1, "Number of beans is " + count);
630       }
631     } catch (Exception e) {
632       fail(method + e.getMessage());
633     }
634   }
635 
636   @Test
637   public void testInWhereStaticValue() {
638     String method = "testInWhereStaticValue:";
639 
640     try {
641       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
642 
643       CpoWhere cw = cpoAdapter.newWhere();
644       CpoWhere cw1 = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.IN, null);
645       cw1.setStaticValue("(" + (IDB + 1) + "," + (IDB + 3) + "," + (IDB + 5) + ")");
646 
647       cw.addWhere(cw1);
648 
649       ArrayList<CpoWhere> wheres = new ArrayList<>();
650       wheres.add(cw);
651       try (Stream<ValueObject> beans =
652           cpoAdapter.retrieveBeans(
653               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
654         long count =
655             beans
656                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
657                 .count();
658         assertEquals(count, 3, "Number of beans is " + count);
659       }
660     } catch (Exception e) {
661       fail(method + e.getMessage());
662     }
663   }
664 
665   @Test
666   public void testInWhereCollection() {
667     String method = "testInWhereCollection:";
668 
669     try {
670       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
671       Collection<Integer> inColl = new ArrayList<>();
672       inColl.add(IDB + 1);
673       inColl.add(IDB + 3);
674       inColl.add(IDB + 5);
675 
676       CpoWhere cw = cpoAdapter.newWhere();
677       CpoWhere cw1 = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.IN, inColl);
678 
679       cw.addWhere(cw1);
680 
681       ArrayList<CpoWhere> wheres = new ArrayList<>();
682       wheres.add(cw);
683       try (Stream<ValueObject> beans =
684           cpoAdapter.retrieveBeans(
685               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
686         long count =
687             beans
688                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
689                 .count();
690         assertEquals(count, 3, "Number of beans is " + count);
691       }
692     } catch (Exception e) {
693       fail(method + e.getMessage());
694     }
695   }
696 
697   @Test
698   public void testMultiInWhereCollection() {
699     String method = "testMultiInWhereCollection:";
700 
701     try {
702       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
703       Collection<Integer> inColl1 = new ArrayList<>();
704       inColl1.add(IDB + 1);
705       inColl1.add(IDB + 2);
706 
707       Collection<Integer> inColl2 = new ArrayList<>();
708       inColl2.add(IDB + 3);
709       inColl2.add(IDB + 4);
710 
711       Collection<Integer> inColl3 = new ArrayList<>();
712       inColl3.add(IDB + 5);
713       inColl3.add(-(IDB + 6));
714 
715       //      CpoWhere cw = cpoAdapter.newWhere();
716       CpoWhere cw1 = cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.IN, inColl1);
717       CpoWhere cw2 = cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.IN, inColl2);
718       CpoWhere cw3 = cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.IN, inColl3);
719 
720       ArrayList<CpoWhere> wheres = new ArrayList<>();
721       wheres.add(cw1);
722       wheres.add(cw2);
723       wheres.add(cw3);
724       try (Stream<ValueObject> beans =
725           cpoAdapter.retrieveBeans(
726               CpoQuery.group(ValueObject.FG_LIST_TESTORDERBYRETRIEVE).wheres(wheres), valObj)) {
727         long count =
728             beans
729                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
730                 .count();
731         assertEquals(count, 6, "Number of beans is " + count);
732       }
733     } catch (Exception e) {
734       fail(method + e.getMessage());
735     }
736   }
737 
738   @Test
739   public void testNonAttributeInWhereCollection() {
740     String method = "testNonAttributeInWhereCollection:";
741 
742     try {
743       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
744       Collection<Integer> inColl = new ArrayList<>();
745       inColl.add(IDB + 1);
746       inColl.add(IDB + 3);
747       inColl.add(IDB + 5);
748 
749       CpoWhere cw = cpoAdapter.newWhere();
750       CpoWhere cw1 = cpoAdapter.newWhere(Logical.NONE, "value_object.id", Comparison.IN, inColl);
751 
752       cw.addWhere(cw1);
753 
754       ArrayList<CpoWhere> wheres = new ArrayList<>();
755       wheres.add(cw);
756       try (Stream<ValueObject> beans =
757           cpoAdapter.retrieveBeans(
758               CpoQuery.group(ValueObject.FG_LIST_TESTWHERERETRIEVE).wheres(wheres), valObj)) {
759         long count =
760             beans
761                 .filter(b -> Math.abs(b.getId()) >= IDB && Math.abs(b.getId()) < IDB + 100000)
762                 .count();
763         assertEquals(count, 3, "Number of beans is " + count);
764       }
765     } catch (Exception e) {
766       fail(method + e.getMessage());
767     }
768   }
769 
770   @Test
771   public void testWhereParens() {
772     String method = "testWhereParens:";
773     Collection<ValueObject> col = null;
774 
775     try {
776       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
777 
778       // Without the correct parens, this will return multiple rows for a retrieveBean which is a
779       // failure
780       CpoWhere cw1 = cpoAdapter.newWhere();
781       cw1.setLogical(Logical.AND);
782       cw1.addWhere(cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, IDB + 1));
783       cw1.addWhere(cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.EQ, IDB + 3));
784 
785       ArrayList<CpoWhere> wheres = new ArrayList<>();
786       ArrayList<CpoOrderBy> orderBys = new ArrayList<>();
787       wheres.add(cw1);
788 
789       valObj =
790           cpoAdapter.retrieveBean(
791               CpoQuery.group(ValueObject.FG_RETRIEVE_NULL).wheres(wheres).orderBys(orderBys),
792               valObj);
793 
794       assertNotNull(valObj, "Value Object should not be null");
795       assertEquals(valObj.getId(), IDB + 1, "Id should equal 1");
796     } catch (Exception e) {
797       fail(method + e.getMessage());
798     }
799   }
800 
801   @Test
802   public void testWhereOrderBy() {
803     String method = "testWhereOrderBy:";
804     Collection<ValueObject> col = null;
805 
806     try {
807       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
808 
809       // Without the correct parens, this will return multiple rows for a retrieveBean which is a
810       // failure
811       CpoWhere cw1 = cpoAdapter.newWhere();
812       cw1.setLogical(Logical.AND);
813       cw1.addWhere(cpoAdapter.newWhere(Logical.NONE, ValueObject.ATTR_ID, Comparison.EQ, IDB + 1));
814       cw1.addWhere(cpoAdapter.newWhere(Logical.OR, ValueObject.ATTR_ID, Comparison.EQ, IDB + 3));
815 
816       ArrayList<CpoWhere> wheres = new ArrayList<>();
817       ArrayList<CpoOrderBy> orderBys = new ArrayList<>();
818       wheres.add(cw1);
819 
820       valObj =
821           cpoAdapter.retrieveBean(
822               CpoQuery.group(ValueObject.FG_RETRIEVE_NULL).wheres(wheres).orderBys(orderBys),
823               valObj,
824               valObj);
825 
826       assertNotNull(valObj, "Value Object should not be null");
827       assertEquals(valObj.getId(), IDB + 1, "Id should equal 1");
828     } catch (Exception e) {
829       fail(method + e.getMessage());
830     }
831   }
832 }