All Known Implementing Classes:
OrientDBQuery

public interface DBQuery
Contract for executing read-only database queries against the backend storage.

Implementations must connect to the backend using a read-only database user (e.g. PermissionMode.READER for OrientDB). This ensures that non-idempotent statements — such as INSERT, UPDATE, DELETE, CREATE, or DROP — are rejected at the database engine level regardless of the SQL text supplied by the caller. No explicit SQL-syntax validation is therefore required.

Read-only queries that do not start with SELECT (e.g. TRAVERSE, MATCH) are valid and handled correctly.

Authorization is not a concern of this class: callers must enforce role checks (restricted to globally-privileged administrators) before invoking query(), exactly as done for every other operation exposed through a PolicyEnforcementPoint.

Author:
Luca Frosini (ISTI - CNR)
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether the last execution produced at least one non-element row.
    Executes the configured query against the database backend.
    void
    setHierarchical(boolean hierarchical)
    Sets whether the query should be evaluated across the caller's token Context and all of its descendants, rather than the token Context alone.
    void
    setIncludeContexts(boolean includeContexts)
    Sets whether to include the contexts map on results when rawResult is false.
    void
    setMetadataPolicy(org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
    Sets the metadata inclusion policy applied to results when rawResult is false.
    void
    Sets the SQL-like query text to execute.
    void
    setRawResult(boolean rawResult)
    Sets whether to return the raw database result representation (true) or the standard Information System projection (false).
  • Method Details

    • setQuery

      void setQuery(String query)
      Sets the SQL-like query text to execute.
      Parameters:
      query - the query text
    • setRawResult

      void setRawResult(boolean rawResult)
      Sets whether to return the raw database result representation (true) or the standard Information System projection (false).
      Parameters:
      rawResult - the raw-result flag
    • setHierarchical

      void setHierarchical(boolean hierarchical)
      Sets whether the query should be evaluated across the caller's token Context and all of its descendants, rather than the token Context alone.
      Parameters:
      hierarchical - the hierarchical flag
    • setMetadataPolicy

      void setMetadataPolicy(org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy)
      Sets the metadata inclusion policy applied to results when rawResult is false. Ignored when rawResult is true.
      Parameters:
      metadataPolicy - the metadata policy
    • setIncludeContexts

      void setIncludeContexts(boolean includeContexts)
      Sets whether to include the contexts map on results when rawResult is false. Ignored when rawResult is true.
      Parameters:
      includeContexts - the includeContexts flag
    • hasNonElementResults

      boolean hasNonElementResults()
      Returns whether the last execution produced at least one non-element row.
      Returns:
      true when scalar or projection rows were returned
    • query

      String query() throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Executes the configured query against the database backend.
      Returns:
      JSON array string of query results
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the query syntax is invalid or if it contains mutations
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if a result cannot be serialized completely