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 <comphelper/servicehelper.hxx>
23 #include <connectivity/dbexception.hxx>
24 #include <unotools/ucbhelper.hxx>
25 #include <strings.hrc>
26 
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;
33 
createObject(const OUString & _rName)34 sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName)
35 {
36     OUString sFile = m_pTable->getConnection()->getURL() +
37         OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER) +
38         _rName + ".ndx";
39     if ( !UCBContentHelper::Exists(sFile) )
40     {
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 );
46     }
47 
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)
51     {
52         pFileStream->SetEndian(SvStreamEndian::LITTLE);
53         pFileStream->SetBufferSize(DINDEX_PAGE_SIZE);
54         ODbaseIndex::NDXHeader aHeader;
55 
56         pFileStream->Seek(0);
57         ReadHeader(*pFileStream, aHeader);
58         pFileStream.reset();
59 
60         rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
61         xRet = pIndex;
62         pIndex->openIndexFile();
63     }
64     else
65     {
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 );
71     }
72     return xRet;
73 }
74 
impl_refresh()75 void ODbaseIndexes::impl_refresh(  )
76 {
77     if(m_pTable)
78         m_pTable->refreshIndexes();
79 }
80 
createDescriptor()81 Reference< XPropertySet > ODbaseIndexes::createDescriptor()
82 {
83     return new ODbaseIndex(m_pTable);
84 }
85 
86 // XAppend
appendObject(const OUString & _rForName,const Reference<XPropertySet> & descriptor)87 sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
88 {
89     ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(descriptor.get());
90     if(pIndex)
91         pIndex->CreateImpl();
92 
93     return createObject( _rForName );
94 }
95 
96 // XDrop
dropObject(sal_Int32 _nPos,const OUString &)97 void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
98 {
99     rtl::Reference<ODbaseIndex> pIndex = dynamic_cast<ODbaseIndex*>(getObject(_nPos).get());
100     if ( pIndex )
101         pIndex->DropImpl();
102 }
103 
104 
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
106