コード例 #1
0
  @Test
  public void multiple_same_column() throws RowNotFoundException {
    final CMapSync map = mapService.getMap(RING_OF_POWER_TABLE);
    final String quote = newQuote();

    final DateTime ts = DateTime.now(DateTimeZone.UTC);
    final ValueTuple valueToPut = ValueTuple.of(COL_QUOTES, quote).with(COL_TIMESTAMP, ts);

    map.put(new CPutQuery(valueToPut));
    final CQuery query =
        CQueryBuilder.createPreparedQuery()
            .of(COL_QUOTES, COL_TIMESTAMP)
            .addFilters()
            .eq(COL_QUOTES)
            .gte(COL_TIMESTAMP)
            .lte(COL_TIMESTAMP)
            .noMoreFilters()
            .noFiltering();
    final CPreparedGet preparedQuery = mapService.prepareGet(RING_OF_POWER_TABLE, query);
    final ValueTuple value =
        preparedQuery
            .bind()
            .bindTo(COL_QUOTES, quote)
            .bindTo(COL_TIMESTAMP, ts)
            .stopBinding()
            .one();

    assertEquals(value, valueToPut);
  }
コード例 #2
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) {
    }
  }
コード例 #3
0
  //  @Test(expected = CQueryException.class, expectedExceptionsMessageRegExp = "No such key as god.
  // Has keys .*")
  // TODO: exception message
  @Test(expected = CQueryException.class)
  public void getOnePreparedStatementWrongColumn() throws RowNotFoundException {
    final CQuery query =
        CQueryBuilder.createPreparedQuery()
            .of(COL_QUOTES, COL_TIMESTAMP)
            .addFilters()
            .eq(COL_QUOTES)
            .lte(COL_TIMESTAMP)
            .noMoreFilters()
            .noFiltering();

    final CPreparedGet preparedQuery = mapService.prepareGet(RING_OF_POWER_TABLE, query);
    preparedQuery.bind().bindTo(CColumn.of("god", TEXT), (String) null).stopBinding().one();
  }
コード例 #4
0
  @Test(expected = CQueryException.class)
  public void getOnePreparedStatementBindNotAllColumns() throws RowNotFoundException {
    final CQuery query =
        CQueryBuilder.createPreparedQuery()
            .of(COL_QUOTES, COL_TIMESTAMP)
            .addFilters()
            .eq(COL_QUOTES)
            .lte(COL_TIMESTAMP)
            .noMoreFilters()
            .noFiltering();

    final CPreparedGet preparedQuery = mapService.prepareGet(RING_OF_POWER_TABLE, query);
    preparedQuery.bind().bindTo(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC)).stopBinding().one();
  }
コード例 #5
0
  @Test
  public void getPreparedStatement() {
    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.createPreparedQuery()
            .of(COL_QUOTES, COL_TIMESTAMP)
            .addFilters()
            .eq(COL_QUOTES)
            .lte(COL_TIMESTAMP)
            .noMoreFilters()
            .noFiltering();
    final CPreparedGet preparedQuery = mapService.prepareGet(RING_OF_POWER_TABLE, query);
    final CPreparedGet.PreparedGetExecutor preparedExecutor =
        preparedQuery
            .bind()
            .bindTo(COL_QUOTES, quote)
            .bindTo(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC))
            .stopBinding();

    final List<ValueTuple> values = Lists.newArrayList(preparedExecutor.all());

    assertEquals(1, values.size());
    assertTrue(values.contains(valueToPut));

    final ValueTuple valueToPut2 =
        ValueTuple.of(COL_QUOTES, newQuote()).with(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC));

    map.put(new CPutQuery(valueToPut2));

    final List<ValueTuple> valueTuples = Lists.newArrayList(preparedExecutor.all());
    assertEquals(1, valueTuples.size());
    assertTrue(valueTuples.contains(valueToPut));
  }
コード例 #6
0
  @Test
  public void geOnePreparedStatement() throws RowNotFoundException {
    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.createPreparedQuery()
            .of(COL_QUOTES, COL_TIMESTAMP)
            .addFilters()
            .eq(COL_QUOTES)
            .lte(COL_TIMESTAMP)
            .noMoreFilters()
            .noFiltering();

    final CPreparedGet preparedQuery = mapService.prepareGet(RING_OF_POWER_TABLE, query);

    final PreparedGetExecutor prepared =
        preparedQuery
            .bind()
            .bindTo(COL_QUOTES, quote)
            .bindTo(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC))
            .stopBinding();

    final ValueTuple value = prepared.one();
    assertEquals(valueToPut, value);

    final ValueTuple valueToPut2 =
        ValueTuple.of(COL_QUOTES, newQuote()).with(COL_TIMESTAMP, DateTime.now(DateTimeZone.UTC));

    map.put(new CPutQuery(valueToPut2));
    final ValueTuple one = prepared.one();
    assertEquals(valueToPut, one);
  }