use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class RyaDAOHelper method query.
public static CloseableIteration<? extends Map.Entry<Statement, BindingSet>, QueryEvaluationException> query(RyaDAO ryaDAO, Collection<Map.Entry<Statement, BindingSet>> statements, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException {
Collection<Map.Entry<RyaStatement, BindingSet>> ryaStatements = new ArrayList<Map.Entry<RyaStatement, BindingSet>>(statements.size());
for (Map.Entry<Statement, BindingSet> entry : statements) {
ryaStatements.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>(RdfToRyaConversions.convertStatement(entry.getKey()), entry.getValue()));
}
final CloseableIteration<? extends Map.Entry<RyaStatement, BindingSet>, RyaDAOException> query;
try {
query = ryaDAO.getQueryEngine().queryWithBindingSet(ryaStatements, conf);
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
return new // TODO: Create a new class struct for this
CloseableIteration<Map.Entry<Statement, BindingSet>, QueryEvaluationException>() {
private boolean isClosed = false;
@Override
public void close() throws QueryEvaluationException {
isClosed = true;
try {
query.close();
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
@Override
public boolean hasNext() throws QueryEvaluationException {
try {
return query.hasNext();
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
@Override
public Map.Entry<Statement, BindingSet> next() throws QueryEvaluationException {
if (!hasNext() || isClosed) {
throw new NoSuchElementException();
}
try {
Map.Entry<RyaStatement, BindingSet> next = query.next();
if (next == null) {
return null;
}
return new RdfCloudTripleStoreUtils.CustomEntry<Statement, BindingSet>(RyaToRdfConversions.convertStatement(next.getKey()), next.getValue());
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
@Override
public void remove() throws QueryEvaluationException {
try {
query.remove();
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
};
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class RyaDAOHelper method query.
public static CloseableIteration<Statement, QueryEvaluationException> query(RyaDAO ryaDAO, Statement stmt, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException {
final CloseableIteration<RyaStatement, RyaDAOException> query;
try {
query = ryaDAO.getQueryEngine().query(RdfToRyaConversions.convertStatement(stmt), conf);
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
// TODO: only support one context for now
return new // TODO: Create a new class struct for this
CloseableIteration<Statement, QueryEvaluationException>() {
private boolean isClosed = false;
@Override
public void close() throws QueryEvaluationException {
try {
isClosed = true;
query.close();
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
@Override
public boolean hasNext() throws QueryEvaluationException {
try {
return query.hasNext();
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
@Override
public Statement next() throws QueryEvaluationException {
if (!hasNext() || isClosed) {
throw new NoSuchElementException();
}
try {
RyaStatement next = query.next();
if (next == null) {
return null;
}
return RyaToRdfConversions.convertStatement(next);
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
@Override
public void remove() throws QueryEvaluationException {
try {
query.remove();
} catch (RyaDAOException e) {
throw new QueryEvaluationException(e);
}
}
};
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class HashJoin method join.
@Override
public CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) throws RyaDAOException {
ConcurrentHashMap<RyaURI, Integer> ht = new ConcurrentHashMap<RyaURI, Integer>();
int count = 0;
boolean first = true;
for (Map.Entry<RyaURI, RyaType> predObj : predObjs) {
count++;
RyaURI pred = predObj.getKey();
RyaType obj = predObj.getValue();
// query
CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, obj), null);
// add to hashtable
while (results.hasNext()) {
RyaURI subject = results.next().getSubject();
if (!first) {
if (!ht.containsKey(subject)) {
// not in join
continue;
}
}
ht.put(subject, count);
}
// remove from hashtable values that are under count
if (first) {
first = false;
} else {
for (Map.Entry<RyaURI, Integer> entry : ht.entrySet()) {
if (entry.getValue() < count) {
ht.remove(entry.getKey());
}
}
}
}
return new EnumerationWrapper<RyaURI, RyaDAOException>(ht.keys());
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class HashJoin method join.
@Override
public CloseableIteration<RyaStatement, RyaDAOException> join(C conf, RyaURI... preds) throws RyaDAOException {
ConcurrentHashMap<Map.Entry<RyaURI, RyaType>, Integer> ht = new ConcurrentHashMap<Map.Entry<RyaURI, RyaType>, Integer>();
int count = 0;
boolean first = true;
for (RyaURI pred : preds) {
count++;
// query
CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, null), null);
// add to hashtable
while (results.hasNext()) {
RyaStatement next = results.next();
RyaURI subject = next.getSubject();
RyaType object = next.getObject();
Map.Entry<RyaURI, RyaType> entry = new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(subject, object);
if (!first) {
if (!ht.containsKey(entry)) {
// not in join
continue;
}
}
ht.put(entry, count);
}
// remove from hashtable values that are under count
if (first) {
first = false;
} else {
for (Map.Entry<Map.Entry<RyaURI, RyaType>, Integer> entry : ht.entrySet()) {
if (entry.getValue() < count) {
ht.remove(entry.getKey());
}
}
}
}
final Enumeration<Map.Entry<RyaURI, RyaType>> keys = ht.keys();
return new CloseableIteration<RyaStatement, RyaDAOException>() {
@Override
public void close() throws RyaDAOException {
}
@Override
public boolean hasNext() throws RyaDAOException {
return keys.hasMoreElements();
}
@Override
public RyaStatement next() throws RyaDAOException {
Map.Entry<RyaURI, RyaType> subjObj = keys.nextElement();
return new RyaStatement(subjObj.getKey(), null, subjObj.getValue());
}
@Override
public void remove() throws RyaDAOException {
keys.nextElement();
}
};
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class AccumuloRyaStatementStore method addStatement.
@Override
public void addStatement(final RyaStatement statement) throws AddStatementException {
try {
accumuloRyaDao.add(statement);
accumuloRyaDao.flush();
// RYA-197 is the ticket for fixing this hack.
if (!containsStatement(statement)) {
statement.setTimestamp(statement.getTimestamp() + 1L);
accumuloRyaDao.add(statement);
}
} catch (final RyaDAOException | ContainsStatementException e) {
throw new AddStatementException("Unable to add the Rya Statement", e);
}
}
Aggregations