22 #include <com/sun/star/sdbc/FetchDirection.hpp>
23 #include <com/sun/star/sdbc/SQLException.hpp>
24 #include <com/sun/star/ucb/FetchError.hpp>
25 #include <osl/diagnose.h>
41 , m_bColumnCountCached(
false )
42 , m_bNeedToPropagateFetchSize( true )
43 , m_bFirstFetchSizePropagationDone(
false )
44 , m_nLastFetchSize( 1 )
45 , m_bLastFetchDirection( true )
46 , m_aPropertyNameForFetchSize( OUString(
"FetchSize") )
47 , m_aPropertyNameForFetchDirection( OUString(
"FetchDirection") )
62 OWeakObject::acquire();
68 OWeakObject::release();
71 Any SAL_CALL CachedContentResultSetStub
72 ::queryInterface(
const Type& rType )
81 , static_cast< XTypeProvider* >(
this )
82 , static_cast< XServiceInfo* >(
this )
83 , static_cast< XFetchProvider* >(
this )
84 , static_cast< XFetchProviderForContentAccess* >(
this )
87 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
95 void CachedContentResultSetStub
96 ::impl_propertyChange(
const PropertyChangeEvent& rEvt )
98 impl_EnsureNotDisposed();
102 if( rEvt.PropertyName == m_aPropertyNameForFetchSize
103 || rEvt.PropertyName == m_aPropertyNameForFetchDirection )
106 PropertyChangeEvent aEvt( rEvt );
108 aEvt.Further =
false;
110 impl_notifyPropertyChangeListeners( aEvt );
115 void CachedContentResultSetStub
116 ::impl_vetoableChange(
const PropertyChangeEvent& rEvt )
118 impl_EnsureNotDisposed();
122 if( rEvt.PropertyName == m_aPropertyNameForFetchSize
123 || rEvt.PropertyName == m_aPropertyNameForFetchDirection )
126 PropertyChangeEvent aEvt( rEvt );
128 aEvt.Further =
false;
130 impl_notifyVetoableChangeListeners( aEvt );
165 return "com.sun.star.comp.ucb.CachedContentResultSetStub";
175 return {
"com.sun.star.ucb.CachedContentResultSetStub" };
184 sal_Int32 nRowStartPosition, sal_Int32 nRowCount,
bool bDirection,
185 std::function<
void( css::uno::Any& rRowContent)> impl_loadRow)
190 OSL_FAIL(
"broadcaster was disposed already" );
195 aRet.StartIndex = nRowStartPosition;
196 aRet.Orientation = bDirection;
197 aRet.FetchError = FetchError::SUCCESS;
201 if( nOldOriginal_Pos != nRowStartPosition )
204 aRet.FetchError = FetchError::EXCEPTION;
208 aRet.FetchError = FetchError::EXCEPTION;
210 aRet.Rows.realloc( 1 );
214 impl_loadRow( aRet.Rows.getArray()[0] );
216 catch( SQLException& )
218 aRet.Rows.realloc( 0 );
219 aRet.FetchError = FetchError::EXCEPTION;
224 aRet.Rows.realloc( nRowCount );
225 auto pRows = aRet.Rows.getArray();
226 bool bOldOriginal_AfterLast =
false;
227 if( !nOldOriginal_Pos )
232 bool bValidNewPos =
false;
238 catch( SQLException& )
240 aRet.Rows.realloc( 0 );
241 aRet.FetchError = FetchError::EXCEPTION;
246 aRet.Rows.realloc( 0 );
247 aRet.FetchError = FetchError::EXCEPTION;
250 if( nOldOriginal_Pos )
252 else if( bOldOriginal_AfterLast )
259 for( ; nN <= nRowCount; )
261 impl_loadRow( pRows[nN-1] );
263 if( nN <= nRowCount )
269 aRet.Rows.realloc( nN-1 );
270 aRet.FetchError = FetchError::ENDOFDATA;
278 aRet.Rows.realloc( nN-1 );
279 aRet.FetchError = FetchError::ENDOFDATA;
286 catch( SQLException& )
288 aRet.Rows.realloc( nN-1 );
289 aRet.FetchError = FetchError::EXCEPTION;
292 if( nOldOriginal_Pos )
294 else if( bOldOriginal_AfterLast )
301 FetchResult SAL_CALL CachedContentResultSetStub
302 ::fetch( sal_Int32 nRowStartPosition
303 , sal_Int32 nRowCount,
sal_Bool bDirection )
305 impl_init_xRowOrigin();
306 return impl_fetchHelper( nRowStartPosition, nRowCount, bDirection,
307 [&](css::uno::Any& rRowContent)
308 {
return impl_getCurrentRowContent(rRowContent, m_xRowOrigin); });
311 sal_Int32 CachedContentResultSetStub
312 ::impl_getColumnCount()
317 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
318 nCount = m_nColumnCount;
319 bCached = m_bColumnCountCached;
327 nCount = xMetaData->getColumnCount();
329 catch( SQLException& )
331 OSL_FAIL(
"couldn't determine the column count" );
335 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
336 m_nColumnCount = nCount;
337 m_bColumnCountCached =
true;
338 return m_nColumnCount;
341 void CachedContentResultSetStub
342 ::impl_getCurrentRowContent( Any& rRowContent
345 sal_Int32
nCount = impl_getColumnCount();
348 auto aContentRange = asNonConstRange(aContent);
349 for( sal_Int32 nN = 1; nN <= nCount; nN++ )
351 aContentRange[nN-1] = xRow->getObject( nN,
nullptr );
354 rRowContent <<= aContent;
357 void CachedContentResultSetStub
358 ::impl_propagateFetchSizeAndDirection( sal_Int32 nFetchSize,
bool bFetchDirection )
367 if( !m_bNeedToPropagateFetchSize )
373 bool bFirstPropagationDone;
375 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
376 bNeedAction = m_bNeedToPropagateFetchSize;
377 nLastSize = m_nLastFetchSize;
378 bLastDirection = m_bLastFetchDirection;
379 bFirstPropagationDone = m_bFirstFetchSizePropagationDone;
384 if( nLastSize == nFetchSize
385 && bLastDirection == bFetchDirection
386 && bFirstPropagationDone )
389 if(!bFirstPropagationDone)
394 bool bHasSize = xPropertySetInfo->hasPropertyByName( m_aPropertyNameForFetchSize );
395 bool bHasDirection = xPropertySetInfo->hasPropertyByName( m_aPropertyNameForFetchDirection );
397 if(!bHasSize || !bHasDirection)
399 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
400 m_bNeedToPropagateFetchSize =
false;
405 bool bSetSize = ( nLastSize !=nFetchSize ) || !bFirstPropagationDone;
406 bool bSetDirection = ( bLastDirection !=bFetchDirection ) || !bFirstPropagationDone;
409 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
410 m_bFirstFetchSizePropagationDone =
true;
411 m_nLastFetchSize = nFetchSize;
412 m_bLastFetchDirection = bFetchDirection;
418 aValue <<= nFetchSize;
423 catch( css::uno::Exception& ) {}
428 sal_Int32 nFetchDirection = FetchDirection::FORWARD;
429 if( !bFetchDirection )
430 nFetchDirection = FetchDirection::REVERSE;
432 aValue <<= nFetchDirection;
437 catch( css::uno::Exception& ) {}
444 void CachedContentResultSetStub
445 ::impl_getCurrentContentIdentifierString( Any& rAny
448 rAny <<= xContentAccess->queryContentIdentifierString();
451 void CachedContentResultSetStub
452 ::impl_getCurrentContentIdentifier( Any& rAny
455 rAny <<= xContentAccess->queryContentIdentifier();
458 void CachedContentResultSetStub
459 ::impl_getCurrentContent( Any& rAny
462 rAny <<= xContentAccess->queryContent();
466 FetchResult SAL_CALL CachedContentResultSetStub
467 ::fetchContentIdentifierStrings( sal_Int32 nRowStartPosition
468 , sal_Int32 nRowCount,
sal_Bool bDirection )
470 impl_init_xContentAccessOrigin();
471 return impl_fetchHelper( nRowStartPosition, nRowCount, bDirection,
472 [&](css::uno::Any& rRowContent)
473 {
return impl_getCurrentContentIdentifierString(rRowContent, m_xContentAccessOrigin); });
477 FetchResult SAL_CALL CachedContentResultSetStub
478 ::fetchContentIdentifiers( sal_Int32 nRowStartPosition
479 , sal_Int32 nRowCount,
sal_Bool bDirection )
481 impl_init_xContentAccessOrigin();
482 return impl_fetchHelper( nRowStartPosition, nRowCount, bDirection,
483 [&](css::uno::Any& rRowContent)
484 {
return impl_getCurrentContentIdentifier(rRowContent, m_xContentAccessOrigin); });
488 FetchResult SAL_CALL CachedContentResultSetStub
489 ::fetchContents( sal_Int32 nRowStartPosition
490 , sal_Int32 nRowCount,
sal_Bool bDirection )
492 impl_init_xContentAccessOrigin();
493 return impl_fetchHelper( nRowStartPosition, nRowCount, bDirection,
494 [&](css::uno::Any& rRowContent)
495 {
return impl_getCurrentContent(rRowContent, m_xContentAccessOrigin); });
514 return "com.sun.star.comp.ucb.CachedContentResultSetStubFactory";
522 return {
"com.sun.star.ucb.CachedContentResultSetStubFactory" };
528 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
530 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
543 ::createCachedContentResultSetStub(
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
CachedContentResultSetStub(css::uno::Reference< css::sdbc::XResultSet > const &xOrigin)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
bool impl_isForwardOnly()
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::ucb::FetchResult impl_fetchHelper(sal_Int32 nRowStartPosition, sal_Int32 nRowCount, bool bDirection, std::function< void(css::uno::Any &rRowContent)> impl_loadRow)
virtual void SAL_CALL release() noexcept override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL acquire() noexcept override
class SAL_NO_VTABLE XPropertySet
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
XTYPEPROVIDER_COMMON_IMPL(UcbContentProviderProxy)
void impl_propagateFetchSizeAndDirection(sal_Int32 nFetchSize, bool bFetchDirection)
virtual ~CachedContentResultSetStubFactory() override
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
CachedContentResultSetStubFactory()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_CachedContentResultSetStubFactory_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
css::uno::Reference< css::sdbc::XResultSet > m_xResultSetOrigin
virtual ~CachedContentResultSetStub() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
void impl_EnsureNotDisposed()
bool m_bDetectedRangeSegmentation false
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override