@Override public void handleMerge(NodeStateContext nodeStateContext) { // Ignored, entity remains in the same state // Mark this entity for saving in database depending upon whether it's // deep equals to the // one in persistence cache // nodeStateContext.setDirty(true); // if (((Node) nodeStateContext).isDirty() || ((Node) nodeStateContext).isInState(DetachedState.class)) // { ((Node) nodeStateContext).setUpdate(true); // Add this node into persistence cache nodeStateContext.getPersistenceCache().getMainCache().addNodeToCache((Node) nodeStateContext); // Cascade merge operation for all related entities for whom // cascade=ALL // or MERGE // recursivelyPerformOperation(nodeStateContext, OPERATION.MERGE); // } }
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()); }
@Override public void handlePersist(NodeStateContext nodeStateContext) { // Transient ---> Managed moveNodeToNextState(nodeStateContext, new ManagedState()); // Mark this entity for saving in database nodeStateContext.setDirty(true); // Add this node into persistence cache nodeStateContext.getPersistenceCache().getMainCache().addNodeToCache((Node) nodeStateContext); // Recurse persist operation on all managed entities for whom // cascade=ALL or PERSIST // recursivelyPerformOperation(nodeStateContext, OPERATION.PERSIST); }
@Override public void handleMerge(NodeStateContext nodeStateContext) { // create a new managed entity and copy state of original entity into // this one. Object copiedNodeData = ObjectUtils.deepCopy(nodeStateContext.getData(), nodeStateContext.getPersistenceDelegator().getKunderaMetadata()); nodeStateContext.setData(copiedNodeData); moveNodeToNextState(nodeStateContext, new ManagedState()); nodeStateContext.getPersistenceCache().getMainCache().addNodeToCache((Node) nodeStateContext); }