Add no-deprecated to warnings due to dynamic exceptions.
[anna.git] / example / dbos / workdir / storage / Directory.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 <anna/core/functions.hpp>
10 #include <anna/core/tracing/Logger.hpp>
11
12 #include <anna/io/functions.hpp>
13
14 #include <anna/dbms/Database.hpp>
15 #include <anna/dbms/Statement.hpp>
16
17 #include <anna/dbos/Repository.hpp>
18
19 #include "../filesystem/Directory.hpp"
20
21 #include "Directory.hpp"
22
23 using namespace std;
24 using namespace anna;
25 using namespace workdir;
26
27 /*static*/
28 storage::Directory::Loader* storage::Directory::st_loader = NULL;
29
30 /*static*/
31 ExclusiveHash <std::string> storage::Directory::st_hash;
32
33 /*static*/
34 int storage::Directory::st_maxSize = 0;
35
36 dbos_prepare_object (storage::Directory);
37
38 void storage::Directory::setup (dbos::Repository& repository, const int maxSize)
39    throw (RuntimeException)
40 {
41    st_loader = new Directory::Loader ();
42    st_maxSize = maxSize;
43
44    Directory::setStorageArea (
45       repository.createStorageArea (                                                  // (1)
46          Directory::getStorageAreaId (), Directory::getStorageAreaName (), Directory::getMaxSize (),
47          Directory::allocator, 2
48       )
49    );
50 }
51
52 storage::Directory* storage::Directory::instantiate (const filesystem::Directory* directory)
53    throw (RuntimeException)
54 {
55    if (st_loader == NULL)
56       throw RuntimeException ("storage::Directory::setup no ha sido invocado", ANNA_FILE_LOCATION);
57
58    Directory* result = NULL;
59
60    try {
61       Guard guard (st_loader, "storage::Directory::Loader");
62       result = dbos::ObjectFacade <Directory>::instance (st_loader->setKey (directory));
63    }
64    catch (dbms::DatabaseException& edb) {
65       throw RuntimeException (edb);
66    }
67
68    return result;
69 }
70
71 void storage::Directory::initialize (dbos::Loader& loader)
72    throw (RuntimeException, dbms::DatabaseException)
73 {
74    Directory::Loader& dbLoader = static_cast <Directory::Loader&> (loader);
75    
76    a_filesystemDirectory = dbLoader.getDirectory ();
77    a_inode = dbLoader.getINode ();
78       
79    LOGINFORMATION (
80       string msg ("storage::Directory::initialize | ");
81       msg += asString ();
82       Logger::information (msg, ANNA_FILE_LOCATION);
83    );
84 }
85
86 void storage::Directory::destroy ()
87    throw ()
88 {
89    LOGINFORMATION (
90       string msg ("storage::Directory::destroy | ");
91       msg += asString ();
92       Logger::information (msg, ANNA_FILE_LOCATION);
93    );
94 }
95
96 string storage::Directory::asString () const
97    throw ()
98 {
99    std::string result ("storage::Directory { Name: ");
100    result += a_filesystemDirectory->getPath ();
101    result += functions::asHexText (" | I-Node: ", a_inode);
102    return result += " }";
103 }
104
105 /* 
106  * Transfiere la información del medio físico al primer nivel de C++.
107  * Posteriormente será interpretada en storage::Directory::initialize
108  */
109 bool storage::Directory::Loader::load (dbms::Connection*, const dbos::StorageArea* ssaa) 
110    throw (RuntimeException)
111 {
112    a_inode = io::functions::getINode (a_filesystemDirectory->getPath ());
113    return true;
114 }
115
116 dbos::Index storage::Directory::Loader::getIndex () const 
117    throw ()
118 {
119    return st_hash.calcule (a_filesystemDirectory->getPath ());   
120 }
121
122 string storage::Directory::Loader::asString () const
123    throw ()
124 {
125    std::string result ("storage::Loader::Directory { Name: ");
126    result += a_filesystemDirectory->getPath ();
127    return result += " }";
128 }
129