Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / file / filrow.cxx
blob0c78507540af23c16f3955e49a4c20504e1e70a9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "filrow.hxx"
30 #include "shell.hxx"
31 #include "prov.hxx"
33 using namespace fileaccess;
34 using namespace com::sun::star;
35 using namespace com::sun::star::uno;
37 // Funktion for TypeConverting
40 template< class _type_ >
41 sal_Bool convert( shell* pShell,
42 uno::Reference< script::XTypeConverter >& xConverter,
43 uno::Any& rValue,
44 _type_& aReturn )
46 // Try first without converting
47 sal_Bool no_success = ! ( rValue >>= aReturn );
49 if ( no_success )
51 if( ! xConverter.is() )
53 xConverter = uno::Reference< script::XTypeConverter >(
54 pShell->m_xMultiServiceFactory->createInstance(
55 rtl::OUString("com.sun.star.script.Converter") ), uno::UNO_QUERY );
58 try
60 if( rValue.hasValue() )
62 uno::Any aConvertedValue
63 = xConverter->convertTo( rValue,getCppuType( static_cast< const _type_* >(0) ) );
64 no_success = ! ( aConvertedValue >>= aReturn );
66 else
67 no_success = sal_True;
69 catch (const lang::IllegalArgumentException&)
71 no_success = sal_True;
73 catch (const script::CannotConvertException&)
75 no_success = sal_True;
78 return no_success;
82 XRow_impl::XRow_impl( shell* pMyShell,const uno::Sequence< uno::Any >& seq )
83 : m_aValueMap( seq ),
84 m_pMyShell( pMyShell ),
85 m_xProvider( pMyShell->m_pProvider ),
86 m_xTypeConverter( 0 )
90 XRow_impl::~XRow_impl()
95 void SAL_CALL
96 XRow_impl::acquire(
97 void )
98 throw()
100 OWeakObject::acquire();
103 void SAL_CALL
104 XRow_impl::release(
105 void )
106 throw()
108 OWeakObject::release();
112 uno::Any SAL_CALL
113 XRow_impl::queryInterface(
114 const uno::Type& rType )
115 throw( uno::RuntimeException )
117 uno::Any aRet = cppu::queryInterface( rType,
118 (static_cast< lang::XTypeProvider* >(this)),
119 (static_cast< sdbc::XRow* >(this)) );
120 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
124 XTYPEPROVIDER_IMPL_2( XRow_impl,
125 lang::XTypeProvider,
126 sdbc::XRow )
129 sal_Bool SAL_CALL
130 XRow_impl::wasNull(
131 void )
132 throw( sdbc::SQLException,
133 uno::RuntimeException)
135 return m_nWasNull;
139 rtl::OUString SAL_CALL
140 XRow_impl::getString(
141 sal_Int32 columnIndex )
142 throw( sdbc::SQLException,
143 uno::RuntimeException)
145 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
146 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
147 rtl::OUString Value;
148 osl::MutexGuard aGuard( m_aMutex );
149 m_nWasNull = ::convert<rtl::OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
150 return Value;
153 sal_Bool SAL_CALL
154 XRow_impl::getBoolean(
155 sal_Int32 columnIndex )
156 throw( sdbc::SQLException,
157 uno::RuntimeException)
159 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
160 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
161 sal_Bool Value( false );
162 osl::MutexGuard aGuard( m_aMutex );
163 m_nWasNull = ::convert<sal_Bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
164 return Value;
168 sal_Int8 SAL_CALL
169 XRow_impl::getByte(
170 sal_Int32 columnIndex )
171 throw( sdbc::SQLException,
172 uno::RuntimeException)
174 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
175 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
176 sal_Int8 Value( 0 );
177 osl::MutexGuard aGuard( m_aMutex );
178 m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
179 return Value;
182 sal_Int16 SAL_CALL
183 XRow_impl::getShort(
184 sal_Int32 columnIndex )
185 throw( sdbc::SQLException,
186 uno::RuntimeException)
188 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
189 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
190 sal_Int16 Value( 0 );
191 osl::MutexGuard aGuard( m_aMutex );
192 m_nWasNull = ::convert<sal_Int16>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
193 return Value;
197 sal_Int32 SAL_CALL
198 XRow_impl::getInt(
199 sal_Int32 columnIndex )
200 throw( sdbc::SQLException,
201 uno::RuntimeException)
203 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
204 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
205 sal_Int32 Value( 0 );
206 osl::MutexGuard aGuard( m_aMutex );
207 m_nWasNull = ::convert<sal_Int32>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
208 return Value;
211 sal_Int64 SAL_CALL
212 XRow_impl::getLong(
213 sal_Int32 columnIndex )
214 throw( sdbc::SQLException,
215 uno::RuntimeException)
217 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
218 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
219 sal_Int64 Value( 0 );
220 osl::MutexGuard aGuard( m_aMutex );
221 m_nWasNull = ::convert<sal_Int64>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
222 return Value;
225 float SAL_CALL
226 XRow_impl::getFloat(
227 sal_Int32 columnIndex )
228 throw( sdbc::SQLException,
229 uno::RuntimeException)
231 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
232 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
233 float Value( 0 );
234 osl::MutexGuard aGuard( m_aMutex );
235 m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
236 return Value;
239 double SAL_CALL
240 XRow_impl::getDouble(
241 sal_Int32 columnIndex )
242 throw( sdbc::SQLException,
243 uno::RuntimeException)
245 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
246 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
247 double Value( 0 );
248 osl::MutexGuard aGuard( m_aMutex );
249 m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
250 return Value;
253 uno::Sequence< sal_Int8 > SAL_CALL
254 XRow_impl::getBytes(
255 sal_Int32 columnIndex )
256 throw( sdbc::SQLException,
257 uno::RuntimeException)
259 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
260 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
261 uno::Sequence< sal_Int8 > Value(0);
262 osl::MutexGuard aGuard( m_aMutex );
263 m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
264 return Value;
267 util::Date SAL_CALL
268 XRow_impl::getDate(
269 sal_Int32 columnIndex )
270 throw( sdbc::SQLException,
271 uno::RuntimeException)
273 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
274 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
275 util::Date Value;
276 osl::MutexGuard aGuard( m_aMutex );
277 m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
278 return Value;
281 util::Time SAL_CALL
282 XRow_impl::getTime(
283 sal_Int32 columnIndex )
284 throw( sdbc::SQLException,
285 uno::RuntimeException)
287 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
288 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
289 util::Time Value;
290 osl::MutexGuard aGuard( m_aMutex );
291 m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
292 return Value;
295 util::DateTime SAL_CALL
296 XRow_impl::getTimestamp(
297 sal_Int32 columnIndex )
298 throw( sdbc::SQLException,
299 uno::RuntimeException)
301 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
302 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
303 util::DateTime Value;
304 osl::MutexGuard aGuard( m_aMutex );
305 m_nWasNull = ::convert<util::DateTime>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
306 return Value;
310 uno::Reference< io::XInputStream > SAL_CALL
311 XRow_impl::getBinaryStream(
312 sal_Int32 columnIndex )
313 throw( sdbc::SQLException,
314 uno::RuntimeException)
316 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
317 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
318 uno::Reference< io::XInputStream > Value;
319 osl::MutexGuard aGuard( m_aMutex );
320 m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
321 return Value;
325 uno::Reference< io::XInputStream > SAL_CALL
326 XRow_impl::getCharacterStream(
327 sal_Int32 columnIndex )
328 throw( sdbc::SQLException,
329 uno::RuntimeException)
331 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
332 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
333 uno::Reference< io::XInputStream > Value;
334 osl::MutexGuard aGuard( m_aMutex );
335 m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
336 return Value;
340 uno::Any SAL_CALL
341 XRow_impl::getObject(
342 sal_Int32 columnIndex,
343 const uno::Reference< container::XNameAccess >& )
344 throw( sdbc::SQLException,
345 uno::RuntimeException)
347 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
348 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
349 uno::Any Value;
350 osl::MutexGuard aGuard( m_aMutex );
351 m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
352 return Value;
355 uno::Reference< sdbc::XRef > SAL_CALL
356 XRow_impl::getRef(
357 sal_Int32 columnIndex )
358 throw( sdbc::SQLException,
359 uno::RuntimeException)
361 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
362 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
363 uno::Reference< sdbc::XRef > Value;
364 osl::MutexGuard aGuard( m_aMutex );
365 m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell,
366 m_xTypeConverter,
367 m_aValueMap[ --columnIndex ],
368 Value );
369 return Value;
372 uno::Reference< sdbc::XBlob > SAL_CALL
373 XRow_impl::getBlob(
374 sal_Int32 columnIndex )
375 throw( sdbc::SQLException,
376 uno::RuntimeException)
378 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
379 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
380 uno::Reference< sdbc::XBlob > Value;
381 osl::MutexGuard aGuard( m_aMutex );
382 m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell,
383 m_xTypeConverter,
384 m_aValueMap[ --columnIndex ],
385 Value );
386 return Value;
389 uno::Reference< sdbc::XClob > SAL_CALL
390 XRow_impl::getClob(
391 sal_Int32 columnIndex )
392 throw( sdbc::SQLException,
393 uno::RuntimeException)
395 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
396 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
397 uno::Reference< sdbc::XClob > Value;
398 osl::MutexGuard aGuard( m_aMutex );
399 m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell,
400 m_xTypeConverter,
401 m_aValueMap[ --columnIndex ],
402 Value );
403 return Value;
407 uno::Reference< sdbc::XArray > SAL_CALL
408 XRow_impl::getArray(
409 sal_Int32 columnIndex )
410 throw( sdbc::SQLException,
411 uno::RuntimeException)
413 if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
414 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
415 uno::Reference< sdbc::XArray > Value;
416 osl::MutexGuard aGuard( m_aMutex );
417 m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell,
418 m_xTypeConverter,
419 m_aValueMap[ --columnIndex ],
420 Value );
421 return Value;
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */