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.util.ArrayList;
28  import java.util.Collection;
29  import java.util.stream.Stream;
30  import org.synchronoss.cpo.core.CpoAdapter;
31  import org.synchronoss.cpo.core.CpoAdapterFactoryManager;
32  import org.synchronoss.cpo.core.CpoQuery;
33  import org.synchronoss.cpo.core.CpoWhere;
34  import org.synchronoss.cpo.core.enums.Comparison;
35  import org.synchronoss.cpo.core.enums.Logical;
36  import org.synchronoss.cpo.jdbc.ValueObject;
37  import org.testng.annotations.AfterClass;
38  import org.testng.annotations.BeforeClass;
39  import org.testng.annotations.Test;
40  
41  /**
42   * BlobTest is a test class for testing the JdbcAdapter class Constructors
43   *
44   * @author david berry
45   */
46  public class InterleavedWhereTest {
47  
48    // unique id base so this class's rows never collide with another test class's
49    private static final int IDB = 1500000;
50  
51    private CpoAdapter cpoAdapter = null;
52    private final ArrayList<ValueObject> al = new ArrayList<>();
53  
54    /** Creates a new InterleavedWhereTest object. */
55    public InterleavedWhereTest() {}
56  
57    /**
58     * <code>setUp</code> Load the datasource from the properties in the property file
59     * jdbc_en_US.properties
60     */
61    @BeforeClass
62    public void setUp() {
63      String method = "setUp:";
64  
65      try {
66        cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
67        assertNotNull(cpoAdapter, method + "cpoAdapter is null");
68      } catch (Exception e) {
69        fail(method + e.getMessage());
70      }
71      ValueObject vo1 = ValueObjectFactory.createValueObject(IDB + 1);
72      vo1.setAttrVarChar("Test");
73      vo1.setAttrBit(true);
74      al.add(vo1);
75  
76      ValueObject vo3 = ValueObjectFactory.createValueObject(IDB + 3);
77      vo3.setAttrVarChar("Test");
78      vo3.setAttrBit(true);
79      al.add(vo3);
80  
81      ValueObject vo5 = ValueObjectFactory.createValueObject(IDB + 5);
82      vo5.setAttrVarChar("Test");
83      vo5.setAttrBit(true);
84      al.add(vo5);
85      try {
86        cpoAdapter.insertBeans(ValueObject.FG_CREATE_TESTORDERBYINSERT, al);
87      } catch (Exception e) {
88        fail(method + e.getMessage());
89      }
90    }
91  
92    /** DOCUMENT ME! */
93    @AfterClass
94    public void tearDown() {
95      String method = "tearDown:";
96      try {
97        cpoAdapter.deleteBeans(ValueObject.FG_DELETE_TESTORDERBYDELETE, al);
98  
99      } catch (Exception e) {
100       fail(method + e.getMessage());
101     }
102     cpoAdapter = null;
103   }
104 
105   /** DOCUMENT ME! */
106   @Test
107   public void testInterleavedInWhereCollection() {
108     String method = "testInterleavedInWhereCollection:";
109     Collection<ValueObject> coll;
110     CpoWhere cw;
111     CpoWhere cw1 = null;
112 
113     try {
114       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
115       valObj.setAttrBit(true);
116       valObj.setAttrVarChar("Test");
117       Collection<Integer> inColl = new ArrayList<>();
118       inColl.add(IDB + 1);
119       inColl.add(IDB + 3);
120       inColl.add(IDB + 5);
121 
122       cw = cpoAdapter.newWhere(Logical.AND, ValueObject.ATTR_ID, Comparison.IN, inColl);
123 
124       ArrayList<CpoWhere> wheres = new ArrayList<>();
125       wheres.add(cw);
126       try (Stream<ValueObject> beans =
127           cpoAdapter.retrieveBeans(
128               CpoQuery.group(ValueObject.FG_LIST_INTERLEAVEDWHERE).wheres(wheres), valObj); ) {
129         long count = beans.count();
130         assertEquals(count, 3, "Number of beans is " + count);
131       }
132     } catch (Exception e) {
133       fail(method + e.getMessage());
134     }
135   }
136 }