int commandExecuterRemoveChild(CommandExecuter commandExecuter,Command command){ CommandExecuterInternal* internal=(CommandExecuterInternal*)commandExecuter; Node parent; int result; result=registryGetNode(internal->registry,commandGetInt(command,ENTITY_ID),&parent); VALIDATE(result); Node child; char* arcName; int arcLength=commandGetByteArray(command,ARC_NAME,&arcName); return registryRemoveChild(internal->registry,parent,arcName,arcLength,commandGetInt(command,SESSION_ID)); }
int validationManagerValidateOnCoreExecuteInternalRecurcive(ValidationManager validationManager,ArrayList commands,int administrator,int dept){ ValidationManagerStruct* internal=(ValidationManagerStruct*)validationManager; if(commands!=NULL&&dept<arrayListSize(commands)){ Command command=arrayListGetValueAt(commands,dept); int coreManagerId=commandGetInt(command,CORE_MANAGER_ID); int sessionId=commandGetInt(command,SESSION_ID); int transaction=commandGetInt(command,TRANSACTION); int schimaId=commandGetInt(command,SCHEMA_ID); int type=commandGetInt(command,COMMAND_TYPE); int version=commandGetInt(command,VERSION); int entityId=commandGetInt(command,ENTITY_ID); VALIDATE_TRANSACTION(transaction); VALIDATE_CORE_MANAGER_ID(coreManagerId); VALIDATE_SESSION_ID(sessionId); if(IS_CREATE_NEW_ENTITY(type)){ int lock=commandGetInt(command,LOCK); StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES); VALIDATE(registryValidateNodeCreate(internal->registry,entityId)); Node node; nodeCreate(internal->registry,entityId,schimaId,lock,&node); stringHashmapPutAll(node->attributes,newAttributesMap); stringHashmapFree(newAttributesMap); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if( VALID!= result){ registryDeleteNode(internal->registry,node); return result; } char* buf; int length=nodeSerialize(node,&buf); commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length); memoryFree(buf); } if(IS_ADD_CHILD_ENTITY_TO_PARENT_ENTITY(type)){ char* arcName; int childEntityId=commandGetInt(command,ENTITY_CHILD_ID); int arcNameLenght=commandGetString(command,ARC_NAME,&arcName); Node parent; registryGetNode(internal->registry,entityId,&parent); Node child; registryGetNode(internal->registry,childEntityId,&child); VALIDATE(registryValidateAddChild(parent,child,arcName,arcNameLenght,sessionId)); registryAddChild(internal->registry,parent,child,arcName,arcNameLenght); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if( VALID!= result){ registryRemoveChild(internal->registry,parent,arcName,arcNameLenght); return result; } char* buf; int length=nodeSerialize(parent,&buf); commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length); memoryFree(buf); } if(IS_REMOVE_CHILD_ENTITY_FROM_PARENT_ENTITY(type)){ char* arcName; int childEntityId=commandGetInt(command,ENTITY_CHILD_ID); int arcNameLenght=commandGetString(command,ARC_NAME,&arcName); Node parent; registryGetNode(internal->registry,entityId,&parent); Node child; registryGetNode(internal->registry,childEntityId,&child); VALIDATE(registryValidateRemoveChild(parent,arcName,arcNameLenght,sessionId)); registryRemoveChild(internal->registry,parent,arcName,arcNameLenght); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if( VALID!= result){ registryAddChild(internal->registry,parent,child,arcName,arcNameLenght); return result; } char* buf; int length=nodeSerialize(parent,&buf); commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length); memoryFree(buf); } if(IS_LOCK_ENTITY(type)){ int lock=commandGetInt(command,LOCK); int forceLock=commandGetInt(command,FORCE_LOCK); Node node; registryGetNode(internal->registry,entityId,&node); VALIDATE(registryValidateUpdateLock(node,lock,sessionId,forceLock,administrator)); registryUpdateLock(internal->registry,node,lock,sessionId); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if( VALID!= result){ int revertedLock=lock==TRUE?FALSE:TRUE; registryUpdateLock(internal->registry,node,revertedLock,sessionId); return result; } } if(IS_DELETE_ENTITY(type)){ int lock=commandGetInt(command,LOCK); Node node; VALIDATE(registryGetNode(internal->registry,entityId,&node)); VALIDATE(registryValidateDeleteNode(node,sessionId)); registryDeleteNode(internal->registry,node); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if( VALID!= result){ nodeCreate(internal->registry,entityId,schimaId,lock,&node); return result; } } if(IS_ADD_ATTRIBUTE(type)){ StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES); Node node; registryGetNode(internal->registry,entityId,&node); VALIDATE(registryValidateUpdate(node,sessionId)); Array array; stringHashmapToArray(newAttributesMap,&array); int lenght=arrayGetLength(array); int i; StringHashMap toRemove = stringHashmapCreate(SMALL_CONTAINER_SIZE); for(i=0;i<lenght;i++){ Attribute newAttribute=(Attribute)arrayGetObject(array,i); Attribute oldAttribute; stringHashmapGet(node->attributes,newAttribute->name,newAttribute->nameLength,(Object) &oldAttribute); if(oldAttribute!=NULL){ stringHashmapPut(toRemove,newAttribute->name,newAttribute->nameLength,oldAttribute); stringHashmapRemove(node->attributes,newAttribute->name,newAttribute->nameLength); } stringHashmapPut(node->attributes,newAttribute->name,newAttribute->nameLength,(Object)newAttribute); } arrayFree(array); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if(result!=VALID){ stringHashmapToArray(newAttributesMap,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute newAttribute=(Attribute)arrayGetObject(array,i); stringHashmapRemove(node->attributes,newAttribute->name,newAttribute->nameLength); attributeFree(newAttribute,TRUE); } stringHashmapPutAll(node->attributes,toRemove); arrayFree(array); stringHashmapFree(toRemove); }else{ stringHashmapToArray(toRemove,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute oldAttribute=(Attribute)arrayGetObject(array,i); stringHashmapRemove(toRemove,oldAttribute->name,oldAttribute->nameLength); attributeFree(oldAttribute,TRUE); } arrayFree(array); stringHashmapFree(toRemove); } stringHashmapFree(newAttributesMap); char* buf; int length=nodeSerialize(node,&buf); commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length); memoryFree(buf); } if(IS_REMOVE_ATTRIBUTE(type)){ StringHashMap toRemoveAttributeMap=commandGetAttributes(command,ATTRIBUTES); Node node; registryGetNode(internal->registry,entityId,&node); VALIDATE(registryValidateUpdate(node,sessionId)); Array array; stringHashmapToArray(toRemoveAttributeMap,&array); int lenght=arrayGetLength(array); int i; StringHashMap oldAttributes = stringHashmapCreate(SMALL_CONTAINER_SIZE); for(i=0;i<lenght;i++){ Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i); Attribute oldAttribute; stringHashmapGet(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object) &oldAttribute); if(oldAttribute!=NULL){ stringHashmapPut(oldAttributes,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object)oldAttribute); stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength); } } arrayFree(array); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if(result!=VALID){ stringHashmapToArray(oldAttributes,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute oldAttribute=(Attribute)arrayGetObject(array,i); stringHashmapPut(node->attributes,oldAttribute->name,oldAttribute->nameLength,(Object)oldAttribute); } arrayFree(array); stringHashmapToArray(toRemoveAttributeMap,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i); stringHashmapPut(toRemoveAttributeMap,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object)toRemoveAttribute); attributeFree(toRemoveAttribute,TRUE); } arrayFree(array); stringHashmapFree(toRemoveAttributeMap); }else{ stringHashmapToArray(oldAttributes,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute oldAttribute=(Attribute)arrayGetObject(array,i); stringHashmapRemove(oldAttributes,oldAttribute->name,oldAttribute->nameLength); attributeFree(oldAttribute,TRUE); } arrayFree(array); stringHashmapToArray(toRemoveAttributeMap,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute toAddAttribute=(Attribute)arrayGetObject(array,i); stringHashmapPut(toRemoveAttributeMap,toAddAttribute->name,toAddAttribute->nameLength,(Object)toAddAttribute); attributeFree(toAddAttribute,TRUE); } arrayFree(array); stringHashmapFree(toRemoveAttributeMap); } char* buf; int length=nodeSerialize(node,&buf); commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length); memoryFree(buf); } if(IS_UPDATE_ENTITY(type)){ StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES); Node node; registryGetNode(internal->registry,entityId,&node); StringHashMap oldAttributesMap=stringHashmapCreate(SMALL_CONTAINER_SIZE); stringHashmapPutAll(oldAttributesMap,node->attributes); Array array; stringHashmapToArray(node->attributes,&array); int lenght=arrayGetLength(array); int i; for(i=0;i<lenght;i++){ Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i); stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength); } stringHashmapPutAll(node->attributes,newAttributesMap); int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1); if(result!=VALID){ stringHashmapToArray(node->attributes,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i); stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength); attributeFree(toRemoveAttribute,TRUE); } stringHashmapPutAll(node->attributes,oldAttributesMap); stringHashmapFree(newAttributesMap); stringHashmapFree(oldAttributesMap); }else{ stringHashmapToArray(oldAttributesMap,&array); lenght=arrayGetLength(array); for(i=0;i<lenght;i++){ Attribute oldAttribute=(Attribute)arrayGetObject(array,i); stringHashmapRemove(oldAttributesMap,oldAttribute->name,oldAttribute->nameLength); attributeFree(oldAttribute,TRUE); } stringHashmapFree(oldAttributesMap); stringHashmapFree(newAttributesMap); } char* buf; int length=nodeSerialize(node,&buf); commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length); memoryFree(buf); } } return VALID; }