public Node getNodeFromCache(Object entity, EntityMetadata entityMetadata, PersistenceDelegator pd) { if (entity == null) { throw new IllegalArgumentException("Entity is null, can't check whether it's in persistence context"); } Object primaryKey = PropertyAccessorHelper.getId(entity, entityMetadata); if (primaryKey == null) { throw new IllegalArgumentException("Primary key not set into entity"); } String nodeId = ObjectGraphUtils.getNodeId(primaryKey, entity.getClass()); return getNodeFromCache(nodeId, pd); }
/** * Remove the given entity from the persistence context, causing a managed * entity to become detached. */ public void detach(Object entity) { Node node = getPersistenceCache().getMainCache().getNodeFromCache(entity, getMetadata(entity.getClass()), this); if (node != null) { node.detach(); } }
/** * Check if the instance is a managed entity instance belonging to the * current persistence context. */ boolean contains(Object entity) { Node node = getPersistenceCache().getMainCache().getNodeFromCache(entity, getMetadata(entity.getClass()), this); return node != null && node.isInState(ManagedState.class); }
private NodeState getChildNodeState(EntityMetadata metadata, Object childObj) { Object childId = PropertyAccessorHelper.getId(childObj, metadata); String childNodeId = ObjectGraphUtils.getNodeId(childId, childObj.getClass()); Node childNodeInCache = persistenceCache.getMainCache().getNodeFromCache(childNodeId, pd); return childNodeInCache != null ? childNodeInCache.getCurrentNodeState() : new TransientState(); }
Assert.assertTrue(storeNode.isDirty()); Assert.assertNotNull(storeNode.getPersistenceCache().getMainCache() .getNodeFromCache(storeNode.getNodeId(), null));
Assert.assertTrue(storeNode.isUpdate()); Assert.assertNotNull(storeNode.getPersistenceCache().getMainCache() .getNodeFromCache(storeNode.getNodeId(), null));
@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()); }
.getPersistenceCache() .getMainCache() .getNodeFromCache( entity1, KunderaMetadataManager.getEntityMetadata(persistenceDelegator.getKunderaMetadata(), .getPersistenceCache() .getMainCache() .getNodeFromCache( entity2, KunderaMetadataManager.getEntityMetadata(persistenceDelegator.getKunderaMetadata(), .getPersistenceCache() .getMainCache() .getNodeFromCache( entity1, KunderaMetadataManager.getEntityMetadata(persistenceDelegator.getKunderaMetadata(),
Node nodeInPersistenceCache = pd.getPersistenceCache().getMainCache().getNodeFromCache(nodeId, pd);
@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()); }
Node nodeInPersistenceCache = persistenceCache.getMainCache().getNodeFromCache(nodeId, pd);
@Test public void test_1_1_1_1() { FlushManager flushManager = new FlushManager(); PhotographerUni_1_1_1_1 a = new PhotographerUni_1_1_1_1(); a.setPhotographerId(1); AlbumUni_1_1_1_1 b = new AlbumUni_1_1_1_1(); b.setAlbumId("b1"); PhotoUni_1_1_1_1 c = new PhotoUni_1_1_1_1(); c.setPhotoId("c1"); a.setAlbum(b); b.setPhoto(c); ObjectGraph graph = graphBuilder.getObjectGraph(a, null); pc.getMainCache().addGraphToCache(graph, pc); PersistenceDelegator pd = new PersistenceDelegator(emfImpl.getKunderaMetadataInstance(), pc); Node headNode = pc.getMainCache() .getNodeFromCache(ObjectGraphUtils.getNodeId("c1", PhotoUni_1_1_1_1.class), pd); markAllNodeAsDirty(); flushManager.buildFlushStack(graph.getHeadNode(), EventType.INSERT); Deque<Node> fs = flushManager.getFlushStack(); Assert.assertEquals(3, fs.size()); }