Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
distribution: [ "temurin", "corretto" ]
java: [ "17", "21" ]
java: [ "21", "25" ]
name: Testing with Java ${{ matrix.java }} (${{ matrix.distribution }})
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>org.topbraid</groupId>
<artifactId>shacl</artifactId>
<version>1.4.5-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>TopBraid SHACL API</name>
Expand Down Expand Up @@ -68,11 +68,11 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ver.jena>5.2.0</ver.jena>
<ver.jena>6.0.0</ver.jena>
<ver.junit>4.13.2</ver.junit>
<ver.slf4j>2.0.17</ver.slf4j>
<ver.log4j2>2.25.2</ver.log4j2>
<java.version>17</java.version>
<java.version>21</java.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
* An ARQ FunctionRegistry that can be used to associate functions
* with Threads, so that additional functions from a given Model can
* be made visible depending on the SPARQL query thread.
*
*
* <p>The contract of this class is very strict to prevent memory leaks:
* Users always need to make sure that unregister is called as soon
* as a query (block) ends, and to restore any old CurrentThreadFunctions
* object that was registered before. So a typical block would be:</p>
*
*
* <code>
* Model model = ... a Model with extra SHACL/SPIN functions
* CurrentThreadFunctions old = CurrentThreadFunctionRegistry.register(model);
Expand All @@ -42,32 +42,32 @@
* finally {
* CurrentThreadFunctionRegistry.unregister(old);
* }</code>
*
*
* <p>In preparation of the above, the application should start up with code
* such as</p>
*
*
* <code>
* FunctionRegistry oldFR = FunctionRegistry.get();
* CurrentThreadFunctionRegistry threadFR = new CurrentThreadFunctionRegistry(oldFR);
* FunctionRegistry.set(ARQ.getContext(), threadFR);
* </code>
*
* <p>and (for SPIN) do the same for the SPINThreadPropertyFunctionRegistry.</p>
*
*
* @author Holger Knublauch
*/
public class CurrentThreadFunctionRegistry extends FunctionRegistry {

private static ThreadLocal<CurrentThreadFunctions> localFunctions = new ThreadLocal<>();

private static CurrentThreadFunctionRegistry singleton = new CurrentThreadFunctionRegistry(FunctionRegistry.get());


public static CurrentThreadFunctionRegistry get() {
return singleton;
}


/**
* Registers a set of extra SPIN functions from a given Model for the current
* Thread.
Expand All @@ -92,8 +92,8 @@ public static Runnable register(Model model) {
};
}
}


/**
* Unregisters the current Model for the current Thread.
* @param old the old functions that shall be restored or null
Expand All @@ -106,21 +106,21 @@ private static void unregister(CurrentThreadFunctions old) {
localFunctions.remove();
}
}

public static CurrentThreadFunctions getFunctions() {
return localFunctions.get();
}

private FunctionRegistry base;

private CurrentThreadFunctionRegistry(FunctionRegistry base) {
this.base = base;
}


@Override
public FunctionFactory get(String uri) {
FunctionFactory b = base.get(uri);
public FunctionFactory getFunctionFactory(String uri) {
FunctionFactory b = base.getFunctionFactory(uri);
if(b != null) {
return b;
}
Expand All @@ -141,7 +141,7 @@ public boolean isRegistered(String uri) {
return true;
}
else {
return get(uri) != null;
return getFunctionFactory(uri) != null;
}
}

Expand All @@ -154,19 +154,21 @@ public Iterator<String> keys() {


@Override
public void put(String uri, Class<?> funcClass) {
public FunctionRegistry put(String uri, Class<?> funcClass) {
base.put(uri, funcClass);
return this;
}


@Override
public void put(String uri, FunctionFactory f) {
public FunctionRegistry put(String uri, FunctionFactory f) {
base.put(uri, f);
return this;
}


@Override
public FunctionFactory remove(String uri) {
return base.remove(uri);
public void remove(String uri) {
base.remove(uri);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/topbraid/jenax/util/DiffGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ExtendedIterator<Triple> find(Node s, Node p, Node o) {

@Override
public ExtendedIterator<Triple> find(Triple m) {
return find(m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject());
return find(m.getSubject(), m.getPredicate(), m.getObject());
}


Expand Down
23 changes: 11 additions & 12 deletions src/main/java/org/topbraid/jenax/util/ExceptionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static RuntimeException throwRootCauseUnchecked(Throwable t) {
return ExceptionUtil.throwDeepCauseChecked(t,RuntimeException.class);
}


/**
* Does not return:
* throws an unchecked exception, based on <code>t</code>.
Expand All @@ -68,9 +68,9 @@ public static RuntimeException throwUnchecked(Throwable t) {
throw new RuntimeException(t);
}


/**
* Always
* Always
* throw an exception; based on <code>t</code>.
* The <code>getCause</code> chain of <code>t</code>
* is analyzed, and then,
Expand Down Expand Up @@ -109,7 +109,7 @@ public static <EX extends Throwable> EX throwDeepCauseChecked(Throwable t, Class
if (firstError!=null) { throw firstError; }
if (firstEX!=null) { throw firstEX; }
if (firstRTE!=null) { throw firstRTE; }

// Wrap original problem in clazz.
EX rslt = null;
try {
Expand Down Expand Up @@ -138,11 +138,11 @@ public static <EX extends Throwable> EX throwDeepCauseChecked(Throwable t, Class
* from its cause if the given throwable has no own message.
* Will return null if no explicit message is provided
* in the throwable or any of its causes.
*
*
* The intent is to get "The real message" instead of
* "x.y.SomeException: The real message" when the throwable
* bearing the real message is wrapped without a new message.
*
*
* @see Throwable#getMessage()
* @see Throwable#getCause()
*/
Expand All @@ -164,7 +164,7 @@ public static String getDeepMessage(Throwable t) {
// It's a custom message, good!
return msg;
}

public static String getStackTrace(Throwable t) {
if (t == null) return null;
StringWriter writer = new StringWriter();
Expand All @@ -181,21 +181,21 @@ private static <TT extends Throwable> TT chooseNonNullCorrectClass(Class<? exten

/**
* True if the given throwable or one of its causes (via {@link Throwable#getCause()})
* is an instance of the given class.
* is an instance of the given class.
*/
public static boolean hasDeepCause(Throwable t, Class<? extends Throwable> throwableClass) {
return t != null && getDeepCause(t, throwableClass) != null;
}

@SuppressWarnings("unchecked")
public static <EX extends Throwable> EX getDeepCause(Throwable t, Class<? extends EX> clazz) {
if (t == null ) {
throw new NullPointerException();
}
// Walk chain finding first item of each interesting class.
for (Throwable tt=t;tt!=null;tt=tt.getCause()) {
if (clazz.isInstance(tt)) {
return (EX)tt;
if (clazz.isInstance(tt)) {
return (EX)tt;
}
}
return null;
Expand Down Expand Up @@ -259,7 +259,6 @@ public static String shortenStackTraceForServletCall(String stackTrace) {
*
* @see #shortenStackTrace(String, String)
*/
@SuppressWarnings("serial")
public static Throwable withServletContainerStackOmitted(Throwable t) {
if (t == null) return null;
return new Throwable(t) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/topbraid/jenax/util/JenaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ private static Node invokeFunction(Resource function, ExprList args, Dataset dat
DatasetGraph dsg = dataset.asDatasetGraph();
Context cxt = ARQ.getContext().copy();
cxt.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
FunctionEnv env = new ExecutionContext(cxt, dsg.getDefaultGraph(), dsg, null);
FunctionEnv env = ExecutionContext.create(dsg, cxt);
try {
NodeValue r = expr.eval(BindingRoot.create(), env);
if (r != null) {
Expand All @@ -1182,7 +1182,7 @@ public static Node invokeFunction3(Resource function, Node argument1, Node argum
* @return a new Query with the bindings applied
*/
public static Query queryWithSubstitutions(Query query, final Map<Var, Node> substitutions) {
Query result = QueryTransformOps.transform(query, substitutions);
Query result = QueryTransformOps.replaceVars(query, substitutions);

// TODO: Replace this hack once there is a Jena patch
if (result.hasHaving()) {
Expand Down
48 changes: 25 additions & 23 deletions src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import org.apache.jena.graph.Graph;
import org.apache.jena.graph.compose.MultiUnion;
import org.apache.jena.mem.GraphMemBase;
import org.apache.jena.mem.GraphMem;
import org.apache.jena.memvalue.GraphMemValue;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.Model;
Expand All @@ -31,22 +32,22 @@
* This is an extension point for the SPIN library
* allowing modification of some low level utilities
* that are exposed through {@link JenaUtil}.
*
*
* Note: Unstable - should not be used outside of TopBraid.
*
*
* @author Jeremy Carroll
*/
public class JenaUtilHelper {

/**
* Return a multiunion.
* @return the MultiUnion graph
*/
public MultiUnion createMultiUnion() {
return new MultiUnion();
}


/**
* Return a multiunion, initialized with the given graphs.
* @param graphs the Graphs to convert
Expand All @@ -56,7 +57,7 @@ public MultiUnion createMultiUnion(Iterator<Graph> graphs) {
return new MultiUnion(graphs);
}


/**
* Return a multiunion, initialized with the given graphs.
* @param graphs the Graphs to convert
Expand All @@ -65,8 +66,8 @@ public MultiUnion createMultiUnion(Iterator<Graph> graphs) {
public MultiUnion createMultiUnion(Graph[] graphs) {
return new MultiUnion(graphs);
}


/**
* A memory graph with no reification.
* @return the default Graph
Expand All @@ -75,7 +76,7 @@ public Graph createDefaultGraph() {
return GraphFactory.createDefaultGraph();
}


/**
* Returns true if optimizations for faster graphs should
* be applied; false if graph is slower. A typical fast graph
Expand All @@ -86,34 +87,35 @@ public Graph createDefaultGraph() {
* @param graph A simple graph, not a {@link MultiUnion}
* @return true if the graph is fast
*/
public boolean isMemoryGraph(Graph graph) {
return (graph instanceof GraphMemBase);
@SuppressWarnings("deprecation")
public boolean isMemoryGraph(Graph graph) {
return (graph instanceof GraphMem) || (graph instanceof GraphMemValue );
}


public Model asReadOnlyModel(Model m) {
return m;
}


public Graph asReadOnlyGraph(Graph g) {
return g;
}


public OntModel createOntologyModel(OntModelSpec spec, Model base) {
return ModelFactory.createOntologyModel(spec, base);
}


public Graph createConcurrentGraph() {
return createDefaultGraph();
}


public void setGraphReadOptimization(boolean b) {
}

public Graph deepCloneReadOnlyGraph(Graph g) {
return asReadOnlyGraph(g);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public QueryExecution create(Query query, Model model, QuerySolution initialBind
return QueryExecution.create()
.query(query)
.model(model)
.initialBinding(initialBinding)
.substitution(initialBinding)
.build();
}

Expand Down
Loading