OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Message.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2023 Vincent ROGIER <vince.rogier@ocilib.net>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
23 #include "ocilibcpp/types.hpp"
24 
25 // ReSharper disable CppClangTidyHicppUseAuto
26 // ReSharper disable CppClangTidyModernizeUseAuto
27 // ReSharper disable CppClangTidyMiscMisplacedConst
28 
29 namespace ocilib
30 {
31 
32 inline Message::Message(const TypeInfo &typeInfo)
33 {
34  Connection connection = typeInfo.GetConnection();
35 
36  AcquireAllocated
37  (
38  core::Check(OCI_MsgCreate(typeInfo)),
39  connection.GetHandle()
40  );
41 }
42 
43 inline Message::Message(OCI_Msg *pMessage, core::Handle *parent)
44 {
45  AcquireTransient(pMessage, parent);
46 }
47 
48 inline void Message::Reset()
49 {
50  core::Check(OCI_MsgReset(*this));
51 }
52 
53 template<>
54 inline Object Message::GetPayload<Object>()
55 {
56  return Object(core::Check(OCI_MsgGetObject(*this)), nullptr);
57 }
58 
59 template<>
60 inline void Message::SetPayload<Object>(const Object &value)
61 {
62  core::Check(OCI_MsgSetObject(*this, value));
63 }
64 
65 template<>
66 inline Raw Message::GetPayload<Raw>()
67 {
68  unsigned int size = 0;
69 
70  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
71 
72  core::Check(OCI_MsgGetRaw(*this, static_cast<AnyPointer>(buffer), &size));
73 
74  return core::MakeRaw(buffer, size);
75 }
76 
77 template<>
78 inline void Message::SetPayload<Raw>(const Raw &value)
79 {
80  const AnyPointer data = value.empty() ? nullptr : static_cast<AnyPointer>(const_cast<Raw::value_type*>(&value[0])) ;
81 
82  core::Check(OCI_MsgSetRaw(*this, data, static_cast<unsigned int>(value.size())));
83 }
84 
86 {
87  return Date(core::Check(OCI_MsgGetEnqueueTime(*this)), nullptr);
88 }
89 
90 inline int Message::GetAttemptCount() const
91 {
92  return core::Check(OCI_MsgGetAttemptCount(*this));
93 }
94 
96 {
97  return MessageState(static_cast<MessageState::Type>(core::Check(OCI_MsgGetState(*this))));
98 }
99 
100 inline Raw Message::GetID() const
101 {
102  unsigned int size = OCI_SIZE_BUFFER;
103 
104  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
105 
106  core::Check(OCI_MsgGetID(*this, static_cast<AnyPointer>(buffer), &size));
107 
108  return core::MakeRaw(buffer, size);
109 }
110 
111 inline int Message::GetExpiration() const
112 {
113  return core::Check(OCI_MsgGetExpiration(*this));
114 }
115 
116 inline void Message::SetExpiration(int value)
117 {
118  core::Check(OCI_MsgSetExpiration(*this, value));
119 }
120 
121 inline int Message::GetEnqueueDelay() const
122 {
123  return core::Check(OCI_MsgGetEnqueueDelay(*this));
124 }
125 
126 inline void Message::SetEnqueueDelay(int value)
127 {
128  core::Check(OCI_MsgSetEnqueueDelay(*this, value));
129 }
130 
131 inline int Message::GetPriority() const
132 {
133  return core::Check(OCI_MsgGetPriority(*this));
134 }
135 
136 inline void Message::SetPriority(int value)
137 {
138  core::Check(OCI_MsgSetPriority(*this, value));
139 }
140 
142 {
143  unsigned int size = OCI_SIZE_BUFFER;
144 
145  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
146 
147  core::Check(OCI_MsgGetOriginalID(*this, static_cast<AnyPointer>(buffer), &size));
148 
149  return core::MakeRaw(buffer, size);
150 }
151 
152 inline void Message::SetOriginalID(const Raw &value)
153 {
154  const AnyPointer data = value.empty() ? nullptr : static_cast<AnyPointer>(const_cast<Raw::value_type*>(&value[0])) ;
155 
156  core::Check(OCI_MsgSetOriginalID(*this, data, static_cast<unsigned int>(value.size())));
157 }
158 
160 {
162 }
163 
164 inline void Message::SetCorrelation(const ostring& value)
165 {
166  core::Check(OCI_MsgSetCorrelation(*this, value.c_str()));
167 }
168 
170 {
172 }
173 
174 inline void Message::SetExceptionQueue(const ostring& value)
175 {
176  core::Check(OCI_MsgSetExceptionQueue(*this, value.c_str()));
177 }
178 
179 inline Agent Message::GetSender() const
180 {
181  return Agent(core::Check(OCI_MsgGetSender(*this)), nullptr);
182 }
183 
184 inline void Message::SetSender(const Agent &agent)
185 {
186  core::Check(OCI_MsgSetSender(*this, agent));
187 }
188 
189 inline void Message::SetConsumers(std::vector<Agent> &agents)
190 {
191  const size_t size = agents.size();
192  core::ManagedBuffer<OCI_Agent*> buffer(size);
193 
194  OCI_Agent ** pAgents = static_cast<OCI_Agent **>(buffer);
195 
196  for (size_t i = 0; i < size; ++i)
197  {
198  pAgents[i] = static_cast<const Agent &>(agents[i]);
199  }
200 
201  core::Check(OCI_MsgSetConsumers(*this, pAgents, static_cast<unsigned int>(size)));
202 }
203 
204 }
AQ identified agent for messages delivery.
Definition: types.hpp:7332
A connection or session with a specific database.
Definition: types.hpp:1580
Object identifying the SQL data type DATE.
Definition: types.hpp:2678
void SetCorrelation(const ostring &value)
Set the correlation identifier of the message.
Definition: Message.hpp:164
void SetSender(const Agent &agent)
Set the original sender of the message.
Definition: Message.hpp:184
int GetAttemptCount() const
Return the number of attempts that have been made to dequeue the message.
Definition: Message.hpp:90
ostring GetExceptionQueue() const
Get the Exception queue name of the message.
Definition: Message.hpp:169
void SetPriority(int value)
Set the priority of the message.
Definition: Message.hpp:136
core::Enum< MessageStateValues > MessageState
Message state.
Definition: types.hpp:7451
Raw GetOriginalID() const
Return the original ID of the message in the last queue that generated this message.
Definition: Message.hpp:141
Date GetEnqueueTime() const
return the time the message was enqueued
Definition: Message.hpp:85
MessageState GetState() const
Return the state of the message at the time of the dequeue.
Definition: Message.hpp:95
void SetExpiration(int value)
set the duration that the message is available for dequeuing
Definition: Message.hpp:116
Message(const TypeInfo &typeInfo)
Create a message object based on the given payload type.
Definition: Message.hpp:32
Agent GetSender() const
Return the original sender of the message.
Definition: Message.hpp:179
Raw GetID() const
Return the ID of the message.
Definition: Message.hpp:100
void Reset()
Reset all attributes of the message.
Definition: Message.hpp:48
ostring GetCorrelation() const
Get the correlation identifier of the message.
Definition: Message.hpp:159
void SetEnqueueDelay(int value)
set the number of seconds to delay the enqueued message
Definition: Message.hpp:126
int GetExpiration() const
Return the duration that the message is available for dequeuing.
Definition: Message.hpp:111
int GetEnqueueDelay() const
Return the number of seconds that a message is delayed for dequeuing.
Definition: Message.hpp:121
int GetPriority() const
Return the priority of the message.
Definition: Message.hpp:131
void SetConsumers(std::vector< Agent > &agents)
Set the recipient list of a message to enqueue.
Definition: Message.hpp:189
void SetOriginalID(const Raw &value)
Set the original ID of the message in the last queue that generated this message.
Definition: Message.hpp:152
void SetExceptionQueue(const ostring &value)
Set the name of the queue to which the message is moved to if it cannot be processed successfully.
Definition: Message.hpp:174
Object identifying the SQL data type OBJECT.
Definition: types.hpp:4668
Provides type information on Oracle Database objects.
Definition: types.hpp:4531
Connection GetConnection() const
Return the connection associated with a statement.
Definition: TypeInfo.hpp:52
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:118
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:325
Internal usage. Provide a buffer class with RAII capabilities.
Definition: core.hpp:197
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgGetID(OCI_Msg *msg, void *id, unsigned int *len)
Return the ID of the message.
OCI_SYM_PUBLIC OCI_Msg *OCI_API OCI_MsgCreate(OCI_TypeInfo *typinf)
Create a message object based on the given payload type.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetPriority(OCI_Msg *msg, int value)
Set the priority of the message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetEnqueueDelay(OCI_Msg *msg, int value)
set the number of seconds to delay the enqueued message
OCI_SYM_PUBLIC const otext *OCI_API OCI_MsgGetExceptionQueue(OCI_Msg *msg)
Get the Exception queue name of the message.
OCI_SYM_PUBLIC OCI_Object *OCI_API OCI_MsgGetObject(OCI_Msg *msg)
Get the object payload of the given message.
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetAttemptCount(OCI_Msg *msg)
Return the number of attempts that have been made to dequeue the message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetCorrelation(OCI_Msg *msg, const otext *correlation)
set the correlation identifier of the message
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgReset(OCI_Msg *msg)
Reset all attributes of a message object.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetSender(OCI_Msg *msg, OCI_Agent *sender)
Set the original sender of a message.
OCI_SYM_PUBLIC OCI_Agent *OCI_API OCI_MsgGetSender(OCI_Msg *msg)
Return the original sender of a message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetExceptionQueue(OCI_Msg *msg, const otext *queue)
Set the name of the queue to which the message is moved to if it cannot be processed successfully.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetConsumers(OCI_Msg *msg, OCI_Agent **consumers, unsigned int count)
Set the recipient list of a message to enqueue.
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetExpiration(OCI_Msg *msg)
Return the duration that the message is available for dequeuing.
OCI_SYM_PUBLIC const otext *OCI_API OCI_MsgGetCorrelation(OCI_Msg *msg)
Get the correlation identifier of the message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgGetRaw(OCI_Msg *msg, void *raw, unsigned int *size)
Get the RAW payload of the given message.
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetPriority(OCI_Msg *msg)
Return the priority of the message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetOriginalID(OCI_Msg *msg, const void *id, unsigned int len)
Set the original ID of the message in the last queue that generated this message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgGetOriginalID(OCI_Msg *msg, void *id, unsigned int *len)
Return the original ID of the message in the last queue that generated this message.
OCI_SYM_PUBLIC OCI_Date *OCI_API OCI_MsgGetEnqueueTime(OCI_Msg *msg)
return the time the message was enqueued
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetExpiration(OCI_Msg *msg, int value)
set the duration that the message is available for dequeuing
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetEnqueueDelay(OCI_Msg *msg)
Return the number of seconds that a message is delayed for dequeuing.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetObject(OCI_Msg *msg, OCI_Object *obj)
Set the object payload of the given message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetRaw(OCI_Msg *msg, const void *raw, unsigned int size)
Set the RAW payload of the given message.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_MsgGetState(OCI_Msg *msg)
Return the state of the message at the time of the dequeue.
struct OCI_Msg OCI_Msg
OCILIB encapsulation of A/Q message.
Definition: types.h:450
struct OCI_Agent OCI_Agent
OCILIB encapsulation of A/Q Agent.
Definition: types.h:460
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so,...
Definition: Utils.hpp:53
ostring MakeString(const otext *result, int size=-1)
Internal usage. Constructs a C++ string object from the given OCILIB string pointer.
Definition: Utils.hpp:65
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
OCILIB ++ Namespace.
std::basic_string< otext, std::char_traits< otext >, std::allocator< otext > > ostring
string class wrapping the OCILIB otext * type and OTEXT() macros ( see Character sets )
Definition: config.hpp:120
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
void * AnyPointer
Alias for the generic void pointer.
Definition: config.hpp:129