List of usage examples for org.hibernate.collection.internal AbstractPersistentCollection getOwner
@Override
public Object getOwner()
From source file:ch.algotrader.cache.CollectionHandler.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//from w ww. j a v a 2 s . c o m protected CacheResponse put(Object obj, List<EntityCacheSubKey> stack) { if (obj instanceof AbstractPersistentCollection) { AbstractPersistentCollection col = (AbstractPersistentCollection) obj; // do not process uninitialized PersistentCollections if (!col.wasInitialized()) { return CacheResponse.skippedObject(); } // check stack on Persistent Collections with role only if (col.getRole() != null) { EntityCacheSubKey cacheKey = new EntityCacheSubKey((BaseEntityI) col.getOwner(), col.getRole()); if (stack.contains(cacheKey)) { return CacheResponse.processedObject(); } else { stack.add(cacheKey); } } } synchronized (obj) { // process Maps if (obj instanceof Map) { Map map = (Map) obj; for (Object o : map.entrySet()) { Map.Entry entry = (Map.Entry) o; Object value = entry.getValue(); CacheResponse response = this.cacheManager.put(value, stack); if (response.getState() == CacheState.EXISTING && response.getValue() != value) { // replace the value with the existingValue entry.setValue(response.getValue()); } } // process Lists } else if (obj instanceof List) { List list = (List) obj; for (ListIterator it = list.listIterator(); it.hasNext();) { Object value = it.next(); CacheResponse response = this.cacheManager.put(value, stack); if (response.getState() == CacheState.EXISTING && response.getValue() != value) { // replace the value with the existingValue it.set(response.getValue()); } } // process Sets } else if (obj instanceof Set) { Set set = (Set) obj; for (Object value : set) { this.cacheManager.put(value, stack); // values are not replaced in the set since objects might not be initialized enough for equals/hashCode need by Set.add() } } else { throw new IllegalArgumentException("unsupported collection type " + obj.getClass()); } } return CacheResponse.newObject(); }