Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/connectivity/source/drivers/dbase/DIndexes.cxx
Line
Count
Source
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
#include <dbase/DIndexes.hxx>
21
#include <dbase/DIndex.hxx>
22
#include <connectivity/dbexception.hxx>
23
#include <unotools/ucbhelper.hxx>
24
#include <strings.hrc>
25
26
using namespace utl;
27
using namespace ::connectivity;
28
using namespace ::dbtools;
29
using namespace ::connectivity::dbase;
30
using namespace ::com::sun::star::uno;
31
using namespace ::com::sun::star::beans;
32
33
css::uno::Reference< css::beans::XPropertySet > ODbaseIndexes::createObject(const OUString& _rName)
34
0
{
35
0
    OUString sFile = m_pTable->getConnection()->getURL() +
36
0
        OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER) +
37
0
        _rName + ".ndx";
38
0
    if ( !UCBContentHelper::Exists(sFile) )
39
0
    {
40
0
        const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
41
0
                STR_COULD_NOT_LOAD_FILE,
42
0
                "$filename$", sFile
43
0
            ) );
44
0
        ::dbtools::throwGenericSQLException( sError, *m_pTable );
45
0
    }
46
47
0
    std::unique_ptr<SvStream> pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE);
48
0
    if(!pFileStream)
49
0
    {
50
0
        const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
51
0
                STR_COULD_NOT_LOAD_FILE,
52
0
                "$filename$", sFile
53
0
             ) );
54
0
        ::dbtools::throwGenericSQLException( sError, *m_pTable );
55
0
    }
56
57
0
    pFileStream->SetEndian(SvStreamEndian::LITTLE);
58
0
    pFileStream->SetBufferSize(DINDEX_PAGE_SIZE);
59
0
    ODbaseIndex::NDXHeader aHeader;
60
61
0
    pFileStream->Seek(0);
62
0
    ReadHeader(*pFileStream, aHeader);
63
0
    pFileStream.reset();
64
65
0
    rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
66
0
    pIndex->openIndexFile();
67
0
    return pIndex;
68
0
}
69
70
void ODbaseIndexes::impl_refresh(  )
71
0
{
72
0
    if(m_pTable)
73
0
        m_pTable->refreshIndexes();
74
0
}
75
76
Reference< XPropertySet > ODbaseIndexes::createDescriptor()
77
0
{
78
0
    return new ODbaseIndex(m_pTable);
79
0
}
80
81
// XAppend
82
css::uno::Reference< css::beans::XPropertySet > ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
83
0
{
84
0
    ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(descriptor.get());
85
0
    if(pIndex)
86
0
        pIndex->CreateImpl();
87
88
0
    return createObject( _rForName );
89
0
}
90
91
// XDrop
92
void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
93
0
{
94
0
    rtl::Reference<ODbaseIndex> pIndex = dynamic_cast<ODbaseIndex*>(getObject(_nPos).get());
95
0
    if ( pIndex )
96
0
        pIndex->DropImpl();
97
0
}
98
99
100
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */