Search in sources :

Example 56 with RyaType

use of org.apache.rya.api.domain.RyaType 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 57 with RyaType

use of org.apache.rya.api.domain.RyaType 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 58 with RyaType

use of org.apache.rya.api.domain.RyaType 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)

Example 59 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class RyaTypeDocumentConverterTest method fromDocument.

@Test
public void fromDocument() throws DocumentConverterException {
    // Convert a document into a RyaType
    final Document document = new Document().append(RyaTypeDocumentConverter.DATA_TYPE, XMLSchema.DOUBLE.toString()).append(RyaTypeDocumentConverter.VALUE, "4.5");
    final RyaType ryaType = new RyaTypeDocumentConverter().fromDocument(document);
    // Show the converted value has the expected structure.
    final RyaType expected = RdfToRyaConversions.convertLiteral(new ValueFactoryImpl().createLiteral(4.5));
    assertEquals(expected, ryaType);
}
Also used : ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Document(org.bson.Document) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 60 with RyaType

use of org.apache.rya.api.domain.RyaType 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();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Tuple(org.apache.pig.data.Tuple)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)178 RyaURI (org.apache.rya.api.domain.RyaURI)146 RyaStatement (org.apache.rya.api.domain.RyaStatement)115 Test (org.junit.Test)109 BindingSet (org.openrdf.query.BindingSet)42 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)42 ArrayList (java.util.ArrayList)35 StatementPattern (org.openrdf.query.algebra.StatementPattern)35 ParsedQuery (org.openrdf.query.parser.ParsedQuery)35 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)35 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)34 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)34 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)28 Property (org.apache.rya.indexing.entity.model.Property)23 URIImpl (org.openrdf.model.impl.URIImpl)23 HashSet (java.util.HashSet)22 Entity (org.apache.rya.indexing.entity.model.Entity)20 Value (org.openrdf.model.Value)19 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19 BatchWriter (org.apache.accumulo.core.client.BatchWriter)18