/** * Remove a prefix-to-namespace mapping from the Sail connection of this graph. * * @param prefix the prefix of the prefix-to-namespace mapping to remove */ public void removeNamespace(final String prefix) { try { this.sailConnection.get().removeNamespace(prefix); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Add a prefix-to-namespace mapping to the Sail connection of this graph. * * @param prefix the prefix (e.g. tg) * @param namespace the namespace (e.g. http://tinkerpop.com#) */ public void addNamespace(final String prefix, final String namespace) { try { this.sailConnection.get().setNamespace(prefix, namespace); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
public void rollback() { try { SailConnection sc = this.sailConnection.get(); sc.rollback(); sc.begin(); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Construct a new SailGraph with an uninitialized Sail. * * @param sail a not-yet-initialized Sail instance */ public SailGraph(final Sail sail) { try { PropertyConfigurator.configure(SailGraph.class.getResource(LOG4J_PROPERTIES)); } catch (Throwable e) { LOGGER.warning("failed to configure Log4j: " + e.getMessage()); } try { this.rawGraph = sail; sail.initialize(); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Given a URI, expand it to its full URI. * * @param uri the compressed URI (e.g. tg:knows) * @return the expanded URI (e.g. http://tinkerpop.com#knows) */ public String expandPrefix(String uri) { try { if (uri.contains(SailTokens.NAMESPACE_SEPARATOR)) { String namespace = this.sailConnection.get().getNamespace(uri.substring(0, uri.indexOf(SailTokens.NAMESPACE_SEPARATOR))); if (null != namespace) uri = namespace + uri.substring(uri.indexOf(SailTokens.NAMESPACE_SEPARATOR) + 1); } } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } return uri; }
public SailEdgeIterator() { try { this.statements = graph.getSailConnection().get().getStatements(subject, predicate, object, false); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
public void commit() { try { SailConnection sc = this.sailConnection.get(); sc.commit(); sc.begin(); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
public Edge next() { try { return new SailEdge(this.statements.next(), graph); } catch (SailException e) { throw new RuntimeException(e.getMessage()); } catch (NoSuchElementException e) { try { this.statements.close(); } catch (SailException e2) { throw new RuntimeException(e2.getMessage(), e2); } throw e; } } }
/** * Remove the version with the given ID from the triple store. Calling this service will only remove the versioning * metadata, not the triples themselves. Triples that are marked as deleted and no longer attached to a version will * be cleaned up by a garbage collection process that is running periodically or can be triggered manually. * * @param id * @return */ @DELETE @Path("/versions/{id:[0-9]+}") public Response deleteVersion(@PathParam("id") Long id) { try { Version version = versioningService.getVersion(id); if(version != null) { versioningService.removeVersion(id); return Response.ok().entity("success").build(); } else { return Response.status(Response.Status.NOT_FOUND).entity("version with id "+id+" does not exist").build(); } } catch (SailException e) { return Response.serverError().entity("error deleting version "+id+": "+e.getMessage()).build(); } }
public boolean hasNext() { try { if (this.statements.hasNext()) return true; else { this.statements.close(); return false; } } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Get all the prefix-to-namespace mappings of the graph. * * @return a map of the prefix-to-namespace mappings */ public Map<String, String> getNamespaces() { Map<String, String> namespaces = new HashMap<String, String>(); try { final CloseableIteration<? extends Namespace, SailException> results = this.sailConnection.get().getNamespaces(); while (results.hasNext()) { Namespace namespace = results.next(); namespaces.put(namespace.getPrefix(), namespace.getName()); } results.close(); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } return namespaces; }
/** * Given a URI, compress it to its prefixed URI. * * @param uri the expanded URI (e.g. http://tinkerpop.com#knows) * @return the prefixed URI (e.g. tg:knows) */ public String prefixNamespace(String uri) { try { CloseableIteration<? extends Namespace, SailException> namespaces = this.sailConnection.get().getNamespaces(); while (namespaces.hasNext()) { Namespace namespace = namespaces.next(); if (uri.contains(namespace.getName())) uri = uri.replace(namespace.getName(), namespace.getPrefix() + SailTokens.NAMESPACE_SEPARATOR); } namespaces.close(); } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } return uri; }
private void updateLiteral(final Literal oldLiteral, final Literal newLiteral) { try { final Set<Statement> statements = new HashSet<Statement>(); final CloseableIteration<? extends Statement, SailException> results = this.graph.getSailConnection().get().getStatements(null, null, oldLiteral, false); while (results.hasNext()) { statements.add(results.next()); } results.close(); this.graph.getSailConnection().get().removeStatements(null, null, oldLiteral); for (Statement statement : statements) { SailHelper.addStatement(statement.getSubject(), statement.getPredicate(), newLiteral, statement.getContext(), this.graph.getSailConnection().get()); } } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
@Test public void testClose() { try { con.close(); con.addStatement(painter, RDF.TYPE, RDFS.CLASS); fail("Operation on connection after close should result in IllegalStateException"); } catch (IllegalStateException e) { // do nothing, this is expected } catch (SailException e) { fail(e.getMessage()); } }
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); try { CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter; SailConnection sailCon = getSailConnection(); bindingsIter = sailCon.evaluate(tupleExpr, getActiveDataset(), getBindings(), getIncludeInferred()); bindingsIter = enforceMaxQueryTime(bindingsIter); return new TupleQueryResultImpl(new ArrayList<String>(tupleExpr.getBindingNames()), bindingsIter); } catch (SailException e) { throw new QueryEvaluationException(e.getMessage(), e); } }
protected static void removeStatement(final Statement statement, final SailConnection sailConnection) { try { if (null != statement.getContext()) { sailConnection.removeStatements(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext()); } else { sailConnection.removeStatements(statement.getSubject(), statement.getPredicate(), statement.getObject()); } } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
protected static void addStatement(final Statement statement, final SailConnection sailConnection) { try { if (null != statement.getContext()) { sailConnection.addStatement(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext()); } else { sailConnection.addStatement(statement.getSubject(), statement.getPredicate(), statement.getObject()); } } catch (SailException e) { throw new RuntimeException(e.getMessage(), e); } }
@Override protected void initializeInternal() throws RepositoryException { try { sail.initialize(); } catch (SailLockedException e) { String l = e.getLockedBy(); String r = e.getRequestedBy(); String m = e.getMessage(); throw new RepositoryLockedException(l, r, m, e); } catch (SailException e) { throw new RepositoryException(e.getMessage(), e); } }
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); try { CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter; SailConnection sailCon = getConnection().getSailConnection(); bindingsIter = sailCon.evaluate(tupleExpr, getActiveDataset(), getBindings(), getIncludeInferred()); bindingsIter = enforceMaxQueryTime(bindingsIter); return new IteratingTupleQueryResult(new ArrayList<String>(tupleExpr.getBindingNames()), bindingsIter); } catch (SailException e) { throw new QueryEvaluationException(e.getMessage(), e); } }
@Test public void testClose() { try { con.close(); con.addStatement(painter, RDF.TYPE, RDFS.CLASS); fail("Operation on connection after close should result in IllegalStateException"); } catch (IllegalStateException e) { // do nothing, this is expected } catch (SailException e) { fail(e.getMessage()); } }