xref: /AOO41X/main/connectivity/source/inc/dbase/DIndex.hxx (revision caf5cd79edad04a48dcaf209068b3b89eae4622e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CONNECTIVITY_DBASE_INDEX_HXX_
25 #define _CONNECTIVITY_DBASE_INDEX_HXX_
26 
27 #include "connectivity/sdbcx/VIndex.hxx"
28 #include <com/sun/star/lang/XUnoTunnel.hpp>
29 #include "dbase/DTable.hxx"
30 #include "dbase/dindexnode.hxx"
31 
32 #define dBASE_III_GROUP "dBase III"
33 
34 namespace connectivity
35 {
36     namespace dbase
37     {
38         class OIndexIterator;
39         class ONDXKey;
40 
41         typedef sdbcx::OIndex ODbaseIndex_BASE;
42         typedef file::OBoolOperator OBoolOperator_BASE;
43         typedef file::OOperand OOperand_BASE;
44 
45         class ODbaseIndex : public ODbaseIndex_BASE
46         {
47             friend SvStream& operator << (SvStream &rStream, ODbaseIndex&);
48             friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
49 
50             friend class ONDXNode;
51             friend class ONDXPage;
52             friend class ONDXPagePtr;
53             friend class OIndexIterator;
54 
55         public:
56             //==================================================================
57             // Kopfsatz-Struktur, verbleibt im Speicher
58             //==================================================================
59             struct NDXHeader
60             {
61                 sal_uInt32  db_rootpage;                    /* Position der Rootpage        */
62                 sal_uInt32  db_pagecount;                   /* Anzahl Pages                 */
63                 sal_uInt8   db_frei[4];                     /* reserviert                   */
64                 sal_uInt16  db_keylen;                      /* Laenge des Schluessels       */
65                 sal_uInt16  db_maxkeys;                     /* Max. # keys pro Seite        */
66                 sal_uInt16  db_keytype;                     /* Art des Schluessels
67                                                            (0-Text)
68                                                            (1-Numerisch)                */
69                 sal_uInt16  db_keyrec;                      /* Laenge eines IndexSatzes
70                                                            SatzNr + keylen              */
71                 sal_uInt8   db_frei1[3];                    /* reserviert                   */
72                 sal_uInt8   db_unique;                      /* eindeutig                    */
73                 char        db_name[488];                   /* index_name   (Feldname)      */
74             };
75 
76         private:
77             SvStream*       m_pFileStream;                  // Stream zum Lesen/Schreiben des Index
78             NDXHeader       m_aHeader;
79             ONDXPageList    m_aCollector;                   // Pool von nicht mehr benoetigten Seiten
80             ONDXPagePtr     m_aRoot,                        // Wurzel des b+ Baums
81                             m_aCurLeaf;                 // aktuelles Blatt
82             sal_uInt16          m_nCurNode;                 // Position des aktuellen Knoten
83 
84             sal_uInt32          m_nPageCount,
85                             m_nRootPage;
86 
87             ODbaseTable*    m_pTable;
88             sal_Bool            m_bUseCollector : 1;                        // Verwenden des GarbageCollectors
89 
90             ::rtl::OUString getCompletePath();
91             void closeImpl();
92             /* closes and kill the index file and throws an error.
93             */
94             void impl_killFileAndthrowError_throw(sal_uInt16 _nErrorId,const ::rtl::OUString& _sFile);
95         protected:
96             virtual ~ODbaseIndex();
97         public:
98             ODbaseIndex(ODbaseTable* _pTable);
99             ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const ::rtl::OUString& _Name);
100 
101             sal_Bool openIndexFile();
102             virtual void refreshColumns();
103 
104             // com::sun::star::lang::XUnoTunnel
105             virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(com::sun::star::uno::RuntimeException);
106             static com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
107 
108             virtual void SAL_CALL acquire() throw();
109             virtual void SAL_CALL release() throw();
110 
getTable() const111             const ODbaseTable* getTable() const { return m_pTable; }
getHeader() const112             const NDXHeader& getHeader() const { return m_aHeader; }
113             virtual OIndexIterator* createIterator(OBoolOperator_BASE* pOp,
114                                                          const OOperand_BASE* pOperand = NULL);
115 
SetRootPos(sal_uInt32 nPos)116             void SetRootPos(sal_uInt32 nPos)        {m_nRootPage = nPos;}
SetPageCount(sal_uInt32 nCount)117             void SetPageCount(sal_uInt32 nCount)    {m_nPageCount = nCount;}
118 
GetRootPos()119             sal_uInt32 GetRootPos()                 {return m_nRootPage;}
GetPageCount()120             sal_uInt32 GetPageCount()               {return m_nPageCount;}
121 
IsText() const122             sal_Bool IsText() const                 {return m_aHeader.db_keytype == 0;}
GetMaxNodes() const123             sal_uInt16 GetMaxNodes() const          {return m_aHeader.db_maxkeys;}
124 
125             virtual sal_Bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue);
126             virtual sal_Bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&);
127             virtual sal_Bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue);
128             virtual sal_Bool Find(sal_uInt32 nRec, const ORowSetValue& rValue);
129 
130             void createINFEntry();
131             sal_Bool CreateImpl();
132             sal_Bool DropImpl();
133 
134             DECLARE_SERVICE_INFO();
135         protected:
136 
137             ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = NULL, sal_Bool bLoad = sal_False);
138             void Collect(ONDXPage*);
139             ONDXPagePtr getRoot();
140 
isUnique() const141             sal_Bool isUnique() const { return m_IsUnique; }
UseCollector() const142             sal_Bool UseCollector() const {return m_bUseCollector;}
143             // Tree operationen
144             void Insert(ONDXPagePtr aCurPage, ONDXNode& rNode);
145             void Release(sal_Bool bSave = sal_True);
146             sal_Bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue);
147         };
148 
149         SvStream& operator << (SvStream &rStream, ODbaseIndex&);
150         SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
151     }
152 }
153 
154 #endif // _CONNECTIVITY_DBASE_INDEX_HXX_
155 
156 
157