Search in sources :

Example 1 with EntityStorage

use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.

the class MongoEntityIndexIT method ensureInEntityStore_Test.

@Test
public void ensureInEntityStore_Test() throws Exception {
    final Sail sail = RyaSailFactory.getInstance(conf);
    SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    conn.begin();
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        setupTypes(indexer);
        addStatements(conn);
        final EntityStorage entities = indexer.getEntityStorage();
        final RyaURI subject = new RyaURI("urn:alice");
        final Optional<Entity> alice = entities.get(subject);
        assertTrue(alice.isPresent());
    } finally {
        conn.close();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoEntityIndexer(org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) Test(org.junit.Test)

Example 2 with EntityStorage

use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.

the class EntityQueryNodeIT method evaluate_constantObject.

@Test
public void evaluate_constantObject() throws Exception {
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), "testDB");
    final ValueFactory vf = ValueFactoryImpl.getInstance();
    final RyaURI subject = new RyaURI("urn:SSN:111-11-1111");
    final Entity entity = Entity.builder().setSubject(subject).setExplicitType(PERSON_TYPE.getId()).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:age"), RdfToRyaConversions.convertLiteral(vf.createLiteral(20)))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:eye"), RdfToRyaConversions.convertLiteral(vf.createLiteral("blue")))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:name"), RdfToRyaConversions.convertLiteral(vf.createLiteral("Bob")))).build();
    storage.create(entity);
    // A set of patterns that match a sepecific Entity subject.
    final List<StatementPattern> patterns = getSPs("SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> \"blue\" . " + "<urn:SSN:111-11-1111> <urn:name> ?name . " + "}");
    final EntityQueryNode node = new EntityQueryNode(PERSON_TYPE, patterns, storage);
    final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet());
    final MapBindingSet expected = new MapBindingSet();
    expected.addBinding("age", vf.createLiteral("20"));
    expected.addBinding("-const-blue", vf.createLiteral("blue"));
    expected.addBinding("name", vf.createLiteral("Bob"));
    while (rez.hasNext()) {
        assertEquals(expected, rez.next());
        break;
    }
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) 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) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 3 with EntityStorage

use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.

the class MongoEntityStorageIT method search_byDataType.

@Test
public void search_byDataType() throws Exception {
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    // The Type we will search by.
    final Type icecreamType = new Type(new RyaURI("urn:icecream"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:brand")).add(new RyaURI("urn:flavor")).add(new RyaURI("urn:cost")).build());
    // Some Person typed entities.
    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();
    // Some Icecream typed objects.
    final Entity chocolateIcecream = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    final Entity vanillaIcecream = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/22356325213432")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Vanilla"))).build();
    final Entity strawberryIcecream = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/77544325436721")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Strawberry"))).build();
    // Create the objects in the storage.
    storage.create(alice);
    storage.create(bob);
    storage.create(chocolateIcecream);
    storage.create(vanillaIcecream);
    storage.create(strawberryIcecream);
    // Search for all icecreams.
    final Set<TypedEntity> objects = new HashSet<>();
    try (final ConvertingCursor<TypedEntity> it = storage.search(Optional.empty(), icecreamType, new HashSet<>())) {
        while (it.hasNext()) {
            objects.add(it.next());
        }
    }
    // Verify the expected results were returned.
    final Set<TypedEntity> expected = Sets.newHashSet(chocolateIcecream.makeTypedEntity(new RyaURI("urn:icecream")).get(), vanillaIcecream.makeTypedEntity(new RyaURI("urn:icecream")).get());
    assertEquals(expected, objects);
}
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 4 with EntityStorage

use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.

the class MongoEntityStorageIT method create_and_get.

@Test
public void create_and_get() throws Exception {
    // An Entity that will be stored.
    final Entity entity = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    // Create it.
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(entity);
    // Get it.
    final Optional<Entity> storedEntity = storage.get(new RyaURI("urn:GTIN-14/00012345600012"));
    // Verify the correct value was returned.
    assertEquals(entity, storedEntity.get());
}
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) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 5 with EntityStorage

use of org.apache.rya.indexing.entity.storage.EntityStorage in project incubator-rya by apache.

the class MongoEntityStorageIT method can_not_create_with_same_subject.

@Test
public void can_not_create_with_same_subject() throws Exception {
    // A Type that will be stored.
    final Entity entity = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    // Create it.
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(entity);
    // Try to create it again. This will fail.
    boolean failed = false;
    try {
        storage.create(entity);
    } catch (final EntityAlreadyExistsException e) {
        failed = true;
    }
    assertTrue(failed);
}
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) EntityAlreadyExistsException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityAlreadyExistsException) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) 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