public synchronized void removeNodeFromCache(Node node) { if (getHeadNodes().contains(node)) { getHeadNodes().remove(node); } if (nodeMappings.get(node.getNodeId()) != null) { nodeMappings.remove(node.getNodeId()); } evictFroml2Cache(node); logCacheEvent("REMOVED FROM ", node.getNodeId()); node = null; // Eligible for GC }
public void addGraphToCache(ObjectGraph graph, PersistenceCache persistenceCache) { // Add each node in the graph to cache for (String key : graph.getNodeMapping().keySet()) { Node thisNode = graph.getNodeMapping().get(key); addNodeToCache(thisNode); // Remove all those head nodes in persistence cache, that are there // in Graph as a non-head node if (!thisNode.isHeadNode() && persistenceCache.getMainCache().getHeadNodes().contains(thisNode)) { persistenceCache.getMainCache().getHeadNodes().remove(thisNode); } } // Add head Node to list of head nodes addHeadNode(graph.getHeadNode()); }
@Test public void testPersistenceCache() { Store store = new Store(1, "Food Bazaar, Noida"); store.addCounter(new BillingCounter(1, "A")); store.addCounter(new BillingCounter(2, "B")); store.addCounter(new BillingCounter(3, "C")); ObjectGraph graph = graphBuilder.getObjectGraph(store, null); pc.getMainCache().addGraphToCache(graph, pc); Assert.assertNotNull(pc.getMainCache()); Assert.assertEquals(1, pc.getMainCache().getHeadNodes().size()); PersistenceDelegator pd = new PersistenceDelegator(emfImpl.getKunderaMetadataInstance(), pc); Node headNode = pc.getMainCache().getNodeFromCache(ObjectGraphUtils.getNodeId("1", Store.class), pd); Assert.assertNotNull(headNode); Assert.assertNull(headNode.getParents()); Assert.assertEquals(3, headNode.getChildren().size()); Assert.assertEquals(4, pc.getMainCache().size()); }
@Test public void testFlashStockForStore() { FlushManager flushManager = new FlushManager(); Store store = new Store(1, "Food Bazaar, Noida"); store.addCounter(new BillingCounter(1, "A")); store.addCounter(new BillingCounter(2, "B")); store.addCounter(new BillingCounter(3, "C")); ObjectGraph graph = graphBuilder.getObjectGraph(store, null); pc.getMainCache().addGraphToCache(graph, pc); Assert.assertNotNull(pc.getMainCache()); Assert.assertEquals(1, pc.getMainCache().getHeadNodes().size()); PersistenceDelegator pd = new PersistenceDelegator(emfImpl.getKunderaMetadataInstance(), pc); Node headNode = pc.getMainCache().getNodeFromCache(ObjectGraphUtils.getNodeId("1", Store.class), pd); Assert.assertNotNull(headNode); Assert.assertNull(headNode.getParents()); Assert.assertEquals(3, headNode.getChildren().size()); Assert.assertEquals(4, pc.getMainCache().size()); markAllNodeAsDirty(); flushManager.buildFlushStack(headNode, EventType.INSERT); Deque<Node> fs = flushManager.getFlushStack(); Assert.assertEquals(4, fs.size()); }
/** * */ private void markAllNodeAsDirty() { if (pc.getMainCache() != null) { Set<Node> headNodes = pc.getMainCache().getHeadNodes(); if (headNodes != null) { for (Node hn : headNodes) { if (hn != null) hn.setDirty(true); } } Collection<Node> allNodes = pc.getMainCache().getAllNodes(); if (allNodes != null) { for (Node node : allNodes) { if (node != null) node.setDirty(true); } } } }