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_ftp.hxx"
26 #include <ucbhelper/contentidentifier.hxx>
27 #include <com/sun/star/ucb/OpenMode.hpp>
28 #include <com/sun/star/uno/Reference.h>
29 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #endif
32 #include <com/sun/star/ucb/ListActionType.hpp>
33 #include <com/sun/star/ucb/XSourceInitialization.hpp>
34 #include <ucbhelper/resultsetmetadata.hxx>
35 #include "ftpresultsetbase.hxx"
36
37 using namespace ftp;
38 using namespace com::sun::star;
39
ResultSetBase(const uno::Reference<lang::XMultiServiceFactory> & xMSF,const uno::Reference<ucb::XContentProvider> & xProvider,sal_Int32 nOpenMode,const uno::Sequence<beans::Property> & seq,const uno::Sequence<ucb::NumberedSortingInfo> & seqSort)40 ResultSetBase::ResultSetBase(
41 const uno::Reference< lang::XMultiServiceFactory >& xMSF,
42 const uno::Reference< ucb::XContentProvider >& xProvider,
43 sal_Int32 nOpenMode,
44 const uno::Sequence< beans::Property >& seq,
45 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort )
46 : m_xMSF( xMSF ),
47 m_xProvider( xProvider ),
48 m_nRow( -1 ),
49 m_nWasNull( true ),
50 m_nOpenMode( nOpenMode ),
51 m_bRowCountFinal( true ),
52 m_sProperty( seq ),
53 m_sSortingInfo( seqSort ),
54 m_pDisposeEventListeners( 0 ),
55 m_pRowCountListeners( 0 ),
56 m_pIsFinalListeners( 0 )
57 {
58 }
59
~ResultSetBase()60 ResultSetBase::~ResultSetBase()
61 {
62 delete m_pIsFinalListeners;
63 delete m_pRowCountListeners;
64 delete m_pDisposeEventListeners;
65 }
66
67
68 // XInterface
69
70 void SAL_CALL
acquire(void)71 ResultSetBase::acquire(
72 void )
73 throw()
74 {
75 OWeakObject::acquire();
76 }
77
78
79 void SAL_CALL
release(void)80 ResultSetBase::release(
81 void )
82 throw()
83 {
84 OWeakObject::release();
85 }
86
87
88
89 uno::Any SAL_CALL
queryInterface(const uno::Type & rType)90 ResultSetBase::queryInterface(
91 const uno::Type& rType )
92 throw( uno::RuntimeException )
93 {
94 uno::Any aRet = cppu::queryInterface(
95 rType,
96 SAL_STATIC_CAST( lang::XComponent*, this),
97 SAL_STATIC_CAST( sdbc::XRow*, this),
98 SAL_STATIC_CAST( sdbc::XResultSet*, this),
99 SAL_STATIC_CAST( sdbc::XResultSetMetaDataSupplier*, this),
100 SAL_STATIC_CAST( beans::XPropertySet*, this ),
101 SAL_STATIC_CAST( ucb::XContentAccess*, this) );
102 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
103 }
104
105
106
107 // XComponent
108
109
110 void SAL_CALL
addEventListener(const uno::Reference<lang::XEventListener> & Listener)111 ResultSetBase::addEventListener(
112 const uno::Reference< lang::XEventListener >& Listener )
113 throw( uno::RuntimeException )
114 {
115 osl::MutexGuard aGuard( m_aMutex );
116
117 if ( ! m_pDisposeEventListeners )
118 m_pDisposeEventListeners =
119 new cppu::OInterfaceContainerHelper( m_aMutex );
120
121 m_pDisposeEventListeners->addInterface( Listener );
122 }
123
124
125 void SAL_CALL
removeEventListener(const uno::Reference<lang::XEventListener> & Listener)126 ResultSetBase::removeEventListener(
127 const uno::Reference< lang::XEventListener >& Listener )
128 throw( uno::RuntimeException )
129 {
130 osl::MutexGuard aGuard( m_aMutex );
131
132 if ( m_pDisposeEventListeners )
133 m_pDisposeEventListeners->removeInterface( Listener );
134 }
135
136
137
138 void SAL_CALL
dispose()139 ResultSetBase::dispose()
140 throw( uno::RuntimeException )
141 {
142 osl::MutexGuard aGuard( m_aMutex );
143
144 lang::EventObject aEvt;
145 aEvt.Source = static_cast< lang::XComponent * >( this );
146
147 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
148 {
149 m_pDisposeEventListeners->disposeAndClear( aEvt );
150 }
151 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
152 {
153 m_pRowCountListeners->disposeAndClear( aEvt );
154 }
155 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
156 {
157 m_pIsFinalListeners->disposeAndClear( aEvt );
158 }
159 }
160
161
162
163 // XResultSet
164
165 sal_Bool SAL_CALL
next(void)166 ResultSetBase::next(
167 void )
168 throw( sdbc::SQLException,
169 uno::RuntimeException )
170 {
171 sal_Bool test;
172 if( ++m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
173 test = true;
174 else
175 test = false;
176 return test;
177 }
178
179
180 sal_Bool SAL_CALL
isBeforeFirst(void)181 ResultSetBase::isBeforeFirst(
182 void )
183 throw( sdbc::SQLException,
184 uno::RuntimeException )
185 {
186 return m_nRow == -1;
187 }
188
189
190 sal_Bool SAL_CALL
isAfterLast(void)191 ResultSetBase::isAfterLast(
192 void )
193 throw( sdbc::SQLException,
194 uno::RuntimeException )
195 {
196 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
197 }
198
199
200 sal_Bool SAL_CALL
isFirst(void)201 ResultSetBase::isFirst(
202 void )
203 throw( sdbc::SQLException,
204 uno::RuntimeException )
205 {
206 return m_nRow == 0;
207 }
208
209
210 sal_Bool SAL_CALL
isLast(void)211 ResultSetBase::isLast(
212 void )
213 throw( sdbc::SQLException,
214 uno::RuntimeException)
215 {
216 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
217 return true;
218 else
219 return false;
220 }
221
222
223 void SAL_CALL
beforeFirst(void)224 ResultSetBase::beforeFirst(
225 void )
226 throw( sdbc::SQLException,
227 uno::RuntimeException)
228 {
229 m_nRow = -1;
230 }
231
232
233 void SAL_CALL
afterLast(void)234 ResultSetBase::afterLast(
235 void )
236 throw( sdbc::SQLException,
237 uno::RuntimeException )
238 {
239 m_nRow = m_aItems.size();
240 }
241
242
243 sal_Bool SAL_CALL
first(void)244 ResultSetBase::first(
245 void )
246 throw( sdbc::SQLException,
247 uno::RuntimeException)
248 {
249 m_nRow = -1;
250 return next();
251 }
252
253
254 sal_Bool SAL_CALL
last(void)255 ResultSetBase::last(
256 void )
257 throw( sdbc::SQLException,
258 uno::RuntimeException )
259 {
260 m_nRow = m_aItems.size() - 1;
261 return true;
262 }
263
264
265 sal_Int32 SAL_CALL
getRow(void)266 ResultSetBase::getRow(
267 void )
268 throw( sdbc::SQLException,
269 uno::RuntimeException)
270 {
271 // Test, whether behind last row
272 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
273 return 0;
274 else
275 return m_nRow+1;
276 }
277
278
absolute(sal_Int32 row)279 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
280 throw( sdbc::SQLException, uno::RuntimeException)
281 {
282 if( row >= 0 )
283 m_nRow = row - 1;
284 else
285 {
286 last();
287 m_nRow += ( row + 1 );
288 if( m_nRow < -1 )
289 m_nRow = -1;
290 }
291
292 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
293 }
294
295
296
297
298 sal_Bool SAL_CALL
relative(sal_Int32 row)299 ResultSetBase::relative(
300 sal_Int32 row )
301 throw( sdbc::SQLException,
302 uno::RuntimeException)
303 {
304 if( isAfterLast() || isBeforeFirst() )
305 throw sdbc::SQLException();
306
307 if( row > 0 )
308 while( row-- )
309 next();
310 else if( row < 0 )
311 while( row++ && m_nRow > - 1 )
312 previous();
313
314 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
315 }
316
317
318
319 sal_Bool SAL_CALL
previous(void)320 ResultSetBase::previous(
321 void )
322 throw( sdbc::SQLException,
323 uno::RuntimeException)
324 {
325 if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
326 m_nRow = m_aItems.size(); // Correct Handling of afterLast
327 if( 0 <= m_nRow ) -- m_nRow;
328
329 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
330 }
331
332
333 void SAL_CALL
refreshRow(void)334 ResultSetBase::refreshRow(
335 void )
336 throw( sdbc::SQLException,
337 uno::RuntimeException)
338 {
339 }
340
341
342 sal_Bool SAL_CALL
rowUpdated(void)343 ResultSetBase::rowUpdated(
344 void )
345 throw( sdbc::SQLException,
346 uno::RuntimeException )
347 {
348 return false;
349 }
350
351 sal_Bool SAL_CALL
rowInserted(void)352 ResultSetBase::rowInserted(
353 void )
354 throw( sdbc::SQLException,
355 uno::RuntimeException )
356 {
357 return false;
358 }
359
360 sal_Bool SAL_CALL
rowDeleted(void)361 ResultSetBase::rowDeleted(
362 void )
363 throw( sdbc::SQLException,
364 uno::RuntimeException )
365 {
366 return false;
367 }
368
369
370 uno::Reference< uno::XInterface > SAL_CALL
getStatement(void)371 ResultSetBase::getStatement(
372 void )
373 throw( sdbc::SQLException,
374 uno::RuntimeException )
375 {
376 uno::Reference< uno::XInterface > test( 0 );
377 return test;
378 }
379
380
381 // XCloseable
382
383 void SAL_CALL
close(void)384 ResultSetBase::close(
385 void )
386 throw( sdbc::SQLException,
387 uno::RuntimeException)
388 {
389 }
390
391
392 rtl::OUString SAL_CALL
queryContentIdentifierString(void)393 ResultSetBase::queryContentIdentifierString(
394 void )
395 throw( uno::RuntimeException )
396 {
397 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
398 return m_aPath[m_nRow];
399 else
400 return rtl::OUString();
401 }
402
403
404 uno::Reference< ucb::XContentIdentifier > SAL_CALL
queryContentIdentifier(void)405 ResultSetBase::queryContentIdentifier(
406 void
407 )
408 throw(
409 uno::RuntimeException
410 )
411 {
412 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
413 {
414 if(!m_aIdents[m_nRow].is()) {
415 rtl::OUString url = queryContentIdentifierString();
416 if(url.getLength() )
417 m_aIdents[m_nRow] =
418 uno::Reference< ucb::XContentIdentifier >(
419 new ::ucbhelper::ContentIdentifier(m_xMSF,url) );
420 }
421 return m_aIdents[m_nRow];
422 }
423
424 return uno::Reference<ucb::XContentIdentifier>();
425 }
426
427
428 uno::Reference< ucb::XContent > SAL_CALL
queryContent(void)429 ResultSetBase::queryContent(
430 void )
431 throw( uno::RuntimeException )
432 {
433 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
434 return m_xProvider->queryContent(queryContentIdentifier());
435 else
436 return uno::Reference< ucb::XContent >();
437 }
438
439
440
441 class XPropertySetInfoImpl
442 : public cppu::OWeakObject,
443 public beans::XPropertySetInfo
444 {
445 public:
446
XPropertySetInfoImpl(const uno::Sequence<beans::Property> & aSeq)447 XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
448 : m_aSeq( aSeq )
449 {
450 }
451
acquire(void)452 void SAL_CALL acquire( void )
453 throw()
454 {
455 OWeakObject::acquire();
456 }
457
458
release(void)459 void SAL_CALL release( void )
460 throw()
461 {
462 OWeakObject::release();
463 }
464
queryInterface(const uno::Type & rType)465 uno::Any SAL_CALL queryInterface( const uno::Type& rType )
466 throw( uno::RuntimeException )
467 {
468 uno::Any aRet = cppu::queryInterface(
469 rType,
470 SAL_STATIC_CAST( beans::XPropertySetInfo*, this ) );
471 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
472 }
473
getProperties()474 uno::Sequence< beans::Property > SAL_CALL getProperties()
475 throw( uno::RuntimeException )
476 {
477 return m_aSeq;
478 }
479
getPropertyByName(const::rtl::OUString & aName)480 beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName )
481 throw( beans::UnknownPropertyException,
482 uno::RuntimeException)
483 {
484 for( int i = 0; i < m_aSeq.getLength(); ++i )
485 if( aName == m_aSeq[i].Name )
486 return m_aSeq[i];
487 throw beans::UnknownPropertyException();
488 }
489
hasPropertyByName(const::rtl::OUString & Name)490 sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name )
491 throw( uno::RuntimeException )
492 {
493 for( int i = 0; i < m_aSeq.getLength(); ++i )
494 if( Name == m_aSeq[i].Name )
495 return true;
496 return false;
497 }
498
499 private:
500
501 uno::Sequence< beans::Property > m_aSeq;
502 };
503
504
505
506 // XPropertySet
507 uno::Reference< beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()508 ResultSetBase::getPropertySetInfo()
509 throw( uno::RuntimeException)
510 {
511 uno::Sequence< beans::Property > seq(2);
512 seq[0].Name = rtl::OUString::createFromAscii( "RowCount" );
513 seq[0].Handle = -1;
514 seq[0].Type = getCppuType( static_cast< sal_Int32* >(0) );
515 seq[0].Attributes = beans::PropertyAttribute::READONLY;
516
517 seq[1].Name = rtl::OUString::createFromAscii( "IsRowCountFinal" );
518 seq[1].Handle = -1;
519 seq[1].Type = getCppuType( static_cast< sal_Bool* >(0) );
520 seq[1].Attributes = beans::PropertyAttribute::READONLY;
521
522 //t
523 return uno::Reference< beans::XPropertySetInfo > (
524 new XPropertySetInfoImpl( seq ) );
525 }
526
527
528
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any &)529 void SAL_CALL ResultSetBase::setPropertyValue(
530 const rtl::OUString& aPropertyName, const uno::Any& /*aValue*/ )
531 throw( beans::UnknownPropertyException,
532 beans::PropertyVetoException,
533 lang::IllegalArgumentException,
534 lang::WrappedTargetException,
535 uno::RuntimeException)
536 {
537 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) ||
538 aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
539 return;
540
541 throw beans::UnknownPropertyException();
542 }
543
544
getPropertyValue(const rtl::OUString & PropertyName)545 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
546 const rtl::OUString& PropertyName )
547 throw( beans::UnknownPropertyException,
548 lang::WrappedTargetException,
549 uno::RuntimeException)
550 {
551 if( PropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
552 {
553 uno::Any aAny;
554 aAny <<= m_bRowCountFinal;
555 return aAny;
556 }
557 else if ( PropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
558 {
559 uno::Any aAny;
560 sal_Int32 count = m_aItems.size();
561 aAny <<= count;
562 return aAny;
563 }
564 else
565 throw beans::UnknownPropertyException();
566 }
567
568
addPropertyChangeListener(const rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & xListener)569 void SAL_CALL ResultSetBase::addPropertyChangeListener(
570 const rtl::OUString& aPropertyName,
571 const uno::Reference< beans::XPropertyChangeListener >& xListener )
572 throw( beans::UnknownPropertyException,
573 lang::WrappedTargetException,
574 uno::RuntimeException)
575 {
576 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
577 {
578 osl::MutexGuard aGuard( m_aMutex );
579 if ( ! m_pIsFinalListeners )
580 m_pIsFinalListeners =
581 new cppu::OInterfaceContainerHelper( m_aMutex );
582
583 m_pIsFinalListeners->addInterface( xListener );
584 }
585 else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
586 {
587 osl::MutexGuard aGuard( m_aMutex );
588 if ( ! m_pRowCountListeners )
589 m_pRowCountListeners =
590 new cppu::OInterfaceContainerHelper( m_aMutex );
591 m_pRowCountListeners->addInterface( xListener );
592 }
593 else
594 throw beans::UnknownPropertyException();
595 }
596
597
removePropertyChangeListener(const rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & aListener)598 void SAL_CALL ResultSetBase::removePropertyChangeListener(
599 const rtl::OUString& aPropertyName,
600 const uno::Reference< beans::XPropertyChangeListener >& aListener )
601 throw( beans::UnknownPropertyException,
602 lang::WrappedTargetException,
603 uno::RuntimeException)
604 {
605 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) &&
606 m_pIsFinalListeners )
607 {
608 osl::MutexGuard aGuard( m_aMutex );
609 m_pIsFinalListeners->removeInterface( aListener );
610 }
611 else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) &&
612 m_pRowCountListeners )
613 {
614 osl::MutexGuard aGuard( m_aMutex );
615 m_pRowCountListeners->removeInterface( aListener );
616 }
617 else
618 throw beans::UnknownPropertyException();
619 }
620
621
addVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)622 void SAL_CALL ResultSetBase::addVetoableChangeListener(
623 const rtl::OUString& /*PropertyName*/,
624 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
625 throw( beans::UnknownPropertyException,
626 lang::WrappedTargetException,
627 uno::RuntimeException)
628 {
629 }
630
631
removeVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)632 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
633 const rtl::OUString& /*PropertyName*/,
634 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
635 throw( beans::UnknownPropertyException,
636 lang::WrappedTargetException,
637 uno::RuntimeException)
638 {
639 }
640
641
642
643 // XResultSetMetaDataSupplier
644 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
getMetaData(void)645 ResultSetBase::getMetaData(
646 void )
647 throw( sdbc::SQLException,
648 uno::RuntimeException )
649 {
650 ::ucbhelper::ResultSetMetaData* p =
651 new ::ucbhelper::ResultSetMetaData(
652 m_xMSF, m_sProperty );
653 return uno::Reference< sdbc::XResultSetMetaData >( p );
654 }
655
656
657
658
659