mirror of https://gitee.com/bigwinds/arangodb
simplifications
This commit is contained in:
parent
c157363f3c
commit
4de5e41044
|
@ -222,7 +222,6 @@ add_executable(${BIN_ARANGOD}
|
|||
Utils/CollectionKeysRepository.cpp
|
||||
Utils/Cursor.cpp
|
||||
Utils/CursorRepository.cpp
|
||||
Utils/DocumentHelper.cpp
|
||||
Utils/OperationCursor.cpp
|
||||
Utils/ShapedJsonTransformer.cpp
|
||||
Utils/StandaloneTransactionContext.cpp
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
/// @author Jan Steemann
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Cluster/ClusterInfo.h"
|
||||
|
||||
#include "ClusterInfo.h"
|
||||
#include "Basics/json.h"
|
||||
#include "Basics/Logger.h"
|
||||
#include "Basics/json-utilities.h"
|
||||
|
@ -33,6 +32,7 @@
|
|||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Basics/WriteLocker.h"
|
||||
#include "Cluster/ServerState.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
|
||||
#include <velocypack/Iterator.h>
|
||||
|
|
|
@ -23,13 +23,12 @@
|
|||
|
||||
#include "RestVocbaseBaseHandler.h"
|
||||
#include "Basics/conversions.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/StringBuffer.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Basics/VPackStringBufferAdapter.h"
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "Utils/DocumentHelper.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
|
||||
#include <velocypack/Builder.h>
|
||||
|
@ -127,6 +126,20 @@ RestVocbaseBaseHandler::RestVocbaseBaseHandler(HttpRequest* request)
|
|||
|
||||
RestVocbaseBaseHandler::~RestVocbaseBaseHandler() {}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief assemble a document id from a string and a string
|
||||
/// optionally url-encodes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string RestVocbaseBaseHandler::assembleDocumentId(
|
||||
std::string const& collectionName, std::string const& key, bool urlEncode) {
|
||||
if (urlEncode) {
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR +
|
||||
StringUtils::urlEncode(key);
|
||||
}
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Generate a result for successful save
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -215,7 +228,7 @@ void RestVocbaseBaseHandler::generate20x(
|
|||
if (slice.isObject()) {
|
||||
_response->setHeader("etag", 4, "\"" + slice.get(TRI_VOC_ATTRIBUTE_REV).copyString() + "\"");
|
||||
// pre 1.4 location headers withdrawn for >= 3.0
|
||||
std::string escapedHandle(DocumentHelper::assembleDocumentId(
|
||||
std::string escapedHandle(assembleDocumentId(
|
||||
collectionName, slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString(), true));
|
||||
if (type == TRI_COL_TYPE_EDGE) {
|
||||
_response->setHeader("location", 8,
|
||||
|
@ -305,7 +318,7 @@ void RestVocbaseBaseHandler::generatePreconditionFailed(
|
|||
|
||||
VPackBuilder builder;
|
||||
builder.openObject();
|
||||
builder.add(TRI_VOC_ATTRIBUTE_ID, VPackValue(DocumentHelper::assembleDocumentId(collectionName, key)));
|
||||
builder.add(TRI_VOC_ATTRIBUTE_ID, VPackValue(assembleDocumentId(collectionName, key, false)));
|
||||
builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(std::to_string(rev)));
|
||||
builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(key));
|
||||
builder.close();
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "Rest/HttpResponse.h"
|
||||
#include "RestHandler/RestBaseHandler.h"
|
||||
#include "RestServer/VocbaseContext.h"
|
||||
#include "Utils/SingleCollectionTransaction.h"
|
||||
#include "Utils/transactions.h"
|
||||
|
||||
struct TRI_vocbase_t;
|
||||
|
@ -125,6 +124,14 @@ class RestVocbaseBaseHandler : public RestBaseHandler {
|
|||
~RestVocbaseBaseHandler();
|
||||
|
||||
protected:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief assemble a document id from a string and a string
|
||||
/// optionally url-encodes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string assembleDocumentId(std::string const&, std::string const&, bool);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief check if a collection needs to be created on the fly
|
||||
///
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#define ARANGOD_REST_SERVER_VOCBASE_CONTEXT_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "Rest/HttpResponse.h"
|
||||
#include "Rest/RequestContext.h"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
#include "CollectionKeys.h"
|
||||
#include "Utils/CollectionGuard.h"
|
||||
#include "Utils/DocumentHelper.h"
|
||||
#include "Utils/transactions.h"
|
||||
#include "VocBase/compactor.h"
|
||||
#include "VocBase/DatafileHelper.h"
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 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 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "DocumentHelper.h"
|
||||
#include "Basics/json.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "VocBase/vocbase.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief assemble a document id from a string and a string
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string DocumentHelper::assembleDocumentId(
|
||||
std::string const& collectionName, std::string const& key, bool urlEncode) {
|
||||
if (urlEncode) {
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR +
|
||||
StringUtils::urlEncode(key);
|
||||
}
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief assemble a document id from a string and a char* key
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string DocumentHelper::assembleDocumentId(
|
||||
std::string const& collectionName, const TRI_voc_key_t key,
|
||||
bool urlEncode) {
|
||||
if (key == nullptr) {
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + "_unknown";
|
||||
}
|
||||
|
||||
if (urlEncode) {
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR +
|
||||
StringUtils::urlEncode(key);
|
||||
}
|
||||
|
||||
return collectionName + TRI_DOCUMENT_HANDLE_SEPARATOR_STR + key;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief extract the collection id and document key from an id
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool DocumentHelper::parseDocumentId(CollectionNameResolver const& resolver,
|
||||
char const* input, TRI_voc_cid_t& cid,
|
||||
char** key) {
|
||||
if (input == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char const* pos = strchr(input, TRI_DOCUMENT_HANDLE_SEPARATOR_CHR);
|
||||
|
||||
if (pos == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cid = resolver.getCollectionIdCluster(std::string(input, pos - input));
|
||||
*key = (char*)(pos + 1);
|
||||
|
||||
if (cid == 0 || **key == '\0') {
|
||||
// unknown collection or empty key
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief extract the "_key" attribute from a JSON object
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int DocumentHelper::getKey(TRI_json_t const* json, TRI_voc_key_t* key) {
|
||||
*key = 0;
|
||||
|
||||
// check type of json
|
||||
if (!TRI_IsObjectJson(json)) {
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
// check if _key is there
|
||||
TRI_json_t const* k = TRI_LookupObjectJson(json, TRI_VOC_ATTRIBUTE_KEY);
|
||||
|
||||
if (k == nullptr) {
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
if (!TRI_IsStringJson(k)) {
|
||||
// _key is there but not a string
|
||||
return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD;
|
||||
}
|
||||
|
||||
// _key is there and a string
|
||||
*key = k->_value._string.data;
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 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 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGOD_UTILS_DOCUMENT_HELPER_H
|
||||
#define ARANGOD_UTILS_DOCUMENT_HELPER_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
#include "Utils/CollectionNameResolver.h"
|
||||
#include "VocBase/voc-types.h"
|
||||
|
||||
struct TRI_json_t;
|
||||
|
||||
namespace arangodb {
|
||||
|
||||
class DocumentHelper {
|
||||
private:
|
||||
DocumentHelper() = delete;
|
||||
|
||||
~DocumentHelper() = delete;
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief assemble a document id from a string and a string
|
||||
/// TODO: remove
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string assembleDocumentId(std::string const&,
|
||||
std::string const& key,
|
||||
bool urlEncode = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief assemble a document id from a string and a char* key
|
||||
/// TODO: remove
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string assembleDocumentId(std::string const&, const TRI_voc_key_t,
|
||||
bool urlEncode = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief extract the collection id and document key from an id
|
||||
/// TODO: remove
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool parseDocumentId(arangodb::CollectionNameResolver const&,
|
||||
char const*, TRI_voc_cid_t&, char**);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief extract the "_key" attribute from a JSON object
|
||||
/// TODO: remove
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int getKey(struct TRI_json_t const*, TRI_voc_key_t*);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,14 +25,8 @@
|
|||
#define ARANGOD_UTILS_TRANSACTION_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
//#include "Basics/tri-strings.h"
|
||||
//#include "Basics/VelocyPackHelper.h"
|
||||
//#include "Utils/CollectionNameResolver.h"
|
||||
#include "Utils/OperationOptions.h"
|
||||
#include "Utils/OperationResult.h"
|
||||
//#include "Utils/TransactionContext.h"
|
||||
//#include "VocBase/collection.h"
|
||||
//#include "VocBase/document-collection.h"
|
||||
#include "VocBase/transaction.h"
|
||||
#include "VocBase/vocbase.h"
|
||||
#include "VocBase/voc-types.h"
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "Basics/conversions.h"
|
||||
#include "VocBase/KeyGenerator.h"
|
||||
#include "V8/v8-conv.h"
|
||||
#include "Utils/DocumentHelper.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
|
|
|
@ -30,6 +30,13 @@
|
|||
namespace arangodb {
|
||||
namespace DatafileHelper {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bit mask for datafile ids (fids) that indicates whether a file is
|
||||
/// a WAL file (bit set) or a datafile (bit not set)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
constexpr uint64_t WalFileBitmask() { return 0x8000000000000000ULL; }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief maximal size of a marker
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -55,8 +55,6 @@ class Slice;
|
|||
}
|
||||
}
|
||||
|
||||
#define TRI_WAL_FILE_BITMASK 0x8000000000000000ULL
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief master pointer
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -105,7 +103,7 @@ struct TRI_doc_mptr_t {
|
|||
// return the datafile id.
|
||||
inline TRI_voc_fid_t getFid() const {
|
||||
// unmask the WAL bit
|
||||
return (_fid & ~TRI_WAL_FILE_BITMASK);
|
||||
return (_fid & ~arangodb::DatafileHelper::WalFileBitmask());
|
||||
}
|
||||
|
||||
// sets datafile id. note that the highest bit of the file id must
|
||||
|
@ -117,7 +115,7 @@ struct TRI_doc_mptr_t {
|
|||
// set the WAL bit if required
|
||||
_fid = fid;
|
||||
if (isWal) {
|
||||
_fid |= TRI_WAL_FILE_BITMASK;
|
||||
_fid |= arangodb::DatafileHelper::WalFileBitmask();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +140,7 @@ struct TRI_doc_mptr_t {
|
|||
// the _fid value is set, and to a datafile otherwise
|
||||
inline bool pointsToWal() const {
|
||||
// check whether the WAL bit is set
|
||||
return ((_fid & TRI_WAL_FILE_BITMASK) == 1);
|
||||
return ((_fid & arangodb::DatafileHelper::WalFileBitmask()) == 1);
|
||||
}
|
||||
|
||||
// return the marker's revision id
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "Basics/Common.h"
|
||||
#include "Basics/vector.h"
|
||||
//#include "VocBase/datafile.h"
|
||||
#include "VocBase/voc-types.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#define ARANGOD_VOC_BASE_VOC_TYPES_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
#include "Cluster/ServerState.h"
|
||||
|
||||
#include <velocypack/Slice.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
|
Loading…
Reference in New Issue