Interface DBQuery
- 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 TypeMethodDescriptionbooleanReturns whether the last execution produced at least one non-element row.query()Executes the configured query against the database backend.voidsetHierarchical(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.voidsetIncludeContexts(boolean includeContexts) Sets whether to include thecontextsmap on results whenrawResultisfalse.voidsetMetadataPolicy(org.gcube.informationsystem.resourceregistry.api.rest.MetadataPolicy metadataPolicy) Sets the metadata inclusion policy applied to results whenrawResultisfalse.voidSets the SQL-like query text to execute.voidsetRawResult(boolean rawResult) Sets whether to return the raw database result representation (true) or the standard Information System projection (false).
-
Method Details
-
setQuery
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 whenrawResultisfalse. Ignored whenrawResultistrue.- Parameters:
metadataPolicy- the metadata policy
-
setIncludeContexts
void setIncludeContexts(boolean includeContexts) Sets whether to include thecontextsmap on results whenrawResultisfalse. Ignored whenrawResultistrue.- Parameters:
includeContexts- the includeContexts flag
-
hasNonElementResults
boolean hasNonElementResults()Returns whether the last execution produced at least one non-element row.- Returns:
truewhen scalar or projection rows were returned
-
query
String query() throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryExceptionExecutes 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 mutationsorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if a result cannot be serialized completely
-