eclipse and database driven resources - tracking parent-child relatioships

My application has all of the resource stored in a database. It is entirely database driven. I want to provide a navigatable view of the these resources in my RCP. Using the common navigator framework (CNF) I can provide a view to navigate these resources rather generically. However, the classic problem is that while the toplevel objects in the CNF are defined logically in the application many of the lower level resources (in the tree view) are going to be from the database. For example, the top level resources have contacts and security objects. I represent these directly in code similar to IResources in the eclipse world. However, the list of contacts come from the database directly and are represent as domain objects using an ORM with a persistent context (long conversation).

So if I want to have menu commands defined on those database resources, I can certainly do so but I often need to calculate the application-level logical object so I can perform operations on the group, etc. To do this, I need to track that the domain object belongs to one of the resources. For example, that the contact domain object belongs to the logical "Contacts" highest level resource defined in my application. I could program in logic throughout my application that says that any time you encounter a contacts domain object, find the contacts resource.

But this type of logic will no work if your CNF needs to display multiple roots, for example, when you access multiple databases at the top level and are open at the same time. In this case, just having a contacts domain object does not give you enough information to know which root the object belongs to. And, since you would use the same IContentProvider object to display the logical hierarchy for each root, you need to disambiguate the parent-child relationships. The solution I have is to use a ChildrenTracker object and each time IStructureContentProvider.getChildren is called, you can call a method on the ChildrenTracker.add(Object parent, Object[] children) to program the relationship directly into the children tracker cache object. Don't forget to remove the relationship if you close the database connection or the objects change. This represents a hard to manage but necessary relationship tracking object.


Popular posts from this blog

zio layers and framework integration

typescript and react types

dotty+scala.js+async: interesting options