LibreOffice Module ucb (master) 1
filrow.cxx
Go to the documentation of this file.
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
26using namespace fileaccess;
27using namespace com::sun::star;
28using 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
38template< class _type_ >
39static 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
78XRow_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
86{
87}
88
89
90sal_Bool SAL_CALL
92{
93 return m_nWasNull;
94}
95
96
97OUString SAL_CALL
99 sal_Int32 columnIndex )
100{
101 if( isIndexOutOfBounds( columnIndex ) )
102 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
103 return getValue<OUString>(columnIndex);
104}
105
106sal_Bool SAL_CALL
108 sal_Int32 columnIndex )
109{
110 if( isIndexOutOfBounds( columnIndex ) )
111 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
112 return getValue<bool>(columnIndex);
113}
114
115
116sal_Int8 SAL_CALL
118 sal_Int32 columnIndex )
119{
120 if( isIndexOutOfBounds( columnIndex ) )
121 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
122 return getValue<sal_Int8>(columnIndex);
123}
124
125sal_Int16 SAL_CALL
127 sal_Int32 columnIndex )
128{
129 if( isIndexOutOfBounds( columnIndex ) )
130 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
131 return getValue<sal_Int16>(columnIndex);
132}
133
134
135sal_Int32 SAL_CALL
137 sal_Int32 columnIndex )
138{
139 if( isIndexOutOfBounds( columnIndex ) )
140 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
141 return getValue<sal_Int32>(columnIndex);
142}
143
144sal_Int64 SAL_CALL
146 sal_Int32 columnIndex )
147{
148 if( isIndexOutOfBounds( columnIndex ) )
149 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
150 return getValue<sal_Int64>(columnIndex);
151}
152
153float SAL_CALL
155 sal_Int32 columnIndex )
156{
157 if( isIndexOutOfBounds( columnIndex ) )
158 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
159 return getValue<float>(columnIndex);
160}
161
162double SAL_CALL
164 sal_Int32 columnIndex )
165{
166 if( isIndexOutOfBounds( columnIndex ) )
167 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
168 return getValue<double>(columnIndex);
169}
170
171uno::Sequence< sal_Int8 > SAL_CALL
173 sal_Int32 columnIndex )
174{
175 if( isIndexOutOfBounds( columnIndex ) )
176 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
177 return getValue<uno::Sequence< sal_Int8 >>(columnIndex);
178}
179
180util::Date SAL_CALL
182 sal_Int32 columnIndex )
183{
184 if( isIndexOutOfBounds( columnIndex ) )
185 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
186 return getValue<util::Date>(columnIndex);
187}
188
189util::Time SAL_CALL
191 sal_Int32 columnIndex )
192{
193 if( isIndexOutOfBounds( columnIndex ) )
194 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
195 return getValue<util::Time>(columnIndex);
196}
197
198util::DateTime SAL_CALL
200 sal_Int32 columnIndex )
201{
202 if( isIndexOutOfBounds( columnIndex ) )
203 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
204 return getValue<util::DateTime>(columnIndex);
205}
206
207
208uno::Reference< io::XInputStream > SAL_CALL
210 sal_Int32 columnIndex )
211{
212 if( isIndexOutOfBounds( columnIndex ) )
213 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
214 return getValue<uno::Reference< io::XInputStream >>(columnIndex);
215}
216
217
218uno::Reference< io::XInputStream > SAL_CALL
220 sal_Int32 columnIndex )
221{
222 if( isIndexOutOfBounds( columnIndex ) )
223 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
224 return getValue<uno::Reference< io::XInputStream >>(columnIndex);
225}
226
227
228uno::Any SAL_CALL
230 sal_Int32 columnIndex,
231 const uno::Reference< container::XNameAccess >& )
232{
233 if( isIndexOutOfBounds( columnIndex ) )
234 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
235 std::scoped_lock aGuard( m_aMutex );
236 uno::Any Value = m_aValueMap[columnIndex - 1];
237 m_nWasNull = !Value.hasValue();
238 return Value;
239}
240
241uno::Reference< sdbc::XRef > SAL_CALL
243 sal_Int32 columnIndex )
244{
245 if( isIndexOutOfBounds( columnIndex ) )
246 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
247 return getValue<uno::Reference< sdbc::XRef >>(columnIndex);
248}
249
250uno::Reference< sdbc::XBlob > SAL_CALL
252 sal_Int32 columnIndex )
253{
254 if( isIndexOutOfBounds( columnIndex ) )
255 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
256 return getValue<uno::Reference< sdbc::XBlob >>(columnIndex);
257}
258
259uno::Reference< sdbc::XClob > SAL_CALL
261 sal_Int32 columnIndex )
262{
263 if( isIndexOutOfBounds( columnIndex ) )
264 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
265 return getValue<uno::Reference< sdbc::XClob >>(columnIndex);
266}
267
268
269uno::Reference< sdbc::XArray > SAL_CALL
271 sal_Int32 columnIndex )
272{
273 if( isIndexOutOfBounds( columnIndex ) )
274 throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
275 return getValue<uno::Reference< sdbc::XArray >>(columnIndex);
276}
277
278bool
279XRow_impl::isIndexOutOfBounds(sal_Int32 nIndex) const
280{
281 return nIndex < 1 || m_aValueMap.getLength() < nIndex;
282}
283
284template<typename T>
285T XRow_impl::getValue(sal_Int32 columnIndex)
286{
287 T aValue{};
288 std::scoped_lock aGuard( m_aMutex );
289 m_nWasNull = ::convert<T>( m_pMyShell, m_xTypeConverter, m_aValueMap[ --columnIndex ], aValue );
290 return aValue;
291}
292
293/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: filtask.hxx:478
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
Definition: filrow.cxx:219
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
Definition: filrow.cxx:209
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
Definition: filrow.cxx:199
css::uno::Sequence< css::uno::Any > m_aValueMap
Definition: filrow.hxx:102
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
Definition: filrow.cxx:181
bool isIndexOutOfBounds(sal_Int32 nIndex) const
Definition: filrow.cxx:279
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
Definition: filrow.cxx:163
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
Definition: filrow.cxx:242
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
Definition: filrow.cxx:154
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
Definition: filrow.cxx:136
std::mutex m_aMutex
Definition: filrow.hxx:101
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
Definition: filrow.cxx:98
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
Definition: filrow.cxx:251
TaskManager * m_pMyShell
Definition: filrow.hxx:104
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
Definition: filrow.cxx:107
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
Definition: filrow.cxx:229
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
Definition: filrow.cxx:126
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
Definition: filrow.cxx:117
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
Definition: filrow.cxx:145
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
Definition: filrow.cxx:270
css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter
Definition: filrow.hxx:105
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
Definition: filrow.cxx:260
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
Definition: filrow.cxx:172
T getValue(sal_Int32 columnIndex)
Definition: filrow.cxx:285
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
Definition: filrow.cxx:190
virtual ~XRow_impl() override
Definition: filrow.cxx:85
virtual sal_Bool SAL_CALL wasNull() override
Definition: filrow.cxx:91
Reference< XTypeConverter > xConverter
#define THROW_WHERE
Definition: filrow.cxx:31
static bool convert(TaskManager const *pShell, uno::Reference< script::XTypeConverter > &xConverter, const uno::Any &rValue, _type_ &aReturn)
Definition: filrow.cxx:39
sal_Int32 nIndex
Value
convert
bool hasValue()
unsigned char sal_Bool
signed char sal_Int8