Update date in Doxyfile
[anna.git] / source / dbos / Repository.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #include <stdlib.h>
10
11 #include <anna/core/tracing/Logger.hpp>
12
13 #include <anna/xml/Node.hpp>
14 #include <anna/xml/Attribute.hpp>
15
16 #include <anna/dbos/Repository.hpp>
17 #include <anna/dbos/StorageArea.hpp>
18 #include <anna/dbos/internal/sccs.hpp>
19
20 using namespace std;
21 using namespace anna;
22
23 dbos::Repository::Repository(const char* name) :
24   a_name(name) {
25   sccs::activate();
26 }
27
28 dbos::Repository::Repository(const std::string& name) :
29   a_name(name) {
30   sccs::activate();
31 }
32
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) ;
37
38   if(ii != a_storageAreas.end()) {
39     string msg(ii->second->asString());
40     msg += " | Already in use";
41     throw RuntimeException(msg, ANNA_FILE_LOCATION);
42   }
43
44   StorageArea* result = new StorageArea(name, maxSize, objectAllocator, accessMode, errorCode);
45   a_storageAreas.insert(container::value_type(index, result));
46   LOGDEBUG(
47     string msg("dbos::Repository::createStorageArea | Name: ");
48     msg += a_name;
49     msg += " | ";
50     msg += result->asString();
51     Logger::debug(msg, ANNA_FILE_LOCATION);
52   );
53   return result;
54 }
55
56 dbos::StorageArea* dbos::Repository::findStorageArea(const dbos::StorageId index)
57 throw() {
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;
61 }
62
63 void dbos::Repository::clear()
64 throw(RuntimeException) {
65   Guard guard(this, "dbos::Repository from clear");
66   LOGWARNING(
67     string msg("dbos::Repository::clear | Name: ");
68     msg += a_name;
69     Logger::warning(msg, ANNA_FILE_LOCATION);
70   );
71
72   for(storage_iterator ii = storage_begin(), maxii = storage_end(); ii != maxii; ii ++)
73     storageArea(ii)->clear();
74 }
75
76 xml::Node* dbos::Repository::asXML(xml::Node* parent) const
77 throw() {
78   xml::Node* result = parent->createChild("dbos.Repository");
79   dbos::Size maxSize(0);
80   dbos::Size size(0);
81   const StorageArea* ssaa;
82   result->createAttribute("Name", a_name);
83
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();
88     ssaa->asXML(result);
89   }
90
91   result->createAttribute("SizeOf", StorageArea::asMemorySize(size));
92   result->createAttribute("MaxSizeOf", StorageArea::asMemorySize(maxSize));
93   return result;
94 }
95