diff --git a/exec/load/json-db.js b/exec/load/json-db.js index 4517cac74dc12a139cef80d7fe3c491b1c9462dd..5e42c9d85c77c53e8f1ef572db1f5dc571020b44 100644 --- a/exec/load/json-db.js +++ b/exec/load/json-db.js @@ -503,15 +503,18 @@ function JSONdb (fileName) { /* generic query handler, will process locks, reads, writes, and unlocks and put them into the appropriate queues */ this.query = function(client,query) { - if(query.location == undefined || query.location.length == 0) - query.location = "data"; - else - query.location = "data." + query.location; - /* store the child name */ - var parent = get_pname(query.location); - /* strip the last child identifier from the string */ - var property = get_cname(query.location); + /* retain original query location for subscriber updates */ + var location = query.location; + if(location == undefined || location.length == 0) + location = "data"; + else + location = "data." + location; + + /* store the parent name */ + var parent = get_pname(location); + /* strip the last child identifier from the string */ + var property = get_cname(location); /* temporary array for queue additions */ var q=[]; @@ -539,7 +542,7 @@ function JSONdb (fileName) { } q.push(new Request( - client,query.oper,parent,property,query.data,query.timeout + client,query.oper,query.location,parent,property,query.data,query.timeout )); /* push this query into a queue to be processed at the next response cycle (this.cycle()) */; @@ -548,11 +551,11 @@ function JSONdb (fileName) { if(query.lock !== locks.NONE) { /* put lock ahead of the operation in request queue */ q.unshift(new Request( - client,"LOCK",parent,property,query.lock + client,"LOCK",query.location,parent,property,query.lock )); /* put unlock after the operation in the request queue */ q.push(new Request( - client,"LOCK",parent,property,locks.UNLOCK + client,"LOCK",query.location,parent,property,locks.UNLOCK )); } @@ -678,7 +681,7 @@ function JSONdb (fileName) { /* locate the requested record within the database */ var record=identify_remains.call( - this,request.client,request.parent,request.property,request.oper + this,request.oper,request.location,request.parent,request.property ); /* if there was an error parsing object location, delete request */ @@ -810,9 +813,10 @@ function JSONdb (fileName) { /* request object generated by queue() method contains the requested object parent, the specific child property requested, data (in the case of a PUT operation ) */ - function Request(client,operation,parent,property,data,timeout) { + function Request(client,operation,location,parent,property,data,timeout) { this.client=client; this.oper=operation; + this.location=location; this.parent=parent; this.property=property; this.data=data; @@ -843,11 +847,10 @@ function JSONdb (fileName) { /* parse an object location name and return the object (ex: dicewarz2.games.1.players.1.tiles.0) an object containing the corresponding data and its shadow object */ - function identify_remains(client,parent,property,oper) { - - var data=this.masterData; + function identify_remains(oper,location,parent,property) { + + var object=this.masterData; var shadow=this.masterShadow; - var location=property; var info={ lock:{}, lock_type:locks.NONE, @@ -866,15 +869,14 @@ function JSONdb (fileName) { create_shadow(shadow,c); shadow=shadow[c]; /* keep track of current object, and store the immediate parent of the request object */ - if(data !== undefined) { - if(data[c] === undefined && oper == "WRITE") - create_data(data,c); - data=data[c]; + if(object !== undefined) { + if(object[c] === undefined && oper == "WRITE") + create_data(object,c); + object=object[c]; } /* check the current object's lock and subscriber status along the way */ info = investigate(shadow,info); } - location = parent + "." + property; } /* ensure requested shadow object's existance */ @@ -885,7 +887,7 @@ function JSONdb (fileName) { info = search_party(shadow[property],info); /* return selected database object, shadow object, and overall lock status of the chosen tree */ - return new Record(data,shadow,location,property,info); + return new Record(object,shadow,location,property,info); } /* if the requested child object does not exist, create it */