From 03e6449d465e4ca41b89136f3f464da18414dcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 25 Jan 2012 12:26:46 +0100 Subject: [PATCH] Bug #1086: Re-implement cache key for User, Group and Host pools --- include/GroupPool.h | 14 ++++++++++++++ include/HostPool.h | 14 ++++++++++++++ include/PoolSQL.h | 2 +- include/UserPool.h | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/GroupPool.h b/include/GroupPool.h index 28afe2eba8..335a52c245 100644 --- a/include/GroupPool.h +++ b/include/GroupPool.h @@ -93,9 +93,23 @@ public: */ Group * get(const string& name, bool lock) { + // The owner is set to -1, because it is not used in the key() method return static_cast(PoolSQL::get(name,-1,lock)); }; + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + // Name is enough key because Groups can't repeat names. + return name; + }; + /** Update a particular Group * @param user pointer to Group * @return 0 on success diff --git a/include/HostPool.h b/include/HostPool.h index 700344ff1a..7bdc0bfc23 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -79,9 +79,23 @@ public: */ Host * get(string name, bool lock) { + // The owner is set to -1, because it is not used in the key() method return static_cast(PoolSQL::get(name,-1,lock)); }; + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + // Name is enough key because Hosts can't repeat names. + return name; + }; + /** * Bootstraps the database table(s) associated to the Host pool * @return 0 on success diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 822a5559b3..86c1fc0a05 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -273,7 +273,7 @@ private: * * @return the key, a string */ - string key(const string& name, int uid) + virtual string key(const string& name, int uid) { ostringstream key; diff --git a/include/UserPool.h b/include/UserPool.h index 20120b4c62..3926c71613 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -80,9 +80,23 @@ public: */ User * get(string name, bool lock) { + // The owner is set to -1, because it is not used in the key() method return static_cast(PoolSQL::get(name,-1,lock)); }; + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + // Name is enough key because Users can't repeat names. + return name; + }; + /** Update a particular User * @param user pointer to User * @return 0 on success