Search in sources :

Example 6 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class HTTPRepositoryConnection method removeWithoutCommit.

@Override
protected void removeWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
    if (this.getRepository().useCompatibleMode()) {
        txn.add(new RemoveStatementsOperation(subject, predicate, object, contexts));
        return;
    }
    flushTransactionState(Protocol.Action.DELETE);
    if (toRemove == null) {
        toRemove = new LinkedHashModel();
    }
    if (subject == null) {
        subject = SESAME.WILDCARD;
    }
    if (predicate == null) {
        predicate = SESAME.WILDCARD;
    }
    if (object == null) {
        object = SESAME.WILDCARD;
    }
    toRemove.add(subject, predicate, object, contexts);
}
Also used : RemoveStatementsOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.RemoveStatementsOperation) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 7 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class HTTPRepositoryConnection method addWithoutCommit.

/*
	 * @Override public void remove(Resource subject, URI predicate, Value object, Resource... contexts)
	 * throws RepositoryException { if (!isActive()) { // operation is not part of a transaction - just send
	 * directly OpenRDFUtil.verifyContextNotNull(contexts); if (subject == null) { subject = SESAME.WILDCARD;
	 * } if (predicate == null) { predicate = SESAME.WILDCARD; } if (object == null) { object =
	 * SESAME.WILDCARD; } final Model m = new LinkedHashModel(); m.add(subject, predicate, object, contexts);
	 * removeModel(m); } else { super.remove(subject, predicate, object, contexts); } }
	 */
@Override
protected void addWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
    if (this.getRepository().useCompatibleMode()) {
        txn.add(new AddStatementOperation(subject, predicate, object, contexts));
        return;
    }
    flushTransactionState(Protocol.Action.ADD);
    if (toAdd == null) {
        toAdd = new LinkedHashModel();
    }
    toAdd.add(subject, predicate, object, contexts);
}
Also used : AddStatementOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 8 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RemoteRepositoryManager method getRepositoryConfig.

@Override
public RepositoryConfig getRepositoryConfig(String id) throws RepositoryException {
    Model model = new LinkedHashModel();
    try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
        httpClient.setUsernameAndPassword(username, password);
        httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
        httpClient.getStatements(null, null, null, true, new StatementCollector(model));
    } catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
        throw new RepositoryException(ue);
    }
    return RepositoryConfigUtil.getRepositoryConfig(model, id);
}
Also used : QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) IOException(java.io.IOException)

Example 9 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RemoteRepositoryManager method addRepositoryConfig.

@Override
public void addRepositoryConfig(RepositoryConfig config) throws RepositoryException, RepositoryConfigException {
    try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
        String baseURI = Protocol.getRepositoryLocation(serverURL, config.getID());
        Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + config.getID());
        httpClient.setUsernameAndPassword(username, password);
        httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
        Model model = new LinkedHashModel();
        config.export(model, ctx);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Rio.write(model, baos, httpClient.getPreferredRDFFormat());
        removeRepository(config.getID());
        try (InputStream contents = new ByteArrayInputStream(baos.toByteArray())) {
            httpClient.upload(contents, baseURI, httpClient.getPreferredRDFFormat(), false, true, ctx);
        }
    } catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
        throw new RepositoryException(ue);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(org.eclipse.rdf4j.model.Resource) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 10 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class HTTPRepositoryConnection method add.

@Override
public void add(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
    if (!isActive()) {
        logger.debug("adding statement directly: {} {} {} {}", new Object[] { subject, predicate, object, contexts });
        // operation is not part of a transaction - just send directly
        OpenRDFUtil.verifyContextNotNull(contexts);
        final Model m = new LinkedHashModel();
        m.add(subject, predicate, object, contexts);
        addModel(m);
    } else {
        logger.debug("adding statement in txn: {} {} {} {}", new Object[] { subject, predicate, object, contexts });
        super.add(subject, predicate, object, contexts);
    }
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Aggregations

LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)30 Model (org.eclipse.rdf4j.model.Model)23 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)11 Test (org.junit.Test)11 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)7 ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)6 Statement (org.eclipse.rdf4j.model.Statement)5 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)5 Literal (org.eclipse.rdf4j.model.Literal)4 Before (org.junit.Before)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 IRI (org.eclipse.rdf4j.model.IRI)3 Resource (org.eclipse.rdf4j.model.Resource)3 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)2 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)2 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2