JPAContainer: Filter Before Adding to Container

I am mapping an entity, SearchableEntity, to a JPAContainer. This SearchableEntity class is nothing but an abstract superclass with the fields id, type, and searchableCriteria that will allow users to search for several different entity types (Users, Contacts, etc.) from the same same box (a TokenField in this case).

I need to add quite a few filters to the container to show only the data that is relevant to the user, but due to the layers of abstraction and the size that the SearchableEntity container is expected to be, I need a more efficient way to do this.

I’m assuming that at some point, JPAContainer does something along the lines of:

SELECT id FROM SearchableEntity; In order to initially fill the container.

Is there a way to replace this with something like the following query?

SELECT id FROM SearchableEntity WHERE type != Contact;

This is a very simplified example, but basically what I need to do is change the initial query so that the container never even knows about the irrelevant queries in the first place. Is this possible?

A couple of things I have tried:

  • Putting my query in the filtersWillBeAdded method of CriteriaQueryModifierDelegate. This works fine with small data samples, but is way to slow with large samples due to the fact that it gets hit 10+ times before even showing the component. At around 10,000 ids, it causes a stack overflow and crashes.
  • Overriding getItemIds(int startIndex, int numberOfItems) in JPAContainer and returning the ids from the query there. This seems to work, and is fast even with a lot of data, but the items displayed are out of sync with the items that are actually in the container.

I’m running into a similar issue. Bump.