Search in sources :

Example 11 with RyaStatementBuilder

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

the class MongoDBRyaDAO2IT method testReconstructDao.

@Test
public void testReconstructDao() throws RyaDAOException, IOException {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        builder.setSubject(new RyaURI("http://subject.com"));
        builder.setObject(new RyaURI("http://object.com"));
        builder.setColumnVisibility(new DocumentVisibility("B").flatten());
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(builder.build());
        assertEquals(coll.count(), 1);
        final Document dbo = coll.find().first();
        assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
        assertTrue(dbo.containsKey(TIMESTAMP));
    } finally {
        dao.destroy();
    }
    // Test reinitializing the same instance
    try {
        dao.init();
    } finally {
        dao.destroy();
    }
    // Reconstruct new DAO and try again
    dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        builder.setSubject(new RyaURI("http://subject.com"));
        builder.setObject(new RyaURI("http://object.com"));
        builder.setColumnVisibility(new DocumentVisibility("B").flatten());
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(builder.build());
        assertEquals(coll.count(), 1);
        final Document dbo = coll.find().first();
        assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
        assertTrue(dbo.containsKey(TIMESTAMP));
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 12 with RyaStatementBuilder

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

the class MongoDBRyaBatchWriterIT method statement.

private static RyaStatement statement(final int v) {
    final RyaStatementBuilder builder = new RyaStatementBuilder();
    builder.setPredicate(ryaURI(v));
    builder.setSubject(ryaURI(v));
    builder.setObject(ryaURI(v));
    return builder.build();
}
Also used : RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder)

Example 13 with RyaStatementBuilder

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

the class MongoDBRyaDAOIT method testDeleteWildcard.

@Test
public void testDeleteWildcard() throws RyaDAOException {
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        builder.setColumnVisibility(new DocumentVisibility("A").flatten());
        dao.delete(builder.build(), conf);
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 14 with RyaStatementBuilder

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

the class PipelineQueryIT method insert.

private void insert(Resource subject, URI predicate, Value object, int derivationLevel) throws RyaDAOException {
    final RyaStatementBuilder builder = new RyaStatementBuilder();
    builder.setSubject(RdfToRyaConversions.convertResource(subject));
    builder.setPredicate(RdfToRyaConversions.convertURI(predicate));
    builder.setObject(RdfToRyaConversions.convertValue(object));
    final RyaStatement rstmt = builder.build();
    if (derivationLevel > 0) {
        DBObject obj = new SimpleMongoDBStorageStrategy().serialize(builder.build());
        obj.put("derivation_level", derivationLevel);
        getRyaDbCollection().insert(obj);
    } else {
        dao.add(rstmt);
    }
}
Also used : RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaStatement(org.apache.rya.api.domain.RyaStatement) DBObject(com.mongodb.DBObject) SimpleMongoDBStorageStrategy(org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy)

Aggregations

RyaStatementBuilder (org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder)14 RyaURI (org.apache.rya.api.domain.RyaURI)12 Test (org.junit.Test)10 MongoDatabase (com.mongodb.client.MongoDatabase)8 Document (org.bson.Document)8 RyaStatement (org.apache.rya.api.domain.RyaStatement)6 DocumentVisibility (org.apache.rya.mongodb.document.visibility.DocumentVisibility)6 DBObject (com.mongodb.DBObject)1 Date (java.util.Date)1 RyaType (org.apache.rya.api.domain.RyaType)1 SimpleMongoDBStorageStrategy (org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy)1