java.lang.Object
org.gcube.informationsystem.resourceregistry.queries.json.JsonQuery

public class JsonQuery extends Object
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 Details

    • objectMapper

      protected org.gcube.com.fasterxml.jackson.databind.ObjectMapper objectMapper
      In-use Jackson object mapper.
    • jsonQuery

      protected org.gcube.com.fasterxml.jackson.databind.JsonNode jsonQuery
      The input JSON query structure tree node.
    • entryPoint

      protected JsonQueryElement entryPoint
      The parsed root query element helper.
    • polymorphic

      protected boolean polymorphic
      Whether the entry-point match may include registered subtypes.
  • Constructor Details

    • JsonQuery

      public JsonQuery()
      Creates a new JsonQuery instance with default ObjectMapper.
  • Method Details

    • setPolymorphic

      public void setPolymorphic(boolean polymorphic)
      Configures whether the entry-point match includes registered subtypes.
      Parameters:
      polymorphic - true for polymorphic matching; false for 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

      public JsonQueryElement getEntryPoint()
      Returns the parsed root query element helper resolved by the last createQuery()/ createMatchQuery() call.
      Returns:
      the entry-point query element, or null if no query has been built yet
    • getQueryParameters

      public Map<String,Object> 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 appropriate JsonQueryElement subclass for the specified JSON query root node.
      Parameters:
      jsonQuery - the JSON query node
      Returns:
      the corresponding JsonQueryElement subclass helper
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException - if the query target type is not registered
      org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException - if the schema type definition is invalid
      org.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.ResourceRegistryException
      Builds 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 fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if query syntax or constraints are violated
      org.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.ResourceRegistryException
      Builds 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 fails
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if query syntax or constraints are violated
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - on database error