Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / file / filrow.cxx
blob8342985c45cbf28daf243229f780331adb0c80b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "filrow.hxx"
21 #include "shell.hxx"
22 #include "prov.hxx"
23 #include <com/sun/star/script/Converter.hpp>
24 #include <comphelper/processfactory.hxx>
26 using namespace fileaccess;
27 using namespace com::sun::star;
28 using namespace com::sun::star::uno;
30 // Funktion for TypeConverting
33 template< class _type_ >
34 sal_Bool convert( shell* pShell,
35 uno::Reference< script::XTypeConverter >& xConverter,
36 uno::Any& rValue,
37 _type_& aReturn )
39 // Try first without converting
40 sal_Bool no_success = ! ( rValue >>= aReturn );
42 if ( no_success )
44 if( ! xConverter.is() )
46 xConverter = script::Converter::create(pShell->m_xContext);
49 try
51 if( rValue.hasValue() )
53 uno::Any aConvertedValue
54 = xConverter->convertTo( rValue,getCppuType( static_cast< const _type_* >(0) ) );
55 no_success = ! ( aConvertedValue >>= aReturn );
57 else
58 no_success = sal_True;
60 catch (const lang::IllegalArgumentException&)
62 no_success = sal_True;
64 catch (const script::CannotConvertException&)
66 no_success = sal_True;
69 return no_success;
73 XRow_impl::XRow_impl( shell* pMyShell,const uno::Sequence< uno::Any >& seq )
74 : m_aValueMap( seq ),
75 m_pMyShell( pMyShell ),
76 m_xProvider( pMyShell->m_pProvider ),
77 m_xTypeConverter( 0 )
81 XRow_impl::~XRow_impl()
86 void SAL_CALL
87 XRow_impl::acquire(
88 void )
89 throw()
91 OWeakObject::acquire();
94 void SAL_CALL
95 XRow_impl::release(
96 void )
97 throw()
99 OWeakObject::release();
103 uno::Any SAL_CALL
104 XRow_impl::queryInterface(
105 const uno::Type& rType )
106 throw( uno::RuntimeException )
108 uno::Any aRet = cppu::queryInterface( rType,
109 (static_cast< lang::XTypeProvider* >(this)),
110 (static_cast< sdbc::XRow* >(this)) );
111 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
115 XTYPEPROVIDER_IMPL_2( XRow_impl,
116 lang::XTypeProvider,
117 sdbc::XRow )
120 sal_Bool SAL_CALL
121 XRow_impl::wasNull(
122 void )
123 throw( sdbc::SQLException,
124 uno::RuntimeException)
126 return m_nWasNull;
130 rtl::OUString SAL_CALL
131 XRow_impl::getString(
132 sal_Int32 columnIndex )
133 throw( sdbc::SQLException,
134 uno::RuntimeException)
136 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
137 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
138 rtl::OUString Value;
139 osl::MutexGuard aGuard( m_aMutex );
140 m_nWasNull = ::convert<rtl::OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
141 return Value;
144 sal_Bool SAL_CALL
145 XRow_impl::getBoolean(
146 sal_Int32 columnIndex )
147 throw( sdbc::SQLException,
148 uno::RuntimeException)
150 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
151 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
152 sal_Bool Value( false );
153 osl::MutexGuard aGuard( m_aMutex );
154 m_nWasNull = ::convert<sal_Bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
155 return Value;
159 sal_Int8 SAL_CALL
160 XRow_impl::getByte(
161 sal_Int32 columnIndex )
162 throw( sdbc::SQLException,
163 uno::RuntimeException)
165 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
166 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
167 sal_Int8 Value( 0 );
168 osl::MutexGuard aGuard( m_aMutex );
169 m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
170 return Value;
173 sal_Int16 SAL_CALL
174 XRow_impl::getShort(
175 sal_Int32 columnIndex )
176 throw( sdbc::SQLException,
177 uno::RuntimeException)
179 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
180 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
181 sal_Int16 Value( 0 );
182 osl::MutexGuard aGuard( m_aMutex );
183 m_nWasNull = ::convert<sal_Int16>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
184 return Value;
188 sal_Int32 SAL_CALL
189 XRow_impl::getInt(
190 sal_Int32 columnIndex )
191 throw( sdbc::SQLException,
192 uno::RuntimeException)
194 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
195 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
196 sal_Int32 Value( 0 );
197 osl::MutexGuard aGuard( m_aMutex );
198 m_nWasNull = ::convert<sal_Int32>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
199 return Value;
202 sal_Int64 SAL_CALL
203 XRow_impl::getLong(
204 sal_Int32 columnIndex )
205 throw( sdbc::SQLException,
206 uno::RuntimeException)
208 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
209 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
210 sal_Int64 Value( 0 );
211 osl::MutexGuard aGuard( m_aMutex );
212 m_nWasNull = ::convert<sal_Int64>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
213 return Value;
216 float SAL_CALL
217 XRow_impl::getFloat(
218 sal_Int32 columnIndex )
219 throw( sdbc::SQLException,
220 uno::RuntimeException)
222 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
223 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
224 float Value( 0 );
225 osl::MutexGuard aGuard( m_aMutex );
226 m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
227 return Value;
230 double SAL_CALL
231 XRow_impl::getDouble(
232 sal_Int32 columnIndex )
233 throw( sdbc::SQLException,
234 uno::RuntimeException)
236 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
237 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
238 double Value( 0 );
239 osl::MutexGuard aGuard( m_aMutex );
240 m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
241 return Value;
244 uno::Sequence< sal_Int8 > SAL_CALL
245 XRow_impl::getBytes(
246 sal_Int32 columnIndex )
247 throw( sdbc::SQLException,
248 uno::RuntimeException)
250 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
251 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
252 uno::Sequence< sal_Int8 > Value(0);
253 osl::MutexGuard aGuard( m_aMutex );
254 m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
255 return Value;
258 util::Date SAL_CALL
259 XRow_impl::getDate(
260 sal_Int32 columnIndex )
261 throw( sdbc::SQLException,
262 uno::RuntimeException)
264 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
265 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
266 util::Date Value;
267 osl::MutexGuard aGuard( m_aMutex );
268 m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
269 return Value;
272 util::Time SAL_CALL
273 XRow_impl::getTime(
274 sal_Int32 columnIndex )
275 throw( sdbc::SQLException,
276 uno::RuntimeException)
278 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
279 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
280 util::Time Value;
281 osl::MutexGuard aGuard( m_aMutex );
282 m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
283 return Value;
286 util::DateTime SAL_CALL
287 XRow_impl::getTimestamp(
288 sal_Int32 columnIndex )
289 throw( sdbc::SQLException,
290 uno::RuntimeException)
292 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
293 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
294 util::DateTime Value;
295 osl::MutexGuard aGuard( m_aMutex );
296 m_nWasNull = ::convert<util::DateTime>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
297 return Value;
301 uno::Reference< io::XInputStream > SAL_CALL
302 XRow_impl::getBinaryStream(
303 sal_Int32 columnIndex )
304 throw( sdbc::SQLException,
305 uno::RuntimeException)
307 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
308 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
309 uno::Reference< io::XInputStream > Value;
310 osl::MutexGuard aGuard( m_aMutex );
311 m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
312 return Value;
316 uno::Reference< io::XInputStream > SAL_CALL
317 XRow_impl::getCharacterStream(
318 sal_Int32 columnIndex )
319 throw( sdbc::SQLException,
320 uno::RuntimeException)
322 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
323 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
324 uno::Reference< io::XInputStream > Value;
325 osl::MutexGuard aGuard( m_aMutex );
326 m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
327 return Value;
331 uno::Any SAL_CALL
332 XRow_impl::getObject(
333 sal_Int32 columnIndex,
334 const uno::Reference< container::XNameAccess >& )
335 throw( sdbc::SQLException,
336 uno::RuntimeException)
338 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
339 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
340 uno::Any Value;
341 osl::MutexGuard aGuard( m_aMutex );
342 m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
343 return Value;
346 uno::Reference< sdbc::XRef > SAL_CALL
347 XRow_impl::getRef(
348 sal_Int32 columnIndex )
349 throw( sdbc::SQLException,
350 uno::RuntimeException)
352 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
353 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
354 uno::Reference< sdbc::XRef > Value;
355 osl::MutexGuard aGuard( m_aMutex );
356 m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell,
357 m_xTypeConverter,
358 m_aValueMap[ --columnIndex ],
359 Value );
360 return Value;
363 uno::Reference< sdbc::XBlob > SAL_CALL
364 XRow_impl::getBlob(
365 sal_Int32 columnIndex )
366 throw( sdbc::SQLException,
367 uno::RuntimeException)
369 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
370 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
371 uno::Reference< sdbc::XBlob > Value;
372 osl::MutexGuard aGuard( m_aMutex );
373 m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell,
374 m_xTypeConverter,
375 m_aValueMap[ --columnIndex ],
376 Value );
377 return Value;
380 uno::Reference< sdbc::XClob > SAL_CALL
381 XRow_impl::getClob(
382 sal_Int32 columnIndex )
383 throw( sdbc::SQLException,
384 uno::RuntimeException)
386 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
387 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
388 uno::Reference< sdbc::XClob > Value;
389 osl::MutexGuard aGuard( m_aMutex );
390 m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell,
391 m_xTypeConverter,
392 m_aValueMap[ --columnIndex ],
393 Value );
394 return Value;
398 uno::Reference< sdbc::XArray > SAL_CALL
399 XRow_impl::getArray(
400 sal_Int32 columnIndex )
401 throw( sdbc::SQLException,
402 uno::RuntimeException)
404 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
405 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
406 uno::Reference< sdbc::XArray > Value;
407 osl::MutexGuard aGuard( m_aMutex );
408 m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell,
409 m_xTypeConverter,
410 m_aValueMap[ --columnIndex ],
411 Value );
412 return Value;
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */