LibreOffice Module connectivity (master) 1
DIndex.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sdbcx/VIndex.hxx>
23#include <dbase/DTable.hxx>
24#include <dbase/dindexnode.hxx>
25
26inline constexpr OStringLiteral dBASE_III_GROUP = "dBase III";
27
28namespace connectivity::dbase
29 {
30 class OIndexIterator;
31 class ONDXKey;
32
34
36 {
37 friend SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&);
39
40 friend class ONDXNode;
41 friend class ONDXPage;
42 friend class ONDXPagePtr;
43 friend class OIndexIterator;
44
45 public:
46
47 // Header struct - stays in memory
48
49 struct NDXHeader
50 {
51 sal_uInt32 db_rootpage; /* Rootpage position */
52 sal_uInt32 db_pagecount; /* Page count */
53 sal_uInt8 db_free[4]; /* Reserved */
54 sal_uInt16 db_keylen; /* Key length */
55 sal_uInt16 db_maxkeys; /* Maximum number of keys per page */
56 sal_uInt16 db_keytype; /* Type of key:
57 0 = Text
58 1 = Numerical */
59 sal_uInt16 db_keyrec; /* Length of an index record
60 RecordNumber + keylen */
61 sal_uInt8 db_free1[3]; /* Reserved */
62 sal_uInt8 db_unique; /* Unique */
63 char db_name[488]; /* index_name (field name) */
64 };
65
66 private:
67 std::unique_ptr<SvStream> m_pFileStream; // Stream to read/write the index
69 std::vector<ONDXPage*>
70 m_aCollector; // Pool of obsolete pages
71 ONDXPagePtr m_aRoot, // Root of the B+ tree
72 m_aCurLeaf; // Current leaf
73 sal_uInt16 m_nCurNode; // Position of the current node
74
75 sal_uInt32 m_nPageCount,
77
79 bool m_bUseCollector : 1; // Use the Garbage Collector
80
81 OUString getCompletePath() const;
82 void closeImpl();
83 // Closes and kills the index file and throws an error
84 void impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile);
85 protected:
86 virtual ~ODbaseIndex() override;
87 public:
88 ODbaseIndex(ODbaseTable* _pTable);
89 ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& Name);
90
91 void openIndexFile();
92 virtual void refreshColumns() override;
93
94 const ODbaseTable* getTable() const { return m_pTable; }
95 const NDXHeader& getHeader() const { return m_aHeader; }
96 std::unique_ptr<OIndexIterator> createIterator();
97
98 void SetRootPos(sal_uInt32 nPos) {m_nRootPage = nPos;}
99 void SetPageCount(sal_uInt32 nCount) {m_nPageCount = nCount;}
100
101 sal_uInt32 GetPageCount() const {return m_nPageCount;}
102
103 sal_uInt16 GetMaxNodes() const {return m_aHeader.db_maxkeys;}
104
105 bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue);
106 bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&);
107 bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue);
108 bool Find(sal_uInt32 nRec, const ORowSetValue& rValue);
109
110 void createINFEntry();
111 void CreateImpl();
112 void DropImpl();
113
115 protected:
116
117 ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = nullptr, bool bLoad = false);
118 void Collect(ONDXPage*);
119 ONDXPagePtr const & getRoot();
120
121 bool isUnique() const { return m_IsUnique; }
122 bool UseCollector() const {return m_bUseCollector;}
123 // Tree operations
124 void Release(bool bSave = true);
125 bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue);
126 };
127
128 SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&);
129 SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
130
131 void ReadHeader(SvStream & rStream, ODbaseIndex::NDXHeader & rHeader);
132}
133
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OStringLiteral dBASE_III_GROUP
Definition: DIndex.hxx:26
bool Insert(sal_uInt32 nRec, const ORowSetValue &rValue)
Definition: DIndex.cxx:187
bool Update(sal_uInt32 nRec, const ORowSetValue &, const ORowSetValue &)
Definition: DIndex.cxx:211
void SetPageCount(sal_uInt32 nCount)
Definition: DIndex.hxx:99
ODbaseIndex(ODbaseTable *_pTable)
Definition: DIndex.cxx:54
std::vector< ONDXPage * > m_aCollector
Definition: DIndex.hxx:70
virtual void refreshColumns() override
Definition: DIndex.cxx:84
void SetRootPos(sal_uInt32 nPos)
Definition: DIndex.hxx:98
OUString getCompletePath() const
Definition: DIndex.cxx:361
ONDXPagePtr const & getRoot()
Definition: DIndex.cxx:102
bool Find(sal_uInt32 nRec, const ORowSetValue &rValue)
Definition: DIndex.cxx:176
std::unique_ptr< OIndexIterator > createIterator()
Definition: DIndex.cxx:142
bool Delete(sal_uInt32 nRec, const ORowSetValue &rValue)
Definition: DIndex.cxx:224
bool ConvertToKey(ONDXKey *rKey, sal_uInt32 nRec, const ORowSetValue &rValue)
Definition: DIndex.cxx:148
const NDXHeader & getHeader() const
Definition: DIndex.hxx:95
void Release(bool bSave=true)
Definition: DIndex.cxx:251
ONDXPage * CreatePage(sal_uInt32 nPagePos, ONDXPage *pParent=nullptr, bool bLoad=false)
Definition: DIndex.cxx:293
const ODbaseTable * getTable() const
Definition: DIndex.hxx:94
virtual ~ODbaseIndex() override
Definition: DIndex.cxx:79
friend SvStream & operator>>(SvStream &rStream, ODbaseIndex &)
sal_uInt32 GetPageCount() const
Definition: DIndex.hxx:101
std::unique_ptr< SvStream > m_pFileStream
Definition: DIndex.hxx:67
void impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString &_sFile)
Definition: DIndex.cxx:446
friend SvStream & WriteODbaseIndex(SvStream &rStream, const ODbaseIndex &)
sal_uInt16 GetMaxNodes() const
Definition: DIndex.hxx:103
int nCount
sal_uInt16 nPos
void ReadHeader(SvStream &rStream, ODbaseIndex::NDXHeader &rHeader)
Definition: DIndex.cxx:314
sdbcx::OIndex ODbaseIndex_BASE
Definition: DIndex.hxx:31
SvStream & operator>>(SvStream &rStream, ODbaseIndex &)
Definition: DIndex.cxx:333
SvStream & WriteODbaseIndex(SvStream &rStream, const ODbaseIndex &)
Definition: DIndex.cxx:343
unsigned char sal_uInt8