rasdaman base DBMS
dbobject.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 */
23 #ifndef _DBOBJECT_HH_
24 #define _DBOBJECT_HH_
25 
26 class DBObject;
27 class EOId;
28 
29 template <class T> class DBRef;
30 
31 #include <iosfwd>
32 
33 #include "oidif.hh"
34 #include "raslib/mddtypes.hh"
35 #include "raslib/error.hh"
36 #include "binaryrepresentation.hh"
37 
38 #ifdef RMANBENCHMARK
39 #include "raslib/rmdebug.hh"
40 #endif
41 
43 
44 //@ManMemo: Module: {\bf reladminif}.
45 /*@Doc:
46 Base class for all persistent classes. it supplies functionality for reference counting,
47 management by ObjectBroker, modification management, cache size.
48 
49 a persistent DBObject has a unique OId. this oid identifies it in the database.
50 */
54 class DBObject
55 {
56 public:
57  virtual void destroy(void);
58  /*@Doc:
59  deletes the object if and only if
60  the refence count is zero and
61  the object is not cached and
62  the transaction is not readonly.
63  */
64 
65  int getReferenceCount(void) const;
66  /*@Doc:
67  Returns the number of references that exist for this object
68  */
69 
70  void incrementReferenceCount(void);
71  /*@Doc:
72  Reference counting functions. These should be private with friend DBRef, but the compiler
73  doesn't allow friend template classes, only instances. Don't call directly, only DBRef
74  is allowed to.
75  */
76 
77  void decrementReferenceCount(void);
78  /*@Doc:
79  Reference counting functions. These should be private with friend DBRef, but the compiler
80  doesn't allow friend template classes, only instances. Don't call directly, only DBRef
81  is allowed to.
82  */
83 
84  virtual ~DBObject();
85  /*@Doc:
86  deregisters this object with the ObjectBroker.
87  the oid is not invalidated to allow the ObjectBroker to kill it.
88  */
89 
90  DBObject();
91  /*@Doc:
92  initializes all attributes. the oid is set to 0. the objecttype is set to OId::INVALID.
93  */
94 
95  DBObject(const DBObject& old);
96  /*@Doc:
97  clones all attributes.
98  */
99 
100  DBObject(const OId& id) throw (r_Error);
101  /*@Doc:
102  initializes only referenceCount, myOId, objecttype. _isCached is set to 0.
103  Subclasses may contain a call to readFromDb which can throw a r_Error_ObjectUnknown
104  or database related exception.
105  */
106 
107  virtual void setPersistent(bool newPersistent) throw (r_Error);
108  /*@Doc:
109  setPersistent(true) makes the object persistent as soon as validate is called.
110  a r_Error_TransactionReadOnly is thrown when the transaction is readonly.
111  setPersistent(false) deletes the object from the database as soon as validate is called.
112  if the state of the object changes in a read only transaction
113  (e.g. persistent->non persistent) a r_Error_TransactionReadOnly is thrown.
114  */
115 
116  bool isPersistent() const;
117  /*@Doc:
118  tells if an object is persistent.
119  */
120 
121  void validate() throw (r_Error);
122  /*@Doc:
123  writes the object to database/deletes it or updates it.
124  any r_Errors from insertInDb, updateInDb, deleteFromDb, readFromDb are passed to the
125  caller.
126  */
127 
128  virtual void setModified() throw (r_Error);
129  /*@Doc:
130  marks this object dirty.
131  a r_Error_TransactionReadOnly should be thrown when the transaction is readonly.
132  this is because of o2 related stuff in dbmddobject. should be taken care of.
133  */
134 
135  bool isModified() const;
136  /*@Doc:
137  tells if this object is dirty.
138  */
139 
140  OId getOId() const;
141  /*@Doc:
142  returns the oid of this object
143  */
144 
145  EOId getEOId() const;
146  /*@Doc:
147  returns the EOId of this object.
148  */
149 
150  OId::OIdType getObjectType() const;
151  /*@Doc:
152  returns the type of this object (MDDSet, ...). objects which are not
153  yet persistent also return their object type.
154  */
155 
156  DBObject& operator=(const DBObject& old);
157  /*@Doc:
158  clones all DBObject attributes except reference count.
159  */
160 
161  bool isCached() const;
162  /*@Doc:
163  tells if this object is cached.
164  */
165 
166  virtual void setCached(bool newCached);
167  /*@Doc:
168 
169  */
170 
171  virtual r_Bytes getMemorySize() const;
172  /*@Doc:
173  returns the memory space used by this object.
174  */
175 
176  virtual void printStatus(unsigned int level = 0, std::ostream& stream = std::cout) const;
177  /*@Doc:
178  prints the indent, OIdType, myOId as long and myOId as double.
179  */
180 
181  virtual r_Bytes getTotalStorageSize() const;
182  /*@Doc:
183  returns the space taken up by this object in the database.
184  as dbobject has no persistent attributes it returns 0.
185  */
186 
187  virtual BinaryRepresentation getBinaryRepresentation() const throw (r_Error);
188  /*@Doc:
189  returns the binary representation fit for storage in the database
190  */
191 
192  virtual void setBinaryRepresentation(const BinaryRepresentation&) throw (r_Error);
193  /*@Doc:
194  set the objects state from the binary represenation
195  */
196 
197  virtual char* getBinaryName() const;
198  /*Doc:
199  create the name for binary represenation from the oid
200  */
201 
202 #ifdef RMANBENCHMARK
203  static RMTimer readTimer;
204 
205  static RMTimer updateTimer;
206 
207  static RMTimer insertTimer;
208 
209  static RMTimer deleteTimer;
210 #endif
211 
212 protected:
213  virtual void release();
214  /*@Doc:
215  releases all dynamic memory (references to other persistent obkjects).
216  this is needed for cross transactional caches.
217  dbobject does not have any dynamic memory.
218  */
219 
220  virtual void readFromDb() throw (r_Error);
221  /*@Doc:
222  reads the object from database. myOId must be set!!!
223  a r_Error_ObjectUnknown is thrown when the oid is not in the database.
224  */
225 
226  virtual void insertInDb() throw (r_Error);
227  /*@Doc:
228  writes the object into the database. the object must not be in the database.
229  a r_Error_TransactionReadOnly is thrown when the transaction is readonly.
230  this implementation checks for readOnlyTA
231  */
232 
233  virtual void deleteFromDb() throw (r_Error);
234  /*@Doc:
235  deletes an object in the database.
236  a r_Error_TransactionReadOnly is thrown when the transaction is readonly.
237  this implementation checks for readOnlyTA
238  */
239 
240  virtual void updateInDb() throw (r_Error);
241  /*@Doc:
242  updates an existing object in the database
243  a r_Error_TransactionReadOnly is thrown when the transaction is readonly.
244  this implementation checks for readOnlyTA
245  */
246 
248  /*@Doc:
249  tells, if this object should be in the database or not.
250  */
251 
253  /*@Doc:
254  tells, if this object is already in the database.
255  */
256 
258  /*@Doc:
259  tells, if this object has changed an should be updated in the database.
260  */
261 
262  bool _isCached;
263  /*@Doc:
264  tells , if this objects is cached or not
265  */
266 
268  /*@Doc:
269  the oid of this object. is set by setPersistent(1) or by the constructor
270  of optional persistent objects (types).
271  */
272 
274  /*@Doc:
275  the type of this object. needed by setPersistent(1) to allocate the correct oid.
276  */
277 
279  /*@Doc:
280  The number of references that exist for this file. Use get_reference() for reading
281  its value from derived classes. Modified by incr_reference and decr_reference.
282  */
283 
284 private:
285 
286  void sharedObjectInit(void);
287  /*@Doc:
288  Initialization code shared by all constructors.
289  does not do anything.
290  */
291 };
292 
293 #endif
virtual void insertInDb()
bool _isModified
Definition: dbobject.hh:257
void decrementReferenceCount(void)
virtual void printStatus(unsigned int level=0, std::ostream &stream=std::cout) const
OId getOId() const
Definition: eoid.hh:52
EOId getEOId() const
virtual void destroy(void)
virtual ~DBObject()
virtual void deleteFromDb()
Definition: dbobject.hh:29
virtual char * getBinaryName() const
virtual void release()
bool _isInDatabase
Definition: dbobject.hh:252
bool isModified() const
virtual void setModified()
virtual r_Bytes getTotalStorageSize() const
Definition: oidif.hh:67
bool _isPersistent
Definition: dbobject.hh:247
void incrementReferenceCount(void)
virtual void setPersistent(bool newPersistent)
DBObject & operator=(const DBObject &old)
virtual void updateInDb()
OId::OIdType getObjectType() const
int getReferenceCount(void) const
OIdType
Definition: oidif.hh:70
int referenceCount
Definition: dbobject.hh:278
virtual r_Bytes getMemorySize() const
bool _isCached
Definition: dbobject.hh:262
virtual BinaryRepresentation getBinaryRepresentation() const
virtual void setBinaryRepresentation(const BinaryRepresentation &)
DBRef< DBObject > DBObjectId
Definition: dbobject.hh:29
virtual void setCached(bool newCached)
OId myOId
Definition: dbobject.hh:267
OId::OIdType objecttype
Definition: dbobject.hh:273
Definition: binaryrepresentation.hh:26
bool isPersistent() const
void validate()
bool isCached() const
Definition: dbobject.hh:54
virtual void readFromDb()