LibreOffice Module connectivity (master) 1
DIndexes.cxx
Go to the documentation of this file.
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>
25#include <strings.hrc>
26
27using namespace ::comphelper;
28
29using namespace utl;
30using namespace ::connectivity;
31using namespace ::dbtools;
32using namespace ::connectivity::dbase;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::beans;
35using namespace ::com::sun::star::sdbcx;
36using namespace ::com::sun::star::sdbc;
37using namespace ::com::sun::star::container;
38using namespace ::com::sun::star::lang;
39
40sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName)
41{
42 OUString sFile = m_pTable->getConnection()->getURL() +
43 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER) +
44 _rName + ".ndx";
45 if ( !UCBContentHelper::Exists(sFile) )
46 {
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 );
52 }
53
55 std::unique_ptr<SvStream> pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE);
56 if(pFileStream)
57 {
58 pFileStream->SetEndian(SvStreamEndian::LITTLE);
59 pFileStream->SetBufferSize(DINDEX_PAGE_SIZE);
61
62 pFileStream->Seek(0);
63 ReadHeader(*pFileStream, aHeader);
64 pFileStream.reset();
65
66 rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
67 xRet = pIndex;
68 pIndex->openIndexFile();
69 }
70 else
71 {
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 );
77 }
78 return xRet;
79}
80
81void ODbaseIndexes::impl_refresh( )
82{
83 if(m_pTable)
84 m_pTable->refreshIndexes();
85}
86
87Reference< XPropertySet > ODbaseIndexes::createDescriptor()
88{
89 return new ODbaseIndex(m_pTable);
90}
91
92// XAppend
93sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
94{
95 ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(descriptor.get());
96 if(pIndex)
97 pIndex->CreateImpl();
98
99 return createObject( _rForName );
100}
101
102// XDrop
103void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
104{
105 rtl::Reference<ODbaseIndex> pIndex = dynamic_cast<ODbaseIndex*>(getObject(_nPos).get());
106 if ( pIndex )
107 pIndex->DropImpl();
108}
109
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< SvStream > createStream_simpleError(const OUString &_rFileName, StreamMode _eOpenMode)
Definition: FTable.cxx:155
#define DINDEX_PAGE_SIZE
Definition: dindexnode.hxx:26
void ReadHeader(SvStream &rStream, ODbaseIndex::NDXHeader &rHeader)
Definition: DIndex.cxx:314
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
#define PROPERTY_ID_DELIMITER
Definition: propertyids.hxx:87
sal_Int32 _nPos