Examples of AttributeUpdate


Examples of com.amazonaws.services.dynamodbv2.document.AttributeUpdate

    public void howToAddElementsToSet() {
        Table table = dynamo.getTable(TABLE_NAME);
        // Add a set of phone numbers to the attribute "phone"
        final String phoneNumber1 = "123-456-7890";
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            new AttributeUpdate("phone").put(new FluentHashSet<String>(phoneNumber1)));
        GetItemOutcome outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true)
        );
        Item item = outcome.getItem();
        Set<String> phoneNumbers = item.getStringSet("phone");
        assertTrue(1 == phoneNumbers.size());
        System.out.println(phoneNumbers);

        // Add a 2nd phone number to the set
        final String phoneNumber2 = "987-654-3210";
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            new AttributeUpdate("phone").addElements(phoneNumber2));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        phoneNumbers = item.getStringSet("phone");
        System.out.println(phoneNumbers);
        assertTrue(2== phoneNumbers.size());

        // removes the 2nd phone number from the set
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            new AttributeUpdate("phone").removeElements(phoneNumber2));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        phoneNumbers = item.getStringSet("phone");
        System.out.println(phoneNumbers);
        assertTrue(1 == phoneNumbers.size());

        // deletes the phone attribute
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                new AttributeUpdate("phone").delete());
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        phoneNumbers = item.getStringSet("phone");
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.AttributeUpdate

        Item item = outcome.getItem();
        final int oldZipCode = item.getInt("zipcode");

        // Increments the zip code attribute
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                new AttributeUpdate("zipcode").addNumeric(1));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        int newZipCode = item.getInt("zipcode");
        assertEquals(oldZipCode + 1, newZipCode);

        // Decrements the zip code attribute
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                new AttributeUpdate("zipcode").addNumeric(-1));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        newZipCode = item.getInt("zipcode");
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.AttributeUpdate

            table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                // Specifies the criteria that the "phone" attribute must exist
                // as a precondition to adding the phone number
                Arrays.asList(new Expected("phone").exists()),
                // Adds the phone number if the expectation is satisfied
                new AttributeUpdate("phone").addElements(phoneNumberToAdd));
            fail("Update Should fail as the phone number attribute is not present in the row");
        } catch (AmazonServiceException expected) {
            // Failed the criteria as expected
        }
    }
View Full Code Here

Examples of org.waveprotocol.wave.model.document.operation.util.ImmutableUpdateMap.AttributeUpdate

  public static AttributesUpdate scrubAttributesUpdate(AttributesUpdate unscrubbed,
      ScrubCache nameScrubber) {
    List<AttributeUpdate> list = new ArrayList<AttributeUpdate>();
    for (int i = 0; i < unscrubbed.changeSize(); i++) {
      list.add(new AttributeUpdate(
          nameScrubber.scrubUniquely(unscrubbed.getChangeKey(i)),
          scrubMostString(unscrubbed.getOldValue(i)),
          scrubMostString(unscrubbed.getNewValue(i))));
    }
    return AttributesUpdateImpl.fromUnsortedUpdatesUnchecked(list);
View Full Code Here

Examples of org.waveprotocol.wave.model.document.operation.util.ImmutableUpdateMap.AttributeUpdate

public class ImmutableUpdateMapTest extends TestCase {

  public void testCheckUpdatesSorted() {
    // see also the corresponding tests in ImmutableStateMapTest.
    ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(new AttributeUpdate[] {}));
    ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(new AttributeUpdate("a", null, "1")));
    ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
        new AttributeUpdate("aa", "0", "1"),
        new AttributeUpdate("ab", null, null)));
    ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
        new AttributeUpdate("a", "0", null),
        new AttributeUpdate("b", "p", "2"),
        new AttributeUpdate("c", "1", "1")));
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("asdfa", "a", "1"),
          new AttributeUpdate("asdfb", "2", null),
          new AttributeUpdate("asdfb", "2", "3")));
      fail();
    } catch (IllegalArgumentException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("rar", null, "1"),
          new AttributeUpdate("rar", "2", null),
          new AttributeUpdate("rbr", "1", "2")));
      fail();
    } catch (IllegalArgumentException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          null,
          new AttributeUpdate("a", "2", "1")));
      fail();
    } catch (NullPointerException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("a", "2", "a"),
          null));
      fail();
    } catch (NullPointerException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("a", "1", "j"),
          new AttributeUpdate("a", "1", "r")));
      fail();
    } catch (IllegalArgumentException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("a", "1", "f"),
          null,
          new AttributeUpdate("c", "a", "1")));
      fail();
    } catch (NullPointerException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          null,
          new AttributeUpdate("a", "1", "o"),
          new AttributeUpdate("c", "1", "l")));
      fail();
    } catch (NullPointerException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("a", "1", "y"),
          new AttributeUpdate("c", "1", ";"),
          null));
      fail();
    } catch (NullPointerException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("ard", "1", "3"),
          new AttributeUpdate("ard", "1", "2"),
          null));
      fail();
    } catch (IllegalArgumentException e) {
      // ok
    }
    try {
      ImmutableUpdateMap.checkUpdatesSorted(Arrays.asList(
          new AttributeUpdate("a", "1", null),
          new AttributeUpdate("c", "2", null),
          new AttributeUpdate("b", "3", null)));
      fail();
    } catch (IllegalArgumentException e) {
      // ok
    }
  }
View Full Code Here

Examples of org.waveprotocol.wave.model.document.operation.util.ImmutableUpdateMap.AttributeUpdate

  private AttributesUpdate attributesUpdateFrom(UpdateAttributes message) {
    List<AttributeUpdate> updates = new ArrayList<AttributeUpdate>();
    for (int i = 0; i < message.getAttributeUpdateSize(); i++) {
      KeyValueUpdate p = message.getAttributeUpdate(i);
      updates.add(new AttributeUpdate(p.getKey(), p.hasOldValue() ? p.getOldValue() : null,
          p.hasNewValue() ? p.getNewValue() : null));
    }
    return createAttributesUpdateImpl(updates);
  }
View Full Code Here

Examples of org.waveprotocol.wave.model.document.operation.util.ImmutableUpdateMap.AttributeUpdate

  public static AttributesUpdate scrubAttributesUpdate(AttributesUpdate unscrubbed,
      ScrubCache nameScrubber) {
    List<AttributeUpdate> list = new ArrayList<AttributeUpdate>();
    for (int i = 0; i < unscrubbed.changeSize(); i++) {
      list.add(new AttributeUpdate(
          nameScrubber.scrubUniquely(unscrubbed.getChangeKey(i)),
          scrubMostString(unscrubbed.getOldValue(i)),
          scrubMostString(unscrubbed.getNewValue(i))));
    }
    return AttributesUpdateImpl.fromUnsortedUpdatesUnchecked(list);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.