Search in sources :

Example 6 with RyaStatementBuilder

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

the class MongoDBRyaDAO2IT method testDelete.

@Test
public void testDelete() throws RyaDAOException, MongoException, 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"));
        final RyaStatement statement = builder.build();
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(statement);
        assertEquals(coll.count(), 1);
        dao.delete(statement, conf);
        assertEquals(coll.count(), 0);
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaStatement(org.apache.rya.api.domain.RyaStatement) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 7 with RyaStatementBuilder

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

the class MongoDBRyaDAO2IT method testAdd.

@Test
public void testAdd() throws RyaDAOException, MongoException, 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"));
        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);
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 8 with RyaStatementBuilder

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

the class ITBase method makeRyaStatement.

/**
 * A helper function for creating a {@link RyaStatement} that represents a
 * Triple.
 *
 * @param subject
 *            - The Subject of the Triple. (not null)
 * @param predicate
 *            - The Predicate of the Triple. (not null)
 * @param object
 *            - The Object of the Triple. (not null)
 * @return A Triple as a {@link RyaStatement}.
 */
protected static RyaStatement makeRyaStatement(final String subject, final String predicate, final String object) {
    checkNotNull(subject);
    checkNotNull(predicate);
    checkNotNull(object);
    final RyaStatementBuilder builder = RyaStatement.builder().setSubject(new RyaURI(subject)).setPredicate(new RyaURI(predicate));
    if (object.startsWith("http://")) {
        builder.setObject(new RyaURI(object));
    } else {
        builder.setObject(new RyaType(object));
    }
    builder.setTimestamp(new Date().getTime());
    return builder.build();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaType(org.apache.rya.api.domain.RyaType) Date(java.util.Date)

Example 9 with RyaStatementBuilder

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

the class MongoDBRyaDAO2IT method testDeleteWildcardSubjectWithContext.

@Test
public void testDeleteWildcardSubjectWithContext() throws RyaDAOException, MongoException, 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.setContext(new RyaURI("http://context.com"));
        final RyaStatement statement = builder.build();
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(statement);
        assertEquals(coll.count(), 1);
        final RyaStatementBuilder builder2 = new RyaStatementBuilder();
        builder2.setPredicate(new RyaURI("http://temp.com"));
        builder2.setObject(new RyaURI("http://object.com"));
        builder2.setContext(new RyaURI("http://context3.com"));
        final RyaStatement query = builder2.build();
        dao.delete(query, conf);
        assertEquals(coll.count(), 1);
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaStatement(org.apache.rya.api.domain.RyaStatement) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 10 with RyaStatementBuilder

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

the class MongoDBRyaDAO2IT method testDeleteWildcard.

@Test
public void testDeleteWildcard() throws RyaDAOException {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        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) Test(org.junit.Test)

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