Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _CONNECTIVITY_DBASE_INDEX_HXX_
21 : #define _CONNECTIVITY_DBASE_INDEX_HXX_
22 :
23 : #include "connectivity/sdbcx/VIndex.hxx"
24 : #include <com/sun/star/lang/XUnoTunnel.hpp>
25 : #include "dbase/DTable.hxx"
26 : #include "dbase/dindexnode.hxx"
27 :
28 : #define dBASE_III_GROUP "dBase III"
29 :
30 : namespace connectivity
31 : {
32 : namespace dbase
33 : {
34 : class OIndexIterator;
35 : class ONDXKey;
36 :
37 : typedef sdbcx::OIndex ODbaseIndex_BASE;
38 : typedef file::OBoolOperator OBoolOperator_BASE;
39 : typedef file::OOperand OOperand_BASE;
40 :
41 : class ODbaseIndex : public ODbaseIndex_BASE
42 : {
43 : friend SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&);
44 : friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
45 :
46 : friend class ONDXNode;
47 : friend class ONDXPage;
48 : friend class ONDXPagePtr;
49 : friend class OIndexIterator;
50 :
51 : public:
52 :
53 : // Header struct - stays in memory
54 :
55 : struct NDXHeader
56 : {
57 : sal_uInt32 db_rootpage; /* Rootpage position */
58 : sal_uInt32 db_pagecount; /* Page count */
59 : sal_uInt8 db_frei[4]; /* Reserved */
60 : sal_uInt16 db_keylen; /* Key length */
61 : sal_uInt16 db_maxkeys; /* Maximum number of keys per page */
62 : sal_uInt16 db_keytype; /* Type of key:
63 : 0 = Text
64 : 1 = Numerical */
65 : sal_uInt16 db_keyrec; /* Length of an index record
66 : RecordNumber + keylen */
67 : sal_uInt8 db_frei1[3]; /* Reserved */
68 : sal_uInt8 db_unique; /* Unique */
69 : char db_name[488]; /* index_name (field name) */
70 : };
71 :
72 : private:
73 : SvStream* m_pFileStream; // Stream to read/write the index
74 : NDXHeader m_aHeader;
75 : ONDXPageList m_aCollector; // Pool of obsolete pages
76 : ONDXPagePtr m_aRoot, // Root of the B+ tree
77 : m_aCurLeaf; // Current leaf
78 : sal_uInt16 m_nCurNode; // Position of the current node
79 :
80 : sal_uInt32 m_nPageCount,
81 : m_nRootPage;
82 :
83 : ODbaseTable* m_pTable;
84 : sal_Bool m_bUseCollector : 1; // Use the Garbage Collector
85 :
86 : OUString getCompletePath();
87 : void closeImpl();
88 : // Closes and kills the index file and throws an error
89 : void impl_killFileAndthrowError_throw(sal_uInt16 _nErrorId,const OUString& _sFile);
90 : protected:
91 : virtual ~ODbaseIndex();
92 : public:
93 : ODbaseIndex(ODbaseTable* _pTable);
94 : ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& _Name);
95 :
96 : sal_Bool openIndexFile();
97 : virtual void refreshColumns() SAL_OVERRIDE;
98 :
99 : // com::sun::star::lang::XUnoTunnel
100 : virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
101 : static com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
102 :
103 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
104 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
105 :
106 0 : const ODbaseTable* getTable() const { return m_pTable; }
107 0 : const NDXHeader& getHeader() const { return m_aHeader; }
108 : virtual OIndexIterator* createIterator(OBoolOperator_BASE* pOp,
109 : const OOperand_BASE* pOperand = NULL);
110 :
111 0 : void SetRootPos(sal_uInt32 nPos) {m_nRootPage = nPos;}
112 0 : void SetPageCount(sal_uInt32 nCount) {m_nPageCount = nCount;}
113 :
114 : sal_uInt32 GetRootPos() {return m_nRootPage;}
115 0 : sal_uInt32 GetPageCount() {return m_nPageCount;}
116 :
117 : sal_Bool IsText() const {return m_aHeader.db_keytype == 0;}
118 0 : sal_uInt16 GetMaxNodes() const {return m_aHeader.db_maxkeys;}
119 :
120 : virtual sal_Bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue);
121 : virtual sal_Bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&);
122 : virtual sal_Bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue);
123 : virtual sal_Bool Find(sal_uInt32 nRec, const ORowSetValue& rValue);
124 :
125 : void createINFEntry();
126 : sal_Bool CreateImpl();
127 : sal_Bool DropImpl();
128 :
129 : DECLARE_SERVICE_INFO();
130 : protected:
131 :
132 : ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = NULL, sal_Bool bLoad = sal_False);
133 : void Collect(ONDXPage*);
134 : ONDXPagePtr getRoot();
135 :
136 0 : sal_Bool isUnique() const { return m_IsUnique; }
137 0 : sal_Bool UseCollector() const {return m_bUseCollector;}
138 : // Tree operations
139 : void Insert(ONDXPagePtr aCurPage, ONDXNode& rNode);
140 : void Release(sal_Bool bSave = sal_True);
141 : sal_Bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue);
142 : };
143 :
144 : SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&);
145 : SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
146 : }
147 : }
148 :
149 : #endif // _CONNECTIVITY_DBASE_INDEX_HXX_
150 :
151 :
152 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|