public class APIQuery extends Object implements VarSupply, WantsMetadata
Modifier and Type | Class and Description |
---|---|
protected static class |
APIQuery.FilterExpressions |
static interface |
APIQuery.QueryBasis
The parameters that form the basis of an API Query.
|
Modifier and Type | Field and Description |
---|---|
protected Set<String> |
allowedReserved |
protected List<RDFQ.Triple> |
basicGraphTriples
List of pseudo-triples which form the basic graph pattern element of this
query.
|
long |
cacheExpiryMilliseconds |
protected String |
defaultLanguage |
protected int |
defaultPageSize |
List<PendingParameterValue> |
deferredFilters |
protected boolean |
enableETags |
protected List<RenderExpression> |
filterExpressions
List of little infix expressions (operands must be RDFQ.Any's) which are
SPARQL filters for this query.
|
protected String |
fixedSelect |
protected String |
graphName |
protected String |
graphTemplate |
protected String |
itemTemplate |
protected int |
maxPageSize |
protected Set<String> |
metadataOptions |
protected List<List<RDFQ.Triple>> |
optionalGraphTriples |
protected int |
pageNumber |
protected int |
pageSize |
static String |
PREFIX_VAR |
protected boolean |
purging |
static Variable |
SELECT_VAR |
protected ShortnameService |
sns |
protected String |
sortByOrderSpecs |
protected boolean |
sortByOrderSpecsFrozen |
protected com.hp.hpl.jena.rdf.model.Resource |
subjectResource |
protected TextSearchConfig |
textSearchConfig |
protected int |
varcount |
protected Map<Variable,Param.Info> |
varInfo |
static Pattern |
varPattern
Pattern for matching SPARQL query variables (including the leading '?').
|
protected Map<String,Variable> |
varsForPropertyChains
Map from property chain names (ie dotted strings) to the variable at the
end of that chain.
|
protected ValTranslator |
vt |
protected StringBuffer |
whereExpressions |
Constructor and Description |
---|
APIQuery(APIQuery.QueryBasis qb) |
APIQuery(APIQuery other) |
Modifier and Type | Method and Description |
---|---|
void |
addAllowReserved(String name) |
void |
addFilterExpression(RenderExpression e) |
void |
addMetadataOptions(String[] options) |
protected void |
addNameProp(Param param,
String literal) |
void |
addNumericRangeFilter(Variable v,
double x,
double dx) |
protected void |
addPropertyHasntValue(Param param) |
protected Variable |
addPropertyHasValue_REV(Param param) |
protected void |
addPropertyHasValue(Param param) |
protected void |
addPropertyHasValue(Param param,
String val) |
protected void |
addRangeFilter(Param param,
String val,
String op) |
void |
addSearchTriple(String val) |
APIQuery |
addSubjectHasProperty(com.hp.hpl.jena.rdf.model.Resource P,
Any O) |
void |
addTriplePatterns(List<RDFQ.Triple> triples)
Update this query-generator with a bunch of basic graph triples to use.
|
void |
addWhere(String whereClause) |
boolean |
allowReserved(String name)
Answer true if
name is a reserved name (_whatever) that is
allowed to be used (and ignored). |
void |
appendFilterExpressions(PrefixLogger pl,
StringBuilder q) |
String |
assembleRawCountQuery(PrefixLogger pl,
Bindings b) |
String |
assembleRawSelectQuery(PrefixLogger pl,
Bindings b) |
String |
assembleSelectQuery(Bindings b,
com.hp.hpl.jena.shared.PrefixMapping prefixes) |
String |
assembleSelectQuery(com.hp.hpl.jena.shared.PrefixMapping prefixes) |
protected String |
bindDefinedvariables(PrefixLogger pl,
String query,
Bindings cc)
Take the SPARQL query string
query and replace any ?SPOO
where SPOO is a variable bound in cc with the SPARQL
representation of that variable's value. |
void |
clearLanguages() |
String |
constructBGP(PrefixLogger pl) |
String |
cookRawValue(String raw_val)
Raw values have come in from the outside world (as arguments to URL
query-part filters) and may optionally be cooked to get rid of suspect
characters.
|
APIQuery |
copy() |
int |
countVarsAllocated()
Answer the number of variables allocated so far (used for testing).
|
protected com.hp.hpl.jena.query.Query |
createQuery(String selectQuery) |
void |
deferrableAddFilter(Param param,
String val) |
protected APIResultSet |
fetchDescriptionOfAllResources(Controls c,
String select,
APISpec spec,
String graphName,
View view,
List<com.hp.hpl.jena.rdf.model.Resource> results) |
List<RDFQ.Triple> |
getBasicGraphTriples() |
String |
getDefaultLanguage()
Answer the (current) default language string.
|
List<RenderExpression> |
getFilterExpressions() |
TextSearchConfig |
getItemSource() |
List<List<RDFQ.Triple>> |
getOptionalGraphTriples() |
int |
getPageNumber()
Answer the currently-set page number.
|
int |
getPageSize()
Answer the currently-set page size.
|
String |
getQueryString(APISpec spec,
Bindings call)
Return the select query that would be run or a plain string for the
resource
|
String |
getSubject()
Return the fixed subject for a subject query, null for a select query
|
boolean |
isFixedSubject()
Return true if this query is a fixed subject instead of a select
|
String |
languagesFor(String param) |
Variable |
newVar()
Answer a new variable not equal to any that this VarSupply has
delivered before.
|
protected void |
optionalProperty(Variable startFrom,
Param param,
Variable var)
Generate triples to bind
var to the value of the
param property chain if it exists (ie all of the triples are
OPTIONAL). |
APIResultSet |
runQuery(NoteBoard nb,
Controls c,
APISpec spec,
Cache cache,
Bindings b,
View view)
Run the defined query against the datasource
|
protected APIResultSet |
runQueryWithSource(NoteBoard nb,
Controls c,
APISpec spec,
Bindings call,
String graphName,
View view,
Source source) |
protected Couple<String,List<com.hp.hpl.jena.rdf.model.Resource>> |
selectResources(Controls c,
APISpec spec,
Bindings b,
Source source)
Answer the select query (if any; otherwise, "") and list of resources
obtained by running that query.
|
void |
setDefaultLanguage(String defaults)
Set the default language, discarding any existing default language.
|
void |
setEnableETags(boolean e)
Set the etags enable flag; true -> enabled.
|
void |
setFixedSelect(String fixedSelect) |
void |
setGraphName(String graphName) |
void |
setLanguagesFor(String fullParamName,
String languages) |
void |
setOrderBy(String orderBy)
Discard any existing order expressions (a string that may appear after
SPARQL's ORDER BY).
|
void |
setPageNumber(int page)
Set which page should be returned.
|
void |
setPageSize(int pageSize)
Set the page size to use when paging through results.
|
void |
setSortBy(String orderSpecs)
Discard any existing order expressions.
|
void |
setSubject(String subj) |
void |
setSubjectAsItemEndpoint(String subj)
Sets the query to just describe a single resource, rather than search for
a list
|
boolean |
setTotalCountRequested(boolean b)
If the current total count request is null, set it to
b and
return true; otherwise return false (meaning "could not set"). |
void |
setTypeConstraint(com.hp.hpl.jena.rdf.model.Resource typeConstraint) |
protected void |
unpackSortByOrderSpecs() |
boolean |
wantsMetadata(String name) |
public static final Variable SELECT_VAR
public static final String PREFIX_VAR
protected List<RDFQ.Triple> basicGraphTriples
protected List<List<RDFQ.Triple>> optionalGraphTriples
protected final List<RenderExpression> filterExpressions
protected final TextSearchConfig textSearchConfig
protected String defaultLanguage
protected int varcount
protected int pageSize
protected int pageNumber
protected com.hp.hpl.jena.rdf.model.Resource subjectResource
protected String itemTemplate
protected String fixedSelect
protected boolean enableETags
protected String sortByOrderSpecs
protected boolean sortByOrderSpecsFrozen
protected String graphName
protected String graphTemplate
protected final boolean purging
public static final Pattern varPattern
protected final int defaultPageSize
protected final int maxPageSize
protected final ShortnameService sns
protected final ValTranslator vt
protected final StringBuffer whereExpressions
protected final Map<Variable,Param.Info> varInfo
public final List<PendingParameterValue> deferredFilters
public final long cacheExpiryMilliseconds
public APIQuery(APIQuery.QueryBasis qb)
public APIQuery(APIQuery other)
public List<RDFQ.Triple> getBasicGraphTriples()
public List<List<RDFQ.Triple>> getOptionalGraphTriples()
public List<RenderExpression> getFilterExpressions()
public void addFilterExpression(RenderExpression e)
public TextSearchConfig getItemSource()
public boolean setTotalCountRequested(boolean b)
b
and
return true; otherwise return false (meaning "could not set").public APIQuery copy()
public void setGraphName(String graphName)
public void setEnableETags(boolean e)
public void setPageSize(int pageSize)
public int getPageSize()
public void setPageNumber(int page)
public int getPageNumber()
public void setTypeConstraint(com.hp.hpl.jena.rdf.model.Resource typeConstraint)
public void setSubjectAsItemEndpoint(String subj)
subj
- the target resource as either a prefix_name string or as a
full URIpublic void setSubject(String subj)
public void addAllowReserved(String name)
public boolean isFixedSubject()
public String getSubject()
public void setDefaultLanguage(String defaults)
public String getDefaultLanguage()
public void clearLanguages()
public void addMetadataOptions(String[] options)
public String cookRawValue(String raw_val)
public void addSearchTriple(String val)
public APIQuery addSubjectHasProperty(com.hp.hpl.jena.rdf.model.Resource P, Any O)
public void addNumericRangeFilter(Variable v, double x, double dx)
public void addTriplePatterns(List<RDFQ.Triple> triples)
protected void addPropertyHasValue(Param param)
protected void optionalProperty(Variable startFrom, Param param, Variable var)
var
to the value of the
param
property chain if it exists (ie all of the triples are
OPTIONAL).protected void addPropertyHasntValue(Param param)
public void setOrderBy(String orderBy)
orderBy
as the new order
expressions.public void setFixedSelect(String fixedSelect)
public void setSortBy(String orderSpecs)
orderSpec
to
produce a new order expression. orderSpec is a comma-separated list of
sort fields, each optionally proceeded by - for DESC. Each field is a
property chain used to bind a new variable v when is used as the ORDER BY
field.protected void unpackSortByOrderSpecs()
public Variable newVar()
VarSupply
public int countVarsAllocated()
public void addWhere(String whereClause)
public String assembleSelectQuery(Bindings b, com.hp.hpl.jena.shared.PrefixMapping prefixes)
public String assembleSelectQuery(com.hp.hpl.jena.shared.PrefixMapping prefixes)
public String assembleRawSelectQuery(PrefixLogger pl, Bindings b)
public void appendFilterExpressions(PrefixLogger pl, StringBuilder q)
public String constructBGP(PrefixLogger pl)
protected String bindDefinedvariables(PrefixLogger pl, String query, Bindings cc)
query
and replace any ?SPOO
where SPOO is a variable bound in cc
with the SPARQL
representation of that variable's value. Note that this will include
any occurrences of ?SPOO, including those inside SPARQL quotes.
Fixing this probably should happen earlier, but note that bits of query
are mashed together from strings in the config file, ie, without going
through RDFQ.public String getQueryString(APISpec spec, Bindings call)
public APIResultSet runQuery(NoteBoard nb, Controls c, APISpec spec, Cache cache, Bindings b, View view)
protected APIResultSet runQueryWithSource(NoteBoard nb, Controls c, APISpec spec, Bindings call, String graphName, View view, Source source)
protected APIResultSet fetchDescriptionOfAllResources(Controls c, String select, APISpec spec, String graphName, View view, List<com.hp.hpl.jena.rdf.model.Resource> results)
protected Couple<String,List<com.hp.hpl.jena.rdf.model.Resource>> selectResources(Controls c, APISpec spec, Bindings b, Source source)
public String assembleRawCountQuery(PrefixLogger pl, Bindings b)
protected com.hp.hpl.jena.query.Query createQuery(String selectQuery)
public boolean wantsMetadata(String name)
wantsMetadata
in interface WantsMetadata
public boolean allowReserved(String name)
name
is a reserved name (_whatever) that is
allowed to be used (and ignored).Copyright © 2014. All Rights Reserved.