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/DCode.hxx" 27 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 28 #include "dbase/DIndex.hxx" 29 #include "dbase/DIndexIter.hxx" 30 31 32 using namespace connectivity::dbase; 33 using namespace connectivity::file; 34 using namespace ::com::sun::star::uno; 35 using namespace ::com::sun::star::beans; 36 using namespace ::com::sun::star::sdbcx; 37 using namespace ::com::sun::star::lang; 38 using namespace ::com::sun::star::container; 39 40 TYPEINIT1(OFILEOperandAttr, OOperandAttr); 41 // ----------------------------------------------------------------------------- 42 OOperandAttr* OFILEAnalyzer::createOperandAttr(sal_Int32 _nPos, 43 const Reference< XPropertySet>& _xCol, 44 const Reference< XNameAccess>& _xIndexes) 45 { 46 return new OFILEOperandAttr((sal_uInt16)_nPos,_xCol,_xIndexes); 47 } 48 49 //------------------------------------------------------------------ 50 OFILEOperandAttr::OFILEOperandAttr(sal_uInt16 _nPos, 51 const Reference< XPropertySet>& _xColumn, 52 const Reference< XNameAccess>& _xIndexes) 53 : OOperandAttr(_nPos,_xColumn) 54 { 55 if(_xIndexes.is()) 56 { 57 ::rtl::OUString sName; 58 Reference<XPropertySetInfo> xColInfo = _xColumn->getPropertySetInfo(); 59 Reference<XPropertySet> xIndex; 60 61 Sequence< ::rtl::OUString> aSeq = _xIndexes->getElementNames(); 62 const ::rtl::OUString* pBegin = aSeq.getConstArray(); 63 const ::rtl::OUString* pEnd = pBegin + aSeq.getLength(); 64 for(;pBegin != pEnd;++pBegin) 65 { 66 _xIndexes->getByName(*pBegin) >>= xIndex; 67 if(xIndex.is()) 68 { 69 Reference<XColumnsSupplier> xColsSup(xIndex,UNO_QUERY); 70 Reference<XNameAccess> xNameAccess = xColsSup->getColumns(); 71 _xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName; 72 if(xNameAccess->hasByName(sName)) 73 { 74 m_xIndex = xIndex; 75 break; 76 } 77 else if(xColInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME))) 78 { 79 _xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= sName; 80 if(xNameAccess->hasByName(sName)) 81 { 82 m_xIndex = xIndex; 83 break; 84 } 85 } 86 } 87 } 88 } 89 90 } 91 // ------------------------------------------------------------------------- 92 sal_Bool OFILEOperandAttr::isIndexed() const 93 { 94 return m_xIndex.is(); 95 } 96 //------------------------------------------------------------------ 97 OEvaluateSet* OFILEOperandAttr::preProcess(OBoolOperator* pOp, OOperand* pRight) 98 { 99 OEvaluateSet* pEvaluateSet = NULL; 100 if (isIndexed()) 101 { 102 Reference<XUnoTunnel> xTunnel(m_xIndex,UNO_QUERY); 103 if(xTunnel.is()) 104 { 105 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) ); 106 if(pIndex) 107 { 108 OIndexIterator* pIter = pIndex->createIterator(pOp,pRight); 109 110 if (pIter) 111 { 112 pEvaluateSet = new OEvaluateSet(); 113 sal_uIntPtr nRec = pIter->First(); 114 while (nRec != NODE_NOTFOUND) 115 { 116 (*pEvaluateSet)[nRec] = nRec; 117 nRec = pIter->Next(); 118 } 119 } 120 delete pIter; 121 } 122 } 123 } 124 return pEvaluateSet; 125 } 126 127 128