X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbos%2FRepository.cpp;fp=source%2Fdbos%2FRepository.cpp;h=49dd9611112f6cf27c2d3b5277123153dff30dd4;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/source/dbos/Repository.cpp b/source/dbos/Repository.cpp new file mode 100644 index 0000000..49dd961 --- /dev/null +++ b/source/dbos/Repository.cpp @@ -0,0 +1,95 @@ +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // + + +#include + +#include + +#include +#include + +#include +#include +#include + +using namespace std; +using namespace anna; + +dbos::Repository::Repository(const char* name) : + a_name(name) { + sccs::activate(); +} + +dbos::Repository::Repository(const std::string& name) : + a_name(name) { + sccs::activate(); +} + +dbos::StorageArea* dbos::Repository::createStorageArea(const dbos::StorageId index, const char* name, const dbos::Size maxSize, dbos::ObjectAllocator objectAllocator, const int errorCode, const StorageArea::AccessMode::_v accessMode) +throw(RuntimeException) { + Guard guard(this, "dbos::Repository from createStorageArea"); + storage_iterator ii = a_storageAreas.find(index) ; + + if(ii != a_storageAreas.end()) { + string msg(ii->second->asString()); + msg += " | Already in use"; + throw RuntimeException(msg, ANNA_FILE_LOCATION); + } + + StorageArea* result = new StorageArea(name, maxSize, objectAllocator, accessMode, errorCode); + a_storageAreas.insert(container::value_type(index, result)); + LOGDEBUG( + string msg("dbos::Repository::createStorageArea | Name: "); + msg += a_name; + msg += " | "; + msg += result->asString(); + Logger::debug(msg, ANNA_FILE_LOCATION); + ); + return result; +} + +dbos::StorageArea* dbos::Repository::findStorageArea(const dbos::StorageId index) +throw() { + Guard guard(this, "dbos::Repository from findStorageArea"); + storage_iterator ii = a_storageAreas.find(index); + return (ii != a_storageAreas.end()) ? storageArea(ii) : NULL; +} + +void dbos::Repository::clear() +throw(RuntimeException) { + Guard guard(this, "dbos::Repository from clear"); + LOGWARNING( + string msg("dbos::Repository::clear | Name: "); + msg += a_name; + Logger::warning(msg, ANNA_FILE_LOCATION); + ); + + for(storage_iterator ii = storage_begin(), maxii = storage_end(); ii != maxii; ii ++) + storageArea(ii)->clear(); +} + +xml::Node* dbos::Repository::asXML(xml::Node* parent) const +throw() { + xml::Node* result = parent->createChild("dbos.Repository"); + dbos::Size maxSize(0); + dbos::Size size(0); + const StorageArea* ssaa; + result->createAttribute("Name", a_name); + + for(const_storage_iterator ii = storage_begin(), maxii = storage_end(); ii != maxii; ii ++) { + ssaa = storageArea(ii); + maxSize += ssaa->getMaxSizeOf(); + size += ssaa->getSizeOf(); + ssaa->asXML(result); + } + + result->createAttribute("SizeOf", StorageArea::asMemorySize(size)); + result->createAttribute("MaxSizeOf", StorageArea::asMemorySize(maxSize)); + return result; +} +