コード例 #1
0
  private void doQueryEscapeTestHelper(String data, TableRequestOptions options)
      throws StorageException {
    Class1 ref = new Class1();
    ref.setA(data);
    ref.setPartitionKey(UUID.randomUUID().toString());
    ref.setRowKey("foo");

    this.table.execute(TableOperation.insert(ref), options, null);
    TableQuery<Class1> query =
        TableQuery.from(Class1.class)
            .where(
                String.format(
                    "(PartitionKey eq '%s') and (A eq '%s')", ref.getPartitionKey(), data));

    int count = 0;

    for (Class1 ent : this.table.execute(query, options, null)) {
      count++;
      assertEquals(ent.getA(), ref.getA());
      assertEquals(ent.getB(), ref.getB());
      assertEquals(ent.getC(), ref.getC());
      assertEquals(ent.getPartitionKey(), ref.getPartitionKey());
      assertEquals(ent.getRowKey(), ref.getRowKey());
    }

    assertEquals(count, 1);
  }
コード例 #2
0
  private void doEscapeTestHelper(
      String data, boolean useBatch, boolean includeInKey, TableRequestOptions options)
      throws StorageException {
    Class1 ref = new Class1();
    ref.setA(data);
    ref.setPartitionKey(includeInKey ? "temp" + data : "temp");
    ref.setRowKey(UUID.randomUUID().toString());

    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.insert(ref);
      this.table.execute(batch, options, null);
    } else {
      this.table.execute(TableOperation.insert(ref), options, null);
    }

    TableResult res = null;

    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class);
      res = this.table.execute(batch, options, null).get(0);
    } else {
      res =
          this.table.execute(
              TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class),
              options,
              null);
    }

    Class1 retObj = res.getResultAsType();
    assertEquals(ref.getA(), retObj.getA());
    assertEquals(ref.getPartitionKey(), retObj.getPartitionKey());

    ref.setEtag(retObj.getEtag());
    ref.setB(data);

    // Merge
    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.merge(ref);
      this.table.execute(batch, options, null);
    } else {
      this.table.execute(TableOperation.merge(ref), options, null);
    }

    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class);
      res = this.table.execute(batch, options, null).get(0);
    } else {
      res =
          this.table.execute(
              TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class),
              options,
              null);
    }

    retObj = res.getResultAsType();
    assertEquals(ref.getA(), retObj.getA());
    assertEquals(ref.getB(), retObj.getB());

    // Replace
    ref.setEtag(retObj.getEtag());
    ref.setC(data);

    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.replace(ref);
      this.table.execute(batch, options, null);
    } else {
      this.table.execute(TableOperation.replace(ref), options, null);
    }

    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class);
      res = this.table.execute(batch, options, null).get(0);
    } else {
      res =
          this.table.execute(
              TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class),
              options,
              null);
    }

    retObj = res.getResultAsType();
    assertEquals(ref.getA(), retObj.getA());
    assertEquals(ref.getB(), retObj.getB());
    assertEquals(ref.getC(), retObj.getC());

    if (useBatch) {
      TableBatchOperation batch = new TableBatchOperation();
      batch.delete(retObj);
      res = this.table.execute(batch, options, null).get(0);
    } else {
      res = this.table.execute(TableOperation.delete(retObj), options, null);
    }
  }