1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
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 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.
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 #ifndef anna_dbos_Object_hpp
38 #define anna_dbos_Object_hpp
40 #include <anna/core/RuntimeException.hpp>
42 #include <anna/dbms/DatabaseException.hpp>
44 #include <anna/dbos/Loader.hpp>
53 Interfaz que deben cumplir los objetos persistentes.
55 Ejemplo de definicion de una clase usando esta interfaz:
57 \include dbos_demo.p/oodb.d/hdrs/dbos_demo.oodb.Table01.h
59 Ejemplo de implementacion de la clase correspondiente a la definicion:
61 \include dbos_demo.p/oodb.d/oodb.Table01.cc
66 Devuelve el indice asociado a este objeto
67 \return el indice asociado a este objeto
69 Index getIndex() const throw() { return a_index; }
72 * Devuelve \em true si este objeto ya existe en el medio físico (fué cargado desde allí o fue creado y grabado posteriormente) o
73 * \em false si este objeto sólo existe en la memoria intermedia.
74 * \return \em true si este objeto ya existe en el medio físico (fué cargado desde allí o fue creado y grabado posteriormente) o
75 * \em false si este objeto sólo existe en la memoria intermedia.
77 bool isStored() const throw() { return a_isStored; }
83 Object() : a_index(0), a_isStored(false) {;}
86 Inicializa este objeto con la informacion obtenida desde el medio fisico donde
87 esta grabado el objeto. Normalmente este medio fisico correspondera con una base de datos.
89 \param loader Cargador que contiene la informacion con la que debemos inicializar este objeto.
92 virtual void initialize(Loader& loader) throw(RuntimeException, dbms::DatabaseException) = 0;
95 Actualiza la informacion de este objeto con la nueva informacion obtenida del medio
97 \param creator Creador que contiene la informacion con la que debemos inicializar este objeto.
99 virtual void create(Creator& creator) throw(RuntimeException, dbms::DatabaseException) {;}
102 Libera los recursos reservados por este objeto. Este metodo solo se invocara cuando el objeto
103 vaya a ser sacado definitivamente del area de almacenamiento.
105 virtual void destroy() throw() {;}
108 Devuelve \em true si el registro del medio fisico ha cambiado respecto al registro
109 cargado en memoria o \em false en otro caso.
111 \param loader Cargador que contiene la informacion con la que deberiamos re-inicializar
114 \return \em true si el registro del medio fisico ha cambiado respecto al registro
115 cargado en memoria o \em false en otro caso.
117 virtual bool hasChanges(Loader& loader) throw(RuntimeException, dbms::DatabaseException) {
122 Devuelve \em true si el objeto requiere comenzar el proceso de comprobacion de recarga
123 de datos \em false en otro caso.
125 virtual bool enableUpdate() const throw() { return true; }
131 void setIndex(const Index index) throw() { a_index = index; }
133 friend class StorageArea;