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

Commit

Permalink
Merge branch 'develop' into issues/GH-1113-shacl-api
Browse files Browse the repository at this point in the history
* develop:
  ignore code generated during mvn install
  eclipse-rdf4j/rdf4j#1246 shutdown repo to cause error
  eclipse-rdf4j/rdf4j#1246 close unclosed resource
  eclipse-rdf4j/rdf4j#1182 use logger instead of println

Signed-off-by: Håvard Ottestad <[email protected]>
  • Loading branch information
hmottestad committed Jan 19, 2019
2 parents c3b523a + 2f3f553 commit 7224be2
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ dependency-reduced-pom.xml
# NetBean files
**/nb-configuration.xml
**/nbactions*.xml
compliance/sparql/overlays
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,26 @@ public void close()
semaphore.lock();
try {
try {
SailDataset toCloseSnapshot = snapshot;
snapshot = null;
if (toCloseSnapshot != null) {
toCloseSnapshot.close();
try {
SailDataset toCloseSnapshot = snapshot;
snapshot = null;
if (toCloseSnapshot != null) {
toCloseSnapshot.close();
}
} finally {
SailSink toCloseSerializable = serializable;
serializable = null;
if (toCloseSerializable != null) {
toCloseSerializable.close();
}
}
}
finally {
SailSink toCloseSerializable = serializable;
serializable = null;
if (toCloseSerializable != null) {
toCloseSerializable.close();
} finally {
SailSink toClosePrepared = prepared;
prepared = null;
if (toClosePrepared != null) {
toClosePrepared.close();
}

}
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class ShaclSailConnection extends NotifyingSailConnectionWrapper {

private final Logger logger = LoggerFactory.getLogger(getClass());
private static final Logger logger = LoggerFactory.getLogger(ShaclSailConnection.class);

private NotifyingSailConnection previousStateConnection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@


import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.sail.SailException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;
Expand All @@ -22,6 +25,9 @@
*/
public abstract class FilterPlanNode<T extends PushBasedPlanNode & SupportsParentProvider> implements ParentProvider {

static private final Logger logger = LoggerFactory.getLogger(FilterPlanNode.class);


PlanNode parent;

T trueNode;
Expand Down Expand Up @@ -84,7 +90,7 @@ private void calculateNext() {
} else {
if (falseNode != null) {
if(LoggingNode.loggingEnabled){
System.out.println(leadingSpace() + that.getClass().getSimpleName() + ";falseNode: " + " " + temp.toString());
logger.debug(leadingSpace() + that.getClass().getSimpleName() + ";falseNode: " + " " + temp.toString());
}
falseNode.push(temp);

Expand Down Expand Up @@ -177,11 +183,6 @@ public String getId() {


private String leadingSpace() {
StringBuilder ret = new StringBuilder();
int depth = parent.depth()+1;
while (--depth > 0) {
ret.append(" ");
}
return ret.toString();
return StringUtils.leftPad("", parent.depth(), " ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

package org.eclipse.rdf4j.sail.shacl.planNodes;

import org.apache.commons.lang.StringUtils;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.common.iteration.Iterations;
import org.eclipse.rdf4j.sail.SailException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import java.util.List;
Expand All @@ -22,6 +25,9 @@
*/
public class LoggingNode implements PlanNode {

static private final Logger logger = LoggerFactory.getLogger(LoggingNode.class);


PlanNode parent;

boolean pullAll = true;
Expand Down Expand Up @@ -93,7 +99,7 @@ public void close() throws SailException {
public boolean hasNext() throws SailException {
boolean hasNext = parentIterator.hasNext();

//System.out.println(leadingSpace()+parent.getClass().getSimpleName()+".hasNext() : "+hasNext);
// logger.debug(leadingSpace()+parent.getClass().getSimpleName()+".hasNext() : "+hasNext);
return hasNext;
}

Expand All @@ -105,7 +111,7 @@ public Tuple next() throws SailException {

assert next != null;

System.out.println(leadingSpace() + parent.getClass().getSimpleName() + ".next(): " + " " + next.toString());
logger.debug(leadingSpace() + parent.getClass().getSimpleName() + ".next(): " + " " + next.toString());

return next;
}
Expand Down Expand Up @@ -140,11 +146,7 @@ public IteratorData getIteratorDataType() {
}

private String leadingSpace() {
StringBuilder ret = new StringBuilder();
int depth = depth();
while (--depth > 0) {
ret.append(" ");
}
return ret.toString();
return StringUtils.leftPad("", depth(), " ");
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.eclipse.rdf4j.sail.shacl.planNodes;

import org.apache.commons.lang.StringUtils;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.sail.SailException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class PushBasedLoggingNode implements SupportsParentProvider, PushBasedPlanNode, PlanNode {

static private final Logger logger = LoggerFactory.getLogger(PushBasedLoggingNode.class);


private final PushBasedPlanNode parent;
private List<PlanNode> parents;

Expand Down Expand Up @@ -43,7 +49,7 @@ public IteratorData getIteratorDataType() {
@Override
public void push(Tuple t) {
if(LoggingNode.loggingEnabled){
System.out.println(leadingSpace() + parent.getClass().getSimpleName() + ".next(): " + " " + t.toString());
logger.debug(leadingSpace() + parent.getClass().getSimpleName() + ".next(): " + " " + t.toString());
}
parent.push(t);
}
Expand All @@ -61,11 +67,6 @@ public void receiveParentProvider(ParentProvider parentProvider) {
}

private String leadingSpace() {
StringBuilder ret = new StringBuilder();
int depth = depth();
while (--depth > 0) {
ret.append(" ");
}
return ret.toString();
return StringUtils.leftPad("", depth(), " ");
}
}
47 changes: 23 additions & 24 deletions shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/ShaclTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static Collection<Object[]> getTestsToRun() {
return ret;
}

void runTestCase(String shaclPath, String dataPath, ExpectedResult expectedResult) throws Exception {
private void runTestCase(String shaclPath, String dataPath, ExpectedResult expectedResult) throws Exception {

if (!dataPath.endsWith("/")) {
dataPath = dataPath + "/";
Expand All @@ -137,35 +137,36 @@ void runTestCase(String shaclPath, String dataPath, ExpectedResult expectedResul
for (int j = 0; j < 100; j++) {

String name = dataPath + "query" + j + ".rq";
InputStream resourceAsStream = ShaclTest.class.getClassLoader().getResourceAsStream(name);
if (resourceAsStream == null) {
continue;
}
try (InputStream resourceAsStream = ShaclTest.class.getClassLoader().getResourceAsStream(name)) {
if (resourceAsStream == null) {
continue;
}

ran = true;
System.out.println(name);
ran = true;
System.out.println(name);

try (SailRepositoryConnection connection = shaclRepository.getConnection()) {
connection.begin();
String query = IOUtil.readString(resourceAsStream);
connection.prepareUpdate(query).execute();
connection.commit();
}
catch (RepositoryException sailException) {
exception = true;
System.out.println(sailException.getMessage());
try (SailRepositoryConnection connection = shaclRepository.getConnection()) {
connection.begin(IsolationLevels.SNAPSHOT);
String query = IOUtil.readString(resourceAsStream);
connection.prepareUpdate(query).execute();
connection.commit();
} catch (RepositoryException sailException) {
exception = true;
System.out.println(sailException.getMessage());

}
catch (IOException e) {
}
} catch (IOException e) {
e.printStackTrace();
}

}

shaclSail.shutDown();

if (ran) {
if (expectedResult == ExpectedResult.valid) {
assertFalse("Expected transaction to succeed", exception);
}
else {
} else {
assertTrue("Expected transaction to fail", exception);
}
}
Expand Down Expand Up @@ -210,17 +211,15 @@ void runTestCaseSingleTransaction(String shaclPath, String dataPath, ExpectedRes
String query = IOUtil.readString(resourceAsStream);
shaclSailConnection.prepareUpdate(query).execute();

}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}

try {
shaclSailConnection.commit();

}
catch (RepositoryException sailException) {
} catch (RepositoryException sailException) {
exception = true;
System.out.println(sailException.getMessage());
}
Expand Down
5 changes: 5 additions & 0 deletions shacl/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
<level value="info" />
<appender-ref ref="STDOUT" />
</root>

<logger name="org.eclipse.rdf4j.sail.shacl" level="debug"/>



</configuration>

0 comments on commit 7224be2

Please sign in to comment.