Skip to content

Add view context reference for entity views #202

@Mobe91

Description

@Mobe91

When dealing with subviews containing subqueries, it would be useful to be able to refer to the subview's context root. This fosters the independence of entity views from the view hierarchy they are used in as subquery providers can be implemented without knowing the view hierarchy. Consider the following example:

@EntityView(DocumentVersion.class)
public interface DocumentVersionView {
   DocumentView getDocument();
}

@EntityView(Document.class)
public interface DocumentView {
  @MappingSubquery(MyUselessSubqueryProvider.class)
  public List<UselessStuff> getMeUselessStuff();

  public static class MyUselessSubqueryProvider implements SubqueryProvider {
     createSubquery(SubqueryInitiator init) {
         init.from(UselessStuff.class, "useless")
              .where("useless.documentId").eqExpression("OUTER(document.id)"); // we have to know that we are nested in DocumentVersionView

//           .where("useless.documentId").eqExpression("VIEW_ROOT(id)");  -- VIEW_ROOT implicitely resolves to OUTER(document) context - the root of the DocumentView view.
     }
  }
}

The introduction of the VIEW_ROOT keyword for this purpose is a suggestion as it is quite intuitive in my opinion. Of course, we can decide for a different term as well.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions