use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class ClerezzaYard method writeLockGraph.
/**
* @return
* @throws YardException
*/
private Lock writeLockGraph() throws YardException {
if (immutable) {
throw new YardException("Unable modify data in ClerezzaYard '" + getId() + "' because the backing RDF graph '" + yardGraphUri + "' is read-only!");
}
final Lock writeLock;
writeLock = graph.getLock().writeLock();
writeLock.lock();
return writeLock;
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class SesameYard method store.
protected final Iterable<Representation> store(Iterable<Representation> representations, boolean allowCreate) throws IllegalArgumentException, YardException {
RepositoryConnection con = null;
try {
con = repository.getConnection();
con.begin();
ArrayList<Representation> added = new ArrayList<Representation>();
for (Representation representation : representations) {
if (representation != null) {
//reassign
Representation stored = store(con, representation, allowCreate, false);
//to check if the store was successful
if (stored != null) {
added.add(stored);
} else {
//can only be the case if allowCreate==false (update was called)
log.warn(String.format("Unable to update Representation %s in Yard %s because it is not present!", representation.getId(), getId()));
}
}
//ignore null values in the parsed Iterable!
}
con.commit();
return added;
} catch (RepositoryException e) {
throw new YardException("Unable to remove parsed Representations", e);
} catch (IllegalArgumentException e) {
try {
//to avoid Exception logs in case store(..) throws an Exception
//in the case allowCreate and canNotCreateIsError do not allow
//the store operation
con.rollback();
} catch (RepositoryException ignore) {
}
throw e;
} finally {
if (con != null) {
try {
con.close();
} catch (RepositoryException ignore) {
}
}
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class SesameYard method remove.
@Override
public final void remove(Iterable<String> ids) throws IllegalArgumentException, YardException {
if (ids == null) {
throw new IllegalArgumentException("The parsed Iterable over the IDs to remove MUST NOT be NULL!");
}
RepositoryConnection con = null;
try {
con = repository.getConnection();
con.begin();
for (String id : ids) {
if (id != null) {
remove(con, sesameFactory.createURI(id));
}
}
con.commit();
} catch (RepositoryException e) {
throw new YardException("Unable to remove parsed Representations", e);
} finally {
if (con != null) {
try {
con.close();
} catch (RepositoryException ignore) {
}
}
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class SesameYard method findReferences.
@Override
public QueryResultList<String> findReferences(FieldQuery parsedQuery) throws YardException, IllegalArgumentException {
if (parsedQuery == null) {
throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
}
final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
RepositoryConnection con = null;
TupleQueryResult results = null;
try {
con = repository.getConnection();
con.begin();
//execute the query
int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
results = executeSparqlFieldQuery(con, query, limit, false);
//parse the results
List<String> ids = limit > 0 ? new ArrayList<String>(limit) : new ArrayList<String>();
while (results.hasNext()) {
BindingSet result = results.next();
Value value = result.getValue(query.getRootVariableName());
if (value instanceof Resource) {
ids.add(value.stringValue());
}
}
con.commit();
return new QueryResultListImpl<String>(query, ids, String.class);
} catch (RepositoryException e) {
throw new YardException("Unable to execute findReferences query", e);
} catch (QueryEvaluationException e) {
throw new YardException("Unable to execute findReferences query", e);
} finally {
if (results != null) {
//close the result if present
try {
results.close();
} catch (QueryEvaluationException ignore) {
/* ignore */
}
}
if (con != null) {
try {
con.close();
} catch (RepositoryException ignore) {
/* ignore */
}
}
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class SesameYard method isRepresentation.
@Override
public boolean isRepresentation(String id) throws YardException {
if (id == null) {
throw new IllegalArgumentException("The parsed id MUST NOT be NULL!");
}
if (id.isEmpty()) {
throw new IllegalArgumentException("The parsed id MUST NOT be EMPTY!");
}
RepositoryConnection con = null;
try {
con = repository.getConnection();
con.begin();
boolean state = isRepresentation(con, sesameFactory.createURI(id));
con.commit();
return state;
} catch (RepositoryException e) {
throw new YardException("Unable to check for Representation " + id, e);
} finally {
if (con != null) {
try {
con.close();
} catch (RepositoryException ignore) {
}
}
}
}
Aggregations