12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
32f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file
52f86921cSAndrew Rist * distributed with this work for additional information
62f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
72f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist * with the License. You may obtain a copy of the License at
102f86921cSAndrew Rist *
112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122f86921cSAndrew Rist *
132f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist * software distributed under the License is distributed on an
152f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist * KIND, either express or implied. See the License for the
172f86921cSAndrew Rist * specific language governing permissions and limitations
182f86921cSAndrew Rist * under the License.
192f86921cSAndrew Rist *
202f86921cSAndrew Rist *************************************************************/
212f86921cSAndrew Rist
222f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25421ed02eSdamjan #include "precompiled_cacher.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <cachedcontentresultsetstub.hxx>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ucb/FetchError.hpp>
30cdf0e10cSrcweir #include <osl/diagnose.h>
31cdf0e10cSrcweir
32cdf0e10cSrcweir using namespace com::sun::star::beans;
33cdf0e10cSrcweir using namespace com::sun::star::lang;
34cdf0e10cSrcweir using namespace com::sun::star::sdbc;
35cdf0e10cSrcweir using namespace com::sun::star::ucb;
36cdf0e10cSrcweir using namespace com::sun::star::uno;
37cdf0e10cSrcweir using namespace com::sun::star::util;
38cdf0e10cSrcweir using namespace cppu;
39cdf0e10cSrcweir using namespace rtl;
40cdf0e10cSrcweir
CachedContentResultSetStub(Reference<XResultSet> xOrigin)41cdf0e10cSrcweir CachedContentResultSetStub::CachedContentResultSetStub( Reference< XResultSet > xOrigin )
42cdf0e10cSrcweir : ContentResultSetWrapper( xOrigin )
43cdf0e10cSrcweir , m_nColumnCount( 0 )
44cdf0e10cSrcweir , m_bColumnCountCached( sal_False )
45cdf0e10cSrcweir , m_bNeedToPropagateFetchSize( sal_True )
46cdf0e10cSrcweir , m_bFirstFetchSizePropagationDone( sal_False )
47cdf0e10cSrcweir , m_nLastFetchSize( 1 )//this value is not important at all
48cdf0e10cSrcweir , m_bLastFetchDirection( sal_True )//this value is not important at all
49cdf0e10cSrcweir , m_aPropertyNameForFetchSize( OUString::createFromAscii( "FetchSize" ) )
50cdf0e10cSrcweir , m_aPropertyNameForFetchDirection( OUString::createFromAscii( "FetchDirection" ) )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir impl_init();
53cdf0e10cSrcweir }
54cdf0e10cSrcweir
~CachedContentResultSetStub()55cdf0e10cSrcweir CachedContentResultSetStub::~CachedContentResultSetStub()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir impl_deinit();
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
60cdf0e10cSrcweir //--------------------------------------------------------------------------
61cdf0e10cSrcweir // XInterface methods.
62cdf0e10cSrcweir //--------------------------------------------------------------------------
XINTERFACE_COMMON_IMPL(CachedContentResultSetStub)63cdf0e10cSrcweir XINTERFACE_COMMON_IMPL( CachedContentResultSetStub )
64cdf0e10cSrcweir
65cdf0e10cSrcweir Any SAL_CALL CachedContentResultSetStub
66cdf0e10cSrcweir ::queryInterface( const Type& rType )
67cdf0e10cSrcweir throw ( RuntimeException )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir //list all interfaces inclusive baseclasses of interfaces
70cdf0e10cSrcweir
71cdf0e10cSrcweir Any aRet = ContentResultSetWrapper::queryInterface( rType );
72cdf0e10cSrcweir if( aRet.hasValue() )
73cdf0e10cSrcweir return aRet;
74cdf0e10cSrcweir
75cdf0e10cSrcweir aRet = cppu::queryInterface( rType
76cdf0e10cSrcweir , static_cast< XTypeProvider* >( this )
77cdf0e10cSrcweir , static_cast< XServiceInfo* >( this )
78cdf0e10cSrcweir , static_cast< XFetchProvider* >( this )
79cdf0e10cSrcweir , static_cast< XFetchProviderForContentAccess* >( this )
80cdf0e10cSrcweir );
81cdf0e10cSrcweir
82cdf0e10cSrcweir return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir //--------------------------------------------------------------------------
86cdf0e10cSrcweir // own methods. ( inherited )
87cdf0e10cSrcweir //--------------------------------------------------------------------------
88cdf0e10cSrcweir
89cdf0e10cSrcweir //virtual
90cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_propertyChange(const PropertyChangeEvent & rEvt)91cdf0e10cSrcweir ::impl_propertyChange( const PropertyChangeEvent& rEvt )
92cdf0e10cSrcweir throw( RuntimeException )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir impl_EnsureNotDisposed();
95cdf0e10cSrcweir
96cdf0e10cSrcweir //don't notify events on fetchsize and fetchdirection to the above CachedContentResultSet
97cdf0e10cSrcweir //because it will ignore them anyway and we can save this remote calls
98cdf0e10cSrcweir if( rEvt.PropertyName == m_aPropertyNameForFetchSize
99cdf0e10cSrcweir || rEvt.PropertyName == m_aPropertyNameForFetchDirection )
100cdf0e10cSrcweir return;
101cdf0e10cSrcweir
102cdf0e10cSrcweir PropertyChangeEvent aEvt( rEvt );
103cdf0e10cSrcweir aEvt.Source = static_cast< XPropertySet * >( this );
104cdf0e10cSrcweir aEvt.Further = sal_False;
105cdf0e10cSrcweir
106cdf0e10cSrcweir impl_notifyPropertyChangeListeners( aEvt );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir
110cdf0e10cSrcweir //virtual
111cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_vetoableChange(const PropertyChangeEvent & rEvt)112cdf0e10cSrcweir ::impl_vetoableChange( const PropertyChangeEvent& rEvt )
113cdf0e10cSrcweir throw( PropertyVetoException,
114cdf0e10cSrcweir RuntimeException )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir impl_EnsureNotDisposed();
117cdf0e10cSrcweir
118cdf0e10cSrcweir //don't notify events on fetchsize and fetchdirection to the above CachedContentResultSet
119cdf0e10cSrcweir //because it will ignore them anyway and we can save this remote calls
120cdf0e10cSrcweir if( rEvt.PropertyName == m_aPropertyNameForFetchSize
121cdf0e10cSrcweir || rEvt.PropertyName == m_aPropertyNameForFetchDirection )
122cdf0e10cSrcweir return;
123cdf0e10cSrcweir
124cdf0e10cSrcweir PropertyChangeEvent aEvt( rEvt );
125cdf0e10cSrcweir aEvt.Source = static_cast< XPropertySet * >( this );
126cdf0e10cSrcweir aEvt.Further = sal_False;
127cdf0e10cSrcweir
128cdf0e10cSrcweir impl_notifyVetoableChangeListeners( aEvt );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //--------------------------------------------------------------------------
132cdf0e10cSrcweir // XTypeProvider methods.
133cdf0e10cSrcweir //--------------------------------------------------------------------------
134cdf0e10cSrcweir
XTYPEPROVIDER_COMMON_IMPL(CachedContentResultSetStub)135cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( CachedContentResultSetStub )
136cdf0e10cSrcweir //list all interfaces exclusive baseclasses
137cdf0e10cSrcweir Sequence< Type > SAL_CALL CachedContentResultSetStub
138cdf0e10cSrcweir ::getTypes()
139cdf0e10cSrcweir throw( RuntimeException )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir static Sequence< Type >* pTypes = NULL;
142cdf0e10cSrcweir if( !pTypes )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
145cdf0e10cSrcweir if( !pTypes )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir pTypes = new Sequence< Type >(13);
148cdf0e10cSrcweir (*pTypes)[0] = CPPU_TYPE_REF( XTypeProvider );
149cdf0e10cSrcweir (*pTypes)[1] = CPPU_TYPE_REF( XServiceInfo );
150cdf0e10cSrcweir (*pTypes)[2] = CPPU_TYPE_REF( XComponent );
151cdf0e10cSrcweir (*pTypes)[3] = CPPU_TYPE_REF( XCloseable );
152cdf0e10cSrcweir (*pTypes)[4] = CPPU_TYPE_REF( XResultSetMetaDataSupplier );
153cdf0e10cSrcweir (*pTypes)[5] = CPPU_TYPE_REF( XPropertySet );
154cdf0e10cSrcweir (*pTypes)[6] = CPPU_TYPE_REF( XPropertyChangeListener );
155cdf0e10cSrcweir (*pTypes)[7] = CPPU_TYPE_REF( XVetoableChangeListener );
156cdf0e10cSrcweir (*pTypes)[8] = CPPU_TYPE_REF( XResultSet );
157cdf0e10cSrcweir (*pTypes)[9] = CPPU_TYPE_REF( XContentAccess );
158cdf0e10cSrcweir (*pTypes)[10] = CPPU_TYPE_REF( XRow );
159cdf0e10cSrcweir (*pTypes)[11] = CPPU_TYPE_REF( XFetchProvider );
160cdf0e10cSrcweir (*pTypes)[12] = CPPU_TYPE_REF( XFetchProviderForContentAccess );
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir return *pTypes;
164cdf0e10cSrcweir /*
165cdf0e10cSrcweir static cppu::OTypeCollection * pCollection = 0;
166cdf0e10cSrcweir if (!pCollection)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir osl::MutexGuard aGuard(osl::Mutex::getGlobalMutex());
169cdf0e10cSrcweir if (!pCollection)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir static cppu::OTypeCollection
172cdf0e10cSrcweir aTheCollection(
173cdf0e10cSrcweir getCppuType(
174cdf0e10cSrcweir static_cast< Reference< XTypeProvider >
175cdf0e10cSrcweir const * >(
176cdf0e10cSrcweir 0)),
177cdf0e10cSrcweir getCppuType(
178cdf0e10cSrcweir static_cast< Reference< XServiceInfo >
179cdf0e10cSrcweir const * >(
180cdf0e10cSrcweir 0)),
181cdf0e10cSrcweir getCppuType(
182cdf0e10cSrcweir static_cast< Reference< XComponent >
183cdf0e10cSrcweir const * >(
184cdf0e10cSrcweir 0)),
185cdf0e10cSrcweir getCppuType(
186cdf0e10cSrcweir static_cast< Reference< XCloseable >
187cdf0e10cSrcweir const * >(
188cdf0e10cSrcweir 0)),
189cdf0e10cSrcweir getCppuType(
190cdf0e10cSrcweir static_cast< Reference< XResultSetMetaDataSupplier >
191cdf0e10cSrcweir const * >(
192cdf0e10cSrcweir 0)),
193cdf0e10cSrcweir getCppuType(
194cdf0e10cSrcweir static_cast< Reference< XPropertySet >
195cdf0e10cSrcweir const * >(
196cdf0e10cSrcweir 0)),
197cdf0e10cSrcweir getCppuType(
198cdf0e10cSrcweir static_cast< Reference< XPropertyChangeListener >
199cdf0e10cSrcweir const * >(
200cdf0e10cSrcweir 0)),
201cdf0e10cSrcweir getCppuType(
202cdf0e10cSrcweir static_cast< Reference< XVetoableChangeListener >
203cdf0e10cSrcweir const * >(
204cdf0e10cSrcweir 0)),
205cdf0e10cSrcweir getCppuType(
206cdf0e10cSrcweir static_cast< Reference< XResultSet >
207cdf0e10cSrcweir const * >(
208cdf0e10cSrcweir 0)),
209cdf0e10cSrcweir getCppuType(
210cdf0e10cSrcweir static_cast< Reference< XContentAccess >
211cdf0e10cSrcweir const * >(
212cdf0e10cSrcweir 0)),
213cdf0e10cSrcweir getCppuType(
214cdf0e10cSrcweir static_cast< Reference< XRow >
215cdf0e10cSrcweir const * >(
216cdf0e10cSrcweir 0)),
217cdf0e10cSrcweir getCppuType(
218cdf0e10cSrcweir static_cast< Reference< XFetchProvider >
219cdf0e10cSrcweir const * >(
220cdf0e10cSrcweir 0)),
221cdf0e10cSrcweir getCppuType(
222cdf0e10cSrcweir static_cast< Reference< XFetchProviderForContentAccess >
223cdf0e10cSrcweir const * >(
224cdf0e10cSrcweir 0))
225cdf0e10cSrcweir );
226cdf0e10cSrcweir pCollection = &aTheCollection;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir return pCollection->getTypes();
230cdf0e10cSrcweir */
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
233cdf0e10cSrcweir //--------------------------------------------------------------------------
234cdf0e10cSrcweir // XServiceInfo methods.
235cdf0e10cSrcweir //--------------------------------------------------------------------------
236cdf0e10cSrcweir
237cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( CachedContentResultSetStub,
238cdf0e10cSrcweir OUString::createFromAscii(
239cdf0e10cSrcweir "com.sun.star.comp.ucb.CachedContentResultSetStub" ),
240cdf0e10cSrcweir OUString::createFromAscii(
241cdf0e10cSrcweir CACHED_CRS_STUB_SERVICE_NAME ) );
242cdf0e10cSrcweir
243cdf0e10cSrcweir //-----------------------------------------------------------------
244cdf0e10cSrcweir // XFetchProvider methods.
245cdf0e10cSrcweir //-----------------------------------------------------------------
246cdf0e10cSrcweir
247cdf0e10cSrcweir #define FETCH_XXX( impl_loadRow, loadInterface ) \
248cdf0e10cSrcweir impl_EnsureNotDisposed(); \
249cdf0e10cSrcweir if( !m_xResultSetOrigin.is() ) \
250cdf0e10cSrcweir { \
251cdf0e10cSrcweir OSL_ENSURE( sal_False, "broadcaster was disposed already" ); \
252cdf0e10cSrcweir throw RuntimeException(); \
253cdf0e10cSrcweir } \
254cdf0e10cSrcweir impl_propagateFetchSizeAndDirection( nRowCount, bDirection ); \
255cdf0e10cSrcweir FetchResult aRet; \
256cdf0e10cSrcweir aRet.StartIndex = nRowStartPosition; \
257cdf0e10cSrcweir aRet.Orientation = bDirection; \
258cdf0e10cSrcweir aRet.FetchError = FetchError::SUCCESS; /*ENDOFDATA, EXCEPTION*/ \
259cdf0e10cSrcweir sal_Int32 nOldOriginal_Pos = m_xResultSetOrigin->getRow(); \
260cdf0e10cSrcweir if( impl_isForwardOnly() ) \
261cdf0e10cSrcweir { \
262cdf0e10cSrcweir if( nOldOriginal_Pos != nRowStartPosition ) \
263cdf0e10cSrcweir { \
264cdf0e10cSrcweir /*@todo*/ \
265cdf0e10cSrcweir aRet.FetchError = FetchError::EXCEPTION; \
266cdf0e10cSrcweir return aRet; \
267cdf0e10cSrcweir } \
268cdf0e10cSrcweir if( nRowCount != 1 ) \
269cdf0e10cSrcweir aRet.FetchError = FetchError::EXCEPTION; \
270cdf0e10cSrcweir \
271cdf0e10cSrcweir aRet.Rows.realloc( 1 ); \
272cdf0e10cSrcweir \
273cdf0e10cSrcweir try \
274cdf0e10cSrcweir { \
275cdf0e10cSrcweir impl_loadRow( aRet.Rows[0], loadInterface ); \
276cdf0e10cSrcweir } \
277cdf0e10cSrcweir catch( SQLException& ) \
278cdf0e10cSrcweir { \
279cdf0e10cSrcweir aRet.Rows.realloc( 0 ); \
280cdf0e10cSrcweir aRet.FetchError = FetchError::EXCEPTION; \
281cdf0e10cSrcweir return aRet; \
282cdf0e10cSrcweir } \
283cdf0e10cSrcweir return aRet; \
284cdf0e10cSrcweir } \
285cdf0e10cSrcweir aRet.Rows.realloc( nRowCount ); \
286cdf0e10cSrcweir sal_Bool bOldOriginal_AfterLast = sal_False; \
287cdf0e10cSrcweir if( !nOldOriginal_Pos ) \
288cdf0e10cSrcweir bOldOriginal_AfterLast = m_xResultSetOrigin->isAfterLast(); \
289cdf0e10cSrcweir sal_Int32 nN = 1; \
290cdf0e10cSrcweir sal_Bool bValidNewPos = sal_False; \
291cdf0e10cSrcweir try \
292cdf0e10cSrcweir { \
293cdf0e10cSrcweir try \
294cdf0e10cSrcweir { \
295cdf0e10cSrcweir /*if( nOldOriginal_Pos != nRowStartPosition )*/ \
296cdf0e10cSrcweir bValidNewPos = m_xResultSetOrigin->absolute( nRowStartPosition ); \
297cdf0e10cSrcweir } \
298cdf0e10cSrcweir catch( SQLException& ) \
299cdf0e10cSrcweir { \
300cdf0e10cSrcweir aRet.Rows.realloc( 0 ); \
301cdf0e10cSrcweir aRet.FetchError = FetchError::EXCEPTION; \
302cdf0e10cSrcweir return aRet; \
303cdf0e10cSrcweir } \
304cdf0e10cSrcweir if( !bValidNewPos ) \
305cdf0e10cSrcweir { \
306cdf0e10cSrcweir aRet.Rows.realloc( 0 ); \
307cdf0e10cSrcweir aRet.FetchError = FetchError::EXCEPTION; \
308cdf0e10cSrcweir \
309cdf0e10cSrcweir /*restore old position*/ \
310cdf0e10cSrcweir if( nOldOriginal_Pos ) \
311cdf0e10cSrcweir m_xResultSetOrigin->absolute( nOldOriginal_Pos ); \
312cdf0e10cSrcweir else if( bOldOriginal_AfterLast ) \
313cdf0e10cSrcweir m_xResultSetOrigin->afterLast(); \
314cdf0e10cSrcweir else \
315cdf0e10cSrcweir m_xResultSetOrigin->beforeFirst(); \
316cdf0e10cSrcweir \
317cdf0e10cSrcweir return aRet; \
318cdf0e10cSrcweir } \
319cdf0e10cSrcweir for( ; nN <= nRowCount; ) \
320cdf0e10cSrcweir { \
321cdf0e10cSrcweir impl_loadRow( aRet.Rows[nN-1], loadInterface ); \
322cdf0e10cSrcweir nN++; \
323cdf0e10cSrcweir if( nN <= nRowCount ) \
324cdf0e10cSrcweir { \
325cdf0e10cSrcweir if( bDirection ) \
326cdf0e10cSrcweir { \
327cdf0e10cSrcweir if( !m_xResultSetOrigin->next() ) \
328cdf0e10cSrcweir { \
329cdf0e10cSrcweir aRet.Rows.realloc( nN-1 ); \
330cdf0e10cSrcweir aRet.FetchError = FetchError::ENDOFDATA; \
331cdf0e10cSrcweir break; \
332cdf0e10cSrcweir } \
333cdf0e10cSrcweir } \
334cdf0e10cSrcweir else \
335cdf0e10cSrcweir { \
336cdf0e10cSrcweir if( !m_xResultSetOrigin->previous() ) \
337cdf0e10cSrcweir { \
338cdf0e10cSrcweir aRet.Rows.realloc( nN-1 ); \
339cdf0e10cSrcweir aRet.FetchError = FetchError::ENDOFDATA; \
340cdf0e10cSrcweir break; \
341cdf0e10cSrcweir } \
342cdf0e10cSrcweir } \
343cdf0e10cSrcweir } \
344cdf0e10cSrcweir } \
345cdf0e10cSrcweir } \
346cdf0e10cSrcweir catch( SQLException& ) \
347cdf0e10cSrcweir { \
348cdf0e10cSrcweir aRet.Rows.realloc( nN-1 ); \
349cdf0e10cSrcweir aRet.FetchError = FetchError::EXCEPTION; \
350cdf0e10cSrcweir } \
351cdf0e10cSrcweir /*restore old position*/ \
352cdf0e10cSrcweir if( nOldOriginal_Pos ) \
353cdf0e10cSrcweir m_xResultSetOrigin->absolute( nOldOriginal_Pos ); \
354cdf0e10cSrcweir else if( bOldOriginal_AfterLast ) \
355cdf0e10cSrcweir m_xResultSetOrigin->afterLast(); \
356cdf0e10cSrcweir else \
357cdf0e10cSrcweir m_xResultSetOrigin->beforeFirst(); \
358cdf0e10cSrcweir return aRet;
359cdf0e10cSrcweir
360cdf0e10cSrcweir FetchResult SAL_CALL CachedContentResultSetStub
fetch(sal_Int32 nRowStartPosition,sal_Int32 nRowCount,sal_Bool bDirection)361cdf0e10cSrcweir ::fetch( sal_Int32 nRowStartPosition
362cdf0e10cSrcweir , sal_Int32 nRowCount, sal_Bool bDirection )
363cdf0e10cSrcweir throw( RuntimeException )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir impl_init_xRowOrigin();
366cdf0e10cSrcweir FETCH_XXX( impl_getCurrentRowContent, m_xRowOrigin );
367cdf0e10cSrcweir }
368cdf0e10cSrcweir
369cdf0e10cSrcweir sal_Int32 SAL_CALL CachedContentResultSetStub
impl_getColumnCount()370cdf0e10cSrcweir ::impl_getColumnCount()
371cdf0e10cSrcweir {
372cdf0e10cSrcweir sal_Int32 nCount;
373cdf0e10cSrcweir sal_Bool bCached;
374cdf0e10cSrcweir {
375cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
376cdf0e10cSrcweir nCount = m_nColumnCount;
377cdf0e10cSrcweir bCached = m_bColumnCountCached;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir if( !bCached )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir try
382cdf0e10cSrcweir {
383cdf0e10cSrcweir Reference< XResultSetMetaData > xMetaData = getMetaData();
384cdf0e10cSrcweir if( xMetaData.is() )
385cdf0e10cSrcweir nCount = xMetaData->getColumnCount();
386cdf0e10cSrcweir }
387cdf0e10cSrcweir catch( SQLException& )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir OSL_ENSURE( sal_False, "couldn't determine the column count" );
390cdf0e10cSrcweir nCount = 0;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir }
393cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
394cdf0e10cSrcweir m_nColumnCount = nCount;
395cdf0e10cSrcweir m_bColumnCountCached = sal_True;
396cdf0e10cSrcweir return m_nColumnCount;
397cdf0e10cSrcweir }
398cdf0e10cSrcweir
399cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_getCurrentRowContent(Any & rRowContent,Reference<XRow> xRow)400cdf0e10cSrcweir ::impl_getCurrentRowContent( Any& rRowContent
401cdf0e10cSrcweir , Reference< XRow > xRow )
402cdf0e10cSrcweir throw ( SQLException, RuntimeException )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir sal_Int32 nCount = impl_getColumnCount();
405cdf0e10cSrcweir
406cdf0e10cSrcweir Sequence< Any > aContent( nCount );
407cdf0e10cSrcweir for( sal_Int32 nN = 1; nN <= nCount; nN++ )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir aContent[nN-1] = xRow->getObject( nN, NULL );
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
412cdf0e10cSrcweir rRowContent <<= aContent;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
415cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_propagateFetchSizeAndDirection(sal_Int32 nFetchSize,sal_Bool bFetchDirection)416cdf0e10cSrcweir ::impl_propagateFetchSizeAndDirection( sal_Int32 nFetchSize, sal_Bool bFetchDirection )
417cdf0e10cSrcweir throw ( RuntimeException )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir //this is done only for the case, that there is another CachedContentResultSet in the chain of underlying ResulSets
420cdf0e10cSrcweir
421cdf0e10cSrcweir //we do not propagate the property 'FetchSize' or 'FetchDirection' via 'setPropertyValue' from the above CachedContentResultSet to save remote calls
422cdf0e10cSrcweir
423cdf0e10cSrcweir //if the underlying ResultSet has a property FetchSize and FetchDirection,
424cdf0e10cSrcweir //we will set these properties, if the new given parameters are different from the last ones
425cdf0e10cSrcweir
426cdf0e10cSrcweir if( !m_bNeedToPropagateFetchSize )
427cdf0e10cSrcweir return;
428cdf0e10cSrcweir
429cdf0e10cSrcweir sal_Bool bNeedAction;
430cdf0e10cSrcweir sal_Int32 nLastSize;
431cdf0e10cSrcweir sal_Bool bLastDirection;
432cdf0e10cSrcweir sal_Bool bFirstPropagationDone;
433cdf0e10cSrcweir {
434cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
435cdf0e10cSrcweir bNeedAction = m_bNeedToPropagateFetchSize;
436cdf0e10cSrcweir nLastSize = m_nLastFetchSize;
437cdf0e10cSrcweir bLastDirection = m_bLastFetchDirection;
438cdf0e10cSrcweir bFirstPropagationDone = m_bFirstFetchSizePropagationDone;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir if( bNeedAction )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir if( nLastSize == nFetchSize
443cdf0e10cSrcweir && bLastDirection == bFetchDirection
444cdf0e10cSrcweir && bFirstPropagationDone == sal_True )
445cdf0e10cSrcweir return;
446cdf0e10cSrcweir
447cdf0e10cSrcweir if(!bFirstPropagationDone)
448cdf0e10cSrcweir {
449*940681c7SMatthias Seidel //check whether the properties 'FetchSize' and 'FetchDirection' do exist
450cdf0e10cSrcweir
451cdf0e10cSrcweir Reference< XPropertySetInfo > xPropertySetInfo = getPropertySetInfo();
452cdf0e10cSrcweir sal_Bool bHasSize = xPropertySetInfo->hasPropertyByName( m_aPropertyNameForFetchSize );
453cdf0e10cSrcweir sal_Bool bHasDirection = xPropertySetInfo->hasPropertyByName( m_aPropertyNameForFetchDirection );
454cdf0e10cSrcweir
455cdf0e10cSrcweir if(!bHasSize || !bHasDirection)
456cdf0e10cSrcweir {
457cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
458cdf0e10cSrcweir m_bNeedToPropagateFetchSize = sal_False;
459cdf0e10cSrcweir return;
460cdf0e10cSrcweir }
461cdf0e10cSrcweir }
462cdf0e10cSrcweir
463cdf0e10cSrcweir sal_Bool bSetSize = ( nLastSize !=nFetchSize ) || !bFirstPropagationDone;
464cdf0e10cSrcweir sal_Bool bSetDirection = ( bLastDirection !=bFetchDirection ) || !bFirstPropagationDone;
465cdf0e10cSrcweir
466cdf0e10cSrcweir {
467cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
468cdf0e10cSrcweir m_bFirstFetchSizePropagationDone = sal_True;
469cdf0e10cSrcweir m_nLastFetchSize = nFetchSize;
470cdf0e10cSrcweir m_bLastFetchDirection = bFetchDirection;
471cdf0e10cSrcweir }
472cdf0e10cSrcweir
473cdf0e10cSrcweir if( bSetSize )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir Any aValue;
476cdf0e10cSrcweir aValue <<= nFetchSize;
477cdf0e10cSrcweir try
478cdf0e10cSrcweir {
479cdf0e10cSrcweir setPropertyValue( m_aPropertyNameForFetchSize, aValue );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir catch( com::sun::star::uno::Exception& ) {}
482cdf0e10cSrcweir }
483cdf0e10cSrcweir if( bSetDirection )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir sal_Int32 nFetchDirection = FetchDirection::FORWARD;
486cdf0e10cSrcweir if( !bFetchDirection )
487cdf0e10cSrcweir nFetchDirection = FetchDirection::REVERSE;
488cdf0e10cSrcweir Any aValue;
489cdf0e10cSrcweir aValue <<= nFetchDirection;
490cdf0e10cSrcweir try
491cdf0e10cSrcweir {
492cdf0e10cSrcweir setPropertyValue( m_aPropertyNameForFetchDirection, aValue );
493cdf0e10cSrcweir }
494cdf0e10cSrcweir catch( com::sun::star::uno::Exception& ) {}
495cdf0e10cSrcweir }
496cdf0e10cSrcweir
497cdf0e10cSrcweir }
498cdf0e10cSrcweir }
499cdf0e10cSrcweir
500cdf0e10cSrcweir //-----------------------------------------------------------------
501cdf0e10cSrcweir // XFetchProviderForContentAccess methods.
502cdf0e10cSrcweir //-----------------------------------------------------------------
503cdf0e10cSrcweir
504cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_getCurrentContentIdentifierString(Any & rAny,Reference<XContentAccess> xContentAccess)505cdf0e10cSrcweir ::impl_getCurrentContentIdentifierString( Any& rAny
506cdf0e10cSrcweir , Reference< XContentAccess > xContentAccess )
507cdf0e10cSrcweir throw ( RuntimeException )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir rAny <<= xContentAccess->queryContentIdentifierString();
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_getCurrentContentIdentifier(Any & rAny,Reference<XContentAccess> xContentAccess)513cdf0e10cSrcweir ::impl_getCurrentContentIdentifier( Any& rAny
514cdf0e10cSrcweir , Reference< XContentAccess > xContentAccess )
515cdf0e10cSrcweir throw ( RuntimeException )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir rAny <<= xContentAccess->queryContentIdentifier();
518cdf0e10cSrcweir }
519cdf0e10cSrcweir
520cdf0e10cSrcweir void SAL_CALL CachedContentResultSetStub
impl_getCurrentContent(Any & rAny,Reference<XContentAccess> xContentAccess)521cdf0e10cSrcweir ::impl_getCurrentContent( Any& rAny
522cdf0e10cSrcweir , Reference< XContentAccess > xContentAccess )
523cdf0e10cSrcweir throw ( RuntimeException )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir rAny <<= xContentAccess->queryContent();
526cdf0e10cSrcweir }
527cdf0e10cSrcweir
528cdf0e10cSrcweir //virtual
529cdf0e10cSrcweir FetchResult SAL_CALL CachedContentResultSetStub
fetchContentIdentifierStrings(sal_Int32 nRowStartPosition,sal_Int32 nRowCount,sal_Bool bDirection)530cdf0e10cSrcweir ::fetchContentIdentifierStrings( sal_Int32 nRowStartPosition
531cdf0e10cSrcweir , sal_Int32 nRowCount, sal_Bool bDirection )
532cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir impl_init_xContentAccessOrigin();
535cdf0e10cSrcweir FETCH_XXX( impl_getCurrentContentIdentifierString, m_xContentAccessOrigin );
536cdf0e10cSrcweir }
537cdf0e10cSrcweir
538cdf0e10cSrcweir //virtual
539cdf0e10cSrcweir FetchResult SAL_CALL CachedContentResultSetStub
fetchContentIdentifiers(sal_Int32 nRowStartPosition,sal_Int32 nRowCount,sal_Bool bDirection)540cdf0e10cSrcweir ::fetchContentIdentifiers( sal_Int32 nRowStartPosition
541cdf0e10cSrcweir , sal_Int32 nRowCount, sal_Bool bDirection )
542cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException )
543cdf0e10cSrcweir {
544cdf0e10cSrcweir impl_init_xContentAccessOrigin();
545cdf0e10cSrcweir FETCH_XXX( impl_getCurrentContentIdentifier, m_xContentAccessOrigin );
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
548cdf0e10cSrcweir //virtual
549cdf0e10cSrcweir FetchResult SAL_CALL CachedContentResultSetStub
fetchContents(sal_Int32 nRowStartPosition,sal_Int32 nRowCount,sal_Bool bDirection)550cdf0e10cSrcweir ::fetchContents( sal_Int32 nRowStartPosition
551cdf0e10cSrcweir , sal_Int32 nRowCount, sal_Bool bDirection )
552cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir impl_init_xContentAccessOrigin();
555cdf0e10cSrcweir FETCH_XXX( impl_getCurrentContent, m_xContentAccessOrigin );
556cdf0e10cSrcweir }
557cdf0e10cSrcweir
558cdf0e10cSrcweir //--------------------------------------------------------------------------
559cdf0e10cSrcweir //--------------------------------------------------------------------------
560cdf0e10cSrcweir // class CachedContentResultSetStubFactory
561cdf0e10cSrcweir //--------------------------------------------------------------------------
562cdf0e10cSrcweir //--------------------------------------------------------------------------
563cdf0e10cSrcweir
CachedContentResultSetStubFactory(const Reference<XMultiServiceFactory> & rSMgr)564cdf0e10cSrcweir CachedContentResultSetStubFactory::CachedContentResultSetStubFactory(
565cdf0e10cSrcweir const Reference< XMultiServiceFactory > & rSMgr )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir m_xSMgr = rSMgr;
568cdf0e10cSrcweir }
569cdf0e10cSrcweir
~CachedContentResultSetStubFactory()570cdf0e10cSrcweir CachedContentResultSetStubFactory::~CachedContentResultSetStubFactory()
571cdf0e10cSrcweir {
572cdf0e10cSrcweir }
573cdf0e10cSrcweir
574cdf0e10cSrcweir //--------------------------------------------------------------------------
575cdf0e10cSrcweir // CachedContentResultSetStubFactory XInterface methods.
576cdf0e10cSrcweir //--------------------------------------------------------------------------
577cdf0e10cSrcweir
578cdf0e10cSrcweir XINTERFACE_IMPL_3( CachedContentResultSetStubFactory,
579cdf0e10cSrcweir XTypeProvider,
580cdf0e10cSrcweir XServiceInfo,
581cdf0e10cSrcweir XCachedContentResultSetStubFactory );
582cdf0e10cSrcweir
583cdf0e10cSrcweir //--------------------------------------------------------------------------
584cdf0e10cSrcweir // CachedContentResultSetStubFactory XTypeProvider methods.
585cdf0e10cSrcweir //--------------------------------------------------------------------------
586cdf0e10cSrcweir
587cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( CachedContentResultSetStubFactory,
588cdf0e10cSrcweir XTypeProvider,
589cdf0e10cSrcweir XServiceInfo,
590cdf0e10cSrcweir XCachedContentResultSetStubFactory );
591cdf0e10cSrcweir
592cdf0e10cSrcweir //--------------------------------------------------------------------------
593cdf0e10cSrcweir // CachedContentResultSetStubFactory XServiceInfo methods.
594cdf0e10cSrcweir //--------------------------------------------------------------------------
595cdf0e10cSrcweir
596cdf0e10cSrcweir XSERVICEINFO_IMPL_1( CachedContentResultSetStubFactory,
597cdf0e10cSrcweir OUString::createFromAscii(
598cdf0e10cSrcweir "com.sun.star.comp.ucb.CachedContentResultSetStubFactory" ),
599cdf0e10cSrcweir OUString::createFromAscii(
600cdf0e10cSrcweir CACHED_CRS_STUB_FACTORY_NAME ) );
601cdf0e10cSrcweir
602cdf0e10cSrcweir //--------------------------------------------------------------------------
603cdf0e10cSrcweir // Service factory implementation.
604cdf0e10cSrcweir //--------------------------------------------------------------------------
605cdf0e10cSrcweir
606cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedContentResultSetStubFactory );
607cdf0e10cSrcweir
608cdf0e10cSrcweir //--------------------------------------------------------------------------
609cdf0e10cSrcweir // CachedContentResultSetStubFactory XCachedContentResultSetStubFactory methods.
610cdf0e10cSrcweir //--------------------------------------------------------------------------
611cdf0e10cSrcweir
612cdf0e10cSrcweir //virtual
613cdf0e10cSrcweir Reference< XResultSet > SAL_CALL CachedContentResultSetStubFactory
createCachedContentResultSetStub(const Reference<XResultSet> & xSource)614cdf0e10cSrcweir ::createCachedContentResultSetStub(
615cdf0e10cSrcweir const Reference< XResultSet > & xSource )
616cdf0e10cSrcweir throw( RuntimeException )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir if( xSource.is() )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir Reference< XResultSet > xRet;
621cdf0e10cSrcweir xRet = new CachedContentResultSetStub( xSource );
622cdf0e10cSrcweir return xRet;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir return NULL;
625cdf0e10cSrcweir }
626cdf0e10cSrcweir
627cdf0e10cSrcweir
628