Search in sources :

Example 1 with RepositoryConnectionListener

use of org.eclipse.rdf4j.repository.event.RepositoryConnectionListener in project rdf4j by eclipse.

the class NotifyingRepositoryConnectionWrapper method setAutoCommit.

@Override
@Deprecated
public void setAutoCommit(boolean autoCommit) throws RepositoryException {
    boolean wasAutoCommit = isAutoCommit();
    getDelegate().setAutoCommit(autoCommit);
    if (activated && wasAutoCommit != autoCommit) {
        for (RepositoryConnectionListener listener : listeners) {
            listener.setAutoCommit(getDelegate(), autoCommit);
        }
        if (autoCommit) {
            for (RepositoryConnectionListener listener : listeners) {
                listener.commit(getDelegate());
            }
        }
    }
}
Also used : RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener)

Example 2 with RepositoryConnectionListener

use of org.eclipse.rdf4j.repository.event.RepositoryConnectionListener in project rdf4j by eclipse.

the class NotifyingRepositoryConnectionWrapper method clearNamespaces.

@Override
public void clearNamespaces() throws RepositoryException {
    if (activated && reportDeltas()) {
        RepositoryResult<Namespace> namespaces;
        namespaces = getDelegate().getNamespaces();
        List<String> prefix = new ArrayList<String>();
        try {
            while (namespaces.hasNext()) {
                Namespace ns = namespaces.next();
                prefix.add(ns.getPrefix());
            }
        } finally {
            namespaces.close();
        }
        getDelegate().clearNamespaces();
        for (String p : prefix) {
            removeNamespace(p);
        }
    } else if (activated) {
        getDelegate().clearNamespaces();
        for (RepositoryConnectionListener listener : listeners) {
            listener.clearNamespaces(getDelegate());
        }
    } else {
        getDelegate().clearNamespaces();
    }
}
Also used : RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener) ArrayList(java.util.ArrayList) Namespace(org.eclipse.rdf4j.model.Namespace)

Example 3 with RepositoryConnectionListener

use of org.eclipse.rdf4j.repository.event.RepositoryConnectionListener 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 4 with RepositoryConnectionListener

use of org.eclipse.rdf4j.repository.event.RepositoryConnectionListener in project rdf4j by eclipse.

the class NotifyingRepositoryWrapper method getConnection.

@Override
public NotifyingRepositoryConnection getConnection() throws RepositoryException {
    RepositoryConnection con = getDelegate().getConnection();
    NotifyingRepositoryConnection ncon = new NotifyingRepositoryConnectionWrapper(this, con, getDefaultReportDeltas());
    if (activated) {
        for (RepositoryListener listener : listeners) {
            listener.getConnection(this, ncon);
        }
    }
    for (RepositoryConnectionListener l : conListeners) {
        ncon.addRepositoryConnectionListener(l);
    }
    return ncon;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) NotifyingRepositoryConnection(org.eclipse.rdf4j.repository.event.NotifyingRepositoryConnection) RepositoryListener(org.eclipse.rdf4j.repository.event.RepositoryListener) RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener) NotifyingRepositoryConnection(org.eclipse.rdf4j.repository.event.NotifyingRepositoryConnection)

Example 5 with RepositoryConnectionListener

use of org.eclipse.rdf4j.repository.event.RepositoryConnectionListener in project rdf4j by eclipse.

the class NotifyingRepositoryConnectionWrapper method addWithoutCommit.

@Override
public void addWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
    boolean reportEvent = activated;
    if (reportEvent && reportDeltas()) {
        // Only report if the statement is not present yet
        reportEvent = !getDelegate().hasStatement(subject, predicate, object, false, contexts);
    }
    getDelegate().add(subject, predicate, object, contexts);
    if (reportEvent) {
        for (RepositoryConnectionListener listener : listeners) {
            listener.add(getDelegate(), subject, predicate, object, contexts);
        }
    }
}
Also used : RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener)

Aggregations

RepositoryConnectionListener (org.eclipse.rdf4j.repository.event.RepositoryConnectionListener)5 ArrayList (java.util.ArrayList)2 IRI (org.eclipse.rdf4j.model.IRI)1 Namespace (org.eclipse.rdf4j.model.Namespace)1 Resource (org.eclipse.rdf4j.model.Resource)1 Statement (org.eclipse.rdf4j.model.Statement)1 Value (org.eclipse.rdf4j.model.Value)1 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)1 NotifyingRepositoryConnection (org.eclipse.rdf4j.repository.event.NotifyingRepositoryConnection)1 RepositoryListener (org.eclipse.rdf4j.repository.event.RepositoryListener)1