All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.fortytwo.sesametools.writeonly.WriteOnlySailConnection Maven / Gradle / Ivy

There is a newer version: 1.9
Show newest version

package net.fortytwo.sesametools.writeonly;

import info.aduna.iteration.CloseableIteration;
import net.fortytwo.sesametools.EmptyCloseableIteration;
import org.openrdf.model.IRI;
import org.openrdf.model.Namespace;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.query.BindingSet;
import org.openrdf.query.Dataset;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.algebra.TupleExpr;
import org.openrdf.rio.RDFHandler;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.sail.SailException;
import org.openrdf.sail.helpers.AbstractSail;
import org.openrdf.sail.helpers.AbstractSailConnection;

/**
 * @author Joshua Shinavier (http://fortytwo.net).
 */
public class WriteOnlySailConnection extends AbstractSailConnection {
    private RDFHandler handler;
    private ValueFactory valueFactory;

    public WriteOnlySailConnection(final AbstractSail sail,
                                   final RDFHandler handler,
                                   final ValueFactory valueFactory) {
        super(sail);
        this.handler = handler;
        this.valueFactory = valueFactory;
    }

    protected void addStatementInternal(
            final Resource subj, final IRI pred, final Value obj, final Resource... contexts) throws SailException {

        if (null == contexts || 0 == contexts.length) {
            Statement st = valueFactory.createStatement(subj, pred, obj);
            try {
                handler.handleStatement(st);
            } catch (RDFHandlerException e) {
                throw new SailException(e);
            }
        } else {
            for (Resource ctx : contexts) {
                Statement st = valueFactory.createStatement(subj, pred, obj, ctx);
                try {
                    handler.handleStatement(st);
                } catch (RDFHandlerException e) {
                    throw new SailException(e);
                }
            }
        }
    }

    protected void clearInternal(Resource... arg0) throws SailException {
        // Does nothing.
    }

    protected void clearNamespacesInternal() throws SailException {
        // Does nothing.
    }

    protected void closeInternal() throws SailException {
    }

    protected void commitInternal() throws SailException {
    }

    protected CloseableIteration evaluateInternal(
            TupleExpr arg0, Dataset arg1, BindingSet arg2, boolean arg3)
            throws SailException {
        return new EmptyCloseableIteration<>();
    }

    protected CloseableIteration getContextIDsInternal()
            throws SailException {
        return new EmptyCloseableIteration<>();
    }

    protected String getNamespaceInternal(final String prefix) throws SailException {
        return null;
    }

    protected CloseableIteration getNamespacesInternal()
            throws SailException {
        return new EmptyCloseableIteration<>();
    }

    protected CloseableIteration getStatementsInternal(
            Resource arg0, IRI arg1, Value arg2, boolean arg3, Resource... arg4)
            throws SailException {
        return new EmptyCloseableIteration<>();
    }

    protected void removeNamespaceInternal(String arg0) throws SailException {
        // Does nothing.
    }

    protected void removeStatementsInternal(Resource arg0, IRI arg1, Value arg2,
                                 Resource... arg3) throws SailException {
        // Does nothing.
    }

    protected void rollbackInternal() throws SailException {
    }

    protected void setNamespaceInternal(String arg0, String arg1) throws SailException {
        // Does nothing.
    }

    protected long sizeInternal(final Resource... contexts) throws SailException {
        return 0;
    }

    protected void startTransactionInternal() throws SailException {
        // Does nothing.
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy