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