コード例 #1
0
  @Test
  public void removePreparedStatement() {
    final CMapSync map = mapService.getMap(RING_OF_POWER_TABLE);
    final String quote = newQuote();
    final ValueTuple valueToPut =
        ValueTuple.of(COL_QUOTES, quote).with(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC));

    map.put(new CPutQuery(valueToPut));

    final CQuery query =
        CQueryBuilder.createPreparedRemoveQuery()
            .addFilters()
            .eq(COL_QUOTES)
            .noMoreFilters()
            .noFiltering();

    final CPreparedRemove preparedQuery = mapService.prepareRemove(RING_OF_POWER_TABLE, query);

    final CPreparedRemove.PreparedRemoveExecutor prepared =
        preparedQuery.bind().bindTo(COL_QUOTES, quote).stopBinding();

    prepared.execute();
    assertEquals(0, Lists.newArrayList(map.all()).size());
    map.put(new CPutQuery(valueToPut));
    prepared.execute();
    assertEquals(0, Lists.newArrayList(map.all()).size());
  }
コード例 #2
0
  @Test
  public void batchStatementTest() {
    final CMapSync map = mapService.getMap(RING_OF_POWER_TABLE);
    final CQuery query =
        CQueryBuilder.createPreparedRemoveQuery()
            .addFilters()
            .eq(COL_QUOTES)
            .noMoreFilters()
            .noFiltering();

    final CPreparedPut preparedPutQuery = mapService.preparePut(RING_OF_POWER_TABLE);
    final CPreparedRemove preparedRemoveQuery =
        mapService.prepareRemove(RING_OF_POWER_TABLE, query);
    final CPreparedPut.PreparedPutExecutor preparedPutExecutor =
        preparedPutQuery
            .bind()
            .bindTo(COL_QUOTES, newQuote())
            .bindTo(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC))
            .stopBinding();

    final CPreparedRemove.PreparedRemoveExecutor preparedRemoveExecutor =
        preparedRemoveQuery.bind().bindTo(COL_QUOTES, newQuote()).stopBinding();

    final CBatch batch = mapService.batch();

    batch.put(preparedPutExecutor);
    batch.remove(preparedRemoveExecutor);
    batch.apply();
    assertEquals(1, Lists.newArrayList(map.all()).size());
  }
コード例 #3
0
  @Test
  public void prepared_get_multiple_times() throws RowNotFoundException {
    final CQuery query =
        CQueryBuilder.createPreparedQuery()
            .of(COL_QUOTES, COL_TIMESTAMP)
            .addFilters()
            .eq(COL_QUOTES)
            .lte(COL_TIMESTAMP)
            .noMoreFilters()
            .noFiltering();
    final CQuery delQuery =
        CQueryBuilder.createPreparedRemoveQuery()
            .addFilters()
            .eq(COL_QUOTES)
            .noMoreFilters()
            .noFiltering();

    final CPreparedGet preparedQuery = mapService.prepareGet(RING_OF_POWER_TABLE, query);
    final CPreparedRemove preparedDelQuery =
        mapService.prepareRemove(RING_OF_POWER_TABLE, delQuery);

    final String quote = newQuote();
    final DateTime time = DateTime.now(DateTimeZone.UTC);

    try {
      preparedQuery
          .bind()
          .bindTo(COL_QUOTES, quote)
          .bindTo(COL_TIMESTAMP, time)
          .stopBinding()
          .one();
      fail();
    } catch (final RowNotFoundException ignored) {
    }

    final CMapSync map = mapService.getMap(RING_OF_POWER_TABLE);
    map.put(
        CQueryBuilder.createPutQuery()
            .addValueTuple(ValueTuple.of(COL_QUOTES, quote).with(COL_TIMESTAMP, time))
            .end());

    preparedQuery.bind().bindTo(COL_QUOTES, quote).bindTo(COL_TIMESTAMP, time).stopBinding().one();

    preparedDelQuery.bind().bindTo(COL_QUOTES, quote).stopBinding().execute();

    try {
      preparedQuery
          .bind()
          .bindTo(COL_QUOTES, quote)
          .bindTo(COL_TIMESTAMP, time)
          .stopBinding()
          .one();
      fail();
    } catch (final RowNotFoundException ignored) {
    }
  }