1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
) +
39 if ( !UCBContentHelper::Exists(sFile
) )
41 const OUString
sError( m_pTable
->getConnection()->getResources().getResourceStringWithSubstitution(
42 STR_COULD_NOT_LOAD_FILE
,
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
);
52 pFileStream
->SetEndian(SvStreamEndian::LITTLE
);
53 pFileStream
->SetBufferSize(DINDEX_PAGE_SIZE
);
54 ODbaseIndex::NDXHeader aHeader
;
57 ReadHeader(*pFileStream
, aHeader
);
60 rtl::Reference
<ODbaseIndex
> pIndex
= new ODbaseIndex(m_pTable
,aHeader
,_rName
);
62 pIndex
->openIndexFile();
66 const OUString
sError( m_pTable
->getConnection()->getResources().getResourceStringWithSubstitution(
67 STR_COULD_NOT_LOAD_FILE
,
70 ::dbtools::throwGenericSQLException( sError
, *m_pTable
);
75 void ODbaseIndexes::impl_refresh( )
78 m_pTable
->refreshIndexes();
81 Reference
< XPropertySet
> ODbaseIndexes::createDescriptor()
83 return new ODbaseIndex(m_pTable
);
87 sdbcx::ObjectType
ODbaseIndexes::appendObject( const OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
89 ODbaseIndex
* pIndex
= dynamic_cast<ODbaseIndex
*>(descriptor
.get());
93 return createObject( _rForName
);
97 void ODbaseIndexes::dropObject(sal_Int32 _nPos
, const OUString
& /*_sElementName*/)
99 rtl::Reference
<ODbaseIndex
> pIndex
= dynamic_cast<ODbaseIndex
*>(getObject(_nPos
).get());
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */