Search in sources :

Example 6 with ObjectTypeImpl

use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.

the class JavaSerializationJUnitTest method testStructImplSerialization.

@Test
public void testStructImplSerialization() throws Exception {
    String[] fieldNames = { "col1", "col2" };
    ObjectType[] fieldTypes = { new ObjectTypeImpl(Integer.class), new ObjectTypeImpl(String.class) };
    StructTypeImpl type = new StructTypeImpl(fieldNames, fieldTypes);
    Object[] values = { new Integer(123), new String("456") };
    StructImpl si = new StructImpl(type, values);
    verifyJavaSerialization(si);
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) StructImpl(org.apache.geode.cache.query.internal.StructImpl) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 7 with ObjectTypeImpl

use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.

the class LikePredicateJUnitTest method likePercentageTerminated_3.

/**
   * Tests a simple % terminated like predicate with an OR condition
   * 
   * @throws Exception
   */
private void likePercentageTerminated_3(boolean useBindPrm) throws Exception {
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();
    Region region = cache.createRegion("pos", regionAttributes);
    char ch = 'd';
    String base = "abc";
    for (int i = 1; i < 6; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.status = base + ch;
        ch += 1;
        region.put(new Integer(i), pf);
    }
    base = "abd";
    ch = 'd';
    for (int i = 6; i < 11; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.status = base + ch;
        ch += 1;
        region.put(new Integer(i), pf);
    }
    QueryService qs = cache.getQueryService();
    Query q;
    SelectResults results;
    SelectResults expectedResults;
    String predicate = "";
    if (useBindPrm) {
        predicate = "$1";
    } else {
        predicate = " 'abc%'";
    }
    q = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate + " OR ps.ID > 6");
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "abc%" });
    } else {
        results = (SelectResults) q.execute();
    }
    ResultsBag bag = new ResultsBag(null);
    for (int i = 1; i < 11; ++i) {
        if (i != 6) {
            bag.add(region.get(new Integer(i)));
        }
    }
    expectedResults = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), bag.asSet());
    SelectResults[][] rs = new SelectResults[][] { { results, expectedResults } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    // Create Index
    qs.createIndex("status", IndexType.FUNCTIONAL, "ps.status", "/pos ps");
    QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private boolean indexCalled = false;

        public void afterIndexLookup(Collection results) {
            indexCalled = true;
        }

        public void endQuery() {
            assertFalse(indexCalled);
        }
    });
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "abc%" });
    } else {
        results = (SelectResults) q.execute();
    }
    rs[0][0] = results;
    rs[0][1] = expectedResults;
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    qs.createIndex("id", IndexType.FUNCTIONAL, "ps.ID", "/pos ps");
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private boolean[] indexCalled = new boolean[] { false, false };

        private int i = 0;

        public void afterIndexLookup(Collection results) {
            indexCalled[i++] = true;
        }

        public void endQuery() {
            for (int i = 0; i < indexCalled.length; ++i) {
                assertTrue(indexCalled[i]);
            }
        }
    });
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "abc%" });
    } else {
        results = (SelectResults) q.execute();
    }
    rs[0][0] = results;
    rs[0][1] = expectedResults;
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    QueryObserverHolder.setInstance(old);
}
Also used : Query(org.apache.geode.cache.query.Query) RegionAttributes(org.apache.geode.cache.RegionAttributes) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) ResultsCollectionWrapper(org.apache.geode.cache.query.internal.ResultsCollectionWrapper) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag) Cache(org.apache.geode.cache.Cache)

Example 8 with ObjectTypeImpl

use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.

the class LikePredicateJUnitTest method equalityForm_2.

/**
   * Tests simple \% or \ _ terminated string which in effect means equality
   * 
   * @throws Exception
   */
private void equalityForm_2(boolean useBindPrms) throws Exception {
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();
    Region region = cache.createRegion("pos", regionAttributes);
    String str = "d_";
    String base = "abc";
    for (int i = 1; i < 6; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.status = base + str;
        region.put(new Integer(i), pf);
    }
    base = "abc";
    str = "d%";
    for (int i = 6; i < 11; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.status = base + str;
        region.put(new Integer(i), pf);
    }
    QueryService qs = cache.getQueryService();
    Query q, q1;
    SelectResults results;
    SelectResults expectedResults;
    String predicate = "";
    if (useBindPrms) {
        predicate = "$1";
    } else {
        predicate = " 'abcd\\_'";
    }
    q = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate);
    if (useBindPrms) {
        results = (SelectResults) q.execute(new Object[] { "abcd\\_" });
    } else {
        results = (SelectResults) q.execute();
    }
    ResultsBag bag = new ResultsBag(null);
    for (int i = 1; i < 6; ++i) {
        bag.add(region.get(new Integer(i)));
    }
    expectedResults = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), bag.asSet());
    SelectResults[][] rs = new SelectResults[][] { { results, expectedResults } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    predicate = "";
    if (useBindPrms) {
        predicate = "$1";
    } else {
        predicate = " 'abcd\\%'";
    }
    q1 = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate);
    if (useBindPrms) {
        results = (SelectResults) q1.execute(new Object[] { "abcd\\%" });
    } else {
        results = (SelectResults) q1.execute();
    }
    bag = new ResultsBag(null);
    for (int i = 6; i < 11; ++i) {
        bag.add(region.get(new Integer(i)));
    }
    SelectResults expectedResults1 = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), bag.asSet());
    SelectResults[][] rs1 = new SelectResults[][] { { results, expectedResults1 } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs1, this);
    // Create Index
    qs.createIndex("status", IndexType.FUNCTIONAL, "ps.status", "/pos ps");
    QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private boolean indexCalled = false;

        public void afterIndexLookup(Collection results) {
            indexCalled = true;
        }

        public void endQuery() {
            assertTrue(indexCalled);
        }
    });
    if (useBindPrms) {
        results = (SelectResults) q.execute(new Object[] { "abcd\\_" });
    } else {
        results = (SelectResults) q.execute();
    }
    rs[0][0] = results;
    rs[0][1] = expectedResults;
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    if (useBindPrms) {
        results = (SelectResults) q1.execute(new Object[] { "abcd\\%" });
    } else {
        results = (SelectResults) q1.execute();
    }
    rs1[0][0] = results;
    rs1[0][1] = expectedResults1;
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs1, this);
    QueryObserverHolder.setInstance(old);
}
Also used : Query(org.apache.geode.cache.query.Query) RegionAttributes(org.apache.geode.cache.RegionAttributes) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) ResultsCollectionWrapper(org.apache.geode.cache.query.internal.ResultsCollectionWrapper) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag) Cache(org.apache.geode.cache.Cache)

Example 9 with ObjectTypeImpl

use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.

the class LikePredicateJUnitTest method likePercentageTerminated_5.

private void likePercentageTerminated_5(boolean useBindPrm) throws Exception {
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();
    Region region = cache.createRegion("pos", regionAttributes);
    char ch = 'd';
    String base = "abc";
    for (int i = 1; i < 6; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.status = base + ch;
        ch += 1;
        region.put(new Integer(i), pf);
    }
    QueryService qs = cache.getQueryService();
    Query q;
    SelectResults results;
    SelectResults expectedResults;
    String predicate = "";
    if (useBindPrm) {
        predicate = "$1";
    } else {
        predicate = " 'a%c%'";
    }
    q = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate);
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "a%bc%" });
    } else {
        results = (SelectResults) q.execute();
    }
    ResultsBag bag = new ResultsBag(null);
    for (int i = 1; i < 6; ++i) {
        bag.add(region.get(new Integer(i)));
    }
    expectedResults = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), bag.asSet());
    SelectResults[][] rs = new SelectResults[][] { { results, expectedResults } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    // Create Index
    qs.createIndex("status", IndexType.FUNCTIONAL, "ps.status", "/pos ps");
    q = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate);
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "a%bc%" });
    } else {
        results = (SelectResults) q.execute();
    }
    rs = new SelectResults[][] { { results, expectedResults } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    if (useBindPrm) {
        predicate = "$1";
    } else {
        predicate = "'abc_'";
    }
    q = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate);
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "abc_" });
    } else {
        results = (SelectResults) q.execute();
    }
    rs = new SelectResults[][] { { results, expectedResults } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
    if (useBindPrm) {
        predicate = "$1";
    } else {
        predicate = "'_bc_'";
    }
    q = qs.newQuery("SELECT distinct *  FROM /pos ps WHERE ps.status like " + predicate);
    if (useBindPrm) {
        results = (SelectResults) q.execute(new Object[] { "_bc_" });
    } else {
        results = (SelectResults) q.execute();
    }
    rs = new SelectResults[][] { { results, expectedResults } };
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
}
Also used : Query(org.apache.geode.cache.query.Query) RegionAttributes(org.apache.geode.cache.RegionAttributes) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) ResultsCollectionWrapper(org.apache.geode.cache.query.internal.ResultsCollectionWrapper) Region(org.apache.geode.cache.Region) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag) Cache(org.apache.geode.cache.Cache)

Example 10 with ObjectTypeImpl

use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.

the class ResultsCollectionWrapperLimitJUnitTest method testRemoveAll.

@Test
public void testRemoveAll() {
    List ordered = new ArrayList();
    for (int i = 1; i < 11; ++i) {
        ordered.add(new Integer(i));
    }
    ResultsCollectionWrapper wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 5);
    assertFalse(wrapper.remove(new Integer(6)));
    assertTrue(wrapper.remove(new Integer(4)));
    assertEquals(4, wrapper.size());
    List newList = new ArrayList();
    for (int i = 1; i < 6; ++i) {
        newList.add(new Integer(i));
    }
    assertTrue(wrapper.removeAll(newList));
    assertTrue(wrapper.size() == 0);
    ordered = new ArrayList();
    for (int i = 1; i < 11; ++i) {
        ordered.add(new Integer(i));
    }
    wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 5);
    newList = new ArrayList();
    for (int i = 2; i < 11; ++i) {
        newList.add(new Integer(i));
    }
    assertTrue(wrapper.removeAll(newList));
    assertTrue(wrapper.size() == 1);
    Iterator itr = wrapper.iterator();
    assertEquals(itr.next(), new Integer(1));
    assertFalse(itr.hasNext());
}
Also used : ArrayList(java.util.ArrayList) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)53 Test (org.junit.Test)37 SelectResults (org.apache.geode.cache.query.SelectResults)31 ArrayList (java.util.ArrayList)27 Portfolio (org.apache.geode.cache.query.data.Portfolio)27 QueryService (org.apache.geode.cache.query.QueryService)25 ObjectType (org.apache.geode.cache.query.types.ObjectType)25 List (java.util.List)24 Query (org.apache.geode.cache.query.Query)24 Region (org.apache.geode.cache.Region)23 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)23 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 UnitTest (org.apache.geode.test.junit.categories.UnitTest)17 Index (org.apache.geode.cache.query.Index)16 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)14 Collection (java.util.Collection)11 Iterator (java.util.Iterator)10 ResultsBag (org.apache.geode.cache.query.internal.ResultsBag)8 ResultsCollectionWrapper (org.apache.geode.cache.query.internal.ResultsCollectionWrapper)8 AttributesFactory (org.apache.geode.cache.AttributesFactory)7