xref: /trunk/main/ucb/source/ucp/file/filrow.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
119   uno::Any aRet = cppu::queryInterface( rType,
120                     SAL_STATIC_CAST( lang::XTypeProvider*,this),
121                     SAL_STATIC_CAST( sdbc::XRow*,this) );
122   return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
123 }
124 
125 
XTYPEPROVIDER_IMPL_2(XRow_impl,lang::XTypeProvider,sdbc::XRow)126 XTYPEPROVIDER_IMPL_2( XRow_impl,
127                       lang::XTypeProvider,
128                       sdbc::XRow )
129 
130 
131 sal_Bool SAL_CALL
132 XRow_impl::wasNull(
133            void )
134 {
135   return m_nWasNull;
136 }
137 
138 
139 rtl::OUString SAL_CALL
getString(sal_Int32 columnIndex)140 XRow_impl::getString(
141              sal_Int32 columnIndex )
142 {
143   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
144     throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
145   rtl::OUString  Value;
146   osl::MutexGuard aGuard( m_aMutex );
147   m_nWasNull = ::convert<rtl::OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
148   return Value;
149 }
150 
151 sal_Bool SAL_CALL
getBoolean(sal_Int32 columnIndex)152 XRow_impl::getBoolean(
153     sal_Int32 columnIndex )
154 {
155     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
156         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
157     sal_Bool  Value( false );
158     osl::MutexGuard aGuard( m_aMutex );
159     m_nWasNull = ::convert<sal_Bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
160     return Value;
161 }
162 
163 
164 sal_Int8 SAL_CALL
getByte(sal_Int32 columnIndex)165 XRow_impl::getByte(
166     sal_Int32 columnIndex )
167 {
168     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
169         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
170     sal_Int8  Value( 0 );
171     osl::MutexGuard aGuard( m_aMutex );
172     m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
173     return Value;
174 }
175 
176 sal_Int16 SAL_CALL
getShort(sal_Int32 columnIndex)177 XRow_impl::getShort(
178     sal_Int32 columnIndex )
179 {
180     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
181         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
182     sal_Int16  Value( 0 );
183     osl::MutexGuard aGuard( m_aMutex );
184     m_nWasNull = ::convert<sal_Int16>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
185     return Value;
186 }
187 
188 
189 sal_Int32 SAL_CALL
getInt(sal_Int32 columnIndex)190 XRow_impl::getInt(
191           sal_Int32 columnIndex )
192 {
193     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
194         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
195     sal_Int32  Value( 0 );
196     osl::MutexGuard aGuard( m_aMutex );
197     m_nWasNull = ::convert<sal_Int32>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
198     return Value;
199 }
200 
201 sal_Int64 SAL_CALL
getLong(sal_Int32 columnIndex)202 XRow_impl::getLong(
203            sal_Int32 columnIndex )
204 {
205     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
206         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
207     sal_Int64  Value( 0 );
208     osl::MutexGuard aGuard( m_aMutex );
209     m_nWasNull = ::convert<sal_Int64>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
210     return Value;
211 }
212 
213 float SAL_CALL
getFloat(sal_Int32 columnIndex)214 XRow_impl::getFloat(
215     sal_Int32 columnIndex )
216 {
217     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
218         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
219     float  Value( 0 );
220     osl::MutexGuard aGuard( m_aMutex );
221     m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
222     return Value;
223 }
224 
225 double SAL_CALL
getDouble(sal_Int32 columnIndex)226 XRow_impl::getDouble(
227     sal_Int32 columnIndex )
228 {
229     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
230         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
231     double  Value( 0 );
232     osl::MutexGuard aGuard( m_aMutex );
233     m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
234     return Value;
235 }
236 
237 uno::Sequence< sal_Int8 > SAL_CALL
getBytes(sal_Int32 columnIndex)238 XRow_impl::getBytes(
239     sal_Int32 columnIndex )
240 {
241     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
242         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
243     uno::Sequence< sal_Int8 >  Value(0);
244     osl::MutexGuard aGuard( m_aMutex );
245     m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
246     return Value;
247 }
248 
249 util::Date SAL_CALL
getDate(sal_Int32 columnIndex)250 XRow_impl::getDate(
251     sal_Int32 columnIndex )
252 {
253     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
254         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
255     util::Date  Value;
256     osl::MutexGuard aGuard( m_aMutex );
257     m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
258     return Value;
259 }
260 
261 util::Time SAL_CALL
getTime(sal_Int32 columnIndex)262 XRow_impl::getTime(
263     sal_Int32 columnIndex )
264 {
265     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
266         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
267     util::Time  Value;
268     osl::MutexGuard aGuard( m_aMutex );
269     m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
270     return Value;
271 }
272 
273 util::DateTime SAL_CALL
getTimestamp(sal_Int32 columnIndex)274 XRow_impl::getTimestamp(
275             sal_Int32 columnIndex )
276 {
277   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
278     throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
279   util::DateTime  Value;
280   osl::MutexGuard aGuard( m_aMutex );
281   m_nWasNull = ::convert<util::DateTime>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
282   return Value;
283 }
284 
285 
286 uno::Reference< io::XInputStream > SAL_CALL
getBinaryStream(sal_Int32 columnIndex)287 XRow_impl::getBinaryStream(
288                sal_Int32 columnIndex )
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   uno::Reference< io::XInputStream >  Value;
293   osl::MutexGuard aGuard( m_aMutex );
294   m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
295   return Value;
296 }
297 
298 
299 uno::Reference< io::XInputStream > SAL_CALL
getCharacterStream(sal_Int32 columnIndex)300 XRow_impl::getCharacterStream(
301                   sal_Int32 columnIndex )
302 {
303   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
304       throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
305   uno::Reference< io::XInputStream > Value;
306   osl::MutexGuard aGuard( m_aMutex );
307   m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
308   return Value;
309 }
310 
311 
312 uno::Any SAL_CALL
getObject(sal_Int32 columnIndex,const uno::Reference<container::XNameAccess> &)313 XRow_impl::getObject(
314     sal_Int32 columnIndex,
315     const uno::Reference< container::XNameAccess >& )
316 {
317     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
318         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
319     uno::Any  Value;
320     osl::MutexGuard aGuard( m_aMutex );
321     m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
322     return Value;
323 }
324 
325 uno::Reference< sdbc::XRef > SAL_CALL
getRef(sal_Int32 columnIndex)326 XRow_impl::getRef(
327     sal_Int32 columnIndex )
328 {
329     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
330         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
331     uno::Reference< sdbc::XRef > Value;
332     osl::MutexGuard aGuard( m_aMutex );
333     m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell,
334                                                           m_xTypeConverter,
335                                                           m_aValueMap[ --columnIndex ],
336                                                           Value );
337     return Value;
338 }
339 
340 uno::Reference< sdbc::XBlob > SAL_CALL
getBlob(sal_Int32 columnIndex)341 XRow_impl::getBlob(
342            sal_Int32 columnIndex )
343 {
344     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
345         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
346     uno::Reference< sdbc::XBlob > Value;
347     osl::MutexGuard aGuard( m_aMutex );
348     m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell,
349                                                            m_xTypeConverter,
350                                                            m_aValueMap[ --columnIndex ],
351                                                            Value );
352     return Value;
353 }
354 
355 uno::Reference< sdbc::XClob > SAL_CALL
getClob(sal_Int32 columnIndex)356 XRow_impl::getClob(
357            sal_Int32 columnIndex )
358 {
359     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
360         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
361     uno::Reference< sdbc::XClob > Value;
362     osl::MutexGuard aGuard( m_aMutex );
363     m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell,
364                                                            m_xTypeConverter,
365                                                            m_aValueMap[ --columnIndex ],
366                                                            Value );
367     return Value;
368 }
369 
370 
371 uno::Reference< sdbc::XArray > SAL_CALL
getArray(sal_Int32 columnIndex)372 XRow_impl::getArray(
373     sal_Int32 columnIndex )
374 {
375     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
376         throw sdbc::SQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), ::rtl::OUString(), 0, uno::Any() );
377     uno::Reference< sdbc::XArray > Value;
378     osl::MutexGuard aGuard( m_aMutex );
379     m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell,
380                                                             m_xTypeConverter,
381                                                             m_aValueMap[ --columnIndex ],
382                                                             Value );
383     return Value;
384 }
385