private void initialize(com.impetus.kundera.cache.Cache l2Cache, PersistenceCache pc) { mainCache = new MainCache(l2Cache,this); // embeddedCache = new EmbeddedCache(l2Cache); // elementCollectionCache = new ElementCollectionCache(l2Cache); // transactionalCache = new TransactionalCache(l2Cache); // flushStack = new FlushStack(); // joinTableDataMap = new HashMap<String, JoinTableData>(); // // flushManager = new FlushManager(); }
/** * Refresh the state of the instance from the database, overwriting changes * made to the entity, if any. */ public void refresh(Object entity) { if (contains(entity)) { MainCache mainCache = (MainCache) getPersistenceCache().getMainCache(); Node node = mainCache.getNodeFromCache(entity, getMetadata(entity.getClass()), this); // Locking as it might read from persistence context. try { lock.readLock().lock(); node.setPersistenceDelegator(this); node.refresh(); } finally { lock.readLock().unlock(); } } else { throw new IllegalArgumentException("This is not a valid or managed entity, can't be refreshed"); } }
/** * @param entity * @param pd * @param entityId */ public static void addEntityToPersistenceCache(Object entity, PersistenceDelegator pd, Object entityId) { MainCache mainCache = (MainCache) pd.getPersistenceCache().getMainCache(); String nodeId = ObjectGraphUtils.getNodeId(entityId, entity.getClass()); Node node = new Node(nodeId, entity.getClass(), new ManagedState(), pd.getPersistenceCache(), entityId, pd); node.setData(entity); node.setPersistenceDelegator(pd); mainCache.addNodeToCache(node); }
Node node = mainCache.getNodeFromCache(nodeId, this);