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