|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Why is FunctionListMap using identity to check values and not equals?I have the following situation:
private final EventList<E> items = GlazedLists.threadSafeList(new BasicEventList<E>()); private final DisposableMap<Key, E> itemsLookup = GlazedLists.syncEventListToMap(this.items, new FunctionList.Function<E, Key>() { public Key evaluate(final E sourceValue) { return getKey(sourceValue); } }); I get updates from an external database that say which object (by key) has changed or was removed. The removal using the itemsLookup works. However the put() method uses an Identity compare to find the item to be replaced. This is of course not working, since I am loading a new Object (different identity but same key) from the database every time. The object with the same Key should be replaced by using the equals method. How could I achieve that? So when an Update comes in I do an itemsLookup.put(key, database.load(key)) which naturally throws an exception because the new Object is not found in the base list. Thanks, Phil |
|
|
|
|
|
Re: Why is FunctionListMap using identity to check values and not equals?If I get an item out of a DB two times it has a different identity each time. However it is the same object, as defined by the key (Primary key if you want so).
What I would like to have GL do for me is help me reacting to CRUD changes in the DB. I get JMS messages when an item is created, removed or updated in the database. I want to reflect this change in my EventList. For Create: add the new item for update: refresh the item in the eventlist (if not existing, add it) for delete: remove the item from my eventlist. However using identities it is not possible to do. The lookup of items must be using the Key. Hope its clear now :)
|
|
|
|
|
|
Re: Why is FunctionListMap using identity to check values and not equals?Holger's analysis is correct to my eye. FunctionListMap.put() is fine to use identity comparison when searching for the value to update in the valueList. This is because FunctionListMap guarantees that the delegate Map and valueList continually refer to the exact same (identical) objects.
Anywho, what IS possible is that you're being tripped up by concurrent access. If you want to write throught he map, and concurrent changes to the backing EventList are possible, you'd still need to .lock() the pipeline behind the FunctionListMap before attempting your put()s or get()s. Otherwise you could get RuntimeExceptions... Just a thought. If you can reproduce your problem with a test case, we'll look at it with you. James On Thu, Jun 25, 2009 at 9:57 AM, Holger Brands <hbrands@...> wrote: I understand your use case but not your reasoning: |
| Free embeddable forum powered by Nabble | Forum Help |