Search in sources :

Example 16 with EntityStorage

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());
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) Test(org.junit.Test)

Example 17 with EntityStorage

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) Test(org.junit.Test)

Example 18 with EntityStorage

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()));
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaType(org.apache.rya.api.domain.RyaType) Type(org.apache.rya.indexing.entity.model.Type) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with EntityStorage

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);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 20 with EntityStorage

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);
    }
}
Also used : MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Aggregations

EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)24 Entity (org.apache.rya.indexing.entity.model.Entity)23 RyaURI (org.apache.rya.api.domain.RyaURI)22 Test (org.junit.Test)22 Property (org.apache.rya.indexing.entity.model.Property)18 RyaType (org.apache.rya.api.domain.RyaType)16 MongoEntityStorage (org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage)11 TypeStorage (org.apache.rya.indexing.entity.storage.TypeStorage)10 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)9 MongoTypeStorage (org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage)8 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 Type (org.apache.rya.indexing.entity.model.Type)5 ValueFactory (org.openrdf.model.ValueFactory)3 BindingSet (org.openrdf.query.BindingSet)3 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)3 StatementPattern (org.openrdf.query.algebra.StatementPattern)3 MapBindingSet (org.openrdf.query.impl.MapBindingSet)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 Date (java.util.Date)2