Search in sources :

Example 61 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class RepositoryManager method removeRepository.

/**
 * Removes the specified repository by deleting its configuration from the manager's system repository if
 * such a configuration is present, and removing any persistent data associated with the repository.
 * Returns <tt>true</tt> if the system repository actually contained the specified repository
 * configuration. <strong>NB this operation can not be undone!</strong>
 *
 * @param repositoryID
 *        The ID of the repository that needs to be removed.
 * @throws RepositoryException
 *         If the manager failed to update its system repository.
 * @throws RepositoryConfigException
 *         If the manager doesn't know how to remove a repository due to inconsistent configuration data
 *         in the system repository. For example, this happens when there are multiple existing
 *         configurations with the concerning ID.
 */
public boolean removeRepository(String repositoryID) throws RepositoryException, RepositoryConfigException {
    logger.debug("Removing repository {}.", 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;
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 62 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class RepositoryManager method removeRepositoryConfig.

/**
 * 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.6.7. 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;
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 63 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method setNamespace.

public void setNamespace(String prefix, String name) throws RepositoryException {
    if (prefix == null) {
        throw new NullPointerException("prefix must not be null");
    }
    if (name == null) {
        throw new NullPointerException("name must not be null");
    }
    if (this.getRepository().useCompatibleMode()) {
        boolean localTransaction = startLocalTransaction();
        txn.add(new SetNamespaceOperation(prefix, name));
        conditionalCommit(localTransaction);
        return;
    }
    try {
        client.setNamespacePrefix(prefix, name);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : SetNamespaceOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.SetNamespaceOperation) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 64 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class HTTPGraphQuery method evaluate.

/*
	 * public GraphQueryResult evaluate() throws QueryEvaluationException { HTTPClient client =
	 * httpCon.getRepository().getHTTPClient(); try { return client.sendGraphQuery(queryLanguage, queryString,
	 * baseURI, dataset, includeInferred, maxQueryTime, getBindingsArray()); } catch (IOException e) { throw
	 * new HTTPQueryEvaluationException(e.getMessage(), e); } catch (RepositoryException e) { throw new
	 * HTTPQueryEvaluationException(e.getMessage(), e); } catch (MalformedQueryException e) { throw new
	 * HTTPQueryEvaluationException(e.getMessage(), e); } }
	 */
public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException {
    SPARQLProtocolSession client = getHttpClient();
    try {
        conn.flushTransactionState(Protocol.Action.QUERY);
        client.sendGraphQuery(queryLanguage, queryString, baseURI, dataset, includeInferred, getMaxExecutionTime(), handler, getBindingsArray());
    } catch (IOException e) {
        throw new HTTPQueryEvaluationException(e.getMessage(), e);
    } catch (RepositoryException e) {
        throw new HTTPQueryEvaluationException(e.getMessage(), e);
    } catch (MalformedQueryException e) {
        throw new HTTPQueryEvaluationException(e.getMessage(), e);
    }
}
Also used : SPARQLProtocolSession(org.eclipse.rdf4j.http.client.SPARQLProtocolSession) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 65 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class RepositoryConfigUtil method getRepositoryConfig.

@Deprecated
public static RepositoryConfig getRepositoryConfig(Repository repository, String repositoryID) throws RepositoryConfigException, RepositoryException {
    RepositoryConnection con = repository.getConnection();
    try {
        Statement idStatement = getIDStatement(con, repositoryID);
        if (idStatement == null) {
            // No such config
            return null;
        }
        Resource repositoryNode = idStatement.getSubject();
        Resource context = idStatement.getContext();
        if (context == null) {
            throw new RepositoryException("No configuration context for repository " + repositoryID);
        }
        Model contextGraph = QueryResults.asModel(con.getStatements(null, null, null, true, context));
        return RepositoryConfig.create(contextGraph, repositoryNode);
    } finally {
        con.close();
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Aggregations

RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)67 IOException (java.io.IOException)24 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)20 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)15 RDF4JException (org.eclipse.rdf4j.RDF4JException)13 HttpResponse (org.apache.http.HttpResponse)11 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)10 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)8 HttpGet (org.apache.http.client.methods.HttpGet)7 Resource (org.eclipse.rdf4j.model.Resource)7 Statement (org.eclipse.rdf4j.model.Statement)6 ArrayList (java.util.ArrayList)5 HttpPut (org.apache.http.client.methods.HttpPut)5 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)5 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)5 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)5 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4