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 //
9 #include <anna/core/functions.hpp>
10 #include <anna/core/tracing/Logger.hpp>
12 #include <anna/io/functions.hpp>
14 #include <anna/dbms/Database.hpp>
15 #include <anna/dbms/Statement.hpp>
17 #include <anna/dbos/Repository.hpp>
19 #include "../filesystem/Directory.hpp"
21 #include "Directory.hpp"
25 using namespace workdir;
28 storage::Directory::Loader* storage::Directory::st_loader = NULL;
31 ExclusiveHash <std::string> storage::Directory::st_hash;
34 int storage::Directory::st_maxSize = 0;
36 dbos_prepare_object (storage::Directory);
38 void storage::Directory::setup (dbos::Repository& repository, const int maxSize)
41 st_loader = new Directory::Loader ();
44 Directory::setStorageArea (
45 repository.createStorageArea ( // (1)
46 Directory::getStorageAreaId (), Directory::getStorageAreaName (), Directory::getMaxSize (),
47 Directory::allocator, 2
52 storage::Directory* storage::Directory::instantiate (const filesystem::Directory* directory)
55 if (st_loader == NULL)
56 throw RuntimeException ("storage::Directory::setup no ha sido invocado", ANNA_FILE_LOCATION);
58 Directory* result = NULL;
61 Guard guard (st_loader, "storage::Directory::Loader");
62 result = dbos::ObjectFacade <Directory>::instance (st_loader->setKey (directory));
64 catch (dbms::DatabaseException& edb) {
65 throw RuntimeException (edb);
71 void storage::Directory::initialize (dbos::Loader& loader)
74 Directory::Loader& dbLoader = static_cast <Directory::Loader&> (loader);
76 a_filesystemDirectory = dbLoader.getDirectory ();
77 a_inode = dbLoader.getINode ();
80 string msg ("storage::Directory::initialize | ");
82 Logger::information (msg, ANNA_FILE_LOCATION);
86 void storage::Directory::destroy ()
90 string msg ("storage::Directory::destroy | ");
92 Logger::information (msg, ANNA_FILE_LOCATION);
96 string storage::Directory::asString () const
99 std::string result ("storage::Directory { Name: ");
100 result += a_filesystemDirectory->getPath ();
101 result += functions::asHexText (" | I-Node: ", a_inode);
102 return result += " }";
106 * Transfiere la información del medio físico al primer nivel de C++.
107 * Posteriormente será interpretada en storage::Directory::initialize
109 bool storage::Directory::Loader::load (dbms::Connection*, const dbos::StorageArea* ssaa)
112 a_inode = io::functions::getINode (a_filesystemDirectory->getPath ());
116 dbos::Index storage::Directory::Loader::getIndex () const
119 return st_hash.calcule (a_filesystemDirectory->getPath ());
122 string storage::Directory::Loader::asString () const
125 std::string result ("storage::Loader::Directory { Name: ");
126 result += a_filesystemDirectory->getPath ();
127 return result += " }";