org.eclipse.rdf4j.repository.RepositoryException Java Examples
The following examples show how to use
org.eclipse.rdf4j.repository.RepositoryException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FedXConnection.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
/** * Remove the specified endpoint from the federation. * * @param e * the endpoint * @param updateStrategy * optional parameter, to determine if strategy is to be updated, default=true */ public void removeEndpoint(Endpoint e, boolean ...updateStrategy) throws RepositoryException { log.info("Removing endpoint " + e.getId() + " from federation ..."); /* check if e is a federation member */ if (!endpoints.contains(e)) throw new FedXRuntimeException("Endpoint " + e.getId() + " is not a member of the current federation."); endpoints.remove(e); endpointManager.removeEndpoint(e); e.shutDown(); if (updateStrategy==null || updateStrategy.length==0 || (updateStrategy.length==1 && updateStrategy[0]==true)) { updateStrategy(); } }
Example #2
Source File: QueryStorage.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Save a query. UNSAFE from an injection point of view. It is the responsibility of the calling code to call * checkAccess() with the full credentials first. * * @param repository the repository the query is associated with * @param queryName the name for the query * @param userName the user saving the query * @param shared whether the query is to be shared with other users * @param queryLanguage the language, SeRQL or SPARQL, of the query * @param queryText the actual query text * @param infer * @param rowsPerPage rows to display per page, may be 0 (all), 10, 50, 100, or 200) * @throws RDF4JException */ public void saveQuery(final HTTPRepository repository, final String queryName, final String userName, final boolean shared, final QueryLanguage queryLanguage, final String queryText, final boolean infer, final int rowsPerPage) throws RDF4JException { if (QueryLanguage.SPARQL != queryLanguage && QueryLanguage.SERQL != queryLanguage) { throw new RepositoryException("May only save SPARQL or SeRQL queries, not" + queryLanguage.toString()); } if (0 != rowsPerPage && 10 != rowsPerPage && 20 != rowsPerPage && 50 != rowsPerPage && 100 != rowsPerPage && 200 != rowsPerPage) { throw new RepositoryException("Illegal value for rows per page: " + rowsPerPage); } this.checkQueryText(queryText); final QueryStringBuilder save = new QueryStringBuilder(SAVE); save.replaceURI(REPOSITORY, repository.getRepositoryURL()); save.replaceURI(QUERY, "urn:uuid:" + UUID.randomUUID()); save.replaceQuote(QUERY_NAME, queryName); this.replaceUpdateFields(save, userName, shared, queryLanguage, queryText, infer, rowsPerPage); updateQueryRepository(save.toString()); }
Example #3
Source File: StatementEditor.java From inception with Apache License 2.0 | 6 votes |
private void actionMakeExplicit(AjaxRequestTarget aTarget) { try { // add the statement as-is to the knowledge base kbService.upsertStatement(kbModel.getObject(), statement.getObject()); // to update the statement in the UI, one could either reload all statements of the // corresponding instance or (much easier) just set the inferred attribute of the // KBStatement to false, so that's what's done here statement.getObject().setInferred(false); aTarget.add(this); send(getPage(), Broadcast.BREADTH, new AjaxStatementChangedEvent(aTarget, statement.getObject())); } catch (RepositoryException e) { error("Unable to make statement explicit " + e.getLocalizedMessage()); LOG.error("Unable to make statement explicit.", e); aTarget.addChildren(getPage(), IFeedback.class); } }
Example #4
Source File: Load.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Add data from a URL or local file. If the dataURL is null, then the datafile will be used. * * @param repository repository * @param baseURI base URI * @param context context (can be null) * @param dataURL url of the data * @param dataFile file containing data * @throws RepositoryException * @throws IOException * @throws RDFParseException */ private void addData(Repository repository, String baseURI, String context, URL dataURL, File dataFile) throws RepositoryException, IOException, RDFParseException { Resource[] contexts = getContexts(repository, context); writeln("Loading data..."); final long startTime = System.nanoTime(); try (RepositoryConnection con = repository.getConnection()) { if (dataURL == null) { con.add(dataFile, baseURI, null, contexts); } else { con.add(dataURL, baseURI, null, contexts); } } final long endTime = System.nanoTime(); writeln("Data has been added to the repository (" + (endTime - startTime) / 1_000_000 + " ms)"); }
Example #5
Source File: SummariesUpdate.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
/** * Update Index regularly on a specific date and time * @param lstEndPoints List of SPARQL endpoints * @param date specific date and time in "dd-MM-yyyy HH:mm:ss" * @param outputFile Output location of index * @param branchLimit Branching limit */ public static void updateIndexAtFixedTime(final List<String> lstEndPoints, Date date, final String outputFile, final int branchLimit) { Timer timer = new Timer(); timer.schedule(new TimerTask() {public void run() { try { TBSSSummariesGenerator generator = new TBSSSummariesGenerator(outputFile); long startTime = System.currentTimeMillis(); generator.generateSummaries(lstEndPoints,null, branchLimit); System.out.println("Index is secessfully updated to "+ outputFile); System.out.println("Data Summaries Generation Time (sec): "+ (System.currentTimeMillis()-startTime)/1000); } catch (IOException | RepositoryException | MalformedQueryException | QueryEvaluationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }, date); }
Example #6
Source File: LocalRepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public RepositoryInfo getRepositoryInfo(String id) { RepositoryConfig config = getRepositoryConfig(id); if (config == null) { return null; } RepositoryInfo repInfo = new RepositoryInfo(); repInfo.setId(config.getID()); repInfo.setDescription(config.getTitle()); try { repInfo.setLocation(getRepositoryDir(config.getID()).toURI().toURL()); } catch (MalformedURLException mue) { throw new RepositoryException("Location of repository does not resolve to a valid URL", mue); } repInfo.setReadable(true); repInfo.setWritable(true); return repInfo; }
Example #7
Source File: Drop.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Try to drop a repository after confirmation from user * * @param repoID repository ID * @throws IOException * @throws RepositoryException * @throws RepositoryConfigException */ private void dropRepository(final String repoID) throws IOException, RepositoryException, RepositoryConfigException { boolean proceed = askProceed("WARNING: you are about to drop repository '" + repoID + "'.", true); if (proceed && !state.getManager().isSafeToRemove(repoID)) { proceed = askProceed("WARNING: dropping this repository may break another that is proxying it.", false); } if (proceed) { if (repoID.equals(state.getRepositoryID())) { close.closeRepository(false); } final boolean isRemoved = state.getManager().removeRepository(repoID); if (isRemoved) { writeInfo("Dropped repository '" + repoID + "'"); } else { writeInfo("Unknown repository '" + repoID + "'"); } } else { writeln("Drop aborted"); } }
Example #8
Source File: SummaryServlet.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void service(TupleResultBuilder builder, String xslPath) throws RepositoryException, QueryEvaluationException, MalformedQueryException, QueryResultHandlerException { builder.transform(xslPath, "summary.xsl"); builder.start("id", "description", "location", "server", "size", "contexts"); builder.link(Arrays.asList(INFO)); try (RepositoryConnection con = repository.getConnection()) { String size = null; String numContexts = null; try { List<Future<String>> futures = getRepositoryStatistics(con); size = getResult("repository size.", futures.get(0)); numContexts = getResult("labeled contexts.", futures.get(1)); } catch (InterruptedException e) { LOGGER.warn("Interrupted while requesting repository statistics.", e); } builder.result(info.getId(), info.getDescription(), info.getLocation(), getServer(), size, numContexts); builder.end(); } }
Example #9
Source File: AbstractLuceneSailTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testQueryWithSpecifiedSubject() throws RepositoryException, MalformedQueryException, QueryEvaluationException { try (RepositoryConnection connection = repository.getConnection()) { // fire a query with the subject pre-specified TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SERQL, QUERY_STRING); query.setBinding("Subject", SUBJECT_1); query.setBinding("Query", vf.createLiteral("one")); TupleQueryResult result = query.evaluate(); // check that this subject and only this subject is returned assertTrue(result.hasNext()); BindingSet bindings = result.next(); assertEquals(SUBJECT_1, (IRI) bindings.getValue("Subject")); assertNotNull(bindings.getValue("Score")); assertFalse(result.hasNext()); } }
Example #10
Source File: AbstractLuceneSailTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testUnionQuery() throws RepositoryException, MalformedQueryException, QueryEvaluationException { String queryStr = ""; queryStr += "PREFIX search: <http://www.openrdf.org/contrib/lucenesail#> "; queryStr += "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "; queryStr += "SELECT DISTINCT ?result { "; queryStr += "{ ?result search:matches ?match1 . "; queryStr += " ?match1 search:query 'one' ; "; queryStr += " search:property <urn:predicate1> . }"; queryStr += " UNION "; queryStr += "{ ?result search:matches ?match2 . "; queryStr += " ?match2 search:query 'one' ; "; queryStr += " search:property <urn:predicate2> . } "; queryStr += "} "; try (RepositoryConnection connection = repository.getConnection()) { // fire a query with the subject pre-specified TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SPARQL, queryStr); query.setBinding("result", SUBJECT_1); try (TupleQueryResult result = query.evaluate()) { // check that this subject and only this subject is returned BindingSet bs = result.next(); assertEquals(SUBJECT_1, bs.getValue("result")); } } }
Example #11
Source File: HTTPRepositoryConnection.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public RepositoryResult<Resource> getContextIDs() throws RepositoryException { try { List<Resource> contextList = new ArrayList<>(); try (TupleQueryResult contextIDs = client.getContextIDs()) { while (contextIDs.hasNext()) { BindingSet bindingSet = contextIDs.next(); Value context = bindingSet.getValue("contextID"); if (context instanceof Resource) { contextList.add((Resource) context); } } } return createRepositoryResult(contextList); } catch (QueryEvaluationException | IOException e) { throw new RepositoryException(e); } }
Example #12
Source File: StatsGenerator.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
public static String getFscores(String queryNo,TupleQueryResult res) throws QueryEvaluationException, RepositoryException, MalformedQueryException { String Fscores = "" ; double precision, recall,F1; Set<String> curResults = getCurrentResult(res) ; //System.out.println("current:"+ curResults); Set<String> actualResults = getActualResults(queryNo) ; //System.out.println("actual:" +actualResults); Set<String> diffSet = Sets.difference(actualResults, curResults); //System.out.println(diffSet); //System.out.println(Sets.difference( curResults,actualResults)); double correctResults = actualResults.size()-diffSet.size(); precision = (correctResults/curResults.size()); recall = correctResults/actualResults.size(); F1 = 2*(precision*recall)/(precision+recall); Fscores = "Precision: "+precision+", Recall: " + recall +", F1: "+F1; return Fscores; }
Example #13
Source File: FedSumGenerator.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
/** * Write all the distinct object authorities having predicate p. * consider <http://www.dbpedia.com/schema/xyz> rdf:type <http://www.dbpedia.com/schema/actor> * we are interested in http://www.dbpedia.com part of object. Note: for rdf:type we store all the classes * @param predicate Predicate * @param endpoint Endpoint URL * * @throws MalformedQueryException * @throws RepositoryException * @throws QueryEvaluationException * @throws IOException */ public void writeObjAuthority(String predicate, String endpoint) throws RepositoryException, MalformedQueryException, QueryEvaluationException, IOException { ArrayList<String> objAuthorities = new ArrayList<String>(); String strQuery = getObjAuthorityQury(predicate); SPARQLRepository repo = new SPARQLRepository(endpoint); TupleQuery query = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, strQuery); TupleQueryResult res = query.evaluate(); while (res.hasNext()) { if (predicate.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")) objAuthorities.add(res.next().getValue("o").toString()); else { String[] objPrts = res.next().getValue("o").toString().split("/"); if ((objPrts.length>1)) { String objAuth =objPrts[0]+"//"+objPrts[2]; if(!objAuthorities.contains(objAuth)) objAuthorities.add(objAuth); } } } repo.getConnection().close(); if(!objAuthorities.isEmpty()) { bw.newLine(); bw.append(" ds:objAuthority "); for(int authority=0; authority<objAuthorities.size();authority++) { String strAuth = objAuthorities.get(authority); if(authority==objAuthorities.size()-1) bw.write("<"+strAuth + "> ; "); else bw.write("<"+ strAuth+ ">, "); } } }
Example #14
Source File: ConnectionManager.java From semagrow with Apache License 2.0 | 5 votes |
public void shutdown() { for (Repository repo : repoMap.values()) { if (repo.isInitialized()) try { repo.shutDown(); } catch (RepositoryException e) { logger.warn("Failed to shutdown repo {}", repo); } } }
Example #15
Source File: PrepareOwnedTupleExpr.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void meetNodeLocalParentNotOwned(StringBuilder builder, boolean mapping, Map<String, String> bindings, ProjectionElemList list) throws RepositoryException, MalformedQueryException { OwnedTupleExpr owned = new OwnedTupleExpr(owner.getOwner(), patternNode.clone()); owned.prepare(QueryLanguage.SPARQL, builder.toString(), bindings); if (mapping) { Projection proj = new Projection(owned, list); patternNode.replaceWith(proj); } else { patternNode.replaceWith(owned); } }
Example #16
Source File: NamespaceController.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ModelAndView getRemoveNamespaceResult(HttpServletRequest request, String prefix) throws ServerHTTPException { try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) { repositoryCon.removeNamespace(prefix); } catch (RepositoryException e) { throw new ServerHTTPException("Repository error: " + e.getMessage(), e); } return new ModelAndView(EmptySuccessView.getInstance()); }
Example #17
Source File: CustomGraphQueryInferencerTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected CustomGraphQueryInferencer createRepository(boolean withMatchQuery) throws IOException, MalformedQueryException, UnsupportedQueryLanguageException, RepositoryException, SailException, RDFParseException { String testFolder = TEST_DIR_PREFIX + resourceFolder; String rule = ResourceUtil.getString(testFolder + "/rule.rq"); String match = withMatchQuery ? ResourceUtil.getString(testFolder + "/match.rq") : ""; initial = ResourceUtil.getString(testFolder + "/initial.ttl"); delete = ResourceUtil.getString(testFolder + "/delete.ru"); NotifyingSail store = newSail(); return new CustomGraphQueryInferencer(store, language, rule, match); }
Example #18
Source File: Endpoint.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
/** * Shutdown this repository. * * @throws RepositoryException */ public void shutDown() throws RepositoryException { if (repo==null) throw new RepositoryException("Repository for endpoint " + id + " not yet specified"); if (!isInitialized()) return; conn.close(); conn = null; repo.shutDown(); initialized = false; }
Example #19
Source File: SPARQLConnection.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query, String base) throws RepositoryException, MalformedQueryException { if (SPARQL.equals(ql)) { return new SPARQLBooleanQuery(client, base, query); } throw new UnsupportedQueryLanguageException("Unsupported query language " + ql); }
Example #20
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void addStatement(Statement statement) throws ModelRuntimeException { this.assertModel(); try { org.eclipse.rdf4j.model.Statement s = ConversionUtil.toRDF4J(statement, this.valueFactory); this.connection.add(s, s.getContext()); } catch(RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #21
Source File: HTTPTupleQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { SPARQLProtocolSession client = getHttpClient(); try { conn.flushTransactionState(Protocol.Action.QUERY); return client.sendTupleQuery(queryLanguage, queryString, baseURI, dataset, getIncludeInferred(), getMaxExecutionTime(), getBindingsArray()); } catch (IOException | RepositoryException | MalformedQueryException e) { throw new HTTPQueryEvaluationException(e.getMessage(), e); } }
Example #22
Source File: RepositoryModel.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override @Deprecated public void commit() { try { if (this.connection.isActive()) this.connection.commit(); } catch (RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #23
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override @Deprecated public void setAutocommit(boolean autocommit) { try { this.connection.setAutoCommit(autocommit); } catch(RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #24
Source File: RepositoryModel.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void removeNamespace(String prefix) { assertModel(); try { this.connection.removeNamespace(prefix); } catch (RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #25
Source File: TypeFilteringRepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public RepositoryInfo getRepositoryInfo(String id) throws RepositoryException { try { if (isCorrectType(id)) { return delegate.getRepositoryInfo(id); } return null; } catch (RepositoryConfigException e) { throw new RepositoryException(e.getMessage(), e); } }
Example #26
Source File: ContextAwareConnection.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException { if (baseURI == null) { baseURI = getBaseURI(); } if (isNilContext(contexts) && !dataFormat.supportsContexts()) { super.add(in, baseURI, dataFormat, getAddContexts()); } else { super.add(in, baseURI, dataFormat, contexts); } }
Example #27
Source File: AbstractGenericLuceneTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@After public void tearDown() throws IOException, RepositoryException { try { if (connection != null) { connection.close(); } } finally { if (repository != null) { repository.shutDown(); } } }
Example #28
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public long size() throws ModelRuntimeException { this.assertModel(); try { return this.connection.size(); } catch(RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #29
Source File: RDFRemover.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void handleStatement(Statement st) throws RDFHandlerException { try { if (enforceContext) { // Override supplied context info con.remove(st.getSubject(), st.getPredicate(), st.getObject(), context); } else { con.remove(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext()); } } catch (RepositoryException e) { throw new RDFHandlerException(e); } }
Example #30
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Removes the configuration for the specified repository from the manager's system repository if such a * configuration is present. Returns <tt>true</tt> if the system repository actually contained the specified * repository configuration. * * @param repositoryID The ID of the repository whose configuration needs to be removed. * @throws RepositoryException If the manager failed to update it's system repository. * @throws RepositoryConfigException If the manager doesn't know how to remove a configuration due to inconsistent * configuration data in the system repository. For example, this happens when * there are multiple existing configurations with the concerning ID. * @deprecated since 2.0. Use {@link #removeRepository(String repositoryID)} instead. */ @Deprecated public boolean removeRepositoryConfig(String repositoryID) throws RepositoryException, RepositoryConfigException { logger.debug("Removing repository configuration for {}.", repositoryID); boolean isRemoved = hasRepositoryConfig(repositoryID); synchronized (initializedRepositories) { // update SYSTEM repository if there is one for 2.2 compatibility Repository systemRepository = getSystemRepository(); if (systemRepository != null) { RepositoryConfigUtil.removeRepositoryConfigs(systemRepository, repositoryID); } if (isRemoved) { logger.debug("Shutdown repository {} after removal of configuration.", repositoryID); Repository repository = initializedRepositories.remove(repositoryID); if (repository != null && repository.isInitialized()) { repository.shutDown(); } try { cleanUpRepository(repositoryID); } catch (IOException e) { throw new RepositoryException("Unable to clean up resources for removed repository " + repositoryID, e); } } } return isRemoved; }