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