xref: /trunk/main/ucb/source/cacher/cachedcontentresultset.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
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
10cdf0e10cSrcweir  *
112f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 <cachedcontentresultset.hxx>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ucb/FetchError.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ucb/ResultSetException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
32cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
34cdf0e10cSrcweir #include <rtl/ustring.hxx>
35cdf0e10cSrcweir #include <osl/diagnose.h>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star::beans;
38cdf0e10cSrcweir using namespace com::sun::star::lang;
39cdf0e10cSrcweir using namespace com::sun::star::script;
40cdf0e10cSrcweir using namespace com::sun::star::sdbc;
41cdf0e10cSrcweir using namespace com::sun::star::ucb;
42cdf0e10cSrcweir using namespace com::sun::star::uno;
43cdf0e10cSrcweir using namespace com::sun::star::util;
44cdf0e10cSrcweir using namespace cppu;
45cdf0e10cSrcweir using namespace rtl;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE 256
48cdf0e10cSrcweir #define COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION FetchDirection::FORWARD
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //--------------------------------------------------------------------------
51cdf0e10cSrcweir //--------------------------------------------------------------------------
52cdf0e10cSrcweir //define for getXXX methods of interface XRow
53cdf0e10cSrcweir //--------------------------------------------------------------------------
54cdf0e10cSrcweir //--------------------------------------------------------------------------
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //if you change this macro please pay attention to
57cdf0e10cSrcweir //function ::getObject, where this is similar implemented
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define XROW_GETXXX( getXXX, Type )                     \
60cdf0e10cSrcweir impl_EnsureNotDisposed();                               \
61cdf0e10cSrcweir ReacquireableGuard aGuard( m_aMutex );                  \
62cdf0e10cSrcweir sal_Int32 nRow = m_nRow;                                \
63cdf0e10cSrcweir sal_Int32 nFetchSize = m_nFetchSize;                    \
64cdf0e10cSrcweir sal_Int32 nFetchDirection = m_nFetchDirection;          \
65cdf0e10cSrcweir if( !m_aCache.hasRow( nRow ) )                          \
66cdf0e10cSrcweir {                                                       \
67cdf0e10cSrcweir     if( !m_aCache.hasCausedException( nRow ) )          \
68cdf0e10cSrcweir {                                                       \
69cdf0e10cSrcweir         if( !m_xFetchProvider.is() )                    \
70cdf0e10cSrcweir         {                                               \
71cdf0e10cSrcweir             OSL_ENSURE( sal_False, "broadcaster was disposed already" );    \
72cdf0e10cSrcweir             throw SQLException();                       \
73cdf0e10cSrcweir         }                                               \
74cdf0e10cSrcweir         aGuard.clear();                                 \
75cdf0e10cSrcweir         if( impl_isForwardOnly() )                      \
76cdf0e10cSrcweir             applyPositionToOrigin( nRow );              \
77cdf0e10cSrcweir                                                         \
78cdf0e10cSrcweir         impl_fetchData( nRow, nFetchSize, nFetchDirection ); \
79cdf0e10cSrcweir     }                                                   \
80cdf0e10cSrcweir     aGuard.reacquire();                                 \
81cdf0e10cSrcweir     if( !m_aCache.hasRow( nRow ) )                      \
82cdf0e10cSrcweir     {                                                   \
83cdf0e10cSrcweir         m_bLastReadWasFromCache = sal_False;            \
84cdf0e10cSrcweir         aGuard.clear();                                 \
85cdf0e10cSrcweir         applyPositionToOrigin( nRow );                  \
86cdf0e10cSrcweir         impl_init_xRowOrigin();                         \
87cdf0e10cSrcweir         return m_xRowOrigin->getXXX( columnIndex );     \
88cdf0e10cSrcweir     }                                                   \
89cdf0e10cSrcweir }                                                       \
90cdf0e10cSrcweir const Any& rValue = m_aCache.getAny( nRow, columnIndex );\
91cdf0e10cSrcweir Type aRet = Type();                                     \
92cdf0e10cSrcweir m_bLastReadWasFromCache = sal_True;                     \
93cdf0e10cSrcweir m_bLastCachedReadWasNull = !( rValue >>= aRet );        \
94cdf0e10cSrcweir /* Last chance. Try type converter service... */        \
95cdf0e10cSrcweir if ( m_bLastCachedReadWasNull && rValue.hasValue() )    \
96cdf0e10cSrcweir {                                                       \
97cdf0e10cSrcweir     Reference< XTypeConverter > xConverter              \
98cdf0e10cSrcweir                                 = getTypeConverter();   \
99cdf0e10cSrcweir     if ( xConverter.is() )                              \
100cdf0e10cSrcweir     {                                                   \
101cdf0e10cSrcweir         try                                             \
102cdf0e10cSrcweir         {                                               \
103cdf0e10cSrcweir             Any aConvAny = xConverter->convertTo(       \
104cdf0e10cSrcweir                 rValue,                                 \
105cdf0e10cSrcweir                 getCppuType( static_cast<               \
106cdf0e10cSrcweir                     const Type * >( 0 ) ) );            \
107cdf0e10cSrcweir             m_bLastCachedReadWasNull = !( aConvAny >>= aRet ); \
108cdf0e10cSrcweir         }                                               \
109cdf0e10cSrcweir         catch ( IllegalArgumentException )              \
110cdf0e10cSrcweir         {                                               \
111cdf0e10cSrcweir         }                                               \
112cdf0e10cSrcweir         catch ( CannotConvertException )                \
113cdf0e10cSrcweir         {                                               \
114cdf0e10cSrcweir         }                                               \
115cdf0e10cSrcweir     }                                                   \
116cdf0e10cSrcweir }                                                       \
117cdf0e10cSrcweir return aRet;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir //--------------------------------------------------------------------------
120cdf0e10cSrcweir //--------------------------------------------------------------------------
121cdf0e10cSrcweir // CCRS_Cache methoeds.
122cdf0e10cSrcweir //--------------------------------------------------------------------------
123cdf0e10cSrcweir //--------------------------------------------------------------------------
124cdf0e10cSrcweir 
CCRS_Cache(const Reference<XContentIdentifierMapping> & xMapping)125cdf0e10cSrcweir CachedContentResultSet::CCRS_Cache::CCRS_Cache(
126cdf0e10cSrcweir     const Reference< XContentIdentifierMapping > & xMapping )
127cdf0e10cSrcweir     : m_pResult( NULL )
128cdf0e10cSrcweir     , m_xContentIdentifierMapping( xMapping )
129cdf0e10cSrcweir     , m_pMappedReminder( NULL )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
~CCRS_Cache()133cdf0e10cSrcweir CachedContentResultSet::CCRS_Cache::~CCRS_Cache()
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     delete m_pResult;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir void SAL_CALL CachedContentResultSet::CCRS_Cache
clear()139cdf0e10cSrcweir     ::clear()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     if( m_pResult )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         delete m_pResult;
144cdf0e10cSrcweir         m_pResult = NULL;
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir     clearMappedReminder();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir void SAL_CALL CachedContentResultSet::CCRS_Cache
loadData(const FetchResult & rResult)150cdf0e10cSrcweir     ::loadData( const FetchResult& rResult )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     clear();
153cdf0e10cSrcweir     m_pResult = new FetchResult( rResult );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache
hasRow(sal_Int32 row)157cdf0e10cSrcweir     ::hasRow( sal_Int32 row )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     if( !m_pResult )
160cdf0e10cSrcweir         return sal_False;
161cdf0e10cSrcweir     long nStart = m_pResult->StartIndex;
162cdf0e10cSrcweir     long nEnd = nStart;
163cdf0e10cSrcweir     if( m_pResult->Orientation )
164cdf0e10cSrcweir         nEnd += m_pResult->Rows.getLength() - 1;
165cdf0e10cSrcweir     else
166cdf0e10cSrcweir         nStart -= m_pResult->Rows.getLength() + 1;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     return nStart <= row && row <= nEnd;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir sal_Int32 SAL_CALL CachedContentResultSet::CCRS_Cache
getMaxRow()172cdf0e10cSrcweir     ::getMaxRow()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     if( !m_pResult )
175cdf0e10cSrcweir         return 0;
176cdf0e10cSrcweir     long nEnd = m_pResult->StartIndex;
177cdf0e10cSrcweir     if( m_pResult->Orientation )
178cdf0e10cSrcweir         return nEnd += m_pResult->Rows.getLength() - 1;
179cdf0e10cSrcweir     else
180cdf0e10cSrcweir         return nEnd;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache
hasKnownLast()184cdf0e10cSrcweir     ::hasKnownLast()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     if( !m_pResult )
187cdf0e10cSrcweir         return sal_False;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     if( ( m_pResult->FetchError & FetchError::ENDOFDATA )
190cdf0e10cSrcweir         && m_pResult->Orientation
191cdf0e10cSrcweir         && m_pResult->Rows.getLength() )
192cdf0e10cSrcweir         return sal_True;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     return sal_False;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache
hasCausedException(sal_Int32 nRow)198cdf0e10cSrcweir     ::hasCausedException( sal_Int32 nRow )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     if( !m_pResult )
201cdf0e10cSrcweir         return sal_False;
202cdf0e10cSrcweir     if( !( m_pResult->FetchError & FetchError::EXCEPTION ) )
203cdf0e10cSrcweir         return sal_False;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     long nEnd = m_pResult->StartIndex;
206cdf0e10cSrcweir     if( m_pResult->Orientation )
207cdf0e10cSrcweir         nEnd += m_pResult->Rows.getLength();
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     return nRow == nEnd+1;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir Any& SAL_CALL CachedContentResultSet::CCRS_Cache
getRowAny(sal_Int32 nRow)213cdf0e10cSrcweir     ::getRowAny( sal_Int32 nRow )
214cdf0e10cSrcweir     throw( SQLException,
215cdf0e10cSrcweir     RuntimeException )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir     if( !nRow )
218cdf0e10cSrcweir         throw SQLException();
219cdf0e10cSrcweir     if( !m_pResult )
220cdf0e10cSrcweir         throw SQLException();
221cdf0e10cSrcweir     if( !hasRow( nRow ) )
222cdf0e10cSrcweir         throw SQLException();
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     long nDiff = nRow - m_pResult->StartIndex;
225cdf0e10cSrcweir     if( nDiff < 0 )
226cdf0e10cSrcweir         nDiff *= -1;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     return (m_pResult->Rows)[nDiff];
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir void SAL_CALL CachedContentResultSet::CCRS_Cache
remindMapped(sal_Int32 nRow)232cdf0e10cSrcweir     ::remindMapped( sal_Int32 nRow )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     //remind that this row was mapped
235cdf0e10cSrcweir     if( !m_pResult )
236cdf0e10cSrcweir         return;
237cdf0e10cSrcweir     long nDiff = nRow - m_pResult->StartIndex;
238cdf0e10cSrcweir     if( nDiff < 0 )
239cdf0e10cSrcweir         nDiff *= -1;
240cdf0e10cSrcweir     Sequence< sal_Bool >* pMappedReminder = getMappedReminder();
241cdf0e10cSrcweir     if( nDiff < pMappedReminder->getLength() )
242cdf0e10cSrcweir         (*pMappedReminder)[nDiff] = sal_True;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache
isRowMapped(sal_Int32 nRow)246cdf0e10cSrcweir     ::isRowMapped( sal_Int32 nRow )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     if( !m_pMappedReminder || !m_pResult )
249cdf0e10cSrcweir         return sal_False;
250cdf0e10cSrcweir     long nDiff = nRow - m_pResult->StartIndex;
251cdf0e10cSrcweir     if( nDiff < 0 )
252cdf0e10cSrcweir         nDiff *= -1;
253cdf0e10cSrcweir     if( nDiff < m_pMappedReminder->getLength() )
254cdf0e10cSrcweir         return (*m_pMappedReminder)[nDiff];
255cdf0e10cSrcweir     return sal_False;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir void SAL_CALL CachedContentResultSet::CCRS_Cache
clearMappedReminder()259cdf0e10cSrcweir     ::clearMappedReminder()
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     delete m_pMappedReminder;
262cdf0e10cSrcweir     m_pMappedReminder = NULL;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir Sequence< sal_Bool >* SAL_CALL CachedContentResultSet::CCRS_Cache
getMappedReminder()266cdf0e10cSrcweir     ::getMappedReminder()
267cdf0e10cSrcweir {
268cdf0e10cSrcweir     if( !m_pMappedReminder )
269cdf0e10cSrcweir     {
270cdf0e10cSrcweir         sal_Int32 nCount = m_pResult->Rows.getLength();
271cdf0e10cSrcweir         m_pMappedReminder = new Sequence< sal_Bool >( nCount );
272cdf0e10cSrcweir         for( ;nCount; nCount-- )
273cdf0e10cSrcweir             (*m_pMappedReminder)[nCount] = sal_False;
274cdf0e10cSrcweir     }
275cdf0e10cSrcweir     return m_pMappedReminder;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir const Any& SAL_CALL CachedContentResultSet::CCRS_Cache
getAny(sal_Int32 nRow,sal_Int32 nColumnIndex)279cdf0e10cSrcweir     ::getAny( sal_Int32 nRow, sal_Int32 nColumnIndex )
280cdf0e10cSrcweir     throw( SQLException,
281cdf0e10cSrcweir     RuntimeException )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     if( !nColumnIndex )
284cdf0e10cSrcweir         throw SQLException();
285cdf0e10cSrcweir     if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) )
286cdf0e10cSrcweir     {
287cdf0e10cSrcweir         Any& rRow = getRowAny( nRow );
288cdf0e10cSrcweir         Sequence< Any > aValue;
289cdf0e10cSrcweir         rRow >>= aValue;
290cdf0e10cSrcweir         if( m_xContentIdentifierMapping->mapRow( aValue ) )
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             rRow <<= aValue;
293cdf0e10cSrcweir             remindMapped( nRow );
294cdf0e10cSrcweir         }
295cdf0e10cSrcweir         else
296cdf0e10cSrcweir             m_xContentIdentifierMapping.clear();
297cdf0e10cSrcweir     }
298cdf0e10cSrcweir     const Sequence< Any >& rRow =
299cdf0e10cSrcweir         (* reinterpret_cast< const Sequence< Any > * >
300cdf0e10cSrcweir         (getRowAny( nRow ).getValue() ));
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     if( nColumnIndex > rRow.getLength() )
303cdf0e10cSrcweir         throw SQLException();
304cdf0e10cSrcweir     return rRow[nColumnIndex-1];
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir const rtl::OUString& SAL_CALL CachedContentResultSet::CCRS_Cache
getContentIdentifierString(sal_Int32 nRow)308cdf0e10cSrcweir     ::getContentIdentifierString( sal_Int32 nRow )
309cdf0e10cSrcweir     throw( com::sun::star::uno::RuntimeException )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     try
312cdf0e10cSrcweir     {
313cdf0e10cSrcweir         if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) )
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             Any& rRow = getRowAny( nRow );
316cdf0e10cSrcweir             rtl::OUString aValue;
317cdf0e10cSrcweir             rRow >>= aValue;
318cdf0e10cSrcweir             rRow <<= m_xContentIdentifierMapping->mapContentIdentifierString( aValue );
319cdf0e10cSrcweir             remindMapped( nRow );
320cdf0e10cSrcweir         }
321cdf0e10cSrcweir         return (* reinterpret_cast< const rtl::OUString * >
322cdf0e10cSrcweir                 (getRowAny( nRow ).getValue() ));
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir     catch( SQLException )
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir         throw RuntimeException();
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir const Reference< XContentIdentifier >& SAL_CALL CachedContentResultSet::CCRS_Cache
getContentIdentifier(sal_Int32 nRow)331cdf0e10cSrcweir     ::getContentIdentifier( sal_Int32 nRow )
332cdf0e10cSrcweir     throw( com::sun::star::uno::RuntimeException )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     try
335cdf0e10cSrcweir     {
336cdf0e10cSrcweir         if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) )
337cdf0e10cSrcweir         {
338cdf0e10cSrcweir             Any& rRow = getRowAny( nRow );
339cdf0e10cSrcweir             Reference< XContentIdentifier > aValue;
340cdf0e10cSrcweir             rRow >>= aValue;
341cdf0e10cSrcweir             rRow <<= m_xContentIdentifierMapping->mapContentIdentifier( aValue );
342cdf0e10cSrcweir             remindMapped( nRow );
343cdf0e10cSrcweir         }
344cdf0e10cSrcweir         return (* reinterpret_cast< const Reference< XContentIdentifier > * >
345cdf0e10cSrcweir                 (getRowAny( nRow ).getValue() ));
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir     catch( SQLException )
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         throw RuntimeException();
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir const Reference< XContent >& SAL_CALL CachedContentResultSet::CCRS_Cache
getContent(sal_Int32 nRow)354cdf0e10cSrcweir     ::getContent( sal_Int32 nRow )
355cdf0e10cSrcweir     throw( com::sun::star::uno::RuntimeException )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     try
358cdf0e10cSrcweir     {
359cdf0e10cSrcweir         if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) )
360cdf0e10cSrcweir         {
361cdf0e10cSrcweir             Any& rRow = getRowAny( nRow );
362cdf0e10cSrcweir             Reference< XContent > aValue;
363cdf0e10cSrcweir             rRow >>= aValue;
364cdf0e10cSrcweir             rRow <<= m_xContentIdentifierMapping->mapContent( aValue );
365cdf0e10cSrcweir             remindMapped( nRow );
366cdf0e10cSrcweir         }
367cdf0e10cSrcweir         return (* reinterpret_cast< const Reference< XContent > * >
368cdf0e10cSrcweir                 (getRowAny( nRow ).getValue() ));
369cdf0e10cSrcweir     }
370cdf0e10cSrcweir     catch( SQLException )
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         throw RuntimeException();
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //--------------------------------------------------------------------------
377cdf0e10cSrcweir //--------------------------------------------------------------------------
378cdf0e10cSrcweir // class CCRS_PropertySetInfo
379cdf0e10cSrcweir //--------------------------------------------------------------------------
380cdf0e10cSrcweir //--------------------------------------------------------------------------
381cdf0e10cSrcweir 
382cdf0e10cSrcweir class CCRS_PropertySetInfo :
383cdf0e10cSrcweir                 public cppu::OWeakObject,
384cdf0e10cSrcweir                 public com::sun::star::lang::XTypeProvider,
385cdf0e10cSrcweir                 public com::sun::star::beans::XPropertySetInfo
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     friend class CachedContentResultSet;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     //my Properties
390cdf0e10cSrcweir     Sequence< com::sun::star::beans::Property >*
391cdf0e10cSrcweir                             m_pProperties;
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     //some helping variables ( names for my special properties )
394cdf0e10cSrcweir     static rtl::OUString    m_aPropertyNameForCount;
395cdf0e10cSrcweir     static rtl::OUString    m_aPropertyNameForFinalCount;
396cdf0e10cSrcweir     static rtl::OUString    m_aPropertyNameForFetchSize;
397cdf0e10cSrcweir     static rtl::OUString    m_aPropertyNameForFetchDirection;
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     long                    m_nFetchSizePropertyHandle;
400cdf0e10cSrcweir     long                    m_nFetchDirectionPropertyHandle;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir private:
403cdf0e10cSrcweir     sal_Int32 SAL_CALL
404cdf0e10cSrcweir     impl_getRemainedHandle() const;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     sal_Bool SAL_CALL
407cdf0e10cSrcweir     impl_queryProperty(
408cdf0e10cSrcweir             const rtl::OUString& rName
409cdf0e10cSrcweir             , com::sun::star::beans::Property& rProp ) const;
410cdf0e10cSrcweir     sal_Int32 SAL_CALL
411cdf0e10cSrcweir     impl_getPos( const rtl::OUString& rName ) const;
412cdf0e10cSrcweir 
413cdf0e10cSrcweir     static sal_Bool SAL_CALL
414cdf0e10cSrcweir     impl_isMyPropertyName( const rtl::OUString& rName );
415cdf0e10cSrcweir 
416cdf0e10cSrcweir public:
417cdf0e10cSrcweir     CCRS_PropertySetInfo(   Reference<
418cdf0e10cSrcweir             XPropertySetInfo > xPropertySetInfoOrigin );
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     virtual ~CCRS_PropertySetInfo();
421cdf0e10cSrcweir 
422cdf0e10cSrcweir     // XInterface
423cdf0e10cSrcweir     XINTERFACE_DECL()
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     // XTypeProvider
426cdf0e10cSrcweir     XTYPEPROVIDER_DECL()
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     // XPropertySetInfo
429cdf0e10cSrcweir     virtual Sequence< com::sun::star::beans::Property > SAL_CALL
430cdf0e10cSrcweir     getProperties()
431cdf0e10cSrcweir         throw( RuntimeException );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     virtual com::sun::star::beans::Property SAL_CALL
434cdf0e10cSrcweir     getPropertyByName( const rtl::OUString& aName )
435cdf0e10cSrcweir         throw( com::sun::star::beans::UnknownPropertyException, RuntimeException );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     virtual sal_Bool SAL_CALL
438cdf0e10cSrcweir     hasPropertyByName( const rtl::OUString& Name )
439cdf0e10cSrcweir         throw( RuntimeException );
440cdf0e10cSrcweir };
441cdf0e10cSrcweir 
442cdf0e10cSrcweir OUString    CCRS_PropertySetInfo::m_aPropertyNameForCount( OUString::createFromAscii( "RowCount" ) );
443cdf0e10cSrcweir OUString    CCRS_PropertySetInfo::m_aPropertyNameForFinalCount( OUString::createFromAscii( "IsRowCountFinal" ) );
444cdf0e10cSrcweir OUString    CCRS_PropertySetInfo::m_aPropertyNameForFetchSize( OUString::createFromAscii( "FetchSize" ) );
445cdf0e10cSrcweir OUString    CCRS_PropertySetInfo::m_aPropertyNameForFetchDirection( OUString::createFromAscii( "FetchDirection" ) );
446cdf0e10cSrcweir 
CCRS_PropertySetInfo(Reference<XPropertySetInfo> xInfo)447cdf0e10cSrcweir CCRS_PropertySetInfo::CCRS_PropertySetInfo(
448cdf0e10cSrcweir         Reference< XPropertySetInfo > xInfo )
449cdf0e10cSrcweir         : m_pProperties( NULL )
450cdf0e10cSrcweir         , m_nFetchSizePropertyHandle( -1 )
451cdf0e10cSrcweir         , m_nFetchDirectionPropertyHandle( -1 )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     //initialize list of properties:
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     // it is required, that the received xInfo contains the two
456cdf0e10cSrcweir     // properties with names 'm_aPropertyNameForCount' and
457cdf0e10cSrcweir     // 'm_aPropertyNameForFinalCount'
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     if( xInfo.is() )
460cdf0e10cSrcweir     {
461cdf0e10cSrcweir         Sequence<Property> aProps = xInfo->getProperties();
462cdf0e10cSrcweir         m_pProperties = new Sequence<Property> ( aProps );
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir     else
465cdf0e10cSrcweir     {
466cdf0e10cSrcweir         OSL_ENSURE( sal_False, "The received XPropertySetInfo doesn't contain required properties" );
467cdf0e10cSrcweir         m_pProperties = new Sequence<Property>;
468cdf0e10cSrcweir     }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir     //ensure, that we haven't got the Properties 'FetchSize' and 'Direction' twice:
471cdf0e10cSrcweir     sal_Int32 nFetchSize = impl_getPos( m_aPropertyNameForFetchSize );
472cdf0e10cSrcweir     sal_Int32 nFetchDirection = impl_getPos( m_aPropertyNameForFetchDirection );
473cdf0e10cSrcweir     sal_Int32 nDeleted = 0;
474cdf0e10cSrcweir     if( nFetchSize != -1 )
475cdf0e10cSrcweir         nDeleted++;
476cdf0e10cSrcweir     if( nFetchDirection != -1 )
477cdf0e10cSrcweir         nDeleted++;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     Sequence< Property >* pOrigProps = new Sequence<Property> ( *m_pProperties );
480cdf0e10cSrcweir     sal_Int32 nOrigProps = pOrigProps->getLength();
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     m_pProperties->realloc( nOrigProps + 2 - nDeleted );//note that nDeleted is <= 2
483cdf0e10cSrcweir     for( sal_Int32 n = 0, m = 0; n < nOrigProps; n++, m++ )
484cdf0e10cSrcweir     {
485cdf0e10cSrcweir         if( n == nFetchSize || n == nFetchDirection )
486cdf0e10cSrcweir             m--;
487cdf0e10cSrcweir         else
488cdf0e10cSrcweir             (*m_pProperties)[ m ] = (*pOrigProps)[ n ];
489cdf0e10cSrcweir     }
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         Property& rMyProp = (*m_pProperties)[ nOrigProps - nDeleted ];
492cdf0e10cSrcweir         rMyProp.Name = m_aPropertyNameForFetchSize;
493cdf0e10cSrcweir         rMyProp.Type = getCppuType( static_cast< const sal_Int32 * >( 0 ) );
494cdf0e10cSrcweir         rMyProp.Attributes = PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT;
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         if( nFetchSize != -1 )
497cdf0e10cSrcweir             m_nFetchSizePropertyHandle = (*pOrigProps)[nFetchSize].Handle;
498cdf0e10cSrcweir         else
499cdf0e10cSrcweir             m_nFetchSizePropertyHandle = impl_getRemainedHandle();
500cdf0e10cSrcweir 
501cdf0e10cSrcweir         rMyProp.Handle = m_nFetchSizePropertyHandle;
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     }
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         Property& rMyProp = (*m_pProperties)[ nOrigProps - nDeleted + 1 ];
506cdf0e10cSrcweir         rMyProp.Name = m_aPropertyNameForFetchDirection;
507cdf0e10cSrcweir         rMyProp.Type = getCppuType( static_cast< const sal_Bool * >( 0 ) );
508cdf0e10cSrcweir         rMyProp.Attributes = PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir         if( nFetchSize != -1 )
511cdf0e10cSrcweir             m_nFetchDirectionPropertyHandle = (*pOrigProps)[nFetchDirection].Handle;
512cdf0e10cSrcweir         else
513cdf0e10cSrcweir             m_nFetchDirectionPropertyHandle = impl_getRemainedHandle();
514cdf0e10cSrcweir 
515cdf0e10cSrcweir         m_nFetchDirectionPropertyHandle = rMyProp.Handle;
516cdf0e10cSrcweir     }
517cdf0e10cSrcweir     delete pOrigProps;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
~CCRS_PropertySetInfo()520cdf0e10cSrcweir CCRS_PropertySetInfo::~CCRS_PropertySetInfo()
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     delete m_pProperties;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir //--------------------------------------------------------------------------
526cdf0e10cSrcweir // XInterface methods.
527cdf0e10cSrcweir //--------------------------------------------------------------------------
528cdf0e10cSrcweir //list all interfaces inclusive baseclasses of interfaces
529cdf0e10cSrcweir XINTERFACE_IMPL_2( CCRS_PropertySetInfo
530cdf0e10cSrcweir                   , XTypeProvider
531cdf0e10cSrcweir                   , XPropertySetInfo
532cdf0e10cSrcweir                   );
533cdf0e10cSrcweir 
534cdf0e10cSrcweir //--------------------------------------------------------------------------
535cdf0e10cSrcweir // XTypeProvider methods.
536cdf0e10cSrcweir //--------------------------------------------------------------------------
537cdf0e10cSrcweir //list all interfaces exclusive baseclasses
538cdf0e10cSrcweir XTYPEPROVIDER_IMPL_2( CCRS_PropertySetInfo
539cdf0e10cSrcweir                     , XTypeProvider
540cdf0e10cSrcweir                     , XPropertySetInfo
541cdf0e10cSrcweir                     );
542cdf0e10cSrcweir //--------------------------------------------------------------------------
543cdf0e10cSrcweir // XPropertySetInfo methods.
544cdf0e10cSrcweir //--------------------------------------------------------------------------
545cdf0e10cSrcweir //virtual
546cdf0e10cSrcweir Sequence< Property > SAL_CALL CCRS_PropertySetInfo
getProperties()547cdf0e10cSrcweir     ::getProperties() throw( RuntimeException )
548cdf0e10cSrcweir {
549cdf0e10cSrcweir     return *m_pProperties;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir //virtual
553cdf0e10cSrcweir Property SAL_CALL CCRS_PropertySetInfo
getPropertyByName(const rtl::OUString & aName)554cdf0e10cSrcweir     ::getPropertyByName( const rtl::OUString& aName )
555cdf0e10cSrcweir         throw( UnknownPropertyException, RuntimeException )
556cdf0e10cSrcweir {
557cdf0e10cSrcweir     if ( !aName.getLength() )
558cdf0e10cSrcweir         throw UnknownPropertyException();
559cdf0e10cSrcweir 
560cdf0e10cSrcweir     Property aProp;
561cdf0e10cSrcweir     if ( impl_queryProperty( aName, aProp ) )
562cdf0e10cSrcweir         return aProp;
563cdf0e10cSrcweir 
564cdf0e10cSrcweir     throw UnknownPropertyException();
565cdf0e10cSrcweir }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir //virtual
568cdf0e10cSrcweir sal_Bool SAL_CALL CCRS_PropertySetInfo
hasPropertyByName(const rtl::OUString & Name)569cdf0e10cSrcweir     ::hasPropertyByName( const rtl::OUString& Name )
570cdf0e10cSrcweir         throw( RuntimeException )
571cdf0e10cSrcweir {
572cdf0e10cSrcweir     return ( impl_getPos( Name ) != -1 );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir //--------------------------------------------------------------------------
576cdf0e10cSrcweir // impl_ methods.
577cdf0e10cSrcweir //--------------------------------------------------------------------------
578cdf0e10cSrcweir 
579cdf0e10cSrcweir sal_Int32 SAL_CALL CCRS_PropertySetInfo
impl_getPos(const OUString & rName) const580cdf0e10cSrcweir             ::impl_getPos( const OUString& rName ) const
581cdf0e10cSrcweir {
582cdf0e10cSrcweir     for( sal_Int32 nN = m_pProperties->getLength(); nN--; )
583cdf0e10cSrcweir     {
584cdf0e10cSrcweir         const Property& rMyProp = (*m_pProperties)[nN];
585cdf0e10cSrcweir         if( rMyProp.Name == rName )
586cdf0e10cSrcweir             return nN;
587cdf0e10cSrcweir     }
588cdf0e10cSrcweir     return -1;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir sal_Bool SAL_CALL CCRS_PropertySetInfo
impl_queryProperty(const OUString & rName,Property & rProp) const592cdf0e10cSrcweir         ::impl_queryProperty( const OUString& rName, Property& rProp ) const
593cdf0e10cSrcweir {
594cdf0e10cSrcweir     for( sal_Int32 nN = m_pProperties->getLength(); nN--; )
595cdf0e10cSrcweir     {
596cdf0e10cSrcweir         const Property& rMyProp = (*m_pProperties)[nN];
597cdf0e10cSrcweir         if( rMyProp.Name == rName )
598cdf0e10cSrcweir         {
599cdf0e10cSrcweir             rProp.Name = rMyProp.Name;
600cdf0e10cSrcweir             rProp.Handle = rMyProp.Handle;
601cdf0e10cSrcweir             rProp.Type = rMyProp.Type;
602cdf0e10cSrcweir             rProp.Attributes = rMyProp.Attributes;
603cdf0e10cSrcweir 
604cdf0e10cSrcweir             return sal_True;
605cdf0e10cSrcweir         }
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir     return sal_False;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir //static
611cdf0e10cSrcweir sal_Bool SAL_CALL CCRS_PropertySetInfo
impl_isMyPropertyName(const OUString & rPropertyName)612cdf0e10cSrcweir         ::impl_isMyPropertyName( const OUString& rPropertyName )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir     return ( rPropertyName == m_aPropertyNameForCount
615cdf0e10cSrcweir     || rPropertyName == m_aPropertyNameForFinalCount
616cdf0e10cSrcweir     || rPropertyName == m_aPropertyNameForFetchSize
617cdf0e10cSrcweir     || rPropertyName == m_aPropertyNameForFetchDirection );
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir sal_Int32 SAL_CALL CCRS_PropertySetInfo
impl_getRemainedHandle() const621cdf0e10cSrcweir             ::impl_getRemainedHandle( ) const
622cdf0e10cSrcweir {
623cdf0e10cSrcweir     sal_Int32 nHandle = 1;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     if( !m_pProperties )
626cdf0e10cSrcweir     {
627cdf0e10cSrcweir         OSL_ENSURE( sal_False, "Properties not initialized yet" );
628cdf0e10cSrcweir         return nHandle;
629cdf0e10cSrcweir     }
630cdf0e10cSrcweir     sal_Bool bFound = sal_True;
631cdf0e10cSrcweir     while( bFound )
632cdf0e10cSrcweir     {
633cdf0e10cSrcweir         bFound = sal_False;
634cdf0e10cSrcweir         for( sal_Int32 nN = m_pProperties->getLength(); nN--; )
635cdf0e10cSrcweir         {
636cdf0e10cSrcweir             if( nHandle == (*m_pProperties)[nN].Handle )
637cdf0e10cSrcweir             {
638cdf0e10cSrcweir                 bFound = sal_True;
639cdf0e10cSrcweir                 nHandle++;
640cdf0e10cSrcweir                 break;
641cdf0e10cSrcweir             }
642cdf0e10cSrcweir         }
643cdf0e10cSrcweir     }
644cdf0e10cSrcweir     return nHandle;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir //--------------------------------------------------------------------------
648cdf0e10cSrcweir //--------------------------------------------------------------------------
649cdf0e10cSrcweir // class CachedContentResultSet
650cdf0e10cSrcweir //--------------------------------------------------------------------------
651cdf0e10cSrcweir //--------------------------------------------------------------------------
652cdf0e10cSrcweir 
CachedContentResultSet(const Reference<XMultiServiceFactory> & xSMgr,const Reference<XResultSet> & xOrigin,const Reference<XContentIdentifierMapping> & xContentIdentifierMapping)653cdf0e10cSrcweir CachedContentResultSet::CachedContentResultSet(
654cdf0e10cSrcweir                   const Reference< XMultiServiceFactory > & xSMgr
655cdf0e10cSrcweir                 , const Reference< XResultSet > & xOrigin
656cdf0e10cSrcweir                 , const Reference< XContentIdentifierMapping > &
657cdf0e10cSrcweir                     xContentIdentifierMapping )
658cdf0e10cSrcweir                 : ContentResultSetWrapper( xOrigin )
659cdf0e10cSrcweir 
660cdf0e10cSrcweir                 , m_xSMgr( xSMgr )
661cdf0e10cSrcweir                 , m_xFetchProvider( NULL )
662cdf0e10cSrcweir                 , m_xFetchProviderForContentAccess( NULL )
663cdf0e10cSrcweir 
664cdf0e10cSrcweir                 , m_xMyPropertySetInfo( NULL )
665cdf0e10cSrcweir                 , m_pMyPropSetInfo( NULL )
666cdf0e10cSrcweir 
667cdf0e10cSrcweir                 , m_xContentIdentifierMapping( xContentIdentifierMapping )
668cdf0e10cSrcweir                 , m_nRow( 0 ) // Position is one-based. Zero means: before first element.
669cdf0e10cSrcweir                 , m_bAfterLast( sal_False )
670cdf0e10cSrcweir                 , m_nLastAppliedPos( 0 )
671cdf0e10cSrcweir                 , m_bAfterLastApplied( sal_False )
672cdf0e10cSrcweir                 , m_nKnownCount( 0 )
673cdf0e10cSrcweir                 , m_bFinalCount( sal_False )
674cdf0e10cSrcweir                 , m_nFetchSize(
675cdf0e10cSrcweir                     COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE )
676cdf0e10cSrcweir                 , m_nFetchDirection(
677cdf0e10cSrcweir                     COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION )
678cdf0e10cSrcweir 
679cdf0e10cSrcweir                 , m_bLastReadWasFromCache( sal_False )
680cdf0e10cSrcweir                 , m_bLastCachedReadWasNull( sal_True )
681cdf0e10cSrcweir                 , m_aCache( m_xContentIdentifierMapping )
682cdf0e10cSrcweir                 , m_aCacheContentIdentifierString( m_xContentIdentifierMapping )
683cdf0e10cSrcweir                 , m_aCacheContentIdentifier( m_xContentIdentifierMapping )
684cdf0e10cSrcweir                 , m_aCacheContent( m_xContentIdentifierMapping )
685cdf0e10cSrcweir                 , m_bTriedToGetTypeConverter( sal_False )
686cdf0e10cSrcweir                 , m_xTypeConverter( NULL )
687cdf0e10cSrcweir {
688cdf0e10cSrcweir     m_xFetchProvider = Reference< XFetchProvider >( m_xResultSetOrigin, UNO_QUERY );
689cdf0e10cSrcweir     OSL_ENSURE( m_xFetchProvider.is(), "interface XFetchProvider is required" );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir     m_xFetchProviderForContentAccess = Reference< XFetchProviderForContentAccess >( m_xResultSetOrigin, UNO_QUERY );
692cdf0e10cSrcweir     OSL_ENSURE( m_xFetchProviderForContentAccess.is(), "interface XFetchProviderForContentAccess is required" );
693cdf0e10cSrcweir 
694cdf0e10cSrcweir     impl_init();
695cdf0e10cSrcweir };
696cdf0e10cSrcweir 
~CachedContentResultSet()697cdf0e10cSrcweir CachedContentResultSet::~CachedContentResultSet()
698cdf0e10cSrcweir {
699cdf0e10cSrcweir     impl_deinit();
700cdf0e10cSrcweir     //do not delete m_pMyPropSetInfo, cause it is hold via reference
701cdf0e10cSrcweir };
702cdf0e10cSrcweir 
703cdf0e10cSrcweir //--------------------------------------------------------------------------
704cdf0e10cSrcweir // impl_ methods.
705cdf0e10cSrcweir //--------------------------------------------------------------------------
706cdf0e10cSrcweir 
707cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
applyPositionToOrigin(sal_Int32 nRow)708cdf0e10cSrcweir     ::applyPositionToOrigin( sal_Int32 nRow )
709cdf0e10cSrcweir     throw( SQLException,
710cdf0e10cSrcweir            RuntimeException )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     impl_EnsureNotDisposed();
713cdf0e10cSrcweir     //-------------------------------------------------------------------------
714cdf0e10cSrcweir     /**
715cdf0e10cSrcweir     @returns
716cdf0e10cSrcweir         <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
717cdf0e10cSrcweir         the result set.
718cdf0e10cSrcweir     */
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
721cdf0e10cSrcweir     OSL_ENSURE( nRow >= 0, "only positive values supported" );
722cdf0e10cSrcweir     if( !m_xResultSetOrigin.is() )
723cdf0e10cSrcweir     {
724cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
725cdf0e10cSrcweir         return sal_False;
726cdf0e10cSrcweir     }
727cdf0e10cSrcweir //  OSL_ENSURE( nRow <= m_nKnownCount, "don't step into regions you don't know with this method" );
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     sal_Int32 nLastAppliedPos = m_nLastAppliedPos;
730cdf0e10cSrcweir     sal_Bool bAfterLastApplied = m_bAfterLastApplied;
731cdf0e10cSrcweir     sal_Bool bAfterLast = m_bAfterLast;
732cdf0e10cSrcweir     sal_Int32 nForwardOnly = m_nForwardOnly;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     aGuard.clear();
735cdf0e10cSrcweir 
736cdf0e10cSrcweir     if( bAfterLastApplied || nLastAppliedPos != nRow )
737cdf0e10cSrcweir     {
738cdf0e10cSrcweir         if( nForwardOnly == 1 )
739cdf0e10cSrcweir         {
740cdf0e10cSrcweir             if( bAfterLastApplied || bAfterLast || !nRow || nRow < nLastAppliedPos )
741cdf0e10cSrcweir                 throw SQLException();
742cdf0e10cSrcweir 
743cdf0e10cSrcweir             sal_Int32 nN = nRow - nLastAppliedPos;
744cdf0e10cSrcweir             sal_Int32 nM;
745cdf0e10cSrcweir             for( nM = 0; nN--; nM++ )
746cdf0e10cSrcweir             {
747cdf0e10cSrcweir                 if( !m_xResultSetOrigin->next() )
748cdf0e10cSrcweir                     break;
749cdf0e10cSrcweir             }
750cdf0e10cSrcweir 
751cdf0e10cSrcweir             aGuard.reacquire();
752cdf0e10cSrcweir             m_nLastAppliedPos += nM;
753cdf0e10cSrcweir             m_bAfterLastApplied = nRow != m_nLastAppliedPos;
754cdf0e10cSrcweir             return nRow == m_nLastAppliedPos;
755cdf0e10cSrcweir         }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir         if( !nRow ) //absolute( 0 ) will throw exception
758cdf0e10cSrcweir         {
759cdf0e10cSrcweir             m_xResultSetOrigin->beforeFirst();
760cdf0e10cSrcweir 
761cdf0e10cSrcweir             aGuard.reacquire();
762cdf0e10cSrcweir             m_nLastAppliedPos = 0;
763cdf0e10cSrcweir             m_bAfterLastApplied = sal_False;
764cdf0e10cSrcweir             return sal_False;
765cdf0e10cSrcweir         }
766cdf0e10cSrcweir         try
767cdf0e10cSrcweir         {
768cdf0e10cSrcweir             //move absolute, if !nLastAppliedPos
769cdf0e10cSrcweir             //because move relative would throw exception
770cdf0e10cSrcweir             if( !nLastAppliedPos || bAfterLast || bAfterLastApplied )
771cdf0e10cSrcweir             {
772cdf0e10cSrcweir                 sal_Bool bValid = m_xResultSetOrigin->absolute( nRow );
773cdf0e10cSrcweir 
774cdf0e10cSrcweir                 aGuard.reacquire();
775cdf0e10cSrcweir                 m_nLastAppliedPos = nRow;
776cdf0e10cSrcweir                 m_bAfterLastApplied = !bValid;
777cdf0e10cSrcweir                 return bValid;
778cdf0e10cSrcweir             }
779cdf0e10cSrcweir             else
780cdf0e10cSrcweir             {
781cdf0e10cSrcweir                 sal_Bool bValid = m_xResultSetOrigin->relative( nRow - nLastAppliedPos );
782cdf0e10cSrcweir 
783cdf0e10cSrcweir                 aGuard.reacquire();
784cdf0e10cSrcweir                 m_nLastAppliedPos += ( nRow - nLastAppliedPos );
785cdf0e10cSrcweir                 m_bAfterLastApplied = !bValid;
786cdf0e10cSrcweir                 return bValid;
787cdf0e10cSrcweir             }
788cdf0e10cSrcweir         }
789cdf0e10cSrcweir         catch( SQLException& rEx )
790cdf0e10cSrcweir         {
791cdf0e10cSrcweir             if( !bAfterLastApplied && !bAfterLast && nRow > nLastAppliedPos && impl_isForwardOnly() )
792cdf0e10cSrcweir             {
793cdf0e10cSrcweir                 sal_Int32 nN = nRow - nLastAppliedPos;
794cdf0e10cSrcweir                 sal_Int32 nM;
795cdf0e10cSrcweir                 for( nM = 0; nN--; nM++ )
796cdf0e10cSrcweir                 {
797cdf0e10cSrcweir                     if( !m_xResultSetOrigin->next() )
798cdf0e10cSrcweir                         break;
799cdf0e10cSrcweir                 }
800cdf0e10cSrcweir 
801cdf0e10cSrcweir                 aGuard.reacquire();
802cdf0e10cSrcweir                 m_nLastAppliedPos += nM;
803cdf0e10cSrcweir                 m_bAfterLastApplied = nRow != m_nLastAppliedPos;
804cdf0e10cSrcweir             }
805cdf0e10cSrcweir             else
806cdf0e10cSrcweir                 throw rEx;
807cdf0e10cSrcweir         }
808cdf0e10cSrcweir 
809cdf0e10cSrcweir         return nRow == m_nLastAppliedPos;
810cdf0e10cSrcweir     }
811cdf0e10cSrcweir     return sal_True;
812cdf0e10cSrcweir };
813cdf0e10cSrcweir 
814cdf0e10cSrcweir //--------------------------------------------------------------------------
815cdf0e10cSrcweir //--------------------------------------------------------------------------
816cdf0e10cSrcweir //define for fetching data
817cdf0e10cSrcweir //--------------------------------------------------------------------------
818cdf0e10cSrcweir //--------------------------------------------------------------------------
819cdf0e10cSrcweir 
820cdf0e10cSrcweir #define FETCH_XXX( aCache, fetchInterface, fetchMethod )            \
821cdf0e10cSrcweir sal_Bool bDirection = !!(                                           \
822cdf0e10cSrcweir     nFetchDirection != FetchDirection::REVERSE );                   \
823cdf0e10cSrcweir FetchResult aResult =                                               \
824cdf0e10cSrcweir     fetchInterface->fetchMethod( nRow, nFetchSize, bDirection );    \
825cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard2( m_aMutex );              \
826cdf0e10cSrcweir aCache.loadData( aResult );                                         \
827cdf0e10cSrcweir sal_Int32 nMax = aCache.getMaxRow();                                \
828cdf0e10cSrcweir sal_Int32 nCurCount = m_nKnownCount;                                \
829cdf0e10cSrcweir sal_Bool bIsFinalCount = aCache.hasKnownLast();                     \
830cdf0e10cSrcweir sal_Bool bCurIsFinalCount = m_bFinalCount;                          \
831cdf0e10cSrcweir aGuard2.clear();                                                    \
832cdf0e10cSrcweir if( nMax > nCurCount )                                              \
833cdf0e10cSrcweir     impl_changeRowCount( nCurCount, nMax );                         \
834cdf0e10cSrcweir if( bIsFinalCount && !bCurIsFinalCount )                            \
835cdf0e10cSrcweir     impl_changeIsRowCountFinal( bCurIsFinalCount, bIsFinalCount );
836cdf0e10cSrcweir 
837cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_fetchData(sal_Int32 nRow,sal_Int32 nFetchSize,sal_Int32 nFetchDirection)838cdf0e10cSrcweir     ::impl_fetchData( sal_Int32 nRow
839cdf0e10cSrcweir         , sal_Int32 nFetchSize, sal_Int32 nFetchDirection )
840cdf0e10cSrcweir         throw( com::sun::star::uno::RuntimeException )
841cdf0e10cSrcweir {
842cdf0e10cSrcweir     FETCH_XXX( m_aCache, m_xFetchProvider, fetch );
843cdf0e10cSrcweir }
844cdf0e10cSrcweir 
845cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_changeRowCount(sal_Int32 nOld,sal_Int32 nNew)846cdf0e10cSrcweir     ::impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew )
847cdf0e10cSrcweir {
848cdf0e10cSrcweir     OSL_ENSURE( nNew > nOld, "RowCount only can grow" );
849cdf0e10cSrcweir     if( nNew <= nOld )
850cdf0e10cSrcweir         return;
851cdf0e10cSrcweir 
852cdf0e10cSrcweir     //create PropertyChangeEvent and set value
853cdf0e10cSrcweir     PropertyChangeEvent aEvt;
854cdf0e10cSrcweir     {
855cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
856cdf0e10cSrcweir         aEvt.Source =  static_cast< XPropertySet * >( this );
857cdf0e10cSrcweir         aEvt.Further = sal_False;
858cdf0e10cSrcweir         aEvt.OldValue <<= nOld;
859cdf0e10cSrcweir         aEvt.NewValue <<= nNew;
860cdf0e10cSrcweir 
861cdf0e10cSrcweir         m_nKnownCount = nNew;
862cdf0e10cSrcweir     }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir     //send PropertyChangeEvent to listeners
865cdf0e10cSrcweir     impl_notifyPropertyChangeListeners( aEvt );
866cdf0e10cSrcweir }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_changeIsRowCountFinal(sal_Bool bOld,sal_Bool bNew)869cdf0e10cSrcweir     ::impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir     OSL_ENSURE( !bOld && bNew, "This change is not allowed for IsRowCountFinal" );
872cdf0e10cSrcweir     if( ! (!bOld && bNew ) )
873cdf0e10cSrcweir         return;
874cdf0e10cSrcweir 
875cdf0e10cSrcweir     //create PropertyChangeEvent and set value
876cdf0e10cSrcweir     PropertyChangeEvent aEvt;
877cdf0e10cSrcweir     {
878cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
879cdf0e10cSrcweir         aEvt.Source =  static_cast< XPropertySet * >( this );
880cdf0e10cSrcweir         aEvt.Further = sal_False;
881cdf0e10cSrcweir         aEvt.OldValue <<= bOld;
882cdf0e10cSrcweir         aEvt.NewValue <<= bNew;
883cdf0e10cSrcweir 
884cdf0e10cSrcweir         m_bFinalCount = bNew;
885cdf0e10cSrcweir     }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir     //send PropertyChangeEvent to listeners
888cdf0e10cSrcweir     impl_notifyPropertyChangeListeners( aEvt );
889cdf0e10cSrcweir }
890cdf0e10cSrcweir 
891cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
impl_isKnownValidPosition(sal_Int32 nRow)892cdf0e10cSrcweir     ::impl_isKnownValidPosition( sal_Int32 nRow )
893cdf0e10cSrcweir {
894cdf0e10cSrcweir     return m_nKnownCount && nRow
895cdf0e10cSrcweir             && nRow <= m_nKnownCount;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
impl_isKnownInvalidPosition(sal_Int32 nRow)899cdf0e10cSrcweir     ::impl_isKnownInvalidPosition( sal_Int32 nRow )
900cdf0e10cSrcweir {
901cdf0e10cSrcweir     if( !nRow )
902cdf0e10cSrcweir         return sal_True;
903cdf0e10cSrcweir     if( !m_bFinalCount )
904cdf0e10cSrcweir         return sal_False;
905cdf0e10cSrcweir     return nRow > m_nKnownCount;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 
909cdf0e10cSrcweir //virtual
910cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_initPropertySetInfo()911cdf0e10cSrcweir     ::impl_initPropertySetInfo()
912cdf0e10cSrcweir {
913cdf0e10cSrcweir     ContentResultSetWrapper::impl_initPropertySetInfo();
914cdf0e10cSrcweir 
915cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
916cdf0e10cSrcweir     if( m_pMyPropSetInfo )
917cdf0e10cSrcweir         return;
918cdf0e10cSrcweir     m_pMyPropSetInfo = new CCRS_PropertySetInfo( m_xPropertySetInfo );
919cdf0e10cSrcweir     m_xMyPropertySetInfo = m_pMyPropSetInfo;
920cdf0e10cSrcweir     m_xPropertySetInfo = m_xMyPropertySetInfo;
921cdf0e10cSrcweir }
922cdf0e10cSrcweir 
923cdf0e10cSrcweir //--------------------------------------------------------------------------
924cdf0e10cSrcweir // XInterface methods. ( inherited )
925cdf0e10cSrcweir //--------------------------------------------------------------------------
XINTERFACE_COMMON_IMPL(CachedContentResultSet)926cdf0e10cSrcweir XINTERFACE_COMMON_IMPL( CachedContentResultSet )
927cdf0e10cSrcweir 
928cdf0e10cSrcweir Any SAL_CALL CachedContentResultSet
929cdf0e10cSrcweir     ::queryInterface( const Type&  rType )
930cdf0e10cSrcweir     throw ( RuntimeException )
931cdf0e10cSrcweir {
932cdf0e10cSrcweir     //list all interfaces inclusive baseclasses of interfaces
933cdf0e10cSrcweir 
934cdf0e10cSrcweir     Any aRet = ContentResultSetWrapper::queryInterface( rType );
935cdf0e10cSrcweir     if( aRet.hasValue() )
936cdf0e10cSrcweir         return aRet;
937cdf0e10cSrcweir 
938cdf0e10cSrcweir     aRet = cppu::queryInterface( rType,
939cdf0e10cSrcweir                 static_cast< XTypeProvider* >( this ),
940cdf0e10cSrcweir                 static_cast< XServiceInfo* >( this ) );
941cdf0e10cSrcweir 
942cdf0e10cSrcweir     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
943cdf0e10cSrcweir }
944cdf0e10cSrcweir 
945cdf0e10cSrcweir //--------------------------------------------------------------------------
946cdf0e10cSrcweir // XTypeProvider methods.
947cdf0e10cSrcweir //--------------------------------------------------------------------------
948cdf0e10cSrcweir //list all interfaces exclusive baseclasses
949cdf0e10cSrcweir XTYPEPROVIDER_IMPL_11( CachedContentResultSet
950cdf0e10cSrcweir                     , XTypeProvider
951cdf0e10cSrcweir                     , XServiceInfo
952cdf0e10cSrcweir                     , XComponent
953cdf0e10cSrcweir                     , XCloseable
954cdf0e10cSrcweir                     , XResultSetMetaDataSupplier
955cdf0e10cSrcweir                     , XPropertySet
956cdf0e10cSrcweir 
957cdf0e10cSrcweir                     , XPropertyChangeListener
958cdf0e10cSrcweir                     , XVetoableChangeListener
959cdf0e10cSrcweir 
960cdf0e10cSrcweir                     , XContentAccess
961cdf0e10cSrcweir 
962cdf0e10cSrcweir                     , XResultSet
963cdf0e10cSrcweir                     , XRow );
964cdf0e10cSrcweir 
965cdf0e10cSrcweir //--------------------------------------------------------------------------
966cdf0e10cSrcweir // XServiceInfo methods.
967cdf0e10cSrcweir //--------------------------------------------------------------------------
968cdf0e10cSrcweir 
969cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( CachedContentResultSet,
970cdf0e10cSrcweir                            OUString::createFromAscii(
971cdf0e10cSrcweir                             "com.sun.star.comp.ucb.CachedContentResultSet" ),
972cdf0e10cSrcweir                            OUString::createFromAscii(
973cdf0e10cSrcweir                             CACHED_CONTENT_RESULTSET_SERVICE_NAME ) );
974cdf0e10cSrcweir 
975cdf0e10cSrcweir //--------------------------------------------------------------------------
976cdf0e10cSrcweir // XPropertySet methods. ( inherited )
977cdf0e10cSrcweir //--------------------------------------------------------------------------
978cdf0e10cSrcweir 
979cdf0e10cSrcweir // virtual
980cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
setPropertyValue(const OUString & aPropertyName,const Any & aValue)981cdf0e10cSrcweir     ::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
982cdf0e10cSrcweir     throw( UnknownPropertyException,
983cdf0e10cSrcweir            PropertyVetoException,
984cdf0e10cSrcweir            IllegalArgumentException,
985cdf0e10cSrcweir            WrappedTargetException,
986cdf0e10cSrcweir            RuntimeException )
987cdf0e10cSrcweir {
988cdf0e10cSrcweir     impl_EnsureNotDisposed();
989cdf0e10cSrcweir 
990cdf0e10cSrcweir     if( !getPropertySetInfo().is() )
991cdf0e10cSrcweir     {
992cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
993cdf0e10cSrcweir         throw UnknownPropertyException();
994cdf0e10cSrcweir     }
995cdf0e10cSrcweir 
996cdf0e10cSrcweir     Property aProp = m_pMyPropSetInfo->getPropertyByName( aPropertyName );
997cdf0e10cSrcweir         //throws UnknownPropertyException, if so
998cdf0e10cSrcweir 
999cdf0e10cSrcweir     if( aProp.Attributes & PropertyAttribute::READONLY )
1000cdf0e10cSrcweir     {
1001cdf0e10cSrcweir         //It is assumed, that the properties
1002cdf0e10cSrcweir         //'RowCount' and 'IsRowCountFinal' are readonly!
1003cdf0e10cSrcweir         throw IllegalArgumentException();
1004cdf0e10cSrcweir     }
1005cdf0e10cSrcweir     if( aProp.Name == CCRS_PropertySetInfo
1006cdf0e10cSrcweir                         ::m_aPropertyNameForFetchDirection )
1007cdf0e10cSrcweir     {
1008cdf0e10cSrcweir         //check value
1009cdf0e10cSrcweir         sal_Int32 nNew;
1010cdf0e10cSrcweir         if( !( aValue >>= nNew ) )
1011cdf0e10cSrcweir         {
1012cdf0e10cSrcweir             throw IllegalArgumentException();
1013cdf0e10cSrcweir         }
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir         if( nNew == FetchDirection::UNKNOWN )
1016cdf0e10cSrcweir         {
1017cdf0e10cSrcweir             nNew = COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION;
1018cdf0e10cSrcweir         }
1019cdf0e10cSrcweir         else if( !( nNew == FetchDirection::FORWARD
1020cdf0e10cSrcweir                 || nNew == FetchDirection::REVERSE ) )
1021cdf0e10cSrcweir         {
1022cdf0e10cSrcweir             throw IllegalArgumentException();
1023cdf0e10cSrcweir         }
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir         //create PropertyChangeEvent and set value
1026cdf0e10cSrcweir         PropertyChangeEvent aEvt;
1027cdf0e10cSrcweir         {
1028cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
1029cdf0e10cSrcweir             aEvt.Source =  static_cast< XPropertySet * >( this );
1030cdf0e10cSrcweir             aEvt.PropertyName = aPropertyName;
1031cdf0e10cSrcweir             aEvt.Further = sal_False;
1032cdf0e10cSrcweir             aEvt.PropertyHandle = m_pMyPropSetInfo->
1033cdf0e10cSrcweir                                     m_nFetchDirectionPropertyHandle;
1034cdf0e10cSrcweir             aEvt.OldValue <<= m_nFetchDirection;
1035cdf0e10cSrcweir             aEvt.NewValue <<= nNew;
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir             m_nFetchDirection = nNew;
1038cdf0e10cSrcweir         }
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir         //send PropertyChangeEvent to listeners
1041cdf0e10cSrcweir         impl_notifyPropertyChangeListeners( aEvt );
1042cdf0e10cSrcweir     }
1043cdf0e10cSrcweir     else if( aProp.Name == CCRS_PropertySetInfo
1044cdf0e10cSrcweir                         ::m_aPropertyNameForFetchSize )
1045cdf0e10cSrcweir     {
1046cdf0e10cSrcweir         //check value
1047cdf0e10cSrcweir         sal_Int32 nNew;
1048cdf0e10cSrcweir         if( !( aValue >>= nNew ) )
1049cdf0e10cSrcweir         {
1050cdf0e10cSrcweir             throw IllegalArgumentException();
1051cdf0e10cSrcweir         }
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir         if( nNew < 0 )
1054cdf0e10cSrcweir         {
1055cdf0e10cSrcweir             nNew = COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE;
1056cdf0e10cSrcweir         }
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir         //create PropertyChangeEvent and set value
1059cdf0e10cSrcweir         PropertyChangeEvent aEvt;
1060cdf0e10cSrcweir         {
1061cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
1062cdf0e10cSrcweir             aEvt.Source =  static_cast< XPropertySet * >( this );
1063cdf0e10cSrcweir             aEvt.PropertyName = aPropertyName;
1064cdf0e10cSrcweir             aEvt.Further = sal_False;
1065cdf0e10cSrcweir             aEvt.PropertyHandle = m_pMyPropSetInfo->
1066cdf0e10cSrcweir                                     m_nFetchSizePropertyHandle;
1067cdf0e10cSrcweir             aEvt.OldValue <<= m_nFetchSize;
1068cdf0e10cSrcweir             aEvt.NewValue <<= nNew;
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir             m_nFetchSize = nNew;
1071cdf0e10cSrcweir         }
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir         //send PropertyChangeEvent to listeners
1074cdf0e10cSrcweir         impl_notifyPropertyChangeListeners( aEvt );
1075cdf0e10cSrcweir     }
1076cdf0e10cSrcweir     else
1077cdf0e10cSrcweir     {
1078cdf0e10cSrcweir         impl_init_xPropertySetOrigin();
1079cdf0e10cSrcweir         {
1080cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
1081cdf0e10cSrcweir             if( !m_xPropertySetOrigin.is() )
1082cdf0e10cSrcweir             {
1083cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1084cdf0e10cSrcweir                 return;
1085cdf0e10cSrcweir             }
1086cdf0e10cSrcweir         }
1087cdf0e10cSrcweir         m_xPropertySetOrigin->setPropertyValue( aPropertyName, aValue );
1088cdf0e10cSrcweir     }
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir //--------------------------------------------------------------------------
1092cdf0e10cSrcweir // virtual
1093cdf0e10cSrcweir Any SAL_CALL CachedContentResultSet
getPropertyValue(const OUString & rPropertyName)1094cdf0e10cSrcweir     ::getPropertyValue( const OUString& rPropertyName )
1095cdf0e10cSrcweir     throw( UnknownPropertyException,
1096cdf0e10cSrcweir            WrappedTargetException,
1097cdf0e10cSrcweir            RuntimeException )
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir     impl_EnsureNotDisposed();
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir     if( !getPropertySetInfo().is() )
1102cdf0e10cSrcweir     {
1103cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1104cdf0e10cSrcweir         throw UnknownPropertyException();
1105cdf0e10cSrcweir     }
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir     Property aProp = m_pMyPropSetInfo->getPropertyByName( rPropertyName );
1108cdf0e10cSrcweir         //throws UnknownPropertyException, if so
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir     Any aValue;
1111cdf0e10cSrcweir     if( rPropertyName == CCRS_PropertySetInfo
1112cdf0e10cSrcweir                         ::m_aPropertyNameForCount )
1113cdf0e10cSrcweir     {
1114cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1115cdf0e10cSrcweir         aValue <<= m_nKnownCount;
1116cdf0e10cSrcweir     }
1117cdf0e10cSrcweir     else if( rPropertyName == CCRS_PropertySetInfo
1118cdf0e10cSrcweir                             ::m_aPropertyNameForFinalCount )
1119cdf0e10cSrcweir     {
1120cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1121cdf0e10cSrcweir         aValue <<= m_bFinalCount;
1122cdf0e10cSrcweir     }
1123cdf0e10cSrcweir     else if( rPropertyName == CCRS_PropertySetInfo
1124cdf0e10cSrcweir                             ::m_aPropertyNameForFetchSize )
1125cdf0e10cSrcweir     {
1126cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1127cdf0e10cSrcweir         aValue <<= m_nFetchSize;
1128cdf0e10cSrcweir     }
1129cdf0e10cSrcweir     else if( rPropertyName == CCRS_PropertySetInfo
1130cdf0e10cSrcweir                             ::m_aPropertyNameForFetchDirection )
1131cdf0e10cSrcweir     {
1132cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1133cdf0e10cSrcweir         aValue <<= m_nFetchDirection;
1134cdf0e10cSrcweir     }
1135cdf0e10cSrcweir     else
1136cdf0e10cSrcweir     {
1137cdf0e10cSrcweir         impl_init_xPropertySetOrigin();
1138cdf0e10cSrcweir         {
1139cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
1140cdf0e10cSrcweir             if( !m_xPropertySetOrigin.is() )
1141cdf0e10cSrcweir             {
1142cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1143cdf0e10cSrcweir                 throw UnknownPropertyException();
1144cdf0e10cSrcweir             }
1145cdf0e10cSrcweir         }
1146cdf0e10cSrcweir         aValue = m_xPropertySetOrigin->getPropertyValue( rPropertyName );
1147cdf0e10cSrcweir     }
1148cdf0e10cSrcweir     return aValue;
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir //--------------------------------------------------------------------------
1152cdf0e10cSrcweir // own methods.  ( inherited )
1153cdf0e10cSrcweir //--------------------------------------------------------------------------
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir //virtual
1156cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_disposing(const EventObject & rEventObject)1157cdf0e10cSrcweir     ::impl_disposing( const EventObject& rEventObject )
1158cdf0e10cSrcweir     throw( RuntimeException )
1159cdf0e10cSrcweir {
1160cdf0e10cSrcweir     {
1161cdf0e10cSrcweir         impl_EnsureNotDisposed();
1162cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1163cdf0e10cSrcweir         //release all references to the broadcaster:
1164cdf0e10cSrcweir         m_xFetchProvider.clear();
1165cdf0e10cSrcweir         m_xFetchProviderForContentAccess.clear();
1166cdf0e10cSrcweir     }
1167cdf0e10cSrcweir     ContentResultSetWrapper::impl_disposing( rEventObject );
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir //virtual
1171cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_propertyChange(const PropertyChangeEvent & rEvt)1172cdf0e10cSrcweir     ::impl_propertyChange( const PropertyChangeEvent& rEvt )
1173cdf0e10cSrcweir     throw( RuntimeException )
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir     impl_EnsureNotDisposed();
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir     PropertyChangeEvent aEvt( rEvt );
1178cdf0e10cSrcweir     aEvt.Source = static_cast< XPropertySet * >( this );
1179cdf0e10cSrcweir     aEvt.Further = sal_False;
1180cdf0e10cSrcweir     //---------
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir     if( CCRS_PropertySetInfo
1183cdf0e10cSrcweir             ::impl_isMyPropertyName( rEvt.PropertyName ) )
1184cdf0e10cSrcweir     {
1185cdf0e10cSrcweir         //don't notify foreign events on fetchsize and fetchdirection
1186cdf0e10cSrcweir         if( aEvt.PropertyName == CCRS_PropertySetInfo
1187cdf0e10cSrcweir                                 ::m_aPropertyNameForFetchSize
1188cdf0e10cSrcweir         || aEvt.PropertyName == CCRS_PropertySetInfo
1189cdf0e10cSrcweir                                 ::m_aPropertyNameForFetchDirection )
1190cdf0e10cSrcweir             return;
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir         //adjust my props 'RowCount' and 'IsRowCountFinal'
1193cdf0e10cSrcweir         if( aEvt.PropertyName == CCRS_PropertySetInfo
1194cdf0e10cSrcweir                             ::m_aPropertyNameForCount )
1195cdf0e10cSrcweir         {//RowCount changed
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir             //check value
1198cdf0e10cSrcweir             sal_Int32 nNew = 0;
1199cdf0e10cSrcweir             if( !( aEvt.NewValue >>= nNew ) )
1200cdf0e10cSrcweir             {
1201cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "PropertyChangeEvent contains wrong data" );
1202cdf0e10cSrcweir                 return;
1203cdf0e10cSrcweir             }
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir             impl_changeRowCount( m_nKnownCount, nNew );
1206cdf0e10cSrcweir         }
1207cdf0e10cSrcweir         else if( aEvt.PropertyName == CCRS_PropertySetInfo
1208cdf0e10cSrcweir                                 ::m_aPropertyNameForFinalCount )
1209cdf0e10cSrcweir         {//IsRowCountFinal changed
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir             //check value
1212cdf0e10cSrcweir             sal_Bool bNew = sal_False;
1213cdf0e10cSrcweir             if( !( aEvt.NewValue >>= bNew ) )
1214cdf0e10cSrcweir             {
1215cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "PropertyChangeEvent contains wrong data" );
1216cdf0e10cSrcweir                 return;
1217cdf0e10cSrcweir             }
1218cdf0e10cSrcweir             impl_changeIsRowCountFinal( m_bFinalCount, bNew );
1219cdf0e10cSrcweir         }
1220cdf0e10cSrcweir         return;
1221cdf0e10cSrcweir     }
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir     //-----------
1224cdf0e10cSrcweir     impl_notifyPropertyChangeListeners( aEvt );
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir //virtual
1229cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
impl_vetoableChange(const PropertyChangeEvent & rEvt)1230cdf0e10cSrcweir     ::impl_vetoableChange( const PropertyChangeEvent& rEvt )
1231cdf0e10cSrcweir     throw( PropertyVetoException,
1232cdf0e10cSrcweir            RuntimeException )
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir     impl_EnsureNotDisposed();
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir     //don't notify events on my properties, cause they are not vetoable
1237cdf0e10cSrcweir     if( CCRS_PropertySetInfo
1238cdf0e10cSrcweir             ::impl_isMyPropertyName( rEvt.PropertyName ) )
1239cdf0e10cSrcweir     {
1240cdf0e10cSrcweir         return;
1241cdf0e10cSrcweir     }
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir     PropertyChangeEvent aEvt( rEvt );
1245cdf0e10cSrcweir     aEvt.Source = static_cast< XPropertySet * >( this );
1246cdf0e10cSrcweir     aEvt.Further = sal_False;
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir     impl_notifyVetoableChangeListeners( aEvt );
1249cdf0e10cSrcweir }
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir //--------------------------------------------------------------------------
1252cdf0e10cSrcweir // XContentAccess methods. ( inherited ) ( -- position dependent )
1253cdf0e10cSrcweir //--------------------------------------------------------------------------
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir #define XCONTENTACCESS_queryXXX( queryXXX, XXX, TYPE )              \
1256cdf0e10cSrcweir impl_EnsureNotDisposed();                                   \
1257cdf0e10cSrcweir ReacquireableGuard aGuard( m_aMutex );                      \
1258cdf0e10cSrcweir sal_Int32 nRow = m_nRow;                                    \
1259cdf0e10cSrcweir sal_Int32 nFetchSize = m_nFetchSize;                        \
1260cdf0e10cSrcweir sal_Int32 nFetchDirection = m_nFetchDirection;              \
1261cdf0e10cSrcweir if( !m_aCache##XXX.hasRow( nRow ) )                         \
1262cdf0e10cSrcweir {                                                           \
1263cdf0e10cSrcweir     if( !m_aCache##XXX.hasCausedException( nRow ) )         \
1264cdf0e10cSrcweir {                                                           \
1265cdf0e10cSrcweir         if( !m_xFetchProviderForContentAccess.is() )        \
1266cdf0e10cSrcweir         {                                                   \
1267cdf0e10cSrcweir             OSL_ENSURE( sal_False, "broadcaster was disposed already" );\
1268cdf0e10cSrcweir             throw RuntimeException();                       \
1269cdf0e10cSrcweir         }                                                   \
1270cdf0e10cSrcweir         aGuard.clear();                                     \
1271cdf0e10cSrcweir         if( impl_isForwardOnly() )                          \
1272cdf0e10cSrcweir             applyPositionToOrigin( nRow );                  \
1273cdf0e10cSrcweir                                                             \
1274cdf0e10cSrcweir         FETCH_XXX( m_aCache##XXX, m_xFetchProviderForContentAccess, fetch##XXX##s ); \
1275cdf0e10cSrcweir     }                                                       \
1276cdf0e10cSrcweir     aGuard.reacquire();                                     \
1277cdf0e10cSrcweir     if( !m_aCache##XXX.hasRow( nRow ) )                     \
1278cdf0e10cSrcweir     {                                                       \
1279cdf0e10cSrcweir         aGuard.clear();                                     \
1280cdf0e10cSrcweir         applyPositionToOrigin( nRow );                      \
1281cdf0e10cSrcweir         TYPE aRet = ContentResultSetWrapper::queryXXX();    \
1282cdf0e10cSrcweir         if( m_xContentIdentifierMapping.is() )              \
1283cdf0e10cSrcweir             return m_xContentIdentifierMapping->map##XXX( aRet );\
1284cdf0e10cSrcweir         return aRet;                                        \
1285cdf0e10cSrcweir     }                                                       \
1286cdf0e10cSrcweir }                                                           \
1287cdf0e10cSrcweir return m_aCache##XXX.get##XXX( nRow );
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir //--------------------------------------------------------------------------
1290cdf0e10cSrcweir // virtual
1291cdf0e10cSrcweir OUString SAL_CALL CachedContentResultSet
queryContentIdentifierString()1292cdf0e10cSrcweir     ::queryContentIdentifierString()
1293cdf0e10cSrcweir     throw( RuntimeException )
1294cdf0e10cSrcweir {
1295cdf0e10cSrcweir     XCONTENTACCESS_queryXXX( queryContentIdentifierString, ContentIdentifierString, OUString )
1296cdf0e10cSrcweir }
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir //--------------------------------------------------------------------------
1299cdf0e10cSrcweir // virtual
1300cdf0e10cSrcweir Reference< XContentIdentifier > SAL_CALL CachedContentResultSet
queryContentIdentifier()1301cdf0e10cSrcweir     ::queryContentIdentifier()
1302cdf0e10cSrcweir     throw( RuntimeException )
1303cdf0e10cSrcweir {
1304cdf0e10cSrcweir     XCONTENTACCESS_queryXXX( queryContentIdentifier, ContentIdentifier, Reference< XContentIdentifier > )
1305cdf0e10cSrcweir }
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir //--------------------------------------------------------------------------
1308cdf0e10cSrcweir // virtual
1309cdf0e10cSrcweir Reference< XContent > SAL_CALL CachedContentResultSet
queryContent()1310cdf0e10cSrcweir     ::queryContent()
1311cdf0e10cSrcweir     throw( RuntimeException )
1312cdf0e10cSrcweir {
1313cdf0e10cSrcweir     XCONTENTACCESS_queryXXX( queryContent, Content, Reference< XContent > )
1314cdf0e10cSrcweir }
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir //-----------------------------------------------------------------
1317cdf0e10cSrcweir // XResultSet methods. ( inherited )
1318cdf0e10cSrcweir //-----------------------------------------------------------------
1319cdf0e10cSrcweir //virtual
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
next()1322cdf0e10cSrcweir     ::next()
1323cdf0e10cSrcweir     throw( SQLException,
1324cdf0e10cSrcweir            RuntimeException )
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir     impl_EnsureNotDisposed();
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1329cdf0e10cSrcweir     //after last
1330cdf0e10cSrcweir     if( m_bAfterLast )
1331cdf0e10cSrcweir         return sal_False;
1332cdf0e10cSrcweir     //last
1333cdf0e10cSrcweir     aGuard.clear();
1334cdf0e10cSrcweir     if( isLast() )
1335cdf0e10cSrcweir     {
1336cdf0e10cSrcweir         aGuard.reacquire();
1337cdf0e10cSrcweir         m_nRow++;
1338cdf0e10cSrcweir         m_bAfterLast = sal_True;
1339cdf0e10cSrcweir         return sal_False;
1340cdf0e10cSrcweir     }
1341cdf0e10cSrcweir     aGuard.reacquire();
1342cdf0e10cSrcweir     //known valid position
1343cdf0e10cSrcweir     if( impl_isKnownValidPosition( m_nRow + 1 ) )
1344cdf0e10cSrcweir     {
1345cdf0e10cSrcweir         m_nRow++;
1346cdf0e10cSrcweir         return sal_True;
1347cdf0e10cSrcweir     }
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir     //unknown position
1350cdf0e10cSrcweir     sal_Int32 nRow = m_nRow;
1351cdf0e10cSrcweir     aGuard.clear();
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir     sal_Bool bValid = applyPositionToOrigin( nRow + 1 );
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir     aGuard.reacquire();
1356cdf0e10cSrcweir     m_nRow = nRow + 1;
1357cdf0e10cSrcweir     m_bAfterLast = !bValid;
1358cdf0e10cSrcweir     return bValid;
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir //virtual
1362cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
previous()1363cdf0e10cSrcweir     ::previous()
1364cdf0e10cSrcweir     throw( SQLException,
1365cdf0e10cSrcweir            RuntimeException )
1366cdf0e10cSrcweir {
1367cdf0e10cSrcweir     impl_EnsureNotDisposed();
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir     if( impl_isForwardOnly() )
1370cdf0e10cSrcweir         throw SQLException();
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1373cdf0e10cSrcweir     //before first ?:
1374cdf0e10cSrcweir     if( !m_bAfterLast && !m_nRow )
1375cdf0e10cSrcweir         return sal_False;
1376cdf0e10cSrcweir     //first ?:
1377cdf0e10cSrcweir     if( !m_bAfterLast && m_nKnownCount && m_nRow == 1 )
1378cdf0e10cSrcweir     {
1379cdf0e10cSrcweir         m_nRow--;
1380cdf0e10cSrcweir         m_bAfterLast = sal_False;
1381cdf0e10cSrcweir         return sal_False;
1382cdf0e10cSrcweir     }
1383cdf0e10cSrcweir     //known valid position ?:
1384cdf0e10cSrcweir     if( impl_isKnownValidPosition( m_nRow - 1 ) )
1385cdf0e10cSrcweir     {
1386cdf0e10cSrcweir         m_nRow--;
1387cdf0e10cSrcweir         m_bAfterLast = sal_False;
1388cdf0e10cSrcweir         return sal_True;
1389cdf0e10cSrcweir     }
1390cdf0e10cSrcweir     //unknown position:
1391cdf0e10cSrcweir     sal_Int32 nRow = m_nRow;
1392cdf0e10cSrcweir     aGuard.clear();
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir     sal_Bool bValid = applyPositionToOrigin( nRow - 1  );
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir     aGuard.reacquire();
1397cdf0e10cSrcweir     m_nRow = nRow - 1;
1398cdf0e10cSrcweir     m_bAfterLast = sal_False;
1399cdf0e10cSrcweir     return bValid;
1400cdf0e10cSrcweir }
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir //virtual
1403cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
absolute(sal_Int32 row)1404cdf0e10cSrcweir     ::absolute( sal_Int32 row )
1405cdf0e10cSrcweir     throw( SQLException,
1406cdf0e10cSrcweir            RuntimeException )
1407cdf0e10cSrcweir {
1408cdf0e10cSrcweir     impl_EnsureNotDisposed();
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir     if( !row )
1411cdf0e10cSrcweir         throw SQLException();
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir     if( impl_isForwardOnly() )
1414cdf0e10cSrcweir         throw SQLException();
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir     if( !m_xResultSetOrigin.is() )
1419cdf0e10cSrcweir     {
1420cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1421cdf0e10cSrcweir         return sal_False;
1422cdf0e10cSrcweir     }
1423cdf0e10cSrcweir     if( row < 0 )
1424cdf0e10cSrcweir     {
1425cdf0e10cSrcweir         if( m_bFinalCount )
1426cdf0e10cSrcweir         {
1427cdf0e10cSrcweir             sal_Int32 nNewRow = m_nKnownCount + 1 + row;
1428cdf0e10cSrcweir             sal_Bool bValid = sal_True;
1429cdf0e10cSrcweir             if( nNewRow <= 0 )
1430cdf0e10cSrcweir             {
1431cdf0e10cSrcweir                 nNewRow = 0;
1432cdf0e10cSrcweir                 bValid = sal_False;
1433cdf0e10cSrcweir             }
1434cdf0e10cSrcweir             m_nRow = nNewRow;
1435cdf0e10cSrcweir             m_bAfterLast = sal_False;
1436cdf0e10cSrcweir             return bValid;
1437cdf0e10cSrcweir         }
1438cdf0e10cSrcweir         //unknown final count:
1439cdf0e10cSrcweir         aGuard.clear();
1440cdf0e10cSrcweir 
1441cdf0e10cSrcweir         // Solaris has problems catching or propagating derived exceptions
1442cdf0e10cSrcweir         // when only the base class is known, so make ResultSetException
1443cdf0e10cSrcweir         // (derived from SQLException) known here:
1444cdf0e10cSrcweir         sal_Bool bValid;
1445cdf0e10cSrcweir         try
1446cdf0e10cSrcweir         {
1447cdf0e10cSrcweir             bValid = m_xResultSetOrigin->absolute( row );
1448cdf0e10cSrcweir         }
1449cdf0e10cSrcweir         catch (ResultSetException &)
1450cdf0e10cSrcweir         {
1451cdf0e10cSrcweir             throw;
1452cdf0e10cSrcweir         }
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir         aGuard.reacquire();
1455cdf0e10cSrcweir         if( m_bFinalCount )
1456cdf0e10cSrcweir         {
1457cdf0e10cSrcweir             sal_Int32 nNewRow = m_nKnownCount + 1 + row;
1458cdf0e10cSrcweir             if( nNewRow < 0 )
1459cdf0e10cSrcweir                 nNewRow = 0;
1460cdf0e10cSrcweir             m_nLastAppliedPos = nNewRow;
1461cdf0e10cSrcweir             m_nRow = nNewRow;
1462cdf0e10cSrcweir             m_bAfterLastApplied = m_bAfterLast = sal_False;
1463cdf0e10cSrcweir             return bValid;
1464cdf0e10cSrcweir         }
1465cdf0e10cSrcweir         aGuard.clear();
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir         sal_Int32 nCurRow = m_xResultSetOrigin->getRow();
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir         aGuard.reacquire();
1470cdf0e10cSrcweir         m_nLastAppliedPos = nCurRow;
1471cdf0e10cSrcweir         m_nRow = nCurRow;
1472cdf0e10cSrcweir         m_bAfterLast = sal_False;
1473cdf0e10cSrcweir         return nCurRow != 0;
1474cdf0e10cSrcweir     }
1475cdf0e10cSrcweir     //row > 0:
1476cdf0e10cSrcweir     if( m_bFinalCount )
1477cdf0e10cSrcweir     {
1478cdf0e10cSrcweir         if( row > m_nKnownCount )
1479cdf0e10cSrcweir         {
1480cdf0e10cSrcweir             m_nRow = m_nKnownCount + 1;
1481cdf0e10cSrcweir             m_bAfterLast = sal_True;
1482cdf0e10cSrcweir             return sal_False;
1483cdf0e10cSrcweir         }
1484cdf0e10cSrcweir         m_nRow = row;
1485cdf0e10cSrcweir         m_bAfterLast = sal_False;
1486cdf0e10cSrcweir         return sal_True;
1487cdf0e10cSrcweir     }
1488cdf0e10cSrcweir     //unknown new position:
1489cdf0e10cSrcweir     aGuard.clear();
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir     sal_Bool bValid = m_xResultSetOrigin->absolute( row );
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir     aGuard.reacquire();
1494cdf0e10cSrcweir     if( m_bFinalCount )
1495cdf0e10cSrcweir     {
1496cdf0e10cSrcweir         sal_Int32 nNewRow = row;
1497cdf0e10cSrcweir         if( nNewRow > m_nKnownCount )
1498cdf0e10cSrcweir         {
1499cdf0e10cSrcweir             nNewRow = m_nKnownCount + 1;
1500cdf0e10cSrcweir             m_bAfterLastApplied = m_bAfterLast = sal_True;
1501cdf0e10cSrcweir         }
1502cdf0e10cSrcweir         else
1503cdf0e10cSrcweir             m_bAfterLastApplied = m_bAfterLast = sal_False;
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir         m_nLastAppliedPos = nNewRow;
1506cdf0e10cSrcweir         m_nRow = nNewRow;
1507cdf0e10cSrcweir         return bValid;
1508cdf0e10cSrcweir     }
1509cdf0e10cSrcweir     aGuard.clear();
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir     sal_Int32 nCurRow = m_xResultSetOrigin->getRow();
1512cdf0e10cSrcweir     sal_Bool bIsAfterLast = m_xResultSetOrigin->isAfterLast();
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir     aGuard.reacquire();
1515cdf0e10cSrcweir     m_nLastAppliedPos = nCurRow;
1516cdf0e10cSrcweir     m_nRow = nCurRow;
1517cdf0e10cSrcweir     m_bAfterLastApplied = m_bAfterLast = bIsAfterLast;
1518cdf0e10cSrcweir     return nCurRow && !bIsAfterLast;
1519cdf0e10cSrcweir }
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir //virtual
1522cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
relative(sal_Int32 rows)1523cdf0e10cSrcweir     ::relative( sal_Int32 rows )
1524cdf0e10cSrcweir     throw( SQLException,
1525cdf0e10cSrcweir            RuntimeException )
1526cdf0e10cSrcweir {
1527cdf0e10cSrcweir     impl_EnsureNotDisposed();
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir     if( impl_isForwardOnly() )
1530cdf0e10cSrcweir         throw SQLException();
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1533cdf0e10cSrcweir     if( m_bAfterLast || impl_isKnownInvalidPosition( m_nRow ) )
1534cdf0e10cSrcweir         throw SQLException();
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir     if( !rows )
1537cdf0e10cSrcweir         return sal_True;
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir     sal_Int32 nNewRow = m_nRow + rows;
1540cdf0e10cSrcweir         if( nNewRow < 0 )
1541cdf0e10cSrcweir             nNewRow = 0;
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir     if( impl_isKnownValidPosition( nNewRow ) )
1544cdf0e10cSrcweir     {
1545cdf0e10cSrcweir         m_nRow = nNewRow;
1546cdf0e10cSrcweir         m_bAfterLast = sal_False;
1547cdf0e10cSrcweir         return sal_True;
1548cdf0e10cSrcweir     }
1549cdf0e10cSrcweir     else
1550cdf0e10cSrcweir     {
1551cdf0e10cSrcweir         //known invalid new position:
1552cdf0e10cSrcweir         if( nNewRow == 0 )
1553cdf0e10cSrcweir         {
1554cdf0e10cSrcweir             m_bAfterLast = sal_False;
1555cdf0e10cSrcweir             m_nRow = 0;
1556cdf0e10cSrcweir             return sal_False;
1557cdf0e10cSrcweir         }
1558cdf0e10cSrcweir         if( m_bFinalCount && nNewRow > m_nKnownCount )
1559cdf0e10cSrcweir         {
1560cdf0e10cSrcweir             m_bAfterLast = sal_True;
1561cdf0e10cSrcweir             m_nRow = m_nKnownCount + 1;
1562cdf0e10cSrcweir             return sal_False;
1563cdf0e10cSrcweir         }
1564cdf0e10cSrcweir         //unknown new position:
1565cdf0e10cSrcweir         aGuard.clear();
1566cdf0e10cSrcweir         sal_Bool bValid = applyPositionToOrigin( nNewRow );
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir         aGuard.reacquire();
1569cdf0e10cSrcweir         m_nRow = nNewRow;
1570cdf0e10cSrcweir         m_bAfterLast = !bValid && nNewRow > 0;
1571cdf0e10cSrcweir         return bValid;
1572cdf0e10cSrcweir     }
1573cdf0e10cSrcweir }
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir //virtual
1577cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
first()1578cdf0e10cSrcweir     ::first()
1579cdf0e10cSrcweir     throw( SQLException,
1580cdf0e10cSrcweir            RuntimeException )
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir     impl_EnsureNotDisposed();
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir     if( impl_isForwardOnly() )
1585cdf0e10cSrcweir         throw SQLException();
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1588cdf0e10cSrcweir     if( impl_isKnownValidPosition( 1 ) )
1589cdf0e10cSrcweir     {
1590cdf0e10cSrcweir         m_nRow = 1;
1591cdf0e10cSrcweir         m_bAfterLast = sal_False;
1592cdf0e10cSrcweir         return sal_True;
1593cdf0e10cSrcweir     }
1594cdf0e10cSrcweir     if( impl_isKnownInvalidPosition( 1 ) )
1595cdf0e10cSrcweir     {
1596cdf0e10cSrcweir         m_nRow = 1;
1597cdf0e10cSrcweir         m_bAfterLast = sal_False;
1598cdf0e10cSrcweir         return sal_False;
1599cdf0e10cSrcweir     }
1600cdf0e10cSrcweir     //unknown position
1601cdf0e10cSrcweir     aGuard.clear();
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir     sal_Bool bValid = applyPositionToOrigin( 1 );
1604cdf0e10cSrcweir 
1605cdf0e10cSrcweir     aGuard.reacquire();
1606cdf0e10cSrcweir     m_nRow = 1;
1607cdf0e10cSrcweir     m_bAfterLast = sal_False;
1608cdf0e10cSrcweir     return bValid;
1609cdf0e10cSrcweir }
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir //virtual
1612cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
last()1613cdf0e10cSrcweir     ::last()
1614cdf0e10cSrcweir     throw( SQLException,
1615cdf0e10cSrcweir            RuntimeException )
1616cdf0e10cSrcweir {
1617cdf0e10cSrcweir     impl_EnsureNotDisposed();
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir     if( impl_isForwardOnly() )
1620cdf0e10cSrcweir         throw SQLException();
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1623cdf0e10cSrcweir     if( m_bFinalCount )
1624cdf0e10cSrcweir     {
1625cdf0e10cSrcweir         m_nRow = m_nKnownCount;
1626cdf0e10cSrcweir         m_bAfterLast = sal_False;
1627cdf0e10cSrcweir         return m_nKnownCount != 0;
1628cdf0e10cSrcweir     }
1629cdf0e10cSrcweir     //unknown position
1630cdf0e10cSrcweir     if( !m_xResultSetOrigin.is() )
1631cdf0e10cSrcweir     {
1632cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1633cdf0e10cSrcweir         return sal_False;
1634cdf0e10cSrcweir     }
1635cdf0e10cSrcweir     aGuard.clear();
1636cdf0e10cSrcweir 
1637cdf0e10cSrcweir     sal_Bool bValid = m_xResultSetOrigin->last();
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir     aGuard.reacquire();
1640cdf0e10cSrcweir     m_bAfterLastApplied = m_bAfterLast = sal_False;
1641cdf0e10cSrcweir     if( m_bFinalCount )
1642cdf0e10cSrcweir     {
1643cdf0e10cSrcweir         m_nLastAppliedPos = m_nKnownCount;
1644cdf0e10cSrcweir         m_nRow = m_nKnownCount;
1645cdf0e10cSrcweir         return bValid;
1646cdf0e10cSrcweir     }
1647cdf0e10cSrcweir     aGuard.clear();
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir     sal_Int32 nCurRow = m_xResultSetOrigin->getRow();
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir     aGuard.reacquire();
1652cdf0e10cSrcweir     m_nLastAppliedPos = nCurRow;
1653cdf0e10cSrcweir     m_nRow = nCurRow;
1654cdf0e10cSrcweir     OSL_ENSURE( nCurRow >= m_nKnownCount, "position of last row < known Count, that could not be" );
1655cdf0e10cSrcweir     m_nKnownCount = nCurRow;
1656cdf0e10cSrcweir     m_bFinalCount = sal_True;
1657cdf0e10cSrcweir     return nCurRow != 0;
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir //virtual
1661cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
beforeFirst()1662cdf0e10cSrcweir     ::beforeFirst()
1663cdf0e10cSrcweir     throw( SQLException,
1664cdf0e10cSrcweir            RuntimeException )
1665cdf0e10cSrcweir {
1666cdf0e10cSrcweir     impl_EnsureNotDisposed();
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir     if( impl_isForwardOnly() )
1669cdf0e10cSrcweir         throw SQLException();
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
1672cdf0e10cSrcweir     m_nRow = 0;
1673cdf0e10cSrcweir     m_bAfterLast = sal_False;
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir //virtual
1677cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
afterLast()1678cdf0e10cSrcweir     ::afterLast()
1679cdf0e10cSrcweir     throw( SQLException,
1680cdf0e10cSrcweir            RuntimeException )
1681cdf0e10cSrcweir {
1682cdf0e10cSrcweir     impl_EnsureNotDisposed();
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir     if( impl_isForwardOnly() )
1685cdf0e10cSrcweir         throw SQLException();
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
1688cdf0e10cSrcweir     m_nRow = 1;
1689cdf0e10cSrcweir     m_bAfterLast = sal_True;
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir //virtual
1693cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
isAfterLast()1694cdf0e10cSrcweir     ::isAfterLast()
1695cdf0e10cSrcweir     throw( SQLException,
1696cdf0e10cSrcweir            RuntimeException )
1697cdf0e10cSrcweir {
1698cdf0e10cSrcweir     impl_EnsureNotDisposed();
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1701cdf0e10cSrcweir     if( !m_bAfterLast )
1702cdf0e10cSrcweir         return sal_False;
1703cdf0e10cSrcweir     if( m_nKnownCount )
1704cdf0e10cSrcweir         return m_bAfterLast;
1705cdf0e10cSrcweir     if( m_bFinalCount )
1706cdf0e10cSrcweir         return sal_False;
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir     if( !m_xResultSetOrigin.is() )
1709cdf0e10cSrcweir     {
1710cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1711cdf0e10cSrcweir         return sal_False;
1712cdf0e10cSrcweir     }
1713cdf0e10cSrcweir     aGuard.clear();
1714cdf0e10cSrcweir 
1715*c2cc1a3cSJohn Bampton     //find out whether the original resultset contains rows or not
1716cdf0e10cSrcweir     m_xResultSetOrigin->afterLast();
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir     aGuard.reacquire();
1719cdf0e10cSrcweir     m_bAfterLastApplied = sal_True;
1720cdf0e10cSrcweir     aGuard.clear();
1721cdf0e10cSrcweir 
1722cdf0e10cSrcweir     return m_xResultSetOrigin->isAfterLast();
1723cdf0e10cSrcweir }
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir //virtual
1726cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
isBeforeFirst()1727cdf0e10cSrcweir     ::isBeforeFirst()
1728cdf0e10cSrcweir     throw( SQLException,
1729cdf0e10cSrcweir            RuntimeException )
1730cdf0e10cSrcweir {
1731cdf0e10cSrcweir     impl_EnsureNotDisposed();
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
1734cdf0e10cSrcweir     if( m_bAfterLast )
1735cdf0e10cSrcweir         return sal_False;
1736cdf0e10cSrcweir     if( m_nRow )
1737cdf0e10cSrcweir         return sal_False;
1738cdf0e10cSrcweir     if( m_nKnownCount )
1739cdf0e10cSrcweir         return !m_nRow;
1740cdf0e10cSrcweir     if( m_bFinalCount )
1741cdf0e10cSrcweir         return sal_False;
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir     if( !m_xResultSetOrigin.is() )
1744cdf0e10cSrcweir     {
1745cdf0e10cSrcweir         OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1746cdf0e10cSrcweir         return sal_False;
1747cdf0e10cSrcweir     }
1748cdf0e10cSrcweir     aGuard.clear();
1749cdf0e10cSrcweir 
1750*c2cc1a3cSJohn Bampton     //find out whether the original resultset contains rows or not
1751cdf0e10cSrcweir     m_xResultSetOrigin->beforeFirst();
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir     aGuard.reacquire();
1754cdf0e10cSrcweir     m_bAfterLastApplied = sal_False;
1755cdf0e10cSrcweir     m_nLastAppliedPos = 0;
1756cdf0e10cSrcweir     aGuard.clear();
1757cdf0e10cSrcweir 
1758cdf0e10cSrcweir     return m_xResultSetOrigin->isBeforeFirst();
1759cdf0e10cSrcweir }
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir //virtual
1762cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
isFirst()1763cdf0e10cSrcweir     ::isFirst()
1764cdf0e10cSrcweir     throw( SQLException,
1765cdf0e10cSrcweir            RuntimeException )
1766cdf0e10cSrcweir {
1767cdf0e10cSrcweir     impl_EnsureNotDisposed();
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir     sal_Int32 nRow = 0;
1770cdf0e10cSrcweir     Reference< XResultSet > xResultSetOrigin;
1771cdf0e10cSrcweir 
1772cdf0e10cSrcweir     {
1773cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1774cdf0e10cSrcweir         if( m_bAfterLast )
1775cdf0e10cSrcweir             return sal_False;
1776cdf0e10cSrcweir         if( m_nRow != 1 )
1777cdf0e10cSrcweir             return sal_False;
1778cdf0e10cSrcweir         if( m_nKnownCount )
1779cdf0e10cSrcweir             return m_nRow == 1;
1780cdf0e10cSrcweir         if( m_bFinalCount )
1781cdf0e10cSrcweir             return sal_False;
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir         nRow = m_nRow;
1784cdf0e10cSrcweir         xResultSetOrigin = m_xResultSetOrigin;
1785cdf0e10cSrcweir     }
1786cdf0e10cSrcweir 
1787cdf0e10cSrcweir     //need to ask origin
1788cdf0e10cSrcweir     {
1789cdf0e10cSrcweir         if( applyPositionToOrigin( nRow ) )
1790cdf0e10cSrcweir             return xResultSetOrigin->isFirst();
1791cdf0e10cSrcweir         else
1792cdf0e10cSrcweir             return sal_False;
1793cdf0e10cSrcweir     }
1794cdf0e10cSrcweir }
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir //virtual
1797cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
isLast()1798cdf0e10cSrcweir     ::isLast()
1799cdf0e10cSrcweir     throw( SQLException,
1800cdf0e10cSrcweir            RuntimeException )
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir     impl_EnsureNotDisposed();
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir     sal_Int32 nRow = 0;
1805cdf0e10cSrcweir     Reference< XResultSet > xResultSetOrigin;
1806cdf0e10cSrcweir     {
1807cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1808cdf0e10cSrcweir         if( m_bAfterLast )
1809cdf0e10cSrcweir             return sal_False;
1810cdf0e10cSrcweir         if( m_nRow < m_nKnownCount )
1811cdf0e10cSrcweir             return sal_False;
1812cdf0e10cSrcweir         if( m_bFinalCount )
1813cdf0e10cSrcweir             return m_nKnownCount && m_nRow == m_nKnownCount;
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir         nRow = m_nRow;
1816cdf0e10cSrcweir         xResultSetOrigin = m_xResultSetOrigin;
1817cdf0e10cSrcweir     }
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir     //need to ask origin
1820cdf0e10cSrcweir     {
1821cdf0e10cSrcweir         if( applyPositionToOrigin( nRow ) )
1822cdf0e10cSrcweir             return xResultSetOrigin->isLast();
1823cdf0e10cSrcweir         else
1824cdf0e10cSrcweir             return sal_False;
1825cdf0e10cSrcweir     }
1826cdf0e10cSrcweir }
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir 
1829cdf0e10cSrcweir //virtual
1830cdf0e10cSrcweir sal_Int32 SAL_CALL CachedContentResultSet
getRow()1831cdf0e10cSrcweir     ::getRow()
1832cdf0e10cSrcweir     throw( SQLException,
1833cdf0e10cSrcweir            RuntimeException )
1834cdf0e10cSrcweir {
1835cdf0e10cSrcweir     impl_EnsureNotDisposed();
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
1838cdf0e10cSrcweir     if( m_bAfterLast )
1839cdf0e10cSrcweir         return 0;
1840cdf0e10cSrcweir     return m_nRow;
1841cdf0e10cSrcweir }
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir //virtual
1844cdf0e10cSrcweir void SAL_CALL CachedContentResultSet
refreshRow()1845cdf0e10cSrcweir     ::refreshRow()
1846cdf0e10cSrcweir     throw( SQLException,
1847cdf0e10cSrcweir            RuntimeException )
1848cdf0e10cSrcweir {
1849cdf0e10cSrcweir     impl_EnsureNotDisposed();
1850cdf0e10cSrcweir 
1851cdf0e10cSrcweir     //the ContentResultSet is static and will not change
1852cdf0e10cSrcweir     //therefore we don't need to reload anything
1853cdf0e10cSrcweir }
1854cdf0e10cSrcweir 
1855cdf0e10cSrcweir //virtual
1856cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
rowUpdated()1857cdf0e10cSrcweir     ::rowUpdated()
1858cdf0e10cSrcweir     throw( SQLException,
1859cdf0e10cSrcweir            RuntimeException )
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir     impl_EnsureNotDisposed();
1862cdf0e10cSrcweir 
1863cdf0e10cSrcweir     //the ContentResultSet is static and will not change
1864cdf0e10cSrcweir     return sal_False;
1865cdf0e10cSrcweir }
1866cdf0e10cSrcweir //virtual
1867cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
rowInserted()1868cdf0e10cSrcweir     ::rowInserted()
1869cdf0e10cSrcweir     throw( SQLException,
1870cdf0e10cSrcweir            RuntimeException )
1871cdf0e10cSrcweir {
1872cdf0e10cSrcweir     impl_EnsureNotDisposed();
1873cdf0e10cSrcweir 
1874cdf0e10cSrcweir     //the ContentResultSet is static and will not change
1875cdf0e10cSrcweir     return sal_False;
1876cdf0e10cSrcweir }
1877cdf0e10cSrcweir 
1878cdf0e10cSrcweir //virtual
1879cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
rowDeleted()1880cdf0e10cSrcweir     ::rowDeleted()
1881cdf0e10cSrcweir     throw( SQLException,
1882cdf0e10cSrcweir            RuntimeException )
1883cdf0e10cSrcweir {
1884cdf0e10cSrcweir     impl_EnsureNotDisposed();
1885cdf0e10cSrcweir 
1886cdf0e10cSrcweir     //the ContentResultSet is static and will not change
1887cdf0e10cSrcweir     return sal_False;
1888cdf0e10cSrcweir }
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir //virtual
1891cdf0e10cSrcweir Reference< XInterface > SAL_CALL CachedContentResultSet
getStatement()1892cdf0e10cSrcweir     ::getStatement()
1893cdf0e10cSrcweir     throw( SQLException,
1894cdf0e10cSrcweir            RuntimeException )
1895cdf0e10cSrcweir {
1896cdf0e10cSrcweir     impl_EnsureNotDisposed();
1897cdf0e10cSrcweir     //@todo ?return anything
1898cdf0e10cSrcweir     return Reference< XInterface >();
1899cdf0e10cSrcweir }
1900cdf0e10cSrcweir 
1901cdf0e10cSrcweir //-----------------------------------------------------------------
1902cdf0e10cSrcweir // XRow methods. ( inherited )
1903cdf0e10cSrcweir //-----------------------------------------------------------------
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir //virtual
1906cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
wasNull()1907cdf0e10cSrcweir     ::wasNull()
1908cdf0e10cSrcweir     throw( SQLException,
1909cdf0e10cSrcweir            RuntimeException )
1910cdf0e10cSrcweir {
1911cdf0e10cSrcweir     impl_EnsureNotDisposed();
1912cdf0e10cSrcweir     impl_init_xRowOrigin();
1913cdf0e10cSrcweir     {
1914cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1915cdf0e10cSrcweir         if( m_bLastReadWasFromCache )
1916cdf0e10cSrcweir             return m_bLastCachedReadWasNull;
1917cdf0e10cSrcweir         if( !m_xRowOrigin.is() )
1918cdf0e10cSrcweir         {
1919cdf0e10cSrcweir             OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1920cdf0e10cSrcweir             return sal_False;
1921cdf0e10cSrcweir         }
1922cdf0e10cSrcweir     }
1923cdf0e10cSrcweir     return m_xRowOrigin->wasNull();
1924cdf0e10cSrcweir }
1925cdf0e10cSrcweir 
1926cdf0e10cSrcweir //virtual
1927cdf0e10cSrcweir rtl::OUString SAL_CALL CachedContentResultSet
getString(sal_Int32 columnIndex)1928cdf0e10cSrcweir     ::getString( sal_Int32 columnIndex )
1929cdf0e10cSrcweir     throw( SQLException,
1930cdf0e10cSrcweir            RuntimeException )
1931cdf0e10cSrcweir {
1932cdf0e10cSrcweir     XROW_GETXXX( getString, OUString );
1933cdf0e10cSrcweir }
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir //virtual
1936cdf0e10cSrcweir sal_Bool SAL_CALL CachedContentResultSet
getBoolean(sal_Int32 columnIndex)1937cdf0e10cSrcweir     ::getBoolean( sal_Int32 columnIndex )
1938cdf0e10cSrcweir     throw( SQLException,
1939cdf0e10cSrcweir            RuntimeException )
1940cdf0e10cSrcweir {
1941cdf0e10cSrcweir     XROW_GETXXX( getBoolean, sal_Bool );
1942cdf0e10cSrcweir }
1943cdf0e10cSrcweir 
1944cdf0e10cSrcweir //virtual
1945cdf0e10cSrcweir sal_Int8 SAL_CALL CachedContentResultSet
getByte(sal_Int32 columnIndex)1946cdf0e10cSrcweir     ::getByte( sal_Int32 columnIndex )
1947cdf0e10cSrcweir     throw( SQLException,
1948cdf0e10cSrcweir            RuntimeException )
1949cdf0e10cSrcweir {
1950cdf0e10cSrcweir     XROW_GETXXX( getByte, sal_Int8 );
1951cdf0e10cSrcweir }
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir //virtual
1954cdf0e10cSrcweir sal_Int16 SAL_CALL CachedContentResultSet
getShort(sal_Int32 columnIndex)1955cdf0e10cSrcweir     ::getShort( sal_Int32 columnIndex )
1956cdf0e10cSrcweir     throw( SQLException,
1957cdf0e10cSrcweir            RuntimeException )
1958cdf0e10cSrcweir {
1959cdf0e10cSrcweir     XROW_GETXXX( getShort, sal_Int16 );
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir 
1962cdf0e10cSrcweir //virtual
1963cdf0e10cSrcweir sal_Int32 SAL_CALL CachedContentResultSet
getInt(sal_Int32 columnIndex)1964cdf0e10cSrcweir     ::getInt( sal_Int32 columnIndex )
1965cdf0e10cSrcweir     throw( SQLException,
1966cdf0e10cSrcweir            RuntimeException )
1967cdf0e10cSrcweir {
1968cdf0e10cSrcweir     XROW_GETXXX( getInt, sal_Int32 );
1969cdf0e10cSrcweir }
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir //virtual
1972cdf0e10cSrcweir sal_Int64 SAL_CALL CachedContentResultSet
getLong(sal_Int32 columnIndex)1973cdf0e10cSrcweir     ::getLong( sal_Int32 columnIndex )
1974cdf0e10cSrcweir     throw( SQLException,
1975cdf0e10cSrcweir            RuntimeException )
1976cdf0e10cSrcweir {
1977cdf0e10cSrcweir     XROW_GETXXX( getLong, sal_Int64 );
1978cdf0e10cSrcweir }
1979cdf0e10cSrcweir 
1980cdf0e10cSrcweir //virtual
1981cdf0e10cSrcweir float SAL_CALL CachedContentResultSet
getFloat(sal_Int32 columnIndex)1982cdf0e10cSrcweir     ::getFloat( sal_Int32 columnIndex )
1983cdf0e10cSrcweir     throw( SQLException,
1984cdf0e10cSrcweir            RuntimeException )
1985cdf0e10cSrcweir {
1986cdf0e10cSrcweir     XROW_GETXXX( getFloat, float );
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir //virtual
1990cdf0e10cSrcweir double SAL_CALL CachedContentResultSet
getDouble(sal_Int32 columnIndex)1991cdf0e10cSrcweir     ::getDouble( sal_Int32 columnIndex )
1992cdf0e10cSrcweir     throw( SQLException,
1993cdf0e10cSrcweir            RuntimeException )
1994cdf0e10cSrcweir {
1995cdf0e10cSrcweir     XROW_GETXXX( getDouble, double );
1996cdf0e10cSrcweir }
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir //virtual
1999cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL CachedContentResultSet
getBytes(sal_Int32 columnIndex)2000cdf0e10cSrcweir     ::getBytes( sal_Int32 columnIndex )
2001cdf0e10cSrcweir     throw( SQLException,
2002cdf0e10cSrcweir            RuntimeException )
2003cdf0e10cSrcweir {
2004cdf0e10cSrcweir     XROW_GETXXX( getBytes, Sequence< sal_Int8 > );
2005cdf0e10cSrcweir }
2006cdf0e10cSrcweir 
2007cdf0e10cSrcweir //virtual
2008cdf0e10cSrcweir Date SAL_CALL CachedContentResultSet
getDate(sal_Int32 columnIndex)2009cdf0e10cSrcweir     ::getDate( sal_Int32 columnIndex )
2010cdf0e10cSrcweir     throw( SQLException,
2011cdf0e10cSrcweir            RuntimeException )
2012cdf0e10cSrcweir {
2013cdf0e10cSrcweir     XROW_GETXXX( getDate, Date );
2014cdf0e10cSrcweir }
2015cdf0e10cSrcweir 
2016cdf0e10cSrcweir //virtual
2017cdf0e10cSrcweir Time SAL_CALL CachedContentResultSet
getTime(sal_Int32 columnIndex)2018cdf0e10cSrcweir     ::getTime( sal_Int32 columnIndex )
2019cdf0e10cSrcweir     throw( SQLException,
2020cdf0e10cSrcweir            RuntimeException )
2021cdf0e10cSrcweir {
2022cdf0e10cSrcweir     XROW_GETXXX( getTime, Time );
2023cdf0e10cSrcweir }
2024cdf0e10cSrcweir 
2025cdf0e10cSrcweir //virtual
2026cdf0e10cSrcweir DateTime SAL_CALL CachedContentResultSet
getTimestamp(sal_Int32 columnIndex)2027cdf0e10cSrcweir     ::getTimestamp( sal_Int32 columnIndex )
2028cdf0e10cSrcweir     throw( SQLException,
2029cdf0e10cSrcweir            RuntimeException )
2030cdf0e10cSrcweir {
2031cdf0e10cSrcweir     XROW_GETXXX( getTimestamp, DateTime );
2032cdf0e10cSrcweir }
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir //virtual
2035cdf0e10cSrcweir Reference< com::sun::star::io::XInputStream >
2036cdf0e10cSrcweir     SAL_CALL CachedContentResultSet
getBinaryStream(sal_Int32 columnIndex)2037cdf0e10cSrcweir     ::getBinaryStream( sal_Int32 columnIndex )
2038cdf0e10cSrcweir     throw( SQLException,
2039cdf0e10cSrcweir            RuntimeException )
2040cdf0e10cSrcweir {
2041cdf0e10cSrcweir     XROW_GETXXX( getBinaryStream, Reference< com::sun::star::io::XInputStream > );
2042cdf0e10cSrcweir }
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir //virtual
2045cdf0e10cSrcweir Reference< com::sun::star::io::XInputStream >
2046cdf0e10cSrcweir     SAL_CALL CachedContentResultSet
getCharacterStream(sal_Int32 columnIndex)2047cdf0e10cSrcweir     ::getCharacterStream( sal_Int32 columnIndex )
2048cdf0e10cSrcweir     throw( SQLException,
2049cdf0e10cSrcweir            RuntimeException )
2050cdf0e10cSrcweir {
2051cdf0e10cSrcweir     XROW_GETXXX( getCharacterStream, Reference< com::sun::star::io::XInputStream > );
2052cdf0e10cSrcweir }
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir //virtual
2055cdf0e10cSrcweir Any SAL_CALL CachedContentResultSet
getObject(sal_Int32 columnIndex,const Reference<com::sun::star::container::XNameAccess> & typeMap)2056cdf0e10cSrcweir     ::getObject( sal_Int32 columnIndex,
2057cdf0e10cSrcweir            const Reference<
2058cdf0e10cSrcweir             com::sun::star::container::XNameAccess >& typeMap )
2059cdf0e10cSrcweir     throw( SQLException,
2060cdf0e10cSrcweir            RuntimeException )
2061cdf0e10cSrcweir {
2062cdf0e10cSrcweir     //if you change this macro please pay attention to
2063cdf0e10cSrcweir     //define XROW_GETXXX, where this is similar implemented
2064cdf0e10cSrcweir 
2065cdf0e10cSrcweir     ReacquireableGuard aGuard( m_aMutex );
2066cdf0e10cSrcweir     sal_Int32 nRow = m_nRow;
2067cdf0e10cSrcweir     sal_Int32 nFetchSize = m_nFetchSize;
2068cdf0e10cSrcweir     sal_Int32 nFetchDirection = m_nFetchDirection;
2069cdf0e10cSrcweir     if( !m_aCache.hasRow( nRow ) )
2070cdf0e10cSrcweir     {
2071cdf0e10cSrcweir         if( !m_aCache.hasCausedException( nRow ) )
2072cdf0e10cSrcweir         {
2073cdf0e10cSrcweir             if( !m_xFetchProvider.is() )
2074cdf0e10cSrcweir             {
2075cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
2076cdf0e10cSrcweir                 return Any();
2077cdf0e10cSrcweir             }
2078cdf0e10cSrcweir             aGuard.clear();
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir             impl_fetchData( nRow, nFetchSize, nFetchDirection );
2081cdf0e10cSrcweir         }
2082cdf0e10cSrcweir         aGuard.reacquire();
2083cdf0e10cSrcweir         if( !m_aCache.hasRow( nRow ) )
2084cdf0e10cSrcweir         {
2085cdf0e10cSrcweir             m_bLastReadWasFromCache = sal_False;
2086cdf0e10cSrcweir             aGuard.clear();
2087cdf0e10cSrcweir             applyPositionToOrigin( nRow );
2088cdf0e10cSrcweir             impl_init_xRowOrigin();
2089cdf0e10cSrcweir             return m_xRowOrigin->getObject( columnIndex, typeMap );
2090cdf0e10cSrcweir         }
2091cdf0e10cSrcweir     }
2092cdf0e10cSrcweir     //@todo: pay attention to typeMap
2093cdf0e10cSrcweir     const Any& rValue = m_aCache.getAny( nRow, columnIndex );
2094cdf0e10cSrcweir     Any aRet;
2095cdf0e10cSrcweir     m_bLastReadWasFromCache = sal_True;
2096cdf0e10cSrcweir     m_bLastCachedReadWasNull = !( rValue >>= aRet );
2097cdf0e10cSrcweir     return aRet;
2098cdf0e10cSrcweir }
2099cdf0e10cSrcweir 
2100cdf0e10cSrcweir //virtual
2101cdf0e10cSrcweir Reference< XRef > SAL_CALL CachedContentResultSet
getRef(sal_Int32 columnIndex)2102cdf0e10cSrcweir     ::getRef( sal_Int32 columnIndex )
2103cdf0e10cSrcweir     throw( SQLException,
2104cdf0e10cSrcweir            RuntimeException )
2105cdf0e10cSrcweir {
2106cdf0e10cSrcweir     XROW_GETXXX( getRef, Reference< XRef > );
2107cdf0e10cSrcweir }
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir //virtual
2110cdf0e10cSrcweir Reference< XBlob > SAL_CALL CachedContentResultSet
getBlob(sal_Int32 columnIndex)2111cdf0e10cSrcweir     ::getBlob( sal_Int32 columnIndex )
2112cdf0e10cSrcweir     throw( SQLException,
2113cdf0e10cSrcweir            RuntimeException )
2114cdf0e10cSrcweir {
2115cdf0e10cSrcweir     XROW_GETXXX( getBlob, Reference< XBlob > );
2116cdf0e10cSrcweir }
2117cdf0e10cSrcweir 
2118cdf0e10cSrcweir //virtual
2119cdf0e10cSrcweir Reference< XClob > SAL_CALL CachedContentResultSet
getClob(sal_Int32 columnIndex)2120cdf0e10cSrcweir     ::getClob( sal_Int32 columnIndex )
2121cdf0e10cSrcweir     throw( SQLException,
2122cdf0e10cSrcweir            RuntimeException )
2123cdf0e10cSrcweir {
2124cdf0e10cSrcweir     XROW_GETXXX( getClob, Reference< XClob > );
2125cdf0e10cSrcweir }
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir //virtual
2128cdf0e10cSrcweir Reference< XArray > SAL_CALL CachedContentResultSet
getArray(sal_Int32 columnIndex)2129cdf0e10cSrcweir     ::getArray( sal_Int32 columnIndex )
2130cdf0e10cSrcweir     throw( SQLException,
2131cdf0e10cSrcweir            RuntimeException )
2132cdf0e10cSrcweir {
2133cdf0e10cSrcweir     XROW_GETXXX( getArray, Reference< XArray > );
2134cdf0e10cSrcweir }
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir //-----------------------------------------------------------------
2137cdf0e10cSrcweir // Type Converter Support
2138cdf0e10cSrcweir //-----------------------------------------------------------------
2139cdf0e10cSrcweir 
getTypeConverter()2140cdf0e10cSrcweir const Reference< XTypeConverter >& CachedContentResultSet::getTypeConverter()
2141cdf0e10cSrcweir {
2142cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
2143cdf0e10cSrcweir 
2144cdf0e10cSrcweir     if ( !m_bTriedToGetTypeConverter && !m_xTypeConverter.is() )
2145cdf0e10cSrcweir     {
2146cdf0e10cSrcweir         m_bTriedToGetTypeConverter = sal_True;
2147cdf0e10cSrcweir         m_xTypeConverter = Reference< XTypeConverter >(
2148cdf0e10cSrcweir                                 m_xSMgr->createInstance(
2149cdf0e10cSrcweir                                     OUString::createFromAscii(
2150cdf0e10cSrcweir                                         "com.sun.star.script.Converter" ) ),
2151cdf0e10cSrcweir                                 UNO_QUERY );
2152cdf0e10cSrcweir 
2153cdf0e10cSrcweir         OSL_ENSURE( m_xTypeConverter.is(),
2154cdf0e10cSrcweir                     "PropertyValueSet::getTypeConverter() - "
2155cdf0e10cSrcweir                     "Service 'com.sun.star.script.Converter' n/a!" );
2156cdf0e10cSrcweir     }
2157cdf0e10cSrcweir     return m_xTypeConverter;
2158cdf0e10cSrcweir }
2159cdf0e10cSrcweir 
2160cdf0e10cSrcweir //--------------------------------------------------------------------------
2161cdf0e10cSrcweir //--------------------------------------------------------------------------
2162cdf0e10cSrcweir // class CachedContentResultSetFactory
2163cdf0e10cSrcweir //--------------------------------------------------------------------------
2164cdf0e10cSrcweir //--------------------------------------------------------------------------
2165cdf0e10cSrcweir 
CachedContentResultSetFactory(const Reference<XMultiServiceFactory> & rSMgr)2166cdf0e10cSrcweir CachedContentResultSetFactory::CachedContentResultSetFactory(
2167cdf0e10cSrcweir         const Reference< XMultiServiceFactory > & rSMgr )
2168cdf0e10cSrcweir {
2169cdf0e10cSrcweir     m_xSMgr = rSMgr;
2170cdf0e10cSrcweir }
2171cdf0e10cSrcweir 
~CachedContentResultSetFactory()2172cdf0e10cSrcweir CachedContentResultSetFactory::~CachedContentResultSetFactory()
2173cdf0e10cSrcweir {
2174cdf0e10cSrcweir }
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir //--------------------------------------------------------------------------
2177cdf0e10cSrcweir // CachedContentResultSetFactory XInterface methods.
2178cdf0e10cSrcweir //--------------------------------------------------------------------------
2179cdf0e10cSrcweir 
2180cdf0e10cSrcweir XINTERFACE_IMPL_3( CachedContentResultSetFactory,
2181cdf0e10cSrcweir                    XTypeProvider,
2182cdf0e10cSrcweir                    XServiceInfo,
2183cdf0e10cSrcweir                    XCachedContentResultSetFactory );
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir //--------------------------------------------------------------------------
2186cdf0e10cSrcweir // CachedContentResultSetFactory XTypeProvider methods.
2187cdf0e10cSrcweir //--------------------------------------------------------------------------
2188cdf0e10cSrcweir 
2189cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( CachedContentResultSetFactory,
2190cdf0e10cSrcweir                       XTypeProvider,
2191cdf0e10cSrcweir                       XServiceInfo,
2192cdf0e10cSrcweir                       XCachedContentResultSetFactory );
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir //--------------------------------------------------------------------------
2195cdf0e10cSrcweir // CachedContentResultSetFactory XServiceInfo methods.
2196cdf0e10cSrcweir //--------------------------------------------------------------------------
2197cdf0e10cSrcweir 
2198cdf0e10cSrcweir XSERVICEINFO_IMPL_1( CachedContentResultSetFactory,
2199cdf0e10cSrcweir                      OUString::createFromAscii(
2200cdf0e10cSrcweir                         "com.sun.star.comp.ucb.CachedContentResultSetFactory" ),
2201cdf0e10cSrcweir                      OUString::createFromAscii(
2202cdf0e10cSrcweir                         CACHED_CONTENT_RESULTSET_FACTORY_NAME ) );
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir //--------------------------------------------------------------------------
2205cdf0e10cSrcweir // Service factory implementation.
2206cdf0e10cSrcweir //--------------------------------------------------------------------------
2207cdf0e10cSrcweir 
2208cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedContentResultSetFactory );
2209cdf0e10cSrcweir 
2210cdf0e10cSrcweir //--------------------------------------------------------------------------
2211cdf0e10cSrcweir // CachedContentResultSetFactory XCachedContentResultSetFactory methods.
2212cdf0e10cSrcweir //--------------------------------------------------------------------------
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir     //virtual
2215cdf0e10cSrcweir Reference< XResultSet > SAL_CALL CachedContentResultSetFactory
createCachedContentResultSet(const Reference<XResultSet> & xSource,const Reference<XContentIdentifierMapping> & xMapping)2216cdf0e10cSrcweir     ::createCachedContentResultSet(
2217cdf0e10cSrcweir             const Reference< XResultSet > & xSource,
2218cdf0e10cSrcweir             const Reference< XContentIdentifierMapping > & xMapping )
2219cdf0e10cSrcweir             throw( com::sun::star::uno::RuntimeException )
2220cdf0e10cSrcweir {
2221cdf0e10cSrcweir     Reference< XResultSet > xRet;
2222cdf0e10cSrcweir     xRet = new CachedContentResultSet( m_xSMgr, xSource, xMapping );
2223cdf0e10cSrcweir     return xRet;
2224cdf0e10cSrcweir }
2225