예제 #1
0
 /**
  * handleAddAttributeCommand
  * Adds or override new attributes to
  * @param addAttributeCommand
  */
 public void handleAddAttributeCommand(Command addAttributeCommand)
 {
     int entityId=addAttributeCommand.getEntityId();
     NodeAttribute[] attributes = addAttributeCommand.getAttributes();
     registry.addAttributes(entityId, attributes);
     Node node=registry.getNode(entityId);
     foreach (NodeAttribute attribute in attributes) {
     NodeAttribute oldValue = node.getAttributes().get(attribute.getName());
     if(oldValue!=null){
         foreach (NodeModelChangedListener listenerNode in listenerNodes) {
             listenerNode.attributeChanged(node, oldValue, attribute);
         }
     }else{
         foreach (NodeModelChangedListener listenerNode in listenerNodes) {
             listenerNode.attributeAdded(node, attribute);
         }
     }
     }
 }
예제 #2
0
 /**
  * handleUpdateNodeCommand
  * Remove old attributes and set or override new ones.
  * @param updateItemCommand
  */
 public void handleUpdateNodeCommand(Command updateItemCommand)
 {
     int entityId=updateItemCommand.getEntityId();
     NodeAttribute[] attributes = updateItemCommand.getAttributes();
     Node node=registry.getNode(entityId);
     List<NodeAttribute> removedAttributes = registry.updateNode(entityId, attributes);
     foreach (NodeAttribute oldAttribute in removedAttributes) {
     foreach (NodeModelChangedListener listenerNode in listenerNodes) {
         listenerNode.attributeChanged(node, oldAttribute, null);
     }
     }
     foreach (NodeAttribute attribute in attributes) {
     NodeAttribute oldValue = node.getAttributes().get(attribute.getName());
     if(oldValue!=null){
         foreach (NodeModelChangedListener listenerNode in listenerNodes) {
             listenerNode.attributeChanged(node, oldValue, attribute);
         }
     }else{
         foreach (NodeModelChangedListener listenerNode in listenerNodes) {
             listenerNode.attributeAdded(node, attribute);
         }
     }
     }
 }
예제 #3
0
        /**
         * handleNewItemCommand
         * Creates new node
         * @param itemCommand
         * @throws PlanckDBException
         */
        public void handleNewItemCommand(Command itemCommand)
        {
            int entityId= itemCommand.getEntityId();
            NodeAttribute[] attributes = itemCommand.getAttributes();
            bool entityLock= itemCommand.getLock();
            int ownerId=entityLock? itemCommand.GetSessionId(): PlanckDBConstants.NON_ENTITY_OWNER;

            registry.createNewNode(entityId,entityLock,sessionMetaData.GetSessionId(),ownerId,attributes);
            Node node=registry.getNode(entityId);
            foreach (NodeModelChangedListener listenerNode in listenerNodes) {
            listenerNode.newItem(node);
            }
            foreach (NodeModelChangedListener listenerNode in listenerNodes) {
            foreach (NodeAttribute attribute in attributes) {
                listenerNode.attributeChanged(node, null, attribute);
            }
            }
        }
예제 #4
0
 /**
  * handleRemoveAttributeCommand
  * Removes attributes from node
  * @param updateItemCommand
  */
 public void handleRemoveAttributeCommand(Command updateItemCommand)
 {
     int entityId=updateItemCommand.getEntityId();
     NodeAttribute[] attributes = updateItemCommand.getAttributes();
     registry.removeAttributes(entityId, attributes);
     Node node=registry.getNode(entityId);
     foreach (NodeModelChangedListener listenerNode in listenerNodes) {
     foreach (NodeAttribute attribute in attributes) {
         listenerNode.attributeChanged(node, attribute, null);
     }
     }
 }
예제 #5
0
 public Command revertCommand(Command command)
 {
     int commandType=command.getCommandType();
     Int32 entityId = command.getEntityId();
     Int32 childEntityId = command.getChildEntityId();
     Int32 schemaId=(Int32)command.GetSchemaId();
     Int32 coreManagerId=command.GetCoreManagerKey();
     Int32 sessionId=command.GetSessionId();
     bool lockEntity=command.getLock();
     bool oldLock=command.getOldLock();
     NodeAttribute[] oldAttributes=command.getOldAttributes();
     NodeAttribute[] attributes=command.getAttributes();
     byte[] arcName=command.getArcName();
     long lockTimeout=command.getLockTimeOut();
     switch (commandType){
         case PlanckDBConstants.CREATE_NEW_ENTITY:{
             return buildDeleteNode(entityId,lockEntity,schemaId,coreManagerId,sessionId, lockTimeout, attributes);
         }
         case PlanckDBConstants.DELETE_ENTITY:{
             Command newCommand= buildCreateNode(oldLock,schemaId,coreManagerId,sessionId, lockTimeout, oldAttributes);
             newCommand.Push(PlanckDBConstants.ENTITY_ID, PlanckDBConstants.INTEGER,entityId);
             return newCommand;
         }
         case PlanckDBConstants.ADD_CHILD_ENTITY_TO_PARENT_ENTITY:{
             return buildRemoveChildFromParentNode(entityId,arcName,childEntityId,schemaId,coreManagerId,sessionId, lockTimeout);
         }
         case PlanckDBConstants.REMOVE_CHILD_ENTITY_FROM_PARENT_ENTITY:{
             return buildAddChildToParentNode(entityId,childEntityId,arcName,schemaId,coreManagerId,sessionId, lockTimeout);
         }
         case PlanckDBConstants.UPDATE_ENTITY:{
             Command newCommand = buildUpdateNode(entityId, schemaId, coreManagerId, sessionId, lockTimeout, attributes);
             newCommand.Push(PlanckDBConstants.OLD_ATTRIBUTES, PlanckDBConstants.ATTRIBUTE_MAP,oldAttributes);
             return newCommand;
         }
         case PlanckDBConstants.ADD_ATTRIBUTE:{
             return buildRemoveAttributes(entityId,schemaId,coreManagerId,sessionId,lockTimeout,attributes);
         }
         case PlanckDBConstants.REMOVE_ATTRIBUTE:{
             return buildAddAttributes(entityId,schemaId,coreManagerId,sessionId, lockTimeout, oldAttributes);
         }
     }
     throw  new PlanckDBException("unsupported state the should not reach to this point of the code");
 }