bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / dbase / DIndexes.cxx
blob2a4cf72fb49668c741ca68678a9fe075c67853d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <dbase/DIndexes.hxx>
21 #include <dbase/DIndex.hxx>
22 #include <comphelper/servicehelper.hxx>
23 #include <connectivity/dbexception.hxx>
24 #include <unotools/ucbhelper.hxx>
25 #include <strings.hrc>
27 using namespace ::comphelper;
29 using namespace utl;
30 using namespace ::connectivity;
31 using namespace ::dbtools;
32 using namespace ::connectivity::dbase;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::sdbc;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::lang;
40 sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName)
42 OUString sFile = m_pTable->getConnection()->getURL() +
43 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER) +
44 _rName + ".ndx";
45 if ( !UCBContentHelper::Exists(sFile) )
47 const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
48 STR_COULD_NOT_LOAD_FILE,
49 "$filename$", sFile
50 ) );
51 ::dbtools::throwGenericSQLException( sError, *m_pTable );
54 sdbcx::ObjectType xRet;
55 std::unique_ptr<SvStream> pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE);
56 if(pFileStream)
58 pFileStream->SetEndian(SvStreamEndian::LITTLE);
59 pFileStream->SetBufferSize(DINDEX_PAGE_SIZE);
60 ODbaseIndex::NDXHeader aHeader;
62 pFileStream->Seek(0);
63 ReadHeader(*pFileStream, aHeader);
64 pFileStream.reset();
66 rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
67 xRet = pIndex;
68 pIndex->openIndexFile();
70 else
72 const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
73 STR_COULD_NOT_LOAD_FILE,
74 "$filename$", sFile
75 ) );
76 ::dbtools::throwGenericSQLException( sError, *m_pTable );
78 return xRet;
81 void ODbaseIndexes::impl_refresh( )
83 if(m_pTable)
84 m_pTable->refreshIndexes();
87 Reference< XPropertySet > ODbaseIndexes::createDescriptor()
89 return new ODbaseIndex(m_pTable);
92 // XAppend
93 sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
95 Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY);
96 if(xTunnel.is())
98 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) );
99 if(!pIndex)
100 throw SQLException();
101 pIndex->CreateImpl();
104 return createObject( _rForName );
107 // XDrop
108 void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
110 auto pIndex = comphelper::getUnoTunnelImplementation<ODbaseIndex>(getObject(_nPos));
111 if ( pIndex )
112 pIndex->DropImpl();
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */