Revert "Remove mysql and oracle resources for anna-ericsson project"
[anna.git] / source / dbos / Repository.cpp
diff --git a/source/dbos/Repository.cpp b/source/dbos/Repository.cpp
new file mode 100644 (file)
index 0000000..49dd961
--- /dev/null
@@ -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 <stdlib.h>
+
+#include <anna/core/tracing/Logger.hpp>
+
+#include <anna/xml/Node.hpp>
+#include <anna/xml/Attribute.hpp>
+
+#include <anna/dbos/Repository.hpp>
+#include <anna/dbos/StorageArea.hpp>
+#include <anna/dbos/internal/sccs.hpp>
+
+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;
+}
+