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 
28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBASE_INDEX_HXX_
29*cdf0e10cSrcweir #define _CONNECTIVITY_DBASE_INDEX_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "connectivity/sdbcx/VIndex.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
33*cdf0e10cSrcweir #include "dbase/DTable.hxx"
34*cdf0e10cSrcweir #include "dbase/dindexnode.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #define dBASE_III_GROUP "dBase III"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace connectivity
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir 	namespace dbase
41*cdf0e10cSrcweir 	{
42*cdf0e10cSrcweir 		class OIndexIterator;
43*cdf0e10cSrcweir 		class ONDXKey;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 		typedef sdbcx::OIndex ODbaseIndex_BASE;
46*cdf0e10cSrcweir 		typedef file::OBoolOperator OBoolOperator_BASE;
47*cdf0e10cSrcweir 		typedef file::OOperand OOperand_BASE;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 		class ODbaseIndex :	public ODbaseIndex_BASE
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 			friend SvStream& operator << (SvStream &rStream, ODbaseIndex&);
52*cdf0e10cSrcweir 			friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 			friend class ONDXNode;
55*cdf0e10cSrcweir 			friend class ONDXPage;
56*cdf0e10cSrcweir 			friend class ONDXPagePtr;
57*cdf0e10cSrcweir 			friend class OIndexIterator;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 		public:
60*cdf0e10cSrcweir 			//==================================================================
61*cdf0e10cSrcweir 			// Kopfsatz-Struktur, verbleibt im Speicher
62*cdf0e10cSrcweir 			//==================================================================
63*cdf0e10cSrcweir 			struct NDXHeader
64*cdf0e10cSrcweir 			{
65*cdf0e10cSrcweir 				sal_uInt32  db_rootpage;                    /* Position der Rootpage		*/
66*cdf0e10cSrcweir 				sal_uInt32  db_pagecount;                   /* Anzahl Pages					*/
67*cdf0e10cSrcweir 				sal_uInt8	db_frei[4];						/* reserviert					*/
68*cdf0e10cSrcweir 				sal_uInt16  db_keylen;						/* Laenge des Schluessels	    */
69*cdf0e10cSrcweir 				sal_uInt16  db_maxkeys;						/* Max. # keys pro Seite	    */
70*cdf0e10cSrcweir 				sal_uInt16  db_keytype;                     /* Art des Schluessels
71*cdf0e10cSrcweir 														   (0-Text)
72*cdf0e10cSrcweir 														   (1-Numerisch)				*/
73*cdf0e10cSrcweir 				sal_uInt16  db_keyrec;                      /* Laenge eines IndexSatzes
74*cdf0e10cSrcweir 														   SatzNr + keylen				*/
75*cdf0e10cSrcweir 				sal_uInt8	db_frei1[3];					/* reserviert					*/
76*cdf0e10cSrcweir 				sal_uInt8	db_unique;						/* eindeutig					*/
77*cdf0e10cSrcweir 				char		db_name[488];                   /* index_name	(Feldname)		*/
78*cdf0e10cSrcweir 			};
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 		private:
81*cdf0e10cSrcweir 			SvStream*		m_pFileStream;					// Stream zum Lesen/Schreiben des Index
82*cdf0e10cSrcweir 			NDXHeader		m_aHeader;
83*cdf0e10cSrcweir             ONDXPageList    m_aCollector;                   // Pool von nicht mehr benoetigten Seiten
84*cdf0e10cSrcweir 			ONDXPagePtr		m_aRoot,						// Wurzel des b+ Baums
85*cdf0e10cSrcweir 							m_aCurLeaf;					// aktuelles Blatt
86*cdf0e10cSrcweir 			sal_uInt16			m_nCurNode;					// Position des aktuellen Knoten
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 			sal_uInt32			m_nPageCount,
89*cdf0e10cSrcweir 							m_nRootPage;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 			ODbaseTable*	m_pTable;
92*cdf0e10cSrcweir 			sal_Bool			m_bUseCollector : 1;						// Verwenden des GarbageCollectors
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 			::rtl::OUString getCompletePath();
95*cdf0e10cSrcweir 			void closeImpl();
96*cdf0e10cSrcweir             /* closes and kill the index file and throws an error.
97*cdf0e10cSrcweir             */
98*cdf0e10cSrcweir             void impl_killFileAndthrowError_throw(sal_uInt16 _nErrorId,const ::rtl::OUString& _sFile);
99*cdf0e10cSrcweir 		protected:
100*cdf0e10cSrcweir 			virtual ~ODbaseIndex();
101*cdf0e10cSrcweir 		public:
102*cdf0e10cSrcweir 			ODbaseIndex(ODbaseTable* _pTable);
103*cdf0e10cSrcweir 			ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const ::rtl::OUString& _Name);
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 			sal_Bool openIndexFile();
106*cdf0e10cSrcweir 			virtual void refreshColumns();
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 			// com::sun::star::lang::XUnoTunnel
109*cdf0e10cSrcweir 			virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(com::sun::star::uno::RuntimeException);
110*cdf0e10cSrcweir 			static com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 			virtual void SAL_CALL acquire() throw();
113*cdf0e10cSrcweir             virtual void SAL_CALL release() throw();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 			const ODbaseTable* getTable() const { return m_pTable; }
116*cdf0e10cSrcweir 			const NDXHeader& getHeader() const { return m_aHeader; }
117*cdf0e10cSrcweir 			virtual OIndexIterator* createIterator(OBoolOperator_BASE* pOp,
118*cdf0e10cSrcweir 														 const OOperand_BASE* pOperand = NULL);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 			void SetRootPos(sal_uInt32 nPos)		{m_nRootPage = nPos;}
121*cdf0e10cSrcweir 			void SetPageCount(sal_uInt32 nCount)	{m_nPageCount = nCount;}
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 			sal_uInt32 GetRootPos()					{return m_nRootPage;}
124*cdf0e10cSrcweir 			sal_uInt32 GetPageCount()				{return m_nPageCount;}
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 			sal_Bool IsText() const					{return m_aHeader.db_keytype == 0;}
127*cdf0e10cSrcweir 			sal_uInt16 GetMaxNodes() const			{return m_aHeader.db_maxkeys;}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 			virtual sal_Bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue);
130*cdf0e10cSrcweir 			virtual sal_Bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&);
131*cdf0e10cSrcweir 			virtual sal_Bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue);
132*cdf0e10cSrcweir 			virtual sal_Bool Find(sal_uInt32 nRec, const ORowSetValue& rValue);
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 			void createINFEntry();
135*cdf0e10cSrcweir 			sal_Bool CreateImpl();
136*cdf0e10cSrcweir 			sal_Bool DropImpl();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
139*cdf0e10cSrcweir 		protected:
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 			ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = NULL, sal_Bool bLoad = sal_False);
142*cdf0e10cSrcweir 			void Collect(ONDXPage*);
143*cdf0e10cSrcweir 			ONDXPagePtr getRoot();
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 			sal_Bool isUnique() const { return m_IsUnique; }
146*cdf0e10cSrcweir 			sal_Bool UseCollector() const {return m_bUseCollector;}
147*cdf0e10cSrcweir 			// Tree operationen
148*cdf0e10cSrcweir 			void Insert(ONDXPagePtr aCurPage, ONDXNode& rNode);
149*cdf0e10cSrcweir 			void Release(sal_Bool bSave = sal_True);
150*cdf0e10cSrcweir 			sal_Bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue);
151*cdf0e10cSrcweir 		};
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 		SvStream& operator << (SvStream &rStream, ODbaseIndex&);
154*cdf0e10cSrcweir 		SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
155*cdf0e10cSrcweir 	}
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir #endif // _CONNECTIVITY_DBASE_INDEX_HXX_
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 
161