1
0
Fork 0

fixed edges

This commit is contained in:
Frank Celler 2012-04-12 17:11:56 +02:00
parent a831ba82f3
commit c50c758c0e
19 changed files with 572 additions and 135 deletions

View File

@ -0,0 +1,8 @@
avocado> v1 = db.vertex.save({ name : "vertex 1" });
{ "_id" : "86294/1528086", "_rev" : 1528086 }
avocado> v2 = db.vertex.save({ name : "vertex 2" });
{ "_id" : "86294/1593622", "_rev" : 1593622 }
avocado> e1 = edges.relation.save(v1, v2, { label : "knows" });
{ "_id" : "1659158/3100950", "_rev" : 3100950 }
avocado> edges._document(e1);
{ "_id" : "1659158/3100950", "_rev" : 3100950, "_from" : "86294/1528086", "_to" : "86294/1593622", "label" : "knows" }

View File

@ -0,0 +1,2 @@
avocado> edges.relation.edges("86294/1593622");
[{ "_id" : "1659158/3100950", "_rev" : 3100950, "_from" : "86294/1528086", "_to" : "86294/1593622", "label" : "knows" }]

View File

@ -0,0 +1,4 @@
avocado> edges.relation.inEdges("86294/1528086");
[ ]
avocado> edges.relation.inEdges("86294/1593622");
[{ "_id" : "1659158/3100950", "_rev" : 3100950, "_from" : "86294/1528086", "_to" : "86294/1593622", "label" : "knows" }]

View File

@ -0,0 +1,4 @@
avocado> edges.relation.outEdges("86294/1528086");
[{ "_id" : "1659158/3100950", "_rev" : 3100950, "_from" : "86294/1528086", "_to" : "86294/1593622", "label" : "knows" }]
avocado> edges.relation.outEdges("86294/1593622");
[ ]

View File

@ -339,6 +339,7 @@ WIKI = \
RestSystem \
ShellCollection \
ShellDocument \
ShellEdge \
SimpleQueries \
UserManualServer \
UserManualShell \

View File

@ -888,6 +888,7 @@ WIKI = \
RestSystem \
ShellCollection \
ShellDocument \
ShellEdge \
SimpleQueries \
UserManualServer \
UserManualShell \

View File

@ -42,6 +42,8 @@
///
/// @copydoc GlossaryDocumentRevision
///
/// @copydoc GlossaryEdge
///
/// @copydoc GlossaryIndex
///
/// @copydoc GlossaryIndexGeo
@ -112,11 +114,18 @@
/// @page GlossaryEdge
//////////////////////
///
/// @GE{Edges}: Edges in AvocadoDB are special documents. In addition to the
/// @GE{Edge}: Edges in AvocadoDB are special documents. In addition to the
/// internal attributes @LIT{_id} and @LIT{_rev}, they have two attributes
/// @LIT{_form} and @LIT{_to}, which contain document handles namely the
/// start-point and the end-point of the edge.
///
/// @page GlossaryEdgeCollection
////////////////////////////////
///
/// @GE{Edge Collection}: Edge collections are special collection where
/// edge documents live. Instead of using @LIT{db}, one must use @LIT{edges}
/// to access the edge collection.
///
/// @page GlossaryIndex
///////////////////////
///

View File

@ -56,6 +56,7 @@
/// <li>Shell Commands
/// <ol>
/// <li>@ref ShellDocument</li>
/// <li>@ref ShellEdge</li>
/// <li>@ref ShellCollection</li>
/// </ol>
/// </li>

View File

@ -41,11 +41,11 @@
/// @page RestEdgeCallsTOC
///
/// <ol>
/// <li>@ref RestEdgeRead "GET /document/document-handle"</li>
/// <li>@ref RestEdgeRead "GET /edge/document-handle"</li>
/// <li>@ref RestEdgeCreate "POST /edge?collection=collection-identifier&from=from-handle&to=to-handle"</li>
/// <li>@ref RestEdgeUpdate "PUT /document/document-handle"</li>
/// <li>@ref RestEdgeDelete "DELETE /document/document-handle"</li>
/// <li>@ref RestEdgeHead "HEAD /document/document-handle"</li>
/// <li>@ref RestEdgeUpdate "PUT /edge/document-handle"</li>
/// <li>@ref RestEdgeDelete "DELETE /edge/document-handle"</li>
/// <li>@ref RestEdgeHead "HEAD /edge/document-handle"</li>
/// </ol>
////////////////////////////////////////////////////////////////////////////////

View File

@ -54,12 +54,12 @@
/// </li>
/// <li>Database Methods
/// <ol>
/// <li>@ref ShellCollectionRead "db._collection(collection-identifier)"</li>
/// <li>@ref ShellCollectionCreate "db._create(collection-name, properties)"</li>
/// <li>@ref ShellCollectionRead "db._collection(collection-identifier)"</li>
/// <li>@ref ShellCollectionReadAll "db._collections()"</li>
/// <li>@ref ShellCollectionReadShortCut "db.collection-name"</li>
/// <li>@ref ShellCollectionDropDb "db._drop(collection)"</li>
/// <li>@ref ShellCollectionTruncateDb "db._truncate(collection)"</li>
/// <li>@ref ShellCollectionReadShortCut "db.collection-name"</li>
/// </ol>
/// </li>
/// </ol>
@ -150,20 +150,16 @@
/// @copydetails JS_RenameVocbaseCol
/// <hr>
///
/// @anchor ShellCollectionRead
/// @copydetails JS_CollectionVocBase
/// <hr>
///
/// @anchor ShellCollectionCreate
/// @copydetails JS_CreateVocBase
/// <hr>
///
/// @anchor ShellCollectionReadAll
/// @copydetails JS_CollectionsVocBase
/// @anchor ShellCollectionRead
/// @copydetails JS_CollectionVocBase
/// <hr>
///
/// @anchor ShellCollectionReadShortCut
/// @copydetails MapGetVocBase
/// @anchor ShellCollectionReadAll
/// @copydetails JS_CollectionsVocBase
/// <hr>
///
/// @anchor ShellCollectionDropDb
@ -174,6 +170,8 @@
/// @copydetails JSF_AvocadoDatabase_prototype__truncate
/// <hr>
///
/// @anchor ShellCollectionReadShortCut
/// @copydetails MapGetVocBase
////////////////////////////////////////////////////////////////////////////////
// Local Variables:

91
RestServer/shell-edge.dox Normal file
View File

@ -0,0 +1,91 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief avocado shell
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2012 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 Dr. Frank Celler
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @page ShellEdgeTOC
///
/// <ol>
/// <li>@ref ShellEdgeIntro</li>
/// <li>@ref ShellEdgeShell
/// @copydetails ShellEdgeCallsTOC
/// </li>
/// </ol>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @page ShellEdgeCallsTOC
///
/// <ol>
/// <li>@ref ShellEdgeCreate "edge-collection.save(from-handle, to-handle, data)"</li>
/// <li>@ref ShellEdgeEdges "edge-collection.edges(vertex-handle)"</li>
/// <li>@ref ShellEdgeInEdges "edge-collection.inEdges(vertex-handle)"</li>
/// <li>@ref ShellEdgeOutEdges "edge-collection.outEdges(vertex-handle)"</li>
/// </ol>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @page ShellEdge AvocadoDB Interface for Edges
///
/// This is an introduction to AvocadoDB's interface for edges.
///
/// <hr>
/// @copydoc ShellEdgeTOC
/// <hr>
///
/// @section ShellEdgeIntro Edges, Identifiers, Handles
///////////////////////////////////////////////////////
///
/// @copydoc GlossaryEdge
///
/// @copydoc GlossaryEdgeCollection
///
/// @section ShellEdgeShell Working with Edges
//////////////////////////////////////////////
///
/// @anchor ShellEdgeCreate
/// @copydetails JS_SaveEdgesCol
/// <hr>
///
/// @anchor ShellEdgeEdges
/// @copydetails JS_EdgesQuery
/// <hr>
///
/// @anchor ShellEdgeInEdges
/// @copydetails JS_InEdgesQuery
/// <hr>
///
/// @anchor ShellEdgeOutEdges
/// @copydetails JS_OutEdgesQuery
/// <hr>
///
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: c++
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)"
// End:

View File

@ -84,7 +84,6 @@
/////////////////////////////////////////
///
/// @anchor SimpleQueryDocument
/// @copydetails JS_DocumentQuery
/// <hr>
///
/// @anchor SimpleQueryAll

View File

@ -238,7 +238,7 @@
///
/// @subsection DBAdminDurability3 Configuration
///
/// @copydetails JS_ParameterVocbaseCol
/// @copydetails JS_PropertiesVocbaseCol
///
/// @section DBAdminIndex Index Management
///

View File

@ -884,6 +884,115 @@ static v8::Handle<v8::Value> DeleteVocbaseCol (TRI_vocbase_t* vocbase,
return scope.Close(v8::True());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a new collection
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> CreateVocBase (v8::Arguments const& argv, bool edge) {
v8::HandleScope scope;
TRI_vocbase_t* vocbase = UnwrapClass<TRI_vocbase_t>(argv.Holder(), WRP_VOCBASE_TYPE);
if (vocbase == 0) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_INTERNAL, "corrupted vocbase")));
}
// expecting at least one arguments
if (argv.Length() < 1) {
return scope.Close(v8::ThrowException(
CreateErrorObject(TRI_ERROR_BAD_PARAMETER,
"usage: _create(<name>, <properties>)")));
}
// extract the name
string name = TRI_ObjectToString(argv[0]);
// extract the parameter
TRI_col_parameter_t parameter;
if (2 <= argv.Length()) {
if (! argv[1]->IsObject()) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_BAD_PARAMETER, "<properties> must be an object")));
}
v8::Handle<v8::Object> p = argv[1]->ToObject();
v8::Handle<v8::String> waitForSyncKey = v8::String::New("waitForSync");
v8::Handle<v8::String> journalSizeKey = v8::String::New("journalSize");
if (p->Has(journalSizeKey)) {
double s = TRI_ObjectToDouble(p->Get(journalSizeKey));
if (s < TRI_JOURNAL_MINIMAL_SIZE) {
return scope.Close(v8::ThrowException(
CreateErrorObject(TRI_ERROR_BAD_PARAMETER,
"<properties>.journalSize too small")));
}
TRI_InitParameterCollection(&parameter, name.c_str(), (TRI_voc_size_t) s);
}
else {
TRI_InitParameterCollection(&parameter, name.c_str(), vocbase->_defaultMaximalSize);
}
if (p->Has(waitForSyncKey)) {
parameter._waitForSync = TRI_ObjectToBoolean(p->Get(waitForSyncKey));
}
}
else {
TRI_InitParameterCollection(&parameter, name.c_str(), vocbase->_defaultMaximalSize);
}
TRI_vocbase_col_t const* collection = TRI_CreateCollectionVocBase(vocbase, &parameter);
if (collection == NULL) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_errno(), "cannot create collection")));
}
return scope.Close(edge ? TRI_WrapEdgesCollection(collection) : TRI_WrapCollection(collection));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a single collection or null
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> CollectionVocBase (v8::Arguments const& argv, bool edge) {
v8::HandleScope scope;
TRI_vocbase_t* vocbase = UnwrapClass<TRI_vocbase_t>(argv.Holder(), WRP_VOCBASE_TYPE);
if (vocbase == 0) {
return scope.Close(v8::ThrowException(v8::String::New("corrupted vocbase")));
}
// expecting one argument
if (argv.Length() != 1) {
return scope.Close(v8::ThrowException(v8::String::New("usage: _collection(<name>|<identifier>)")));
}
v8::Handle<v8::Value> val = argv[0];
TRI_vocbase_col_t const* collection = 0;
// number
if (val->IsNumber() || val->IsNumberObject()) {
uint64_t id = (uint64_t) TRI_ObjectToDouble(val);
collection = TRI_LookupCollectionByIdVocBase(vocbase, id);
}
else {
string name = TRI_ObjectToString(val);
collection = TRI_FindCollectionByNameVocBase(vocbase, name.c_str(), false);
}
if (collection == 0) {
return scope.Close(v8::Null());
}
return scope.Close(edge ? TRI_WrapEdgesCollection(collection) : TRI_WrapCollection(collection));
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -1536,7 +1645,7 @@ static v8::Handle<v8::Value> JS_AllQuery (v8::Arguments const& argv) {
///
/// @EXAMPLES
///
/// @verbinclude simple11
/// @verbinclude shell_edge-edges
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_EdgesQuery (v8::Arguments const& argv) {
@ -1553,7 +1662,7 @@ static v8::Handle<v8::Value> JS_EdgesQuery (v8::Arguments const& argv) {
///
/// @EXAMPLES
///
/// @verbinclude simple11
/// @verbinclude shell_edge-in-edges
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_InEdgesQuery (v8::Arguments const& argv) {
@ -1655,7 +1764,7 @@ static v8::Handle<v8::Value> JS_NearQuery (v8::Arguments const& argv) {
///
/// @EXAMPLES
///
/// @verbinclude simple13
/// @verbinclude shell_edge-out-edges
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_OutEdgesQuery (v8::Arguments const& argv) {
@ -4772,7 +4881,7 @@ static v8::Handle<v8::Value> JS_UnloadVocbaseCol (v8::Arguments const& argv) {
/// Saves a new edge and returns the document-handle. @FA{from} and @FA{to}
/// must be documents or document references.
///
/// @verbinclude fluent22
/// @verbinclude shell_create-edge
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_SaveEdgesCol (v8::Arguments const& argv) {
@ -4995,39 +5104,7 @@ static v8::Handle<v8::Value> MapGetVocBase (v8::Local<v8::String> name,
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_CollectionVocBase (v8::Arguments const& argv) {
v8::HandleScope scope;
TRI_vocbase_t* vocbase = UnwrapClass<TRI_vocbase_t>(argv.Holder(), WRP_VOCBASE_TYPE);
if (vocbase == 0) {
return scope.Close(v8::ThrowException(v8::String::New("corrupted vocbase")));
}
// expecting one argument
if (argv.Length() != 1) {
return scope.Close(v8::ThrowException(v8::String::New("usage: _collection(<name>|<identifier>)")));
}
v8::Handle<v8::Value> val = argv[0];
TRI_vocbase_col_t const* collection = 0;
// number
if (val->IsNumber() || val->IsNumberObject()) {
uint64_t id = (uint64_t) TRI_ObjectToDouble(val);
collection = TRI_LookupCollectionByIdVocBase(vocbase, id);
}
else {
string name = TRI_ObjectToString(val);
collection = TRI_FindCollectionByNameVocBase(vocbase, name.c_str(), false);
}
if (collection == 0) {
return scope.Close(v8::Null());
}
return scope.Close(TRI_WrapCollection(collection));
return CollectionVocBase(argv, false);
}
////////////////////////////////////////////////////////////////////////////////
@ -5128,68 +5205,7 @@ static v8::Handle<v8::Value> JS_CompletionsVocBase (v8::Arguments const& argv) {
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_CreateVocBase (v8::Arguments const& argv) {
v8::HandleScope scope;
TRI_vocbase_t* vocbase = UnwrapClass<TRI_vocbase_t>(argv.Holder(), WRP_VOCBASE_TYPE);
if (vocbase == 0) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_INTERNAL, "corrupted vocbase")));
}
// expecting at least one arguments
if (argv.Length() < 1) {
return scope.Close(v8::ThrowException(
CreateErrorObject(TRI_ERROR_BAD_PARAMETER,
"usage: _create(<name>, <properties>)")));
}
// extract the name
string name = TRI_ObjectToString(argv[0]);
// extract the parameter
TRI_col_parameter_t parameter;
if (2 <= argv.Length()) {
if (! argv[1]->IsObject()) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_BAD_PARAMETER, "<properties> must be an object")));
}
v8::Handle<v8::Object> p = argv[1]->ToObject();
v8::Handle<v8::String> waitForSyncKey = v8::String::New("waitForSync");
v8::Handle<v8::String> journalSizeKey = v8::String::New("journalSize");
if (p->Has(journalSizeKey)) {
double s = TRI_ObjectToDouble(p->Get(journalSizeKey));
if (s < TRI_JOURNAL_MINIMAL_SIZE) {
return scope.Close(v8::ThrowException(
CreateErrorObject(TRI_ERROR_BAD_PARAMETER,
"<properties>.journalSize too small")));
}
TRI_InitParameterCollection(&parameter, name.c_str(), (TRI_voc_size_t) s);
}
else {
TRI_InitParameterCollection(&parameter, name.c_str(), vocbase->_defaultMaximalSize);
}
if (p->Has(waitForSyncKey)) {
parameter._waitForSync = TRI_ObjectToBoolean(p->Get(waitForSyncKey));
}
}
else {
TRI_InitParameterCollection(&parameter, name.c_str(), vocbase->_defaultMaximalSize);
}
TRI_vocbase_col_t const* collection = TRI_CreateCollectionVocBase(vocbase, &parameter);
if (collection == NULL) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_errno(), "cannot create collection")));
}
return scope.Close(TRI_WrapCollection(collection));
return CreateVocBase(argv, false);
}
////////////////////////////////////////////////////////////////////////////////
@ -5383,6 +5399,24 @@ static v8::Handle<v8::Value> MapGetEdges (v8::Local<v8::String> name,
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a single collection or null
///
/// @FUN{edges._collection(@FA{collection-identifier})}
///
/// Returns the collection with the given identifier or null if no such
/// collection exists.
///
/// @FUN{edges._collection(@FA{collection-name})}
///
/// Returns the collection with the given name or null if no such collection
/// exists.
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_CollectionEdges (v8::Arguments const& argv) {
return CollectionVocBase(argv, true);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns all collections
////////////////////////////////////////////////////////////////////////////////
@ -5412,6 +5446,32 @@ static v8::Handle<v8::Value> JS_CollectionsEdges (v8::Arguments const& argv) {
return scope.Close(result);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a new edge collection
///
/// @FUN{edges._create(@FA{collection-name})}
///
/// Creates a new collection named @FA{collection-name}. If the collection name
/// already exists, than an error is thrown. The default value for
/// @LIT{waitForSync} is @LIT{false}.
///
/// @FUN{edges._create(@FA{collection-name}, @FA{properties})}
///
/// @FA{properties} must be an object, with the following attribues:
///
/// - @LIT{waitForSync} (optional, default @LIT{false}): If @LIT{true} creating
/// a document will only return after the data was synced to disk.
///
/// - @LIT{journalSize} (optional, default is a @ref CommandLineAvocado
/// "configuration parameter"): The maximal size of
/// a journal or datafile. Note that this also limits the maximal
/// size of a single object. Must be at least 1MB.
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_CreateEdges (v8::Arguments const& argv) {
return CreateVocBase(argv, true);
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -5989,10 +6049,10 @@ void TRI_InitV8VocBridge (v8::Handle<v8::Context> context, TRI_vocbase_t* vocbas
rt->SetNamedPropertyHandler(MapGetEdges);
rt->Set(_CollectionFuncName, v8::FunctionTemplate::New(JS_CollectionVocBase));
rt->Set(_CollectionFuncName, v8::FunctionTemplate::New(JS_CollectionEdges));
rt->Set(_CollectionsFuncName, v8::FunctionTemplate::New(JS_CollectionsEdges));
rt->Set(_CompletionsFuncName, v8::FunctionTemplate::New(JS_CompletionsVocBase));
rt->Set(_CreateFuncName, v8::FunctionTemplate::New(JS_CreateVocBase));
rt->Set(_CreateFuncName, v8::FunctionTemplate::New(JS_CreateEdges));
rt->Set(_DeleteFuncName, v8::FunctionTemplate::New(JS_DeleteVocbase));
rt->Set(_DocumentFuncName, v8::FunctionTemplate::New(JS_DocumentVocbase));

View File

@ -149,7 +149,6 @@
/// @subsection JSFQueryBuilding Query Building Functions
///
/// - @ref JS_AllQuery "all"
/// - @ref JS_DocumentQuery "document"
/// - ref JS_SelectQuery "select"
///
/// @section JSFGlobal Global Functions
@ -174,8 +173,6 @@
///
/// @section JSFDatabases Database Functions
///
/// @copydetails JS_ParameterVocbaseCol
///
/// @subsection JSFDocument Database Document Functions
///
/// @copydetails JS_DeleteVocbaseCol
@ -205,8 +202,6 @@
/// A complete list of the available query building functions can be found @ref
/// SimpleQueries "here".
///
/// @copydetails JS_DocumentQuery
///
/// @subsection JSFQueryExecuting Query Execution Functions
///
/// @section JSFGlobal Global Functions

View File

@ -36,8 +36,9 @@ var jsunity = require("jsunity");
////////////////////////////////////////////////////////////////////////////////
function collectionDocumentSuiteErrorHandling () {
var cn = "UnitTestsCollectionBasics";
var ERRORS = require("internal").errors;
var cn = "UnitTestsCollectionBasics";
var collection = null;
return {
@ -163,9 +164,10 @@ function collectionDocumentSuiteErrorHandling () {
/// @brief test suite: normal operations
////////////////////////////////////////////////////////////////////////////////
function collectionDocumentSuiteReadDocument () {
var cn = "UnitTestsCollectionBasics";
function collectionDocumentSuite () {
var ERRORS = require("internal").errors;
var cn = "UnitTestsCollectionBasics";
var collection = null;
return {
@ -351,7 +353,7 @@ function collectionDocumentSuiteReadDocument () {
/// @brief test suite: error handling
////////////////////////////////////////////////////////////////////////////////
function documentSuiteErrorHandling () {
function databaseDocumentSuiteErrorHandling () {
var cn = "UnitTestsCollectionBasics";
var ERRORS = require("internal").errors;
@ -423,7 +425,7 @@ function documentSuiteErrorHandling () {
/// @brief test suite: normal operations
////////////////////////////////////////////////////////////////////////////////
function documentSuiteReadDocument () {
function databaseDocumentSuite () {
var cn = "UnitTestsCollectionBasics";
var ERRORS = require("internal").errors;
var collection = null;
@ -601,10 +603,10 @@ function documentSuiteReadDocument () {
////////////////////////////////////////////////////////////////////////////////
jsunity.run(collectionDocumentSuiteErrorHandling);
jsunity.run(collectionDocumentSuiteReadDocument);
jsunity.run(collectionDocumentSuite);
jsunity.run(documentSuiteErrorHandling);
jsunity.run(documentSuiteReadDocument);
jsunity.run(databaseDocumentSuiteErrorHandling);
jsunity.run(databaseDocumentSuite);
return jsunity.done();

View File

@ -0,0 +1,262 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief test the document interface
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 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 Dr. Frank Celler
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var jsunity = require("jsunity");
// -----------------------------------------------------------------------------
// --SECTION-- collection methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite: error handling
////////////////////////////////////////////////////////////////////////////////
function collectionEdgeSuiteErrorHandling () {
var ERRORS = require("internal").errors;
var vn = "UnitTestsCollectionVertex";
var vertex = null;
var en = "UnitTestsCollectionEdge";
var edge = null;
var v1 = null;
var v2 = null;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
edges._drop(en);
edge = edges._create(en, { waitForSync : false });
db._drop(vn);
vertex = db._create(vn, { waitForSync : false });
v1 = vertex.save({ a : 1 });
v2 = vertex.save({ a : 2 });
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
edge.drop();
vertex.drop();
},
////////////////////////////////////////////////////////////////////////////////
/// @brief bad handle
////////////////////////////////////////////////////////////////////////////////
testErrorHandlingBadHandle : function () {
try {
edge.save("123456", v1, {});
fail();
}
catch (err) {
assertEqual(ERRORS.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code, err.errorNum);
}
try {
edge.save(v1, "123456", {});
fail();
}
catch (err) {
assertEqual(ERRORS.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code, err.errorNum);
}
},
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite: normal operations
////////////////////////////////////////////////////////////////////////////////
function collectionEdgeSuite () {
var ERRORS = require("internal").errors;
var vn = "UnitTestsCollectionVertex";
var vertex = null;
var en = "UnitTestsCollectionEdge";
var edge = null;
var v1 = null;
var v2 = null;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
edges._drop(en);
edge = edges._create(en, { waitForSync : false });
db._drop(vn);
vertex = db._create(vn, { waitForSync : false });
v1 = vertex.save({ a : 1 });
v2 = vertex.save({ a : 2 });
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
edge.drop();
vertex.drop();
},
////////////////////////////////////////////////////////////////////////////////
/// @brief create an edge
////////////////////////////////////////////////////////////////////////////////
testSaveEdge : function () {
var doc = edge.save(v1, v2, { "Hallo" : "World" });
assertTypeOf("string", doc._id);
assertTypeOf("number", doc._rev);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief read an edge
////////////////////////////////////////////////////////////////////////////////
testReadEdge : function () {
var d = edge.save(v1, v2, { "Hallo" : "World" });
var doc = edge.document(d._id);
assertEqual(d._id, doc._id);
assertEqual(d._rev, doc._rev);
assertEqual(v1._id, doc._from);
assertEqual(v2._id, doc._to);
doc = edge.document(d);
assertEqual(d._id, doc._id);
assertEqual(d._rev, doc._rev);
assertEqual(v1._id, doc._from);
assertEqual(v2._id, doc._to);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief edges query
////////////////////////////////////////////////////////////////////////////////
testReadEdges : function () {
var d1 = edge.save(v1, v2, { "Hallo" : "World" });
var d2 = edge.save(v2, v1, { "World" : "Hallo" });
var e = edge.edges(v1);
assertEqual(2, e.length);
if (e[0]._id == d1._id) {
assertEqual(v2._id, e[0]._to);
assertEqual(v1._id, e[0]._from);
assertEqual(d2._id, e[1]._id);
assertEqual(v1._id, e[1]._to);
assertEqual(v2._id, e[1]._from);
}
else {
assertEqual(v1._id, e[0]._to);
assertEqual(v2._id, e[0]._from);
assertEqual(d1._id, e[1]._id);
assertEqual(v2._id, e[1]._to);
assertEqual(v1._id, e[1]._from);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief in edges query
////////////////////////////////////////////////////////////////////////////////
testReadInEdges : function () {
var d = edge.save(v1, v2, { "Hallo" : "World" });
var e = edge.inEdges(v2);
assertEqual(1, e.length);
assertEqual(d._id, e[0]._id);
assertEqual(v2._id, e[0]._to);
assertEqual(v1._id, e[0]._from);
var f = edge.inEdges(v1);
assertEqual(0, f.length);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief out edges query
////////////////////////////////////////////////////////////////////////////////
testReadOutEdges : function () {
var d = edge.save(v1, v2, { "Hallo" : "World" });
var e = edge.outEdges(v1);
assertEqual(1, e.length);
assertEqual(d._id, e[0]._id);
assertEqual(v2._id, e[0]._to);
assertEqual(v1._id, e[0]._from);
var f = edge.outEdges(v2);
assertEqual(0, f.length);
},
};
}
// -----------------------------------------------------------------------------
// --SECTION-- main
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suites
////////////////////////////////////////////////////////////////////////////////
jsunity.run(collectionEdgeSuiteErrorHandling);
jsunity.run(collectionEdgeSuite);
return jsunity.done();
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// End:

View File

@ -183,7 +183,7 @@ static string JS_server_server =
" return collection.drop()\n"
"};\n"
"\n"
"AvocadoEdges.prototype._drop = AvocadoDatabase._drop;\n"
"AvocadoEdges.prototype._drop = AvocadoDatabase.prototype._drop;\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief truncates a collection\n"
@ -226,7 +226,7 @@ static string JS_server_server =
" }\n"
"};\n"
"\n"
"AvocadoEdges.prototype._truncate = AvocadoDatabase._truncate;\n"
"AvocadoEdges.prototype._truncate = AvocadoDatabase.prototype._truncate;\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief prints a database\n"

View File

@ -182,7 +182,7 @@ AvocadoDatabase.prototype._drop = function(name) {
return collection.drop()
};
AvocadoEdges.prototype._drop = AvocadoDatabase._drop;
AvocadoEdges.prototype._drop = AvocadoDatabase.prototype._drop;
////////////////////////////////////////////////////////////////////////////////
/// @brief truncates a collection
@ -225,7 +225,7 @@ AvocadoDatabase.prototype._truncate = function(name) {
}
};
AvocadoEdges.prototype._truncate = AvocadoDatabase._truncate;
AvocadoEdges.prototype._truncate = AvocadoDatabase.prototype._truncate;
////////////////////////////////////////////////////////////////////////////////
/// @brief prints a database