Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / dbase / DIndexes.cxx
blobf494a046548163c11dfadbdde60bd6879aa5e7c6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DIndexes.cxx,v $
10 * $Revision: 1.18.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "dbase/DIndexes.hxx"
34 #include "dbase/DIndex.hxx"
35 #include <connectivity/dbexception.hxx>
36 #include <unotools/ucbhelper.hxx>
37 #include <comphelper/types.hxx>
38 #include "resource/dbase_res.hrc"
40 using namespace ::comphelper;
42 using namespace utl;
43 using namespace ::connectivity;
44 using namespace ::dbtools;
45 using namespace ::connectivity::dbase;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::sdbcx;
49 using namespace ::com::sun::star::sdbc;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::lang;
53 namespace starutil = ::com::sun::star::util;
55 sdbcx::ObjectType ODbaseIndexes::createObject(const ::rtl::OUString& _rName)
57 // Dir* pDir = m_pTable->getConnection()->getDir();
58 // String aPath = pDir->GetName();
59 // aPath += _rName.getStr();
60 ::rtl::OUString sFile = m_pTable->getConnection()->getURL();
61 sFile += OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER);
62 sFile += _rName;
63 sFile += ::rtl::OUString::createFromAscii(".ndx");
64 if ( !UCBContentHelper::Exists(sFile) )
66 const ::rtl::OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
67 STR_COULD_NOT_LOAD_FILE,
68 "$filename$", sFile
69 ) );
70 ::dbtools::throwGenericSQLException( sError, *m_pTable );
73 sdbcx::ObjectType xRet;
74 SvStream* pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile,STREAM_READ | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE);
75 if(pFileStream)
77 pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
78 pFileStream->SetBufferSize(PAGE_SIZE);
79 ODbaseIndex::NDXHeader aHeader;
81 pFileStream->Seek(0);
82 pFileStream->Read(&aHeader,PAGE_SIZE);
83 delete pFileStream;
85 ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
86 xRet = pIndex;
87 pIndex->openIndexFile();
89 else
91 const ::rtl::OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
92 STR_COULD_NOT_LOAD_FILE,
93 "$filename$", sFile
94 ) );
95 ::dbtools::throwGenericSQLException( sError, *m_pTable );
97 return xRet;
99 // -------------------------------------------------------------------------
100 void ODbaseIndexes::impl_refresh( ) throw(RuntimeException)
102 if(m_pTable)
103 m_pTable->refreshIndexes();
105 // -------------------------------------------------------------------------
106 Reference< XPropertySet > ODbaseIndexes::createDescriptor()
108 return new ODbaseIndex(m_pTable);
110 typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE;
111 // -------------------------------------------------------------------------
112 // XAppend
113 sdbcx::ObjectType ODbaseIndexes::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
115 Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY);
116 if(xTunnel.is())
118 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
119 if(!pIndex || !pIndex->CreateImpl())
120 throw SQLException();
123 return createObject( _rForName );
125 // -------------------------------------------------------------------------
126 // XDrop
127 void ODbaseIndexes::dropObject(sal_Int32 _nPos,const ::rtl::OUString /*_sElementName*/)
129 Reference< XUnoTunnel> xTunnel(getObject(_nPos),UNO_QUERY);
130 if ( xTunnel.is() )
132 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
133 if ( pIndex )
134 pIndex->DropImpl();
138 // -------------------------------------------------------------------------