xref: /trunk/main/connectivity/source/inc/TSkipDeletedSet.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1caf5cd79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3caf5cd79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4caf5cd79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5caf5cd79SAndrew Rist  * distributed with this work for additional information
6caf5cd79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7caf5cd79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8caf5cd79SAndrew Rist  * "License"); you may not use this file except in compliance
9caf5cd79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11caf5cd79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13caf5cd79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14caf5cd79SAndrew Rist  * software distributed under the License is distributed on an
15caf5cd79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16caf5cd79SAndrew Rist  * KIND, either express or implied.  See the License for the
17caf5cd79SAndrew Rist  * specific language governing permissions and limitations
18caf5cd79SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20caf5cd79SAndrew Rist  *************************************************************/
21caf5cd79SAndrew Rist 
22caf5cd79SAndrew Rist 
23cdf0e10cSrcweir #ifndef CONNECTIVITY_SKIPDELETEDSSET_HXX
24cdf0e10cSrcweir #define CONNECTIVITY_SKIPDELETEDSSET_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "TResultSetHelper.hxx"
27cdf0e10cSrcweir #include <rtl/alloc.h>
28cdf0e10cSrcweir #include <hash_map>
29cdf0e10cSrcweir #include <vector>
30cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace connectivity
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     /**
35cdf0e10cSrcweir         the class OSkipDeletedSet supports a general method to skip deleted rows
36cdf0e10cSrcweir     */
37cdf0e10cSrcweir     class OOO_DLLPUBLIC_DBTOOLS OSkipDeletedSet
38cdf0e10cSrcweir     {
39cdf0e10cSrcweir         ::std::vector<sal_Int32>                m_aBookmarksPositions;// vector of iterators to position map, the order is the logical position
40cdf0e10cSrcweir         IResultSetHelper*                       m_pHelper;            // used for moving in the resultset
41cdf0e10cSrcweir         bool                                    m_bDeletedVisible;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir         sal_Bool    moveAbsolute(sal_Int32 _nOffset,sal_Bool _bRetrieveData);
44cdf0e10cSrcweir     public:
45cdf0e10cSrcweir         OSkipDeletedSet(IResultSetHelper* _pHelper);
46cdf0e10cSrcweir         ~OSkipDeletedSet();
47cdf0e10cSrcweir 
operator new(size_t nSize)48cdf0e10cSrcweir         inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
49cdf0e10cSrcweir             { return ::rtl_allocateMemory( nSize ); }
operator new(size_t,void * _pHint)50cdf0e10cSrcweir         inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW( () )
51cdf0e10cSrcweir             { return _pHint; }
operator delete(void * pMem)52cdf0e10cSrcweir         inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
53cdf0e10cSrcweir             { ::rtl_freeMemory( pMem ); }
operator delete(void *,void *)54cdf0e10cSrcweir         inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW( () )
55cdf0e10cSrcweir             {  }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         /**
58cdf0e10cSrcweir             skipDeleted moves the resultset to the position defined by the parameters
59*07a3d7f1SPedro Giffuni             it guarantees that the row isn't deleted
60cdf0e10cSrcweir                 @param
61cdf0e10cSrcweir                     IResultSetHelper::Movement  _eCursorPosition        in which direction the resultset should be moved
62cdf0e10cSrcweir                     sal_Int32                   _nOffset                the position relativ to the movement
63cdf0e10cSrcweir                     sal_Bool                    _bRetrieveData          is true when the current row should be filled which data
64cdf0e10cSrcweir                 @return
65cdf0e10cSrcweir                     true when the movement was successful otherwise false
66cdf0e10cSrcweir         */
67cdf0e10cSrcweir         sal_Bool    skipDeleted(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData);
68cdf0e10cSrcweir         /**
69cdf0e10cSrcweir             clear the map and the vector used in this class
70cdf0e10cSrcweir         */
71cdf0e10cSrcweir         void        clear();
72cdf0e10cSrcweir         /**
73cdf0e10cSrcweir             getMappedPosition returns the mapped position of a logical position
74cdf0e10cSrcweir             @param
75cdf0e10cSrcweir                 sal_Int32 _nBookmark    the logical position
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             @return the mapped position
78cdf0e10cSrcweir         */
79cdf0e10cSrcweir         sal_Int32   getMappedPosition(sal_Int32 _nBookmark) const;
80cdf0e10cSrcweir         /**
81cdf0e10cSrcweir             insertNewPosition adds a new position to the map
82cdf0e10cSrcweir             @param
83cdf0e10cSrcweir                 sal_Int32 _nPos the logical position
84cdf0e10cSrcweir         */
85cdf0e10cSrcweir         void        insertNewPosition(sal_Int32 _nPos);
86cdf0e10cSrcweir         /**
87cdf0e10cSrcweir             deletePosition deletes this position from the map and decrement all following positions
88cdf0e10cSrcweir             @param
89cdf0e10cSrcweir                 sal_Int32 _nPos the logical position
90cdf0e10cSrcweir         */
91cdf0e10cSrcweir         void        deletePosition(sal_Int32 _nPos);
92cdf0e10cSrcweir         /**
93cdf0e10cSrcweir             getLastPosition returns the last position
94cdf0e10cSrcweir             @return the last position
95cdf0e10cSrcweir         */
getLastPosition() const96cdf0e10cSrcweir         inline sal_Int32    getLastPosition() const { return m_aBookmarksPositions.size(); }
SetDeletedVisible(bool _bDeletedVisible)97cdf0e10cSrcweir         inline void SetDeletedVisible(bool _bDeletedVisible) { m_bDeletedVisible = _bDeletedVisible; }
98cdf0e10cSrcweir     };
99cdf0e10cSrcweir }
100cdf0e10cSrcweir #endif // CONNECTIVITY_SKIPDELETEDSSET_HXX
101