1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <anna/core/tracing/Logger.hpp>
13 #include <anna/xml/Node.hpp>
14 #include <anna/xml/Attribute.hpp>
16 #include <anna/dbos/Repository.hpp>
17 #include <anna/dbos/StorageArea.hpp>
18 #include <anna/dbos/internal/sccs.hpp>
23 dbos::Repository::Repository(const char* name) :
28 dbos::Repository::Repository(const std::string& name) :
33 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)
34 throw(RuntimeException) {
35 Guard guard(this, "dbos::Repository from createStorageArea");
36 storage_iterator ii = a_storageAreas.find(index) ;
38 if(ii != a_storageAreas.end()) {
39 string msg(ii->second->asString());
40 msg += " | Already in use";
41 throw RuntimeException(msg, ANNA_FILE_LOCATION);
44 StorageArea* result = new StorageArea(name, maxSize, objectAllocator, accessMode, errorCode);
45 a_storageAreas.insert(container::value_type(index, result));
47 string msg("dbos::Repository::createStorageArea | Name: ");
50 msg += result->asString();
51 Logger::debug(msg, ANNA_FILE_LOCATION);
56 dbos::StorageArea* dbos::Repository::findStorageArea(const dbos::StorageId index)
58 Guard guard(this, "dbos::Repository from findStorageArea");
59 storage_iterator ii = a_storageAreas.find(index);
60 return (ii != a_storageAreas.end()) ? storageArea(ii) : NULL;
63 void dbos::Repository::clear()
64 throw(RuntimeException) {
65 Guard guard(this, "dbos::Repository from clear");
67 string msg("dbos::Repository::clear | Name: ");
69 Logger::warning(msg, ANNA_FILE_LOCATION);
72 for(storage_iterator ii = storage_begin(), maxii = storage_end(); ii != maxii; ii ++)
73 storageArea(ii)->clear();
76 xml::Node* dbos::Repository::asXML(xml::Node* parent) const
78 xml::Node* result = parent->createChild("dbos.Repository");
79 dbos::Size maxSize(0);
81 const StorageArea* ssaa;
82 result->createAttribute("Name", a_name);
84 for(const_storage_iterator ii = storage_begin(), maxii = storage_end(); ii != maxii; ii ++) {
85 ssaa = storageArea(ii);
86 maxSize += ssaa->getMaxSizeOf();
87 size += ssaa->getSizeOf();
91 result->createAttribute("SizeOf", StorageArea::asMemorySize(size));
92 result->createAttribute("MaxSizeOf", StorageArea::asMemorySize(maxSize));