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_ucbhelper.hxx"
26
27 /**************************************************************************
28 TODO
29 **************************************************************************
30
31 *************************************************************************/
32 #include <cppuhelper/interfacecontainer.hxx>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <ucbhelper/resultset.hxx>
35 #include <ucbhelper/resultsetmetadata.hxx>
36
37 using namespace com::sun::star;
38
39 //=========================================================================
40
41 namespace ucbhelper_impl
42 {
43
44 struct PropertyInfo
45 {
46 const char* pName;
47 sal_Int32 nHandle;
48 sal_Int16 nAttributes;
49 const uno::Type& (*pGetCppuType)();
50 };
51
sal_Int32_getCppuType()52 static const uno::Type& sal_Int32_getCppuType()
53 {
54 return getCppuType( static_cast< const sal_Int32 * >( 0 ) );
55 }
56
sal_Bool_getCppuType()57 static const uno::Type& sal_Bool_getCppuType()
58 {
59 return getCppuBooleanType();
60 }
61
62 static const PropertyInfo aPropertyTable[] =
63 {
64 { "IsRowCountFinal",
65 1000,
66 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY,
67 &sal_Bool_getCppuType
68 },
69 { "RowCount",
70 1001,
71 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY,
72 &sal_Int32_getCppuType
73 },
74 { 0,
75 0,
76 0,
77 0
78 }
79 };
80
81 #define RESULTSET_PROPERTY_COUNT 2
82
83 //=========================================================================
84 //
85 // class PropertySetInfo
86 //
87 //=========================================================================
88
89 class PropertySetInfo :
90 public cppu::OWeakObject,
91 public lang::XTypeProvider,
92 public beans::XPropertySetInfo
93 {
94 uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
95 uno::Sequence< beans::Property >* m_pProps;
96
97 private:
98 sal_Bool queryProperty(
99 const rtl::OUString& aName, beans::Property& rProp );
100
101 public:
102 PropertySetInfo(
103 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
104 const PropertyInfo* pProps,
105 sal_Int32 nProps );
106 virtual ~PropertySetInfo();
107
108 // XInterface
109 XINTERFACE_DECL()
110
111 // XTypeProvider
112 XTYPEPROVIDER_DECL()
113
114 // XPropertySetInfo
115 virtual uno::Sequence< beans::Property > SAL_CALL getProperties();
116 virtual beans::Property SAL_CALL getPropertyByName(
117 const rtl::OUString& aName );
118 virtual sal_Bool SAL_CALL hasPropertyByName( const rtl::OUString& Name );
119 };
120
121 //=========================================================================
122 //
123 // PropertyChangeListenerContainer.
124 //
125 //=========================================================================
126
127 struct equalStr_Impl
128 {
operator ()ucbhelper_impl::equalStr_Impl129 bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const
130 {
131 return !!( s1 == s2 );
132 }
133 };
134
135 struct hashStr_Impl
136 {
operator ()ucbhelper_impl::hashStr_Impl137 size_t operator()( const rtl::OUString& rName ) const
138 {
139 return rName.hashCode();
140 }
141 };
142
143 typedef cppu::OMultiTypeInterfaceContainerHelperVar
144 <
145 rtl::OUString,
146 hashStr_Impl,
147 equalStr_Impl
148 > PropertyChangeListenerContainer;
149
150 //=========================================================================
151 //
152 // class PropertyChangeListeners.
153 //
154 //=========================================================================
155
156 class PropertyChangeListeners : public PropertyChangeListenerContainer
157 {
158 public:
PropertyChangeListeners(osl::Mutex & rMtx)159 PropertyChangeListeners( osl::Mutex& rMtx )
160 : PropertyChangeListenerContainer( rMtx ) {}
161 };
162
163 } // namespace ucbhelper_impl
164
165 using namespace ucbhelper_impl;
166
167 namespace ucbhelper
168 {
169
170 //=========================================================================
171 //
172 // struct ResultSet_Impl.
173 //
174 //=========================================================================
175
176 struct ResultSet_Impl
177 {
178 uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
179 uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xEnv;
180 uno::Reference< beans::XPropertySetInfo > m_xPropSetInfo;
181 uno::Reference< sdbc::XResultSetMetaData > m_xMetaData;
182 uno::Sequence< beans::Property > m_aProperties;
183 rtl::Reference< ResultSetDataSupplier > m_xDataSupplier;
184 osl::Mutex m_aMutex;
185 cppu::OInterfaceContainerHelper* m_pDisposeEventListeners;
186 PropertyChangeListeners* m_pPropertyChangeListeners;
187 sal_Int32 m_nPos;
188 sal_Bool m_bWasNull;
189 sal_Bool m_bAfterLast;
190
191 inline ResultSet_Impl(
192 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
193 const uno::Sequence< beans::Property >& rProperties,
194 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier,
195 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >&
196 rxEnv );
197 inline ~ResultSet_Impl();
198 };
199
ResultSet_Impl(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,const uno::Sequence<beans::Property> & rProperties,const rtl::Reference<ResultSetDataSupplier> & rDataSupplier,const uno::Reference<com::sun::star::ucb::XCommandEnvironment> & rxEnv)200 inline ResultSet_Impl::ResultSet_Impl(
201 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
202 const uno::Sequence< beans::Property >& rProperties,
203 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier,
204 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv )
205 : m_xSMgr( rxSMgr ),
206 m_xEnv( rxEnv ),
207 m_aProperties( rProperties ),
208 m_xDataSupplier( rDataSupplier ),
209 m_pDisposeEventListeners( 0 ),
210 m_pPropertyChangeListeners( 0 ),
211 m_nPos( 0 ), // Position is one-based. Zero means: before first element.
212 m_bWasNull( sal_False ),
213 m_bAfterLast( sal_False )
214 {
215 }
216
217 //=========================================================================
~ResultSet_Impl()218 inline ResultSet_Impl::~ResultSet_Impl()
219 {
220 delete m_pDisposeEventListeners;
221 delete m_pPropertyChangeListeners;
222 }
223
224 //=========================================================================
225 //=========================================================================
226 //
227 // ResultSet Implementation.
228 //
229 //=========================================================================
230 //=========================================================================
231
ResultSet(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,const uno::Sequence<beans::Property> & rProperties,const rtl::Reference<ResultSetDataSupplier> & rDataSupplier)232 ResultSet::ResultSet(
233 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
234 const uno::Sequence< beans::Property >& rProperties,
235 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier )
236 : m_pImpl( new ResultSet_Impl(
237 rxSMgr,
238 rProperties,
239 rDataSupplier,
240 uno::Reference< com::sun::star::ucb::XCommandEnvironment >() ) )
241 {
242 rDataSupplier->m_pResultSet = this;
243 }
244
245 //=========================================================================
ResultSet(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,const uno::Sequence<beans::Property> & rProperties,const rtl::Reference<ResultSetDataSupplier> & rDataSupplier,const uno::Reference<com::sun::star::ucb::XCommandEnvironment> & rxEnv)246 ResultSet::ResultSet(
247 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
248 const uno::Sequence< beans::Property >& rProperties,
249 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier,
250 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv )
251 : m_pImpl( new ResultSet_Impl( rxSMgr, rProperties, rDataSupplier, rxEnv ) )
252 {
253 rDataSupplier->m_pResultSet = this;
254 }
255
256 //=========================================================================
257 // virtual
~ResultSet()258 ResultSet::~ResultSet()
259 {
260 delete m_pImpl;
261 }
262
263 //=========================================================================
264 //
265 // XInterface methods.
266 //
267 //=========================================================================
268
269 XINTERFACE_IMPL_9( ResultSet,
270 lang::XTypeProvider,
271 lang::XServiceInfo,
272 lang::XComponent,
273 com::sun::star::ucb::XContentAccess,
274 sdbc::XResultSet,
275 sdbc::XResultSetMetaDataSupplier,
276 sdbc::XRow,
277 sdbc::XCloseable,
278 beans::XPropertySet );
279
280 //=========================================================================
281 //
282 // XTypeProvider methods.
283 //
284 //=========================================================================
285
286 XTYPEPROVIDER_IMPL_9( ResultSet,
287 lang::XTypeProvider,
288 lang::XServiceInfo,
289 lang::XComponent,
290 com::sun::star::ucb::XContentAccess,
291 sdbc::XResultSet,
292 sdbc::XResultSetMetaDataSupplier,
293 sdbc::XRow,
294 sdbc::XCloseable,
295 beans::XPropertySet );
296
297 //=========================================================================
298 //
299 // XServiceInfo methods.
300 //
301 //=========================================================================
302
303 XSERVICEINFO_NOFACTORY_IMPL_1( ResultSet,
304 rtl::OUString::createFromAscii( "ResultSet" ),
305 rtl::OUString::createFromAscii( RESULTSET_SERVICE_NAME ) );
306
307 //=========================================================================
308 //
309 // XComponent methods.
310 //
311 //=========================================================================
312
313 // virtual
dispose()314 void SAL_CALL ResultSet::dispose()
315 {
316 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
317
318 if ( m_pImpl->m_pDisposeEventListeners &&
319 m_pImpl->m_pDisposeEventListeners->getLength() )
320 {
321 lang::EventObject aEvt;
322 aEvt.Source = static_cast< lang::XComponent * >( this );
323 m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
324 }
325
326 if ( m_pImpl->m_pPropertyChangeListeners )
327 {
328 lang::EventObject aEvt;
329 aEvt.Source = static_cast< beans::XPropertySet * >( this );
330 m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
331 }
332
333 m_pImpl->m_xDataSupplier->close();
334 }
335
336 //=========================================================================
337 // virtual
addEventListener(const uno::Reference<lang::XEventListener> & Listener)338 void SAL_CALL ResultSet::addEventListener(
339 const uno::Reference< lang::XEventListener >& Listener )
340 {
341 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
342
343 if ( !m_pImpl->m_pDisposeEventListeners )
344 m_pImpl->m_pDisposeEventListeners =
345 new cppu::OInterfaceContainerHelper( m_pImpl->m_aMutex );
346
347 m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
348 }
349
350 //=========================================================================
351 // virtual
removeEventListener(const uno::Reference<lang::XEventListener> & Listener)352 void SAL_CALL ResultSet::removeEventListener(
353 const uno::Reference< lang::XEventListener >& Listener )
354 {
355 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
356
357 if ( m_pImpl->m_pDisposeEventListeners )
358 m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
359 }
360
361 //=========================================================================
362 //
363 // XResultSetMetaDataSupplier methods.
364 //
365 //=========================================================================
366
367 // virtual
getMetaData()368 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL ResultSet::getMetaData()
369 {
370 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
371
372 if ( !m_pImpl->m_xMetaData.is() )
373 m_pImpl->m_xMetaData = new ResultSetMetaData( m_pImpl->m_xSMgr,
374 m_pImpl->m_aProperties );
375
376 return m_pImpl->m_xMetaData;
377 }
378
379 //=========================================================================
380 //
381 // XResultSet methods.
382 //
383 //=========================================================================
384
385 // virtual
next()386 sal_Bool SAL_CALL ResultSet::next()
387 {
388 // Note: Cursor is initially positioned before the first row.
389 // First call to 'next()' moves it to first row.
390
391 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
392
393 if ( m_pImpl->m_bAfterLast )
394 {
395 m_pImpl->m_xDataSupplier->validate();
396 return sal_False;
397 }
398
399 // getResult works zero-based!
400 if ( !m_pImpl->m_xDataSupplier->getResult( m_pImpl->m_nPos ) )
401 {
402 m_pImpl->m_bAfterLast = sal_True;
403 m_pImpl->m_xDataSupplier->validate();
404 return sal_False;
405 }
406
407 m_pImpl->m_nPos++;
408 m_pImpl->m_xDataSupplier->validate();
409 return sal_True;
410 }
411
412 //=========================================================================
413 // virtual
isBeforeFirst()414 sal_Bool SAL_CALL ResultSet::isBeforeFirst()
415 {
416 if ( m_pImpl->m_bAfterLast )
417 {
418 m_pImpl->m_xDataSupplier->validate();
419 return sal_False;
420 }
421
422 // getResult works zero-based!
423 if ( !m_pImpl->m_xDataSupplier->getResult( 0 ) )
424 {
425 m_pImpl->m_xDataSupplier->validate();
426 return sal_False;
427 }
428
429 m_pImpl->m_xDataSupplier->validate();
430 return ( m_pImpl->m_nPos == 0 );
431 }
432
433 //=========================================================================
434 // virtual
isAfterLast()435 sal_Bool SAL_CALL ResultSet::isAfterLast()
436 {
437 m_pImpl->m_xDataSupplier->validate();
438 return m_pImpl->m_bAfterLast;
439 }
440
441 //=========================================================================
442 // virtual
isFirst()443 sal_Bool SAL_CALL ResultSet::isFirst()
444 {
445 if ( m_pImpl->m_bAfterLast )
446 {
447 m_pImpl->m_xDataSupplier->validate();
448 return sal_False;
449 }
450
451 m_pImpl->m_xDataSupplier->validate();
452 return ( m_pImpl->m_nPos == 1 );
453 }
454
455 //=========================================================================
456 // virtual
isLast()457 sal_Bool SAL_CALL ResultSet::isLast()
458 {
459 if ( m_pImpl->m_bAfterLast )
460 {
461 m_pImpl->m_xDataSupplier->validate();
462 return sal_False;
463 }
464
465 sal_Int32 nCount = m_pImpl->m_xDataSupplier->totalCount();
466 if ( !nCount )
467 {
468 m_pImpl->m_xDataSupplier->validate();
469 return sal_False;
470 }
471
472 m_pImpl->m_xDataSupplier->validate();
473 return ( m_pImpl->m_nPos == nCount );
474 }
475
476 //=========================================================================
477 // virtual
beforeFirst()478 void SAL_CALL ResultSet::beforeFirst()
479 {
480 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
481 m_pImpl->m_bAfterLast = sal_False;
482 m_pImpl->m_nPos = 0;
483 m_pImpl->m_xDataSupplier->validate();
484 }
485
486 //=========================================================================
487 // virtual
afterLast()488 void SAL_CALL ResultSet::afterLast()
489 {
490 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
491 m_pImpl->m_bAfterLast = sal_True;
492 m_pImpl->m_xDataSupplier->validate();
493 }
494
495 //=========================================================================
496 // virtual
first()497 sal_Bool SAL_CALL ResultSet::first()
498 {
499 // getResult works zero-based!
500 if ( m_pImpl->m_xDataSupplier->getResult( 0 ) )
501 {
502 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
503 m_pImpl->m_bAfterLast = sal_False;
504 m_pImpl->m_nPos = 1;
505 m_pImpl->m_xDataSupplier->validate();
506 return sal_True;
507 }
508
509 m_pImpl->m_xDataSupplier->validate();
510 return sal_False;
511 }
512
513 //=========================================================================
514 // virtual
last()515 sal_Bool SAL_CALL ResultSet::last()
516 {
517 sal_Int32 nCount = m_pImpl->m_xDataSupplier->totalCount();
518 if ( nCount )
519 {
520 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
521 m_pImpl->m_bAfterLast = sal_False;
522 m_pImpl->m_nPos = nCount;
523 m_pImpl->m_xDataSupplier->validate();
524 return sal_True;
525 }
526
527 m_pImpl->m_xDataSupplier->validate();
528 return sal_False;
529 }
530
531 //=========================================================================
532 // virtual
getRow()533 sal_Int32 SAL_CALL ResultSet::getRow()
534 {
535 if ( m_pImpl->m_bAfterLast )
536 {
537 m_pImpl->m_xDataSupplier->validate();
538 return 0;
539 }
540
541 m_pImpl->m_xDataSupplier->validate();
542 return m_pImpl->m_nPos;
543 }
544
545 //=========================================================================
546 // virtual
absolute(sal_Int32 row)547 sal_Bool SAL_CALL ResultSet::absolute( sal_Int32 row )
548 {
549 /*
550 If the row number is positive, the cursor moves to the given row number
551 with respect to the beginning of the result set. The first row is row 1,
552 the second is row 2, and so on.
553
554 If the given row number is negative, the cursor moves to an absolute row
555 position with respect to the end of the result set. For example, calling
556 absolute( -1 ) positions the cursor on the last row, absolute( -2 )
557 indicates the next-to-last row, and so on.
558
559 An attempt to position the cursor beyond the first/last row in the result
560 set leaves the cursor before/after the first/last row, respectively.
561
562 Calling absolute( 1 ) is the same as calling first().
563
564 Calling absolute( -1 ) is the same as calling last().
565 */
566 if ( row < 0 )
567 {
568 sal_Int32 nCount = m_pImpl->m_xDataSupplier->totalCount();
569
570 if ( ( row * -1 ) > nCount )
571 {
572 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
573 m_pImpl->m_bAfterLast = sal_False;
574 m_pImpl->m_nPos = 0;
575 m_pImpl->m_xDataSupplier->validate();
576 return sal_False;
577 }
578 else // |row| <= nCount
579 {
580 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
581 m_pImpl->m_bAfterLast = sal_False;
582 m_pImpl->m_nPos = ( nCount + row + 1 );
583 m_pImpl->m_xDataSupplier->validate();
584 return sal_True;
585 }
586 }
587 else if ( row == 0 )
588 {
589 // @throws SQLException
590 // ... if row is 0 ...
591 throw sdbc::SQLException();
592 }
593 else // row > 0
594 {
595 sal_Int32 nCount = m_pImpl->m_xDataSupplier->totalCount();
596
597 if ( row <= nCount )
598 {
599 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
600 m_pImpl->m_bAfterLast = sal_False;
601 m_pImpl->m_nPos = row;
602 m_pImpl->m_xDataSupplier->validate();
603 return sal_True;
604 }
605 else // row > nCount
606 {
607 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
608 m_pImpl->m_bAfterLast = sal_True;
609 m_pImpl->m_xDataSupplier->validate();
610 return sal_False;
611 }
612 }
613
614 // unreachable...
615 }
616
617 //=========================================================================
618 // virtual
relative(sal_Int32 rows)619 sal_Bool SAL_CALL ResultSet::relative( sal_Int32 rows )
620 {
621 /*
622 Attempting to move beyond the first/last row in the result set
623 positions the cursor before/after the first/last row.
624
625 Calling relative( 0 ) is valid, but does not change the cursor position.
626
627 Calling relative( 1 ) is different from calling next() because it makes
628 sense to call next() when there is no current row, for example, when
629 the cursor is positioned before the first row or after the last row of
630 the result set.
631 */
632 if ( m_pImpl->m_bAfterLast || ( m_pImpl->m_nPos == 0 ) )
633 {
634 // "No current row".
635 throw sdbc::SQLException();
636 }
637
638 if ( rows < 0 )
639 {
640 if ( ( m_pImpl->m_nPos + rows ) > 0 )
641 {
642 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
643 m_pImpl->m_bAfterLast = sal_False;
644 m_pImpl->m_nPos = ( m_pImpl->m_nPos + rows );
645 m_pImpl->m_xDataSupplier->validate();
646 return sal_True;
647 }
648 else
649 {
650 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
651 m_pImpl->m_bAfterLast = sal_False;
652 m_pImpl->m_nPos = 0;
653 m_pImpl->m_xDataSupplier->validate();
654 return sal_False;
655 }
656 }
657 else if ( rows == 0 )
658 {
659 // nop.
660 m_pImpl->m_xDataSupplier->validate();
661 return sal_True;
662 }
663 else // rows > 0
664 {
665 sal_Int32 nCount = m_pImpl->m_xDataSupplier->totalCount();
666 if ( ( m_pImpl->m_nPos + rows ) <= nCount )
667 {
668 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
669 m_pImpl->m_bAfterLast = sal_False;
670 m_pImpl->m_nPos = ( m_pImpl->m_nPos + rows );
671 m_pImpl->m_xDataSupplier->validate();
672 return sal_True;
673 }
674 else
675 {
676 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
677 m_pImpl->m_bAfterLast = sal_True;
678 m_pImpl->m_xDataSupplier->validate();
679 return sal_False;
680 }
681 }
682
683 // unreachable...
684 }
685
686 //=========================================================================
687 // virtual
previous()688 sal_Bool SAL_CALL ResultSet::previous()
689 {
690 /*
691 previous() is not the same as relative( -1 ) because it makes sense
692 to call previous() when there is no current row.
693 */
694 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
695
696 if ( m_pImpl->m_bAfterLast )
697 {
698 m_pImpl->m_bAfterLast = sal_False;
699 sal_Int32 nCount = m_pImpl->m_xDataSupplier->totalCount();
700 m_pImpl->m_nPos = nCount;
701 }
702 else if ( m_pImpl->m_nPos )
703 m_pImpl->m_nPos--;
704
705 if ( m_pImpl->m_nPos )
706 {
707 m_pImpl->m_xDataSupplier->validate();
708 return sal_True;
709 }
710
711 m_pImpl->m_xDataSupplier->validate();
712 return sal_False;
713 }
714
715 //=========================================================================
716 // virtual
refreshRow()717 void SAL_CALL ResultSet::refreshRow()
718 {
719 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
720 if ( m_pImpl->m_bAfterLast || ( m_pImpl->m_nPos == 0 ) )
721 return;
722
723 m_pImpl->m_xDataSupplier->releasePropertyValues( m_pImpl->m_nPos );
724 m_pImpl->m_xDataSupplier->validate();
725 }
726
727 //=========================================================================
728 // virtual
rowUpdated()729 sal_Bool SAL_CALL ResultSet::rowUpdated()
730 {
731 m_pImpl->m_xDataSupplier->validate();
732 return sal_False;
733 }
734
735 //=========================================================================
736 // virtual
rowInserted()737 sal_Bool SAL_CALL ResultSet::rowInserted()
738 {
739 m_pImpl->m_xDataSupplier->validate();
740 return sal_False;
741 }
742
743 //=========================================================================
744 // virtual
rowDeleted()745 sal_Bool SAL_CALL ResultSet::rowDeleted()
746 {
747 m_pImpl->m_xDataSupplier->validate();
748 return sal_False;
749 }
750
751 //=========================================================================
752 // virtual
getStatement()753 uno::Reference< uno::XInterface > SAL_CALL ResultSet::getStatement()
754 {
755 /*
756 returns the Statement that produced this ResultSet object. If the
757 result set was generated some other way, ... this method returns null.
758 */
759 m_pImpl->m_xDataSupplier->validate();
760 return uno::Reference< uno::XInterface >();
761 }
762
763 //=========================================================================
764 //
765 // XRow methods.
766 //
767 //=========================================================================
768
769 // virtual
wasNull()770 sal_Bool SAL_CALL ResultSet::wasNull()
771 {
772 // This method can not be implemented correctly!!! Imagine different
773 // threads doing a getXYZ - wasNull calling sequence on the same
774 // implementation object...
775
776 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
777 {
778 uno::Reference< sdbc::XRow > xValues
779 = m_pImpl->m_xDataSupplier->queryPropertyValues(
780 m_pImpl->m_nPos - 1 );
781 if ( xValues.is() )
782 {
783 m_pImpl->m_xDataSupplier->validate();
784 return xValues->wasNull();
785 }
786 }
787
788 m_pImpl->m_xDataSupplier->validate();
789 return m_pImpl->m_bWasNull;
790 }
791
792 //=========================================================================
793 // virtual
getString(sal_Int32 columnIndex)794 rtl::OUString SAL_CALL ResultSet::getString( sal_Int32 columnIndex )
795 {
796 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
797 {
798 uno::Reference< sdbc::XRow > xValues
799 = m_pImpl->m_xDataSupplier->queryPropertyValues(
800 m_pImpl->m_nPos - 1 );
801 if ( xValues.is() )
802 {
803 m_pImpl->m_bWasNull = sal_False;
804 m_pImpl->m_xDataSupplier->validate();
805 return xValues->getString( columnIndex );
806 }
807 }
808
809 m_pImpl->m_bWasNull = sal_True;
810 m_pImpl->m_xDataSupplier->validate();
811 return rtl::OUString();
812 }
813
814 //=========================================================================
815 // virtual
getBoolean(sal_Int32 columnIndex)816 sal_Bool SAL_CALL ResultSet::getBoolean( sal_Int32 columnIndex )
817 {
818 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
819 {
820 uno::Reference< sdbc::XRow > xValues
821 = m_pImpl->m_xDataSupplier->queryPropertyValues(
822 m_pImpl->m_nPos - 1 );
823 if ( xValues.is() )
824 {
825 m_pImpl->m_bWasNull = sal_False;
826 m_pImpl->m_xDataSupplier->validate();
827 return xValues->getBoolean( columnIndex );
828 }
829 }
830
831 m_pImpl->m_bWasNull = sal_True;
832 m_pImpl->m_xDataSupplier->validate();
833 return sal_False;
834 }
835
836 //=========================================================================
837 // virtual
getByte(sal_Int32 columnIndex)838 sal_Int8 SAL_CALL ResultSet::getByte( sal_Int32 columnIndex )
839 {
840 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
841 {
842 uno::Reference< sdbc::XRow > xValues
843 = m_pImpl->m_xDataSupplier->queryPropertyValues(
844 m_pImpl->m_nPos - 1 );
845 if ( xValues.is() )
846 {
847 m_pImpl->m_bWasNull = sal_False;
848 m_pImpl->m_xDataSupplier->validate();
849 return xValues->getByte( columnIndex );
850 }
851 }
852
853 m_pImpl->m_bWasNull = sal_True;
854 m_pImpl->m_xDataSupplier->validate();
855 return 0;
856 }
857
858 //=========================================================================
859 // virtual
getShort(sal_Int32 columnIndex)860 sal_Int16 SAL_CALL ResultSet::getShort( sal_Int32 columnIndex )
861 {
862 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
863 {
864 uno::Reference< sdbc::XRow > xValues
865 = m_pImpl->m_xDataSupplier->queryPropertyValues(
866 m_pImpl->m_nPos - 1 );
867 if ( xValues.is() )
868 {
869 m_pImpl->m_bWasNull = sal_False;
870 m_pImpl->m_xDataSupplier->validate();
871 return xValues->getShort( columnIndex );
872 }
873 }
874
875 m_pImpl->m_bWasNull = sal_True;
876 m_pImpl->m_xDataSupplier->validate();
877 return 0;
878 }
879
880 //=========================================================================
881 // virtual
getInt(sal_Int32 columnIndex)882 sal_Int32 SAL_CALL ResultSet::getInt( sal_Int32 columnIndex )
883 {
884 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
885 {
886 uno::Reference< sdbc::XRow > xValues
887 = m_pImpl->m_xDataSupplier->queryPropertyValues(
888 m_pImpl->m_nPos - 1 );
889 if ( xValues.is() )
890 {
891 m_pImpl->m_bWasNull = sal_False;
892 m_pImpl->m_xDataSupplier->validate();
893 return xValues->getInt( columnIndex );
894 }
895 }
896
897 m_pImpl->m_bWasNull = sal_True;
898 m_pImpl->m_xDataSupplier->validate();
899 return 0;
900 }
901
902 //=========================================================================
903 // virtual
getLong(sal_Int32 columnIndex)904 sal_Int64 SAL_CALL ResultSet::getLong( sal_Int32 columnIndex )
905 {
906 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
907 {
908 uno::Reference< sdbc::XRow > xValues
909 = m_pImpl->m_xDataSupplier->queryPropertyValues(
910 m_pImpl->m_nPos - 1 );
911 if ( xValues.is() )
912 {
913 m_pImpl->m_bWasNull = sal_False;
914 m_pImpl->m_xDataSupplier->validate();
915 return xValues->getLong( columnIndex );
916 }
917 }
918
919 m_pImpl->m_bWasNull = sal_True;
920 m_pImpl->m_xDataSupplier->validate();
921 return 0;
922 }
923
924 //=========================================================================
925 // virtual
getFloat(sal_Int32 columnIndex)926 float SAL_CALL ResultSet::getFloat( sal_Int32 columnIndex )
927 {
928 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
929 {
930 uno::Reference< sdbc::XRow > xValues
931 = m_pImpl->m_xDataSupplier->queryPropertyValues(
932 m_pImpl->m_nPos - 1 );
933 if ( xValues.is() )
934 {
935 m_pImpl->m_bWasNull = sal_False;
936 m_pImpl->m_xDataSupplier->validate();
937 return xValues->getFloat( columnIndex );
938 }
939 }
940
941 m_pImpl->m_bWasNull = sal_True;
942 m_pImpl->m_xDataSupplier->validate();
943 return 0;
944 }
945
946 //=========================================================================
947 // virtual
getDouble(sal_Int32 columnIndex)948 double SAL_CALL ResultSet::getDouble( sal_Int32 columnIndex )
949 {
950 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
951 {
952 uno::Reference< sdbc::XRow > xValues
953 = m_pImpl->m_xDataSupplier->queryPropertyValues(
954 m_pImpl->m_nPos - 1 );
955 if ( xValues.is() )
956 {
957 m_pImpl->m_bWasNull = sal_False;
958 m_pImpl->m_xDataSupplier->validate();
959 return xValues->getDouble( columnIndex );
960 }
961 }
962
963 m_pImpl->m_bWasNull = sal_True;
964 m_pImpl->m_xDataSupplier->validate();
965 return 0;
966 }
967
968 //=========================================================================
969 // virtual
970 uno::Sequence< sal_Int8 > SAL_CALL
getBytes(sal_Int32 columnIndex)971 ResultSet::getBytes( sal_Int32 columnIndex )
972 {
973 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
974 {
975 uno::Reference< sdbc::XRow > xValues
976 = m_pImpl->m_xDataSupplier->queryPropertyValues(
977 m_pImpl->m_nPos - 1 );
978 if ( xValues.is() )
979 {
980 m_pImpl->m_bWasNull = sal_False;
981 m_pImpl->m_xDataSupplier->validate();
982 return xValues->getBytes( columnIndex );
983 }
984 }
985
986 m_pImpl->m_bWasNull = sal_True;
987 m_pImpl->m_xDataSupplier->validate();
988 return uno::Sequence< sal_Int8 >();
989 }
990
991 //=========================================================================
992 // virtual
getDate(sal_Int32 columnIndex)993 util::Date SAL_CALL ResultSet::getDate( sal_Int32 columnIndex )
994 {
995 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
996 {
997 uno::Reference< sdbc::XRow > xValues
998 = m_pImpl->m_xDataSupplier->queryPropertyValues(
999 m_pImpl->m_nPos - 1 );
1000 if ( xValues.is() )
1001 {
1002 m_pImpl->m_bWasNull = sal_False;
1003 m_pImpl->m_xDataSupplier->validate();
1004 return xValues->getDate( columnIndex );
1005 }
1006 }
1007
1008 m_pImpl->m_bWasNull = sal_True;
1009 m_pImpl->m_xDataSupplier->validate();
1010 return util::Date();
1011 }
1012
1013 //=========================================================================
1014 // virtual
getTime(sal_Int32 columnIndex)1015 util::Time SAL_CALL ResultSet::getTime( sal_Int32 columnIndex )
1016 {
1017 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1018 {
1019 uno::Reference< sdbc::XRow > xValues
1020 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1021 m_pImpl->m_nPos - 1 );
1022 if ( xValues.is() )
1023 {
1024 m_pImpl->m_bWasNull = sal_False;
1025 m_pImpl->m_xDataSupplier->validate();
1026 return xValues->getTime( columnIndex );
1027 }
1028 }
1029
1030 m_pImpl->m_bWasNull = sal_True;
1031 m_pImpl->m_xDataSupplier->validate();
1032 return util::Time();
1033 }
1034
1035 //=========================================================================
1036 // virtual
1037 util::DateTime SAL_CALL
getTimestamp(sal_Int32 columnIndex)1038 ResultSet::getTimestamp( sal_Int32 columnIndex )
1039 {
1040 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1041 {
1042 uno::Reference< sdbc::XRow > xValues
1043 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1044 m_pImpl->m_nPos - 1 );
1045 if ( xValues.is() )
1046 {
1047 m_pImpl->m_bWasNull = sal_False;
1048 m_pImpl->m_xDataSupplier->validate();
1049 return xValues->getTimestamp( columnIndex );
1050 }
1051 }
1052
1053 m_pImpl->m_bWasNull = sal_True;
1054 m_pImpl->m_xDataSupplier->validate();
1055 return util::DateTime();
1056 }
1057
1058 //=========================================================================
1059 // virtual
1060 uno::Reference< io::XInputStream > SAL_CALL
getBinaryStream(sal_Int32 columnIndex)1061 ResultSet::getBinaryStream( sal_Int32 columnIndex )
1062 {
1063 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1064 {
1065 uno::Reference< sdbc::XRow > xValues
1066 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1067 m_pImpl->m_nPos - 1 );
1068 if ( xValues.is() )
1069 {
1070 m_pImpl->m_bWasNull = sal_False;
1071 m_pImpl->m_xDataSupplier->validate();
1072 return xValues->getBinaryStream( columnIndex );
1073 }
1074 }
1075
1076 m_pImpl->m_bWasNull = sal_True;
1077 m_pImpl->m_xDataSupplier->validate();
1078 return uno::Reference< io::XInputStream >();
1079 }
1080
1081 //=========================================================================
1082 // virtual
1083 uno::Reference< io::XInputStream > SAL_CALL
getCharacterStream(sal_Int32 columnIndex)1084 ResultSet::getCharacterStream( sal_Int32 columnIndex )
1085 {
1086 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1087 {
1088 uno::Reference< sdbc::XRow > xValues
1089 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1090 m_pImpl->m_nPos - 1 );
1091 if ( xValues.is() )
1092 {
1093 m_pImpl->m_bWasNull = sal_False;
1094 m_pImpl->m_xDataSupplier->validate();
1095 return xValues->getCharacterStream( columnIndex );
1096 }
1097 }
1098
1099 m_pImpl->m_bWasNull = sal_True;
1100 m_pImpl->m_xDataSupplier->validate();
1101 return uno::Reference< io::XInputStream >();
1102 }
1103
1104 //=========================================================================
1105 // virtual
getObject(sal_Int32 columnIndex,const uno::Reference<container::XNameAccess> & typeMap)1106 uno::Any SAL_CALL ResultSet::getObject(
1107 sal_Int32 columnIndex,
1108 const uno::Reference< container::XNameAccess >& typeMap )
1109 {
1110 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1111 {
1112 uno::Reference< sdbc::XRow > xValues
1113 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1114 m_pImpl->m_nPos - 1 );
1115 if ( xValues.is() )
1116 {
1117 m_pImpl->m_bWasNull = sal_False;
1118 m_pImpl->m_xDataSupplier->validate();
1119 return xValues->getObject( columnIndex, typeMap );
1120 }
1121 }
1122
1123 m_pImpl->m_bWasNull = sal_True;
1124 m_pImpl->m_xDataSupplier->validate();
1125 return uno::Any();
1126 }
1127
1128 //=========================================================================
1129 // virtual
1130 uno::Reference< sdbc::XRef > SAL_CALL
getRef(sal_Int32 columnIndex)1131 ResultSet::getRef( sal_Int32 columnIndex )
1132 {
1133 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1134 {
1135 uno::Reference< sdbc::XRow > xValues
1136 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1137 m_pImpl->m_nPos - 1 );
1138 if ( xValues.is() )
1139 {
1140 m_pImpl->m_bWasNull = sal_False;
1141 m_pImpl->m_xDataSupplier->validate();
1142 return xValues->getRef( columnIndex );
1143 }
1144 }
1145
1146 m_pImpl->m_bWasNull = sal_True;
1147 m_pImpl->m_xDataSupplier->validate();
1148 return uno::Reference< sdbc::XRef >();
1149 }
1150
1151 //=========================================================================
1152 // virtual
1153 uno::Reference< sdbc::XBlob > SAL_CALL
getBlob(sal_Int32 columnIndex)1154 ResultSet::getBlob( sal_Int32 columnIndex )
1155 {
1156 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1157 {
1158 uno::Reference< sdbc::XRow > xValues
1159 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1160 m_pImpl->m_nPos - 1 );
1161 if ( xValues.is() )
1162 {
1163 m_pImpl->m_bWasNull = sal_False;
1164 m_pImpl->m_xDataSupplier->validate();
1165 return xValues->getBlob( columnIndex );
1166 }
1167 }
1168
1169 m_pImpl->m_bWasNull = sal_True;
1170 m_pImpl->m_xDataSupplier->validate();
1171 return uno::Reference< sdbc::XBlob >();
1172 }
1173
1174 //=========================================================================
1175 // virtual
1176 uno::Reference< sdbc::XClob > SAL_CALL
getClob(sal_Int32 columnIndex)1177 ResultSet::getClob( sal_Int32 columnIndex )
1178 {
1179 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1180 {
1181 uno::Reference< sdbc::XRow > xValues
1182 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1183 m_pImpl->m_nPos - 1 );
1184 if ( xValues.is() )
1185 {
1186 m_pImpl->m_bWasNull = sal_False;
1187 m_pImpl->m_xDataSupplier->validate();
1188 return xValues->getClob( columnIndex );
1189 }
1190 }
1191
1192 m_pImpl->m_bWasNull = sal_True;
1193 m_pImpl->m_xDataSupplier->validate();
1194 return uno::Reference< sdbc::XClob >();
1195 }
1196
1197 //=========================================================================
1198 // virtual
1199 uno::Reference< sdbc::XArray > SAL_CALL
getArray(sal_Int32 columnIndex)1200 ResultSet::getArray( sal_Int32 columnIndex )
1201 {
1202 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1203 {
1204 uno::Reference< sdbc::XRow > xValues
1205 = m_pImpl->m_xDataSupplier->queryPropertyValues(
1206 m_pImpl->m_nPos - 1 );
1207 if ( xValues.is() )
1208 {
1209 m_pImpl->m_bWasNull = sal_False;
1210 m_pImpl->m_xDataSupplier->validate();
1211 return xValues->getArray( columnIndex );
1212 }
1213 }
1214
1215 m_pImpl->m_bWasNull = sal_True;
1216 m_pImpl->m_xDataSupplier->validate();
1217 return uno::Reference< sdbc::XArray >();
1218 }
1219
1220 //=========================================================================
1221 //
1222 // XCloseable methods.
1223 //
1224 //=========================================================================
1225
1226 // virtual
close()1227 void SAL_CALL ResultSet::close()
1228 {
1229 m_pImpl->m_xDataSupplier->close();
1230 m_pImpl->m_xDataSupplier->validate();
1231 }
1232
1233 //=========================================================================
1234 //
1235 // XContentAccess methods.
1236 //
1237 //=========================================================================
1238
1239 // virtual
queryContentIdentifierString()1240 rtl::OUString SAL_CALL ResultSet::queryContentIdentifierString()
1241 {
1242 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1243 return m_pImpl->m_xDataSupplier->queryContentIdentifierString(
1244 m_pImpl->m_nPos - 1 );
1245
1246 return rtl::OUString();
1247 }
1248
1249 //=========================================================================
1250 // virtual
1251 uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL
queryContentIdentifier()1252 ResultSet::queryContentIdentifier()
1253 {
1254 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1255 return m_pImpl->m_xDataSupplier->queryContentIdentifier(
1256 m_pImpl->m_nPos - 1 );
1257
1258 return uno::Reference< com::sun::star::ucb::XContentIdentifier >();
1259 }
1260
1261 //=========================================================================
1262 // virtual
1263 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
queryContent()1264 ResultSet::queryContent()
1265 {
1266 if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast )
1267 return m_pImpl->m_xDataSupplier->queryContent( m_pImpl->m_nPos - 1 );
1268
1269 return uno::Reference< com::sun::star::ucb::XContent >();
1270 }
1271
1272 //=========================================================================
1273 //
1274 // XPropertySet methods.
1275 //
1276 //=========================================================================
1277
1278 // virtual
1279 uno::Reference< beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()1280 ResultSet::getPropertySetInfo()
1281 {
1282 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
1283
1284 if ( !m_pImpl->m_xPropSetInfo.is() )
1285 m_pImpl->m_xPropSetInfo
1286 = new PropertySetInfo( m_pImpl->m_xSMgr,
1287 aPropertyTable,
1288 RESULTSET_PROPERTY_COUNT );
1289 return m_pImpl->m_xPropSetInfo;
1290 }
1291
1292 //=========================================================================
1293 // virtual
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any &)1294 void SAL_CALL ResultSet::setPropertyValue( const rtl::OUString& aPropertyName,
1295 const uno::Any& )
1296 {
1297 if ( !aPropertyName.getLength() )
1298 throw beans::UnknownPropertyException();
1299
1300 if ( aPropertyName.equals(
1301 rtl::OUString::createFromAscii( "RowCount" ) ) )
1302 {
1303 // property is read-only.
1304 throw lang::IllegalArgumentException();
1305 }
1306 else if ( aPropertyName.equals(
1307 rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) )
1308 {
1309 // property is read-only.
1310 throw lang::IllegalArgumentException();
1311 }
1312 else
1313 {
1314 throw beans::UnknownPropertyException();
1315 }
1316 }
1317
1318 //=========================================================================
1319 // virtual
getPropertyValue(const rtl::OUString & PropertyName)1320 uno::Any SAL_CALL ResultSet::getPropertyValue(
1321 const rtl::OUString& PropertyName )
1322 {
1323 if ( !PropertyName.getLength() )
1324 throw beans::UnknownPropertyException();
1325
1326 uno::Any aValue;
1327
1328 if ( PropertyName.equals(
1329 rtl::OUString::createFromAscii( "RowCount" ) ) )
1330 {
1331 aValue <<= m_pImpl->m_xDataSupplier->currentCount();
1332 }
1333 else if ( PropertyName.equals(
1334 rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) )
1335 {
1336 aValue <<= m_pImpl->m_xDataSupplier->isCountFinal();
1337 }
1338 else
1339 {
1340 throw beans::UnknownPropertyException();
1341 }
1342
1343 return aValue;
1344 }
1345
1346 //=========================================================================
1347 // virtual
addPropertyChangeListener(const rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & xListener)1348 void SAL_CALL ResultSet::addPropertyChangeListener(
1349 const rtl::OUString& aPropertyName,
1350 const uno::Reference< beans::XPropertyChangeListener >& xListener )
1351 {
1352 // Note: An empty property name means a listener for "all" properties.
1353
1354 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
1355
1356 if ( aPropertyName.getLength() &&
1357 !aPropertyName.equals(
1358 rtl::OUString::createFromAscii( "RowCount" ) ) &&
1359 !aPropertyName.equals(
1360 rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) )
1361 throw beans::UnknownPropertyException();
1362
1363 if ( !m_pImpl->m_pPropertyChangeListeners )
1364 m_pImpl->m_pPropertyChangeListeners
1365 = new PropertyChangeListeners( m_pImpl->m_aMutex );
1366
1367 m_pImpl->m_pPropertyChangeListeners->addInterface(
1368 aPropertyName, xListener );
1369 }
1370
1371 //=========================================================================
1372 // virtual
removePropertyChangeListener(const rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & xListener)1373 void SAL_CALL ResultSet::removePropertyChangeListener(
1374 const rtl::OUString& aPropertyName,
1375 const uno::Reference< beans::XPropertyChangeListener >& xListener )
1376 {
1377 osl::MutexGuard aGuard( m_pImpl->m_aMutex );
1378
1379 if ( aPropertyName.getLength() &&
1380 !aPropertyName.equals(
1381 rtl::OUString::createFromAscii( "RowCount" ) ) &&
1382 !aPropertyName.equals(
1383 rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) )
1384 throw beans::UnknownPropertyException();
1385
1386 if ( m_pImpl->m_pPropertyChangeListeners )
1387 m_pImpl->m_pPropertyChangeListeners->removeInterface(
1388 aPropertyName, xListener );
1389
1390 }
1391
1392 //=========================================================================
1393 // virtual
addVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1394 void SAL_CALL ResultSet::addVetoableChangeListener(
1395 const rtl::OUString&,
1396 const uno::Reference< beans::XVetoableChangeListener >& )
1397 {
1398 // No constrained props, at the moment.
1399 }
1400
1401 //=========================================================================
1402 // virtual
removeVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1403 void SAL_CALL ResultSet::removeVetoableChangeListener(
1404 const rtl::OUString&,
1405 const uno::Reference< beans::XVetoableChangeListener >& )
1406 {
1407 // No constrained props, at the moment.
1408 }
1409
1410 //=========================================================================
1411 //
1412 // Non-interface methods.
1413 //
1414 //=========================================================================
1415
propertyChanged(const beans::PropertyChangeEvent & rEvt)1416 void ResultSet::propertyChanged( const beans::PropertyChangeEvent& rEvt )
1417 {
1418 if ( !m_pImpl->m_pPropertyChangeListeners )
1419 return;
1420
1421 // Notify listeners interested especially in the changed property.
1422 cppu::OInterfaceContainerHelper* pPropsContainer
1423 = m_pImpl->m_pPropertyChangeListeners->getContainer(
1424 rEvt.PropertyName );
1425 if ( pPropsContainer )
1426 {
1427 cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
1428 while ( aIter.hasMoreElements() )
1429 {
1430 uno::Reference< beans::XPropertyChangeListener > xListener(
1431 aIter.next(), uno::UNO_QUERY );
1432 if ( xListener.is() )
1433 xListener->propertyChange( rEvt );
1434 }
1435 }
1436
1437 // Notify listeners interested in all properties.
1438 pPropsContainer
1439 = m_pImpl->m_pPropertyChangeListeners->getContainer( rtl::OUString() );
1440 if ( pPropsContainer )
1441 {
1442 cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
1443 while ( aIter.hasMoreElements() )
1444 {
1445 uno::Reference< beans::XPropertyChangeListener > xListener(
1446 aIter.next(), uno::UNO_QUERY );
1447 if ( xListener.is() )
1448 xListener->propertyChange( rEvt );
1449 }
1450 }
1451 }
1452
1453 //=========================================================================
rowCountChanged(sal_uInt32 nOld,sal_uInt32 nNew)1454 void ResultSet::rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew )
1455 {
1456 OSL_ENSURE( nOld < nNew, "ResultSet::rowCountChanged - nOld >= nNew!" );
1457
1458 if ( !m_pImpl->m_pPropertyChangeListeners )
1459 return;
1460
1461 propertyChanged(
1462 beans::PropertyChangeEvent(
1463 static_cast< cppu::OWeakObject * >( this ),
1464 rtl::OUString::createFromAscii( "RowCount" ),
1465 sal_False,
1466 1001,
1467 uno::makeAny( nOld ), // old value
1468 uno::makeAny( nNew ) ) ); // new value
1469 }
1470
1471 //=========================================================================
rowCountFinal()1472 void ResultSet::rowCountFinal()
1473 {
1474 if ( !m_pImpl->m_pPropertyChangeListeners )
1475 return;
1476
1477 propertyChanged(
1478 beans::PropertyChangeEvent(
1479 static_cast< cppu::OWeakObject * >( this ),
1480 rtl::OUString::createFromAscii( "IsRowCountFinal" ),
1481 sal_False,
1482 1000,
1483 uno:: makeAny( sal_False ), // old value
1484 uno::makeAny( sal_True ) ) ); // new value
1485 }
1486
1487 //=========================================================================
getProperties()1488 const uno::Sequence< beans::Property >& ResultSet::getProperties()
1489 {
1490 return m_pImpl->m_aProperties;
1491 }
1492
1493 //=========================================================================
1494 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >&
getEnvironment()1495 ResultSet::getEnvironment()
1496 {
1497 return m_pImpl->m_xEnv;
1498 }
1499
1500 } // namespace ucbhelper
1501
1502 namespace ucbhelper_impl {
1503
1504 //=========================================================================
1505 //=========================================================================
1506 //
1507 // PropertySetInfo Implementation.
1508 //
1509 //=========================================================================
1510 //=========================================================================
1511
PropertySetInfo(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,const PropertyInfo * pProps,sal_Int32 nProps)1512 PropertySetInfo::PropertySetInfo(
1513 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
1514 const PropertyInfo* pProps,
1515 sal_Int32 nProps )
1516 : m_xSMgr( rxSMgr )
1517 {
1518 m_pProps = new uno::Sequence< beans::Property >( nProps );
1519
1520 if ( nProps )
1521 {
1522 const PropertyInfo* pEntry = pProps;
1523 beans::Property* pProperties = m_pProps->getArray();
1524
1525 for ( sal_Int32 n = 0; n < nProps; ++n )
1526 {
1527 beans::Property& rProp = pProperties[ n ];
1528
1529 rProp.Name = rtl::OUString::createFromAscii( pEntry->pName );
1530 rProp.Handle = pEntry->nHandle;
1531 rProp.Type = pEntry->pGetCppuType();
1532 rProp.Attributes = pEntry->nAttributes;
1533
1534 pEntry++;
1535 }
1536 }
1537 }
1538
1539 //=========================================================================
1540 // virtual
~PropertySetInfo()1541 PropertySetInfo::~PropertySetInfo()
1542 {
1543 delete m_pProps;
1544 }
1545
1546 //=========================================================================
1547 //
1548 // XInterface methods.
1549 //
1550 //=========================================================================
1551
1552 XINTERFACE_IMPL_2( PropertySetInfo,
1553 lang::XTypeProvider,
1554 beans::XPropertySetInfo );
1555
1556 //=========================================================================
1557 //
1558 // XTypeProvider methods.
1559 //
1560 //=========================================================================
1561
1562 XTYPEPROVIDER_IMPL_2( PropertySetInfo,
1563 lang::XTypeProvider,
1564 beans::XPropertySetInfo );
1565
1566 //=========================================================================
1567 //
1568 // XPropertySetInfo methods.
1569 //
1570 //=========================================================================
1571
1572 // virtual
getProperties()1573 uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
1574 {
1575 return uno::Sequence< beans::Property >( *m_pProps );
1576 }
1577
1578 //=========================================================================
1579 // virtual
getPropertyByName(const rtl::OUString & aName)1580 beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
1581 const rtl::OUString& aName )
1582 {
1583 beans::Property aProp;
1584 if ( queryProperty( aName, aProp ) )
1585 return aProp;
1586
1587 throw beans::UnknownPropertyException();
1588 }
1589
1590 //=========================================================================
1591 // virtual
hasPropertyByName(const rtl::OUString & Name)1592 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName(
1593 const rtl::OUString& Name )
1594 {
1595 beans::Property aProp;
1596 return queryProperty( Name, aProp );
1597 }
1598
1599 //=========================================================================
queryProperty(const rtl::OUString & aName,beans::Property & rProp)1600 sal_Bool PropertySetInfo::queryProperty(
1601 const rtl::OUString& aName, beans::Property& rProp )
1602 {
1603 sal_Int32 nCount = m_pProps->getLength();
1604 const beans::Property* pProps = m_pProps->getConstArray();
1605 for ( sal_Int32 n = 0; n < nCount; ++n )
1606 {
1607 const beans::Property& rCurr = pProps[ n ];
1608 if ( rCurr.Name == aName )
1609 {
1610 rProp = rCurr;
1611 return sal_True;
1612 }
1613 }
1614
1615 return sal_False;
1616 }
1617
1618 } // namespace ucbhelper_impl
1619