summaryrefslogtreecommitdiffstats
path: root/rasodmg/database.hh
blob: 7491eb02689fbaf8fd8720f45756ebb71fcdd9d0 (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
262
263
264
265
266
267
268
269
270
/*
* 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>.
/
/**
 * INCLUDE:  database.hh
 *
 * MODULE:   rasodmg
 * CLASS:    r_Database
 *
 *	COMMENTS:
 *		None
*/

#ifndef _D_DATABASE_
#define _D_DATABASE_

#include "raslib/rminit.hh"
#include "raslib/error.hh"
#include "rasodmg/object.hh"
#include "raslib/mddtypes.hh"

// forward declarations
class r_Object;
class r_Transaction;
class ClientComm;
class r_Ref_Any;

//@ManMemo: Module: {\bf rasodmg}

/*@Doc:

  A database object must be instantiated and opened before 
  starting any transaction which uses the database, and closed
  after ending these transactions.
  
*/

class r_Database
{
  public:
    /// possible database states 
    enum access_status { not_open, read_write, read_only, exclusive };

    /// possible types define by symbolic names
    enum type_schema {
	    CELL        = 3,
    	    MARRAY 	= 2,
	    COLLECTION  = 1
    		     };
    
    /// default constructor
    r_Database();
    
    /// constructor getting the rasmgr name
    r_Database( const char* name ) throw(r_Error);
    /**
      One error situations can occur which raise an exception of type \Ref{r_Error} with 
      one of the following kinds:    
      r_Error_NameInvalid     && Name is NULL.\\    
    */
    
    /// destructor
    ~r_Database();
    
    /// open a database
    void open( const char* database_name, access_status status = read_write )
      throw( r_Error );
    /**
      The method opens the database specified with {\tt database_name}. Several error
      situations can occur which raise an exception of type \Ref{r_Error} with 
      one of the following kinds:
      
      \begin{tabular}{lll}
      r_Error_HostInvalid     && Host can not be found.\\
      r_Error_ServerInvalid   && Server can not be found.\\
      r_Error_ClientUnknown   && Client is not known by the server (earlier communication problems).\\
      r_Error_DatabaseUnknown && Database does not exist.\\
      r_Error_DatabaseOpen    && Database is already open.\\
      r_Error_TransferFailed  && Other communication problem. \\
      r_Error_NameInvalid     && Name is NULL.\\          
      \end{tabular}      
    */
    
    /// close a database
    void close();
    
    /// create a database with fixed schema RasDaSchema
    void create( const char* name ) throw( r_Error );
    /**
      This method works only if a server host name has been specified with
      {\tt set_servername()}.
      One of error situations can occur will raise an exception of type \Ref{r_Error} with 
      one of the following kinds:    
      r_Error_NameInvalid     && Name is NULL.\\          
    */
    
    /// destroy a database
    void destroy( const char* name ) throw( r_Error );
     /**
      This method works only if a server host name has been specified with
      {\tt set_servername()}.
      One of error situations can occur will raise an exception of type \Ref{r_Error} with 
      one of the following kinds:    
      r_Error_NameInvalid     && Name is NULL.\\          
    */
   
    /// set the server name
    void set_servername( const char* name, int port = RASMGRPORT) throw(r_Error);
    /**
      One of error situations can occur will raise an exception of type \Ref{r_Error} with 
      one of the following kinds:    
      r_Error_NameInvalid     && Name is NULL.\\        
    */    
    /// set the user name and password
    void set_useridentification( const char* name, const char *plain_pass ) throw(r_Error);
    /**
      One of error situations can occur will raise an exception of type \Ref{r_Error} with 
      one of the following kinds:    
      r_Error_NameInvalid     && Name is NULL.\\        
    */
        
    /// get the actual status
    inline access_status get_status() const;
    
    /// give a name to an object (signature is not ODMG conformant because of compiler bug)
    void set_object_name( r_Object& obj, const char* name ) throw(r_Error);
    /**
      The method gives the {\tt name} to the object {\tt obj}. The name is used for
      further retrieval of the object. Right now, names can just be given to sets
      of type {\tt r_Set}.
      One of error situations can occur will raise an exception of type \Ref{r_Error} with 
      one of the following kinds:    
      r_Error_NameInvalid     && Name is NULL.\\        
    */
    
    /// lookup named objects in a database (must be called within open database and running transaction)
    r_Ref_Any lookup_object( const char* name ) const
      throw( r_Error );
    /**      
      The method looks up an object with {\tt name}. Right now, just objects of type \Ref{r_Set} are
      allowed. Error kinds:
      
      \begin{tabular}{lll}
      r_Error_ClientUnknown       && Client is not known by the server (earlier communication problems).\\
      r_Error_DatabaseClosed      && Database is not open. \\
      r_Error_TransactionNotOpen  && No transaction is active. \\
      r_Error_ObjectUnknown       && The object with {\tt name} is not in the database.\\
      r_Error_TransferFailed      && Other communication problem. \\
      r_Error_NameInvalid  	  && Name is NULL.\\              
      \end{tabular}      
    */    
    
    /// lookup objects by oids in a database (must be called within open database and running transaction)
    r_Ref_Any lookup_object( const r_OId& oid ) const
      throw( r_Error );
    /**      
      The method looks up an object with {\tt oid}. Right now, just objects of type \Ref{r_Set} and
      \Ref{r_GMarray} are allowed. 

      Error kinds:
      \begin{tabular}{lll}
      r_Error_ClientUnknown       && Client is not known by the server (earlier communication problems).\\
      r_Error_DatabaseClosed      && Database is not open. \\
      r_Error_TransactionNotOpen  && No transaction is active. \\
      r_Error_ObjectUnknown       && The object with {\tt oid} is not in the database.\\
      r_Error_TransferFailed      && Other communication problem. \\
      \end{tabular}      
    */    

	r_Type* get_type_schema(const char* typeName, type_schema typetype) throw (r_Error);
    /**      
      The method looks up the type structure with {\tt typeName} as its name.  typetype is 1 for marray and 2 for collection.

      Error kinds:
      \begin{tabular}{lll}
      r_Error_ClientUnknown       && Client is not known by the server (earlier communication problems).\\
      r_Error_DatabaseClosed      && Database is not open. \\
      r_Error_TransactionNotOpen  && No transaction is active. \\
      r_Error_ObjectUnknown       && The object with {\tt typeName} is not in the database.\\
      r_Error_TransferFailed      && Other communication problem. \\
      r_Error_TypeInvalid         && The typetype is neither 1 nor 2. \\
      r_Error_NameInvalid         && The typeName is neither NULL or is a "\0". \\
      \end{tabular}      
    */    


    /// set the transfer compression format, both for data sent from the server
    /// to the client and the other way around.
    void set_transfer_format( r_Data_Format format, const char *formatParams=NULL ) throw( r_Error );
    /**
      The method sets the transfer compression used for the communications of
      this client with the server.

      Error kinds:
      \begin{tabular}{lll}
      r_Error_ClientUnknown       && Client is not known by the server\\
      r_Error_DatabaseClosed      && Database is not open\\
      r_Error_FeatureNotSupported && Unsupported transfer format\\
      \end{tabular}
    */

    /// set the storage format for newly created MDD for this client
    void set_storage_format( r_Data_Format format, const char *formatParams=NULL) throw( r_Error );
    /**
      This method sets the storage format to use for MDD created by this client
      in the RasDaMan database. The return values are identical to set_transfer_format()
    */

    /// stores a pointer to the actually opened database
    static r_Database* actual_database; 
    

    //@Man: Methods for internal use only:
    //@{
    ///
    const r_OId get_new_oid( unsigned short objType ) const throw(r_Error);
    ///
    //@}
     
     
     // creates an empty MDD collection on the server
     void insertColl( const char* collName, const char* typeName, const r_OId& oid ) throw( r_Error );
     
     /// removes an object from a collection
     void removeObjFromColl( const char* name, const r_OId& oid ) throw ( r_Error );
     
     ClientComm* getComm();
  private:
    /// stores a pointer to a communication object, which is valid while a database is opened
    ClientComm* communication;      
        
    /// database status
    access_status db_status;

    /// stores the RasMGR name
    char* rasmgrName;		    
    
    /// stores the RasMGR port
    int   rasmgrPort;
    
    /// stores the user name
    char* userName;
    
    /// stores the user password (this will change!)
    char* plainPass;
};

#include "rasodmg/database.icc"
#include "rasodmg/ref.hh"

#endif