From 6049ef11fbb13b28faf4699baaa08f0e5065ff04 Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Thu, 31 Oct 2013 15:12:06 +0100 Subject: [PATCH] Graph: Replace a given edge by ID --- js/client/modules/org/arangodb/graph.js | 8 ++++++++ js/common/modules/org/arangodb/graph-common.js | 12 ++++++++++++ js/common/tests/shell-graph.js | 16 ++++++++++++++++ js/server/modules/org/arangodb/graph.js | 8 ++++++++ 4 files changed, 44 insertions(+) diff --git a/js/client/modules/org/arangodb/graph.js b/js/client/modules/org/arangodb/graph.js index 6465c6c175..8d0e94d30e 100644 --- a/js/client/modules/org/arangodb/graph.js +++ b/js/client/modules/org/arangodb/graph.js @@ -287,6 +287,14 @@ Graph.prototype._replaceVertex = function (id, data) { GraphAPI.putVertex(this._properties._key, id, data); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief replace an edge in the graph +//////////////////////////////////////////////////////////////////////////////// + +Graph.prototype._replaceEdge = function (id, data) { + GraphAPI.putEdge(this._properties._key, id, data); +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief returns a vertex given its id //////////////////////////////////////////////////////////////////////////////// diff --git a/js/common/modules/org/arangodb/graph-common.js b/js/common/modules/org/arangodb/graph-common.js index a5640bb029..0c9810b397 100644 --- a/js/common/modules/org/arangodb/graph-common.js +++ b/js/common/modules/org/arangodb/graph-common.js @@ -793,6 +793,18 @@ Graph.prototype.replaceVertex = function (id, data) { this._replaceVertex(id, data); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief replaces an existing edge by ID +/// +/// @FUN{@FA{graph}.replaceEdge(@FA{id}, @FA{data})} +/// +/// Replaces an existing edge by ID +//////////////////////////////////////////////////////////////////////////////// + +Graph.prototype.replaceEdge = function (id, data) { + this._replaceEdge(id, data); +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief returns the number of vertices /// diff --git a/js/common/tests/shell-graph.js b/js/common/tests/shell-graph.js index 33ab47227f..7d0973cc6a 100644 --- a/js/common/tests/shell-graph.js +++ b/js/common/tests/shell-graph.js @@ -239,6 +239,22 @@ function GraphBasicsSuite() { assertEqual(edge._properties._key, edge.getId()); }, + testReplaceEdge : function () { + var v1, + v2, + edge; + + v1 = graph.addVertex("vertex1"); + v2 = graph.addVertex("vertex2"); + + graph.addEdge(v1, v2, "my-edge"); + + graph.replaceEdge("my-edge", { weight: 2 }); + edge = graph.getEdge("my-edge"); + + assertEqual(2, edge.getProperty("weight")); + }, + //////////////////////////////////////////////////////////////////////////////// /// @brief change a property //////////////////////////////////////////////////////////////////////////////// diff --git a/js/server/modules/org/arangodb/graph.js b/js/server/modules/org/arangodb/graph.js index 1957a75b64..49884cf767 100644 --- a/js/server/modules/org/arangodb/graph.js +++ b/js/server/modules/org/arangodb/graph.js @@ -602,6 +602,14 @@ Graph.prototype._replaceVertex = function (vertex_id, data) { var result = this._vertices.replace(vertex_id, data); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief replaces an edge in the graph +//////////////////////////////////////////////////////////////////////////////// + +Graph.prototype._replaceEdge = function (edge_id, data) { + var result = this._edges.replace(edge_id, data); +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief returns a vertex given its id ///