xref: /aoo42x/main/ucb/source/ucp/file/filrow.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_ucb.hxx"
30 #include "filrow.hxx"
31 #include "shell.hxx"
32 #include "prov.hxx"
33 
34 using namespace fileaccess;
35 using namespace com::sun::star;
36 using namespace com::sun::star::uno;
37 //using namespace com::sun::star::ucb;
38 
39 
40 // Funktion for TypeConverting
41 
42 
43 template< class _type_ >
44 sal_Bool convert( shell* pShell,
45 				  uno::Reference< script::XTypeConverter >& xConverter,
46 				  uno::Any& rValue,
47 				  _type_& aReturn  )
48 {
49 	// Try first without converting
50 	sal_Bool no_success = ! ( rValue >>= aReturn );
51 
52 	if ( no_success )
53 	{
54 		if( ! xConverter.is() )
55 		{
56 			xConverter = uno::Reference< script::XTypeConverter >(
57 				pShell->m_xMultiServiceFactory->createInstance(
58 					rtl::OUString::createFromAscii( "com.sun.star.script.Converter" ) ),uno::UNO_QUERY );
59 
60 /*			DBG_ASSERT( m_xTypeConverter.is(),
61 						"PropertyValueSet::getTypeConverter() - "
62 						"Service 'com.sun.star.script.Converter' n/a!" );*/
63 		}
64 
65 		try
66 		{
67 			if( rValue.hasValue() )
68 			{
69 				uno::Any aConvertedValue
70 					= xConverter->convertTo( rValue,getCppuType( static_cast< const _type_* >(0) ) );
71 				no_success = ! ( aConvertedValue >>= aReturn );
72 			}
73 			else
74 				no_success = sal_True;
75 		}
76 		catch ( lang::IllegalArgumentException )
77 		{
78 			no_success = sal_True;
79 		}
80 		catch ( script::CannotConvertException )
81 		{
82 			no_success = sal_True;
83 		}
84 	}
85 	return no_success;
86 }
87 
88 
89 XRow_impl::XRow_impl( shell* pMyShell,const uno::Sequence< uno::Any >& seq )
90 	: m_aValueMap( seq ),
91 	  m_pMyShell( pMyShell ),
92 	  m_xProvider( pMyShell->m_pProvider ),
93 	  m_xTypeConverter( 0 )
94 {
95 }
96 
97 XRow_impl::~XRow_impl()
98 {
99 }
100 
101 
102 void SAL_CALL
103 XRow_impl::acquire(
104 		   void )
105   throw()
106 {
107   OWeakObject::acquire();
108 }
109 
110 void SAL_CALL
111 XRow_impl::release(
112 		   void )
113   throw()
114 {
115   OWeakObject::release();
116 }
117 
118 
119 uno::Any SAL_CALL
120 XRow_impl::queryInterface(
121 			  const uno::Type& rType )
122   throw( uno::RuntimeException )
123 {
124   uno::Any aRet = cppu::queryInterface( rType,
125                     SAL_STATIC_CAST( lang::XTypeProvider*,this),
126 					SAL_STATIC_CAST( sdbc::XRow*,this) );
127   return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
128 }
129 
130 
131 XTYPEPROVIDER_IMPL_2( XRow_impl,
132 				   	  lang::XTypeProvider,
133 					  sdbc::XRow )
134 
135 
136 sal_Bool SAL_CALL
137 XRow_impl::wasNull(
138 		   void )
139   throw( sdbc::SQLException,
140 	 uno::RuntimeException)
141 {
142   return m_nWasNull;
143 }
144 
145 
146 rtl::OUString SAL_CALL
147 XRow_impl::getString(
148 		     sal_Int32 columnIndex )
149   throw( sdbc::SQLException,
150 	 uno::RuntimeException)
151 {
152   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
153     throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
154   rtl::OUString  Value;
155   osl::MutexGuard aGuard( m_aMutex );
156   m_nWasNull = ::convert<rtl::OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
157   return Value;
158 }
159 
160 sal_Bool SAL_CALL
161 XRow_impl::getBoolean(
162 	sal_Int32 columnIndex )
163 	throw( sdbc::SQLException,
164 		   uno::RuntimeException)
165 {
166 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
167 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
168 	sal_Bool  Value( false );
169 	osl::MutexGuard aGuard( m_aMutex );
170 	m_nWasNull = ::convert<sal_Bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
171 	return Value;
172 }
173 
174 
175 sal_Int8 SAL_CALL
176 XRow_impl::getByte(
177 	sal_Int32 columnIndex )
178 	throw( sdbc::SQLException,
179 		   uno::RuntimeException)
180 {
181 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
182 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
183 	sal_Int8  Value( 0 );
184 	osl::MutexGuard aGuard( m_aMutex );
185 	m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
186 	return Value;
187 }
188 
189 sal_Int16 SAL_CALL
190 XRow_impl::getShort(
191 	sal_Int32 columnIndex )
192 	throw( sdbc::SQLException,
193 		   uno::RuntimeException)
194 {
195 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
196 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
197 	sal_Int16  Value( 0 );
198 	osl::MutexGuard aGuard( m_aMutex );
199 	m_nWasNull = ::convert<sal_Int16>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
200 	return Value;
201 }
202 
203 
204 sal_Int32 SAL_CALL
205 XRow_impl::getInt(
206 		  sal_Int32 columnIndex )
207 	throw( sdbc::SQLException,
208 		   uno::RuntimeException)
209 {
210 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
211 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
212 	sal_Int32  Value( 0 );
213 	osl::MutexGuard aGuard( m_aMutex );
214 	m_nWasNull = ::convert<sal_Int32>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
215 	return Value;
216 }
217 
218 sal_Int64 SAL_CALL
219 XRow_impl::getLong(
220 		   sal_Int32 columnIndex )
221   throw( sdbc::SQLException,
222 	 uno::RuntimeException)
223 {
224 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
225 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
226 	sal_Int64  Value( 0 );
227 	osl::MutexGuard aGuard( m_aMutex );
228 	m_nWasNull = ::convert<sal_Int64>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
229 	return Value;
230 }
231 
232 float SAL_CALL
233 XRow_impl::getFloat(
234 	sal_Int32 columnIndex )
235 	throw( sdbc::SQLException,
236 		   uno::RuntimeException)
237 {
238 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
239 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
240 	float  Value( 0 );
241 	osl::MutexGuard aGuard( m_aMutex );
242 	m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
243 	return Value;
244 }
245 
246 double SAL_CALL
247 XRow_impl::getDouble(
248 	sal_Int32 columnIndex )
249 	throw( sdbc::SQLException,
250 		   uno::RuntimeException)
251 {
252 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
253 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
254 	double  Value( 0 );
255 	osl::MutexGuard aGuard( m_aMutex );
256 	m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
257 	return Value;
258 }
259 
260 uno::Sequence< sal_Int8 > SAL_CALL
261 XRow_impl::getBytes(
262 	sal_Int32 columnIndex )
263 	throw( sdbc::SQLException,
264 		   uno::RuntimeException)
265 {
266 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
267 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
268 	uno::Sequence< sal_Int8 >  Value(0);
269 	osl::MutexGuard aGuard( m_aMutex );
270 	m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
271 	return Value;
272 }
273 
274 util::Date SAL_CALL
275 XRow_impl::getDate(
276 	sal_Int32 columnIndex )
277 	throw( sdbc::SQLException,
278 		   uno::RuntimeException)
279 {
280 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
281 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
282 	util::Date  Value;
283 	osl::MutexGuard aGuard( m_aMutex );
284 	m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
285 	return Value;
286 }
287 
288 util::Time SAL_CALL
289 XRow_impl::getTime(
290 	sal_Int32 columnIndex )
291   throw( sdbc::SQLException,
292 		 uno::RuntimeException)
293 {
294 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
295 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
296 	util::Time  Value;
297 	osl::MutexGuard aGuard( m_aMutex );
298 	m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
299 	return Value;
300 }
301 
302 util::DateTime SAL_CALL
303 XRow_impl::getTimestamp(
304 			sal_Int32 columnIndex )
305   throw( sdbc::SQLException,
306 	 uno::RuntimeException)
307 {
308   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
309     throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
310   util::DateTime  Value;
311   osl::MutexGuard aGuard( m_aMutex );
312   m_nWasNull = ::convert<util::DateTime>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
313   return Value;
314 }
315 
316 
317 uno::Reference< io::XInputStream > SAL_CALL
318 XRow_impl::getBinaryStream(
319 			   sal_Int32 columnIndex )
320   throw( sdbc::SQLException,
321 	 uno::RuntimeException)
322 {
323   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
324     throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
325   uno::Reference< io::XInputStream >  Value;
326   osl::MutexGuard aGuard( m_aMutex );
327   m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
328   return Value;
329 }
330 
331 
332 uno::Reference< io::XInputStream > SAL_CALL
333 XRow_impl::getCharacterStream(
334 			      sal_Int32 columnIndex )
335 	throw( sdbc::SQLException,
336 		   uno::RuntimeException)
337 {
338   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
339 	  throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
340   uno::Reference< io::XInputStream > Value;
341   osl::MutexGuard aGuard( m_aMutex );
342   m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
343   return Value;
344 }
345 
346 
347 uno::Any SAL_CALL
348 XRow_impl::getObject(
349 	sal_Int32 columnIndex,
350 	const uno::Reference< container::XNameAccess >& )
351 	throw( sdbc::SQLException,
352 		   uno::RuntimeException)
353 {
354 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
355 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
356 	uno::Any  Value;
357 	osl::MutexGuard aGuard( m_aMutex );
358 	m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
359 	return Value;
360 }
361 
362 uno::Reference< sdbc::XRef > SAL_CALL
363 XRow_impl::getRef(
364 	sal_Int32 columnIndex )
365 	throw( sdbc::SQLException,
366 		   uno::RuntimeException)
367 {
368 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
369 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
370 	uno::Reference< sdbc::XRef > Value;
371 	osl::MutexGuard aGuard( m_aMutex );
372 	m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell,
373 														  m_xTypeConverter,
374 														  m_aValueMap[ --columnIndex ],
375 														  Value );
376 	return Value;
377 }
378 
379 uno::Reference< sdbc::XBlob > SAL_CALL
380 XRow_impl::getBlob(
381 		   sal_Int32 columnIndex )
382   throw( sdbc::SQLException,
383 	 uno::RuntimeException)
384 {
385 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
386 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
387 	uno::Reference< sdbc::XBlob > Value;
388 	osl::MutexGuard aGuard( m_aMutex );
389 	m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell,
390 														   m_xTypeConverter,
391 														   m_aValueMap[ --columnIndex ],
392 														   Value );
393 	return Value;
394 }
395 
396 uno::Reference< sdbc::XClob > SAL_CALL
397 XRow_impl::getClob(
398 		   sal_Int32 columnIndex )
399   throw( sdbc::SQLException,
400 	 uno::RuntimeException)
401 {
402 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
403 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
404 	uno::Reference< sdbc::XClob > Value;
405 	osl::MutexGuard aGuard( m_aMutex );
406 	m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell,
407 														   m_xTypeConverter,
408 														   m_aValueMap[ --columnIndex ],
409 														   Value );
410 	return Value;
411 }
412 
413 
414 uno::Reference< sdbc::XArray > SAL_CALL
415 XRow_impl::getArray(
416 	sal_Int32 columnIndex )
417 	throw( sdbc::SQLException,
418 		   uno::RuntimeException)
419 {
420 	if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
421 		throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
422 	uno::Reference< sdbc::XArray > Value;
423 	osl::MutexGuard aGuard( m_aMutex );
424 	m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell,
425 															m_xTypeConverter,
426 															m_aValueMap[ --columnIndex ],
427 															Value );
428 	return Value;
429 }
430