Use correct object
[LibreOffice.git] / connectivity / source / drivers / dbase / DIndexes.cxx
blobdf630c531c3e8e9d26f1060e735a312887e5e7b4
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 utl;
28 using namespace ::connectivity;
29 using namespace ::dbtools;
30 using namespace ::connectivity::dbase;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
34 sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName)
36 OUString sFile = m_pTable->getConnection()->getURL() +
37 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER) +
38 _rName + ".ndx";
39 if ( !UCBContentHelper::Exists(sFile) )
41 const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
42 STR_COULD_NOT_LOAD_FILE,
43 "$filename$", sFile
44 ) );
45 ::dbtools::throwGenericSQLException( sError, *m_pTable );
48 sdbcx::ObjectType xRet;
49 std::unique_ptr<SvStream> pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE);
50 if(pFileStream)
52 pFileStream->SetEndian(SvStreamEndian::LITTLE);
53 pFileStream->SetBufferSize(DINDEX_PAGE_SIZE);
54 ODbaseIndex::NDXHeader aHeader;
56 pFileStream->Seek(0);
57 ReadHeader(*pFileStream, aHeader);
58 pFileStream.reset();
60 rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
61 xRet = pIndex;
62 pIndex->openIndexFile();
64 else
66 const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
67 STR_COULD_NOT_LOAD_FILE,
68 "$filename$", sFile
69 ) );
70 ::dbtools::throwGenericSQLException( sError, *m_pTable );
72 return xRet;
75 void ODbaseIndexes::impl_refresh( )
77 if(m_pTable)
78 m_pTable->refreshIndexes();
81 Reference< XPropertySet > ODbaseIndexes::createDescriptor()
83 return new ODbaseIndex(m_pTable);
86 // XAppend
87 sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
89 ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(descriptor.get());
90 if(pIndex)
91 pIndex->CreateImpl();
93 return createObject( _rForName );
96 // XDrop
97 void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
99 rtl::Reference<ODbaseIndex> pIndex = dynamic_cast<ODbaseIndex*>(getObject(_nPos).get());
100 if ( pIndex )
101 pIndex->DropImpl();
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */