1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef CONNECTIVITY_SKIPDELETEDSSET_HXX
28 #define CONNECTIVITY_SKIPDELETEDSSET_HXX
29 
30 #include "TResultSetHelper.hxx"
31 #include <rtl/alloc.h>
32 #include <hash_map>
33 #include <vector>
34 #include "connectivity/dbtoolsdllapi.hxx"
35 
36 namespace connectivity
37 {
38 	/**
39 		the class OSkipDeletedSet supports a general method to skip deleted rows
40 	*/
41 	class OOO_DLLPUBLIC_DBTOOLS OSkipDeletedSet
42 	{
43 		::std::vector<sal_Int32>	            m_aBookmarksPositions;// vector of iterators to position map, the order is the logical position
44 		IResultSetHelper*						m_pHelper;			  // used for moving in the resultset
45         bool                                    m_bDeletedVisible;
46 
47 		sal_Bool	moveAbsolute(sal_Int32 _nOffset,sal_Bool _bRetrieveData);
48 	public:
49 		OSkipDeletedSet(IResultSetHelper* _pHelper);
50 		~OSkipDeletedSet();
51 
52 		inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
53 			{ return ::rtl_allocateMemory( nSize ); }
54 		inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW( () )
55 			{ return _pHint; }
56 		inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
57 			{ ::rtl_freeMemory( pMem ); }
58 		inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW( () )
59 			{  }
60 
61 		/**
62 			skipDeleted moves the resultset to the position defined by the parameters
63 			it garantees that the row isn't deleted
64 				@param
65 					IResultSetHelper::Movement	_eCursorPosition		in which direction the resultset should be moved
66 					sal_Int32					_nOffset				the position relativ to the movement
67 					sal_Bool					_bRetrieveData			is true when the current row should be filled which data
68 				@return
69 					true when the movement was successful otherwise false
70 		*/
71 		sal_Bool	skipDeleted(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData);
72 		/**
73 			clear the map and the vector used in this class
74 		*/
75 		void		clear();
76 		/**
77 			getMappedPosition returns the mapped position of a logical position
78 			@param
79 				sal_Int32 _nBookmark	the logical position
80 
81 			@return the mapped position
82 		*/
83 		sal_Int32	getMappedPosition(sal_Int32 _nBookmark) const;
84 		/**
85 			insertNewPosition adds a new position to the map
86 			@param
87 				sal_Int32 _nPos	the logical position
88 		*/
89 		void		insertNewPosition(sal_Int32 _nPos);
90 		/**
91 			deletePosition deletes this position from the map and decrement all following positions
92 			@param
93 				sal_Int32 _nPos	the logical position
94 		*/
95 		void		deletePosition(sal_Int32 _nPos);
96 		/**
97 			getLastPosition returns the last position
98 			@return the last position
99 		*/
100 		inline sal_Int32	getLastPosition() const { return m_aBookmarksPositions.size(); }
101         inline void SetDeletedVisible(bool _bDeletedVisible) { m_bDeletedVisible = _bDeletedVisible; }
102 	};
103 }
104 #endif // CONNECTIVITY_SKIPDELETEDSSET_HXX
105 
106