use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoEntityStorageIT method update.
@Test
public void update() throws Exception {
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
// Store Alice in the repository.
final Entity alice = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
storage.create(alice);
// Show Alice was stored.
Optional<Entity> latest = storage.get(new RyaURI("urn:SSN/111-11-1111"));
assertEquals(alice, latest.get());
// Change Alice's eye color to brown.
final Entity updated = Entity.builder(alice).setVersion(latest.get().getVersion() + 1).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "brown"))).build();
storage.update(alice, updated);
// Fetch the Alice object and ensure it has the new value.
latest = storage.get(new RyaURI("urn:SSN/111-11-1111"));
assertEquals(updated, latest.get());
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoEntityStorageIT method update_differentSubjects.
@Test(expected = EntityStorageException.class)
public void update_differentSubjects() throws Exception {
// Two objects that do not have the same Subjects.
final Entity old = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setExplicitType(new RyaURI("urn:person")).build();
final Entity updated = Entity.builder().setSubject(new RyaURI("urn:SSN/222-22-2222")).setExplicitType(new RyaURI("urn:person")).build();
// The update will fail.
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
storage.update(old, updated);
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class StatementPatternStorageTest method testSimplePredicateRange.
public void testSimplePredicateRange() throws Exception {
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"), new RyaURI(namespace, "p"), new RyaType("l")));
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "b"), new RyaURI(namespace, "p"), new RyaType("l")));
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "c"), new RyaURI(namespace, "n"), new RyaType("l")));
int count = 0;
List<StatementPatternStorage> storages = createStorages("accumulo://" + tablePrefix + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&predicate=<" + namespace + "p>&mock=true");
for (StatementPatternStorage storage : storages) {
while (true) {
Tuple next = storage.getNext();
if (next == null) {
break;
}
count++;
}
}
assertEquals(2, count);
ryaDAO.destroy();
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class StatementPatternStorageTest method testContext.
public void testContext() throws Exception {
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"), new RyaURI(namespace, "p"), new RyaType("l1")));
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"), new RyaURI(namespace, "p"), new RyaType("l2"), new RyaURI(namespace, "g1")));
int count = 0;
List<StatementPatternStorage> storages = createStorages("accumulo://" + tablePrefix + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&predicate=<" + namespace + "p>&mock=true");
for (StatementPatternStorage storage : storages) {
while (true) {
Tuple next = storage.getNext();
if (next == null) {
break;
}
count++;
}
}
assertEquals(2, count);
count = 0;
storages = createStorages("accumulo://" + tablePrefix + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&predicate=<" + namespace + "p>&context=<" + namespace + "g1>&mock=true");
for (StatementPatternStorage storage : storages) {
while (true) {
Tuple next = storage.getNext();
if (next == null) {
break;
}
count++;
}
}
assertEquals(1, count);
ryaDAO.destroy();
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class StatementPatternStorage method createRange.
protected Map.Entry<TABLE_LAYOUT, Range> createRange(Value s_v, Value p_v, Value o_v) throws IOException {
RyaURI subject_rya = RdfToRyaConversions.convertResource((Resource) s_v);
RyaURI predicate_rya = RdfToRyaConversions.convertURI((URI) p_v);
RyaType object_rya = RdfToRyaConversions.convertValue(o_v);
TriplePatternStrategy strategy = ryaContext.retrieveStrategy(subject_rya, predicate_rya, object_rya, null);
if (strategy == null) {
return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, Range>(TABLE_LAYOUT.SPO, new Range());
}
Map.Entry<TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(subject_rya, predicate_rya, object_rya, null, null);
ByteRange byteRange = entry.getValue();
return new RdfCloudTripleStoreUtils.CustomEntry<org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range>(entry.getKey(), new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())));
}
Aggregations