/// @brief get the _to attribute from an object/document AqlValue AqlValue::getToAttribute(arangodb::AqlTransaction* trx, bool& mustDestroy, bool doCopy) const { mustDestroy = false; switch (type()) { case VPACK_SLICE_POINTER: doCopy = false; case VPACK_INLINE: // fall-through intentional case VPACK_MANAGED: { VPackSlice s(slice()); if (s.isObject()) { VPackSlice found = Transaction::extractToFromDocument(s); if (!found.isNone()) { if (doCopy) { mustDestroy = true; return AqlValue(found); } // return a reference to an existing slice return AqlValue(found.begin()); } } // fall-through intentional break; } case DOCVEC: case RANGE: { // will return null break; } } // default is to return null return AqlValue(arangodb::basics::VelocyPackHelper::NullValue()); }
bool VelocyPackHelper::VPackStringEqual::operator()(VPackSlice const& lhs, VPackSlice const& rhs) const noexcept { auto const lh = lhs.head(); auto const rh = rhs.head(); if (lh != rh) { return false; } VPackValueLength size; if (lh == 0xbf) { // long UTF-8 String size = static_cast<VPackValueLength>(velocypack::readInteger<VPackValueLength>(lhs.begin() + 1, 8)); if (size !=static_cast<VPackValueLength>(velocypack::readInteger<VPackValueLength>(rhs.begin() + 1, 8))) { return false; } return (memcmp(lhs.start() + 1 + 8, rhs.start() + 1 + 8, static_cast<size_t>(size)) == 0); } size = static_cast<VPackValueLength>(lh - 0x40); return (memcmp(lhs.start() + 1, rhs.start() + 1, static_cast<size_t>(size)) == 0); };
void DocumentOperation::revert(arangodb::Transaction* trx) { TRI_ASSERT(trx != nullptr); if (_status == StatusType::CREATED || _status == StatusType::SWAPPED || _status == StatusType::REVERTED) { return; } TRI_ASSERT(_status == StatusType::INDEXED || _status == StatusType::HANDLED); // set to reverted now _status = StatusType::REVERTED; TRI_voc_rid_t oldRevisionId = 0; VPackSlice oldDoc; if (_type != TRI_VOC_DOCUMENT_OPERATION_INSERT) { TRI_ASSERT(!_oldRevision.empty()); oldRevisionId = _oldRevision._revisionId; oldDoc = VPackSlice(_oldRevision._vpack); } TRI_voc_rid_t newRevisionId = 0; VPackSlice newDoc; if (_type != TRI_VOC_DOCUMENT_OPERATION_REMOVE) { TRI_ASSERT(!_newRevision.empty()); newRevisionId = _newRevision._revisionId; newDoc = VPackSlice(_newRevision._vpack); } try { _collection->rollbackOperation(trx, _type, oldRevisionId, oldDoc, newRevisionId, newDoc); } catch (...) { // TODO: decide whether we should rethrow here } if (_type == TRI_VOC_DOCUMENT_OPERATION_INSERT) { TRI_ASSERT(_oldRevision.empty()); TRI_ASSERT(!_newRevision.empty()); // remove now obsolete new revision try { _collection->removeRevision(newRevisionId, true); } catch (...) { // operation probably was never inserted // TODO: decide whether we should rethrow here } } else if (_type == TRI_VOC_DOCUMENT_OPERATION_UPDATE || _type == TRI_VOC_DOCUMENT_OPERATION_REPLACE) { TRI_ASSERT(!_oldRevision.empty()); TRI_ASSERT(!_newRevision.empty()); SimpleIndexElement* element = _collection->primaryIndex()->lookupKeyRef(trx, Transaction::extractKeyFromDocument(newDoc)); if (element != nullptr && element->revisionId() != 0) { VPackSlice keySlice(Transaction::extractKeyFromDocument(oldDoc)); element->updateRevisionId(oldRevisionId, static_cast<uint32_t>(keySlice.begin() - oldDoc.begin())); } // remove now obsolete new revision try { _collection->removeRevision(newRevisionId, true); } catch (...) { // operation probably was never inserted // TODO: decide whether we should rethrow here } } }
void SingleServerTraverser::addEdgeToVelocyPack(VPackSlice edge, VPackBuilder& result) { result.addExternal(edge.begin()); }