- All Implemented Interfaces:
org.apache.jena.shared.PrefixMapping
A Parameterized SPARQL String is a SPARQL query/update into which values may be injected.
Injecting Values
Values may be injected in several ways:
- By treating a variable in the SPARQL string as a parameter
- Using JDBC style positional parameters
- Appending values directly to the command text being built
Variable Parameters
Any variable in the command may have a value injected to it, injecting a value replaces all usages of that variable in the command i.e. substitutes the variable for a constant, injection is done by textual substitution.
Positional Parameters
You can use JDBC style positional parameters if you prefer, a JDBC style
parameter is a single ?
followed by whitespace or certain punctuation
characters (currently ; , .
). Positional parameters have a unique
index which reflects the order in which they appear in the string. Positional
parameters use a zero based index.
Buffer Usage
Additionally you may use this purely as a StringBuffer
replacement
for creating queries since it provides a large variety of convenience methods
for appending things either as-is or as nodes (which causes appropriate
formatting to be applied).
Intended Usage
The intended usage of this is where using a QuerySolutionMap
as
initial bindings is either inappropriate or not possible e.g.
- Generating query/update strings in code without lots of error prone and messy string concatenation
- Preparing a query/update for remote execution
- Where you do not want to simply say some variable should have a certain value but rather wish to insert constants into the query/update in place of variables
- Defending against SPARQL injection when creating a query/update using some external input, see SPARQL Injection notes for limitations.
- Provide a more convenient way to prepend common prefixes to your query
This class is useful for preparing both queries and updates hence the generic
name as it provides programmatic ways to replace variables in the query with
constants and to add prefix and base declarations. A Query
or
UpdateRequest
can be created using the asQuery()
and
asUpdate()
methods assuming the command an instance represents is
actually valid as a query/update.
Warnings
- Note that this class does not in any way check that your command is
syntactically correct until such time as you try and parse it as a
Query
orUpdateRequest
. - Also note that injection is done purely based on textual replacement, it does not understand or respect variable scope in any way. For example if your command text contains sub queries you should ensure that variables within the sub query which you don't want replaced have distinct names from those in the outer query you do want replaced (or vice versa)
SPARQL Injection Notes
While this class was in part designed to prevent SPARQL injection it is by no means foolproof because it works purely at the textual level. The current version of the code addresses some possible attack vectors that the developers have identified but we do not claim to be sufficiently devious to have thought of and prevented every possible attack vector.
Therefore we strongly recommend that users concerned about SPARQL Injection attacks perform their own validation on provided parameters and test their use of this class themselves prior to its use in any security conscious deployment. We also recommend that users do not use easily guess-able variable names for their parameters as these can allow a chained injection attack though generally speaking the code should prevent these.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.jena.shared.PrefixMapping
org.apache.jena.shared.PrefixMapping.Factory, org.apache.jena.shared.PrefixMapping.IllegalPrefixException, org.apache.jena.shared.PrefixMapping.JenaLockedException
-
Field Summary
Fields inherited from interface org.apache.jena.shared.PrefixMapping
Extended, Standard
-
Constructor Summary
ConstructorDescriptionCreates a new parameterized string with an empty command textParameterizedSparqlString
(String command) Creates a new parameterized stringParameterizedSparqlString
(String command, String base) Creates a new parameterized stringParameterizedSparqlString
(String command, String base, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString
(String command, QuerySolutionMap map) Creates a new parameterized stringParameterizedSparqlString
(String command, QuerySolutionMap map, String base) Creates a new parameterized stringParameterizedSparqlString
(String command, QuerySolutionMap map, String base, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString
(String command, QuerySolutionMap map, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString
(String command, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringCreates a new parameterized stringParameterizedSparqlString
(QuerySolutionMap map, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString
(org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized string -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(boolean b) Appends a boolean as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(boolean)
methodvoid
append
(char c) Appends a character as-is to the existing command text, to ensure correct formatting when used as a constant consider using one of theappendLiteral()
methodsvoid
append
(double d) Appends a double as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(double)
methodvoid
append
(float f) Appends a float as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(float)
methodvoid
append
(int i) Appends an integer as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(int)
methodvoid
append
(long l) Appends a long as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(long)
methodvoid
Appends an object as-is to the existing command text, to ensure correct formatting when used as a constant consider converting into a more specific type and using the appropriateappendLiteral()
,appendIri()
orappendNode
methodsvoid
Appends some text as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(String)
orappendIri(String)
method as appropriatevoid
Appends a URI to the command text as a constant using appropriate formattingvoid
appendIri
(org.apache.jena.irix.IRIx iri) Appends an IRI to the command text as a constant using appropriate formattingvoid
appendLiteral
(boolean b) Appends a boolean to the command text as a constant using appropriate formattingvoid
appendLiteral
(double d) Appends a double to the command text as a constant using appropriate formattingvoid
appendLiteral
(float f) Appends a float to the command text as a constant using appropriate formattingvoid
appendLiteral
(int i) Appends an integer to the command text as a constant using appropriate formattingvoid
appendLiteral
(long l) Appends a long to the command text as a constant using appropriate formattingvoid
appendLiteral
(String value) Appends a simple literal as a constant using appropriate formattingvoid
appendLiteral
(String value, String lang) Appends a literal with a lexical value and language to the command text as a constant using appropriate formattingvoid
appendLiteral
(String value, org.apache.jena.datatypes.RDFDatatype datatype) Appends a Typed Literal to the command text as a constant using appropriate formattingvoid
Appends a date time to the command text as a constant using appropriate formattingvoid
appendNode
(org.apache.jena.graph.Node n) Appends a Node to the command text as a constant using appropriate formattingvoid
appendNode
(org.apache.jena.rdf.model.RDFNode n) Appends a Node to the command text as a constant using appropriate formattingasQuery()
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aQuery
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aQuery
using the givenSyntax
syntaxasUpdate()
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aUpdateRequest
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aUpdateRequest
using the givenSyntax
org.apache.jena.shared.PrefixMapping
void
clearParam
(int index) Clears the value for a positional parametervoid
clearParam
(String var) Clears the value for a variable or values parameter so the given variable will not * have a value injectedvoid
Clears all values for variable, values and positional parameterscopy()
Makes a full copy of this parameterized stringcopy
(boolean copyParams) Makes a copy of the command text, base URI and prefix mapping and optionally copies parameter valuescopy
(boolean copyParams, boolean copyBase, boolean copyPrefixes) Makes a copy of the command text and optionally copies other aspectsexpandPrefix
(String prefixed) Gets the Base URI which will be prepended to a queryGets the basic Command TextGets the eligible positional parameters i.e. detected positional parameters that may be set in the command string as it currently standsgetNsPrefixURI
(String prefix) getNsURIPrefix
(String uri) org.apache.jena.graph.Node
getParam
(int index) Gets the current value for a positional parameterorg.apache.jena.graph.Node
Gets the current value for a variable parameterGets the map of currently set positional parameters, this will be an unmodifiable mapGets the syntax used for parsing when callingasQuery()
orasUpdate()
Gets the map of currently set variable parameters, this will be an unmodifiable mapgetVars()
Gets the variable names which are currently treated as variable parameters (i.e. have values set for them)boolean
org.apache.jena.shared.PrefixMapping
lock()
int
org.apache.jena.shared.PrefixMapping
removeNsPrefix
(String prefix) boolean
samePrefixMappingAs
(org.apache.jena.shared.PrefixMapping other) void
setBaseUri
(String base) Sets the Base URI which will be prepended to the query/updatevoid
setCommandText
(String command) Sets the command text, overwriting any existing command text.void
Sets a positional parameter to an IRIvoid
Sets a positional parameter to an IRIvoid
setIri
(int index, org.apache.jena.irix.IRIx iri) Sets a positional parameter to an IRIvoid
Sets a variable parameter to an IRIvoid
Sets a variable parameter to an IRIvoid
Sets a variable parameter to an IRIvoid
setLiteral
(int index, boolean value) Sets a positional parameter to a boolean literalvoid
setLiteral
(int index, double d) Sets a positional parameter to a double literalvoid
setLiteral
(int index, float f) Sets a positional parameter to a float literalvoid
setLiteral
(int index, int i) Sets a positional parameter to an integer literalvoid
setLiteral
(int index, long l) Sets a positional parameter to an integer literalvoid
setLiteral
(int index, String value) Sets a positional parameter to a literalvoid
setLiteral
(int index, String value, String lang) Sets a positional parameter to a literal with a languagevoid
setLiteral
(int index, String value, org.apache.jena.datatypes.RDFDatatype datatype) Sets a positional parameter to a typed literalvoid
setLiteral
(int index, Calendar dt) Sets a positional parameter to a date time literalvoid
setLiteral
(int index, org.apache.jena.rdf.model.Literal lit) Sets a positional parameter to a Literalvoid
setLiteral
(String var, boolean value) Sets a variable parameter to a boolean literalvoid
setLiteral
(String var, double d) Sets a variable parameter to a double literalvoid
setLiteral
(String var, float f) Sets a variable parameter to a float literalvoid
setLiteral
(String var, int i) Sets a variable parameter to an integer literalvoid
setLiteral
(String var, long l) Sets a variable parameter to an integer literalvoid
setLiteral
(String var, String value) Sets a variable parameter to a literalvoid
setLiteral
(String var, String value, String lang) Sets a variable parameter to a literal with a languagevoid
setLiteral
(String var, String value, org.apache.jena.datatypes.RDFDatatype datatype) Sets a variable parameter to a typed literalvoid
setLiteral
(String var, Calendar dt) Sets a variable parameter to a date time literalvoid
setLiteral
(String var, org.apache.jena.rdf.model.Literal lit) Sets a variable parameter to a Literalorg.apache.jena.shared.PrefixMapping
setNsPrefix
(String prefix, String uri) org.apache.jena.shared.PrefixMapping
setNsPrefixes
(Map<String, String> map) org.apache.jena.shared.PrefixMapping
setNsPrefixes
(org.apache.jena.shared.PrefixMapping other) void
setParam
(int index, org.apache.jena.graph.Node n) Sets a Positional Parametervoid
setParam
(int index, org.apache.jena.rdf.model.RDFNode n) Sets a positional parametervoid
Sets a variable parametervoid
Sets a variable parametervoid
Sets the Parametersvoid
setRowValues
(String valueName, Collection<List<? extends org.apache.jena.rdf.model.RDFNode>> rowItems) Allocate multiple lists of variables to a single VALUES valueName.
Using "valuesName" with list(list(prop_A, obj_A), list(prop_B, obj_B)) on query "VALUES (?void
Sets the syntax used for parsing when callingasQuery()
orasUpdate()
void
setValues
(String valueName, Collection<? extends org.apache.jena.rdf.model.RDFNode> items) Assign a VALUES valueName with a multiple items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.
Using "valueName" with list(prop_A, obj_A) on query "VALUES (?void
Assign a VALUES valueName with a single item.
Using "valueName" with Literal obj_A on query "VALUES ?void
setValues
(Map<String, Collection<? extends org.apache.jena.rdf.model.RDFNode>> itemsMap) ** Sets a map of VALUES valueNames and their items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.toString()
This method is where the actual work happens, the original command text is always preserved and we just generated a temporary command string by prepending the defined Base URI and namespace prefixes at the start of the command and injecting the set parameters into a copy of that base command string and return the resulting command.org.apache.jena.shared.PrefixMapping
withDefaultMappings
(org.apache.jena.shared.PrefixMapping map)
-
Constructor Details
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command
- Raw Command Textmap
- Initial Parameters to injectbase
- Base URI
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command
- Raw Command Textmap
- Initial Parameters to inject
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command
- Raw Command Textbase
- Base URI
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command
- Raw Command Text
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
map
- Initial Parameters to inject
-
ParameterizedSparqlString
public ParameterizedSparqlString()Creates a new parameterized string with an empty command text
-
Method Details
-
getSyntax
Gets the syntax used for parsing when callingasQuery()
orasUpdate()
- Returns:
- Syntax
-
setSyntax
Sets the syntax used for parsing when callingasQuery()
orasUpdate()
- Parameters:
syntax
- Syntax
-
setCommandText
Sets the command text, overwriting any existing command text. If you want to append to the command text use one of theappend(String)
,appendIri(String)
,appendLiteral(String)
orappendNode(Node)
methods instead- Parameters:
command
- Command Text
-
append
Appends some text as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(String)
orappendIri(String)
method as appropriate- Parameters:
text
- Text to append
-
append
public void append(char c) Appends a character as-is to the existing command text, to ensure correct formatting when used as a constant consider using one of theappendLiteral()
methods- Parameters:
c
- Character to append
-
append
public void append(boolean b) Appends a boolean as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(boolean)
method- Parameters:
b
- Boolean to append
-
append
public void append(double d) Appends a double as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(double)
method- Parameters:
d
- Double to append
-
append
public void append(float f) Appends a float as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(float)
method- Parameters:
f
- Float to append
-
append
public void append(int i) Appends an integer as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(int)
method- Parameters:
i
- Integer to append
-
append
public void append(long l) Appends a long as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(long)
method- Parameters:
l
- Long to append
-
append
Appends an object as-is to the existing command text, to ensure correct formatting when used as a constant consider converting into a more specific type and using the appropriateappendLiteral()
,appendIri()
orappendNode
methods- Parameters:
obj
- Object to append
-
appendNode
public void appendNode(org.apache.jena.graph.Node n) Appends a Node to the command text as a constant using appropriate formatting- Parameters:
n
- Node to append
-
appendNode
public void appendNode(org.apache.jena.rdf.model.RDFNode n) Appends a Node to the command text as a constant using appropriate formatting- Parameters:
n
- Node to append
-
appendIri
Appends a URI to the command text as a constant using appropriate formatting- Parameters:
uri
- URI to append
-
appendIri
public void appendIri(org.apache.jena.irix.IRIx iri) Appends an IRI to the command text as a constant using appropriate formatting- Parameters:
iri
- IRI to append
-
appendLiteral
Appends a simple literal as a constant using appropriate formatting- Parameters:
value
- Lexical Value
-
appendLiteral
Appends a literal with a lexical value and language to the command text as a constant using appropriate formatting- Parameters:
value
- Lexical Valuelang
- Language
-
appendLiteral
Appends a Typed Literal to the command text as a constant using appropriate formatting- Parameters:
value
- Lexical Valuedatatype
- Datatype
-
appendLiteral
public void appendLiteral(boolean b) Appends a boolean to the command text as a constant using appropriate formatting- Parameters:
b
- Boolean to append
-
appendLiteral
public void appendLiteral(int i) Appends an integer to the command text as a constant using appropriate formatting- Parameters:
i
- Integer to append
-
appendLiteral
public void appendLiteral(long l) Appends a long to the command text as a constant using appropriate formatting- Parameters:
l
- Long to append
-
appendLiteral
public void appendLiteral(float f) Appends a float to the command text as a constant using appropriate formatting- Parameters:
f
- Float to append
-
appendLiteral
public void appendLiteral(double d) Appends a double to the command text as a constant using appropriate formatting- Parameters:
d
- Double to append
-
appendLiteral
Appends a date time to the command text as a constant using appropriate formatting- Parameters:
dt
- Date Time to append
-
getCommandText
Gets the basic Command TextNote: This will not reflect any injected parameters, to see the command with injected parameters invoke the
toString()
method- Returns:
- Command Text
-
setBaseUri
Sets the Base URI which will be prepended to the query/update- Parameters:
base
- Base URI
-
getBaseUri
Gets the Base URI which will be prepended to a query- Returns:
- Base URI
-
setParams
Sets the Parameters- Parameters:
map
- Parameters
-
setParam
public void setParam(int index, org.apache.jena.graph.Node n) Sets a Positional ParameterSetting a parameter to null is equivalent to calling
clearParam(int)
for the given variable- Parameters:
index
- Positional Indexn
- Node
-
setParam
Sets a variable parameterSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variablen
- Value
-
setParam
public void setParam(int index, org.apache.jena.rdf.model.RDFNode n) Sets a positional parameterSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
index
- Positional Indexn
- Node
-
setParam
Sets a variable parameterSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variablen
- Value
-
setIri
Sets a positional parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional Indexiri
- IRI
-
setIri
Sets a variable parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variableiri
- IRI
-
setIri
public void setIri(int index, org.apache.jena.irix.IRIx iri) Sets a positional parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional Indexiri
- IRI
-
setIri
Sets a variable parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variableiri
- IRI
-
setIri
Sets a positional parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional Indexurl
- URL
-
setIri
Sets a variable parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variableurl
- URL used as IRI
-
setLiteral
public void setLiteral(int index, org.apache.jena.rdf.model.Literal lit) Sets a positional parameter to a LiteralSetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional Indexlit
- Value
-
setLiteral
Sets a variable parameter to a LiteralSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variablelit
- Value
-
setLiteral
Sets a positional parameter to a literalSetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional Indexvalue
- Lexical Value
-
setLiteral
Sets a variable parameter to a literalSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variablevalue
- Lexical Value
-
setLiteral
Sets a positional parameter to a literal with a languageSetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional indexvalue
- Lexical Valuelang
- Language
-
setLiteral
Sets a variable parameter to a literal with a languageSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variablevalue
- Lexical Valuelang
- Language
-
setLiteral
Sets a positional parameter to a typed literalSetting a parameter to null is equivalent to calling
clearParam(int)
for the given index- Parameters:
index
- Positional Indexvalue
- Lexical Valuedatatype
- Datatype
-
setLiteral
Sets a variable parameter to a typed literalSetting a parameter to null is equivalent to calling
clearParam(String)
for the given variable- Parameters:
var
- Variablevalue
- Lexical Valuedatatype
- Datatype
-
setLiteral
public void setLiteral(int index, boolean value) Sets a positional parameter to a boolean literal- Parameters:
index
- Positional Indexvalue
- boolean
-
setLiteral
Sets a variable parameter to a boolean literal- Parameters:
var
- Variablevalue
- boolean
-
setLiteral
public void setLiteral(int index, int i) Sets a positional parameter to an integer literal- Parameters:
index
- Positional Indexi
- Integer Value
-
setLiteral
Sets a variable parameter to an integer literal- Parameters:
var
- Variablei
- Integer Value
-
setLiteral
public void setLiteral(int index, long l) Sets a positional parameter to an integer literal- Parameters:
index
- Positional Indexl
- Integer Value
-
setLiteral
Sets a variable parameter to an integer literal- Parameters:
var
- Variablel
- Integer Value
-
setLiteral
public void setLiteral(int index, float f) Sets a positional parameter to a float literal- Parameters:
index
- Positional Indexf
- Float value
-
setLiteral
Sets a variable parameter to a float literal- Parameters:
var
- Variablef
- Float value
-
setLiteral
public void setLiteral(int index, double d) Sets a positional parameter to a double literal- Parameters:
index
- Positional Indexd
- Double value
-
setLiteral
Sets a variable parameter to a double literal- Parameters:
var
- Variabled
- Double value
-
setLiteral
Sets a positional parameter to a date time literal- Parameters:
index
- Positional Indexdt
- Date Time value
-
setLiteral
Sets a variable parameter to a date time literal- Parameters:
var
- Variabledt
- Date Time value
-
getParam
Gets the current value for a variable parameter- Parameters:
var
- Variable- Returns:
- Current value or null if not set
-
getParam
public org.apache.jena.graph.Node getParam(int index) Gets the current value for a positional parameter- Parameters:
index
- Positional Index- Returns:
- Current value or null if not set
-
getVars
Gets the variable names which are currently treated as variable parameters (i.e. have values set for them)- Returns:
- Iterator of variable names
-
getVariableParameters
Gets the map of currently set variable parameters, this will be an unmodifiable map- Returns:
- Map of variable names and values
-
getPositionalParameters
Gets the map of currently set positional parameters, this will be an unmodifiable map- Returns:
- Map of positional indexes and values
-
getEligiblePositionalParameters
Gets the eligible positional parameters i.e. detected positional parameters that may be set in the command string as it currently stands- Returns:
- Iterator of eligible positional parameters
-
clearParam
Clears the value for a variable or values parameter so the given variable will not * have a value injected- Parameters:
var
- Variable
-
clearParam
public void clearParam(int index) Clears the value for a positional parameter- Parameters:
index
- Positional Index
-
clearParams
public void clearParams()Clears all values for variable, values and positional parameters -
toString
This method is where the actual work happens, the original command text is always preserved and we just generated a temporary command string by prepending the defined Base URI and namespace prefixes at the start of the command and injecting the set parameters into a copy of that base command string and return the resulting command.
This class makes no guarantees about the validity of the returned string for use as a SPARQL Query or Update, for example if a variable parameter was injected which was mentioned in the SELECT variables list you'd have a syntax error when you try to parse the query. If you run into issues like this try using a mixture of variable and positional parameters.
- Overrides:
toString
in classObject
- Throws:
ARQException
- May be thrown if the code detects a SPARQL Injection vulnerability because of the interaction of the command string and the injected variables
-
asQuery
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aQuery
- Returns:
- Query if the command text is a valid SPARQL query
- Throws:
QueryException
- Thrown if the command text does not parse
-
asQuery
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aQuery
using the givenSyntax
syntax- Returns:
- Query if the command text is a valid SPARQL query
- Throws:
QueryException
- Thrown if the command text does not parse
-
asUpdate
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aUpdateRequest
- Returns:
- Update if the command text is a valid SPARQL Update request (one/more update commands)
-
asUpdate
Attempts to take the command text with parameters injected from thetoString()
method and parse it as aUpdateRequest
using the givenSyntax
- Returns:
- Update if the command text is a valid SPARQL Update request (one/more update commands)
-
copy
Makes a full copy of this parameterized string- Returns:
- Copy of the string
-
copy
Makes a copy of the command text, base URI and prefix mapping and optionally copies parameter values- Parameters:
copyParams
- Whether to copy parameters- Returns:
- Copy of the string
-
copy
Makes a copy of the command text and optionally copies other aspects- Parameters:
copyParams
- Whether to copy parameterscopyBase
- Whether to copy the Base URIcopyPrefixes
- Whether to copy the prefix mappings- Returns:
- Copy of the string
-
setNsPrefix
- Specified by:
setNsPrefix
in interfaceorg.apache.jena.shared.PrefixMapping
-
removeNsPrefix
- Specified by:
removeNsPrefix
in interfaceorg.apache.jena.shared.PrefixMapping
-
clearNsPrefixMap
public org.apache.jena.shared.PrefixMapping clearNsPrefixMap()- Specified by:
clearNsPrefixMap
in interfaceorg.apache.jena.shared.PrefixMapping
-
setNsPrefixes
- Specified by:
setNsPrefixes
in interfaceorg.apache.jena.shared.PrefixMapping
-
getNsPrefixURI
- Specified by:
getNsPrefixURI
in interfaceorg.apache.jena.shared.PrefixMapping
-
getNsURIPrefix
- Specified by:
getNsURIPrefix
in interfaceorg.apache.jena.shared.PrefixMapping
-
getNsPrefixMap
- Specified by:
getNsPrefixMap
in interfaceorg.apache.jena.shared.PrefixMapping
-
expandPrefix
- Specified by:
expandPrefix
in interfaceorg.apache.jena.shared.PrefixMapping
-
shortForm
- Specified by:
shortForm
in interfaceorg.apache.jena.shared.PrefixMapping
-
qnameFor
- Specified by:
qnameFor
in interfaceorg.apache.jena.shared.PrefixMapping
-
hasNoMappings
public boolean hasNoMappings()- Specified by:
hasNoMappings
in interfaceorg.apache.jena.shared.PrefixMapping
-
numPrefixes
public int numPrefixes()- Specified by:
numPrefixes
in interfaceorg.apache.jena.shared.PrefixMapping
-
lock
public org.apache.jena.shared.PrefixMapping lock()- Specified by:
lock
in interfaceorg.apache.jena.shared.PrefixMapping
-
setValues
public void setValues(String valueName, Collection<? extends org.apache.jena.rdf.model.RDFNode> items) Assign a VALUES valueName with a multiple items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.
Using "valueName" with list(prop_A, obj_A) on query "VALUES (?p ?o) {?valueName}" * would produce "VALUES (?p ?o) {(prop_A obj_A)}".- Parameters:
valueName
-items
-
-
setValues
Assign a VALUES valueName with a single item.
Using "valueName" with Literal obj_A on query "VALUES ?o {?valueName}" would produce * "VALUES ?o {obj_A}".- Parameters:
valueName
-item
-
-
setValues
** Sets a map of VALUES valueNames and their items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.- Parameters:
itemsMap
-
-
setRowValues
public void setRowValues(String valueName, Collection<List<? extends org.apache.jena.rdf.model.RDFNode>> rowItems) Allocate multiple lists of variables to a single VALUES valueName.
Using "valuesName" with list(list(prop_A, obj_A), list(prop_B, obj_B)) on query "VALUES (?p ?o) {?valuesName}" would produce "VALUES (?p ?o) {(prop_A obj_A) * (prop_B obj_B)}".- Parameters:
valueName
-rowItems
-
-