My employer recently asked me to work on a graphing API for our application. Frontend essentially expects data in (x, y) or some other format (depending on the graph being shown). The user can pick what they want to query for in the UI, and this is where I'm getting lost. There are so many possibilities for what data columns could be queried in a single entity, not to mention multiple entities or across associations. My initial thought process is this:
- Create a custom annotation, which marks possible fields that can be queried via the API.
- Have user select from the list of properties what they want to query + filter conditions.
- Create a graph of the entity relations in the application. In this way, regardless of the entity queried, I can form an appropriate Criteria query.
- Walk the graph and form a join for each edge in the graph until the query is formed.
I'm aware of Specifications. However, this requires me to know in advance how many association traversals are needed from the root object. Specifications appear to work fine for a single entity, but traversing associations appears to be cumbersome.
I'm not seeing any advanced examples online or in any documentation for the Criteria API that can handle this task. Can anyone point to some resources or know of a better approach? I'm also fairly new to the Criteria API.