Environment redesign and test/examples review. English API revisions
[anna.git] / example / dbos / workdir / storage / Directory.hpp
1 // ANNA - Anna is Not 'N' Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
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
16 // distribution.
17 //     * Neither the name of Google Inc. 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.
20 //
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.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #ifndef dbos_workdir_storage_Directory_hpp
38 #define dbos_workdir_storage_Directory_hpp
39
40 #include <anna/dbos/Object.hpp>
41 #include <anna/dbos/ObjectFacade.hpp>
42 #include <anna/dbos/Loader.hpp>
43
44 namespace anna {
45    namespace dbms {
46       class Database;
47       class Connection;
48    }
49    namespace dbos {
50       class Repository;
51    }
52 }
53
54 namespace workdir {
55
56 namespace filesystem {
57    class Directory;
58 }
59
60 namespace storage {
61
62 using namespace anna;
63
64 class Directory : public dbos::Object, public dbos::ObjectFacade <Directory> {
65 public:
66    const filesystem::Directory* getFilesystemDirectory () const throw () { return a_filesystemDirectory; }
67    int getINode () const throw () { return a_inode; }
68    
69    std::string asString () const throw ();
70
71    static void setup (dbos::Repository&, const int maxSize) throw (RuntimeException);
72    static Directory* instantiate (const filesystem::Directory*) throw (RuntimeException);
73    
74    static const char* getStorageAreaName () throw () { return "storage::Directory"; }   
75    static const dbos::Size getMaxSize () throw () { return st_maxSize; }   
76
77 private:
78    class Loader : public dbos::Loader {
79    public:
80       Loader () : dbos::Loader () {;}
81
82       Loader& setKey (const filesystem::Directory* directory) throw () {
83          a_filesystemDirectory = directory;
84          return *this; 
85       }
86       
87       const filesystem::Directory* getDirectory () const throw () { return a_filesystemDirectory; }  
88       int getINode () const throw () { return a_inode; }
89
90       dbos::Index getIndex () const throw ();
91       std::string asString () const throw ();
92
93    private:
94       const filesystem::Directory* a_filesystemDirectory;
95       int a_inode;
96
97       // dbms::Statement is not required
98       dbms::Statement* initialize (dbms::Database&) throw (RuntimeException) { return NULL; }
99       bool load (dbms::Connection*, const dbos::StorageArea*) throw (RuntimeException);
100    };
101
102    const filesystem::Directory* a_filesystemDirectory;   
103    int a_inode;
104    
105    static Loader* st_loader;
106    static ExclusiveHash <std::string> st_hash;
107    static int st_maxSize;
108    
109    Directory () { ; }
110    Directory (const Directory&);
111
112    void initialize (dbos::Loader& loader) throw (RuntimeException, dbms::DatabaseException);
113    void destroy () throw ();
114
115    dbos_declare_object (Directory);
116 };
117
118 }
119 }
120
121 #endif