Search in sources :

Example 16 with Statement

use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.

the class NotifyingRepositoryConnectionWrapper method removeWithoutCommit.

@Override
public void removeWithoutCommit(Resource subj, IRI pred, Value obj, Resource... ctx) throws RepositoryException {
    if (activated && reportDeltas()) {
        RepositoryResult<Statement> stmts;
        stmts = getDelegate().getStatements(subj, pred, obj, false, ctx);
        List<Statement> list = new ArrayList<Statement>();
        try {
            while (stmts.hasNext()) {
                list.add(stmts.next());
            }
        } finally {
            stmts.close();
        }
        getDelegate().remove(subj, pred, obj, ctx);
        for (RepositoryConnectionListener listener : listeners) {
            for (Statement stmt : list) {
                Resource s = stmt.getSubject();
                IRI p = stmt.getPredicate();
                Value o = stmt.getObject();
                Resource c = stmt.getContext();
                listener.remove(getDelegate(), s, p, o, c);
            }
        }
    } else if (activated) {
        getDelegate().remove(subj, pred, obj, ctx);
        for (RepositoryConnectionListener listener : listeners) {
            listener.remove(getDelegate(), subj, pred, obj, ctx);
        }
    } else {
        getDelegate().remove(subj, pred, obj, ctx);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener) Statement(org.eclipse.rdf4j.model.Statement) ArrayList(java.util.ArrayList) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Example 17 with Statement

use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.

the class AbstractRepositoryConnection method remove.

@Override
public void remove(Iterable<? extends Statement> statements, Resource... contexts) throws RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    boolean localTransaction = startLocalTransaction();
    try {
        for (Statement st : statements) {
            remove(st, contexts);
        }
        conditionalCommit(localTransaction);
    } catch (RepositoryException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 18 with Statement

use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.

the class RepositoryConfigUtil method getRepositoryConfig.

public static RepositoryConfig getRepositoryConfig(Model model, String repositoryID) {
    Statement idStatement = getIDStatement(model, repositoryID);
    if (idStatement == null) {
        // No such config
        return null;
    }
    Resource repositoryNode = idStatement.getSubject();
    Resource context = idStatement.getContext();
    Model contextGraph = model.filter(null, null, null, context);
    return RepositoryConfig.create(contextGraph, repositoryNode);
}
Also used : 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)

Example 19 with Statement

use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.

the class RepositoryConfigUtil method getContext.

@Deprecated
public static Resource getContext(RepositoryConnection con, String repositoryID) throws RepositoryException, RepositoryConfigException {
    Resource context = null;
    Statement idStatement = getIDStatement(con, repositoryID);
    if (idStatement != null) {
        context = idStatement.getContext();
    }
    return context;
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource)

Example 20 with Statement

use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.

the class TurtleHandlingTest method writeTurtle.

/**
 * Helper method to write the given model to Turtle and return an InputStream containing the results.
 *
 * @param statements
 * @return An {@link InputStream} containing the results.
 * @throws RDFHandlerException
 */
private InputStream writeTurtle(Model statements) throws RDFHandlerException {
    StringWriter writer = new StringWriter();
    RDFWriter turtleWriter = new TurtleWriter(writer);
    turtleWriter.startRDF();
    for (Statement nextStatement : statements) {
        turtleWriter.handleStatement(nextStatement);
    }
    turtleWriter.endRDF();
    return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
Also used : StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) Statement(org.eclipse.rdf4j.model.Statement) TurtleWriter(org.eclipse.rdf4j.rio.turtle.TurtleWriter) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter)

Aggregations

Statement (org.eclipse.rdf4j.model.Statement)74 IRI (org.eclipse.rdf4j.model.IRI)17 Test (org.junit.Test)17 Model (org.eclipse.rdf4j.model.Model)16 Literal (org.eclipse.rdf4j.model.Literal)15 Resource (org.eclipse.rdf4j.model.Resource)15 Value (org.eclipse.rdf4j.model.Value)13 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ArrayList (java.util.ArrayList)10 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)8 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)8 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)8 StringWriter (java.io.StringWriter)7 BNode (org.eclipse.rdf4j.model.BNode)6 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)6 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)6 IOException (java.io.IOException)5