rasdaman complete source
databaseif.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 _DATABASEIF_HH_
24 #define _DATABASEIF_HH_
25 
26 /************************************************************************
27  *
28  *
29  * PURPOSE:
30  *
31  *
32  * COMMENTS:
33  *
34  ***********************************************************************/
35 
36 //@ManMemo: Module: {\bf reladminif}.
37 /*@Doc:
38 With a DatabaseIf instance a database can be opened or closed. There
39 is also functionality for creating and deleting DBs. A
40 database has to be open, before persistence capable classes can be
41 used (see also \Ref{AdminIf}).
42 
43 {\bf Example}
44 
45 {\tt DatabaseIf database;}
46 
47 {\tt database.open( "myDatabase" )}
48 
49 ...
50 
51 {\tt database.close();}
52 */
53 
54 class DatabaseIf;
55 class TransactionIf;
56 
57 #include <iostream>
58 using std::cout;
59 using std::endl;
60 using std::ostream;
61 
62 #include "raslib/error.hh"
67 {
68 public:
69  friend std::ostream& operator<< (std::ostream& stream, DatabaseIf& db);
70  /*@Doc:
71  prints the status of the database (connected, online, offline, name)
72  */
73 
75  void open( const char* dbName ) throw(r_Error);
76  /*@Doc:
77  Precondition: not opened, not connected, db exists
78  Postcondition: open, not connected, db exists
79  If last opened database was not closed (throw r_Error::r_Error_DatabaseOpen)),
80  If database does not exist (throw r_Error::r_Error_DatabaseUnknown).
81  In the current implementation this value is returned, when dbName is not RASBASE,
82  regardles if the db exists or not.
83  */
84 
85  void close();
86  /*@Doc:
87  Precondition: open, not connected, db exists
88  Postcondition: not open, not connected, db exists
89  closes currently opened database. only frees name and sets connected/opened to false.
90  */
91 
92  static void createDB( const char* dbName, const char* schemaName, const char* volumeName=0 ) throw(r_Error);
93  /*@Doc:
94  Precondition: not open, not connected, db does not exist
95  Postcondition: not open, not connected, db exists
96  creates a new database. schemaName and volumeName are ignored.
97  only successful if dbName is RASBASE
98  */
99 
100  static void destroyDB(const char* dbName) throw(r_Error);
101  /*@Doc:
102  Precondition: not open, not connected, db exists
103  Postcondition: not open, not connected, db does not exist
104  destroys an existing database with name {\tt dbName}.
105  Database must not be open in order to be destroyed.
106  A transaction must not be opened.
107  Returns -1 if database does not exist.
108  */
109 
110 
111  void garbage();
112  /*@Doc:
113  this method does not do anything
114  */
115 
116  const char* getName() const;
117  /*@Doc:
118  returns a pointer to the name of the db.
119  */
120 
121  DatabaseIf();
122  /*@Doc:
123  constructor. Initializes opened, myName and connected to 0
124  */
125 
126  bool isConnected() const;
127  /*@Doc:
128  true when there has been an EXEC SQL CONNECT
129  */
130 
131  bool isOpen() const;
132  /*@Doc:
133  true when it was opened by a transaction
134  */
135 
136  ~DatabaseIf();
137  /*@Doc:
138  executes a baseDBMSClose() if it is still connected.
139  */
140 
141  static bool databaseExists(const char* dbname) throw (r_Error);
142  /*@Doc:
143  Precondition: none checked. db must be open and connected.
144  Postcondition: none
145  basedbms error thrown.
146  checks if a database has been created.
147  */
148 
149  static bool isConsistent() throw (r_Error);
150  /*@Doc:
151  Precondition: none checked. db must be open and connected.
152  Postcondition: none
153  basedbms error thrown if something really bad happens.
154  checks if counters are ok.
155  */
156 
157  static long rmanverToLong();
158  /*@Doc:
159  Extract the version number from the git-describe output and
160  convert it to long by removing the dots.
161  */
162 
163 protected:
164  friend class TransactionIf;
165 
166  void baseDBMSOpen() throw (r_Error);
167  /*@Doc:
168  Precondition: current database = 0
169  Postcondition: current database = this
170  issues a CONNECT.
171  sets the DatabaseIf object in AdminIf to this.
172  */
173 
174  void baseDBMSClose();
175  /*@Doc:
176  Precondition: current database = this
177  Postcondition: current database = 0
178  issues a ROLLBACK WORK RELEASE in oracle.
179  issues a DISCONNECT in db2.
180  sets the DatabaseIf object in AdminIf to 0, if it was the same.
181  */
182 
183  static void connect() throw (r_Error);
184  /*@Doc:
185  Precondition: none checked.
186  Postcondition: none.
187  issues a CONNECT.
188  throws r_Error if there is a problem during connection.
189  */
190 
191  static void disconnect() throw (r_Error);
192  /*@Doc:
193  Precondition: none checked.
194  Postcondition: none.
195  issues a CONNECT.
196  throws r_Error if there is a problem during disconnection.
197  */
198 
199  void checkCompatibility() throw (r_Error);
200  /*@Doc:
201  Precondition: none checked.
202  Postcondition: none.
203  throws r_Error if the current rasdaman system does not match the database.
204  */
205 
206 private:
207  bool opened;
208  /*@Doc:
209  TRUE only if database is open.
210  */
211 
212  char* myName;
213  /*@Doc:
214  Valid only if opened.
215  */
216 
217  bool connected;
218  /*@Doc:
219  TRUE only if database connection exists ; )
220  */
221 
222  static const char* DefaultDatabaseName;
223  /*@Doc:
224  only one database is supported. any database name given is compared to this string.
225  access to the db is only granted if the name of the database is the same as this string.
226  */
227 
228 };
229 
230 #endif
void baseDBMSClose()
Definition: databaseif.hh:66
static bool isConsistent()
static void disconnect()
Definition: error.hh:88
bool isConnected() const
friend std::ostream & operator<<(std::ostream &stream, DatabaseIf &db)
void open(const char *dbName)
opens database with name { dbName}.
static bool databaseExists(const char *dbname)
void garbage()
void baseDBMSOpen()
const char * getName() const
void close()
Definition: transactionif.hh:52
void checkCompatibility()
static void createDB(const char *dbName, const char *schemaName, const char *volumeName=0)
static void connect()
bool isOpen() const
static void destroyDB(const char *dbName)
static long rmanverToLong()