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