Java Middleware
=================
We have developed a Java program between the JavaScript frontend and Haskell backend. Since there is no known method to integrate JavaScript and Haskell the way that the system requires, we developed this program. It uses Java Spring framework.
It is responsible for various tasks:
- the program starts the frontend and the backend,
- it translates our multi-model query language into Haskell fold-functions,
- it sends translated queries to the Haskell backend and parses the results,
- it stores queries and results for possible later use.
The program contains a small `JSONDB `_ database that stores queries, parsed queries, and certain results. The Java program connects to Haskell backend using `ProcessBuilder `_.
Query tokenizing, parsing and translating
------------------------------------------
Each selective query becomes an instance of a class called `SelectiveQuery `_.
When SelectiveQuery object is created, the input query string is automatically tokenized, parsed, and translated so that the user can output the corresponding Haskell code i.e. the sequence of fold functions.
Each SelectiveQuery consists of one or multiple `QueryBlocks `_ which have one or multiple
`LambdaFunctions `_.
This structure of classes creates a simple parse tree of the query and it can be efficiently used to modify and understand the query. Certain keywords (``cons``, ``nil`` which are related to :cite:`Grust2004` and :cite:`Grust1999Compr-709`) are
modified with respect to the target model of the query and the correct fold function is used with respect to the target model of the query.
The `CodeGenerator `_ class is partly responsible for this.