mirror of https://gitee.com/bigwinds/arangodb
101 lines
3.4 KiB
C++
101 lines
3.4 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// 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 Michael Hackstein
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "IndexIterator.h"
|
|
#include "Basics/StringUtils.h"
|
|
#include "Cluster/ServerState.h"
|
|
#include "Utils/CollectionNameResolver.h"
|
|
|
|
using namespace arangodb;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief context for an index iterator
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
IndexIteratorContext::IndexIteratorContext(TRI_vocbase_t* vocbase,
|
|
CollectionNameResolver* resolver)
|
|
: vocbase(vocbase), resolver(resolver), ownsResolver(resolver == nullptr) {}
|
|
|
|
IndexIteratorContext::IndexIteratorContext(TRI_vocbase_t* vocbase)
|
|
: IndexIteratorContext(vocbase, nullptr) {}
|
|
|
|
IndexIteratorContext::~IndexIteratorContext() {
|
|
if (ownsResolver) {
|
|
delete resolver;
|
|
}
|
|
}
|
|
|
|
CollectionNameResolver const* IndexIteratorContext::getResolver() const {
|
|
if (resolver == nullptr) {
|
|
TRI_ASSERT(ownsResolver);
|
|
resolver = new CollectionNameResolver(vocbase);
|
|
}
|
|
return resolver;
|
|
}
|
|
|
|
bool IndexIteratorContext::isCluster() const {
|
|
return arangodb::ServerState::instance()->isRunningInCluster();
|
|
}
|
|
|
|
int IndexIteratorContext::resolveId(char const* handle, TRI_voc_cid_t& cid,
|
|
char const*& key) const {
|
|
char const* p = strchr(handle, TRI_DOCUMENT_HANDLE_SEPARATOR_CHR);
|
|
|
|
if (p == nullptr || *p == '\0') {
|
|
return TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD;
|
|
}
|
|
|
|
if (*handle >= '0' && *handle <= '9') {
|
|
cid = arangodb::basics::StringUtils::uint64(handle, p - handle);
|
|
} else {
|
|
std::string const name(handle, p - handle);
|
|
cid = getResolver()->getCollectionIdCluster(name);
|
|
}
|
|
|
|
if (cid == 0) {
|
|
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
|
}
|
|
|
|
key = p + 1;
|
|
|
|
return TRI_ERROR_NO_ERROR;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief default destructor. Does not free anything
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
IndexIterator::~IndexIterator() {}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief default implementation for next
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TRI_doc_mptr_t* IndexIterator::next() { return nullptr; }
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief default implementation for reset
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void IndexIterator::reset() {}
|