Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.mongodb.DBObject;
import com.mongodb.DuplicateKeyException;
import com.mongodb.MongoClient;
import com.mongodb.BulkWriteOperation;

/**
* Default DAO for mongo backed RYA allowing for CRUD operations.
Expand Down Expand Up @@ -240,6 +241,15 @@ public void delete(final RyaStatement statement, final StatefulMongoDBRdfConfigu
public void dropGraph(final StatefulMongoDBRdfConfiguration conf, final RyaIRI... graphs)
throws RyaDAOException {

RyaStatement statement = new RyaStatement();
BulkWriteOperation bulkDelete = coll.initializeUnorderedBulkOperation();

for (final RyaIRI graph : graphs){
statement.setContext(graph);
bulkDelete.find(storageStrategy.getQuery(statement)).remove();
}

bulkDelete.execute();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,49 @@ public void testDelete() throws RyaDAOException, MongoException, IOException {
}
}

@Test
public void testDrop() throws RyaDAOException, MongoException, IOException {
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

dao.setConf(conf);
dao.init();

RyaIRI contexts[] = new RyaIRI[3];
contexts[0] = new RyaIRI("http://context1.com");
contexts[1] = new RyaIRI("http://context2.com");
contexts[2] = new RyaIRI("http://context3.com");

RyaIRI subjects[] = new RyaIRI[2];
subjects[0] = new RyaIRI("http://subject1.com");
subjects[1] = new RyaIRI("http://subject2.com");

final RyaStatementBuilder builder = new RyaStatementBuilder();

for(RyaIRI context : contexts)
{
for(RyaIRI subject : subjects)
{
builder.setPredicate(new RyaIRI("http://temp.com"));
builder.setSubject(subject);
builder.setObject(new RyaIRI("http://object.com"));
builder.setContext(context);
builder.setColumnVisibility(new DocumentVisibility("C").flatten());
dao.add(builder.build());
}
}

assertEquals(6, coll.count());

dao.dropGraph(conf, contexts[0], contexts[1]);
assertEquals(2, coll.count());
} finally {
dao.destroy();
}
}

@Test
public void testDeleteWildcardSubjectWithContext() throws RyaDAOException, MongoException, IOException {
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
Expand Down