Oracle ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
auto-handle.hxx
Go to the documentation of this file.
1 // file : odb/oracle/auto-handle.hxx
2 // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC
3 // license : ODB NCUEL; see accompanying LICENSE file
4 
5 #ifndef ODB_ORACLE_AUTO_HANDLE_HXX
6 #define ODB_ORACLE_AUTO_HANDLE_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/oracle/version.hxx>
12 
13 #include <odb/oracle/details/export.hxx>
14 
15 namespace odb
16 {
17  namespace oracle
18  {
19  //
20  // handle_type_traits
21  //
22 
23  template <typename H>
25 
26  template <>
27  struct LIBODB_ORACLE_EXPORT handle_type_traits<OCIEnv>
28  { static const ub4 htype; };
29 
30  template <>
31  struct LIBODB_ORACLE_EXPORT handle_type_traits<OCIError>
32  { static const ub4 htype; };
33 
34  template <>
35  struct LIBODB_ORACLE_EXPORT handle_type_traits<OCISvcCtx>
36  { static const ub4 htype; };
37 
38  template <>
39  struct LIBODB_ORACLE_EXPORT handle_type_traits<OCIStmt>
40  { static const ub4 htype; };
41 
42  template <>
43  struct LIBODB_ORACLE_EXPORT handle_type_traits<OCIAuthInfo>
44  { static const ub4 htype; };
45 
46  template <>
47  struct LIBODB_ORACLE_EXPORT handle_type_traits<OCITrans>
48  { static const ub4 htype; };
49 
50  //
51  // handle_traits
52  //
53 
54  LIBODB_ORACLE_EXPORT void
55  oci_handle_free (void* handle, ub4 type);
56 
57  template <typename H>
59  {
60  static void
61  release (H* h)
62  {
64  }
65  };
66 
67  template <>
68  struct LIBODB_ORACLE_EXPORT handle_traits<OCISvcCtx>
69  {
70  static void
71  release (OCISvcCtx*, OCIError*);
72  };
73 
74  template <>
75  struct LIBODB_ORACLE_EXPORT handle_traits<OCIStmt>
76  {
77  static void
78  release (OCIStmt*, ub4 release_mode, OCIError*);
79  };
80 
81  //
82  // auto_handle
83  //
84 
85  template <typename H>
87  {
88  public:
89  auto_handle (H* h = 0)
90  : h_ (h)
91  {
92  }
93 
95  {
96  if (h_ != 0)
98  }
99 
100  operator H* () const
101  {
102  return h_;
103  }
104 
105  H*
106  get () const
107  {
108  return h_;
109  }
110 
111  H*
113  {
114  H* h (h_);
115  h_ = 0;
116  return h;
117  }
118 
119  void
120  reset (H* h = 0)
121  {
122  if (h_ != 0)
124 
125  h_ = h;
126  }
127 
128  private:
129  auto_handle (const auto_handle&);
130  auto_handle& operator= (const auto_handle&);
131 
132  private:
133  H* h_;
134  };
135 
136  //
137  // auto_handle<OCISvcCtx>
138  //
139 
140  template <>
141  class LIBODB_ORACLE_EXPORT auto_handle<OCISvcCtx>
142  {
143  public:
145  : h_ (0)
146  {
147  }
148 
150  : h_ (h), e_ (e)
151  {
152  }
153 
155  {
156  if (h_ != 0)
158  }
159 
160  operator OCISvcCtx* () const
161  {
162  return h_;
163  }
164 
165  OCISvcCtx*
166  get () const
167  {
168  return h_;
169  }
170 
171  OCISvcCtx*
173  {
174  OCISvcCtx* h (h_);
175  h_ = 0;
176 
177  return h;
178  }
179 
180  void
181  reset ()
182  {
183  if (h_ != 0)
184  {
186  h_ = 0;
187  }
188  }
189 
190  void
192  {
193  if (h_ != 0)
195 
196  h_ = h;
197  e_ = e;
198  }
199 
200  private:
201  OCISvcCtx* h_;
202  OCIError* e_;
203  };
204 
205  //
206  // auto_handle<OCIStmt>
207  //
208 
209  template <>
210  class LIBODB_ORACLE_EXPORT auto_handle<OCIStmt>
211  {
212  public:
214  : h_ (0)
215  {
216  }
217 
218  auto_handle (OCIStmt* h, ub4 release_mode, OCIError* e)
219  : h_ (h), release_mode_ (release_mode), e_ (e)
220  {
221  }
222 
224  {
225  if (h_ != 0)
226  handle_traits<OCIStmt>::release (h_, release_mode_, e_);
227  }
228 
229  operator OCIStmt* () const
230  {
231  return h_;
232  }
233 
234  OCIStmt*
235  get () const
236  {
237  return h_;
238  }
239 
240  void
241  reset ()
242  {
243  if (h_ != 0)
244  {
245  handle_traits<OCIStmt>::release (h_, release_mode_, e_);
246  h_ = 0;
247  }
248  }
249 
250  void
251  reset (OCIStmt* h, ub4 release_mode, OCIError* e)
252  {
253  if (h_ != 0)
254  handle_traits<OCIStmt>::release (h_, release_mode_, e_);
255 
256  h_ = h;
257  release_mode_ = release_mode;
258  e_ = e;
259  }
260 
261  private:
262  OCIStmt* h_;
263  ub4 release_mode_;
264  OCIError* e_;
265  };
266  }
267 }
268 
269 #include <odb/post.hxx>
270 
271 #endif // ODB_ORACLE_AUTO_HANDLE_HXX
static const ub4 htype
Definition: auto-handle.hxx:48
static const ub4 htype
Definition: auto-handle.hxx:32
void reset()
Definition: auto-handle.hxx:181
H * release()
Definition: auto-handle.hxx:112
struct OCIAuthInfo OCIAuthInfo
Definition: oracle-fwd.hxx:26
void reset(OCISvcCtx *h, OCIError *e)
Definition: auto-handle.hxx:191
auto_handle()
Definition: auto-handle.hxx:144
static const ub4 htype
Definition: auto-handle.hxx:36
unsigned int ub4
Definition: oracle-fwd.hxx:20
struct OCISvcCtx OCISvcCtx
Definition: oracle-fwd.hxx:23
Definition: auto-handle.hxx:58
static const ub4 htype
Definition: auto-handle.hxx:28
auto_handle(OCISvcCtx *h, OCIError *e)
Definition: auto-handle.hxx:149
Definition: auto-handle.hxx:86
~auto_handle()
Definition: auto-handle.hxx:94
auto_handle()
Definition: auto-handle.hxx:213
static const ub4 htype
Definition: auto-handle.hxx:44
static void release(H *h)
Definition: auto-handle.hxx:61
struct OCIStmt OCIStmt
Definition: oracle-fwd.hxx:25
auto_handle(OCIStmt *h, ub4 release_mode, OCIError *e)
Definition: auto-handle.hxx:218
Definition: auto-handle.hxx:24
struct OCIError OCIError
Definition: oracle-fwd.hxx:24
static const ub4 htype
Definition: auto-handle.hxx:40
void reset()
Definition: auto-handle.hxx:241
~auto_handle()
Definition: auto-handle.hxx:223
~auto_handle()
Definition: auto-handle.hxx:154
void reset(H *h=0)
Definition: auto-handle.hxx:120
auto_handle(H *h=0)
Definition: auto-handle.hxx:89
struct OCITrans OCITrans
Definition: oracle-fwd.hxx:27
struct OCIEnv OCIEnv
Definition: oracle-fwd.hxx:22
void reset(OCIStmt *h, ub4 release_mode, OCIError *e)
Definition: auto-handle.hxx:251
LIBODB_ORACLE_EXPORT void oci_handle_free(void *handle, ub4 type)
OCISvcCtx * release()
Definition: auto-handle.hxx:172