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