Beispiel #1
0
ArrayList registrySerializeToCommands(Registry registry){
	RegistryInternal* internal=(RegistryInternal*)registry;

	ArrayList commands=arrayListCreate();
	Array nodeArray;
	hashmapToArray(internal->nodes,&nodeArray);
	int length=arrayGetLength(nodeArray);
	int i;
        int coreManagerId=SERVER_COREMANAGER_ID;
        int serverSessionId=SERVER_SESSION_ID;
	for(i=0;i<length;i++){
		Node node=arrayGetObject(nodeArray,i);
		int schemaId=node->schemaId;
		int locked=node->locked;
		int version=-1;
		int commandType=CREATE_NEW_ENTITY;
		int entityId=node->id;
                
		Command command=commandCreate();
		commandPush(command,COMMAND_TYPE,INTEGER,&commandType,SIZE_OF_INT);
		commandPush(command,LOCK,INTEGER,&locked,SIZE_OF_INT);
		commandPush(command,SCHEMA_ID,INTEGER,&schemaId,SIZE_OF_INT);
		commandPush(command,ENTITY_ID,INTEGER,&entityId,SIZE_OF_INT);
		commandPush(command,VERSION,INTEGER,&version,SIZE_OF_INT);
                commandPush(command,ATTRIBUTES,ATTRIBUTES_MAP,node->attributes,CONTAINER_SIZE);
                commandPush(command,CORE_MANAGER_ID,INTEGER,&coreManagerId,0);
                commandPush(command,SESSION_ID,INTEGER,&serverSessionId,0);
		arrayListAddLast(commands,command);
	}
	for(i=0;i<length;i++){
		Node node=arrayGetObject(nodeArray,i);
		NodeInternal* nodeInternal=(NodeInternal*)node;
		Array children;
		stringHashmapToArray(nodeInternal->children,&children);
		int childrenAmount=arrayGetLength(children);
		int version=-1;
		int schemaId=node->schemaId;
		int j;
		int commandType=ADD_CHILD_ENTITY_TO_PARENT_ENTITY;
		for(j=0;j<childrenAmount;j++){
			Arc childArc=arrayGetObject(children,j);                       
			Command command=commandCreate();
			commandPush(command,COMMAND_TYPE,INTEGER,&commandType,SIZE_OF_INT);
			commandPush(command,ENTITY_ID,INTEGER,&node->id,SIZE_OF_INT);
			commandPush(command,ENTITY_CHILD_ID,INTEGER,&childArc->child->id,SIZE_OF_INT);
			commandPush(command,SCHEMA_ID,INTEGER,&schemaId,SIZE_OF_INT);
			commandPush(command,VERSION,INTEGER,&version,SIZE_OF_INT);
                        commandPush(command,CORE_MANAGER_ID,INTEGER,&coreManagerId,SIZE_OF_INT);
                        commandPush(command,SESSION_ID,INTEGER,&serverSessionId,SIZE_OF_INT);
                        commandPush(command,ARC_NAME,BYTE_ARRAY,childArc->arcName,childArc->arcLength);
			arrayListAddLast(commands,command);
		}
                arrayFree(children);
	}
        arrayFree(nodeArray);
	return commands;
}       
Beispiel #2
0
ArrayList registryGetAllChildsOfNode(Registry registry,Node nodeObject ,int dept){
	ArrayList result=arrayListCreate();
	if(dept==0){
		return result;
	}
	if(nodeObject==NULL){
		return result;
	}
	NodeInternal* node=(NodeInternal*)nodeObject;
	if(node!=NULL){
		Array array;
		stringHashmapToArray(node->children,&array);
		int length=arrayGetLength(array);
		int i;
		for(i=0;i<length;i++){
			Arc arc=arrayGetObject(array,i);
			arrayListAddLast(result,arc->child);
                        ArrayList list=registryGetAllChildsOfNode(registry,arc->child,dept-1);
			arrayListAddAll(result,list);
                        arrayListFree(list);
		}
                arrayFree(array);
	}
	return result;
}
Beispiel #3
0
void tcpConnectionPushCommand(TcpConnection tcpConnection,Command command){
        TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
        if(internal->active==TRUE){
            environmentThreadLock(internal->thread);
            arrayListAddLast(internal->commands,command);
            environmentThreadNotify(internal->thread);
            environmentThreadUnlock(internal->thread);
        }
}
Beispiel #4
0
int registryCreateChildrenBufferElemrnts(ArrayList list,Object data,char* key,int keyLenght){
    ArcStruct * arc=(ArcStruct*)data;
    void* buffer=memoryAlloc(+SIZE_OF_INT*2+arc->arcLength);
    NodeInternal* node=(NodeInternal*)arc->child;
    memcpy(buffer+SIZE_OF_INT*0,&(node->id),SIZE_OF_INT);
    memcpy(buffer+SIZE_OF_INT*1,&arc->arcLength,SIZE_OF_INT);
    memcpy(buffer+SIZE_OF_INT*2,arc->arcName,arc->arcLength);
    arrayListAddLast(list,buffer);
    return VALID;
}
Beispiel #5
0
int validationManagerValidateOnCoreExecute(ValidationManager validationManager,Command command,ArrayList commands,int atomic){
	int administrator=commandGetInt(command,MARKED_AS_ADMINISTRATOR);
	if(atomic==TRUE){
		return validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,0);
	}else{
            commands =arrayListCreate();
            arrayListAddLast(commands,command);
            int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,0);
            arrayListFree(commands);
            return result;
	}
}
Beispiel #6
0
/**
 * addArcToNode method
 * Like the non transactional schemaAdapter in addArcToNode entity,
 * but unlike the non transactional schemaAdapter, this schemaAdapter commits its changes directly on the entities
 * It also accumulate the command in order to rollback the changes in the client or commit the changes in the server
 */
int transactionAddArcToNode(Transaction transaction,Node parent, Node child,char arcName[],int arcNameLenght){
    TransactionInternal*internal=(TransactionInternal*)transaction;
    int result;
    if(internal->transaction!=NULL){
        result=transactionAddArcToNode(internal->transaction,parent, child, arcName,arcNameLenght);
    }else{
        validateSchemaEntity(internal,parent);
        validateSchemaEntity(internal,child);
        int schemaId=internal->sessionMetaData->schemaId;
        int coreManagerId=internal->sessionMetaData->coreManagerId;
        int sessionId=internal->sessionMetaData->id;
        int lockTimeout= schemaAdapterGetLockTimeout(internal->scheamAdapter);
        Command command = commandBuilderCreateAddChildToParentNode(parent->id, child->id, arcName,arcNameLenght, schemaId, coreManagerId, sessionId, lockTimeout);
        commandPush(TRANSACTION, INTEGER, TRUE);
        result=commandExecuterConsume(internal->commandExecutor,command);
        arrayListAddLast(internal->commandList,command);
    }
    return result;
}
Beispiel #7
0
int transactionRemoveAttributeFromNode(Transaction transaction,Node node,StringHashMap attributes){
    TransactionInternal*internal=(TransactionInternal*)transaction;
    int result;
    if(internal->transaction!=NULL){
        result=transactionRemoveAttributeFromNode(internal->transaction,node, attributes);
    }else{
        validateSchemaEntity(internal,node);
        int schemaId=internal->sessionMetaData->schemaId;
        int coreManagerId=internal->sessionMetaData->coreManagerId;
        int sessionId=internal->sessionMetaData->id;
        int lockTimeout= schemaAdapterGetLockTimeout(internal->scheamAdapter);
        int true=TRUE;
        Command command = commandBuilderCreateRemoveAttributes(node->id, schemaId, coreManagerId, sessionId,lockTimeout,attributes);
        commandPush(command,OLD_ATTRIBUTES,ATTRIBUTES_MAP, node->attributes);
        commandPush(command,TRANSACTION, INTEGER, &true);
        result=commandExecuterConsume(internal->commandExecutor,command);
        arrayListAddLast(internal->commandList,command);
    }
    return result;
}
Beispiel #8
0
int transactionRemoveArcFromNode(Transaction transaction,Node parent, char arcName[],int arcNameLenght){
    TransactionInternal*internal=(TransactionInternal*)transaction;
    int result;
    if(internal->transaction!=NULL){
        result=transactionRemoveArcFromNode(internal->transaction,parent, arcName,arcNameLenght);
    }else{
        validateSchemaEntity(internal,parent);
        Arc arc;
        stringHashmapGet(parent->children,arcName,arcNameLenght,(Object*)&arc);
        if(arc!=NULL){
            int schemaId=internal->sessionMetaData->schemaId;
            int coreManagerId=internal->sessionMetaData->coreManagerId;
            int sessionId=internal->sessionMetaData->id;
            int lockTimeout= schemaAdapterGetLockTimeout(internal->scheamAdapter);
            int true = TRUE;
            Command command = commandBuilderCreateAddChildToParentNode(parent->id,arc->child->id,arcName,arcNameLenght, schemaId, coreManagerId, sessionId,lockTimeout);
            commandPush(TRANSACTION, INTEGER, &true);
            result=commandExecuterConsume(internal->commandExecutor,command);
            arrayListAddLast(internal->commandList,command);
        }else{
            return -1;