Skip to content
Browse files

Remove AbstractSession.objectToKey.

* Instead add a trivial method to Persister to allow fetching the id from an entity.
* Prevents potential problems with entities with overridden equals/hashCode.
  • Loading branch information...
1 parent ba11aed commit a967706a197251b5a884eadc693f4624610c940b @tomwidmer tomwidmer committed Mar 20, 2013
View
8 grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractSession.java
@@ -86,8 +86,6 @@ public void onEviction(PersistentEntity key, Collection<PendingUpdate> value) {
protected TPCacheAdapterRepository cacheAdapterRepository;
- protected Map<Object, Serializable> objectToKey = new ConcurrentHashMap<Object, Serializable>();
-
private Map<PersistentEntity, Collection<PendingInsert>> pendingInserts =
new Builder<PersistentEntity, Collection<PendingInsert>>()
.listener(EXCEPTION_THROWING_INSERT_LISTENER)
@@ -351,7 +349,6 @@ public void clear() {
pendingUpdates.clear();
pendingDeletes.clear();
attributes.clear();
- objectToKey.clear();
exceptionOccurred = false;
}
@@ -406,7 +403,6 @@ public void cacheInstance(Class type, Serializable key, Object instance) {
if (type == null || key == null || instance == null) {
return;
}
- objectToKey.put(instance, key);
getInstanceCache(type).put(key, instance);
}
@@ -425,10 +421,10 @@ public void clear(Object o) {
final Map<Serializable, Object> cache = firstLevelCache.get(o.getClass());
if (cache != null) {
- Serializable key = objectToKey.get(o);
+ Persister persister = getPersister(o);
+ Serializable key = persister.getObjectIdentifier(o);
if (key != null) {
cache.remove(key);
- objectToKey.remove(o);
}
}
View
7 grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/Persister.java
@@ -110,4 +110,11 @@
* @return The objects id
*/
Serializable refresh(Object o);
+
+ /**
+ * Get the identifier for the given object, if it has one.
+ * @param o The object.
+ * @return The object's id.
+ */
+ Serializable getObjectIdentifier(Object o);
}

0 comments on commit a967706

Please sign in to comment.
Something went wrong with that request. Please try again.