Package com.pardot.rhombus

Examples of com.pardot.rhombus.Criteria


    // since we are setting up enduuid of 40th index
    // we are expecting 41 objects
    // as inclusive flag to true

    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setEndUuid(UUID.fromString(uuidList.get(40)));
    criteria.setInclusive(true);
    criteria.setLimit((long) (nDataItems / 3) - 10L);

    //now test the count function
    long count = om.count("object2", criteria);
    assertEquals(41, count);

    // since we are setting up enduuid we are expecting 40 objects
    // as inclusive flag to false
    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setEndUuid(UUID.fromString(uuidList.get(40)));
    criteria.setInclusive(false);
    criteria.setLimit((long) (nDataItems / 3) - 10L);


    count = om.count("object2", criteria);
    assertEquals(40, count);

    // we are setting up enduuid as id of first object,
    // with inclusive set to false
    // we are expecting 0 objects

    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setEndUuid(UUID.fromString(uuidList.get(0)));
    criteria.setInclusive(false);
    criteria.setLimit((long) (nDataItems / 3) - 10L);

    count = om.count("object2", criteria);
    assertEquals(0, count);


    // we are setting up enduuid as id of first object,
    // with inclusive set to true
    // we are expecting 1 object

    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setEndUuid(UUID.fromString(uuidList.get(0)));
    criteria.setInclusive(true);
    criteria.setLimit(1L);

    count = om.count("object2", criteria);
    assertEquals(1, count);

    // simulating two page retrievals, like in the php side iterator
    // assuming the page size is 100
    // limit is pageSize + 1 , 101
    // we should get 100 objects back in the last iteration
    // ordering ASC

    long pageSize = 100;
    int nextItem = 0;

    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setOrdering("ASC");
    criteria.setLimit(pageSize + 1);

    List<Map<String, Object>> dbObjects = om.list("object2", criteria);
    assertEquals(pageSize + 1, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {

      String dbObjectId = (String) result.get("id").toString();
      if (nextItem == pageSize) {
        break;
      }
      nextItem++;
    }

    String startUuid = dbObjects.get(nextItem).get("id").toString();
    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setOrdering("ASC");
    criteria.setStartUuid(UUID.fromString(startUuid));
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize, dbObjects.size());


    // simulating two page retrievals, like in the php side iterator
    // assuming the page size is 100
    // limit is pageSize + 1 , 101
    // we should get 100 objects back in the last iteration
    // ordering DESC

    nextItem = 0;

    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize + 1, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {

      String dbObjectId = (String) result.get("id").toString();
      if (nextItem == pageSize) {
        break;
      }
      nextItem++;
    }

    String endUuid = dbObjects.get(nextItem).get("id").toString();
    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setEndUuid(UUID.fromString(endUuid));
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize, dbObjects.size());

    // simulating two page retrievals, like in the php side iterator
    // assuming the page size is 100
    // limit is pageSize + 1 , 101
    // we should get 100 objects back in the last iteration
    // ordering DESC
    // inclusive set to false

    nextItem = 0;

    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setInclusive(false);
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize + 1, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {

      String dbObjectId = (String) result.get("id").toString();
      if (nextItem == pageSize) {
        break;
      }
      nextItem++;
    }

    endUuid = dbObjects.get(nextItem).get("id").toString();
    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setEndUuid(UUID.fromString(endUuid));
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize, dbObjects.size());


    // simulating two page retrievals, like in the php side iterator
    // assuming the page size is 100
    // limit is pageSize + 1 , 101
    // we should get 100 objects back in the last iteration
    // ordering ASC
    // inclusive set to false

    nextItem = 0;

    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setInclusive(false);
    criteria.setOrdering("ASC");
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize + 1, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {

      String dbObjectId = (String) result.get("id").toString();
      if (nextItem == pageSize) {
        break;
      }
      nextItem++;
    }

    startUuid = dbObjects.get(nextItem).get("id").toString();
    criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(false);
    criteria.setOrdering("ASC");
    criteria.setStartUuid(UUID.fromString(startUuid));
    criteria.setLimit(pageSize + 1);

    dbObjects = om.list("object2", criteria);
    assertEquals(pageSize, dbObjects.size());

    cm.teardown();
View Full Code Here


    //Query it back out
    //Make sure that we have the proper number of results
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setLimit(50L);
    List<Map<String, Object>> results = om.list("object1", criteria);
    // Index by field1 so we can compare
    Map<String, Map<String, Object>> indexedResults = Maps.uniqueIndex(results, new Function<Map<String, Object>, String>() {
      public String apply(Map<String, Object> object) {
        return object.get("id").toString();
View Full Code Here

    //Add another object with the same foreign key
    UUID key2 = (UUID) om.insert("testtype", JsonUtil.rhombusMapFromJsonMap(TestHelpers.getTestObject(1), definition.getDefinitions().get("testtype")));

    //Query by foreign key
    Criteria criteria = TestHelpers.getTestCriteria(0);
    long foreignKey = ((Integer) criteria.getIndexKeys().get("foreignid")).longValue();
    criteria.getIndexKeys().put("foreignid", foreignKey);
    List<Map<String, Object>> dbObjects = om.list("testtype", criteria);
    assertEquals(2, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {
      assertEquals(foreignKey, result.get("foreignid"));
    }

    //Remove one of the objects we added
    om.delete("testtype", key);

    //Re-query by foreign key
    dbObjects = om.list("testtype", criteria);
    assertEquals(1, dbObjects.size());

    //Update the values of one of the objects
    Map<String, Object> testObject2 = JsonUtil.rhombusMapFromJsonMap(
        TestHelpers.getTestObject(2),
        definition.getDefinitions().get("testtype"));
    UUID key3 = om.update("testtype", key2, testObject2);

    //Get the updated object back and make sure it matches
    Map<String, Object> dbObject2 = om.getByKey("testtype", key3);
    testObject2.put("id", key2);
    for (String dbKey : dbObject2.keySet()) {
      //Verify that everything is the same
      assertEquals(testObject2.get(dbKey), dbObject2.get(dbKey));
    }

    //Get from the original index
    dbObjects = om.list("testtype", criteria);
    assertEquals(0, dbObjects.size());

    //Get from the new index
    Criteria criteria2 = TestHelpers.getTestCriteria(1);
    criteria2.getIndexKeys().put("foreignid", ((Integer) criteria2.getIndexKeys().get("foreignid")).longValue());
    dbObjects = om.list("testtype", criteria2);
    assertEquals(1, dbObjects.size());

    //an imediate request should return null, because we didnt wait for consistency
    assertEquals(null, om.getNextUpdateIndexRow(null));
View Full Code Here

        assertEquals(testObject.get(dbKey), dbObject.get(dbKey));
      }
    }

    //Query by foreign key
    Criteria criteria = TestHelpers.getTestCriteria(0);
    long foreignKey = ((Long) criteria.getIndexKeys().get("foreignid")).longValue();
    criteria.getIndexKeys().put("foreignid", foreignKey);
    List<Map<String, Object>> dbObjects = om.list("testtype", criteria);
    assertEquals(1, dbObjects.size());
    for (Map<String, Object> result : dbObjects) {
      assertEquals(foreignKey, result.get("foreignid"));
    }
View Full Code Here

    //Make sure that we have the proper number of results
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("object_type", "Account");
    indexValues.put("object_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setLimit(50L);
    List<Map<String, Object>> results = om.list("object_audit", criteria);
    assertEquals(8, results.size());

    //Now query for results since May 1 2013
    criteria.setStartTimestamp(1367366400000L);
    results = om.list("object_audit", criteria);
    assertEquals(7, results.size());

    //And for results since May 14, 2013
    criteria.setStartTimestamp(1368489600000L);
    results = om.list("object_audit", criteria);
    assertEquals(5, results.size());

    cm.teardown();
  }
View Full Code Here

    //Count the number of inserts we made
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);

    //now test the count function
    long count = om.count("object2", criteria);
    assertEquals(nDataItems, count);
View Full Code Here

    //Count the number of inserts we made
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(true);

    //now test the count function
    long count = om.count("object2", criteria);
    assertEquals(nDataItems, count);
View Full Code Here

    //Count the number of inserts we made
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(true);
    criteria.setLimit(20L);

    //now test the count function
    long count = om.count("object2", criteria);
    assertEquals(20, count);
View Full Code Here

    //Count the number of inserts we made
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("field2", "taco");
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(true);

    //now test the count function
    long count = om.count("object2", criteria);
    assertEquals((nDataItems / 3) + 1, count);
View Full Code Here

    //Count the number of inserts we made
    SortedMap<String, Object> indexValues = Maps.newTreeMap();
    indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
    indexValues.put("field2", "taco");
    Criteria criteria = new Criteria();
    criteria.setIndexKeys(indexValues);
    criteria.setAllowFiltering(true);
    criteria.setLimit((long) (nDataItems / 3) - 10L);

    //now test the count function
    long count = om.count("object2", criteria);
    assertEquals((nDataItems / 3) - 10, count);
View Full Code Here

TOP

Related Classes of com.pardot.rhombus.Criteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.