1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "dbase/DIndexes.hxx"
27 #include "dbase/DIndex.hxx"
28 #include <connectivity/dbexception.hxx>
29 #include <unotools/ucbhelper.hxx>
30 #include <comphelper/types.hxx>
31 #include "resource/dbase_res.hrc"
32
33 using namespace ::comphelper;
34
35 using namespace utl;
36 using namespace ::connectivity;
37 using namespace ::dbtools;
38 using namespace ::connectivity::dbase;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::lang;
45
46 namespace starutil = ::com::sun::star::util;
47
createObject(const::rtl::OUString & _rName)48 sdbcx::ObjectType ODbaseIndexes::createObject(const ::rtl::OUString& _rName)
49 {
50 // Dir* pDir = m_pTable->getConnection()->getDir();
51 // String aPath = pDir->GetName();
52 // aPath += _rName.getStr();
53 ::rtl::OUString sFile = m_pTable->getConnection()->getURL();
54 sFile += OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER);
55 sFile += _rName;
56 sFile += ::rtl::OUString::createFromAscii(".ndx");
57 if ( !UCBContentHelper::Exists(sFile) )
58 {
59 const ::rtl::OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
60 STR_COULD_NOT_LOAD_FILE,
61 "$filename$", sFile
62 ) );
63 ::dbtools::throwGenericSQLException( sError, *m_pTable );
64 }
65
66 sdbcx::ObjectType xRet;
67 SvStream* pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile,STREAM_READ | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE);
68 if(pFileStream)
69 {
70 pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
71 pFileStream->SetBufferSize(PAGE_SIZE);
72 ODbaseIndex::NDXHeader aHeader;
73
74 pFileStream->Seek(0);
75 pFileStream->Read(&aHeader,PAGE_SIZE);
76 delete pFileStream;
77
78 ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
79 xRet = pIndex;
80 pIndex->openIndexFile();
81 }
82 else
83 {
84 const ::rtl::OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution(
85 STR_COULD_NOT_LOAD_FILE,
86 "$filename$", sFile
87 ) );
88 ::dbtools::throwGenericSQLException( sError, *m_pTable );
89 }
90 return xRet;
91 }
92 // -------------------------------------------------------------------------
impl_refresh()93 void ODbaseIndexes::impl_refresh( ) throw(RuntimeException)
94 {
95 if(m_pTable)
96 m_pTable->refreshIndexes();
97 }
98 // -------------------------------------------------------------------------
createDescriptor()99 Reference< XPropertySet > ODbaseIndexes::createDescriptor()
100 {
101 return new ODbaseIndex(m_pTable);
102 }
103 typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE;
104 // -------------------------------------------------------------------------
105 // XAppend
appendObject(const::rtl::OUString & _rForName,const Reference<XPropertySet> & descriptor)106 sdbcx::ObjectType ODbaseIndexes::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
107 {
108 Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY);
109 if(xTunnel.is())
110 {
111 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
112 if(!pIndex || !pIndex->CreateImpl())
113 throw SQLException();
114 }
115
116 return createObject( _rForName );
117 }
118 // -------------------------------------------------------------------------
119 // XDrop
dropObject(sal_Int32 _nPos,const::rtl::OUString)120 void ODbaseIndexes::dropObject(sal_Int32 _nPos,const ::rtl::OUString /*_sElementName*/)
121 {
122 Reference< XUnoTunnel> xTunnel(getObject(_nPos),UNO_QUERY);
123 if ( xTunnel.is() )
124 {
125 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
126 if ( pIndex )
127 pIndex->DropImpl();
128 }
129
130 }
131 // -------------------------------------------------------------------------
132
133
134