Package org.topbraid.jenax.functions
Class CurrentThreadFunctionRegistry
- java.lang.Object
-
- org.apache.jena.sparql.function.FunctionRegistry
-
- org.topbraid.jenax.functions.CurrentThreadFunctionRegistry
-
public class CurrentThreadFunctionRegistry extends org.apache.jena.sparql.function.FunctionRegistryAn 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.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:
Model model = ... a Model with extra SHACL/SPIN functions CurrentThreadFunctions old = CurrentThreadFunctionRegistry.register(model); try { // run SPARQL queries here } finally { CurrentThreadFunctionRegistry.unregister(old); }In preparation of the above, the application should start up with code such as
FunctionRegistry oldFR = FunctionRegistry.get(); CurrentThreadFunctionRegistry threadFR = new CurrentThreadFunctionRegistry(oldFR); FunctionRegistry.set(ARQ.getContext(), threadFR);and (for SPIN) do the same for the SPINThreadPropertyFunctionRegistry.
- Author:
- Holger Knublauch
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CurrentThreadFunctionRegistryget()org.apache.jena.sparql.function.FunctionFactoryget(String uri)static CurrentThreadFunctionsgetFunctions()booleanisRegistered(String uri)Iterator<String>keys()voidput(String uri, Class<?> funcClass)voidput(String uri, org.apache.jena.sparql.function.FunctionFactory f)static Runnableregister(org.apache.jena.rdf.model.Model model)Registers a set of extra SPIN functions from a given Model for the current Thread.org.apache.jena.sparql.function.FunctionFactoryremove(String uri)
-
-
-
Method Detail
-
get
public static CurrentThreadFunctionRegistry get()
-
register
public static Runnable register(org.apache.jena.rdf.model.Model model)
Registers a set of extra SPIN functions from a given Model for the current Thread.- Parameters:
model- the Model containing the SPIN functions- Returns:
- a Runnable that must be called (in a finally block) when done to restore the previous state
-
getFunctions
public static CurrentThreadFunctions getFunctions()
-
get
public org.apache.jena.sparql.function.FunctionFactory get(String uri)
- Overrides:
getin classorg.apache.jena.sparql.function.FunctionRegistry
-
isRegistered
public boolean isRegistered(String uri)
- Overrides:
isRegisteredin classorg.apache.jena.sparql.function.FunctionRegistry
-
keys
public Iterator<String> keys()
- Overrides:
keysin classorg.apache.jena.sparql.function.FunctionRegistry
-
put
public void put(String uri, Class<?> funcClass)
- Overrides:
putin classorg.apache.jena.sparql.function.FunctionRegistry
-
put
public void put(String uri, org.apache.jena.sparql.function.FunctionFactory f)
- Overrides:
putin classorg.apache.jena.sparql.function.FunctionRegistry
-
remove
public org.apache.jena.sparql.function.FunctionFactory remove(String uri)
- Overrides:
removein classorg.apache.jena.sparql.function.FunctionRegistry
-
-