Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
option for disabling and enabling validation
Browse files Browse the repository at this point in the history
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
  • Loading branch information
hmottestad committed Dec 31, 2017
1 parent b260f59 commit bfe026e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
14 changes: 14 additions & 0 deletions shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShaclSail.java
Expand Up @@ -25,6 +25,7 @@ public class ShaclSail extends NotifyingSailWrapper {

public List<Shape> shapes;

ShaclSailConfig config = new ShaclSailConfig();

public ShaclSail(NotifyingSail baseSail, SailRepository shaclSail) {
super(baseSail);
Expand All @@ -41,5 +42,18 @@ public NotifyingSailConnection getConnection()
return new ShaclSailConnection(this, super.getConnection());
}

public void disableValidation(){
config.validationEnabled = false;
}

public void enableValidation(){
config.validationEnabled = true;
}

}

class ShaclSailConfig {

boolean validationEnabled = true;

}
Expand Up @@ -35,47 +35,51 @@ public class ShaclSailConnection extends NotifyingSailConnectionWrapper {
public Repository addedStatements;
public Repository removedStatements;

ShaclSailConnection(ShaclSail shaclSail, NotifyingSailConnection connection) {
ShaclSailConnection(ShaclSail sail, NotifyingSailConnection connection) {
super(connection);
this.sail = shaclSail;

addConnectionListener(new SailConnectionListener() {

@Override
public void statementAdded(Statement statement) {
try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
addedStatementsConnection.begin(IsolationLevels.NONE);
addedStatementsConnection.add(statement);
addedStatementsConnection.commit();
}
try (RepositoryConnection removedStatementsConnection = removedStatements.getConnection()) {
removedStatementsConnection.begin(IsolationLevels.NONE);
removedStatementsConnection.remove(statement);
removedStatementsConnection.commit();
this.sail = sail;

if (sail.config.validationEnabled) {

addConnectionListener(new SailConnectionListener() {

@Override
public void statementAdded(Statement statement) {
try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
addedStatementsConnection.begin(IsolationLevels.NONE);
addedStatementsConnection.add(statement);
addedStatementsConnection.commit();
}
try (RepositoryConnection removedStatementsConnection = removedStatements.getConnection()) {
removedStatementsConnection.begin(IsolationLevels.NONE);
removedStatementsConnection.remove(statement);
removedStatementsConnection.commit();
}
}
}

@Override
public void statementRemoved(Statement statement) {
try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
addedStatementsConnection.begin(IsolationLevels.NONE);
addedStatementsConnection.remove(statement);
addedStatementsConnection.commit();
}
try (RepositoryConnection removedStatementsConnection = removedStatements.getConnection()) {
removedStatementsConnection.begin(IsolationLevels.NONE);
removedStatementsConnection.add(statement);
removedStatementsConnection.commit();
@Override
public void statementRemoved(Statement statement) {
try (RepositoryConnection addedStatementsConnection = addedStatements.getConnection()) {
addedStatementsConnection.begin(IsolationLevels.NONE);
addedStatementsConnection.remove(statement);
addedStatementsConnection.commit();
}
try (RepositoryConnection removedStatementsConnection = removedStatements.getConnection()) {
removedStatementsConnection.begin(IsolationLevels.NONE);
removedStatementsConnection.add(statement);
removedStatementsConnection.commit();
}
}
}
}

);
);
}
}

@Override
public void begin(IsolationLevel level)
throws SailException {

assert addedStatements == null;
assert removedStatements == null;

Expand All @@ -84,6 +88,7 @@ public void begin(IsolationLevel level)
removedStatements = new SailRepository(new MemoryStore());
removedStatements.initialize();


super.begin(level);
}

Expand Down Expand Up @@ -123,6 +128,10 @@ private void cleanup() {

private boolean validate() {

if (!sail.config.validationEnabled) {
return true;
}

boolean allValid = true;

for (Shape shape : sail.shapes) {
Expand Down
Expand Up @@ -18,5 +18,5 @@ public interface PlanNode extends PlanNodeCardinality {

boolean validate();

public CloseableIteration<Tuple, SailException> iterator();
CloseableIteration<Tuple, SailException> iterator();
}

0 comments on commit bfe026e

Please sign in to comment.