use of com.jcabi.dynamo.Item 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.Item in project jcabi-dynamo by jcabi.
the class MkRegionTest method storesAndReadsAttributes.
/**
* MkRegion can store and read items.
* @throws Exception If some problem inside
*/
@Test
public void storesAndReadsAttributes() throws Exception {
final String name = "users";
final String key = "id";
final String attr = "description";
final String nattr = "thenumber";
final Region region = new MkRegion(new H2Data().with(name, new String[] { key }, attr, nattr));
final Table table = region.table(name);
table.put(new Attributes().with(key, "32443").with(attr, "first value to \n\t€ save").with(nattr, "150"));
final Item item = table.frame().iterator().next();
MatcherAssert.assertThat(item.has(attr), Matchers.is(true));
MatcherAssert.assertThat(item.get(attr).getS(), Matchers.containsString("\n\t\u20ac save"));
item.put(attr, new AttributeValueUpdate().withValue(new AttributeValue("this is another value")));
MatcherAssert.assertThat(item.get(attr).getS(), Matchers.containsString("another value"));
MatcherAssert.assertThat(item.get(nattr).getN(), Matchers.endsWith("50"));
}
use of com.jcabi.dynamo.Item in project jcabi-dynamo by jcabi.
the class MkRegionTest method storesAndReadsSingleAttribute.
/**
* MkRegion can store and read items.
* @throws Exception If some problem inside
*/
@Test
public void storesAndReadsSingleAttribute() throws Exception {
final String table = "ideas";
final String key = "number";
final String attr = "total";
final Region region = new MkRegion(new H2Data().with(table, new String[] { key }, attr));
final Table tbl = region.table(table);
tbl.put(new Attributes().with(key, "32443").with(attr, "0"));
final Item item = tbl.frame().iterator().next();
item.put(attr, new AttributeValueUpdate().withValue(new AttributeValue().withN("2")).withAction(AttributeAction.PUT));
MatcherAssert.assertThat(item.get(attr).getN(), Matchers.equalTo("2"));
}
Aggregations