Search in sources :

Example 56 with RyaDAOException

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

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

the class MongoDBRyaDAO method destroy.

@Override
public void destroy() throws RyaDAOException {
    if (!isInitialized.get()) {
        return;
    }
    isInitialized.set(false);
    flush();
    try {
        mongoDbBatchWriter.shutdown();
    } catch (final MongoDbBatchWriterException e) {
        throw new RyaDAOException("Error shutting down MongoDB batch writer", e);
    }
    for (final MongoSecondaryIndex indexer : secondaryIndexers) {
        try {
            indexer.close();
        } catch (final IOException e) {
            log.error("Error closing indexer: " + indexer.getClass().getSimpleName(), e);
        }
    }
    IOUtils.closeQuietly(queryEngine);
}
Also used : RyaDAOException(org.apache.rya.api.persist.RyaDAOException) IOException(java.io.IOException) MongoDbBatchWriterException(org.apache.rya.mongodb.batch.MongoDbBatchWriterException)

Example 58 with RyaDAOException

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

the class MongoDBRyaDAO method flush.

@Override
public void flush() throws RyaDAOException {
    try {
        mongoDbBatchWriter.flush();
        flushIndexers();
    } catch (final MongoDbBatchWriterException e) {
        throw new RyaDAOException("Error flushing data.", e);
    }
}
Also used : RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MongoDbBatchWriterException(org.apache.rya.mongodb.batch.MongoDbBatchWriterException)

Example 59 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException 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 60 with RyaDAOException

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

the class AccumuloRyaStatementStore method findStatement.

public RyaStatement findStatement(final RyaStatement ryaStatement) throws RyaDAOException {
    RyaStatement resultRyaStatement = null;
    CloseableIteration<RyaStatement, RyaDAOException> iter = null;
    try {
        iter = accumuloRyaDao.getQueryEngine().query(ryaStatement, accumuloRyaDao.getConf());
        if (iter.hasNext()) {
            resultRyaStatement = iter.next();
        }
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return resultRyaStatement;
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException)

Aggregations

RyaDAOException (org.apache.rya.api.persist.RyaDAOException)100 RyaStatement (org.apache.rya.api.domain.RyaStatement)61 RyaURI (org.apache.rya.api.domain.RyaURI)45 Test (org.junit.Test)39 RyaType (org.apache.rya.api.domain.RyaType)28 IOException (java.io.IOException)26 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)23 AccumuloException (org.apache.accumulo.core.client.AccumuloException)22 SailException (org.openrdf.sail.SailException)15 HashSet (java.util.HashSet)12 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)12 RdfCloudTripleStoreUtils (org.apache.rya.api.RdfCloudTripleStoreUtils)12 Map (java.util.Map)11 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 RyaClientException (org.apache.rya.api.client.RyaClientException)11 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)10 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)8 Text (org.apache.hadoop.io.Text)8