1
0
Fork 0

Prepare returnOld and returnNew.

This commit is contained in:
Max Neunhoeffer 2016-03-10 16:49:03 +01:00
parent a25df3aece
commit 0daedb4cbe
3 changed files with 43 additions and 13 deletions

View File

@ -34,7 +34,9 @@ class Marker;
// a struct for keeping document modification operations in transactions // a struct for keeping document modification operations in transactions
struct OperationOptions { struct OperationOptions {
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! // original marker, set by the recovery procedure only!
arangodb::wal::Marker* recoveryMarker; arangodb::wal::Marker* recoveryMarker;
@ -54,7 +56,11 @@ struct OperationOptions {
// ignore _rev attributes given in documents (for replace and update) // ignore _rev attributes given in documents (for replace and update)
bool ignoreRevs; 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;
}; };
} }

View File

@ -248,7 +248,9 @@ void Transaction::buildDocumentIdentity(VPackBuilder& builder,
TRI_voc_cid_t cid, TRI_voc_cid_t cid,
std::string const& key, std::string const& key,
std::string const& rid, 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); std::string collectionName = resolver()->getCollectionName(cid);
builder.openObject(); builder.openObject();
@ -258,6 +260,16 @@ void Transaction::buildDocumentIdentity(VPackBuilder& builder,
if (!oldRid.empty()) { if (!oldRid.empty()) {
builder.add("_oldRev", VPackValue(oldRid)); 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(); builder.close();
} }
@ -265,9 +277,11 @@ void Transaction::buildDocumentIdentity(VPackBuilder& builder,
TRI_voc_cid_t cid, TRI_voc_cid_t cid,
std::string const& key, std::string const& key,
TRI_voc_rid_t rid, 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); 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); TRI_ASSERT(mptr.getDataPtr() != nullptr);
if (expectedRevision != 0 && expectedRevision != mptr.revisionId()) { if (expectedRevision != 0 && expectedRevision != mptr.revisionId()) {
// still return // still return
buildDocumentIdentity(resultBuilder, cid, key, mptr.revisionId(), ""); buildDocumentIdentity(resultBuilder, cid, key, mptr.revisionId(), "",
nullptr, nullptr);
return TRI_ERROR_ARANGO_CONFLICT; return TRI_ERROR_ARANGO_CONFLICT;
} }
@ -857,7 +872,8 @@ OperationResult Transaction::insertLocal(std::string const& collectionName,
TRI_ASSERT(mptr.getDataPtr() != nullptr); TRI_ASSERT(mptr.getDataPtr() != nullptr);
buildDocumentIdentity(resultBuilder, cid, keyString, mptr.revisionId(), ""); buildDocumentIdentity(resultBuilder, cid, keyString, mptr.revisionId(), "",
nullptr, nullptr);
return TRI_ERROR_NO_ERROR; return TRI_ERROR_NO_ERROR;
}; };
@ -1104,7 +1120,8 @@ OperationResult Transaction::modifyLocal(
if (res == TRI_ERROR_ARANGO_CONFLICT) { if (res == TRI_ERROR_ARANGO_CONFLICT) {
// still return // still return
std::string key = newVal.get(TRI_VOC_ATTRIBUTE_KEY).copyString(); 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; return TRI_ERROR_ARANGO_CONFLICT;
} else if (res != TRI_ERROR_NO_ERROR) { } else if (res != TRI_ERROR_NO_ERROR) {
return res; return res;
@ -1115,7 +1132,8 @@ OperationResult Transaction::modifyLocal(
if (!options.silent) { if (!options.silent) {
std::string key = newVal.get(TRI_VOC_ATTRIBUTE_KEY).copyString(); std::string key = newVal.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
buildDocumentIdentity(resultBuilder, cid, key, 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; return TRI_ERROR_NO_ERROR;
}; };
@ -1253,7 +1271,8 @@ OperationResult Transaction::removeLocal(std::string const& collectionName,
if (res == TRI_ERROR_ARANGO_CONFLICT) { if (res == TRI_ERROR_ARANGO_CONFLICT) {
std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString(); std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
buildDocumentIdentity(resultBuilder, cid, key, buildDocumentIdentity(resultBuilder, cid, key,
std::to_string(actualRevision), ""); std::to_string(actualRevision), "",
nullptr, nullptr);
} }
return res; return res;
} }
@ -1264,7 +1283,8 @@ OperationResult Transaction::removeLocal(std::string const& collectionName,
std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString(); std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
buildDocumentIdentity(resultBuilder, cid, key, buildDocumentIdentity(resultBuilder, cid, key,
std::to_string(actualRevision), ""); std::to_string(actualRevision), "",
nullptr, nullptr);
return TRI_ERROR_NO_ERROR; return TRI_ERROR_NO_ERROR;
}; };

View File

@ -234,13 +234,17 @@ class Transaction {
TRI_voc_cid_t cid, TRI_voc_cid_t cid,
std::string const& key, std::string const& key,
std::string const& rid, 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, void buildDocumentIdentity(VPackBuilder& builder,
TRI_voc_cid_t cid, TRI_voc_cid_t cid,
std::string const& key, std::string const& key,
TRI_voc_rid_t rid, 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 /// @brief read any (random) document