summaryrefslogtreecommitdiffstats
path: root/relmddif/dbmddobj.hh
blob: edd0ea14c79c9678370884d1fe24c6978da90189 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
#ifndef _DBMDDOBJ_HH_
#define _DBMDDOBJ_HH_

#include <iostream>
class ObjectBroker;
class BaseType;
class MDDBaseType;
class OIdIf;
class r_Minterval;
class r_Error;
class DBMinterval;

#include "mddid.hh"
#include "relindexif/indexid.hh"
#include "reladminif/dbobject.hh"
#include "raslib/mddtypes.hh"
#include "relstorageif/storageid.hh"
#include "relstorageif/dbstoragelayout.hh"

//@ManMemo: Module: {\bf relmddif}
/*@Doc:
A {\tt DBMDDObj} object links all neccessary persistent data for an MDD
object.  One DBMDDObj can be inserted in multiple MDD Collections.  It will
only be deleted from the database when there are no more references in MDD
Collections.  This is done through persistent reference counting.

The DBMDDObj stores the following data:
-MDDBaseType: type information on the data that is stored in it.
-Definition domain: the spatial domain this object may extend to.  This
 domain may have open boundaries.
-Index: a refernce to the index which holds the actual data.
-Storagelayout: has asorted methods for modifying how the data is stored in the database.
The definition domain is stored in an extensible but inefficient way.
*/
/**
  * \defgroup Relmddifs Relmddif Classes
  */

/**
  * \ingroup Relmddifs
  */

class DBMDDObj	:	public DBObject
	{
	public:
		DBMDDObj(	const MDDBaseType* type,
				const r_Minterval& domain,
				const DBObjectId& i,
				const DBStorageLayoutId& s,
				const OId& theMDDObj) throw (r_Error);
		/*@Doc:
			type: it contains the basetype which will be used to create perstiles.
			domain: the definition domain.  the extend to which the mdd object may grow.
			i: the index structure which should be used.  there has to be some way to use DBRef<IndexDS>.
			s: the storage layout object.
			theMDDObj: this oid may not be assigned to an mdd object yet!
		*/
		
		DBMDDObj(	const MDDBaseType* newMDDType,
				const r_Minterval& domain,
				const DBObjectId& newObjIx,
				const DBStorageLayoutId& newSL);
		/*@Doc:
			newMDDType: it contains the basetype which will be used to create perstiles.
			domain: the definition domain.  the extend to which the mdd object may grow.
			newObjIx: the index structure which should be used.  there has to be some way to use DBRef<IndexDS>.
			s: the storage layout object.
			The oid is generated by the object itself.
		*/

		const MDDBaseType* getMDDBaseType() const; 
		/*@Doc:
			return the mddbasetype for this object.
		*/

		DBStorageLayoutId getDBStorageLayout() const;
		/*@Doc:
			return the storage layout object for this mdd object.
		*/

		const char* getCellTypeName() const;
		/*@Doc:
			Returns the name of the base type of this MDD object cells.
		*/
		
		const BaseType* getCellType() const;
		/*@Doc:
			Returns the base type of this MDD object cells.
		*/

		r_Dimension dimensionality() const;
		/*@Doc:
			Returns dimensionality of the object.
		*/
		
		r_Minterval getDefinitionDomain() const;
		/*@Doc:
			Returns the definition domain of the object.
		*/
		
		r_Bytes getHeaderSize() const;
		/*@Doc:
			Returns the size of the header for an MDD object.
			The size returned by this funtion is an approximation to
			the size of	the actual physical storage space used by the
			base DBMS. In the current implementation:
			HeaderSize = MDDBaseType*Size + r_Minterval*Size + 
				DBMDDObjIxSize + DBObjectSize
			This should be reviewed and renamed to
				getPhysicalStorageSize
		*/

		virtual void printStatus(unsigned int level = 0, std::ostream& stream = cout) const;
		/*@Doc:
			Prints the status of the object:
			the name of the cell type
			the definition domain
			the index contents
		*/

		void setIx(const DBObjectId& newObjIx);
		/*@Doc:
			make the mdd object use newObjIx instead of its old index structure.
			the old index structure is not deleted from the database!
		*/
		
		DBObjectId getDBIndexDS() const;
		/*@Doc:
			Returns the reference to the index.
		*/
  
		DBMDDObj(const DBMDDObj& old);
		/*@Doc:
			Copy constructor should never be used.
			Should raise a r_Error.
		*/

		virtual ~DBMDDObj();
		/*@Doc:
			Validates the object and deletes the definition domain.
		*/

		virtual void setPersistent(bool t = true) throw (r_Error);
		/*@Doc:
			Was overridden to pass changes to definition domain, storage layout  and
			to the index.
		*/

		virtual void setCached(bool ic);
		/*@Doc:
			overrides DBObject to handle the DBMinterval
		*/

		void incrementPersRefCount();
		/*@Doc:
			used by mddset to tell the mddobj that there is an
			additional mddset ref to it
		*/
		
		void decrementPersRefCount();
		/*@Doc:
			used by mddset to tell the mddobj that there is an mddset
			ref less to it
		*/
		
		int getPersRefCount() const;
		/*@Doc:
			returns the number of persistent references to this object.  
			when zero, the object may be deleted
		*/

		virtual r_Bytes getMemorySize() const;
		/*@Doc:
			Calculates the size of this object in main memory.
		*/
	
	protected:
		friend class ObjectBroker;

		DBMDDObj(const OId& id) throw (r_Error);
		/*@Doc:
			Constructs a DBMDDObj from the database.
		*/

		virtual void insertInDb() throw (r_Error);
		/*@Doc:
			
		*/

		virtual void deleteFromDb() throw (r_Error);
		/*@Doc:
			
		*/

		virtual void readFromDb() throw (r_Error);
		/*@Doc:
			
		*/
		
		virtual void updateInDb() throw (r_Error);
		/*@Doc:
			
		*/
			
	private:

		int persistentRefCount;
		/*@Doc:
			number of persistent references (by mddsets) to this object
		*/
		
		DBMDDObj();
		/*@Doc:
			creates an empty object and does NOT register it
			with ObjectBroker.
		*/

		const MDDBaseType* mddType;
		/*@Doc:
			Type of this object.
		*/
			
		DBMinterval* myDomain;
		/*@Doc:
			Definition domain for the object.
		*/
		
		DBStorageLayoutId storageLayoutId;
		/*@Doc:
			StorageLayout OId
		*/

		DBObjectId objIxId;
		/*@Doc:
			Index OId
		*/
	};

#endif