1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "dbase/DIndexes.hxx"
30 #include "dbase/DIndex.hxx"
31 #include <connectivity/dbexception.hxx>
32 #include <unotools/ucbhelper.hxx>
33 #include <comphelper/types.hxx>
34 #include "resource/dbase_res.hrc"
36 using namespace ::comphelper
;
39 using namespace ::connectivity
;
40 using namespace ::dbtools
;
41 using namespace ::connectivity::dbase
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::sdbcx
;
45 using namespace ::com::sun::star::sdbc
;
46 using namespace ::com::sun::star::container
;
47 using namespace ::com::sun::star::lang
;
49 sdbcx::ObjectType
ODbaseIndexes::createObject(const ::rtl::OUString
& _rName
)
51 ::rtl::OUString sFile
= m_pTable
->getConnection()->getURL();
52 sFile
+= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER
);
54 sFile
+= ::rtl::OUString(".ndx");
55 if ( !UCBContentHelper::Exists(sFile
) )
57 const ::rtl::OUString
sError( m_pTable
->getConnection()->getResources().getResourceStringWithSubstitution(
58 STR_COULD_NOT_LOAD_FILE
,
61 ::dbtools::throwGenericSQLException( sError
, *m_pTable
);
64 sdbcx::ObjectType xRet
;
65 SvStream
* pFileStream
= ::connectivity::file::OFileTable::createStream_simpleError(sFile
,STREAM_READ
| STREAM_NOCREATE
| STREAM_SHARE_DENYWRITE
);
68 pFileStream
->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN
);
69 pFileStream
->SetBufferSize(PAGE_SIZE
);
70 ODbaseIndex::NDXHeader aHeader
;
73 pFileStream
->Read(&aHeader
,PAGE_SIZE
);
76 ODbaseIndex
* pIndex
= new ODbaseIndex(m_pTable
,aHeader
,_rName
);
78 pIndex
->openIndexFile();
82 const ::rtl::OUString
sError( m_pTable
->getConnection()->getResources().getResourceStringWithSubstitution(
83 STR_COULD_NOT_LOAD_FILE
,
86 ::dbtools::throwGenericSQLException( sError
, *m_pTable
);
90 // -------------------------------------------------------------------------
91 void ODbaseIndexes::impl_refresh( ) throw(RuntimeException
)
94 m_pTable
->refreshIndexes();
96 // -------------------------------------------------------------------------
97 Reference
< XPropertySet
> ODbaseIndexes::createDescriptor()
99 return new ODbaseIndex(m_pTable
);
101 // -------------------------------------------------------------------------
103 sdbcx::ObjectType
ODbaseIndexes::appendObject( const ::rtl::OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
105 Reference
<XUnoTunnel
> xTunnel(descriptor
,UNO_QUERY
);
108 ODbaseIndex
* pIndex
= reinterpret_cast< ODbaseIndex
* >( xTunnel
->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
109 if(!pIndex
|| !pIndex
->CreateImpl())
110 throw SQLException();
113 return createObject( _rForName
);
115 // -------------------------------------------------------------------------
117 void ODbaseIndexes::dropObject(sal_Int32 _nPos
,const ::rtl::OUString
/*_sElementName*/)
119 Reference
< XUnoTunnel
> xTunnel(getObject(_nPos
),UNO_QUERY
);
122 ODbaseIndex
* pIndex
= reinterpret_cast< ODbaseIndex
* >( xTunnel
->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
128 // -------------------------------------------------------------------------
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */