Package org.eclipse.rdf4j.workbench.util

## Class QueryStorage

- java.lang.Object
- - org.eclipse.rdf4j.workbench.util.QueryStorage

-     public class QueryStorage
      extends Object

  Provides an interface to the private repository with the saved queries.
  Author:
    Dale Visser

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `askExists​(HTTPRepository repository, String queryName, String userName)` |
    `boolean` | `canChange​(IRI query, String currentUser)` | Determines whether the user with the given userName is allowed to update or delete the given query.
    `boolean` | `canRead​(IRI query, String currentUser)` | Determines whether the user with the given userName is allowed to read the given query.
    `boolean` | `checkAccess​(HTTPRepository repository)` | Checks whether the current user/password credentials can really access the current repository.
    `void` | `deleteQuery​(IRI query, String userName)` | Delete the given query for the given user.
    `String` | `getQueryText​(HTTPRepository repository, String owner, String queryName)` | Retrieves the specified query text.
    `static QueryStorage` | `getSingletonInstance​(AppConfiguration config)` |
    `void` | `saveQuery​(HTTPRepository repository, String queryName, String userName, boolean shared, QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage)` | Save a query.
    `void` | `selectSavedQueries​(HTTPRepository repository, String userName, TupleResultBuilder builder)` | Prepares a query to retrieve the queries accessible to the given user in the given repository.
    `IRI` | `selectSavedQuery​(HTTPRepository repository, String owner, String queryName)` | Returns the URI for the saved query in the given repository with the given name, owned by the given owner.
    `void` | `shutdown()` |
    `void` | `updateQuery​(IRI query, String userName, boolean shared, QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage)` | Update the entry for the given query.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getSingletonInstance

          public static QueryStorage getSingletonInstance​(AppConfiguration config)
                                                   throws RepositoryException,
                                                          IOException

      Throws:
        `RepositoryException`
        `IOException`

    - #### shutdown

          public void shutdown()

    - #### checkAccess

          public boolean checkAccess​(HTTPRepository repository)
                              throws RepositoryException

      Checks whether the current user/password credentials can really access the current repository.
      Parameters:
        `repository` - the current repository
      Returns:
        true, if it is possible to request a statement from the repository with the given credentials
      Throws:
        `RepositoryException` - if there is an issue closing the connection

    - #### saveQuery

          public void saveQuery​(HTTPRepository repository,
                                String queryName,
                                String userName,
                                boolean shared,
                                QueryLanguage queryLanguage,
                                String queryText,
                                boolean infer,
                                int rowsPerPage)
                         throws RDF4JException

      Save a query. UNSAFE from an injection point of view. It is the responsibility of the calling code to call checkAccess() with the full credentials first.
      Parameters:
        `repository` - the repository the query is associated with
        `queryName` - the name for the query
        `userName` - the user saving the query
        `shared` - whether the query is to be shared with other users
        `queryLanguage` - the language of the query (only SPARQL is currently supported)
        `queryText` - the actual query text
        `infer` -
        `rowsPerPage` - rows to display per page, may be 0 (all), 10, 50, 100, or 200)
      Throws:
        `RDF4JException`

    - #### canChange

          public boolean canChange​(IRI query,
                                   String currentUser)
                            throws RepositoryException,
                                   QueryEvaluationException,
                                   MalformedQueryException

      Determines whether the user with the given userName is allowed to update or delete the given query.
      Parameters:
        `query` - the node identifying the query of interest
        `currentUser` - the user to check access for
      Returns:
        true if the given query was saved by the given user or the anonymous user
      Throws:
        `RepositoryException`
        `QueryEvaluationException`
        `MalformedQueryException`

    - #### canRead

          public boolean canRead​(IRI query,
                                 String currentUser)
                          throws RepositoryException,
                                 QueryEvaluationException,
                                 MalformedQueryException

      Determines whether the user with the given userName is allowed to read the given query.
      Parameters:
        `query` - the node identifying the query of interest
        `currentUser` - the user to check access for
      Returns:
        true if the given query was saved by either the given user or the anonymous user, or is shared
      Throws:
        `RepositoryException`
        `QueryEvaluationException`
        `MalformedQueryException`

    - #### askExists

          public boolean askExists​(HTTPRepository repository,
                                   String queryName,
                                   String userName)
                            throws QueryEvaluationException,
                                   RepositoryException,
                                   MalformedQueryException

      Throws:
        `QueryEvaluationException`
        `RepositoryException`
        `MalformedQueryException`

    - #### deleteQuery

          public void deleteQuery​(IRI query,
                                  String userName)
                           throws RepositoryException,
                                  UpdateExecutionException,
                                  MalformedQueryException

      Delete the given query for the given user. It is the responsibility of the calling code to call checkAccess() and canDelete() with the full credentials first.
      Parameters:
        `query` -
        `userName` -
      Throws:
        `RepositoryException`
        `UpdateExecutionException`
        `MalformedQueryException`

    - #### updateQuery

          public void updateQuery​(IRI query,
                                  String userName,
                                  boolean shared,
                                  QueryLanguage queryLanguage,
                                  String queryText,
                                  boolean infer,
                                  int rowsPerPage)
                           throws RepositoryException,
                                  UpdateExecutionException,
                                  MalformedQueryException

      Update the entry for the given query. It is the responsibility of the calling code to call checkAccess() with the full credentials first.
      Parameters:
        `query` - the query to update
        `userName` - the user name
        `shared` - whether to share with other users
        `queryLanguage` - the query language
        `queryText` - the text of the query
        `infer` -
        `rowsPerPage` - the rows per page to display of the query
      Throws:
        `RepositoryException` - if a problem occurs during the update
        `UpdateExecutionException` - if a problem occurs during the update
        `MalformedQueryException` - if a problem occurs during the update

    - #### selectSavedQueries

          public void selectSavedQueries​(HTTPRepository repository,
                                         String userName,
                                         TupleResultBuilder builder)
                                  throws RepositoryException,
                                         MalformedQueryException,
                                         QueryEvaluationException,
                                         QueryResultHandlerException

      Prepares a query to retrieve the queries accessible to the given user in the given repository. When evaluated, the query result will have the following binding names: query, user, queryName, shared, queryLn, queryText, rowsPerPage. It is the responsibility of the calling code to call checkAccess() with the full credentials first.
      Parameters:
        `repository` - that the saved queries run against
        `userName` - that is requesting the saved queries
        `builder` - receives a list of all the saved queries against the given repository and accessible to the given user
      Throws:
        `RepositoryException` - if there's a problem connecting to the saved queries repository
        `MalformedQueryException` - if the query is not legal SPARQL
        `QueryEvaluationException` - if there is a problem while attempting to evaluate the query
        `QueryResultHandlerException`

    - #### selectSavedQuery

          public IRI selectSavedQuery​(HTTPRepository repository,
                                      String owner,
                                      String queryName)
                               throws RDF4JException,
                                      BadRequestException

      Returns the URI for the saved query in the given repository with the given name, owned by the given owner.
      Parameters:
        `repository` - The repository the query is associated with.
        `owner` - The user that saved the query.
        `queryName` - The name given to the query.
      Returns:
        if it exists, the URI referring to the specified saved query.
      Throws:
        `RDF4JException` - if issues occur performing the necessary queries.
        `BadRequestException` - if the the specified stored query doesn't exist

    - #### getQueryText

          public String getQueryText​(HTTPRepository repository,
                                     String owner,
                                     String queryName)
                              throws RDF4JException,
                                     BadRequestException

      Retrieves the specified query text. No security checks are done here. If the saved query exists, its text is returned.
      Parameters:
        `repository` - Repository that the saved query is associated with.
        `owner` - The user that saved the query.
        `queryName` - The name given to the saved query.
      Returns:
        the text of the saved query, if it exists
      Throws:
        `RDF4JException` - if a problem occurs accessing storage
        `BadRequestException` - if the specified query doesn't exist