diff options
| author | Alex Rudyy <orudyy@apache.org> | 2014-01-21 10:08:35 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2014-01-21 10:08:35 +0000 |
| commit | 86bc633c7b3c5612a8cd20db05bbf77ee8a8fa89 (patch) | |
| tree | 8b91887fb9629946de4f192194b2ce7689ca5ef2 /qpid/java | |
| parent | 275bf52cfeacbb93083c2dda50a649ae29ec8f05 (diff) | |
| download | qpid-python-86bc633c7b3c5612a8cd20db05bbf77ee8a8fa89.tar.gz | |
QPID-5413: Fix UpdatableStore row update logic to compare correctly fields of type 'array' and 'object'
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-bdb-ha@1559960 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
2 files changed, 94 insertions, 14 deletions
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js index ea3ba78372..4d5e71f39b 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js @@ -18,10 +18,11 @@ * under the License. * */ -define(["dojo/store/Memory", - "dojox/grid/DataGrid", - "dojo/data/ObjectStore", - "dojo/store/Observable"], function (Memory, DataGrid, ObjectStore, Observable) { +define(["qpid/common/util", + "dojo/store/Memory", + "dojox/grid/DataGrid", + "dojo/data/ObjectStore", + "dojo/store/Observable"], function (util, Memory, DataGrid, ObjectStore, Observable) { function UpdatableStore( data, divName, structure, func, props, Grid, notObservable ) { @@ -86,16 +87,7 @@ define(["dojo/store/Memory", if(data) { for(var i=0; i < data.length; i++) { if(theItem = store.get(data[i].id)) { - var modified; - for(var propName in data[i]) { - if(data[i].hasOwnProperty(propName)) { - if(theItem[ propName ] != data[i][ propName ]) { - theItem[ propName ] = data[i][ propName ]; - modified = true; - changed = true; - } - } - } + var modified = !util.equals(theItem, data[i]); if(modified) { // ... check attributes for updates store.notify(theItem, data[i].id); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js index 3d349830ac..12068fa101 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js @@ -369,6 +369,94 @@ define(["dojo/_base/xhr", { alert(error); } + }; + + util.equals = function(object1, object2) + { + if (object1 && object2) + { + if (typeof object1 != typeof object2) + { + return false; + } + else + { + if (object1 instanceof Array || typeof object1 == "array") + { + if (object1.length != object2.length) + { + return false; + } + + for (var i = 0, l=object1.length; i < l; i++) + { + var item = object1[i]; + if (item && (item instanceof Array || typeof item == "array" || item instanceof Object)) + { + if (!this.equals(item, object2[i])) + { + return false; + } + } + else if (item != object2[i]) + { + return false; + } + } + + return true; + } + else if (object1 instanceof Object) + { + for (propName in object1) + { + if (object1.hasOwnProperty(propName) != object2.hasOwnProperty(propName)) + { + return false; + } + else if (typeof object1[propName] != typeof object2[propName]) + { + return false; + } + } + + for(propName in object2) + { + var object1Prop = object1[propName]; + var object2Prop = object2[propName]; + + if (object2.hasOwnProperty(propName) != object1.hasOwnProperty(propName)) + { + return false; + } + else if (typeof object1Prop != typeof object2Prop) + { + return false; + } + + if(!object2.hasOwnProperty(propName)) + { + // skip functions + continue; + } + + if (object1Prop && (object1Prop instanceof Array || typeof object1Prop == "array" || object1Prop instanceof Object)) + { + if (!this.equals(object1Prop, object2Prop)) + { + return false; + } + } + else if(object1Prop != object2Prop) + { + return false; + } + } + return true; + } + } + } + return object1 === object2; } return util; |
