1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
scottashton 2014-05-28 09:59:15 +02:00
commit 7119cfd5fb
4 changed files with 186 additions and 41 deletions

View File

@ -73,6 +73,7 @@ var GRAPH_CONTEXT = "api";
////////////////////////////////////////////////////////////////////////////////
function graph_by_request (req) {
var key = req.suffix[0];
var g = new graph.Graph(key);
@ -251,8 +252,8 @@ function post_graph_graph (req, res) {
}
var name = json._key;
var vertices = json.vertices;
var edges = json.edges;
var vertices = json.edgeDefinitions[0].from[0];
var edges = json.edgeDefinitions[0].collection;
var waitForSync = false;
if (req.parameters.waitForSync &&
@ -476,11 +477,11 @@ function delete_graph_graph (req, res) {
actions.resultNotFound(req, res, arangodb.ERROR_GRAPH_INVALID_GRAPH, err);
return;
}
if (matchError(req, res, g._properties, arangodb.ERROR_GRAPH_INVALID_GRAPH)) {
return;
}
}
var waitForSync = g._gdb.properties().waitForSync;
if (req.parameters.waitForSync &&
(req.parameters.waitForSync === "true" ||

View File

@ -212,16 +212,17 @@ Graph.prototype.initialize = function (name, vertices, edges) {
edges = edges.name();
}
var newEdgeDefinition = [{"collection": edges, "from" :[vertices], "to": [vertices]}];
results = GraphAPI.postGraph({
_key: name,
vertices: vertices,
edges: edges
edgeDefinitions: newEdgeDefinition
});
}
this._properties = results.graph;
this._vertices = arangodb.db._collection(this._properties.vertices);
this._edges = arangodb.db._collection(this._properties.edges);
this._vertices = arangodb.db._collection(this._properties.edgeDefinitions[0].from[0]);
this._edges = arangodb.db._collection(this._properties.edgeDefinitions[0].collection);
// and dictionary for vertices and edges
this._verticesCache = {};

View File

@ -33,6 +33,7 @@ var arangodb = require("org/arangodb"),
db = arangodb.db,
ArangoCollection = arangodb.ArangoCollection,
common = require("org/arangodb/graph-common"),
newGraph = require("org/arangodb/general-graph"),
Edge = common.Edge,
Graph = common.Graph,
Vertex = common.Vertex,
@ -317,6 +318,8 @@ Vertex.prototype.setProperty = function (name, value) {
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
this._name = name;
var gdb = db._collection("_graphs");
var graphProperties;
var graphPropertiesId;
@ -337,9 +340,10 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
if (typeof edges === 'object' && typeof edges.name === 'function') {
edges = edges.name();
}
// find an existing graph by name
if (vertices === undefined && edges === undefined) {
try {
graphProperties = gdb.document(name);
}
@ -351,19 +355,37 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
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, "
+ "because more than 1 vertex collection is defined. "
+ "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;
}
}
vertices = db._collection(edgeDefinitions[0].from[0]);
if (vertices === null) {
throw "vertex collection '" + graphProperties.vertices + "' has vanished";
throw "vertex collection '" + edgeDefinitions[0].from[0] + "' has vanished";
}
edges = db._collection(graphProperties.edges);
edges = db._collection(edgeDefinitions[0].collection);
if (edges === null) {
throw "edge collection '" + graphProperties.edges + "' has vanished";
throw "edge collection '" + edgeDefinitions[0].collection + "' has vanished";
}
}
// sanity check for vertices
else if (typeof vertices !== "string" || vertices === "") {
throw "<vertices> must be a string or null";
@ -388,26 +410,41 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
// check if know that graph
graphProperties = gdb.firstExample(
'vertices', vertices,
'edges', edges
'edgeDefintions', [{"collection": edges, "from" :[vertices], "to": [vertices]}]
);
if (graphProperties === null) {
// check if edge is used in a graph
graphProperties = gdb.firstExample('edges', edges);
if (graphProperties === null) {
// check if edge is used in a graph
//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) {
findOrCreateCollectionByName(vertices);
findOrCreateEdgeCollectionByName(edges);
graphPropertiesId = gdb.save({
'vertices' : vertices,
'edges' : edges,
'_key' : name
}, waitForSync);
var newEdgeDefinition = [{"collection": edges, "from" :[vertices], "to": [vertices]}];
graphProperties = gdb.document(graphPropertiesId);
graphPropertiesId = gdb.save(
{
'edgeDefinitions' : newEdgeDefinition,
'_key' : name
},
waitForSync
);
graphProperties = gdb.document(graphPropertiesId._key);
}
else {
throw "edge collection already used";
@ -419,21 +456,20 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
}
else {
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);
edges = db._collection(graphProperties.edges);
vertices = db._collection(graphProperties.edgeDefinitions[0].from[0]);
edges = db._collection(graphProperties.edgeDefinitions[0].collection);
}
this._properties = graphProperties;
// and store the collections
this._gdb = gdb;
this._vertices = vertices;
this._edges = edges;
// and dictionary for vertices and edges
this._verticesCache = {};
this._edgesCache = {};
@ -506,15 +542,7 @@ Graph.drop = function (name, waitForSync) {
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.drop = function (waitForSync) {
var gdb = db._collection("_graphs");
gdb.remove(this._properties, true, waitForSync);
if (gdb.byExample({vertices: this._vertices.name()}).count() === 0) {
this._vertices.drop();
}
this._edges.drop();
newGraph._drop(this._name, true);
};
////////////////////////////////////////////////////////////////////////////////

115
lib/Utilities/DummyShell.h Normal file
View File

@ -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: