Search in sources :

Example 11 with Entity

use of org.apache.rya.indexing.entity.model.Entity 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 12 with Entity

use of org.apache.rya.indexing.entity.model.Entity 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)

Example 13 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityStorageIT method update_stale.

@Test(expected = StaleUpdateException.class)
public void update_stale() 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.
    final Optional<Entity> latest = storage.get(new RyaURI("urn:SSN/111-11-1111"));
    assertEquals(alice, latest.get());
    // Create the wrong old state and try to change Alice's eye color to brown.
    final Entity wrongOld = Entity.builder(alice).setVersion(500).build();
    final Entity updated = Entity.builder(alice).setVersion(501).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "brown"))).build();
    storage.update(wrongOld, updated);
}
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 14 with Entity

use of org.apache.rya.indexing.entity.model.Entity in project incubator-rya by apache.

the class MongoEntityStorageIT method delete.

@Test
public void delete() 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);
    // Delete it.
    final boolean deleted = storage.delete(new RyaURI("urn:GTIN-14/00012345600012"));
    // Verify a document was deleted.
    assertTrue(deleted);
}
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 15 with Entity

use of org.apache.rya.indexing.entity.model.Entity 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());
}
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)

Aggregations

Entity (org.apache.rya.indexing.entity.model.Entity)40 RyaURI (org.apache.rya.api.domain.RyaURI)31 Test (org.junit.Test)29 Property (org.apache.rya.indexing.entity.model.Property)24 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)23 RyaType (org.apache.rya.api.domain.RyaType)22 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)13 TypeStorage (org.apache.rya.indexing.entity.storage.TypeStorage)11 MongoEntityStorage (org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage)11 ReflectionToStringBuilder (org.apache.commons.lang.builder.ReflectionToStringBuilder)8 Builder (org.apache.rya.indexing.entity.model.Entity.Builder)8 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)6 URI (org.openrdf.model.URI)4 URIImpl (org.openrdf.model.impl.URIImpl)4 RyaTypeUtils.booleanRyaType (org.apache.rya.api.domain.RyaTypeUtils.booleanRyaType)3 RyaTypeUtils.byteRyaType (org.apache.rya.api.domain.RyaTypeUtils.byteRyaType)3 RyaTypeUtils.dateRyaType (org.apache.rya.api.domain.RyaTypeUtils.dateRyaType)3 RyaTypeUtils.doubleRyaType (org.apache.rya.api.domain.RyaTypeUtils.doubleRyaType)3