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