X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdbos%2Fworkdir%2Fstorage%2FDirectory.cpp;fp=example%2Fdbos%2Fworkdir%2Fstorage%2FDirectory.cpp;h=7c35dc6b097274916f3fe61ca4b35c72be9f886e;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/example/dbos/workdir/storage/Directory.cpp b/example/dbos/workdir/storage/Directory.cpp new file mode 100644 index 0000000..7c35dc6 --- /dev/null +++ b/example/dbos/workdir/storage/Directory.cpp @@ -0,0 +1,129 @@ +// 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 "../filesystem/Directory.hpp" + +#include "Directory.hpp" + +using namespace std; +using namespace anna; +using namespace workdir; + +/*static*/ +storage::Directory::Loader* storage::Directory::st_loader = NULL; + +/*static*/ +ExclusiveHash storage::Directory::st_hash; + +/*static*/ +int storage::Directory::st_maxSize = 0; + +dbos_prepare_object (storage::Directory); + +void storage::Directory::setup (dbos::Repository& repository, const int maxSize) + throw (RuntimeException) +{ + st_loader = new Directory::Loader (); + st_maxSize = maxSize; + + Directory::setStorageArea ( + repository.createStorageArea ( // (1) + Directory::getStorageAreaId (), Directory::getStorageAreaName (), Directory::getMaxSize (), + Directory::allocator, 2 + ) + ); +} + +storage::Directory* storage::Directory::instantiate (const filesystem::Directory* directory) + throw (RuntimeException) +{ + if (st_loader == NULL) + throw RuntimeException ("storage::Directory::setup no ha sido invocado", ANNA_FILE_LOCATION); + + Directory* result = NULL; + + try { + Guard guard (st_loader, "storage::Directory::Loader"); + result = dbos::ObjectFacade ::instance (st_loader->setKey (directory)); + } + catch (dbms::DatabaseException& edb) { + throw RuntimeException (edb); + } + + return result; +} + +void storage::Directory::initialize (dbos::Loader& loader) + throw (RuntimeException, dbms::DatabaseException) +{ + Directory::Loader& dbLoader = static_cast (loader); + + a_filesystemDirectory = dbLoader.getDirectory (); + a_inode = dbLoader.getINode (); + + LOGINFORMATION ( + string msg ("storage::Directory::initialize | "); + msg += asString (); + Logger::information (msg, ANNA_FILE_LOCATION); + ); +} + +void storage::Directory::destroy () + throw () +{ + LOGINFORMATION ( + string msg ("storage::Directory::destroy | "); + msg += asString (); + Logger::information (msg, ANNA_FILE_LOCATION); + ); +} + +string storage::Directory::asString () const + throw () +{ + std::string result ("storage::Directory { Name: "); + result += a_filesystemDirectory->getPath (); + result += functions::asHexText (" | I-Node: ", a_inode); + return result += " }"; +} + +/* + * Transfiere la información del medio físico al primer nivel de C++. + * Posteriormente será interpretada en storage::Directory::initialize + */ +bool storage::Directory::Loader::load (dbms::Connection*, const dbos::StorageArea* ssaa) + throw (RuntimeException) +{ + a_inode = io::functions::getINode (a_filesystemDirectory->getPath ()); + return true; +} + +dbos::Index storage::Directory::Loader::getIndex () const + throw () +{ + return st_hash.calcule (a_filesystemDirectory->getPath ()); +} + +string storage::Directory::Loader::asString () const + throw () +{ + std::string result ("storage::Loader::Directory { Name: "); + result += a_filesystemDirectory->getPath (); + return result += " }"; +} +