From b5c79d89f0c251af78a69fad9e5b6f4e0c64595c Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Thu, 24 Apr 2008 22:16:48 +0200 Subject: [PATCH] Added a manager for Social. --- src/DB/Managers/SocialManager.cpp | 68 +++++++++++++++++++++++++++++++++++++++ src/DB/Managers/SocialManager.h | 45 ++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/DB/Managers/SocialManager.cpp create mode 100644 src/DB/Managers/SocialManager.h diff --git a/src/DB/Managers/SocialManager.cpp b/src/DB/Managers/SocialManager.cpp new file mode 100644 index 0000000..30f9871 --- /dev/null +++ b/src/DB/Managers/SocialManager.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sverre Rabbelier * + * sverre@rabbelier.nl * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "SocialManager.h" +#include "Social.h" +#include "TableImpls.h" +#include "FieldImpls.h" + +using mud::SocialManager; +using mud::Social; +using mud::SocialPtr; + +std::vector SocialManager::List() +{ + SelectionMaskPtr mask(new SelectionMask(GetTable())); + return GetTable()->tableList(mask); +} + +TableImplPtr SocialManager::GetTable() +{ + return db::TableImpls::Get()->SOCIALS; +} + +KeysPtr SocialManager::Add() +{ + SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->SOCIALS); + + bool locked = manager->lock(); + Assert(locked); // new manager, should always be unlocked + + manager->save(); + + manager->unlock(); + return manager->getKeys(); +} + +mud::SocialPtr SocialManager::GetByKey(value_type id) +{ + KeyValuePtr key(new KeyValue(db::TableImpls::Get()->SOCIALS->SOCIALID, id)); + SavableManagerPtr manager = SavableManager::bykey(key); + SocialPtr p(new Social(manager)); + return p; +} + +mud::SocialPtr SocialManager::GetByName(cstring name) +{ + FieldValuePtr value(new FieldValue(db::TableImpls::Get()->SOCIALS->NAME, name)); + SavableManagerPtr manager = SavableManager::byvalue(value); + SocialPtr p(new Social(manager)); + return p; +} diff --git a/src/DB/Managers/SocialManager.h b/src/DB/Managers/SocialManager.h new file mode 100644 index 0000000..fabab1b --- /dev/null +++ b/src/DB/Managers/SocialManager.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2008 by Sverre Rabbelier * + * sverre@rabbelier.nl * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#pragma once + +#include "SavableHeaders.h" +#include "SavableTypes.h" + +namespace mud +{ + class SocialManager + { + public: + TableImplPtr GetTable(); + std::vector List(); + + KeysPtr Add(); + mud::SocialPtr GetByKey(value_type id); + mud::SocialPtr GetByName(cstring name); + + private: + SocialManager(void) {}; + SocialManager(const SocialManager& rhs); + SocialManager operator=(const SocialManager& rhs); + ~SocialManager(void) {}; + + friend class mud::Managers; + }; +} -- 2.11.4.GIT