QueryService Class

WebService used to query a database. Queries are executed asynchronously. Clients submit a query by executing an HTTP POST request to "/job" which, in turn, returns a job ID. Clients can get job status and, when ready, the query results by executing an HTTP GET request to "/job/{ID}". Query results maybe encapsulated using csv, tsv, jsv, or json (default). The format is specified when submitting a new job. Additional routes and capabilities are documented in the getServiceResponse() method.

Note that this class requires JSqlParser which is used to validate queries and mitigate SQL injection by only allowing SELECT SQL statements. The validation logic is not foolproof and it is therefore recommended to restrict access to this service to authorized, trusted users (e.g. admins).

Constructors

QueryService( Database database, javaxt.io.Directory jobDir, javaxt.io.Directory logDir )

Public Methods

getServiceResponse( ServiceRequest request, Database database ) returns ServiceResponse
Used to generate a response to an HTTP request. The default routes are as follows:
  • POST /job - Used to create a new query job and return a jobID
  • GET /job/{jobID} - Returns query results or job status for a given jobID
  • DELETE /job/{jobID} - Used to cancel query for a given jobID
  • GET /jobs - Returns a list of all query jobs associated with the user
  • GET /tables - Returns a list of all the tables in the database
If no path is provided in the request, the method will wait until the query is executed before returning a response. This may result in long wait times and the client might hang up or disconnect before the query is done (not recommended).
notify( QueryJob job ) returns void
Called whenever a job is created, updated, or deleted. You can override this method in your application (e.g. relay job status via websockets).
getTables( ServiceRequest request, Database database ) returns ServiceResponse
Returns a list of tables and columns

Public Classes