mirror of https://gitee.com/bigwinds/arangodb
added CollectionDatasourceFactory
This commit is contained in:
parent
c8b55b9b4d
commit
848cc1ae28
|
@ -51,7 +51,8 @@ function ArangoTraverser (config) {
|
|||
},
|
||||
visitor: TrackingVisitor,
|
||||
filter: VisitAllFilter,
|
||||
expander: CollectionOutboundExpander
|
||||
expander: CollectionOutboundExpander,
|
||||
datasource: null
|
||||
};
|
||||
|
||||
if (typeof config !== "object") {
|
||||
|
@ -94,6 +95,10 @@ function ArangoTraverser (config) {
|
|||
throw "invalid expander";
|
||||
}
|
||||
|
||||
if (typeof config.datasource !== "object") {
|
||||
throw "invalid datasource";
|
||||
}
|
||||
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
@ -458,7 +463,7 @@ function DepthFirstSearch () {
|
|||
|
||||
function CollectionOutboundExpander (config, vertex, path) {
|
||||
var connections = [ ];
|
||||
var outEdges = config.edgeCollection.outEdges(vertex._id);
|
||||
var outEdges = config.datasource.getOutEdges(vertex._id);
|
||||
|
||||
if (outEdges.length > 1 && config.sort) {
|
||||
outEdges.sort(config.sort);
|
||||
|
@ -466,7 +471,7 @@ function CollectionOutboundExpander (config, vertex, path) {
|
|||
|
||||
outEdges.forEach(function (edge) {
|
||||
try {
|
||||
var v = internal.db._document(edge._to);
|
||||
var v = config.datasource.getVertex(edge._to);
|
||||
connections.push({ edge: edge, vertex: v });
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -483,7 +488,7 @@ function CollectionOutboundExpander (config, vertex, path) {
|
|||
|
||||
function CollectionInboundExpander (config, vertex, path) {
|
||||
var connections = [ ];
|
||||
var inEdges = config.edgeCollection.inEdges(vertex._id);
|
||||
var inEdges = config.datasource.getInEdges(vertex._id);
|
||||
|
||||
if (inEdges.length > 1 && config.sort) {
|
||||
inEdges.sort(config.sort);
|
||||
|
@ -491,7 +496,7 @@ function CollectionInboundExpander (config, vertex, path) {
|
|||
|
||||
inEdges.forEach(function (edge) {
|
||||
try {
|
||||
var v = internal.db._document(edge._from);
|
||||
var v = config.datasource.getVertex(edge._from);
|
||||
connections.push({ edge: edge, vertex: v });
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -508,7 +513,7 @@ function CollectionInboundExpander (config, vertex, path) {
|
|||
|
||||
function CollectionAnyExpander (config, vertex, path) {
|
||||
var connections = [ ];
|
||||
var edges = config.edgeCollection.edges(vertex._id);
|
||||
var edges = config.datasource.getAllEdges(vertex._id);
|
||||
|
||||
if (edges.length > 1 && config.sort) {
|
||||
edges.sort(config.sort);
|
||||
|
@ -516,7 +521,7 @@ function CollectionAnyExpander (config, vertex, path) {
|
|||
|
||||
edges.forEach(function (edge) {
|
||||
try {
|
||||
var v = internal.db._document(edge._from === vertex._id ? edge._to : edge._from);
|
||||
var v = config.datasource.getVertex(edge._from === vertex._id ? edge._to : edge._from);
|
||||
connections.push({ edge: edge, vertex: v });
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -527,6 +532,32 @@ function CollectionAnyExpander (config, vertex, path) {
|
|||
return connections;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief default ArangoCollection datasource
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function CollectionDatasourceFactory (edgeCollection) {
|
||||
return {
|
||||
edgeCollection: edgeCollection,
|
||||
|
||||
getAllEdges: function (vertexId) {
|
||||
return this.edgeCollection.edges(vertexId);
|
||||
},
|
||||
|
||||
getInEdges: function (vertexId) {
|
||||
return this.edgeCollection.inEdges(vertexId);
|
||||
},
|
||||
|
||||
getOutEdges: function (vertexId) {
|
||||
return this.edgeCollection.outEdges(vertexId);
|
||||
},
|
||||
|
||||
getVertex: function (vertexId) {
|
||||
return internal.db._document(vertexId);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief default expander that expands all outbound edges labeled with one label in config.labels
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -651,7 +682,7 @@ function MaxDepthFilter (config, vertex, path) {
|
|||
if (path.vertices.length > config.maxDepth) {
|
||||
return ArangoTraverser.PRUNE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief default filter to exclude all vertices up to a given depth
|
||||
|
@ -661,14 +692,15 @@ function MinDepthFilter (config, vertex, path) {
|
|||
if (path.vertices.length <= config.minDepth) {
|
||||
return ArangoTraverser.EXCLUDE;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief default filter to include all vertices matching one of the given attribute sets
|
||||
/// @brief default filter to include all vertices matching one of the given
|
||||
/// attribute sets
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function IncludeMatchingAttributesFilter (config, vertex, path) {
|
||||
if (!Array.isArray(config.matchingAttributes)) {
|
||||
if (! Array.isArray(config.matchingAttributes)) {
|
||||
config.matchingAttributes = [config.matchingAttributes];
|
||||
}
|
||||
var include = false
|
||||
|
@ -803,6 +835,7 @@ exports.Traverser = ArangoTraverser;
|
|||
exports.CollectionOutboundExpander = CollectionOutboundExpander;
|
||||
exports.CollectionInboundExpander = CollectionInboundExpander;
|
||||
exports.CollectionAnyExpander = CollectionAnyExpander;
|
||||
exports.CollectionDatasourceFactory = CollectionDatasourceFactory;
|
||||
exports.VisitAllFilter = VisitAllFilter;
|
||||
exports.IncludeMatchingAttributesFilter = IncludeMatchingAttributesFilter;
|
||||
exports.TrackingVisitor = TrackingVisitor;
|
||||
|
|
|
@ -115,7 +115,7 @@ function GraphTreeTraversalSuite () {
|
|||
vertices: vertices,
|
||||
|
||||
getAllEdges: function (vertexId) {
|
||||
return this.inEdges[vertexId].concat(outEdges[vertex_id]);
|
||||
return this.inEdges[vertexId].concat(outEdges[vertexId]);
|
||||
},
|
||||
|
||||
getInEdges: function (vertexId) {
|
||||
|
@ -1421,7 +1421,7 @@ function CollectionTraversalSuite () {
|
|||
testOutboundExpander : function () {
|
||||
var config = {
|
||||
sort: function (l, r) { return l._key < r._key ? -1 : 1 },
|
||||
edgeCollection: edgeCollection
|
||||
datasource: traversal.CollectionDatasourceFactory(edgeCollection)
|
||||
};
|
||||
|
||||
var expander = traversal.CollectionOutboundExpander;
|
||||
|
@ -1456,7 +1456,7 @@ function CollectionTraversalSuite () {
|
|||
testInboundExpander : function () {
|
||||
var config = {
|
||||
sort: function (l, r) { return l._key < r._key ? -1 : 1 },
|
||||
edgeCollection: edgeCollection
|
||||
datasource: traversal.CollectionDatasourceFactory(edgeCollection)
|
||||
};
|
||||
|
||||
var expander = traversal.CollectionInboundExpander;
|
||||
|
@ -1490,7 +1490,7 @@ function CollectionTraversalSuite () {
|
|||
|
||||
testIterateFullOutbound : function () {
|
||||
var config = {
|
||||
edgeCollection: internal.db._collection(en),
|
||||
datasource: traversal.CollectionDatasourceFactory(internal.db._collection(en)),
|
||||
strategy: traversal.Traverser.DEPTH_FIRST,
|
||||
order: traversal.Traverser.PRE_ORDER,
|
||||
itemOrder: traversal.Traverser.FORWARD,
|
||||
|
@ -1529,7 +1529,7 @@ function CollectionTraversalSuite () {
|
|||
|
||||
testIterateInbound : function () {
|
||||
var config = {
|
||||
edgeCollection: internal.db._collection(en),
|
||||
datasource: traversal.CollectionDatasourceFactory(internal.db._collection(en)),
|
||||
strategy: traversal.Traverser.DEPTH_FIRST,
|
||||
order: traversal.Traverser.PRE_ORDER,
|
||||
itemOrder: traversal.Traverser.FORWARD,
|
||||
|
@ -1561,7 +1561,7 @@ function CollectionTraversalSuite () {
|
|||
|
||||
testIterateUniqueGlobalVertices : function () {
|
||||
var config = {
|
||||
edgeCollection: internal.db._collection(en),
|
||||
datasource: traversal.CollectionDatasourceFactory(internal.db._collection(en)),
|
||||
strategy: traversal.Traverser.DEPTH_FIRST,
|
||||
order: traversal.Traverser.PRE_ORDER,
|
||||
itemOrder: traversal.Traverser.FORWARD,
|
||||
|
@ -1600,7 +1600,7 @@ function CollectionTraversalSuite () {
|
|||
|
||||
testIterateUniquePathVertices : function () {
|
||||
var config = {
|
||||
edgeCollection: internal.db._collection(en),
|
||||
datasource: traversal.CollectionDatasourceFactory(internal.db._collection(en)),
|
||||
strategy: traversal.Traverser.DEPTH_FIRST,
|
||||
order: traversal.Traverser.PRE_ORDER,
|
||||
itemOrder: traversal.Traverser.FORWARD,
|
||||
|
@ -1643,7 +1643,7 @@ function CollectionTraversalSuite () {
|
|||
|
||||
testIterateUniqueEdges : function () {
|
||||
var config = {
|
||||
edgeCollection: internal.db._collection(en),
|
||||
datasource: traversal.CollectionDatasourceFactory(internal.db._collection(en)),
|
||||
strategy: traversal.Traverser.DEPTH_FIRST,
|
||||
order: traversal.Traverser.PRE_ORDER,
|
||||
itemOrder: traversal.Traverser.FORWARD,
|
||||
|
|
|
@ -2348,7 +2348,7 @@ function AHUACATL_GRAPH_TRAVERSE () {
|
|||
}
|
||||
|
||||
var config = {
|
||||
edgeCollection: edgeCollection,
|
||||
datasource: traversal.CollectionDatasourceFactory(edgeCollection),
|
||||
strategy: validate(params.strategy, {
|
||||
'depthfirst': traversal.Traverser.DEPTH_FIRST,
|
||||
'breadthfirst': traversal.Traverser.BREADTH_FIRST
|
||||
|
|
Loading…
Reference in New Issue