1
0
Fork 0

velocypack update

This commit is contained in:
Jan Steemann 2015-11-19 13:28:40 +01:00
parent a6b898c34a
commit 89e0f887b9
33 changed files with 523 additions and 110 deletions

View File

@ -306,6 +306,9 @@ namespace arangodb {
// whether or not a specific key is present in an Object value
bool hasKey (std::string const& key) const;
// return an attribute from an Object value
Slice getKey (std::string const& key) const;
// Syntactic sugar for add:
Builder& operator() (std::string const& attrName, Value sub) {
add(attrName, sub);
@ -448,7 +451,7 @@ namespace arangodb {
// check if a translation for the attribute name exists
uint8_t const* translated = options->attributeTranslator->translate(attrName);
if (translated != nullptr) {
set(Slice(options->attributeTranslator->translate(attrName)));
set(Slice(options->attributeTranslator->translate(attrName), options));
return set(sub);
}
// otherwise fall through to regular behavior

View File

@ -36,12 +36,24 @@ namespace arangodb {
struct Version {
Version () = delete;
Version (Version const&) = delete;
Version& operator = (Version const&) = delete;
static std::string toString ();
Version (int majorValue, int minorValue, int patchValue)
: majorValue(majorValue), minorValue(minorValue), patchValue(patchValue) {
}
static int const major;
static int const minor;
static int const patch;
std::string toString () const;
int compare (Version const& other) const;
static int compare (Version const& lhs, Version const& rhs);
int const majorValue;
int const minorValue;
int const patchValue;
static Version const BuildVersion;
};
} // namespace arangodb::velocypack

View File

@ -24,32 +24,129 @@
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef VELOCYPACK_ALIASES_H
#define VELOCYPACK_ALIASES_H 1
#include "velocypack/velocypack-common.h"
#include "velocypack/vpack.h"
using VPackArrayIterator = arangodb::velocypack::ArrayIterator;
using VPackAttributeExcludeHandler = arangodb::velocypack::AttributeExcludeHandler;
using VPackAttributeTranslator = arangodb::velocypack::AttributeTranslator;
using VPackBuilder = arangodb::velocypack::Builder;
using VPackCharBuffer = arangodb::velocypack::CharBuffer;
using VPackCharBufferSink = arangodb::velocypack::CharBufferSink;
using VPackCollection = arangodb::velocypack::Collection;
using VPackCustomTypeHandler = arangodb::velocypack::CustomTypeHandler;
using VPackDumper = arangodb::velocypack::Dumper;
using VPackException = arangodb::velocypack::Exception;
using VPackHexDump = arangodb::velocypack::HexDump;
using VPackObjectIterator = arangodb::velocypack::ObjectIterator;
using VPackOptions = arangodb::velocypack::Options;
using VPackParser = arangodb::velocypack::Parser;
using VPackSink = arangodb::velocypack::Sink;
using VPackSlice = arangodb::velocypack::Slice;
using VPackStringSink = arangodb::velocypack::StringSink;
using VPackStringStreamSink = arangodb::velocypack::StringStreamSink;
using VPackValue = arangodb::velocypack::Value;
using VPackValueLength = arangodb::velocypack::ValueLength;
using VPackValueType = arangodb::velocypack::ValueType;
using VPackVersion = arangodb::velocypack::Version;
// this header can be included multiple times
namespace {
// unconditional typedefs
#ifndef VELOCYPACK_ALIAS_VPACKVALUELENGTH
#define VELOCYPACK_ALIAS_VPACKVALUELENGTH
using VPackValueLength = arangodb::velocypack::ValueLength;
#endif
// conditional typedefs, only used when the respective headers are already included
#ifdef VELOCYPACK_ITERATOR_H
#ifndef VELOCYPACK_ALIAS_ITERATOR
#define VELOCYPACK_ALIAS_ITERATOR
using VPackArrayIterator = arangodb::velocypack::ArrayIterator;
using VPackObjectIterator = arangodb::velocypack::ObjectIterator;
#endif
#endif
#ifdef VELOCYPACK_BUILDER_H
#ifndef VELOCYPACK_ALIAS_BUILDER
#define VELOCYPACK_ALIAS_BUILDER
using VPackBuilder = arangodb::velocypack::Builder;
#endif
#endif
#ifdef VELOCYPACK_BUFFER_H
#ifndef VELOCYPACK_ALIAS_BUFFER
#define VELOCYPACK_ALIAS_BUFFER
using VPackCharBuffer = arangodb::velocypack::CharBuffer;
#endif
#endif
#ifdef VELOCYPACK_SINK_H
#ifndef VELOCYPACK_ALIAS_SINK
#define VELOCYPACK_ALIAS_SINK
using VPackSink = arangodb::velocypack::Sink;
using VPackCharBufferSink = arangodb::velocypack::CharBufferSink;
using VPackStringSink = arangodb::velocypack::StringSink;
using VPackStringStreamSink = arangodb::velocypack::StringStreamSink;
#endif
#endif
#ifdef VELOCYPACK_COLLECTION_H
#ifndef VELOCYPACK_ALIAS_COLLECTION
#define VELOCYPACK_ALIAS_COLLECTION
using VPackCollection = arangodb::velocypack::Collection;
#endif
#endif
#ifdef VELOCYPACK_ATTRIBUTETRANSLATOR_H
#ifndef VELOCYPACK_ALIAS_ATTRIBUTETRANSLATOR
#define VELOCYPACK_ALIAS_ATTRIBUTETRANSLATOR
using VPackAttributeTranslator = arangodb::velocypack::AttributeTranslator;
#endif
#endif
#ifdef VELOCYPACK_DUMPER_H
#ifndef VELOCYPACK_ALIAS_DUMPER
#define VELOCYPACK_ALIAS_DUMPER
using VPackDumper = arangodb::velocypack::Dumper;
#endif
#endif
#ifdef VELOCYPACK_EXCEPTION_H
#ifndef VELOCYPACK_ALIAS_EXCEPTION
#define VELOCYPACK_ALIAS_EXCEPTION
using VPackException = arangodb::velocypack::Exception;
#endif
#endif
#ifdef VELOCYPACK_HEXDUMP_H
#ifndef VELOCYPACK_ALIAS_HEXDUMP
#define VELOCYPACK_ALIAS_HEXDUMP
using VPackHexDump = arangodb::velocypack::HexDump;
#endif
#endif
#ifdef VELOCYPACK_OPTIONS_H
#ifndef VELOCYPACK_ALIAS_OPTIONS
#define VELOCYPACK_ALIAS_OPTIONS
using VPackOptions = arangodb::velocypack::Options;
using VPackAttributeExcludeHandler = arangodb::velocypack::AttributeExcludeHandler;
using VPackCustomTypeHandler = arangodb::velocypack::CustomTypeHandler;
#endif
#endif
#ifdef VELOCYPACK_PARSER_H
#ifndef VELOCYPACK_ALIAS_PARSER
#define VELOCYPACK_ALIAS_PARSER
using VPackParser = arangodb::velocypack::Parser;
#endif
#endif
#ifdef VELOCYPACK_SLICE_H
#ifndef VELOCYPACK_ALIAS_SLICE
#define VELOCYPACK_ALIAS_SLICE
using VPackSlice = arangodb::velocypack::Slice;
#endif
#endif
#ifdef VELOCYPACK_VALUE_H
#ifndef VELOCYPACK_ALIAS_VALUE
#define VELOCYPACK_ALIAS_VALUE
using VPackValue = arangodb::velocypack::Value;
using VPackValuePair = arangodb::velocypack::ValuePair;
#endif
#endif
#ifdef VELOCYPACK_VALUETYPE_H
#ifndef VELOCYPACK_ALIAS_VALUETYPE
#define VELOCYPACK_ALIAS_VALUETYPE
using VPackValueType = arangodb::velocypack::ValueType;
#endif
#endif
#ifdef VELOCYPACK_VERSION_H
#ifndef VELOCYPACK_ALIAS_VERSION
#define VELOCYPACK_ALIAS_VERSION
using VPackVersion = arangodb::velocypack::Version;
#endif
#endif
}

View File

@ -155,6 +155,27 @@ namespace arangodb {
return v >= shift2 ? (static_cast<int64_t>(v - shift2) - shift) - 1
: static_cast<int64_t>(v);
}
static inline uint64_t readUInt64 (uint8_t const* start) throw() {
uint64_t value = 0;
uint64_t x = 0;
uint8_t const* end = start + 8;
do {
value += static_cast<uint64_t>(*start++) << x;
x += 8;
}
while (start < end);
return value;
}
static inline void storeUInt64 (uint8_t* start, uint64_t value) throw() {
uint8_t const* end = start + 8;
do {
*start++ = static_cast<uint8_t>(value & 0xff);
value >>= 8;
}
while (start < end);
}
} // namespace arangodb::velocypack
} // namespace arangodb

View File

@ -388,6 +388,28 @@ bool Builder::hasKey (std::string const& key) const {
return false;
}
// return an attribute from an Object value
Slice Builder::getKey (std::string const& key) const {
if (_stack.empty()) {
throw Exception(Exception::BuilderNeedOpenObject);
}
ValueLength const& tos = _stack.back();
if (_start[tos] != 0x0b && _start[tos] != 0x14) {
throw Exception(Exception::BuilderNeedOpenObject);
}
std::vector<ValueLength> const& index = _index[_stack.size() - 1];
if (index.empty()) {
return Slice();
}
for (size_t i = 0; i < index.size(); ++i) {
Slice s(_start + tos + index[i], options);
if (s.isString() && s.isEqualString(key)) {
return s;
}
}
return Slice();
}
uint8_t* Builder::set (Value const& item) {
auto const oldPos = _start + _pos;
auto ctype = item.cType();

View File

@ -30,14 +30,29 @@
#include "velocypack/Version.h"
using namespace arangodb::velocypack;
int const Version::major = 0;
int const Version::minor = 1;
int const Version::patch = 0;
std::string Version::toString () {
Version const Version::BuildVersion(0, 0, 1);
std::string Version::toString () const {
std::stringstream version;
version << major << "." << minor << "." << patch;
version << majorValue << "." << minorValue << "." << patchValue;
return version.str();
}
int Version::compare (Version const& other) const {
if (majorValue != other.majorValue) {
return majorValue < other.majorValue ? -1 : 1;
}
if (minorValue != other.minorValue) {
return minorValue < other.minorValue ? -1 : 1;
}
if (patchValue != other.patchValue) {
return patchValue < other.patchValue ? -1 : 1;
}
return 0;
}
int Version::compare (Version const& lhs, Version const& rhs) {
return lhs.compare(rhs);
}

View File

@ -355,7 +355,7 @@ unittests-boost: UnitTests/basics_suite UnitTests/geo_suite
noinst_PROGRAMS += UnitTests/basics_suite UnitTests/geo_suite
UnitTests_basics_suite_CPPFLAGS = -I@top_srcdir@/arangod -I@top_srcdir@/lib @ICU_CPPFLAGS@ @BOOST_CPPFLAGS@
UnitTests_basics_suite_CPPFLAGS = -I@top_srcdir@/arangod -I@top_srcdir@/lib -I@top_srcdir@/3rdParty/velocypack/include @ICU_CPPFLAGS@ @BOOST_CPPFLAGS@
UnitTests_basics_suite_LDADD = -L@top_builddir@/lib -larango -lboost_unit_test_framework @ICU_LDFLAGS@
UnitTests_basics_suite_DEPENDENCIES = @top_builddir@/lib/libarango.a
@ -385,7 +385,7 @@ UnitTests_basics_suite_SOURCES = \
UnitTests/Basics/StringUtilsTest.cpp \
UnitTests/Basics/AttributeNameParserTest.cpp
UnitTests_geo_suite_CPPFLAGS = -I@top_srcdir@/arangod -I@top_builddir@/lib -I@top_srcdir@/lib @BOOST_CPPFLAGS@
UnitTests_geo_suite_CPPFLAGS = -I@top_srcdir@/arangod -I@top_builddir@/lib -I@top_srcdir@/lib -I@top_srcdir@/3rdParty/velocypack/include @BOOST_CPPFLAGS@
UnitTests_geo_suite_LDADD = -L@top_builddir@/lib -larango -lboost_unit_test_framework
UnitTests_geo_suite_DEPENDENCIES = @top_builddir@/lib/libarango.a

View File

@ -32,6 +32,12 @@
#include "Basics/json-utilities.h"
#include "Basics/Exceptions.h"
#include <velocypack/Builder.h>
#include <velocypack/Iterator.h>
#include <velocypack/Slice.h>
#include <velocypack/Value.h>
#include <velocypack/velocypack-aliases.h>
using namespace triagens::aql;
// -----------------------------------------------------------------------------

View File

@ -33,6 +33,7 @@
#include "Basics/Common.h"
#include "Basics/json.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens {

View File

@ -32,6 +32,8 @@
#include "Basics/Common.h"
#include "Basics/JsonHelper.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens {

View File

@ -42,6 +42,9 @@
#include "VocBase/voc-types.h"
#include "V8Server/ApplicationV8.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
struct TRI_json_t;
struct TRI_vocbase_t;

View File

@ -35,6 +35,7 @@
#include "Basics/Mutex.h"
#include "Basics/ReadWriteLock.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
struct TRI_json_t;

View File

@ -32,6 +32,8 @@
#include "Basics/Common.h"
#include "Basics/json.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens {

View File

@ -31,11 +31,14 @@
#include "Basics/logging.h"
#include "Basics/tri-strings.h"
#include "Basics/StringBufferAdapter.h"
#include "Basics/StringUtils.h"
#include "Basics/VPackStringBufferAdapter.h"
#include "Rest/HttpRequest.h"
#include "Rest/HttpResponse.h"
#include <velocypack/Dumper.h>
#include <velocypack/velocypack-aliases.h>
using namespace std;
using namespace triagens::basics;
using namespace triagens::rest;
@ -113,7 +116,7 @@ void RestBaseHandler::generateResult (HttpResponse::HttpResponseCode code,
_response = createResponse(code);
_response->setContentType("application/json; charset=utf-8");
StringBufferAdapter buffer(_response->body().stringBuffer());
VPackStringBufferAdapter buffer(_response->body().stringBuffer());
VPackDumper dumper(&buffer);
try {
@ -190,7 +193,7 @@ void RestBaseHandler::generateError (HttpResponse::HttpResponseCode code, int er
builder.add("errorNum", VPackValue(errorCode));
builder.close();
VPackSlice slice(builder.start());
StringBufferAdapter buffer(_response->body().stringBuffer());
VPackStringBufferAdapter buffer(_response->body().stringBuffer());
VPackDumper dumper(&buffer);
dumper.dump(slice);
}

View File

@ -31,12 +31,11 @@
#define ARANGODB_ADMIN_REST_BASE_HANDLER_H 1
#include "Basics/Common.h"
#include "HttpServer/HttpHandler.h"
#include "Basics/json.h"
#include "HttpServer/HttpHandler.h"
#include "Rest/HttpResponse.h"
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
// -----------------------------------------------------------------------------
@ -108,8 +107,6 @@ namespace triagens {
virtual void generateResult (rest::HttpResponse::HttpResponseCode,
VPackSlice const& slice);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates a cancel message
////////////////////////////////////////////////////////////////////////////////

View File

@ -39,6 +39,10 @@
#include "Utils/CursorRepository.h"
#include "V8Server/ApplicationV8.h"
#include <velocypack/Iterator.h>
#include <velocypack/Value.h>
#include <velocypack/velocypack-aliases.h>
using namespace triagens::arango;
using namespace triagens::rest;

View File

@ -35,6 +35,10 @@
#include "Aql/QueryResult.h"
#include "RestHandler/RestVocbaseBaseHandler.h"
#include <velocypack/Builder.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
struct TRI_json_t;
// -----------------------------------------------------------------------------

View File

@ -31,13 +31,19 @@
#include "Basics/Exceptions.h"
#include "Basics/json.h"
#include "Basics/MutexLocker.h"
#include "Basics/StringBufferAdapter.h"
#include "Basics/VelocyPackHelper.h"
#include "Basics/VPackStringBufferAdapter.h"
#include "Utils/CollectionExport.h"
#include "Utils/Cursor.h"
#include "Utils/CursorRepository.h"
#include "Wal/LogfileManager.h"
#include <velocypack/Builder.h>
#include <velocypack/Dumper.h>
#include <velocypack/Iterator.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
using namespace triagens::arango;
using namespace triagens::rest;
@ -540,7 +546,7 @@ void RestExportHandler::deleteCursor () {
result.add("code", VPackValue(_response->responseCode()));
result.close();
VPackSlice s = result.slice();
triagens::basics::StringBufferAdapter buffer(_response->body().stringBuffer());
triagens::basics::VPackStringBufferAdapter buffer(_response->body().stringBuffer());
VPackDumper dumper(&buffer);
dumper.dump(s);
}

View File

@ -33,10 +33,15 @@
#include "Basics/Exceptions.h"
#include "Basics/MutexLocker.h"
#include "Basics/ScopeGuard.h"
#include "Basics/StringBufferAdapter.h"
#include "Basics/VelocyPackHelper.h"
#include "Basics/VPackStringBufferAdapter.h"
#include "V8Server/ApplicationV8.h"
#include <velocypack/Builder.h>
#include <velocypack/Dumper.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
using namespace triagens::arango;
using namespace triagens::rest;
@ -359,7 +364,7 @@ void RestSimpleHandler::removeByKeys (VPackSlice const& slice) {
result.close();
VPackSlice s = result.slice();
triagens::basics::StringBufferAdapter buffer(_response->body().stringBuffer());
triagens::basics::VPackStringBufferAdapter buffer(_response->body().stringBuffer());
VPackDumper dumper(&buffer);
dumper.dump(s);
}

View File

@ -39,6 +39,12 @@
#include "VocBase/document-collection.h"
#include "VocBase/VocShaper.h"
#include <velocypack/Builder.h>
#include <velocypack/Exception.h>
#include <velocypack/Parser.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
using namespace std;
using namespace triagens::basics;
using namespace triagens::rest;

View File

@ -27,11 +27,17 @@
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "Storage/Options.h"
#include "Basics/Exceptions.h"
#include "Utils/CollectionNameResolver.h"
#include "VocBase/voc-types.h"
#include <velocypack/Dumper.h>
#include <velocypack/Slice.h>
#include <velocypack/Value.h>
#include <velocypack/velocypack-aliases.h>
using namespace arangodb;
// global options used when converting JSON into a document
@ -65,22 +71,25 @@ struct ExcludeHandlerImpl : public VPackAttributeExcludeHandler {
};
struct CustomTypeHandlerImpl : public VPackCustomTypeHandler {
CustomTypeHandlerImpl (triagens::arango::CollectionNameResolver const* resolver,
TRI_voc_cid_t cid)
: resolver(resolver),
cid(cid) {
CustomTypeHandlerImpl (triagens::arango::CollectionNameResolver const* resolver)
: resolver(resolver) {
}
void toJson (VPackSlice const& value, VPackDumper* dumper, VPackSlice const& base) {
std::cout << "TOJSON. VALUE.HEAD(): " << (int) value.head() << "\n";
if (value.head() == 0xf0) {
std::cout << "0xf0\n";
// _id
if (! base.isObject()) {
std::cout << "NO OBJECT. " << base << "\n";
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "invalid value type");
}
uint64_t cid = arangodb::velocypack::readUInt64(value.start() + 1);
std::cout << "HAVE READ CID: " << cid << "\n";
char buffer[512]; // TODO: check if size is appropriate
size_t len = resolver->getCollectionName(&buffer[0], cid);
buffer[len] = '/';
VPackSlice key = base.get("_key");
VPackSlice key = base.get(TRI_VOC_ATTRIBUTE_KEY);
VPackValueLength keyLength;
char const* p = key.getString(keyLength);
@ -89,41 +98,37 @@ struct CustomTypeHandlerImpl : public VPackCustomTypeHandler {
}
memcpy(&buffer[len + 1], p, keyLength);
dumper->appendString(&buffer[0], len + 1 + keyLength);
return;
}
if (value.head() == 0xf1) {
std::cout << "0xf1\n";
// _rev
uint64_t rev = 0;
uint8_t const* start = value.start() + 1;
uint8_t const* end = start + value.byteSize();
do {
rev <<= 8;
rev += static_cast<uint64_t>(*start++);
}
while (start < end);
dumper->sink()->push_back('"');
dumper->appendUInt(rev);
dumper->appendUInt(arangodb::velocypack::readUInt64(value.start() + 1));
dumper->sink()->push_back('"');
return;
}
if (value.head() == 0xf2) {
std::cout << "0xf2\n";
// _from, _to
// TODO
return;
}
std::cout << "OOPS\n";
throw "unknown type!";
}
VPackValueLength byteSize (VPackSlice const& value) {
if (value.head() == 0xf0) {
// _id. this type uses 1 byte only
return 1;
// _id
return 1 + 8; // 0xf0 + 8 bytes for collection id
}
if (value.head() == 0xf1) {
// _rev
return 8;
return 1 + 8; // 0xf1 + 8 bytes for tick value
}
if (value.head() == 0xf2) {
@ -131,23 +136,25 @@ struct CustomTypeHandlerImpl : public VPackCustomTypeHandler {
// TODO!!
return 1;
}
throw "unknown type!";
}
triagens::arango::CollectionNameResolver const* resolver;
TRI_voc_cid_t cid;
};
StorageOptions::StorageOptions ()
: _translator(new VPackAttributeTranslator),
_excludeHandler(new ExcludeHandlerImpl) {
// these attribute names will be translated into short integer values
_translator->add("_key", 1);
_translator->add("_rev", 2);
_translator->add("_id", 3);
_translator->add("_from", 4);
_translator->add("_to", 5);
_translator->add(TRI_VOC_ATTRIBUTE_KEY, 1);
_translator->add(TRI_VOC_ATTRIBUTE_REV, 2);
_translator->add(TRI_VOC_ATTRIBUTE_ID, 3);
_translator->add(TRI_VOC_ATTRIBUTE_FROM, 4);
_translator->add(TRI_VOC_ATTRIBUTE_TO, 5);
_translator->seal();
// set options for JSON to document conversion
@ -195,6 +202,10 @@ VPackOptions StorageOptions::getNonDocumentTemplate () {
return NonDocumentTemplate;
}
VPackCustomTypeHandler* StorageOptions::createCustomHandler (triagens::arango::CollectionNameResolver const* resolver) {
return new CustomTypeHandlerImpl(resolver);
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -31,8 +31,17 @@
#define ARANGODB_STORAGE_OPTIONS_H 1
#include "Basics/Common.h"
#include <velocypack/AttributeTranslator.h>
#include <velocypack/Options.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens {
namespace arango {
class CollectionNameResolver;
}
}
namespace arangodb {
class StorageOptions {
public:
@ -45,6 +54,7 @@ namespace arangodb {
static VPackOptions getDocumentToJsonTemplate ();
static VPackOptions getJsonToDocumentTemplate ();
static VPackOptions getNonDocumentTemplate ();
static VPackCustomTypeHandler* createCustomHandler (triagens::arango::CollectionNameResolver const*);
private:

View File

@ -50,6 +50,9 @@
#include "VocBase/KeyGenerator.h"
#include "Wal/LogfileManager.h"
#include <velocypack/Builder.h>
#include <velocypack/HexDump.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
#include "unicode/timezone.h"
@ -972,7 +975,6 @@ static void ReplaceVocbaseCol (bool useCollection,
/// @brief inserts a document
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
static void InsertVocbaseCol (TRI_vocbase_col_t* col,
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
@ -1006,25 +1008,6 @@ static void InsertVocbaseCol (TRI_vocbase_col_t* col,
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
}
VPackOptions vOptions = arangodb::StorageOptions::getDocumentToJsonTemplate();
VPackBuilder builder(&vOptions);
int res2 = TRI_V8ToVPack(isolate, builder, args[0]->ToObject(), true);
if (res2 || builder.hasKey("_key")) {
}
else {
}
builder.close();
VPackSlice slice(builder.slice());
for (auto const& it : VPackObjectIterator(slice)) {
std::cout << "KEY: " << it.key.copyString() << "\n";
}
// std::cout << "GOT: " << VPackHexDump(slice) << "\n\n";
// set document key
std::unique_ptr<char[]> key;
int res;
@ -1094,6 +1077,163 @@ static void InsertVocbaseCol (TRI_vocbase_col_t* col,
}
}
#include <iostream>
static int AddSystemAttributes (Transaction* trx,
TRI_voc_cid_t cid,
TRI_document_collection_t* document,
VPackBuilder& builder) {
// generate a new tick value
uint64_t const tick = TRI_NewTickServer();
if (! builder.hasKey(TRI_VOC_ATTRIBUTE_KEY)) {
// "_key" attribute not present in object
std::string const keyString = document->_keyGenerator->generate(tick);
builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(keyString));
}
else {
// "_key" attribute is present in object
VPackSlice key(builder.getKey(TRI_VOC_ATTRIBUTE_KEY));
if (! key.isString() ) {
return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD;
}
int res = document->_keyGenerator->validate(key.copyString(), false);
if (res != TRI_ERROR_NO_ERROR) {
// invalid key value
return res;
}
}
// now add _id attribute
uint8_t* p = builder.add(TRI_VOC_ATTRIBUTE_ID, VPackValuePair(9ULL, VPackValueType::Custom));
*p++ = 0xf0;
std::cout << "STORING AT " << (void*) p << ": " << cid << "\n";
arangodb::velocypack::storeUInt64(p, cid);
// now add _rev attribute
p = builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValuePair(9ULL, VPackValueType::Custom));
*p++ = 0xf1;
std::cout << "STORING AT " << (void*) p << ": " << tick << "\n";
arangodb::velocypack::storeUInt64(p, tick);
return TRI_ERROR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts a document
////////////////////////////////////////////////////////////////////////////////
static void InsertVocbaseVPack (TRI_vocbase_col_t* col,
v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
uint32_t const argLength = args.Length();
TRI_GET_GLOBALS();
if (argLength < 1 || argLength > 2) {
TRI_V8_THROW_EXCEPTION_USAGE("insert(<data>, [<waitForSync>])");
}
InsertOptions options;
if (argLength > 1 && args[1]->IsObject()) {
v8::Handle<v8::Object> optionsObject = args[1].As<v8::Object>();
TRI_GET_GLOBAL_STRING(WaitForSyncKey);
if (optionsObject->Has(WaitForSyncKey)) {
options.waitForSync = TRI_ObjectToBoolean(optionsObject->Get(WaitForSyncKey));
}
TRI_GET_GLOBAL_STRING(SilentKey);
if (optionsObject->Has(SilentKey)) {
options.silent = TRI_ObjectToBoolean(optionsObject->Get(SilentKey));
}
}
else {
options.waitForSync = ExtractWaitForSync(args, 2);
}
if (! args[0]->IsObject() || args[0]->IsArray()) {
// invalid value type. must be a document
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
}
// load collection
SingleCollectionWriteTransaction<1> trx(new V8TransactionContext(true), col->_vocbase, col->_cid);
int res = trx.begin(); // TODO: postpone locking from here to later
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION(res);
}
TRI_document_collection_t* document = trx.documentCollection();
triagens::arango::CollectionNameResolver resolver(col->_vocbase);
VPackOptions vOptions = arangodb::StorageOptions::getDocumentToJsonTemplate();
std::unique_ptr<VPackCustomTypeHandler> customTypeHandler(arangodb::StorageOptions::createCustomHandler(&resolver));
vOptions.customTypeHandler = customTypeHandler.get();
VPackBuilder builder(&vOptions);
res = TRI_V8ToVPack(isolate, builder, args[0]->ToObject(), true);
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION(res);
}
res = AddSystemAttributes(&trx, col->_cid, document, builder);
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION(res);
}
builder.close();
VPackSlice slice(builder.slice());
std::cout << "JSON: " << slice.toJson() << "\n";
std::cout << "GOT: " << VPackHexDump(slice) << "\n\n";
// fetch a barrier so nobody unlinks datafiles with the shapes & attributes we might
// need for this document
if (trx.orderDitch(trx.trxCollection()) == nullptr) {
TRI_V8_THROW_EXCEPTION_MEMORY();
}
TRI_doc_mptr_copy_t mptr;
// res = document->insert(trx, &mptr, &slice, options.waitForSync);
res = TRI_ERROR_INTERNAL;
res = trx.finish(res);
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION(res);
}
// TRI_ASSERT(mptr.getDataPtr() != nullptr); // PROTECTED by trx here
if (options.silent) {
TRI_V8_RETURN_TRUE();
}
return TRI_V8_RETURN_TRUE();
/*
char const* docKey = TRI_EXTRACT_MARKER_KEY(&mptr); // PROTECTED by trx here
v8::Handle<v8::Object> result = v8::Object::New(isolate);
TRI_GET_GLOBAL_STRING(_IdKey);
TRI_GET_GLOBAL_STRING(_RevKey);
TRI_GET_GLOBAL_STRING(_KeyKey);
result->Set(_IdKey, V8DocumentId(isolate, trx.resolver()->getCollectionName(col->_cid), docKey));
result->Set(_RevKey, V8RevisionId(isolate, mptr._rid));
result->Set(_KeyKey, TRI_V8_STRING(docKey));
TRI_V8_RETURN(result);
*/
}
////////////////////////////////////////////////////////////////////////////////
/// @brief updates (patches) a document
////////////////////////////////////////////////////////////////////////////////
@ -3296,6 +3436,37 @@ static void JS_InsertVocbaseCol (const v8::FunctionCallbackInfo<v8::Value>& args
TRI_V8_TRY_CATCH_END
}
static void JS_InsertVocbaseVPack (const v8::FunctionCallbackInfo<v8::Value>& args) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
TRI_vocbase_col_t* collection = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), WRP_VOCBASE_COL_TYPE);
if (collection == nullptr) {
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
}
if (ServerState::instance()->isCoordinator()) {
// coordinator case
if ((TRI_col_type_e) collection->_type == TRI_COL_TYPE_DOCUMENT) {
InsertVocbaseColCoordinator(collection, args);
return;
}
InsertEdgeColCoordinator(collection, args);
return;
}
// single server case
if ((TRI_col_type_e) collection->_type == TRI_COL_TYPE_DOCUMENT) {
InsertVocbaseVPack(collection, args);
}
else {
InsertEdgeCol(collection, args);
}
TRI_V8_TRY_CATCH_END
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the status of a collection
////////////////////////////////////////////////////////////////////////////////
@ -4482,6 +4653,7 @@ void TRI_InitV8collection (v8::Handle<v8::Context> context,
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("exists"), JS_ExistsVocbaseCol);
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("figures"), JS_FiguresVocbaseCol);
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("insert"), JS_InsertVocbaseCol);
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("insertv"), JS_InsertVocbaseVPack);
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("load"), JS_LoadVocbaseCol);
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("name"), JS_NameVocbaseCol);
TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("planId"), JS_PlanIdVocbaseCol);

View File

@ -26,38 +26,38 @@
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "StringBufferAdapter.h"
#include "VPackStringBufferAdapter.h"
#include "Basics/Exceptions.h"
void triagens::basics::StringBufferAdapter::push_back (char c) {
void triagens::basics::VPackStringBufferAdapter::push_back (char c) {
int res = TRI_AppendCharStringBuffer(_buffer, c);
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void triagens::basics::StringBufferAdapter::append (std::string const& p) {
void triagens::basics::VPackStringBufferAdapter::append (std::string const& p) {
int res = TRI_AppendString2StringBuffer(_buffer, p.c_str(), p.size());
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void triagens::basics::StringBufferAdapter::append (char const* p) {
void triagens::basics::VPackStringBufferAdapter::append (char const* p) {
int res = TRI_AppendString2StringBuffer(_buffer, p, strlen(p));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void triagens::basics::StringBufferAdapter::append (char const* p, uint64_t len) {
void triagens::basics::VPackStringBufferAdapter::append (char const* p, uint64_t len) {
int res = TRI_AppendString2StringBuffer(_buffer, p, static_cast<size_t>(len));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void triagens::basics::StringBufferAdapter::reserve (uint64_t len) {
void triagens::basics::VPackStringBufferAdapter::reserve (uint64_t len) {
int res = TRI_ReserveStringBuffer(_buffer, static_cast<size_t>(len));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);

View File

@ -26,16 +26,16 @@
////////////////////////////////////////////////////////////////////////////////
#include "string-buffer.h"
#include <velocypack/vpack.h>
#include <velocypack/Sink.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens {
namespace basics {
class StringBufferAdapter final : public VPackSink {
class VPackStringBufferAdapter final : public VPackSink {
public:
StringBufferAdapter (TRI_string_buffer_t* buffer)
VPackStringBufferAdapter (TRI_string_buffer_t* buffer)
: _buffer(buffer) {
}

View File

@ -30,6 +30,7 @@
#include "Basics/JsonHelper.h"
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
namespace triagens {
@ -91,8 +92,6 @@ namespace triagens {
char const*,
bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a string sub-element, or throws if <name> does not exist
/// or it is not a string

View File

@ -121,7 +121,6 @@ add_library(
Basics/SpinLocker.cpp
Basics/ssl-helper.cpp
Basics/string-buffer.cpp
Basics/StringBufferAdapter.cpp
Basics/StringUtils.cpp
Basics/structures.cpp
Basics/system-functions.cpp
@ -135,6 +134,7 @@ add_library(
Basics/VelocyPackHelper.cpp
Basics/voc-errors.cpp
Basics/voc-mimetypes.cpp
Basics/VPackStringBufferAdapter.cpp
Basics/WriteLocker.cpp
Basics/WriteUnlocker.cpp
Basics/xxhash.cpp

View File

@ -59,7 +59,6 @@ lib_libarango_a_SOURCES = \
lib/Basics/SpinLocker.cpp \
lib/Basics/ssl-helper.cpp \
lib/Basics/string-buffer.cpp \
lib/Basics/StringBufferAdapter.cpp \
lib/Basics/StringUtils.cpp \
lib/Basics/structures.cpp \
lib/Basics/system-functions.cpp \
@ -75,6 +74,7 @@ lib_libarango_a_SOURCES = \
lib/Basics/VelocyPackHelper.cpp \
lib/Basics/voc-errors.cpp \
lib/Basics/voc-mimetypes.cpp \
lib/Basics/VPackStringBufferAdapter.cpp \
lib/Basics/WriteLocker.cpp \
lib/Basics/WriteUnlocker.cpp \
lib/Basics/xxhash.cpp \

View File

@ -36,6 +36,11 @@
#include "Basics/tri-strings.h"
#include "Basics/Utf8Helper.h"
#include <velocypack/Builder.h>
#include <velocypack/Options.h>
#include <velocypack/Parser.h>
#include <velocypack/velocypack-aliases.h>
using namespace std;
using namespace triagens::basics;
using namespace triagens::rest;

View File

@ -40,6 +40,7 @@
#include "Rest/ConnectionInfo.h"
#include "Rest/RequestContext.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
// -----------------------------------------------------------------------------

View File

@ -32,6 +32,7 @@
#include "Basics/Common.h"
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
// -----------------------------------------------------------------------------
@ -41,7 +42,6 @@
struct TRI_json_t;
struct TRI_memory_zone_s;
namespace triagens {
namespace rest {

View File

@ -32,6 +32,7 @@
#include "Basics/Exceptions.h"
#include "V8/v8-utils.h"
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
// -----------------------------------------------------------------------------
@ -127,16 +128,18 @@ v8::Handle<v8::Value> TRI_VPackToV8 (v8::Isolate* isolate,
return v8::Undefined(isolate);
}
}
struct BuilderContext {
BuilderContext (v8::Isolate* isolate, VPackBuilder& builder, bool keepTopLevelOpen)
: isolate(isolate), builder(builder), keepTopLevelOpen(keepTopLevelOpen) {
}
v8::Isolate* isolate;
VPackBuilder& builder;
std::set<int> seenHashes;
std::unordered_set<int> seenHashes;
std::vector<v8::Handle<v8::Object>> seenObjects;
bool keepTopLevelOpen;
};

View File

@ -33,6 +33,8 @@
#include "Basics/Common.h"
#include "V8/v8-globals.h"
#include <velocypack/Builder.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
// -----------------------------------------------------------------------------