Search in sources :

Example 1 with RyaSecondaryIndexer

use of org.apache.rya.api.persist.index.RyaSecondaryIndexer in project incubator-rya by apache.

the class MongoDBRyaDAO method add.

@Override
public void add(final Iterator<RyaStatement> statementIter) throws RyaDAOException {
    final List<DBObject> dbInserts = new ArrayList<>();
    while (statementIter.hasNext()) {
        final RyaStatement ryaStatement = statementIter.next();
        final boolean canAdd = DocumentVisibilityUtil.doesUserHaveDocumentAccess(auths, ryaStatement.getColumnVisibility());
        if (canAdd) {
            final DBObject insert = storageStrategy.serialize(ryaStatement);
            dbInserts.add(insert);
            try {
                for (final RyaSecondaryIndexer index : secondaryIndexers) {
                    index.storeStatement(ryaStatement);
                }
            } catch (final IOException e) {
                log.error("Failed to add: " + ryaStatement.toString() + " to the indexer");
            }
        } else {
            throw new RyaDAOException("User does not have the required authorizations to add statement");
        }
    }
    try {
        mongoDbBatchWriter.addObjectsToQueue(dbInserts);
        if (flushEachUpdate.get()) {
            flush();
        }
    } catch (final MongoDbBatchWriterException e) {
        throw new RyaDAOException("Error adding statements", e);
    }
}
Also used : ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) IOException(java.io.IOException) DBObject(com.mongodb.DBObject) RyaSecondaryIndexer(org.apache.rya.api.persist.index.RyaSecondaryIndexer) MongoDbBatchWriterException(org.apache.rya.mongodb.batch.MongoDbBatchWriterException)

Example 2 with RyaSecondaryIndexer

use of org.apache.rya.api.persist.index.RyaSecondaryIndexer in project incubator-rya by apache.

the class MongoDBRyaDAO method delete.

@Override
public void delete(final Iterator<RyaStatement> statements, final StatefulMongoDBRdfConfiguration conf) throws RyaDAOException {
    while (statements.hasNext()) {
        final RyaStatement ryaStatement = statements.next();
        final boolean canDelete = DocumentVisibilityUtil.doesUserHaveDocumentAccess(auths, ryaStatement.getColumnVisibility());
        if (canDelete) {
            coll.remove(storageStrategy.getQuery(ryaStatement));
            for (final RyaSecondaryIndexer index : secondaryIndexers) {
                try {
                    index.deleteStatement(ryaStatement);
                } catch (final IOException e) {
                    log.error("Unable to remove statement: " + ryaStatement.toString() + " from secondary indexer: " + index.getTableName(), e);
                }
            }
        } else {
            throw new RyaDAOException("User does not have the required authorizations to delete statement");
        }
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) IOException(java.io.IOException) RyaSecondaryIndexer(org.apache.rya.api.persist.index.RyaSecondaryIndexer)

Example 3 with RyaSecondaryIndexer

use of org.apache.rya.api.persist.index.RyaSecondaryIndexer in project incubator-rya by apache.

the class MongoDBRyaDAO method delete.

@Override
public void delete(final RyaStatement statement, final StatefulMongoDBRdfConfiguration conf) throws RyaDAOException {
    final boolean canDelete = DocumentVisibilityUtil.doesUserHaveDocumentAccess(auths, statement.getColumnVisibility());
    if (canDelete) {
        final DBObject obj = storageStrategy.getQuery(statement);
        coll.remove(obj);
        for (final RyaSecondaryIndexer index : secondaryIndexers) {
            try {
                index.deleteStatement(statement);
            } catch (final IOException e) {
                log.error("Unable to remove statement: " + statement.toString() + " from secondary indexer: " + index.getTableName(), e);
            }
        }
    } else {
        throw new RyaDAOException("User does not have the required authorizations to delete statement");
    }
}
Also used : RyaDAOException(org.apache.rya.api.persist.RyaDAOException) IOException(java.io.IOException) DBObject(com.mongodb.DBObject) RyaSecondaryIndexer(org.apache.rya.api.persist.index.RyaSecondaryIndexer)

Aggregations

IOException (java.io.IOException)3 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)3 RyaSecondaryIndexer (org.apache.rya.api.persist.index.RyaSecondaryIndexer)3 DBObject (com.mongodb.DBObject)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 ArrayList (java.util.ArrayList)1 MongoDbBatchWriterException (org.apache.rya.mongodb.batch.MongoDbBatchWriterException)1