Package com.pardot.rhombus.cobject.statement

Examples of com.pardot.rhombus.cobject.statement.CQLStatement


      Map<String, Object> data = TestHelpers.getTestObject(0);
      UUID uuid = UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43");
      CQLStatementIterator result = Subject.makeCQLforInsert(KEYSPACE_NAME, def,data,uuid,Long.valueOf(1),null);
      List<CQLStatement> actual = toList(result);

      CQLStatement expected;
      assertEquals("Should generate CQL statements for the static table plus all indexes including the filtered index", 6, actual.size());
      //static table
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype\" (id, filtered, data1, data2, data3, instance, type, foreignid) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
          TABLE_NAME,
View Full Code Here


      indexkeys.put("type", "5");
      indexkeys.put("instance", "222222");

      // creating a iterator that has both start and end and both are inclusive
      BoundedLazyCQLStatementIterator boundedLazyIterator = (BoundedLazyCQLStatementIterator) CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.DESCENDING, null, stop, 10l, true, false, false);
      CQLStatement actual = boundedLazyIterator.next();
      CQLStatement expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id <= ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(1),"777","222222","5", stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);


      // testing if next start uuid is correctly applied
      UUID nextUuid = UUID.fromString("ada375b1-a2d9-11e2-99a3-3f36d3955e43");
      boundedLazyIterator.setNextUuid(nextUuid);

      assertTrue(boundedLazyIterator.hasNext());
      actual = boundedLazyIterator.next();

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(nextUuid, actual.getValues()[4]);

      // testing iterator that has both start and end , non inclusive
      boundedLazyIterator = (BoundedLazyCQLStatementIterator) CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.DESCENDING, null, stop, 10l, false, false, false);
      actual = boundedLazyIterator.next();
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id < ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(1),"777","222222","5", stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);

      // testing if next start uuid is correctly applied
      nextUuid = UUID.fromString("ada375b1-a2d9-11e2-99a3-3f36d3955e43");
      boundedLazyIterator.setNextUuid(nextUuid);

      assertTrue(boundedLazyIterator.hasNext());
      actual = boundedLazyIterator.next();

      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id <= ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(1),"777","222222","5", nextUuid)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(nextUuid, actual.getValues()[4]);

    }
View Full Code Here

      indexkeys.put("type", "5");
      indexkeys.put("instance", "222222");

      // creating a iterator that has both start and end and both are inclusive
      UnboundableCQLStatementIterator unBoundedIterator = (UnboundableCQLStatementIterator) CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.DESCENDING, start, stop, 10l, true, false, false);
      CQLStatement actual = unBoundedIterator.next();
      CQLStatement expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id >= ? AND id <= ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", start, stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);

      // testing if next start uuid is correctly applied
      UUID nextUuid = UUID.fromString("ada375b1-a2d9-11e2-99a3-3f36d3955e43");
      unBoundedIterator.setNextUuid(nextUuid);

      // should not contain next shard
      assertFalse(unBoundedIterator.hasNext());
      actual = unBoundedIterator.next();

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(nextUuid, actual.getValues()[5]);

      // testing iterator that has both start and end , non inclusive
      unBoundedIterator = (UnboundableCQLStatementIterator) CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.DESCENDING, start, stop, 10l, false, false, false);
      actual = unBoundedIterator.next();
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id > ? AND id < ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", start, stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);

      // testing if next start uuid is correctly applied
      nextUuid = UUID.fromString("ada375b1-a2d9-11e2-99a3-3f36d3955e43");
      unBoundedIterator.setNextUuid(nextUuid);

      // should not contain next shard
      assertFalse(unBoundedIterator.hasNext());
      actual = unBoundedIterator.next();

      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id >= ? AND id <= ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", start, nextUuid)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);


      // Repeating the above tests for ascending
      unBoundedIterator = (UnboundableCQLStatementIterator) CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.ASCENDING, start, stop, 10l, true, false, false);
      actual = unBoundedIterator.next();
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id >= ? AND id <= ? ORDER BY id ASC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", start, stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);

      // testing if next start uuid is correctly applied
      nextUuid = UUID.fromString("ada375b1-a2d9-11e2-99a3-3f36d3955e43");
      unBoundedIterator.setNextUuid(nextUuid);

      // should not contain next shard
      assertFalse(unBoundedIterator.hasNext());
      actual = unBoundedIterator.next();

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(nextUuid, actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);

      // testing iterator that has both start and end , non inclusive
      unBoundedIterator = (UnboundableCQLStatementIterator) CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.ASCENDING, start, stop, 10l, false, false, false);
      actual = unBoundedIterator.next();
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id > ? AND id < ? ORDER BY id ASC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", start, stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);

      // testing if next start uuid is correctly applied
      nextUuid = UUID.fromString("ada375b1-a2d9-11e2-99a3-3f36d3955e43");
      unBoundedIterator.setNextUuid(nextUuid);

      // should not contain next shard
      assertFalse(unBoundedIterator.hasNext());
      actual = unBoundedIterator.next();

      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id >= ? AND id <= ? ORDER BY id ASC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", nextUuid, stop)
      );

      assertEquals(expected.getQuery(), actual.getQuery());
      assertEquals(expected.getValues()[0], actual.getValues()[0]);
      assertEquals(expected.getValues()[1], actual.getValues()[1]);
      assertEquals(expected.getValues()[2], actual.getValues()[2]);
      assertEquals(expected.getValues()[3], actual.getValues()[3]);
      assertEquals(expected.getValues()[4], actual.getValues()[4]);
      assertEquals(expected.getValues()[5], actual.getValues()[5]);

    }
View Full Code Here

      UUID uuid = UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43");
      CQLStatementIterator actual = Subject.makeCQLforGet(KEYSPACE_NAME, def, uuid);
      assertEquals("Static gets should return bounded query iterator", true,actual.isBounded());
      assertEquals("Static gets should return an iterator with 1 statement", 1,actual.size());
      Object[] expectedValues = {uuid};
      CQLStatement expected = CQLStatement.make("SELECT * FROM \"testspace\".\"testtype\" WHERE id = ?;", TABLE_NAME, expectedValues);
      assertEquals("Should generate proper CQL for static table get by ID", expected, toList(actual).get(0));

      CObjectShardList shardIdLists = new ShardListMock(Arrays.asList(1L,2L,3L,4L,5L));
      UUID start = UUID.fromString("a8a2abe0-a251-11e2-bcbb-adf1a79a327f");
      UUID stop = UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43");
      //Wide table using shardIdList and therefore bounded
      TreeMap<String,Object> indexkeys = Maps.newTreeMap();
      indexkeys.put("foreignid","777");
      indexkeys.put("type", "5");
      indexkeys.put("instance", "222222");
      actual = CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.DESCENDING, null, UUIDs.startOf(DateTime.now().getMillis()), 10l, false, false, false);
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id < ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(1),"777","222222","5", stop)
      );
      CQLStatement result = actual.next();
      assertEquals(expected.getQuery(), result.getQuery());
      assertEquals(expected.getValues()[0], result.getValues()[0]);
      assertEquals(expected.getValues()[1], result.getValues()[1]);
      assertEquals(expected.getValues()[2], result.getValues()[2]);
      assertEquals(expected.getValues()[3], result.getValues()[3]);

      //expected = "SELECT * FROM \"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = 2 AND foreignid = 777 AND instance = 222222 AND type = 5 AND id <";
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id < ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          Arrays.asList(Long.valueOf(2),"777","222222","5", stop).toArray()
      );

      actual.nextShard();
      result = actual.next();
      assertEquals(expected.getQuery(), result.getQuery());
      assertEquals(expected.getValues()[0], result.getValues()[0]);
      assertEquals(expected.getValues()[1], result.getValues()[1]);
      assertEquals(expected.getValues()[2], result.getValues()[2]);
      assertEquals(expected.getValues()[3], result.getValues()[3]);
      assertEquals("Should be bounded query list", true, actual.isBounded());


      //Wide table exclusive slice bounded query should not use shard list
      indexkeys = Maps.newTreeMap();
      indexkeys.put("foreignid","777");
      indexkeys.put("type", "5");
      indexkeys.put("instance", "222222");
      actual = CObjectCQLGenerator.makeCQLforList(KEYSPACE_NAME, shardIdLists, def, indexkeys, CObjectOrdering.DESCENDING, start, stop, 10l, false, false, false);
      expected = CQLStatement.make(
          "SELECT * FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE shardid = ? AND foreignid = ? AND instance = ? AND type = ? AND id > ? AND id < ? ORDER BY id DESC LIMIT 10 ALLOW FILTERING;",
          TABLE_NAME,
          arrayFromValues(Long.valueOf(160),"777","222222","5", start, stop)
      );
      //"Should generate proper CQL for wide table get by index values"
      CQLStatement actualStatement = actual.next();
      assertEquals(expected, actualStatement);
      assertTrue("Should be bounded query iterator", actual.isBounded());
      assertTrue("Should be none remaining in the iterator", !actual.hasNext());


View Full Code Here

      CDefinition def = CDefinition.fromJsonString(json);
      Map<String, Object> data = TestHelpers.getTestObject(0);
      UUID uuid = UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43");
      CQLStatementIterator result = Subject.makeCQLforDelete(KEYSPACE_NAME, def,uuid,data,Long.valueOf(111));

      CQLStatement expected;

      expected = CQLStatement.make("DELETE FROM \"testspace\".\"testtype\" WHERE id = ?;", TABLE_NAME, Arrays.asList(uuid).toArray());
      assertEquals(expected,result.next());

      expected = CQLStatement.make(
View Full Code Here

      Map<String, Object> data = TestHelpers.getTestObject(0);
      UUID uuid = UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43");
      Map<String,Object> newdata = Maps.newHashMap();
      newdata.put("type", Integer.valueOf(9));
      CQLStatementIterator result = Subject.makeCQLforUpdate(KEYSPACE_NAME, def,uuid,data,newdata);
      CQLStatement expected = CQLStatement.make(
          "DELETE FROM \"testspace\".\"testtype6671808f3f51bcc53ddc76d2419c9060\" WHERE id = ? AND shardid = ? AND instance = ? AND type = ?;",
          TABLE_NAME,
          Arrays.asList(UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"), Long.valueOf(160), Integer.valueOf(222222), Integer.valueOf(5)).toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "DELETE FROM \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" WHERE id = ? AND shardid = ? AND foreignid = ? AND instance = ? AND type = ?;",
          TABLE_NAME,
          Arrays.asList(UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"), Long.valueOf(160), Integer.valueOf(777), Integer.valueOf(222222), Integer.valueOf(5)).toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype6671808f3f51bcc53ddc76d2419c9060\" (id, shardid, filtered, data1, data2, data3, instance, type, foreignid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
          UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
          Long.valueOf(160),
          Integer.valueOf(1),
          "This is data one",
          "This is data two",
          "This is data three",
          Integer.valueOf(222222),
          Integer.valueOf(9),
          Integer.valueOf(777)).toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"__shardindex\" (tablename, indexvalues, shardid, targetrowkey) VALUES (?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
            "testtype6671808f3f51bcc53ddc76d2419c9060",
            "222222:9",
            Long.valueOf(160),
            "160:222222:9").toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" (id, shardid, filtered, data1, data2, data3, instance, type, foreignid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
            UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
            Long.valueOf(160),
            Integer.valueOf(1),
            "This is data one",
            "This is data two",
            "This is data three",
            Integer.valueOf(222222),
            Integer.valueOf(9),
            Integer.valueOf(777)).toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"__shardindex\" (tablename, indexvalues, shardid, targetrowkey) VALUES (?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
            "testtypef9bf3332bb4ec879849ec43c67776131",
            "777:222222:9",
            Long.valueOf(160),
            "160:777:222222:9").toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype7f9bb4e56d3cae5b11c553547cfe5897\" (id, shardid, instance, type, foreignid) VALUES (?, ?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
            UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
            Long.valueOf(1),
            222222,
            9,
            777).toArray()
      );
      assertEquals(expected, result.next());
      //verify that this last insert was on the uneffected index (which is why it does not have a matching __shardindex insert
      assertEquals("testtype7f9bb4e56d3cae5b11c553547cfe5897",makeTableName(def,def.getIndexes().get("foreignid")));
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype\" (id, type) VALUES (?, ?);",
          TABLE_NAME,
          Arrays.asList(
            UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
            Integer.valueOf(9)).toArray()
      );
      assertEquals(expected, result.next());
      CQLStatement next = result.next();
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"__index_updates\" (id, statictablename, instanceid, indexvalues) values (?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              (UUID)next.getValues()[0],
              "testtype",
              UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
              "{\"foreignid\":777,\"instance\":222222,\"type\":9}").toArray()
      );
      assertEquals(expected, next);
      //should be no results left
      assertTrue(!result.hasNext());




      //Now try the same update, but this time we dont change anything and send the same values. In this case
      //It should not generate any deletes
      newdata.put("type", Integer.valueOf(5));
       result = Subject.makeCQLforUpdate(KEYSPACE_NAME, def,uuid,data,newdata);
      //no deletes
      //Go right to the inserts
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype6671808f3f51bcc53ddc76d2419c9060\" (id, shardid, filtered, data1, data2, data3, instance, type, foreignid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
              Long.valueOf(160),
              Integer.valueOf(1),
              "This is data one",
              "This is data two",
              "This is data three",
              Integer.valueOf(222222),
              Integer.valueOf(5),
              Integer.valueOf(777)).toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"__shardindex\" (tablename, indexvalues, shardid, targetrowkey) VALUES (?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              "testtype6671808f3f51bcc53ddc76d2419c9060",
              "222222:5",
              Long.valueOf(160),
              "160:222222:5").toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtypef9bf3332bb4ec879849ec43c67776131\" (id, shardid, filtered, data1, data2, data3, instance, type, foreignid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
              Long.valueOf(160),
              Integer.valueOf(1),
              "This is data one",
              "This is data two",
              "This is data three",
              Integer.valueOf(222222),
              Integer.valueOf(5),
              Integer.valueOf(777)).toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"__shardindex\" (tablename, indexvalues, shardid, targetrowkey) VALUES (?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              "testtypef9bf3332bb4ec879849ec43c67776131",
              "777:222222:5",
              Long.valueOf(160),
              "160:777:222222:5").toArray()
      );
      assertEquals(expected, result.next());
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype7f9bb4e56d3cae5b11c553547cfe5897\" (id, shardid, instance, type, foreignid) VALUES (?, ?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
              Long.valueOf(1),
              222222,
              5,
              777).toArray()
      );
      assertEquals(expected, result.next());
      //verify that this last insert was on the uneffected index (which is why it does not have a matching __shardindex insert
      assertEquals("testtype7f9bb4e56d3cae5b11c553547cfe5897",makeTableName(def,def.getIndexes().get("foreignid")));
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"testtype\" (id, type) VALUES (?, ?);",
          TABLE_NAME,
          Arrays.asList(
              UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
              Integer.valueOf(5)).toArray()
      );
      assertEquals(expected, result.next());
      next = result.next();
      expected = CQLStatement.make(
          "INSERT INTO \"testspace\".\"__index_updates\" (id, statictablename, instanceid, indexvalues) values (?, ?, ?, ?);",
          TABLE_NAME,
          Arrays.asList(
              (UUID)next.getValues()[0],
              "testtype",
              UUID.fromString("ada375b0-a2d9-11e2-99a3-3f36d3955e43"),
              "{\"foreignid\":777,\"instance\":222222,\"type\":5}").toArray()
      );
      assertEquals(expected, next);
View Full Code Here

  public void executeBatch(List<CQLStatementIterator> statementIterators) {
    BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED);
    for(CQLStatementIterator statementIterator : statementIterators) {
      while(statementIterator.hasNext()) {
        CQLStatement statement = statementIterator.next();
        batchStatement.add(getBoundStatement(session, statement));
      }
    } try {
      session.execute(batchStatement);
    } catch(NoHostAvailableException e) {
View Full Code Here

    logger.trace("Created consumer with countdown {}", shutdownLatch.getCount());
  }

  public void start() {
    while(statementIterator.hasNext()) {
      final CQLStatement next = statementIterator.next();
      Runnable r = new Runnable() {
        @Override
        public void run() {
          handle(next);
        }
View Full Code Here

TOP

Related Classes of com.pardot.rhombus.cobject.statement.CQLStatement

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.