mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel
Conflicts: js/common/modules/org/arangodb/general-graph.js
This commit is contained in:
commit
55c494c81d
|
@ -79,22 +79,36 @@
|
||||||
expect(col.loglevel).toEqual(1);
|
expect(col.loglevel).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should check if last page is active", function() {
|
||||||
|
col.page = 1;
|
||||||
|
col.pagesize = 10;
|
||||||
|
col.totalAmount = 14;
|
||||||
|
col.totalPages = 2;
|
||||||
|
expect(col.url()).toEqual('/_admin/log?upto=1&size=4&offset=0');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should check if totalAmount is set", function() {
|
||||||
|
col.totalAmount = 0;
|
||||||
|
col.url();
|
||||||
|
});
|
||||||
|
|
||||||
it("url with upto", function() {
|
it("url with upto", function() {
|
||||||
col.initialize({upto : true, loglevel : 1});
|
col.initialize({upto : true, loglevel : 1});
|
||||||
col.page = 1;
|
col.page = 2;
|
||||||
col.pagesize = 1;
|
col.pagesize = 2;
|
||||||
|
col.totalAmount = 10;
|
||||||
|
|
||||||
expect(col.url()).toEqual('/_admin/log?upto=1&size=1&offset=0');
|
expect(col.url()).toEqual('/_admin/log?upto=1&size=2&offset=4');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("url with no upto", function() {
|
it("url with no upto", function() {
|
||||||
col.initialize({upto : false, loglevel : 1});
|
col.initialize({upto : false, loglevel : 1});
|
||||||
col.upto = false;
|
col.upto = false;
|
||||||
col.page = 1;
|
col.page = 2;
|
||||||
col.pagesize = 1;
|
col.pagesize = 2;
|
||||||
|
col.totalAmount = 10;
|
||||||
|
|
||||||
expect(col.url()).toEqual('/_admin/log?level=1&size=1&offset=0');
|
expect(col.url()).toEqual('/_admin/log?level=1&size=2&offset=4');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,11 @@
|
||||||
|
|
||||||
|
|
||||||
var arangodb = require("org/arangodb"),
|
var arangodb = require("org/arangodb"),
|
||||||
ArangoCollection = arangodb.ArangoCollection,
|
ArangoCollection = arangodb.ArangoCollection,
|
||||||
db = arangodb.db,
|
db = arangodb.db,
|
||||||
_ = require("underscore");
|
_ = require("underscore");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- module "org/arangodb/general-graph"
|
// --SECTION-- module "org/arangodb/general-graph"
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -50,10 +49,10 @@ var arangodb = require("org/arangodb"),
|
||||||
|
|
||||||
|
|
||||||
var stringToArray = function (x) {
|
var stringToArray = function (x) {
|
||||||
if (typeof(x) === "string") {
|
if (typeof(x) === "string") {
|
||||||
return [x];
|
return [x];
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -63,16 +62,16 @@ var stringToArray = function (x) {
|
||||||
|
|
||||||
|
|
||||||
var isValidCollectionsParameter = function (x) {
|
var isValidCollectionsParameter = function (x) {
|
||||||
if (!x) {
|
if (!x) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Array.isArray(x) && x.length === 0) {
|
if (Array.isArray(x) && x.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (typeof(x) !== "string" && !Array.isArray(x)) {
|
if (typeof(x) !== "string" && !Array.isArray(x)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -80,20 +79,20 @@ var isValidCollectionsParameter = function (x) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var findOrCreateCollectionByName = function (name, type) {
|
var findOrCreateCollectionByName = function (name, type) {
|
||||||
var col = db._collection(name),res = false;
|
var col = db._collection(name),res = false;
|
||||||
if (col === null) {
|
if (col === null) {
|
||||||
if (type === ArangoCollection.TYPE_DOCUMENT) {
|
if (type === ArangoCollection.TYPE_DOCUMENT) {
|
||||||
col = db._create(name);
|
col = db._create(name);
|
||||||
} else {
|
} else {
|
||||||
col = db._createEdgeCollection(name);
|
col = db._createEdgeCollection(name);
|
||||||
}
|
}
|
||||||
res = true;
|
res = true;
|
||||||
} else if (!(col instanceof ArangoCollection) || col.type() !== type) {
|
} else if (!(col instanceof ArangoCollection) || col.type() !== type) {
|
||||||
throw "<" + name + "> must be a " +
|
throw "<" + name + "> must be a " +
|
||||||
(type === ArangoCollection.TYPE_DOCUMENT ? "document" : "edge")
|
(type === ArangoCollection.TYPE_DOCUMENT ? "document" : "edge")
|
||||||
+ " collection";
|
+ " collection";
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -111,23 +110,23 @@ var findOrCreateCollectionByName = function (name, type) {
|
||||||
|
|
||||||
var _undirectedRelationDefinition = function (relationName, vertexCollections) {
|
var _undirectedRelationDefinition = function (relationName, vertexCollections) {
|
||||||
|
|
||||||
if (arguments.length < 2) {
|
if (arguments.length < 2) {
|
||||||
throw "method _undirectedRelationDefinition expects 2 arguments";
|
throw "method _undirectedRelationDefinition expects 2 arguments";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof relationName !== "string" || relationName === "") {
|
if (typeof relationName !== "string" || relationName === "") {
|
||||||
throw "<relationName> must be a not empty string";
|
throw "<relationName> must be a not empty string";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidCollectionsParameter(vertexCollections)) {
|
if (!isValidCollectionsParameter(vertexCollections)) {
|
||||||
throw "<vertexCollections> must be a not empty string or array";
|
throw "<vertexCollections> must be a not empty string or array";
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
collection: "relationName",
|
collection: "relationName",
|
||||||
from: stringToArray(vertexCollections),
|
from: stringToArray(vertexCollections),
|
||||||
to: stringToArray(vertexCollections)
|
to: stringToArray(vertexCollections)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,29 +136,29 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) {
|
||||||
|
|
||||||
|
|
||||||
var _directedRelationDefinition = function (
|
var _directedRelationDefinition = function (
|
||||||
relationName, fromVertexCollections, toVertexCollections) {
|
relationName, fromVertexCollections, toVertexCollections) {
|
||||||
|
|
||||||
if (arguments.length < 3) {
|
if (arguments.length < 3) {
|
||||||
throw "method _undirectedRelationDefinition expects 3 arguments";
|
throw "method _undirectedRelationDefinition expects 3 arguments";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof relationName !== "string" || relationName === "") {
|
if (typeof relationName !== "string" || relationName === "") {
|
||||||
throw "<relationName> must be a not empty string";
|
throw "<relationName> must be a not empty string";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidCollectionsParameter(fromVertexCollections)) {
|
if (!isValidCollectionsParameter(fromVertexCollections)) {
|
||||||
throw "<fromVertexCollections> must be a not empty string or array";
|
throw "<fromVertexCollections> must be a not empty string or array";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidCollectionsParameter(toVertexCollections)) {
|
if (!isValidCollectionsParameter(toVertexCollections)) {
|
||||||
throw "<toVertexCollections> must be a not empty string or array";
|
throw "<toVertexCollections> must be a not empty string or array";
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
collection: "relationName",
|
collection: "relationName",
|
||||||
from: stringToArray(fromVertexCollections),
|
from: stringToArray(fromVertexCollections),
|
||||||
to: stringToArray(toVertexCollections)
|
to: stringToArray(toVertexCollections)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -169,12 +168,12 @@ var _directedRelationDefinition = function (
|
||||||
|
|
||||||
var edgeDefinitions = function () {
|
var edgeDefinitions = function () {
|
||||||
|
|
||||||
var res = [], args = arguments;
|
var res = [], args = arguments;
|
||||||
Object.keys(args).forEach(function (x) {
|
Object.keys(args).forEach(function (x) {
|
||||||
res.push(args[x]);
|
res.push(args[x]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -185,52 +184,51 @@ var edgeDefinitions = function () {
|
||||||
|
|
||||||
var _create = function (graphName, edgeDefinitions) {
|
var _create = function (graphName, edgeDefinitions) {
|
||||||
|
|
||||||
var gdb = db._collection("_graphs"),
|
var gdb = db._collection("_graphs"),
|
||||||
g,
|
g,
|
||||||
graphAlreadyExists = true;
|
graphAlreadyExists = true;
|
||||||
|
|
||||||
if (gdb === null) {
|
if (gdb === null) {
|
||||||
throw "_graphs collection does not exist.";
|
throw "_graphs collection does not exist.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!graphName) {
|
if (!graphName) {
|
||||||
throw "a graph name is required to create a graph.";
|
throw "a graph name is required to create a graph.";
|
||||||
}
|
}
|
||||||
if (!Array.isArray(edgeDefinitions) || edgeDefinitions.length === 0) {
|
if (!Array.isArray(edgeDefinitions) || edgeDefinitions.length === 0) {
|
||||||
throw "at least one edge definition is required to create a graph.";
|
throw "at least one edge definition is required to create a graph.";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
g = gdb.document(graphName);
|
g = gdb.document(graphName);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.errorNum !== 1202) {
|
if (e.errorNum !== 1202) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
graphAlreadyExists = false;
|
graphAlreadyExists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (graphAlreadyExists) {
|
if (graphAlreadyExists) {
|
||||||
throw "graph " + graphName + " already exists.";
|
throw "graph " + graphName + " already exists.";
|
||||||
}
|
}
|
||||||
|
|
||||||
var vertexCollections = {};
|
var vertexCollections = {};
|
||||||
var edgeCollections = {};
|
var edgeCollections = {};
|
||||||
edgeDefinitions.forEach(function (e) {
|
edgeDefinitions.forEach(function (e) {
|
||||||
e.from.concat(e.to).forEach(function (v) {
|
e.from.concat(e.to).forEach(function (v) {
|
||||||
findOrCreateCollectionByName(v, ArangoCollection.TYPE_DOCUMENT);
|
findOrCreateCollectionByName(v, ArangoCollection.TYPE_DOCUMENT);
|
||||||
vertexCollections[v] = db[v];
|
vertexCollections[v] = db[v];
|
||||||
});
|
});
|
||||||
findOrCreateCollectionByName(e.collection, ArangoCollection.TYPE_EDGE);
|
findOrCreateCollectionByName(e.collection, ArangoCollection.TYPE_EDGE);
|
||||||
edgeCollections[e] = db[e];
|
edgeCollections[e] = db[e];
|
||||||
});
|
});
|
||||||
|
|
||||||
gdb.save({
|
gdb.save({
|
||||||
'edgeDefinitions' : edgeDefinitions,
|
'edgeDefinitions' : edgeDefinitions,
|
||||||
'_key' : graphName
|
'_key' : graphName
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Graph(graphName, edgeDefinitions, vertexCollections, edgeCollections);
|
|
||||||
|
|
||||||
|
return new Graph(graphName, edgeDefinitions, vertexCollections, edgeCollections);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
///
|
///
|
||||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
///
|
///
|
||||||
/// @author Florian Bartels
|
/// @author Florian Bartels, Michael Hackstein
|
||||||
/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany
|
/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ var jsunity = require("jsunity");
|
||||||
var arangodb = require("org/arangodb");
|
var arangodb = require("org/arangodb");
|
||||||
|
|
||||||
var console = require("console");
|
var console = require("console");
|
||||||
var graph = require("org/arangodb/general-graph")
|
var graph = require("org/arangodb/general-graph");
|
||||||
|
|
||||||
var print = arangodb.print;
|
var print = arangodb.print;
|
||||||
|
|
||||||
|
@ -223,7 +223,6 @@ function GeneralGraphCreationSuite() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*test_create : function () {
|
/*test_create : function () {
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,11 +241,115 @@ function GeneralGraphCreationSuite() {
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- Simple Queries
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function GeneralGraphSimpleQueriesSuite() {
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test: restrict construct on edges
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
test_restrictOnEdges: function() {
|
||||||
|
// Creation of a graph content
|
||||||
|
var inc = graph._directedRelationDefinition("included", ["v1"], ["v1", "v2"]);
|
||||||
|
var exc = graph._directedRelationDefinition("excluded", ["v1"], ["v3"]);
|
||||||
|
/*
|
||||||
|
var g = graph._create("graph", [inc, exc]);
|
||||||
|
var incEdge1 = g.included.save({
|
||||||
|
_from: "v1/1",
|
||||||
|
_to:"v2/1",
|
||||||
|
included: true
|
||||||
|
});
|
||||||
|
var incEdge2 = g.included.save({
|
||||||
|
_from: "v1/2",
|
||||||
|
_to:"v1/1",
|
||||||
|
included: true
|
||||||
|
});
|
||||||
|
var excEdge = g.excluded.save({
|
||||||
|
_from: "v1/1",
|
||||||
|
_to:"v3/1",
|
||||||
|
included: false
|
||||||
|
});
|
||||||
|
var result = g.edges().restrict("v1");
|
||||||
|
assertEqual(result.length, 2);
|
||||||
|
assertNotEqual(result.indexOf(incEdge1), -1);
|
||||||
|
assertNotEqual(result.indexOf(incEdge2), -1);
|
||||||
|
assertEqual(result.indexOf(excEdge), -1);
|
||||||
|
*/
|
||||||
|
},
|
||||||
|
|
||||||
|
test_restrictOnInEdges: function() {
|
||||||
|
// Creation of a graph content
|
||||||
|
var inc = graph._directedRelationDefinition("included", ["v1"], ["v1", "v2"]);
|
||||||
|
var exc = graph._directedRelationDefinition("excluded", ["v1"], ["v3"]);
|
||||||
|
/*
|
||||||
|
var g = graph._create("graph", [inc, exc]);
|
||||||
|
var excEdge1 = g.included.save({
|
||||||
|
_from: "v1/1",
|
||||||
|
_to:"v2/1",
|
||||||
|
included: true
|
||||||
|
});
|
||||||
|
var incEdge = g.included.save({
|
||||||
|
_from: "v1/2",
|
||||||
|
_to:"v1/1",
|
||||||
|
included: true
|
||||||
|
});
|
||||||
|
var excEdge2 = g.excluded.save({
|
||||||
|
_from: "v1/1",
|
||||||
|
_to:"v3/1",
|
||||||
|
included: false
|
||||||
|
});
|
||||||
|
var result = g.edges().restrict("v1");
|
||||||
|
assertEqual(result.length, 1);
|
||||||
|
assertEqual(result.indexOf(excEdge1), -1);
|
||||||
|
assertNotEqual(result.indexOf(incEdge), -1);
|
||||||
|
assertEqual(result.indexOf(excEdge2), -1);
|
||||||
|
*/
|
||||||
|
},
|
||||||
|
|
||||||
|
test_restrictOnOutEdges: function() {
|
||||||
|
// Creation of a graph content
|
||||||
|
var inc = graph._directedRelationDefinition("included", ["v1"], ["v1", "v2"]);
|
||||||
|
var exc = graph._directedRelationDefinition("excluded", ["v1"], ["v3"]);
|
||||||
|
/*
|
||||||
|
var g = graph._create("graph", [inc, exc]);
|
||||||
|
var incEdge = g.included.save({
|
||||||
|
_from: "v1/1",
|
||||||
|
_to:"v2/1",
|
||||||
|
included: true
|
||||||
|
});
|
||||||
|
var excEdge1 = g.included.save({
|
||||||
|
_from: "v1/2",
|
||||||
|
_to:"v1/1",
|
||||||
|
included: true
|
||||||
|
});
|
||||||
|
var excEdge2 = g.excluded.save({
|
||||||
|
_from: "v1/1",
|
||||||
|
_to:"v3/1",
|
||||||
|
included: false
|
||||||
|
});
|
||||||
|
var result = g.edges().restrict("v1");
|
||||||
|
assertEqual(result.length, 1);
|
||||||
|
assertNotEqual(result.indexOf(incEdge), -1);
|
||||||
|
assertEqual(result.indexOf(excEdge1), -1);
|
||||||
|
assertEqual(result.indexOf(excEdge2), -1);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- main
|
// --SECTION-- main
|
||||||
|
@ -257,6 +360,7 @@ function GeneralGraphCreationSuite() {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
jsunity.run(GeneralGraphCreationSuite);
|
jsunity.run(GeneralGraphCreationSuite);
|
||||||
|
jsunity.run(GeneralGraphSimpleQueriesSuite);
|
||||||
|
|
||||||
return jsunity.done();
|
return jsunity.done();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue