rasdaman complete source
typefactory.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 /*************************************************************
24  *
25  *
26  * PURPOSE:
27  *
28  *
29  * COMMENTS:
30  *
31  ************************************************************/
32 
33 #ifndef _TYPEFACTORY_HH_
34 #define _TYPEFACTORY_HH_
35 
36 class TypeFactory;
37 
38 #include <vector>
39 #include <map>
40 
41 #include "reladminif/oidif.hh"
43 
44 class ULongType;
45 class LongType;
46 class CharType;
47 class BoolType;
48 class UShortType;
49 class ShortType;
50 class OctetType;
51 class DoubleType;
52 class FloatType;
53 class ComplexType1;
54 class ComplexType2;
55 class StructType;
56 class BaseType;
57 class SetType;
58 class MDDType;
59 class Type;
60 class DBMinterval;
61 
62 //@ManMemo: Module: {\bf relcatalogif}.
63 
64 /*@Doc:
65 
66 The user specifies types as strings. This is passed down to the
67 TypeFactory where according to the string the object representing
68 the type is read from the database. The base DBMS manages
69 persistent objects for all base types. Pointers to these
70 persistent objects are returned if #mapType# is called. In the
71 current implementation, these pointers get invalid after a
72 transaction is committed. So the user has to call #mapType# again
73 after a commit(most programs do this anyway).
74 
75 The name of the type used for accessing it is the class name without
76 the Type suffix. e.g. "Bool" for \Ref{BoolType} or "ULong" for
77 \Ref{ULongType}.
78 
79 Only one instance of TypeFactory exists at any time. Also only one
80 instance of the types exits in memory. The pointers returned
81 should not be freed, the memory is freed, when the TypeFactory is
82 destroyed. The static member function can also be called directly
83 with the scope operator. The class follows the singleton design
84 pattern(Gamma et. al. S. 127ff.) and the builder design pattern
85 (Gamma et. al. S. 97ff.).
86 
87 {\bf Functionality}
88 
89 Returns a pointer to \Ref{BaseType} to the type which is identified by
90 a string.
91 
92 {\bf Interdependencies}
93 
94 Will be used from \Ref{MDDObject} and subclasses when created.
95 Because all types are stored persistently, it is necessary to open
96 a session using AdminIf::instance()(see \Ref{AdminIf}), a
97 database using DatabaseIf::open()(see \Ref{DatabaseIf) and a
98 transaction using TransactionIf::begin(see \Ref{TransactionIf)
99 before creating instances of types with mapType().
100 */
101 
106 {
107 public:
108  static TypeFactory* instance();
109  /*@Doc:
110  used to access instance of TileFactory.
111  */
112 
113  static const BaseType* mapType(const char* typeName);
114  /*@Doc:
115  maps a string to a base type
116  e.g. #aTypeFactory->mapType("ULong")# returns a pointer to an
117  instance of ULongType. This also works for user defined type
118  like #aTypeFactory->mapType("myStruct")# returning a pointer
119  to a user defined StructType.
120  */
121 
122  //static BaseType* mapType(char* typeName);
123  /*@Doc:
124  maps a string to a base type
125  use the const char* version!!
126  */
127 
128  static const SetType* mapSetType(const char* typeName);
129  /*@Doc:
130  maps a string to a set type
131  */
132 
133  //static const SetType* mapSetType(char* typeName);
134  /*@Doc:
135  maps a string to a set type
136  use the const char* version!!
137  */
138 
139  static const MDDType* mapMDDType(const char* typeName);
140  /*@Doc:
141  maps a string to a mdd type
142  */
143 
144  //static const MDDType* mapMDDType(char* typeName);
145  /*@Doc:
146  maps a string to a mdd type.
147  use the const char* version!!
148  */
149 
150  static const StructType* addStructType(const StructType* type);
151  /*@Doc:
152  add a new struct type to the current DBMS.
153  After calling this function, a user defined type can be
154  retrieved with function #mapType()#. The type only becomes
155  persistent after commit.
156  */
157 
158  static const SetType* addSetType(const SetType* type);
159  /*@Doc:
160  add a new set type to the current DBMS.
161  After calling this function, a user defined set type can be
162  retrieved with function #mapSetType()#. The type only becomes
163  persistent after commit.
164  */
165 
166  static const MDDType* addMDDType(const MDDType* type);
167  /*@Doc:
168  add a new set type to the current DBMS.
169  After calling this function, a user defined mdd type can be
170  retrieved with function #mapMDDType()#. The type only becomes
171  persistent after commit.
172  */
173 
174  static void deleteStructType(const char* typeName);
175  /*@Doc:
176  delete a struct type in the current DBMS.
177  */
178 
179  static void deleteSetType(const char* typeName);
180  /*@Doc:
181  delete a set type in the current DBMS.
182  */
183 
184  static void deleteMDDType(const char* typeName);
185  /*@Doc:
186  delete a mdd type in the current DBMS.
187  */
188 
189  static void deleteTmpSetType(const char* typeName);
190  /*@Doc:
191  delete a temporary set type in the current DBMS, created by a select into
192  */
193 
194  static void deleteTmpMDDType(const char* typeName);
195  /*@Doc:
196  delete a temporary mdd type in the current DBMS, created by a select into
197  */
198 
199  static TypeIterator<StructType> createStructIter();
200  /*@Doc:
201  Note that get_element returns a pointer to a StructType!
202  returns an iterator for StructTypes.
203  */
204 
205  static TypeIterator<SetType> createSetIter();
206  /*@Doc:
207  Note that get_element returns a pointer to a SetType!
208  returns an iterator for SetTypes.
209  */
210 
211  static TypeIterator<MDDType> createMDDIter();
212  /*@Doc:
213  Note that get_element returns a pointer to a MDDType!
214  returns an iterator for MDDTypes.
215  */
216 
217 
218  static Type* addTempType(Type* type);
219  /*@Doc:
220  Memory is freed at commit time of transaction in
221  TransactionIf::commit(), TransactionIf::validate() and
222  TransactionIf::abort().
223 
224  {\em Note:} You have to use addTempType() on a composite type
225  (e.g. \Ref{SetType}) first before calling addTempType() on a
226  component(e.g. \Ref{MDDType}). Otherwise the component may be
227  freed first sometimes leading to a crash.
228  registers a temporary type with the type factory.
229  */
230 
231  static void initialize();
232  /*@Doc:
233  Should only be called by \Ref{TransactionIf}).
234  initializes after a begin transaction. theTempTypes are created.
235  */
236 
237  static void freeTempTypes();
238  /*@Doc:
239  Should only be called by \Ref{TransactionIf}).
240  frees temporary types.
241  */
242 
243  static const Type* ensurePersistence(Type* type);
244  /*@Doc:
245  This function has to be called on all types registered as
246  temporary types but getting persistent during query execution. The
247  type is deleted from the tempTypes list, i.e. not freed on end of
248  transaction. If a structurally equivalent type is found in the
249  database it will be used and a pointer to it returned. Note that
250  this currently works only for StructTypes!
251  has to be called on temporary types getting persistent.
252  */
253 
254  static const short MaxBuiltInId;
255 
256 protected:
257  TypeFactory();
258  /*@Doc:
259  constructor, can not be used from outside.
260  */
261 
262 private:
263  static TypeFactory* myInstance;
264  /*@Doc:
265  pointer to instance for Singleton pattern.
266  */
267 
268  static std::vector<Type*> *theTempTypes;
269  /*@Doc:
270  a vector containing pointers to temporary allocated types.
271  */
272 
273 };
274 
275 #endif
static TypeIterator< MDDType > createMDDIter()
Definition: longtype.hh:57
Definition: ushorttype.hh:55
Definition: settype.hh:57
Definition: floattype.hh:56
static void freeTempTypes()
static void deleteTmpSetType(const char *typeName)
static Type * addTempType(Type *type)
Definition: chartype.hh:58
static const StructType * addStructType(const StructType *type)
static const BaseType * mapType(const char *typeName)
static TypeFactory * instance()
static void deleteStructType(const char *typeName)
Definition: ulongtype.hh:56
Definition: octettype.hh:59
static const SetType * addSetType(const SetType *type)
Definition: structtype.hh:68
Definition: mddtype.hh:58
static TypeIterator< StructType > createStructIter()
static void deleteSetType(const char *typeName)
static const MDDType * addMDDType(const MDDType *type)
static const SetType * mapSetType(const char *typeName)
Definition: relcatalogif/complextype.hh:110
static const Type * ensurePersistence(Type *type)
Definition: relcatalogif/basetype.hh:66
static TypeIterator< SetType > createSetIter()
Definition: typefactory.hh:105
Definition: booltype.hh:58
static const short MaxBuiltInId
Definition: typefactory.hh:254
Definition: relcatalogif/type.hh:68
static const MDDType * mapMDDType(const char *typeName)
static void deleteTmpMDDType(const char *typeName)
static void deleteMDDType(const char *typeName)
Definition: relcatalogif/complextype.hh:74
Definition: dbminterval.hh:47
static void initialize()
Definition: shorttype.hh:58
Definition: doubletype.hh:56