Class JsonQuery
java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.json.JsonQuery
Translates a JSON Query-By-Example payload into the equivalent SQL/MATCH query text.
Purely a query-text builder: it holds no database connection and no
collection-specific execution configuration (pagination, hierarchical scoping, metadata
policy, ...). Execution is collection-specific and lives elsewhere — e.g.
InstancesJsonQueryExecutor for the Instances collection, QueryTemplateManagement.query(String)
for Query Templates, ContextManagement.query(String) for Contexts — each opens its
own environment/connection and serializes results its own way, since these differ too much
across collections (different environments, different visibility/serialization concerns) to
be meaningfully unified under one execution method.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JsonQueryElementThe parsed root query element helper.protected org.gcube.com.fasterxml.jackson.databind.JsonNodeThe input JSON query structure tree node.protected org.gcube.com.fasterxml.jackson.databind.ObjectMapperIn-use Jackson object mapper.protected booleanWhether the entry-point match may include registered subtypes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuilds and returns the SQL MATCH query string buffer equivalent to this JSON query representation.Builds and returns the SQL query string buffer equivalent to this JSON query representation.Returns the parsed root query element helper resolved by the lastcreateQuery()/createMatchQuery()call.org.gcube.com.fasterxml.jackson.databind.JsonNodeReturns the input JSON query tree node.static JsonQueryElementgetJsonQueryElement(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery) Factory helper to instantiate the appropriateJsonQueryElementsubclass for the specified JSON query root node.Returns the named parameters generated for the current query text.voidsetJsonQuery(String jsonQuery) Parses and sets the input JSON query string.voidsetJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery) Sets the input JSON query tree node.voidsetPolymorphic(boolean polymorphic) Configures whether the entry-point match includes registered subtypes.
-
Field Details
-
objectMapper
protected org.gcube.com.fasterxml.jackson.databind.ObjectMapper objectMapperIn-use Jackson object mapper. -
jsonQuery
protected org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQueryThe input JSON query structure tree node. -
entryPoint
The parsed root query element helper. -
polymorphic
protected boolean polymorphicWhether the entry-point match may include registered subtypes.
-
-
Constructor Details
-
JsonQuery
public JsonQuery()Creates a newJsonQueryinstance with default ObjectMapper.
-
-
Method Details
-
setPolymorphic
public void setPolymorphic(boolean polymorphic) Configures whether the entry-point match includes registered subtypes.- Parameters:
polymorphic-truefor polymorphic matching;falsefor the exact Type
-
getJsonQuery
public org.gcube.com.fasterxml.jackson.databind.JsonNode getJsonQuery()Returns the input JSON query tree node.- Returns:
- the JSON query node
-
setJsonQuery
public void setJsonQuery(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery) Sets the input JSON query tree node.- Parameters:
jsonQuery- the JSON query node
-
setJsonQuery
public void setJsonQuery(String jsonQuery) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException Parses and sets the input JSON query string.- Parameters:
jsonQuery- the JSON query string- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException- if the JSON string is invalid
-
getEntryPoint
Returns the parsed root query element helper resolved by the lastcreateQuery()/createMatchQuery()call.- Returns:
- the entry-point query element, or
nullif no query has been built yet
-
getQueryParameters
Returns the named parameters generated for the current query text.- Returns:
- generated OrientDB named parameters
-
getJsonQueryElement
public static JsonQueryElement getJsonQueryElement(org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery) throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Factory helper to instantiate the appropriateJsonQueryElementsubclass for the specified JSON query root node.- Parameters:
jsonQuery- the JSON query node- Returns:
- the corresponding
JsonQueryElementsubclass helper - Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException- if the query target type is not registeredorg.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException- if the schema type definition is invalidorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database or lookup error
-
createQuery
public StringBuffer createQuery() throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException, org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryExceptionBuilds and returns the SQL query string buffer equivalent to this JSON query representation.- Returns:
- SQL query string buffer
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException- if schema traversal failsorg.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException- if query syntax or constraints are violatedorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database error
-
createMatchQuery
public StringBuffer createMatchQuery() throws org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException, org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryExceptionBuilds and returns the SQL MATCH query string buffer equivalent to this JSON query representation.- Returns:
- SQL MATCH query string buffer
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException- if schema traversal failsorg.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException- if query syntax or constraints are violatedorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database error
-