I’m new to Java and JPQL and Views being used with lazy loading. Our old system that we are migrating from had a type of home-brew almost XPath-like feature that walked the schema or object model. We are wanting something similar here with Cuba and wanted to know if there are any recommendations for an approach if something doesn’t already exist.
An example would be something like this:
To get an email address when looking at an entity: = [CurrentEntity].[Company].[Owner].[Email] where this path would literally traverse the objects to get the email address.
To get many email addresses: = [CurrentEntity].[ParyMembers].[User].[Email] would actually yield multiple email address as there are multiple PartyMembers on the entity.
This allowed for very easy dynamic configuration that customers could easily understand. The path was provided as a String as input which we would then parse and walk the path. We would use it in many parts of the application. It’s a lot easier than asking customers to create SQL statements. Is there anything in Cuba that would help with this or at least point me in the right direction for implementing something like this?
Let’s consider this question on the following use case: you have an instance in memory and want to get a reference by traversing the object graph, and you are not sure that the needed graph is loaded from the database.
First, you need a view describing the graph. You can construct it on the fly like this:
View ownerView = new View(Owner.class).addProperty("email");
View companyView = new View(Company.class).addProperty("owner", ownerView);
View myEntityView = new View(MyEntity.class).addProperty("company", companyView);
The latter works only for a single reference, if there is a collection somewhere in the path, it will return this collection and won’t go further.
You can make a generic mechanism around this stuff (and overcome getValueEx() limitations) using meta-model interfaces provided by the platform: MetaClass and MetaProperty. There is a lot of usages of these interfaces in the platform code, see for example MetadataTools bean. Don’t hesitate to ask if you have any questions about the metadata framework.