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/File.hpp"
20 #include "../filesystem/Directory.hpp"
23 #include "Directory.hpp"
27 using namespace workdir;
30 storage::File::Loader* storage::File::st_loader = NULL;
33 ExclusiveHash <std::string> storage::File::st_hash;
36 int storage::File::st_maxSize = 0;
38 dbos_prepare_object (storage::File);
40 void storage::File::setup (dbos::Repository& repository, const int maxSize)
41 throw (RuntimeException)
43 st_loader = new File::Loader ();
46 File::setStorageArea (
47 repository.createStorageArea ( // (1)
48 File::getStorageAreaId (), File::getStorageAreaName (), File::getMaxSize (),
54 storage::File* storage::File::instantiate (const filesystem::File* file)
55 throw (RuntimeException)
57 if (st_loader == NULL)
58 throw RuntimeException ("storage::File::setup no ha sido invocado", ANNA_FILE_LOCATION);
63 Guard guard (st_loader, "storage::File::Loader");
64 result = dbos::ObjectFacade <File>::instance (st_loader->setKey (file));
66 catch (dbms::DatabaseException& edb) {
67 throw RuntimeException (edb);
73 void storage::File::initialize (dbos::Loader& loader)
74 throw (RuntimeException, dbms::DatabaseException)
76 File::Loader& dbLoader = static_cast <File::Loader&> (loader);
78 a_filesystemFile = dbLoader.getFile ();
79 a_parent = Directory::instantiate (filesystem::Directory::down_cast (a_filesystemFile->getParent ()));
80 a_inode = dbLoader.getINode ();
83 string msg ("storage::File::initialize | ");
85 Logger::information (msg, ANNA_FILE_LOCATION);
89 void storage::File::destroy ()
93 string msg ("storage::File::destroy | ");
95 Logger::information (msg, ANNA_FILE_LOCATION);
97 Directory::release (a_parent);
100 string storage::File::asString () const
103 std::string result ("storage::File { Name: ");
104 result += a_filesystemFile->getPath ();
105 result += functions::asHexText (" | I-Node: ", a_inode);
106 return result += " }";
110 * Transfiere la información del medio físico al primer nivel de C++.
111 * Posteriormente será interpretada en storage::File::initialize
113 bool storage::File::Loader::load (dbms::Connection*, const dbos::StorageArea* ssaa)
114 throw (RuntimeException)
116 a_inode = io::functions::getINode (a_filesystemFile->getPath ());
120 dbos::Index storage::File::Loader::getIndex () const
123 return st_hash.calcule (a_filesystemFile->getPath ());
126 string storage::File::Loader::asString () const
129 std::string result ("storage::Loader::File { Name: ");
130 result += a_filesystemFile->getPath ();
131 return result += " }";