OcciConn.hpp 6.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  CERN
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

21
#include "common/threading/MutexLocker.hpp"
22
#include "common/threading/RWLock.hpp"
23
#include "rdbms/wrapper/ConnWrapper.hpp"
24

25
26
27
#include <occi.h>

namespace cta {
28
namespace rdbms {
29
namespace wrapper {
30
31
32
33
34
35
36
37

/**
 * Forward declaraion to avoid a circular dependency beween OcciConn and
 * OcciStmt.
 */
class OcciStmt;

/**
38
 * A convenience wrapper around a connection to an OCCI database.
39
 */
40
class OcciConn: public ConnWrapper {
41
42
43
44
45
public:

  /**
   * Constructor.
   *
46
   * This method will throw an exception if the OCCI connection is a nullptr
Steven Murray's avatar
Steven Murray committed
47
48
   * pointer.
   *
49
   * @param env The OCCI environment.
Steven Murray's avatar
Steven Murray committed
50
   * @param conn The OCCI connection.
51
   */
52
  OcciConn(oracle::occi::Environment *env, oracle::occi::Connection *const conn);
53
54
55
56

  /**
   * Destructor.
   */
57
  ~OcciConn() override;
58
59
60
61

  /**
   * Idempotent close() method.  The destructor calls this method.
   */
62
  void close() override;
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  /**
   * Sets the autocommit mode of the connection.
   *
   * @param autocommitMode The autocommit mode of the connection.
   * @throw AutocommitModeNotSupported If the specified autocommit mode is not
   * supported.
   */
  void setAutocommitMode(const AutocommitMode autocommitMode) override;

  /**
   * Returns the autocommit mode of the connection.
   *
   * @return The autocommit mode of the connection.
   */
  AutocommitMode getAutocommitMode() const noexcept override;

80
81
82
83
84
  /**
   * Executes the statement.
   *
   * @param sql The SQL statement.
   */
85
  void executeNonQuery(const std::string &sql) override;
86

87
88
89
  /**
   * Creates a prepared statement.
   *
90
   * @param sql The SQL statement.
91
92
   * @return The prepared statement.
   */
93
  std::unique_ptr<StmtWrapper> createStmt(const std::string &sql) override;
94
95
96
97

  /**
   * Commits the current transaction.
   */
98
  void commit() override;
99
100
101
102

  /**
   * Rolls back the current transaction.
   */
103
  void rollback() override;
104
105
106
107
108
109
110
111
112
  
  /**
   * Returns the names of all the column and their type as a map for the given 
   * table in the database schema.
   *
   * @param tableName The table name to get the columns.
   * @return The map of types by name of all the columns for the given table in the database schema.
   */
  std::map<std::string, std::string> getColumns(const std::string &tableName) override;
113

Steven Murray's avatar
Steven Murray committed
114
115
116
117
118
119
120
  /**
   * Returns the names of all the tables in the database schema in alphabetical
   * order.
   *
   * @return The names of all the tables in the database schema in alphabetical
   * order.
   */
121
  std::list<std::string> getTableNames() override;
122
123
124
125
126
127
128
129
130
  
  /**
   * Returns the names of all the indices the database schema in alphabetical
   * order.
   *
   * @return The names of all the indices in the database schema in alphabetical
   * order.
   */
  std::list<std::string> getIndexNames() override;
Steven Murray's avatar
Steven Murray committed
131

132
133
134
135
136
  /**
   * Returns true if this connection is open.
   */
  bool isOpen() const override;

137
138
139
140
  /**
   * Returns the names of all the sequences in the database schema in
   * alphabetical order.
   *
141
142
143
   * If the underlying database technologies does not supported sequences then
   * this method simply returns an empty list.
   *
144
145
146
   * @return The names of all the sequences in the database schema in
   * alphabetical order.
   */
147
  std::list<std::string> getSequenceNames() override;
148
149
150
151
152
153
154
155
156
157
158
159
  
  /**
   * Returns the names of all the triggers in the database schema in
   * alphabetical order.
   *
   * If the underlying database technologies does not supported triggers then
   * this method simply returns an empty list.
   *
   * @return The names of all the triggers in the database schema in
   * alphabetical order.
   */
  std::list<std::string> getTriggerNames() override;
160
161
162
163
164
165
166
167
168
169
170
171
  
  /**
   * Returns the names of all the tables that have been set as PARALLEL
   * in alphabetical order.
   * 
   * If the underlying database technologies does not support PARALLEL
   * them this method simply returns an empty list.
   * 
   * @return the names of all the tables that have been set as PARALLEL
   * in alphabetical order. 
   */
  std::list<std::string> getParallelTableNames() override;
172

173
174
175
176
177
178
  /**
   * Returns the Constraint names of a given table in the database schema
   * @param tableName the table name to get the constraint names from
   * @return the list of the names of the constraints that the given table has.
   */
  std::list<std::string> getConstraintNames(const std::string &tableName) override;
179
180
181
182
183
184
185
186
187
188
189
  
  /**
   * 
   * Returns the stored procedure names of the database
   * 
   * If the underlying database technologies does not support stored procedures informations
   * this method simply returns an empty list.
   * 
   * @return the list of the names of the stored procedures in the database
   */
  std::list<std::string> getStoredProcedureNames() override;
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  
  /**
   * Returns the synonym names of the database
   * 
   * If the underlying database technologies does not support synonym informations
   * this method simply returns an empty list.
   * 
   * @return the list of the names of the synonyms in the database
   */
  std::list<std::string> getSynonymNames() override;
  
  /**
   * Returns the type names of the database
   * 
   * If the underlying database technologies does not support type informations
   * this method simply returns an empty list.
   * 
   * @return the list of the names of the types in the database
   */
  std::list<std::string> getTypeNames() override;
210

211
212
private:

213
214
  friend OcciStmt;

215
  /**
Steven Murray's avatar
Steven Murray committed
216
   * Mutex used to serialize access to this object.
217
   */
218
  threading::Mutex m_mutex;
219
220
221
222

  /**
   * The OCCI environment.
   */
223
  oracle::occi::Environment *m_env;
224
225
226
227

  /**
   * The OCCI connection.
   */
228
  oracle::occi::Connection *m_occiConn;
229

230
231
232
233
234
235
236
237
238
239
  /**
   * Read-write lock to protect m_autocommitMode.
   */
  mutable threading::RWLock m_autocommitModeRWLock;

  /**
   * The autocommit mode of the connection.
   */
  AutocommitMode m_autocommitMode;

240
241
242
243
244
245
246
  /**
   * Closes the specified OCCI statement.
   *
   * @param stmt The OCCI statement to be closed.
   */
  void closeStmt(oracle::occi::Statement *const stmt);

247
248
}; // class OcciConn

249
} // namespace wrapper
250
} // namespace rdbms
251
} // namespace cta