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