Debian Codegraph @

ucb/source/ucp/file/filrow.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include "filrow.hxx"
21 #include "filtask.hxx"
22 #include <com/sun/star/script/CannotConvertException.hpp>
23 #include <com/sun/star/script/Converter.hpp>
24 #include <com/sun/star/sdbc/SQLException.hpp>
25
26 using namespace fileaccess;
27 using namespace com::sun::star;
28 using namespace css::uno;
29
30 #if OSL_DEBUG_LEVEL > 0
31 #define THROW_WHERE SAL_WHERE
32 #else
33 #define THROW_WHERE ""
34 #endif
35
36 // Function for TypeConverting
37
38 template< class _type_ >
39 static bool convert( TaskManager const * pShell,
40 uno::Reference< script::XTypeConverter >& xConverter,
41 const uno::Any& rValue,
42 _type_& aReturn )
43 {
44 // Try first without converting
45 bool no_success = ! ( rValue >>= aReturn );
46
47 if ( no_success )
48 {
49 if( ! xConverter.is() )
50 {
51 xConverter = script::Converter::create(pShell->m_xContext);
52 }
53
54 try
55 {
56 if( rValue.hasValue() )
57 {
58 uno::Any aConvertedValue
59 = xConverter->convertTo( rValue,cppu::UnoType<_type_>::get() );
60 no_success = ! ( aConvertedValue >>= aReturn );
61 }
62 else
63 no_success = true;
64 }
65 catch (const lang::IllegalArgumentException&)
66 {
67 no_success = true;
68 }
69 catch (const script::CannotConvertException&)
70 {
71 no_success = true;
72 }
73 }
74 return no_success;
75 }
76
77
78 XRow_impl::XRow_impl( TaskManager* pMyShell,const uno::Sequence< uno::Any >& seq )
79 : m_aValueMap( seq ),
80 m_nWasNull(false),
81 m_pMyShell( pMyShell )
82 {
83 }
84
85 XRow_impl::~XRow_impl()
86 {
87 }
88
89
90 sal_Bool SAL_CALL
91 XRow_impl::wasNull()
92 {
93 std::scoped_lock aGuard( m_aMutex );
94 return m_nWasNull;
95 }
96
97
98 OUString SAL_CALL
99 XRow_impl::getString(
100 sal_Int32 columnIndex )
101 {
102 if( isIndexOutOfBounds( columnIndex ) )
103 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
104 return getValue<OUString>(columnIndex);
105 }
106
107 sal_Bool SAL_CALL
108 XRow_impl::getBoolean(
109 sal_Int32 columnIndex )
110 {
111 if( isIndexOutOfBounds( columnIndex ) )
112 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
113 return getValue<bool>(columnIndex);
114 }
115
116
117 sal_Int8 SAL_CALL
118 XRow_impl::getByte(
119 sal_Int32 columnIndex )
120 {
121 if( isIndexOutOfBounds( columnIndex ) )
122 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
123 return getValue<sal_Int8>(columnIndex);
124 }
125
126 sal_Int16 SAL_CALL
127 XRow_impl::getShort(
128 sal_Int32 columnIndex )
129 {
130 if( isIndexOutOfBounds( columnIndex ) )
131 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
132 return getValue<sal_Int16>(columnIndex);
133 }
134
135
136 sal_Int32 SAL_CALL
137 XRow_impl::getInt(
138 sal_Int32 columnIndex )
139 {
140 if( isIndexOutOfBounds( columnIndex ) )
141 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
142 return getValue<sal_Int32>(columnIndex);
143 }
144
145 sal_Int64 SAL_CALL
146 XRow_impl::getLong(
147 sal_Int32 columnIndex )
148 {
149 if( isIndexOutOfBounds( columnIndex ) )
150 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
151 return getValue<sal_Int64>(columnIndex);
152 }
153
154 float SAL_CALL
155 XRow_impl::getFloat(
156 sal_Int32 columnIndex )
157 {
158 if( isIndexOutOfBounds( columnIndex ) )
159 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
160 return getValue<float>(columnIndex);
161 }
162
163 double SAL_CALL
164 XRow_impl::getDouble(
165 sal_Int32 columnIndex )
166 {
167 if( isIndexOutOfBounds( columnIndex ) )
168 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
169 return getValue<double>(columnIndex);
170 }
171
172 uno::Sequence< sal_Int8 > SAL_CALL
173 XRow_impl::getBytes(
174 sal_Int32 columnIndex )
175 {
176 if( isIndexOutOfBounds( columnIndex ) )
177 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
178 return getValue<uno::Sequence< sal_Int8 >>(columnIndex);
179 }
180
181 util::Date SAL_CALL
182 XRow_impl::getDate(
183 sal_Int32 columnIndex )
184 {
185 if( isIndexOutOfBounds( columnIndex ) )
186 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
187 return getValue<util::Date>(columnIndex);
188 }
189
190 util::Time SAL_CALL
191 XRow_impl::getTime(
192 sal_Int32 columnIndex )
193 {
194 if( isIndexOutOfBounds( columnIndex ) )
195 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
196 return getValue<util::Time>(columnIndex);
197 }
198
199 util::DateTime SAL_CALL
200 XRow_impl::getTimestamp(
201 sal_Int32 columnIndex )
202 {
203 if( isIndexOutOfBounds( columnIndex ) )
204 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
205 return getValue<util::DateTime>(columnIndex);
206 }
207
208
209 uno::Reference< io::XInputStream > SAL_CALL
210 XRow_impl::getBinaryStream(
211 sal_Int32 columnIndex )
212 {
213 if( isIndexOutOfBounds( columnIndex ) )
214 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
215 return getValue<uno::Reference< io::XInputStream >>(columnIndex);
216 }
217
218
219 uno::Reference< io::XInputStream > SAL_CALL
220 XRow_impl::getCharacterStream(
221 sal_Int32 columnIndex )
222 {
223 if( isIndexOutOfBounds( columnIndex ) )
224 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
225 return getValue<uno::Reference< io::XInputStream >>(columnIndex);
226 }
227
228
229 uno::Any SAL_CALL
230 XRow_impl::getObject(
231 sal_Int32 columnIndex,
232 const uno::Reference< container::XNameAccess >& )
233 {
234 if( isIndexOutOfBounds( columnIndex ) )
235 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
236 std::scoped_lock aGuard( m_aMutex );
237 uno::Any Value = m_aValueMap[columnIndex - 1];
238 m_nWasNull = !Value.hasValue();
239 return Value;
240 }
241
242 uno::Reference< sdbc::XRef > SAL_CALL
243 XRow_impl::getRef(
244 sal_Int32 columnIndex )
245 {
246 if( isIndexOutOfBounds( columnIndex ) )
247 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
248 return getValue<uno::Reference< sdbc::XRef >>(columnIndex);
249 }
250
251 uno::Reference< sdbc::XBlob > SAL_CALL
252 XRow_impl::getBlob(
253 sal_Int32 columnIndex )
254 {
255 if( isIndexOutOfBounds( columnIndex ) )
256 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
257 return getValue<uno::Reference< sdbc::XBlob >>(columnIndex);
258 }
259
260 uno::Reference< sdbc::XClob > SAL_CALL
261 XRow_impl::getClob(
262 sal_Int32 columnIndex )
263 {
264 if( isIndexOutOfBounds( columnIndex ) )
265 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
266 return getValue<uno::Reference< sdbc::XClob >>(columnIndex);
267 }
268
269
270 uno::Reference< sdbc::XArray > SAL_CALL
271 XRow_impl::getArray(
272 sal_Int32 columnIndex )
273 {
274 if( isIndexOutOfBounds( columnIndex ) )
275 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
276 return getValue<uno::Reference< sdbc::XArray >>(columnIndex);
277 }
278
279 bool
280 XRow_impl::isIndexOutOfBounds(sal_Int32 nIndex) const
281 {
282 return nIndex < 1 || m_aValueMap.getLength() < nIndex;
283 }
284
285 template<typename T>
286 T XRow_impl::getValue(sal_Int32 columnIndex)
287 {
288 T aValue{};
289 std::scoped_lock aGuard( m_aMutex );
290 m_nWasNull = ::convert<T>( m_pMyShell, m_xTypeConverter, m_aValueMap[ --columnIndex ], aValue );
291 return aValue;
292 }
293
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */