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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_CONNECTIVITY_SQLERROR_HXX
#define INCLUDED_CONNECTIVITY_SQLERROR_HXX
#include <com/sun/star/sdbc/SQLException.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <connectivity/dbtoolsdllapi.hxx>
//........................................................................
namespace connectivity
{
//........................................................................
//====================================================================
//= ErrorCondition
//====================================================================
/** the type of error codes to be used in SQLExceptions
@see com::sun::star::sdbc::SQLException::ErrorCode
*/
typedef ::sal_Int32 ErrorCode;
/** error condition values as defined in com::sun::star::sdb::ErrorCondition
*/
typedef ::sal_Int32 ErrorCondition;
//====================================================================
//= SQLError
//====================================================================
class SQLError_Impl;
/** a class which provides helpers for working with SQLErrors
In particular, this class provides vendor-specific error codes (where
the vendor is OpenOffice.org Base), which can be used in OOo's various
database drivers, and checked in application-level code, to properly
recognize highly specific error conditions.
@see ::com::sun::star::sdb::ErrorCondition
*/
class OOO_DLLPUBLIC_DBTOOLS SQLError
{
public:
// --------------------------------------------------------------------
// - optional
// --------------------------------------------------------------------
/** convenience wrapper around boost::optional, allowing implicit construction
*/
class ParamValue : public ::boost::optional< OUString >
{
typedef ::boost::optional< OUString > base_type;
public:
ParamValue( ) : base_type( ) { }
ParamValue( OUString const& val ) : base_type( val ) { }
ParamValue( ParamValue const& rhs ) : base_type( (base_type const&)rhs ) { }
bool is() const { return !base_type::operator!(); }
};
public:
explicit SQLError( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & _rxContext );
~SQLError();
/** returns the message associated with a given error condition, after (optionally) replacing
a placeholder with a given string
Some error messages need to contain references to runtime-dependent data (say, the
name of a concrete table in the database), which in the resource file's strings are
represented by a placeholder, namely $1$, $2, and so on. This method allows to
retrieve such an error message, and replace upo to 3 placeholders with their concrete
values.
In a non-product build, assertions will fire if the number of placeholders in the
message's resource string does not match the number of passed parameter values.
As specified in the com::sun::star::sdb::ErrorCondition type,
error messages thrown by core components of OpenOffice.org Base will contain
a standardized prefix "[OOoBase]" in every message.
@param _rParamValue1
the value which the placeholder $1$ should be replaced with. If this value is
not present (see <code>::boost::optional::operator !</code>), then no replacement
will happen, and <code>_rParamValue2</code> and <code>_rParamValue3</code> will be
ignored.
@param _rParamValue2
the value which the placeholder $2$ should be replaced with. If this value is
not present (see <code>::boost::optional::operator !</code>), then no replacement
will happen, and <code>_rParamValue3</code> will be ignored.
@param _rParamValue1
the value which the placeholder $1$ should be replaced with. If this value is
not present (see <code>::boost::optional::operator !</code>), then no replacement
will happen.
@see ::com::sun::star::sdb::ErrorCondition
*/
OUString getErrorMessage(
const ErrorCondition _eCondition,
const ParamValue& _rParamValue1 = ParamValue(),
const ParamValue& _rParamValue2 = ParamValue(),
const ParamValue& _rParamValue3 = ParamValue()
) const;
/** returns the error code associated with a given error condition
@see getErrorMessage
@see ::com::sun::star::sdb::ErrorCondition
@see ::com::sun::star::sdbc::SQLException::ErrorCode
*/
static ErrorCode
getErrorCode( const ErrorCondition _eCondition );
/** returns the prefix which is used for OpenOffice.org Base's error messages
As specified in the com::sun::star::sdb::ErrorCondition type,
error messages thrown by core components of OpenOffice.org Base will
contain a standardized prefix in every message. <code>getBaseErrorMessagePrefix</code>
returns this prefix, so clients of such error messages might decide to strip this
prefix before presenting the message to the user, or use it to determine
whether a concrete error has been raised by a OpenOffice.org core component.
*/
static const OUString&
getMessagePrefix();
/** throws an SQLException describing the given error condition
The thrown SQLException will contain the OOo-specific error code which derives
from the given error condition, and the error message associated with that condition.
@param _eCondition
the ErrorCondition which hit you
@param _rxContext
the context in which the error occurred. This will be filled in as
<member scope="com::sun::star::uno">Exception::Context</member> member.
@param _rParamValue1
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the first placeholder
in this message.
@param _rParamValue2
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the second placeholder
in this message.
@param _rParamValue3
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the third placeholder
in this message.
@see getErrorMessage
@see getErrorCode
*/
void raiseException(
const ErrorCondition _eCondition,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext,
const ParamValue& _rParamValue1 = ParamValue(),
const ParamValue& _rParamValue2 = ParamValue(),
const ParamValue& _rParamValue3 = ParamValue()
) const;
/** throws an SQLException describing the given error condition
The thrown SQLException will contain the OOo-specific error code which derives
from the given error condition, and the error message associated with that condition.
Note: You should prefer the version of raiseException which takes
an additional Context parameter, since this allows clients of your
exception to examine where the error occurred.
@param _eCondition
the ErrorCondition which hit you
@param _rParamValue1
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the first placeholder
in this message.
@param _rParamValue2
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the second placeholder
in this message.
@param _rParamValue3
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the third placeholder
in this message.
@see getErrorMessage
@see getErrorCode
*/
void raiseException(
const ErrorCondition _eCondition,
const ParamValue& _rParamValue1 = ParamValue(),
const ParamValue& _rParamValue2 = ParamValue(),
const ParamValue& _rParamValue3 = ParamValue()
) const;
/** raises a typed exception, that is, a UNO exception which is derived from
com::sun::star::sdbc::SQLException
@param _eCondition
the ErrorCondition which hit you
@param _rxContext
the context in which the error occurred. This will be filled in as
<member scope="com::sun::star::uno">Exception::Context</member> member.
@param _rExceptionType
the type of the exception to throw. This type <em>must</em> specify
an exception class derived from com::sun::star::sdbc::SQLException.
@param _rParamValue1
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the first placeholder
in this message.
@param _rParamValue2
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the second placeholder
in this message.
@param _rParamValue3
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the third placeholder
in this message.
@throws ::std::bad_cast
if <arg>_rExceptionType</arg> does not specify an exception class derived from
com::sun::star::sdbc::SQLException.
@see getErrorMessage
@see getErrorCode
*/
void raiseTypedException(
const ErrorCondition _eCondition,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext,
const ::com::sun::star::uno::Type& _rExceptionType,
const ParamValue& _rParamValue1 = ParamValue(),
const ParamValue& _rParamValue2 = ParamValue(),
const ParamValue& _rParamValue3 = ParamValue()
) const;
/** retrieves an <code>SQLException</code> object which contains information about
the given error condition
@param _eCondition
the ErrorCondition which hit you
@param _rxContext
the context in which the error occurred. This will be filled in as
<member scope="com::sun::star::uno">Exception::Context</member> member.
@param _rParamValue1
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the first placeholder
in this message.
@param _rParamValue2
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the second placeholder
in this message.
@param _rParamValue3
a runtime-dependent value which should be filled into the error message
which is associated with <arg>_eCondition</arg>, replacing the third placeholder
in this message.
@see getErrorMessage
@see getErrorCode
*/
::com::sun::star::sdbc::SQLException
getSQLException(
const ErrorCondition _eCondition,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext,
const ParamValue& _rParamValue1 = ParamValue(),
const ParamValue& _rParamValue2 = ParamValue(),
const ParamValue& _rParamValue3 = ParamValue()
) const;
private:
::boost::shared_ptr< SQLError_Impl > m_pImpl;
};
//........................................................................
} // namespace connectivity
//........................................................................
#endif // INCLUDED_CONNECTIVITY_SQLERROR_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|