mirror of https://gitee.com/bigwinds/arangodb
use namespace std
This commit is contained in:
parent
229e710dd1
commit
1925a16640
|
@ -49,11 +49,6 @@ namespace triagens {
|
||||||
// --SECTION-- constructors / destructors
|
// --SECTION-- constructors / destructors
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @addtogroup ArangoDB
|
|
||||||
/// @{
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -71,34 +66,25 @@ namespace triagens {
|
||||||
~CollectionNameResolver () {
|
~CollectionNameResolver () {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- public methods
|
// --SECTION-- public methods
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @addtogroup ArangoDB
|
|
||||||
/// @{
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief look up a collection id for a collection name (local case)
|
/// @brief look up a collection id for a collection name (local case)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TRI_voc_cid_t getCollectionId (string const& name) const {
|
TRI_voc_cid_t getCollectionId (std::string const& name) const {
|
||||||
if (name[0] >= '0' && name[0] <= '9') {
|
if (name[0] >= '0' && name[0] <= '9') {
|
||||||
// name is a numeric id
|
// name is a numeric id
|
||||||
return (TRI_voc_cid_t) triagens::basics::StringUtils::uint64(name);
|
return (TRI_voc_cid_t) triagens::basics::StringUtils::uint64(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TRI_vocbase_col_t* collection = getCollectionStruct(name);
|
TRI_vocbase_col_t const* collection = getCollectionStruct(name);
|
||||||
|
|
||||||
if (collection != 0) {
|
if (collection != nullptr) {
|
||||||
return collection->_cid;
|
return collection->_cid;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -108,19 +94,21 @@ namespace triagens {
|
||||||
/// @brief look up a collection struct for a collection name
|
/// @brief look up a collection struct for a collection name
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const TRI_vocbase_col_t* getCollectionStruct (string const& name) const {
|
const TRI_vocbase_col_t* getCollectionStruct (std::string const& name) const {
|
||||||
|
std::unordered_map<std::string, TRI_vocbase_col_t const*>::iterator it;
|
||||||
|
|
||||||
if (! _resolvedNames.empty()) {
|
if (! _resolvedNames.empty()) {
|
||||||
map<string, const TRI_vocbase_col_t*>::const_iterator it = _resolvedNames.find(name);
|
it = _resolvedNames.find(name);
|
||||||
|
|
||||||
if (it != _resolvedNames.end()) {
|
if (it != _resolvedNames.end()) {
|
||||||
return (*it).second;
|
return (*it).second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const TRI_vocbase_col_t* collection = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
|
TRI_vocbase_col_t const* collection = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
|
||||||
|
|
||||||
if (collection != 0) {
|
if (collection != nullptr) {
|
||||||
_resolvedNames.insert(make_pair(name, collection));
|
_resolvedNames.insert(it, std::make_pair(name, collection));
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
|
@ -130,7 +118,7 @@ namespace triagens {
|
||||||
/// @brief look up a cluster collection id for a cluster collection name
|
/// @brief look up a cluster collection id for a cluster collection name
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TRI_voc_cid_t getCollectionIdCluster (string const& name) const {
|
TRI_voc_cid_t getCollectionIdCluster (std::string const& name) const {
|
||||||
if (! ServerState::instance()->isRunningInCluster()) {
|
if (! ServerState::instance()->isRunningInCluster()) {
|
||||||
return getCollectionId(name);
|
return getCollectionId(name);
|
||||||
}
|
}
|
||||||
|
@ -156,16 +144,18 @@ namespace triagens {
|
||||||
/// translate the local collection ID into a cluster wide collection name.
|
/// translate the local collection ID into a cluster wide collection name.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
string getCollectionName (const TRI_voc_cid_t cid) const {
|
std::string getCollectionName (const TRI_voc_cid_t cid) const {
|
||||||
|
std::unordered_map<TRI_voc_cid_t, std::string>::iterator it;
|
||||||
|
|
||||||
if (! _resolvedIds.empty()) {
|
if (! _resolvedIds.empty()) {
|
||||||
map<TRI_voc_cid_t, string>::const_iterator it = _resolvedIds.find(cid);
|
it = _resolvedIds.find(cid);
|
||||||
|
|
||||||
if (it != _resolvedIds.end()) {
|
if (it != _resolvedIds.end()) {
|
||||||
return (*it).second;
|
return (*it).second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string name;
|
std::string name;
|
||||||
if (ServerState::instance()->isDBserver()) {
|
if (ServerState::instance()->isDBserver()) {
|
||||||
TRI_READ_LOCK_COLLECTIONS_VOCBASE(_vocbase);
|
TRI_READ_LOCK_COLLECTIONS_VOCBASE(_vocbase);
|
||||||
|
|
||||||
|
@ -174,7 +164,7 @@ namespace triagens {
|
||||||
TRI_LookupByKeyAssociativePointer
|
TRI_LookupByKeyAssociativePointer
|
||||||
(&_vocbase->_collectionsById, &cid));
|
(&_vocbase->_collectionsById, &cid));
|
||||||
|
|
||||||
if (0 != found) {
|
if (nullptr != found) {
|
||||||
name = triagens::basics::StringUtils::itoa(found->_planId);
|
name = triagens::basics::StringUtils::itoa(found->_planId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +188,7 @@ namespace triagens {
|
||||||
name = "_unknown";
|
name = "_unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
_resolvedIds.insert(make_pair(cid, name));
|
_resolvedIds.insert(it, std::make_pair(cid, name));
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +198,7 @@ namespace triagens {
|
||||||
/// collection id
|
/// collection id
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
string getCollectionNameCluster (const TRI_voc_cid_t cid) const {
|
std::string getCollectionNameCluster (const TRI_voc_cid_t cid) const {
|
||||||
if (! ServerState::instance()->isRunningInCluster()) {
|
if (! ServerState::instance()->isRunningInCluster()) {
|
||||||
return getCollectionName(cid);
|
return getCollectionName(cid);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +209,7 @@ namespace triagens {
|
||||||
shared_ptr<CollectionInfo> ci
|
shared_ptr<CollectionInfo> ci
|
||||||
= ClusterInfo::instance()->getCollection(_vocbase->_name,
|
= ClusterInfo::instance()->getCollection(_vocbase->_name,
|
||||||
triagens::basics::StringUtils::itoa(cid));
|
triagens::basics::StringUtils::itoa(cid));
|
||||||
string name = ci->name();
|
std::string name = ci->name();
|
||||||
|
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
ClusterInfo::instance()->flush();
|
ClusterInfo::instance()->flush();
|
||||||
|
@ -231,19 +221,10 @@ namespace triagens {
|
||||||
return "_unknown";
|
return "_unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- private variables
|
// --SECTION-- private variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @addtogroup ArangoDB
|
|
||||||
/// @{
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -256,17 +237,13 @@ namespace triagens {
|
||||||
/// @brief collection id => collection struct map
|
/// @brief collection id => collection struct map
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mutable std::map<std::string, const TRI_vocbase_col_t*> _resolvedNames;
|
mutable std::unordered_map<std::string, TRI_vocbase_col_t const*> _resolvedNames;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief collection id => collection name map
|
/// @brief collection id => collection name map
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mutable std::map<TRI_voc_cid_t, std::string> _resolvedIds;
|
mutable std::unordered_map<TRI_voc_cid_t, std::string> _resolvedIds;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue