1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #include <anna/core/functions.hpp>
38 #include <anna/core/tracing/Logger.hpp>
40 #include <anna/io/functions.hpp>
42 #include <anna/dbms/Database.hpp>
43 #include <anna/dbms/Statement.hpp>
45 #include <anna/dbos/Repository.hpp>
47 #include "../filesystem/Directory.hpp"
49 #include "Directory.hpp"
53 using namespace workdir;
56 storage::Directory::Loader* storage::Directory::st_loader = NULL;
59 ExclusiveHash <std::string> storage::Directory::st_hash;
62 int storage::Directory::st_maxSize = 0;
64 dbos_prepare_object (storage::Directory);
66 void storage::Directory::setup (dbos::Repository& repository, const int maxSize)
67 throw (RuntimeException)
69 st_loader = new Directory::Loader ();
72 Directory::setStorageArea (
73 repository.createStorageArea ( // (1)
74 Directory::getStorageAreaId (), Directory::getStorageAreaName (), Directory::getMaxSize (),
75 Directory::allocator, 2
80 storage::Directory* storage::Directory::instantiate (const filesystem::Directory* directory)
81 throw (RuntimeException)
83 if (st_loader == NULL)
84 throw RuntimeException ("storage::Directory::setup no ha sido invocado", ANNA_FILE_LOCATION);
86 Directory* result = NULL;
89 Guard guard (st_loader, "storage::Directory::Loader");
90 result = dbos::ObjectFacade <Directory>::instance (st_loader->setKey (directory));
92 catch (dbms::DatabaseException& edb) {
93 throw RuntimeException (edb);
99 void storage::Directory::initialize (dbos::Loader& loader)
100 throw (RuntimeException, dbms::DatabaseException)
102 Directory::Loader& dbLoader = static_cast <Directory::Loader&> (loader);
104 a_filesystemDirectory = dbLoader.getDirectory ();
105 a_inode = dbLoader.getINode ();
108 string msg ("storage::Directory::initialize | ");
110 Logger::information (msg, ANNA_FILE_LOCATION);
114 void storage::Directory::destroy ()
118 string msg ("storage::Directory::destroy | ");
120 Logger::information (msg, ANNA_FILE_LOCATION);
124 string storage::Directory::asString () const
127 std::string result ("storage::Directory { Name: ");
128 result += a_filesystemDirectory->getPath ();
129 result += functions::asHexText (" | I-Node: ", a_inode);
130 return result += " }";
134 * Transfiere la información del medio físico al primer nivel de C++.
135 * Posteriormente será interpretada en storage::Directory::initialize
137 bool storage::Directory::Loader::load (dbms::Connection*, const dbos::StorageArea* ssaa)
138 throw (RuntimeException)
140 a_inode = io::functions::getINode (a_filesystemDirectory->getPath ());
144 dbos::Index storage::Directory::Loader::getIndex () const
147 return st_hash.calcule (a_filesystemDirectory->getPath ());
150 string storage::Directory::Loader::asString () const
153 std::string result ("storage::Loader::Directory { Name: ");
154 result += a_filesystemDirectory->getPath ();
155 return result += " }";