SQLContainer - itemPassesFilters(RowItem) really usable

Hi,

today i recognized a strange behaviour of the SQLContainer. Newly added items are filtered by itemPassesFilters(). For some circumstances that is really a problem, because i can not access the item anymore.

For instance the SQLContainer is filtered by country == AT. Now i’d like to add a new item for country == AT.
Object id = container.addItem();
Item item = container.getItem(id); —> The item is null, since it does not pass the filter.
item…setValue(‘AT’)

My question: Why does the SQLContainer filter added records?

Thanks in advance,
Florian Pirchner
redVoodo.org

Hi,

This is simply because of how the filters are defined to function. The container does not separate ‘added’ and ‘existing’ items to outside observers. Therefore it would not be logical that you first apply a filter, then add all kinds of items which do not pass that filter and suddenly receive them in your result set.

If you are e.g. using SQLContainer as a data source for a ComboBox that allows adding new items, I’d suggest that you simply remove the filters prior to actually adding the item to the container.

-Tepi

Hi,

thanks a lot for your answer.

I agree your opinion. All container should work a very uniform way. Nevertheless whether they are persistent container or not.

Well, the suggestion of removing all filter, adding an item and adding all filter again is not really what i would like to implement. This issue was detected during the implementation of 1:n relations. A customer has many addresses. To show all addresses of the customer i am adding an equals-customer filter to the addresses. Removing the filter would cause an undefined state for a short period of time since all addresses are referenced to the customer instance!

  • Performance
    I do not want to loose performance. Since i am using vaadin in a business context, i have to deal with really big tables. Since adding and removing filters would clear the caches it might become a problem for some circumstances and the system may become slower.

  • Domain of Filters
    The runtime of redVoodo adds filters at different parts of the core. I am using filter to control which records can potentially be visible to the user. Eg during the creation of a SQLContainer redVoodo adds an organization filter which ensures that a user can only deal with records it has permission to. Also a mandant filter is used which divides the records of a table in logical parts.
    If any class should be able to remove all filters and to add them again, the SQLContainer requires a method #getAllFilters(), since the class may not be aware about the currently added filters. (Btw redVoodo is always aware about the filter since i am using an abstraction above the SQLContainer. But other systems may not)

Suggestion:
I would like to discuss the following suggestion. What is about creating a new interface called Container.TransientItemProvider. It offers a method #getTransientItem(Object id). This method return an item even it does not pass the filter AND is contained in the addedItems cache of the SQLContainer.

Then no filters have to be removed.
Object id = customerAddresses.addItem()
Item item = customerAddresses.getTransientItem(id)
item…setCustomerId(112233) → Now the filter is passed!!!

Looking forward to your opinion.

Florian Pirchner

redVoodo.org

Yes, I’m quite certain this has been the goal.

Have you tried using the getItemUnfiltered(Object itemId) method of SQLContainer? This should provide what you need unless you are using the SQLContainer in autocommit mode (or have already committed the changes) which would make the DB filters kick in.

About the new Interface, can’t comment on that. Maybe someone from the Vaadin dev team could share a thought on that?

-Tepi

Great, that method is exactly what i need! How could i miss it?

Thanks a lot
Florian Pirchner