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