Search in sources :

Example 1 with AttributeUpdates

use of com.jcabi.dynamo.AttributeUpdates in project wring by yegor256.

the class DyEvents method post.

@Override
public void post(final String title, final String text) throws IOException {
    final Iterator<Item> items = this.items(title);
    if (items.hasNext()) {
        final Item item = items.next();
        item.put(new AttributeUpdates().with("rank", new AttributeValueUpdate().withValue(new AttributeValue().withN("1")).withAction(AttributeAction.ADD)).with("text", new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(new AttributeValue().withS(DyEvents.concat(item.get("text").getS(), text)))));
        Logger.info(this, "Event updated for %s: \"%s\"", this.urn, title);
    } else {
        final int rank;
        if (title.startsWith("io.wring.agents.")) {
            rank = -Tv.THOUSAND;
        } else {
            rank = 1;
        }
        this.table().put(new Attributes().with("urn", this.urn).with("title", title).with("text", text).with("rank", rank).with("time", System.currentTimeMillis()));
        Logger.info(this, "Event created for %s: \"%s\"", this.urn, title);
    }
}
Also used : Item(com.jcabi.dynamo.Item) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) Attributes(com.jcabi.dynamo.Attributes) AttributeUpdates(com.jcabi.dynamo.AttributeUpdates)

Example 2 with AttributeUpdates

use of com.jcabi.dynamo.AttributeUpdates in project jcabi-dynamo by jcabi.

the class H2DataTest method updatesTableAttributes.

/**
 * H2Data can update table attributes.
 * @throws Exception In case test fails
 */
@Test
public void updatesTableAttributes() throws Exception {
    final String table = "tests";
    final String key = "tid";
    final int number = 43;
    final String attr = "descr";
    final String value = "Dummy\n\t\u20ac text";
    final String updated = "Updated";
    final MkData data = new H2Data().with(table, new String[] { key }, attr);
    data.put(table, new Attributes().with(key, number).with(attr, value));
    data.update(table, new Attributes().with(key, number), new AttributeUpdates().with(attr, "something else"));
    data.update(table, new Attributes().with(key, number), new AttributeUpdates().with(attr, updated));
    final Iterable<Attributes> result = data.iterate(table, new Conditions().with(key, Conditions.equalTo(number)));
    MatcherAssert.assertThat(result.iterator().next(), Matchers.hasEntry(Matchers.equalTo(attr), Matchers.equalTo(new AttributeValue(updated))));
    MatcherAssert.assertThat(result, Matchers.<Attributes>iterableWithSize(1));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Attributes(com.jcabi.dynamo.Attributes) AttributeUpdates(com.jcabi.dynamo.AttributeUpdates) Conditions(com.jcabi.dynamo.Conditions) Test(org.junit.Test)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 AttributeUpdates (com.jcabi.dynamo.AttributeUpdates)2 Attributes (com.jcabi.dynamo.Attributes)2 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)1 Conditions (com.jcabi.dynamo.Conditions)1 Item (com.jcabi.dynamo.Item)1 Test (org.junit.Test)1