mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel
This commit is contained in:
commit
7119cfd5fb
|
@ -73,6 +73,7 @@ var GRAPH_CONTEXT = "api";
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function graph_by_request (req) {
|
function graph_by_request (req) {
|
||||||
|
|
||||||
var key = req.suffix[0];
|
var key = req.suffix[0];
|
||||||
|
|
||||||
var g = new graph.Graph(key);
|
var g = new graph.Graph(key);
|
||||||
|
@ -251,8 +252,8 @@ function post_graph_graph (req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = json._key;
|
var name = json._key;
|
||||||
var vertices = json.vertices;
|
var vertices = json.edgeDefinitions[0].from[0];
|
||||||
var edges = json.edges;
|
var edges = json.edgeDefinitions[0].collection;
|
||||||
|
|
||||||
var waitForSync = false;
|
var waitForSync = false;
|
||||||
if (req.parameters.waitForSync &&
|
if (req.parameters.waitForSync &&
|
||||||
|
|
|
@ -212,16 +212,17 @@ Graph.prototype.initialize = function (name, vertices, edges) {
|
||||||
edges = edges.name();
|
edges = edges.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var newEdgeDefinition = [{"collection": edges, "from" :[vertices], "to": [vertices]}];
|
||||||
|
|
||||||
results = GraphAPI.postGraph({
|
results = GraphAPI.postGraph({
|
||||||
_key: name,
|
_key: name,
|
||||||
vertices: vertices,
|
edgeDefinitions: newEdgeDefinition
|
||||||
edges: edges
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this._properties = results.graph;
|
this._properties = results.graph;
|
||||||
this._vertices = arangodb.db._collection(this._properties.vertices);
|
this._vertices = arangodb.db._collection(this._properties.edgeDefinitions[0].from[0]);
|
||||||
this._edges = arangodb.db._collection(this._properties.edges);
|
this._edges = arangodb.db._collection(this._properties.edgeDefinitions[0].collection);
|
||||||
|
|
||||||
// and dictionary for vertices and edges
|
// and dictionary for vertices and edges
|
||||||
this._verticesCache = {};
|
this._verticesCache = {};
|
||||||
|
|
|
@ -33,6 +33,7 @@ var arangodb = require("org/arangodb"),
|
||||||
db = arangodb.db,
|
db = arangodb.db,
|
||||||
ArangoCollection = arangodb.ArangoCollection,
|
ArangoCollection = arangodb.ArangoCollection,
|
||||||
common = require("org/arangodb/graph-common"),
|
common = require("org/arangodb/graph-common"),
|
||||||
|
newGraph = require("org/arangodb/general-graph"),
|
||||||
Edge = common.Edge,
|
Edge = common.Edge,
|
||||||
Graph = common.Graph,
|
Graph = common.Graph,
|
||||||
Vertex = common.Vertex,
|
Vertex = common.Vertex,
|
||||||
|
@ -317,6 +318,8 @@ Vertex.prototype.setProperty = function (name, value) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
||||||
|
|
||||||
|
this._name = name;
|
||||||
var gdb = db._collection("_graphs");
|
var gdb = db._collection("_graphs");
|
||||||
var graphProperties;
|
var graphProperties;
|
||||||
var graphPropertiesId;
|
var graphPropertiesId;
|
||||||
|
@ -340,6 +343,7 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
||||||
|
|
||||||
// find an existing graph by name
|
// find an existing graph by name
|
||||||
if (vertices === undefined && edges === undefined) {
|
if (vertices === undefined && edges === undefined) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
graphProperties = gdb.document(name);
|
graphProperties = gdb.document(name);
|
||||||
}
|
}
|
||||||
|
@ -351,16 +355,34 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
||||||
throw "no graph named '" + name + "' found";
|
throw "no graph named '" + name + "' found";
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices = db._collection(graphProperties.vertices);
|
//check if graph can be loaded by this deprecated module
|
||||||
|
var newGraphError = "Graph can not be loaded, "
|
||||||
if (vertices === null) {
|
+ "because more than 1 vertex collection is defined. "
|
||||||
throw "vertex collection '" + graphProperties.vertices + "' has vanished";
|
+ "Please use the new graph module";
|
||||||
|
var edgeDefinitions = db._graphs.document(name).edgeDefinitions;
|
||||||
|
if (edgeDefinitions.length === 0) {
|
||||||
|
throw newGraphError;
|
||||||
|
}
|
||||||
|
if (edgeDefinitions.length > 1) {
|
||||||
|
throw newGraphError;
|
||||||
|
} else if (edgeDefinitions.length === 1) {
|
||||||
|
var from = edgeDefinitions[0].from;
|
||||||
|
var to = edgeDefinitions[0].to;
|
||||||
|
if (from.length !== 1 || to.length !== 1 || from[0] !== to[0]) {
|
||||||
|
throw newGraphError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edges = db._collection(graphProperties.edges);
|
vertices = db._collection(edgeDefinitions[0].from[0]);
|
||||||
|
|
||||||
|
if (vertices === null) {
|
||||||
|
throw "vertex collection '" + edgeDefinitions[0].from[0] + "' has vanished";
|
||||||
|
}
|
||||||
|
|
||||||
|
edges = db._collection(edgeDefinitions[0].collection);
|
||||||
|
|
||||||
if (edges === null) {
|
if (edges === null) {
|
||||||
throw "edge collection '" + graphProperties.edges + "' has vanished";
|
throw "edge collection '" + edgeDefinitions[0].collection + "' has vanished";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,26 +410,41 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
||||||
|
|
||||||
// check if know that graph
|
// check if know that graph
|
||||||
graphProperties = gdb.firstExample(
|
graphProperties = gdb.firstExample(
|
||||||
'vertices', vertices,
|
'edgeDefintions', [{"collection": edges, "from" :[vertices], "to": [vertices]}]
|
||||||
'edges', edges
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (graphProperties === null) {
|
if (graphProperties === null) {
|
||||||
|
|
||||||
// check if edge is used in a graph
|
// check if edge is used in a graph
|
||||||
graphProperties = gdb.firstExample('edges', edges);
|
//hole alle graphen nud schau nach O.o
|
||||||
|
gdb.toArray().forEach(
|
||||||
|
function(singleGraph) {
|
||||||
|
var sGEDs = singleGraph.edgeDefinitions;
|
||||||
|
sGEDs.forEach(
|
||||||
|
function(sGED) {
|
||||||
|
if (sGED.collection === edges) {
|
||||||
|
graphProperties = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (graphProperties === null) {
|
if (graphProperties === null) {
|
||||||
findOrCreateCollectionByName(vertices);
|
findOrCreateCollectionByName(vertices);
|
||||||
findOrCreateEdgeCollectionByName(edges);
|
findOrCreateEdgeCollectionByName(edges);
|
||||||
|
|
||||||
graphPropertiesId = gdb.save({
|
var newEdgeDefinition = [{"collection": edges, "from" :[vertices], "to": [vertices]}];
|
||||||
'vertices' : vertices,
|
|
||||||
'edges' : edges,
|
|
||||||
'_key' : name
|
|
||||||
}, waitForSync);
|
|
||||||
|
|
||||||
graphProperties = gdb.document(graphPropertiesId);
|
graphPropertiesId = gdb.save(
|
||||||
|
{
|
||||||
|
'edgeDefinitions' : newEdgeDefinition,
|
||||||
|
'_key' : name
|
||||||
|
},
|
||||||
|
waitForSync
|
||||||
|
);
|
||||||
|
|
||||||
|
graphProperties = gdb.document(graphPropertiesId._key);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw "edge collection already used";
|
throw "edge collection already used";
|
||||||
|
@ -419,14 +456,13 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (graphProperties.vertices !== vertices || graphProperties.edges !== edges) {
|
if (graphProperties.vertices !== vertices || graphProperties.edges !== edges) {
|
||||||
throw "graph with that name already exists";
|
throw "graph with that name already exists!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices = db._collection(graphProperties.vertices);
|
vertices = db._collection(graphProperties.edgeDefinitions[0].from[0]);
|
||||||
edges = db._collection(graphProperties.edges);
|
edges = db._collection(graphProperties.edgeDefinitions[0].collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._properties = graphProperties;
|
this._properties = graphProperties;
|
||||||
|
|
||||||
// and store the collections
|
// and store the collections
|
||||||
|
@ -506,15 +542,7 @@ Graph.drop = function (name, waitForSync) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Graph.prototype.drop = function (waitForSync) {
|
Graph.prototype.drop = function (waitForSync) {
|
||||||
var gdb = db._collection("_graphs");
|
newGraph._drop(this._name, true);
|
||||||
|
|
||||||
gdb.remove(this._properties, true, waitForSync);
|
|
||||||
|
|
||||||
if (gdb.byExample({vertices: this._vertices.name()}).count() === 0) {
|
|
||||||
this._vertices.drop();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._edges.drop();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief a trivial implementation of a console input (shell)
|
||||||
|
///
|
||||||
|
/// @file
|
||||||
|
///
|
||||||
|
/// DISCLAIMER
|
||||||
|
///
|
||||||
|
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// @author Esteban Lombeyda
|
||||||
|
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef TRIAGENS_UTILITIES_LINENOISESHELL_H
|
||||||
|
#define TRIAGENS_UTILITIES_LINENOISESHELL_H 1
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Completer.h"
|
||||||
|
#include "ShellImplementation.h"
|
||||||
|
|
||||||
|
#include "BasicsC/tri-strings.h"
|
||||||
|
#include "V8/v8-utils.h"
|
||||||
|
|
||||||
|
namespace triagens {
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @addtogroup Shell
|
||||||
|
/// @{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class DummyShell: public ShellImplementation {
|
||||||
|
|
||||||
|
public:
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// public constructor, destructor
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
DummyShell(string const& history, Completer *);
|
||||||
|
|
||||||
|
virtual ~DummyShell();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief line editor open
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual bool open(bool autoComplete);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief line editor shutdown
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual bool close();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief get the history file path
|
||||||
|
///
|
||||||
|
/// The path is "$HOME" plus _historyFilename, if $HOME is set. Else
|
||||||
|
/// the local file _historyFilename.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual std::string historyPath();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief add to history
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual void addHistory(const char*);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief save the history
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual bool writeHistory();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief returns the characters which the user has typed
|
||||||
|
/// @arg is the prompt of the shell
|
||||||
|
/// Note: this is the interface between our shell world and some implementation
|
||||||
|
/// of key events (linenoise, readline)
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual char * getLine(char const *);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: outline-minor
|
||||||
|
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
|
||||||
|
// End:
|
Loading…
Reference in New Issue