1
0
Fork 0

documentation

This commit is contained in:
Frank Celler 2012-01-05 17:31:58 +01:00
parent a6b4c9e1d7
commit f130b4aa32
43 changed files with 437 additions and 356 deletions

View File

@ -1,5 +1,6 @@
avocado> var g = new Graph(db.vertices, edges.edges);
avocado> g;
avocado> var Graph = require("graph").Graph;
avocado> new Graph(db.vertices, edges.edges);
Graph("vertices", "edges")
avocado> new Graph("vertices", "edges");

View File

@ -1,14 +1,8 @@
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex({ name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v1, v2, "knows", { weight : 10 });
Edge(<graph>, "3999653:5570857")
avocado> e.getLabel();
knows
avocado> e.getProperty(e, "weight");
10

View File

@ -1,10 +1,12 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });

View File

@ -1,13 +1,12 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v, v, "self", { "weight" : 10 });
Edge(<graph>, "3999653:5570857")
avocado> e.getProperty("weight");

View File

@ -1,13 +1,12 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v, v, "self");
Edge(<graph>, "3999653:5570857")
avocado> e.getId();

View File

@ -1,20 +1,19 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v, v, "self", { weight: 10 })
Edge(<graph>, "2141724:6339989")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
Edge(<graph>, "3999653:5570857")
avocado> e.getProperty("weight");
avocado> e.getPropert("weight")
10
avocado> e.setProperty("weight", 20);
20
avocado> e.getProperty("weight");
avocado> e.getPropert("weight")
20

View File

@ -1,12 +1,14 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v1, v2);
Edge(<graph>, "3999653:7197720")
avocado> v1.edges();

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
@ -6,10 +8,10 @@ Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e1 = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e1 = g.addEdge(v1, v2, "knows");
Edge(<graph>, "3999653:7360858")
avocado> e2 = g.addEdge(v1, v2, "hates", { "weight" : 10 });
avocado> e2 = g.addEdge(v1, v2, "hates");
Edge(<graph>, "3999653:7426394")
avocado> v2.getInEdges();
@ -20,3 +22,6 @@ avocado> v2.getInEdges("knows");
avocado> v2.getInEdges("hates");
[ Edge(<graph>, "3999653:7426394") ]
avocado> v2.getInEdges("knows", "hates");
[ Edge(<graph>, "3999653:7360858"), Edge(<graph>, "3999653:7426394") ]

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
@ -6,17 +8,20 @@ Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e1 = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e1 = g.addEdge(v1, v2, "knows");
Edge(<graph>, "3999653:7360858")
avocado> e2 = g.addEdge(v1, v2, "hates", { "weight" : 10 });
avocado> e2 = g.addEdge(v1, v2, "hates");
Edge(<graph>, "3999653:7426394")
avocado> v1.getOutEdges();
[ Edge(<graph>, "3999653:7360858"), Edge(<graph>, "3999653:7426394") ]
avocado> v1.getOutEdges('knows');
avocado> v1.getOutEdges("knows");
[ Edge(<graph>, "3999653:7360858") ]
avocado> v1.getOutEdges('hates');
avocado> v1.getOutEdges("hates");
[ Edge(<graph>, "3999653:7426394") ]
avocado> v1.getOutEdges("knows", "hates");
[ Edge(<graph>, "3999653:7360858"), Edge(<graph>, "3999653:7426394") ]

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,13 +1,12 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e1 = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e1 = g.addEdge(v, v, "self");
Edge(<graph>, "3999653:7360858")
avocado> e1.getLabel();
"knows"
knows

View File

@ -1,12 +1,11 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e1 = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e1 = g.addEdge(v, v, "self");
Edge(<graph>, "3999653:7360858")
avocado> e1.getInVertex();

View File

@ -1,12 +1,11 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v, v, "self");
Edge(<graph>, "3999653:7360858")
avocado> e.getOutVertex();

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
@ -7,17 +9,8 @@ Vertex(<graph>, "153246:8712055")
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:8777591")
avocado> v3 = g.addVertex();
Vertex(<graph>, "153246:8843127")
avocado> v1.addInEdge(v2, "knows");
Edge(<graph>, "3999653:8908663")
avocado> v1.getInEdges();
[ Edge(<graph>, "3999653:8908663") ]
avocado> v1.addOutEdge(v3, "knows");
Edge(<graph>, "3999653:8974199")
avocado> v1.getOutEdges();
[ Edge(<graph>, "3999653:8974199") ]

View File

@ -1,23 +1,11 @@
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:8712055")
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:8777591")
avocado> v3 = g.addVertex();
Vertex(<graph>, "153246:8843127")
avocado> v1.addInEdge(v2, "knows", { data : 1 });
Edge(<graph>, "3999653:8908663")
avocado> v1.getInEdges();
[ Edge(<graph>, "3999653:8908663") ]
avocado> v1.addOutEdge(v3, "knows", { data : 1 });
Edge(<graph>, "3999653:8974199")
avocado> v1.getOutEdges();
[ Edge(<graph>, "3999653:8974199") ]

View File

@ -1,2 +1,4 @@
avocado> var Graph = require("graph").Graph;
avocado> g1 = new Graph("vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,2 +1,4 @@
avocado> var Graph = require("graph").Graph;
avocado> g2 = new Graph("vertices", "alternativeEdges");
Graph("vertices", "alternativeEdges")

View File

@ -0,0 +1,16 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:8712055")
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:8843127")
avocado> v1.addOutEdge(v2, "knows");
Edge(<graph>, "3999653:8974199")
avocado> v1.getOutEdges();
[ Edge(<graph>, "3999653:8974199") ]

View File

@ -0,0 +1,11 @@
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:8712055")
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:8777591")
avocado> v1.addOutEdge(v2, "knows", { data : 1 });
Edge(<graph>, "3999653:8974199")
avocado> v1.getOutEdges();
[ Edge(<graph>, "3999653:8974199") ]

View File

@ -0,0 +1,10 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex();
Vertex(<graph>, "153246:1824463")
avocado> g.getVertex("153246:1824463")
Vertex(<graph>, "153246:1824463")

View File

@ -1,8 +1,5 @@
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex({ name : "Hugo" });
Vertex(<graph>, "153246:2034680")
avocado> v.getProperty("name");
"Hugo"
Hugo

View File

@ -0,0 +1,13 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2);
Edge(<graph>, "3999653:5570857")

View File

@ -0,0 +1,5 @@
avocado> e = g.addEdge(v1, v2, { name : "Emil");
Edge(<graph>, "3999653:5570857")
avocado> e.getProperty("name");
Emil

View File

@ -0,0 +1,19 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> e = g.addEdge(v, v, "self", { weight: 10 })
Edge(<graph>, "2141724:6339989")
avocado> e.getPropertyKeys()
[ "weight" ]
avocado> e.setProperty("name", "Hugo");
Hugo
avocado> e.getPropertyKeys()
[ "weight", "name" ]

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
@ -5,4 +7,4 @@ avocado> v = g.addVertex({ name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v.getProperty("name");
"Hugo"
Hugo

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,3 +1,5 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,11 +1,5 @@
avocado> g = new Graph("vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex({ name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows");
Edge(<graph>, "3999653:5570857")
avocado> e.getLabel();
knows

View File

@ -624,8 +624,8 @@ INPUT = \
@srcdir@/RestServer \
@srcdir@/ShapedJson \
@srcdir@/V8 \
@srcdir@/VocBase
@srcdir@/VocBase \
@srcdir@/js
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is

View File

@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS =
AM_CPPFLAGS =
AM_LDFLAGS =
BUILT_SOURCES =
BUILT_SOURCES = js Doxygen/js Doxygen/js/system Doxygen/js/modules
LIBS =
noinst_LIBRARIES = libavocadodb.a
@ -22,9 +22,9 @@ include Makefile.files
.PHONY: js
js:
@test -d js || mkdir js
@test -d $@ || mkdir $@
js/js-%.h: @srcdir@/js/%.js js
js/js-%.h: @srcdir@/js/%.js
@top_srcdir@/config/js2c.sh $< > $@
################################################################################
@ -55,18 +55,18 @@ JsonParserX/%.cpp: @srcdir@/JsonParserX/%.yy
## Doxygen
################################################################################
.PHONY: doxygen
.PHONY: doxygen Doxygen/js Doxygen/js/system Doxygen/js/modules
Doxygen/js:
mkdir Doxygen/js
Doxygen/js Doxygen/js/system Doxygen/js/modules:
test -d $@ || mkdir $@
Doxygen/js/system:
mkdir Doxygen/js/system
Doxygen/js/%.c: @srcdir@/js/%.js Doxygen/js
Doxygen/js/%.c: @srcdir@/js/%.js
python @top_srcdir@/Doxygen/Scripts/js2doxy.py $< > $@
Doxygen/js/system/%.c: @srcdir@/js/system/%.js Doxygen/js/system
Doxygen/js/system/%.c: @srcdir@/js/system/%.js
python @top_srcdir@/Doxygen/Scripts/js2doxy.py $< > $@
Doxygen/js/modules/%.c: @srcdir@/js/system/%.js
python @top_srcdir@/Doxygen/Scripts/js2doxy.py $< > $@
doxygen: Doxygen/avocado.doxy $(DOXYGEN)

View File

@ -214,7 +214,6 @@ avocado_SOURCES = \
BUILT_SOURCES += \
js/js-modules.h \
js/js-actions.h \
js/js-graph.h \
js/js-json.h \
js/js-shell.h
@ -245,13 +244,13 @@ BUILT_SOURCES += \
################################################################################
DOXYGEN = \
Doxygen/js/shell.c \
Doxygen/js/system/indexes.c \
Doxygen/js/actions.c \
Doxygen/js/graph.c \
Doxygen/js/system/collections.c \
Doxygen/js/json.c \
Doxygen/js/modules.c \
Doxygen/js/json.c
Doxygen/js/modules/graph.c \
Doxygen/js/shell.c \
Doxygen/js/system/collections.c \
Doxygen/js/system/indexes.c
################################################################################
## wiki
@ -270,13 +269,16 @@ WIKI = \
Doxygen/xml/d7/daa/Actions.md \
Doxygen/xml/d4/d7d/HttpInterface.md \
Doxygen/xml/d9/de4/JSModules.md \
Doxygen/xml/d0/da4/GraphFuncIndex.md \
Doxygen/xml/d2/d35/JSModuleGraph.md \
Doxygen/xml/d9/db2/CommandLineScheduler.md \
Doxygen/xml/d8/d3d/RestInterface.md \
Doxygen/xml/db/d14/GeoCoordinates.md \
Doxygen/xml/d3/db6/JavaScriptFuncIndex.md \
Doxygen/xml/df/d91/CommandLineRandom.md \
Doxygen/xml/d9/ddd/CommandLineAvocado.md
Doxygen/xml/d9/ddd/CommandLineAvocado.md \
Doxygen/xml/d7/d40/JSModuleConsole.md \
Doxygen/xml/d3/d4b/JSModuleInternal.md \
Doxygen/xml/d2/d66/JSModuleFs.md
Doxygen/xml/d9/d52/DefineAction.md: Doxygen/xml/d9/d52/DefineAction.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@
@ -314,7 +316,7 @@ Doxygen/xml/d4/d7d/HttpInterface.md: Doxygen/xml/d4/d7d/HttpInterface.xml
Doxygen/xml/d9/de4/JSModules.md: Doxygen/xml/d9/de4/JSModules.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@
Doxygen/xml/d0/da4/GraphFuncIndex.md: Doxygen/xml/d0/da4/GraphFuncIndex.xml
Doxygen/xml/d2/d35/JSModuleGraph.md: Doxygen/xml/d2/d35/JSModuleGraph.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@
Doxygen/xml/d9/db2/CommandLineScheduler.md: Doxygen/xml/d9/db2/CommandLineScheduler.xml
@ -335,3 +337,11 @@ Doxygen/xml/df/d91/CommandLineRandom.md: Doxygen/xml/df/d91/CommandLineRandom.xm
Doxygen/xml/d9/ddd/CommandLineAvocado.md: Doxygen/xml/d9/ddd/CommandLineAvocado.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@
Doxygen/xml/d7/d40/JSModuleConsole.md: Doxygen/xml/d7/d40/JSModuleConsole.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@
Doxygen/xml/d3/d4b/JSModuleInternal.md: Doxygen/xml/d3/d4b/JSModuleInternal.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@
Doxygen/xml/d2/d66/JSModuleFs.md: Doxygen/xml/d2/d66/JSModuleFs.xml
python @top_srcdir@/Doxygen/Scripts/xml2md.py $< > $@

View File

@ -227,8 +227,7 @@ JSLoader* ActionDisptacherThread::actionLoader () {
void ActionDisptacherThread::initialise () {
bool ok;
char* filename;
char const* files[] = { "actions.js", "graph.js", "json.js", "modules.js" };
char const* files[] = { "modules.js", "actions.js", "json.js" };
size_t i;
// enter a new isolate
@ -240,7 +239,8 @@ void ActionDisptacherThread::initialise () {
if (_context.IsEmpty()) {
LOGGER_FATAL << "cannot initialize V8 engine";
TRIAGENS_REST_SHUTDOWN;
cerr << "cannot initialize V8 engine\n";
_isolate->Exit();
exit(EXIT_FAILURE);
}
@ -256,8 +256,10 @@ void ActionDisptacherThread::initialise () {
ok = _startupLoader->loadScript(_context, files[i]);
if (! ok) {
LOGGER_FATAL << "cannot load json utilities from file '" << filename << "'";
TRIAGENS_REST_SHUTDOWN;
LOGGER_FATAL << "cannot load json utilities from file '" << files[i] << "'";
cerr << "cannot load json utilities from file '" << files[i] << "'\n";
_context->Exit();
_isolate->Exit();
exit(EXIT_FAILURE);
}
}
@ -272,8 +274,10 @@ void ActionDisptacherThread::initialise () {
ok = actionLoader()->loadAllScripts(_context);
if (! ok) {
LOGGER_FATAL << "cannot load actions from directory '" << filename << "'";
TRIAGENS_REST_SHUTDOWN;
LOGGER_FATAL << "cannot load actions from directory '" << loader->getDirectory() << "'";
cerr << "cannot load actions from directory '" << loader->getDirectory() << "'\n";
_context->Exit();
_isolate->Exit();
exit(EXIT_FAILURE);
}
}

View File

@ -157,7 +157,7 @@ AvocadoServer::AvocadoServer (int argc, char** argv)
_adminPort("localhost:8530"),
_dispatcherThreads(1),
_startupPath(),
_startupModules(),
_startupModules("js/modules"),
_actionPath(),
_systemActionPath(),
_actionThreads(1),
@ -279,7 +279,6 @@ void AvocadoServer::buildApplicationServer () {
// .............................................................................
if (! _applicationServer->parse(_argc, _argv, additional)) {
TRIAGENS_REST_SHUTDOWN;
exit(EXIT_FAILURE);
}
@ -300,7 +299,6 @@ void AvocadoServer::buildApplicationServer () {
if (_startupPath.empty()) {
StartupLoader.defineScript("modules.js", JS_modules);
StartupLoader.defineScript("actions.js", JS_actions);
StartupLoader.defineScript("graph.js", JS_graph);
StartupLoader.defineScript("json.js", JS_json);
StartupLoader.defineScript("shell.js", JS_shell);
}
@ -316,8 +314,8 @@ void AvocadoServer::buildApplicationServer () {
if (ok) {
LOGGER_FATAL << "action directory '" << path << "' must be a directory";
cerr << "action directory '" << path << "' must be a directory\n";
LOGGER_INFO << "please use the '--database.directory' option";
TRIAGENS_REST_SHUTDOWN;
exit(EXIT_FAILURE);
}
@ -325,8 +323,8 @@ void AvocadoServer::buildApplicationServer () {
if (! ok) {
LOGGER_FATAL << "cannot create action directory '" << path << "': " << TRI_last_error();
cerr << "cannot create action directory '" << path << "': " << TRI_last_error() << "\n";
LOGGER_INFO << "please use the '--database.directory' option";
TRIAGENS_REST_SHUTDOWN;
exit(EXIT_FAILURE);
}
}
@ -365,16 +363,16 @@ void AvocadoServer::buildApplicationServer () {
if (_daemonMode) {
if (_pidFile.empty()) {
LOGGER_FATAL << "no pid-file defined, but daemon mode requested";
cerr << "no pid-file defined, but daemon mode requested\n";
LOGGER_INFO << "please use the '--pid-file' option";
TRIAGENS_REST_SHUTDOWN;
exit(EXIT_FAILURE);
}
}
if (_databasePath.empty()) {
LOGGER_FATAL << "no database path has been supplied, giving up";
cerr << "no database path has been supplied, giving up\n";
LOGGER_INFO << "please use the '--database.directory' option";
TRIAGENS_REST_SHUTDOWN;
exit(EXIT_FAILURE);
}
}
@ -515,7 +513,7 @@ void AvocadoServer::executeShell () {
v8::Isolate* isolate;
v8::Persistent<v8::Context> context;
bool ok;
char const* files[] = { "modules.js", "graph.js", "json.js", "shell.js" };
char const* files[] = { "modules.js", "json.js", "shell.js" };
size_t i;
// only simple logging
@ -538,7 +536,7 @@ void AvocadoServer::executeShell () {
if (context.IsEmpty()) {
LOGGER_FATAL << "cannot initialize V8 engine";
TRIAGENS_REST_SHUTDOWN;
cerr << "cannot initialize V8 engine\n";
exit(EXIT_FAILURE);
}
@ -557,7 +555,7 @@ void AvocadoServer::executeShell () {
}
else {
LOGGER_FATAL << "cannot load json file '" << files[i] << "'";
TRIAGENS_REST_SHUTDOWN;
cerr << "cannot load json file '" << files[i] << "'\n";
exit(EXIT_FAILURE);
}
}
@ -614,8 +612,8 @@ void AvocadoServer::openDatabase () {
if (_vocbase == 0) {
LOGGER_FATAL << "cannot open database '" << _databasePath << "'";
cerr << "cannot open database '" << _databasePath << "'\n";
LOGGER_INFO << "please use the '--database.directory' option";
TRIAGENS_REST_SHUTDOWN;
exit(EXIT_FAILURE);
}
}

View File

@ -69,6 +69,14 @@ JSLoader::JSLoader ()
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief gets the directory for scripts
////////////////////////////////////////////////////////////////////////////////
string const& JSLoader::getDirectory () const {
return _directory;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the directory for scripts
////////////////////////////////////////////////////////////////////////////////

View File

@ -88,6 +88,12 @@ namespace triagens {
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief gets the directory for scripts
////////////////////////////////////////////////////////////////////////////////
string const& getDirectory () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the directory for scripts
////////////////////////////////////////////////////////////////////////////////

View File

@ -1790,6 +1790,8 @@ bool TRI_ObjectToBoolean (v8::Handle<v8::Value> value) {
/// assigned inside the @FA{script}, will be visible in the @FA{sandbox} object
/// after execution. The @FA{filename} is used for displaying error
/// messages.
///
/// If @FA{sandbox} is undefined, then @FN{execute} uses the current context.
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_Execute (v8::Arguments const& argv) {
@ -1810,36 +1812,38 @@ static v8::Handle<v8::Value> JS_Execute (v8::Arguments const& argv) {
return scope.Close(v8::ThrowException(v8::String::New("<script> must be a string")));
}
if (! sandboxValue->IsObject()) {
return scope.Close(v8::ThrowException(v8::String::New("<sandbox> must be an object")));
}
bool useSandbox = sandboxValue->IsObject();
v8::Handle<v8::Object> sandbox;
v8::Handle<v8::Context> context;
v8::Handle<v8::Object> sandbox = sandboxValue->ToObject();
if (useSandbox) {
sandbox = sandboxValue->ToObject();
// create new context
v8::Handle<v8::Context> context = v8::Context::New();
context->Enter();
// create new context
context = v8::Context::New();
context->Enter();
// copy sandbox into context
v8::Handle<v8::Array> keys = sandbox->GetPropertyNames();
// copy sandbox into context
v8::Handle<v8::Array> keys = sandbox->GetPropertyNames();
for (i = 0; i < keys->Length(); i++) {
v8::Handle<v8::String> key = keys->Get(v8::Integer::New(i))->ToString();
v8::Handle<v8::Value> value = sandbox->Get(key);
for (i = 0; i < keys->Length(); i++) {
v8::Handle<v8::String> key = keys->Get(v8::Integer::New(i))->ToString();
v8::Handle<v8::Value> value = sandbox->Get(key);
if (TRI_IsTraceLogging(__FILE__)) {
v8::String::Utf8Value keyName(key);
if (TRI_IsTraceLogging(__FILE__)) {
v8::String::Utf8Value keyName(key);
if (*keyName != 0) {
LOG_TRACE("copying key '%s' from sandbox to context", *keyName);
if (*keyName != 0) {
LOG_TRACE("copying key '%s' from sandbox to context", *keyName);
}
}
}
if (value == sandbox) {
value = context->Global();
}
if (value == sandbox) {
value = context->Global();
}
context->Global()->Set(key, value);
context->Global()->Set(key, value);
}
}
// execute script inside the context
@ -1849,8 +1853,10 @@ static v8::Handle<v8::Value> JS_Execute (v8::Arguments const& argv) {
if (script.IsEmpty()) {
assert(tryCatch.HasCaught());
context->DetachGlobal();
context->Exit();
if (useSandbox) {
context->DetachGlobal();
context->Exit();
}
return scope.Close(tryCatch.ReThrow());
}
@ -1861,38 +1867,47 @@ static v8::Handle<v8::Value> JS_Execute (v8::Arguments const& argv) {
if (result.IsEmpty()) {
assert(tryCatch.HasCaught());
context->DetachGlobal();
context->Exit();
if (useSandbox) {
context->DetachGlobal();
context->Exit();
}
return scope.Close(tryCatch.ReThrow());
}
// copy result back into the sandbox
keys = context->Global()->GetPropertyNames();
if (useSandbox) {
v8::Handle<v8::Array> keys = context->Global()->GetPropertyNames();
for (i = 0; i < keys->Length(); i++) {
v8::Handle<v8::String> key = keys->Get(v8::Integer::New(i))->ToString();
v8::Handle<v8::Value> value = context->Global()->Get(key);
if (TRI_IsTraceLogging(__FILE__)) {
v8::String::Utf8Value keyName(key);
if (*keyName != 0) {
LOG_TRACE("copying key '%s' from context to sandbox", *keyName);
for (i = 0; i < keys->Length(); i++) {
v8::Handle<v8::String> key = keys->Get(v8::Integer::New(i))->ToString();
v8::Handle<v8::Value> value = context->Global()->Get(key);
if (TRI_IsTraceLogging(__FILE__)) {
v8::String::Utf8Value keyName(key);
if (*keyName != 0) {
LOG_TRACE("copying key '%s' from context to sandbox", *keyName);
}
}
if (value == context->Global()) {
value = sandbox;
}
sandbox->Set(key, value);
}
if (value == context->Global()) {
value = sandbox;
}
sandbox->Set(key, value);
context->DetachGlobal();
context->Exit();
}
context->DetachGlobal();
context->Exit();
return scope.Close(v8::True());
if (useSandbox) {
return scope.Close(v8::True());
}
else {
return scope.Close(result);
}
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -1 +1 @@
#define TRIAGENS_VERSION "0.0.8 [1121:1129M]"
#define TRIAGENS_VERSION "0.0.8 [1121:1131M]"

View File

@ -84,6 +84,7 @@ Module.prototype.require = function (path) {
var sandbox;
var paths;
var module;
var f;
// first get rid of any ".." and "."
path = this.normalise(path);
@ -121,15 +122,14 @@ Module.prototype.require = function (path) {
// create a new sandbox and execute
ModuleCache[path] = module = new Module(path);
sandbox = {};
sandbox.module = module;
sandbox.exports = module.exports;
sandbox.require = function(path) { return sandbox.module.require(path); }
sandbox.print = print;
content = "(function (module, exports, require, print) {" + content + "\n});";
f = SYS_EXECUTE(content, undefined, path);
SYS_EXECUTE(content, sandbox, path);
if (f == undefined) {
throw "cannot create context function";
}
module.exports = sandbox.exports;
f(module, module.exports, function(path) { return module.require(path); }, print);
return module.exports;
};
@ -325,6 +325,10 @@ fs = ModuleCache["/fs"].exports;
////////////////////////////////////////////////////////////////////////////////
ModuleCache["/internal"] = new Module("/internal");
ModuleCache["/internal"].exports.AvocadoCollection = AvocadoCollection;
ModuleCache["/internal"].exports.AvocadoEdgesCollection = AvocadoEdgesCollection;
ModuleCache["/internal"].exports.db = db;
ModuleCache["/internal"].exports.edges = edges;
ModuleCache["/internal"].exports.execute = SYS_EXECUTE;
ModuleCache["/internal"].exports.load = SYS_LOAD;
ModuleCache["/internal"].exports.log = SYS_LOG;

View File

@ -26,6 +26,10 @@
////////////////////////////////////////////////////////////////////////////////
var internal = require("internal");
var db = internal.db;
var edges = internal.edges;
var AvocadoCollection = internal.AvocadoCollection;
var AvocadoEdgesCollection = internal.AvocadoEdgesCollection;
////////////////////////////////////////////////////////////////////////////////
/// @page Graphs First Steps with Graphs
@ -45,119 +49,124 @@ var internal = require("internal");
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @page GraphFuncIndexTOC
/// @page JSModuleGraphTOC
///
/// <ol>
/// <li>Graph</li>
/// <ol>
/// <li>@ref GraphFuncIndexGraphConstructor "Graph constructor"</li>
/// <li>@ref GraphFuncIndexGraphAddEdge "Graph.addEdge"</li>
/// <li>@ref GraphFuncIndexGraphAddVertex "Graph.addVertex"</li>
/// <li>@ref GraphFuncIndexGraphGetVertex "Graph.getVertex"</li>
/// <li>@ref JSModuleGraphGraphConstructor "Graph constructor"</li>
/// <li>@ref JSModuleGraphGraphAddEdge "Graph.addEdge"</li>
/// <li>@ref JSModuleGraphGraphAddVertex "Graph.addVertex"</li>
/// <li>@ref JSModuleGraphGraphGetVertex "Graph.getVertex"</li>
/// </ol>
/// <li>Vertex</li>
/// <ol>
/// <li>@ref GraphFuncIndexVertexEdges "Vertex.edges"</li>
/// <li>@ref GraphFuncIndexVertexAddInEdge "Vertex.addInEdge"</li>
/// <li>@ref GraphFuncIndexVertexAddOutEdge "Vertex.addOutEdge"</li>
/// <li>@ref GraphFuncIndexVertexGetId "Vertex.getId"</li>
/// <li>@ref GraphFuncIndexVertexGetInEdges "Vertex.getInEdges"</li>
/// <li>@ref GraphFuncIndexVertexGetOutEdges "Vertex.getOutEdges"</li>
/// <li>@ref GraphFuncIndexVertexGetProperty "Vertex.getProperty"</li>
/// <li>@ref GraphFuncIndexVertexGetPropertyKeys "Vertex.getPropertyKeys"</li>
/// <li>@ref GraphFuncIndexVertexProperties "Vertex.properties"</li>
/// <li>@ref GraphFuncIndexVertexSetProperty "Vertex.setProperty"</li>
/// <li>@ref JSModuleGraphVertexAddInEdge "Vertex.addInEdge"</li>
/// <li>@ref JSModuleGraphVertexAddOutEdge "Vertex.addOutEdge"</li>
/// <li>@ref JSModuleGraphVertexEdges "Vertex.edges"</li>
/// <li>@ref JSModuleGraphVertexGetId "Vertex.getId"</li>
/// <li>@ref JSModuleGraphVertexGetInEdges "Vertex.getInEdges"</li>
/// <li>@ref JSModuleGraphVertexGetOutEdges "Vertex.getOutEdges"</li>
/// <li>@ref JSModuleGraphVertexGetProperty "Vertex.getProperty"</li>
/// <li>@ref JSModuleGraphVertexGetPropertyKeys "Vertex.getPropertyKeys"</li>
/// <li>@ref JSModuleGraphVertexProperties "Vertex.properties"</li>
/// <li>@ref JSModuleGraphVertexSetProperty "Vertex.setProperty"</li>
/// </ol>
/// <li>Edge</li>
/// <ol>
/// <li>@ref GraphFuncIndexEdgeGetId "Edge.getId"</li>
/// <li>@ref GraphFuncIndexEdgeGetInVertex "Edge.getInVertex"</li>
/// <li>@ref GraphFuncIndexEdgeGetLabel "Edge.getLabel"</li>
/// <li>@ref GraphFuncIndexEdgeGetOutVertex "Edge.getOutVertex"</li>
/// <li>@ref GraphFuncIndexEdgeGetProperty "Edge.getProperty"</li>
/// <li>@ref GraphFuncIndexEdgeGetPropertyKeys "Edge.getPropertyKeys"</li>
/// <li>@ref GraphFuncIndexEdgeProperties "Edge.properties"</li>
/// <li>@ref GraphFuncIndexEdgeSetProperty "Edge.setProperty"</li>
/// <li>@ref JSModuleGraphEdgeGetId "Edge.getId"</li>
/// <li>@ref JSModuleGraphEdgeGetInVertex "Edge.getInVertex"</li>
/// <li>@ref JSModuleGraphEdgeGetLabel "Edge.getLabel"</li>
/// <li>@ref JSModuleGraphEdgeGetOutVertex "Edge.getOutVertex"</li>
/// <li>@ref JSModuleGraphEdgeGetProperty "Edge.getProperty"</li>
/// <li>@ref JSModuleGraphEdgeGetPropertyKeys "Edge.getPropertyKeys"</li>
/// <li>@ref JSModuleGraphEdgeProperties "Edge.properties"</li>
/// <li>@ref JSModuleGraphEdgeSetProperty "Edge.setProperty"</li>
/// </ol>
/// </li>
/// </ol>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @page GraphFuncIndex Index of Graph Functions
/// @page JSModuleGraph Module "graph"
///
/// @copydoc GraphFuncIndexTOC
/// The graph module provides basic functions dealing with graph structures.
/// It exports the constructors for Graph, Vertex, and Edge.
///
/// <hr>
/// @copydoc JSModuleGraphTOC
/// <hr>
///
/// @section Graph
///
/// @anchor GraphFuncIndexGraphConstructor
/// @anchor JSModuleGraphGraphConstructor
/// @copydetails JSF_Graph
///
/// @anchor GraphFuncIndexGraphAddEdge
/// @anchor JSModuleGraphGraphAddEdge
/// @copydetails JSF_Graph_prototype_addEdge
///
/// @anchor GraphFuncIndexGraphAddVertex
/// @anchor JSModuleGraphGraphAddVertex
/// @copydetails JSF_Graph_prototype_addVertex
///
/// @anchor GraphFuncIndexGraphGetVertex
/// @anchor JSModuleGraphGraphGetVertex
/// @copydetails JSF_Graph_prototype_getVertex
///
/// @section Vertex
///
/// @anchor GraphFuncIndexVertexEdges
/// @copydetails JSF_Vertex_prototype_edges
///
/// @anchor GraphFuncIndexVertexAddInEdge
/// @anchor JSModuleGraphVertexAddInEdge
/// @copydetails JSF_Vertex_prototype_addInEdge
///
/// @anchor GraphFuncIndexVertexAddOutEdge
/// @anchor JSModuleGraphVertexAddOutEdge
/// @copydetails JSF_Vertex_prototype_addOutEdge
///
/// @anchor GraphFuncIndexVertexGetId
/// @anchor JSModuleGraphVertexEdges
/// @copydetails JSF_Vertex_prototype_edges
///
/// @anchor JSModuleGraphVertexGetId
/// @copydetails JSF_Vertex_prototype_getId
///
/// @anchor GraphFuncIndexVertexGetInEdges
/// @anchor JSModuleGraphVertexGetInEdges
/// @copydetails JSF_Vertex_prototype_getInEdges
///
/// @anchor GraphFuncIndexVertexGetOutEdges
/// @anchor JSModuleGraphVertexGetOutEdges
/// @copydetails JSF_Vertex_prototype_getOutEdges
///
/// @anchor GraphFuncIndexVertexGetProperty
/// @anchor JSModuleGraphVertexGetProperty
/// @copydetails JSF_Vertex_prototype_getProperty
///
/// @anchor GraphFuncIndexVertexGetPropertyKeys
/// @anchor JSModuleGraphVertexGetPropertyKeys
/// @copydetails JSF_Vertex_prototype_getPropertyKeys
///
/// @anchor GraphFuncIndexVertexProperties
/// @anchor JSModuleGraphVertexProperties
/// @copydetails JSF_Vertex_prototype_properties
///
/// @anchor GraphFuncIndexVertexSetProperty
/// @anchor JSModuleGraphVertexSetProperty
/// @copydetails JSF_Vertex_prototype_setProperty
///
/// @section Edge
///
/// @anchor GraphFuncIndexEdgeGetId
/// @anchor JSModuleGraphEdgeGetId
/// @copydetails JSF_Edge_prototype_getId
///
/// @anchor GraphFuncIndexEdgeGetInVertex
/// @anchor JSModuleGraphEdgeGetInVertex
/// @copydetails JSF_Edge_prototype_getInVertex
///
/// @anchor GraphFuncIndexEdgeGetLabel
/// @anchor JSModuleGraphEdgeGetLabel
/// @copydetails JSF_Edge_prototype_getLabel
///
/// @anchor GraphFuncIndexEdgeGetOutVertex
/// @anchor JSModuleGraphEdgeGetOutVertex
/// @copydetails JSF_Edge_prototype_getOutVertex
///
/// @anchor GraphFuncIndexEdgeGetProperty
/// @anchor JSModuleGraphEdgeGetProperty
/// @copydetails JSF_Edge_prototype_getProperty
///
/// @anchor GraphFuncIndexEdgeGetPropertyKeys
/// @anchor JSModuleGraphEdgeGetPropertyKeys
/// @copydetails JSF_Edge_prototype_getPropertyKeys
///
/// @anchor GraphFuncIndexEdgeProperties
/// @anchor JSModuleGraphEdgeProperties
/// @copydetails JSF_Edge_prototype_properties
///
/// @anchor GraphFuncIndexEdgeSetProperty
/// @anchor JSModuleGraphEdgeSetProperty
/// @copydetails JSF_Edge_prototype_setProperty
///
////////////////////////////////////////////////////////////////////////////////
@ -180,8 +189,16 @@ var internal = require("internal");
////////////////////////////////////////////////////////////////////////////////
function Edge (graph, id) {
var props;
this._graph = graph;
this._id = id;
props = this._graph._edges.document(this._id).next();
this._label = props._label;
this._from = props._from;
this._to = props._to;
}
////////////////////////////////////////////////////////////////////////////////
@ -236,10 +253,6 @@ Edge.prototype.getInVertex = function () {
////////////////////////////////////////////////////////////////////////////////
Edge.prototype.getLabel = function () {
if (! this.hasOwnProperty("_label")) {
this.properties();
}
return this._label;
}
@ -268,21 +281,17 @@ Edge.prototype.getOutVertex = function () {
////////////////////////////////////////////////////////////////////////////////
Edge.prototype.getProperty = function (name) {
var props;
props = this.properties();
return props[name]
return this.properties()[name];
}
////////////////////////////////////////////////////////////////////////////////
/// @brief gets all property names of an edge
///
/// @FUN{@FA{vertex}.getPropertyKeys()}
/// @FUN{@FA{edge}.getPropertyKeys()}
///
/// Returns all propety names a @FA{vertex}.
/// Returns all propety names an @FA{edge}.
///
/// @verbinclude graph7
/// @verbinclude graph32
////////////////////////////////////////////////////////////////////////////////
Edge.prototype.getPropertyKeys = function () {
@ -316,8 +325,6 @@ Edge.prototype.setProperty = function (name, value) {
var query;
var props;
delete this._properties;
query = this._graph._edges.document(this._id); // TODO use "update"
if (query.hasNext()) {
@ -345,29 +352,16 @@ Edge.prototype.setProperty = function (name, value) {
////////////////////////////////////////////////////////////////////////////////
Edge.prototype.properties = function () {
var query;
var prop;
var props;
if (! this.hasOwnProperty("_properties")) {
query = this._graph._edges.document(this._id);
props = this._graph._edges.document(this._id).next();
if (query.hasNext()) {
this._properties = query.next();
this._label = this._properties._label;
this._from = this._properties._from;
this._to = this._properties._to;
delete props._id;
delete props._label;
delete props._from;
delete props._to;
delete this._properties._id;
delete this._properties._label;
delete this._properties._from;
delete this._properties._to;
}
else {
return undefined;
}
}
return this._properties;
return props;
}
////////////////////////////////////////////////////////////////////////////////
@ -387,7 +381,7 @@ Edge.prototype.properties = function () {
/// @brief edge printing
////////////////////////////////////////////////////////////////////////////////
Edge.prototype.PRINT = function () {
Edge.prototype.PRINT = function (seen, path, names) {
internal.output("Edge(<graph>, \"", this._id, "\")");
}
@ -460,14 +454,14 @@ Vertex.prototype.addInEdge = function (out, label, data) {
/// Creates a new edge from @FA{vertex} to @FA{peer} with given @FA{label} and
/// returns the edge object.
///
/// @verbinclude graph23
/// @verbinclude graph27
///
/// @FUN{@FA{vertex}.addOutEdge(@FA{peer}, @FA{label}, @FA{data})}
///
/// Creates a new edge from @FA{vertex} to @FA{peer} with given @FA{label} and
/// properties defined in @FA{data}. Returns the edge object.
///
/// @verbinclude graph24
/// @verbinclude graph28
////////////////////////////////////////////////////////////////////////////////
Vertex.prototype.addOutEdge = function (ine, label, data) {
@ -489,19 +483,15 @@ Vertex.prototype.edges = function () {
var result;
var graph;
if (! this.hasOwnProperty("_edges")) {
graph = this._graph;
query = graph._vertices.document(this._id).edges(graph._edges);
result = [];
graph = this._graph;
query = graph._vertices.document(this._id).edges(graph._edges);
result = [];
while (query.hasNext()) {
result.push(graph.constructEdge(query.nextRef()));
}
this._edges = result;
while (query.hasNext()) {
result.push(graph.constructEdge(query.nextRef()));
}
return this._edges;
return result;
}
////////////////////////////////////////////////////////////////////////////////
@ -607,11 +597,7 @@ Vertex.prototype.getOutEdges = function () {
////////////////////////////////////////////////////////////////////////////////
Vertex.prototype.getProperty = function (name) {
var props;
props = this.properties();
return props[name]
return this.properties()[name];
}
////////////////////////////////////////////////////////////////////////////////
@ -656,19 +642,15 @@ Vertex.prototype.inbound = function () {
var result;
var graph;
if (! this.hasOwnProperty("_inbound")) {
graph = this._graph;
query = graph._vertices.document(this._id).inEdges(graph._edges);
result = [];
graph = this._graph;
query = graph._vertices.document(this._id).inEdges(graph._edges);
result = [];
while (query.hasNext()) {
result.push(graph.constructEdge(query.nextRef()));
}
this._inbound = result;
while (query.hasNext()) {
result.push(graph.constructEdge(query.nextRef()));
}
return this._inbound;
return result;
}
////////////////////////////////////////////////////////////////////////////////
@ -686,19 +668,15 @@ Vertex.prototype.outbound = function () {
var result;
var graph;
if (! this.hasOwnProperty("_outbound")) {
graph = this._graph;
query = graph._vertices.document(this._id).outEdges(graph._edges);
result = [];
graph = this._graph;
query = graph._vertices.document(this._id).outEdges(graph._edges);
result = [];
while (query.hasNext()) {
result.push(graph.constructEdge(query.nextRef()));
}
this._outbound = result;
while (query.hasNext()) {
result.push(graph.constructEdge(query.nextRef()));
}
return this._outbound;
return result;
}
////////////////////////////////////////////////////////////////////////////////
@ -712,22 +690,13 @@ Vertex.prototype.outbound = function () {
////////////////////////////////////////////////////////////////////////////////
Vertex.prototype.properties = function () {
var query;
var prop;
var props;
if (! this.hasOwnProperty("_properties")) {
query = this._graph._vertices.document(this._id);
props = this._graph._vertices.document(this._id).next();
if (query.hasNext()) {
this._properties = query.next();
delete this._properties._id;
}
else {
return undefined;
}
}
delete props._id;
return this._properties;
return props;
}
////////////////////////////////////////////////////////////////////////////////
@ -779,7 +748,7 @@ Vertex.prototype.setProperty = function (name, value) {
/// @brief vertex representation
////////////////////////////////////////////////////////////////////////////////
Vertex.prototype.PRINT = function () {
Vertex.prototype.PRINT = function (seen, path, names) {
internal.output("Vertex(<graph>, \"", this._id, "\")");
}
@ -806,7 +775,9 @@ Vertex.prototype.PRINT = function () {
/// @FUN{Graph(@FA{vertices}, @FA{edges})}
///
/// Constructs a new graph object using the collection @FA{vertices} for all
/// vertices and the collection @FA{edges} for all edges.
/// vertices and the collection @FA{edges} for all edges. Note that it is
/// possible to construct two graphs with the vertex set, but different edge
/// sets.
///
/// @verbinclude graph1
////////////////////////////////////////////////////////////////////////////////
@ -815,22 +786,21 @@ function Graph (vertices, edg) {
if (typeof vertices === "string") {
vertices = db[vertices];
}
else if (! vertices instanceof AvocadoCollection) {
if (! vertices instanceof AvocadoCollection) {
throw "<vertices> must be a document collection";
}
if (typeof edg === "string") {
edg = edges[edg];
}
else if (! edg instanceof AvocadoEdgesCollection) {
if (! edg instanceof AvocadoEdgesCollection) {
throw "<edges> must be an edges collection";
}
this._vertices = vertices;
this._verticesCache = {};
this._edges = edg;
this._edgesCache = {};
}
////////////////////////////////////////////////////////////////////////////////
@ -854,6 +824,8 @@ function Graph (vertices, edg) {
/// Creates a new edge from @FA{out} to @FA{in} and returns the edge
/// object.
///
/// @verbinclude graph30
///
/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label})}
///
/// Creates a new edge from @FA{out} to @FA{in} with @FA{label} and returns the
@ -866,6 +838,8 @@ function Graph (vertices, edg) {
/// Creates a new edge and returns the edge object. The edge contains the
/// properties defined in @FA{data}.
///
/// @verbinclude graph31
///
/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{label}, @FA{data})}
///
/// Creates a new edge and returns the edge object. The edge has the
@ -906,25 +880,7 @@ Graph.prototype.addEdge = function (out, ine, label, data) {
ref = this._edges.save(out._id, ine._id, shallow);
}
edge = this.constructEdge(ref);
if (out.hasOwnProperty("_edges")) {
out._edges.push(edge);
}
if (out.hasOwnProperty("_outbound")) {
out._outbound.push(edge);
}
if (ine.hasOwnProperty("_edges")) {
ine._edges.push(edge);
}
if (ine.hasOwnProperty("_inbound")) {
ine._inbound.push(edge);
}
return edge;
return this.constructEdge(ref);
}
////////////////////////////////////////////////////////////////////////////////
@ -964,7 +920,7 @@ Graph.prototype.addVertex = function (data) {
///
/// Returns the vertex identified by @FA{id} or undefined.
///
/// @verbinclude graph2
/// @verbinclude graph29
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.getVertex = function (id) {
@ -998,11 +954,7 @@ Graph.prototype.getVertex = function (id) {
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.constructVertex = function(id) {
if (! (id in this._verticesCache)) {
this._verticesCache[id] = new Vertex(this, id);
}
return this._verticesCache[id];
return new Vertex(this, id);
}
////////////////////////////////////////////////////////////////////////////////
@ -1010,18 +962,14 @@ Graph.prototype.constructVertex = function(id) {
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.constructEdge = function(id) {
if (! (id in this._edgesCache)) {
this._edgesCache[id] = new Edge(this, id);
}
return this._edgesCache[id];
return new Edge(this, id);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief graph printing
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.PRINT = function () {
Graph.prototype.PRINT = function (seen, path, names) {
internal.output("Graph(\"", this._vertices._name, "\", \"" + this._edges._name, "\")");
}
@ -1029,6 +977,25 @@ Graph.prototype.PRINT = function () {
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- MODULE EXPORTS
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup AvocadoGraph
/// @{
////////////////////////////////////////////////////////////////////////////////
exports.AvocadoCollection = AvocadoCollection;
exports.AvocadoEdgesCollection = AvocadoEdgesCollection;
exports.Edge = Edge;
exports.Graph = Graph;
exports.Vertex = Vertex;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"