@Override public void handleFlush(NodeStateContext nodeStateContext) { // Entity state to remain as Managed // Flush this node to database Client client = nodeStateContext.getClient(); client.persist((Node) nodeStateContext); // logNodeEvent("FLUSHED", this, nodeStateContext.getNodeId()); // Since node is flushed, mark it as NOT dirty nodeStateContext.setDirty(false); }
@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); }
/** * @param nodeStateContext */ void moveNodeToNextState(NodeStateContext nodeStateContext, NodeState nextState) { nodeStateContext.setCurrentNodeState(nextState); }
Client client = nodeStateContext.getClient(); Class<?> nodeDataClass = nodeStateContext.getDataClass(); EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(nodeStateContext.getPersistenceDelegator().getKunderaMetadata(), nodeDataClass); Object entityId = nodeStateContext.getEntityId(); relationStack.put(nodeDataClass.getCanonicalName()+"#"+PropertyAccessorHelper.getId(entity, entityMetadata), entity); nodeData = reader.recursivelyFindEntities(ee.getEntity(), ee.getRelations(), entityMetadata, nodeStateContext.getPersistenceDelegator(), false,relationStack); nodeStateContext.setData(nodeData); nodeStateContext.getPersistenceCache().getMainCache().processNodeMapping((Node) nodeStateContext); nodeStateContext.setDirty(false);
@Override public void handleRefresh(NodeStateContext nodeStateContext) { // Refresh entity state from the database // Fetch Node data from Client Client client = nodeStateContext.getClient(); Class<?> nodeDataClass = nodeStateContext.getDataClass(); EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(nodeStateContext.getPersistenceDelegator().getKunderaMetadata(), nodeDataClass); Object entityId = nodeStateContext.getEntityId(); EntityReader reader = client.getReader(); EnhanceEntity ee = reader.findById(entityId, entityMetadata, client); if (ee != null && ee.getEntity() != null) { Object nodeData = ee.getEntity(); nodeStateContext.setData(nodeData); } // Cascade refresh operation for all related entities for whom // cascade=ALL or REFRESH recursivelyPerformOperation(nodeStateContext, OPERATION.REFRESH); }
@Override public void handleFlush(NodeStateContext nodeStateContext) { // Entity state to remain as Removed // Flush this node to database Client client = nodeStateContext.getClient(); Node node = (Node) nodeStateContext; Object entityId = node.getEntityId(); client.remove(node.getData(), entityId); // Since node is flushed, mark it as NOT dirty nodeStateContext.setDirty(false); // Remove this node from Persistence Cache nodeStateContext.getPersistenceCache().getMainCache().removeNodeFromCache(node); }
@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 handleRollback(NodeStateContext nodeStateContext) { // If persistence context is EXTENDED, Next state should be Managed // If persistence context is TRANSACTIONAL, Node should be detached if (PersistenceContextType.EXTENDED.equals(nodeStateContext.getPersistenceCache().getPersistenceContextType())) { moveNodeToNextState(nodeStateContext, new ManagedState()); } else if (PersistenceContextType.TRANSACTION.equals(nodeStateContext.getPersistenceCache() .getPersistenceContextType())) { nodeStateContext.detach(); } }
@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); // } }
Map<NodeLink, Node> children = nodeStateContext.getChildren(); if (children != null)
/** * Test method for * {@link com.impetus.kundera.lifecycle.states.NodeState#moveNodeToNextState(com.impetus.kundera.lifecycle.NodeStateContext, com.impetus.kundera.lifecycle.states.NodeState)} * . */ @Test public void testMoveNodeToNextState() { NodeState nodeState = new TransientState(); NodeStateContext node = new Node("1", PersonnelDTO.class, nodeState, pc, "1", null); nodeState.moveNodeToNextState(node, new ManagedState()); Assert.assertEquals(ManagedState.class, node.getCurrentNodeState().getClass()); }
@Override public void handleRollback(NodeStateContext nodeStateContext) { // If persistence context is EXTENDED, Next state should be Transient // If persistence context is TRANSACTIONAL, Next state should be // detached if (PersistenceContextType.EXTENDED.equals(nodeStateContext.getPersistenceCache().getPersistenceContextType())) { moveNodeToNextState(nodeStateContext, new TransientState()); } else if (PersistenceContextType.TRANSACTION.equals(nodeStateContext.getPersistenceCache() .getPersistenceContextType())) { moveNodeToNextState(nodeStateContext, new DetachedState()); } }
@Override public void handleCommit(NodeStateContext nodeStateContext) { nodeStateContext.setCurrentNodeState(new TransientState()); }
@Override public void handleCommit(NodeStateContext nodeStateContext) { nodeStateContext.setCurrentNodeState(new DetachedState()); }