use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.
the class MongoEntityStorageIT method get_noneExisting.
@Test
public void get_noneExisting() throws Exception {
// Get a Type that hasn't been created.
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
final Optional<Entity> storedEntity = storage.get(new RyaURI("urn:GTIN-14/00012345600012"));
// Verify nothing was returned.
assertFalse(storedEntity.isPresent());
}
use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.
the class MongoEntityStorageIT method delete_nonExisting.
@Test
public void delete_nonExisting() throws Exception {
// Delete an Entity that has not been created.
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
final boolean deleted = storage.delete(new RyaURI("urn:GTIN-14/00012345600012"));
// Verify no document was deleted.
assertFalse(deleted);
}
use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.
the class MongoEntityStorageIT method search_byFields.
@Test
public void search_byFields() throws Exception {
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
// A Type that defines a Person.
final Type personType = new Type(new RyaURI("urn:person"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:name")).add(new RyaURI("urn:age")).add(new RyaURI("urn:eye")).build());
// Some Person typed objects.
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();
final Entity bob = Entity.builder().setSubject(new RyaURI("urn:SSN/222-22-2222")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "57"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
final Entity charlie = Entity.builder().setSubject(new RyaURI("urn:SSN/333-33-3333")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Charlie"))).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();
final Entity david = Entity.builder().setSubject(new RyaURI("urn:SSN/444-44-4444")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "David"))).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, "brown"))).build();
final Entity eve = Entity.builder().setSubject(new RyaURI("urn:SSN/555-55-5555")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Eve"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).build();
final Entity frank = Entity.builder().setSubject(new RyaURI("urn:SSN/666-66-6666")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Frank"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).setProperty(new RyaURI("urn:someOtherType"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).build();
final Entity george = Entity.builder().setSubject(new RyaURI("urn:SSN/777-77-7777")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "George"))).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();
// Create the objects in the storage.
storage.create(alice);
storage.create(bob);
storage.create(charlie);
storage.create(david);
storage.create(eve);
storage.create(frank);
storage.create(george);
// Search for all people who are 30 and have blue eyes.
final Set<TypedEntity> objects = new HashSet<>();
final Set<Property> searchValues = Sets.newHashSet(new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")));
try (final ConvertingCursor<TypedEntity> it = storage.search(Optional.empty(), personType, searchValues)) {
while (it.hasNext()) {
objects.add(it.next());
}
}
// Verify the expected results were returned.
assertEquals(2, objects.size());
assertTrue(objects.contains(alice.makeTypedEntity(new RyaURI("urn:person")).get()));
assertTrue(objects.contains(charlie.makeTypedEntity(new RyaURI("urn:person")).get()));
}
use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.
the class MongoEntityIndexerIT method deleteStatement_deletesType.
@Test
public void deleteStatement_deletesType() throws Exception {
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
// Load the type into the TypeStorage.
final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
types.create(PERSON_TYPE);
types.create(EMPLOYEE_TYPE);
// Index a bunch of RyaStatements.
final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
indexer.storeStatements(Sets.newHashSet(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")), new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")), new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")), new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))));
// Remove the explicit type from Alice.
indexer.deleteStatement(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")));
// Fetch the Entity from storage and ensure it looks correct.
final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
final Entity expected = Entity.builder().setSubject(aliceSSN).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"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(entity.getVersion()).build();
assertEquals(expected, entity);
}
}
use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.
the class MongoEntityIndexerIT method addStatement_manyUpdates.
@Test
public void addStatement_manyUpdates() throws Exception {
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
// Load the types into the TypeStorage.
final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
types.create(PERSON_TYPE);
types.create(EMPLOYEE_TYPE);
// Index a bunch of RyaStatements.
final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")));
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")));
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")));
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")));
// Fetch the Entity from storage and ensure it looks correct.
final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
final Entity expected = Entity.builder().setSubject(aliceSSN).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"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(entity.getVersion()).build();
assertEquals(expected, entity);
}
}
Aggregations