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.jdbc.ValueObject;
36  import org.testng.annotations.AfterClass;
37  import org.testng.annotations.BeforeClass;
38  import org.testng.annotations.Test;
39  
40  /**
41   * BlobTest is a test class for testing the JdbcAdapter class Constructors
42   *
43   * @author david berry
44   */
45  public class InterleavedWhereTest {
46  
47    // unique id base so this class's rows never collide with another test class's
48    private static final int IDB = 1500000;
49  
50    private CpoAdapter cpoAdapter = null;
51    private final ArrayList<ValueObject> al = new ArrayList<>();
52  
53    /** Creates a new InterleavedWhereTest object. */
54    public InterleavedWhereTest() {}
55  
56    /**
57     * <code>setUp</code> Load the datasource from the properties in the property file
58     * jdbc_en_US.properties
59     */
60    @BeforeClass
61    public void setUp() {
62      String method = "setUp:";
63  
64      try {
65        cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
66        assertNotNull(cpoAdapter, method + "cpoAdapter is null");
67      } catch (Exception e) {
68        fail(method + e.getMessage());
69      }
70      ValueObject vo1 = ValueObjectFactory.createValueObject(IDB + 1);
71      vo1.setAttrVarChar("Test");
72      vo1.setAttrBit(true);
73      al.add(vo1);
74  
75      ValueObject vo3 = ValueObjectFactory.createValueObject(IDB + 3);
76      vo3.setAttrVarChar("Test");
77      vo3.setAttrBit(true);
78      al.add(vo3);
79  
80      ValueObject vo5 = ValueObjectFactory.createValueObject(IDB + 5);
81      vo5.setAttrVarChar("Test");
82      vo5.setAttrBit(true);
83      al.add(vo5);
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 testInterleavedInWhereCollection() {
107     String method = "testInterleavedInWhereCollection:";
108     Collection<ValueObject> coll;
109     CpoWhere cw;
110     CpoWhere cw1 = null;
111 
112     try {
113       ValueObject valObj = ValueObjectFactory.createValueObject(IDB + 1);
114       valObj.setAttrBit(true);
115       valObj.setAttrVarChar("Test");
116       Collection<Integer> inColl = new ArrayList<>();
117       inColl.add(IDB + 1);
118       inColl.add(IDB + 3);
119       inColl.add(IDB + 5);
120 
121       cw = cpoAdapter.whereBuilder().and(ValueObject.ATTR_ID, Comparison.IN, inColl).build();
122 
123       ArrayList<CpoWhere> wheres = new ArrayList<>();
124       wheres.add(cw);
125       try (Stream<ValueObject> beans =
126           cpoAdapter.retrieveBeans(
127               CpoQuery.group(ValueObject.FG_LIST_INTERLEAVEDWHERE).wheres(wheres), valObj); ) {
128         long count = beans.count();
129         assertEquals(count, 3, "Number of beans is " + count);
130       }
131     } catch (Exception e) {
132       fail(method + e.getMessage());
133     }
134   }
135 }