mirror of https://gitee.com/bigwinds/arangodb
Add insertCluster method to transaction. Change OperationResult.
This commit is contained in:
parent
af107de6f9
commit
52d051d571
|
@ -34,12 +34,33 @@
|
|||
namespace arangodb {
|
||||
|
||||
struct OperationResult {
|
||||
OperationResult() : buffer(), customTypeHandler(nullptr), code(TRI_ERROR_NO_ERROR), wasSynchronous(false) {}
|
||||
OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer, VPackCustomTypeHandler* handler) : buffer(buffer), customTypeHandler(handler), code(TRI_ERROR_NO_ERROR), wasSynchronous(false) {}
|
||||
OperationResult(int code, std::shared_ptr<VPackBuffer<uint8_t>> buffer) : buffer(buffer), customTypeHandler(nullptr), code(code), wasSynchronous(false) {}
|
||||
OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer, bool wasSynchronous) : buffer(buffer), customTypeHandler(nullptr), code(TRI_ERROR_NO_ERROR), wasSynchronous(wasSynchronous) {}
|
||||
explicit OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer) : OperationResult(TRI_ERROR_NO_ERROR, buffer) {}
|
||||
explicit OperationResult(int code) : OperationResult(code, nullptr) { }
|
||||
// OperationResult() : buffer(), customTypeHandler(nullptr), code(TRI_ERROR_NO_ERROR), wasSynchronous(false) {}
|
||||
//OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer, VPackCustomTypeHandler* handler) : buffer(buffer), customTypeHandler(handler), code(TRI_ERROR_NO_ERROR), wasSynchronous(false) {}
|
||||
//OperationResult(int code, std::shared_ptr<VPackBuffer<uint8_t>> buffer) : buffer(buffer), customTypeHandler(nullptr), code(code), wasSynchronous(false) {}
|
||||
//OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer, bool wasSynchronous) : buffer(buffer), customTypeHandler(nullptr), code(TRI_ERROR_NO_ERROR), wasSynchronous(wasSynchronous) {}
|
||||
//explicit OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer) : OperationResult(TRI_ERROR_NO_ERROR, buffer) {}
|
||||
|
||||
explicit OperationResult(int code)
|
||||
: customTypeHandler(nullptr), code(code), wasSynchronous(false) {
|
||||
if (code != TRI_ERROR_NO_ERROR) {
|
||||
errorMessage = TRI_errno_string(code);
|
||||
}
|
||||
}
|
||||
|
||||
OperationResult(int code, std::string const& message)
|
||||
: customTypeHandler(nullptr), errorMessage(message), code(code),
|
||||
wasSynchronous(false) {
|
||||
TRI_ASSERT(code != TRI_ERROR_NO_ERROR);
|
||||
}
|
||||
|
||||
OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer,
|
||||
VPackCustomTypeHandler* handler,
|
||||
std::string const& message,
|
||||
int code,
|
||||
bool wasSynchronous)
|
||||
: buffer(buffer), customTypeHandler(handler), errorMessage(message),
|
||||
code(code), wasSynchronous(wasSynchronous) {
|
||||
}
|
||||
|
||||
~OperationResult() {
|
||||
// TODO: handle destruction of customTypeHandler
|
||||
|
@ -60,6 +81,7 @@ struct OperationResult {
|
|||
|
||||
std::shared_ptr<VPackBuffer<uint8_t>> buffer;
|
||||
VPackCustomTypeHandler* customTypeHandler;
|
||||
std::string errorMessage;
|
||||
int code;
|
||||
bool wasSynchronous;
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "Indexes/PrimaryIndex.h"
|
||||
#include "Storage/Marker.h"
|
||||
#include "VocBase/KeyGenerator.h"
|
||||
#include "Cluster/ClusterMethods.h"
|
||||
|
||||
#include <velocypack/Builder.h>
|
||||
#include <velocypack/Collection.h>
|
||||
|
@ -514,7 +515,7 @@ OperationResult Transaction::documentLocal(std::string const& collectionName,
|
|||
resultBuilder.add(VPackSlice(mptr.vpack()));
|
||||
}
|
||||
|
||||
return OperationResult(resultBuilder.steal(), StorageOptions::getCustomTypeHandler(_vocbase));
|
||||
return OperationResult(resultBuilder.steal(), StorageOptions::getCustomTypeHandler(_vocbase), "", TRI_ERROR_NO_ERROR, false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -556,8 +557,31 @@ OperationResult Transaction::insert(std::string const& collectionName,
|
|||
OperationResult Transaction::insertCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
OperationOptions& options) {
|
||||
// TODO
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||
std::map<std::string, std::string> headers;
|
||||
arangodb::rest::HttpResponse::HttpResponseCode responseCode;
|
||||
std::map<std::string, std::string> resultHeaders;
|
||||
std::string resultBody;
|
||||
|
||||
int res = arangodb::createDocumentOnCoordinator(
|
||||
_vocbase->_name, collectionName, options.waitForSync,
|
||||
value, headers, responseCode, resultHeaders, resultBody);
|
||||
|
||||
if (res == TRI_ERROR_NO_ERROR) {
|
||||
VPackParser parser;
|
||||
try {
|
||||
parser.parse(resultBody);
|
||||
auto bui = parser.steal();
|
||||
auto buf = bui->steal();
|
||||
return OperationResult(buf, nullptr, "", TRI_ERROR_NO_ERROR,
|
||||
responseCode == arangodb::rest::HttpResponse::CREATED);
|
||||
}
|
||||
catch (VPackException& e) {
|
||||
std::string message = "JSON from DBserver not parseable: "
|
||||
+ resultBody + ":" + e.what();
|
||||
return OperationResult(TRI_ERROR_INTERNAL, message);
|
||||
}
|
||||
}
|
||||
return OperationResult(res);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -638,7 +662,8 @@ OperationResult Transaction::insertLocal(std::string const& collectionName,
|
|||
resultBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(resultKey));
|
||||
resultBuilder.close();
|
||||
|
||||
return OperationResult(resultBuilder.steal(), options.waitForSync);
|
||||
return OperationResult(resultBuilder.steal(), nullptr, "", TRI_ERROR_NO_ERROR,
|
||||
options.waitForSync || document->_info.waitForSync());
|
||||
}
|
||||
|
||||
OperationResult Transaction::replace(std::string const& collectionName,
|
||||
|
@ -784,7 +809,8 @@ OperationResult Transaction::updateLocal(std::string const& collectionName,
|
|||
resultBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(resultKey));
|
||||
resultBuilder.close();
|
||||
|
||||
return OperationResult(resultBuilder.steal(), options.waitForSync);
|
||||
return OperationResult(resultBuilder.steal(), nullptr, "", TRI_ERROR_NO_ERROR,
|
||||
options.waitForSync || document->_info.waitForSync());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -896,6 +922,7 @@ OperationResult Transaction::removeLocal(std::string const& collectionName,
|
|||
resultBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key));
|
||||
resultBuilder.close();
|
||||
|
||||
return OperationResult(resultBuilder.steal(), options.waitForSync);
|
||||
return OperationResult(resultBuilder.steal(), nullptr, "", TRI_ERROR_NO_ERROR,
|
||||
options.waitForSync || document->_info.waitForSync());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue