mirror of https://gitee.com/bigwinds/arangodb
Prepare returnOld and returnNew.
This commit is contained in:
parent
a25df3aece
commit
0daedb4cbe
|
@ -34,7 +34,9 @@ class Marker;
|
|||
// a struct for keeping document modification operations in transactions
|
||||
struct OperationOptions {
|
||||
OperationOptions()
|
||||
: recoveryMarker(nullptr), waitForSync(false), keepNull(true), mergeObjects(true), silent(false), ignoreRevs(true) {}
|
||||
: recoveryMarker(nullptr), waitForSync(false), keepNull(true),
|
||||
mergeObjects(true), silent(false), ignoreRevs(true),
|
||||
returnOld(false), returnNew(false) {}
|
||||
|
||||
// original marker, set by the recovery procedure only!
|
||||
arangodb::wal::Marker* recoveryMarker;
|
||||
|
@ -54,7 +56,11 @@ struct OperationOptions {
|
|||
// ignore _rev attributes given in documents (for replace and update)
|
||||
bool ignoreRevs;
|
||||
|
||||
// TODO: add returnOld, returnNew
|
||||
// returnOld: for replace, update and remove return previous value
|
||||
bool returnOld;
|
||||
|
||||
// returnNew: for insert, replace and update return complete new value
|
||||
bool returnNew;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -248,7 +248,9 @@ void Transaction::buildDocumentIdentity(VPackBuilder& builder,
|
|||
TRI_voc_cid_t cid,
|
||||
std::string const& key,
|
||||
std::string const& rid,
|
||||
std::string const& oldRid) {
|
||||
std::string const& oldRid,
|
||||
TRI_doc_mptr_t const* oldMptr,
|
||||
TRI_doc_mptr_t const* newMptr) {
|
||||
std::string collectionName = resolver()->getCollectionName(cid);
|
||||
|
||||
builder.openObject();
|
||||
|
@ -258,6 +260,16 @@ void Transaction::buildDocumentIdentity(VPackBuilder& builder,
|
|||
if (!oldRid.empty()) {
|
||||
builder.add("_oldRev", VPackValue(oldRid));
|
||||
}
|
||||
if (oldMptr != nullptr) {
|
||||
builder.add("old", VPackSlice(oldMptr->vpack()));
|
||||
#warning Add externals later.
|
||||
//builder.add("old", VPackValue(VPackValueType::External, oldMptr->vpack()));
|
||||
}
|
||||
if (newMptr != nullptr) {
|
||||
builder.add("new", VPackSlice(newMptr->vpack()));
|
||||
#warning Add externals later.
|
||||
//builder.add("new", VPackValue(VPackValueType::External, newMptr->vpack()));
|
||||
}
|
||||
builder.close();
|
||||
}
|
||||
|
||||
|
@ -265,9 +277,11 @@ void Transaction::buildDocumentIdentity(VPackBuilder& builder,
|
|||
TRI_voc_cid_t cid,
|
||||
std::string const& key,
|
||||
TRI_voc_rid_t rid,
|
||||
std::string const& oldRid) {
|
||||
std::string const& oldRid,
|
||||
TRI_doc_mptr_t const* oldMptr,
|
||||
TRI_doc_mptr_t const* newMptr) {
|
||||
std::string ridSt = std::to_string(rid);
|
||||
buildDocumentIdentity(builder, cid, key, ridSt, oldRid);
|
||||
buildDocumentIdentity(builder, cid, key, ridSt, oldRid, oldMptr, newMptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -630,7 +644,8 @@ OperationResult Transaction::documentLocal(std::string const& collectionName,
|
|||
TRI_ASSERT(mptr.getDataPtr() != nullptr);
|
||||
if (expectedRevision != 0 && expectedRevision != mptr.revisionId()) {
|
||||
// still return
|
||||
buildDocumentIdentity(resultBuilder, cid, key, mptr.revisionId(), "");
|
||||
buildDocumentIdentity(resultBuilder, cid, key, mptr.revisionId(), "",
|
||||
nullptr, nullptr);
|
||||
return TRI_ERROR_ARANGO_CONFLICT;
|
||||
}
|
||||
|
||||
|
@ -857,7 +872,8 @@ OperationResult Transaction::insertLocal(std::string const& collectionName,
|
|||
|
||||
TRI_ASSERT(mptr.getDataPtr() != nullptr);
|
||||
|
||||
buildDocumentIdentity(resultBuilder, cid, keyString, mptr.revisionId(), "");
|
||||
buildDocumentIdentity(resultBuilder, cid, keyString, mptr.revisionId(), "",
|
||||
nullptr, nullptr);
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
};
|
||||
|
||||
|
@ -1104,7 +1120,8 @@ OperationResult Transaction::modifyLocal(
|
|||
if (res == TRI_ERROR_ARANGO_CONFLICT) {
|
||||
// still return
|
||||
std::string key = newVal.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
|
||||
buildDocumentIdentity(resultBuilder, cid, key, actualRevision, "");
|
||||
buildDocumentIdentity(resultBuilder, cid, key, actualRevision, "",
|
||||
nullptr, nullptr);
|
||||
return TRI_ERROR_ARANGO_CONFLICT;
|
||||
} else if (res != TRI_ERROR_NO_ERROR) {
|
||||
return res;
|
||||
|
@ -1115,7 +1132,8 @@ OperationResult Transaction::modifyLocal(
|
|||
if (!options.silent) {
|
||||
std::string key = newVal.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
|
||||
buildDocumentIdentity(resultBuilder, cid, key,
|
||||
std::to_string(mptr.revisionId()), std::to_string(actualRevision));
|
||||
std::to_string(mptr.revisionId()), std::to_string(actualRevision),
|
||||
nullptr, nullptr);
|
||||
}
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
};
|
||||
|
@ -1253,7 +1271,8 @@ OperationResult Transaction::removeLocal(std::string const& collectionName,
|
|||
if (res == TRI_ERROR_ARANGO_CONFLICT) {
|
||||
std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
|
||||
buildDocumentIdentity(resultBuilder, cid, key,
|
||||
std::to_string(actualRevision), "");
|
||||
std::to_string(actualRevision), "",
|
||||
nullptr, nullptr);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1264,7 +1283,8 @@ OperationResult Transaction::removeLocal(std::string const& collectionName,
|
|||
|
||||
std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
|
||||
buildDocumentIdentity(resultBuilder, cid, key,
|
||||
std::to_string(actualRevision), "");
|
||||
std::to_string(actualRevision), "",
|
||||
nullptr, nullptr);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
};
|
||||
|
|
|
@ -234,13 +234,17 @@ class Transaction {
|
|||
TRI_voc_cid_t cid,
|
||||
std::string const& key,
|
||||
std::string const& rid,
|
||||
std::string const& oldRid);
|
||||
std::string const& oldRid,
|
||||
TRI_doc_mptr_t const* oldMptr,
|
||||
TRI_doc_mptr_t const* newMptr);
|
||||
|
||||
void buildDocumentIdentity(VPackBuilder& builder,
|
||||
TRI_voc_cid_t cid,
|
||||
std::string const& key,
|
||||
TRI_voc_rid_t rid,
|
||||
std::string const& oldRid);
|
||||
std::string const& oldRid,
|
||||
TRI_doc_mptr_t const* oldMptr,
|
||||
TRI_doc_mptr_t const* newMptr);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read any (random) document
|
||||
|
|
Loading…
Reference in New Issue