Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / dbase / DCode.cxx
blob2291db703daee35bb407ce9213ec1fc771794c8c
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: DCode.cxx,v $
10 * $Revision: 1.7 $
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/DCode.hxx"
34 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35 #include "dbase/DIndex.hxx"
36 #include "dbase/DIndexIter.hxx"
39 using namespace connectivity::dbase;
40 using namespace connectivity::file;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::sdbcx;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::container;
47 TYPEINIT1(OFILEOperandAttr, OOperandAttr);
48 // -----------------------------------------------------------------------------
49 OOperandAttr* OFILEAnalyzer::createOperandAttr(sal_Int32 _nPos,
50 const Reference< XPropertySet>& _xCol,
51 const Reference< XNameAccess>& _xIndexes)
53 return new OFILEOperandAttr((sal_uInt16)_nPos,_xCol,_xIndexes);
56 //------------------------------------------------------------------
57 OFILEOperandAttr::OFILEOperandAttr(sal_uInt16 _nPos,
58 const Reference< XPropertySet>& _xColumn,
59 const Reference< XNameAccess>& _xIndexes)
60 : OOperandAttr(_nPos,_xColumn)
62 if(_xIndexes.is())
64 ::rtl::OUString sName;
65 Reference<XPropertySetInfo> xColInfo = _xColumn->getPropertySetInfo();
66 Reference<XPropertySet> xIndex;
68 Sequence< ::rtl::OUString> aSeq = _xIndexes->getElementNames();
69 const ::rtl::OUString* pBegin = aSeq.getConstArray();
70 const ::rtl::OUString* pEnd = pBegin + aSeq.getLength();
71 for(;pBegin != pEnd;++pBegin)
73 _xIndexes->getByName(*pBegin) >>= xIndex;
74 if(xIndex.is())
76 Reference<XColumnsSupplier> xColsSup(xIndex,UNO_QUERY);
77 Reference<XNameAccess> xNameAccess = xColsSup->getColumns();
78 _xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName;
79 if(xNameAccess->hasByName(sName))
81 m_xIndex = xIndex;
82 break;
84 else if(xColInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
86 _xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= sName;
87 if(xNameAccess->hasByName(sName))
89 m_xIndex = xIndex;
90 break;
98 // -------------------------------------------------------------------------
99 sal_Bool OFILEOperandAttr::isIndexed() const
101 return m_xIndex.is();
103 //------------------------------------------------------------------
104 OEvaluateSet* OFILEOperandAttr::preProcess(OBoolOperator* pOp, OOperand* pRight)
106 OEvaluateSet* pEvaluateSet = NULL;
107 if (isIndexed())
109 Reference<XUnoTunnel> xTunnel(m_xIndex,UNO_QUERY);
110 if(xTunnel.is())
112 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
113 if(pIndex)
115 OIndexIterator* pIter = pIndex->createIterator(pOp,pRight);
117 if (pIter)
119 pEvaluateSet = new OEvaluateSet();
120 ULONG nRec = pIter->First();
121 while (nRec != NODE_NOTFOUND)
123 (*pEvaluateSet)[nRec] = nRec;
124 nRec = pIter->Next();
127 delete pIter;
131 return pEvaluateSet;