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);
}
}
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));
}
Aggregations