Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / dbase / DCode.cxx
blob9bed8121e0eacf940094e2bda239559fa86ba0c7
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/DCode.hxx"
30 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
31 #include "dbase/DIndex.hxx"
32 #include "dbase/DIndexIter.hxx"
35 using namespace connectivity::dbase;
36 using namespace connectivity::file;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::container;
43 TYPEINIT1(OFILEOperandAttr, OOperandAttr);
44 // -----------------------------------------------------------------------------
45 OOperandAttr* OFILEAnalyzer::createOperandAttr(sal_Int32 _nPos,
46 const Reference< XPropertySet>& _xCol,
47 const Reference< XNameAccess>& _xIndexes)
49 return new OFILEOperandAttr((sal_uInt16)_nPos,_xCol,_xIndexes);
52 //------------------------------------------------------------------
53 OFILEOperandAttr::OFILEOperandAttr(sal_uInt16 _nPos,
54 const Reference< XPropertySet>& _xColumn,
55 const Reference< XNameAccess>& _xIndexes)
56 : OOperandAttr(_nPos,_xColumn)
58 if(_xIndexes.is())
60 ::rtl::OUString sName;
61 Reference<XPropertySetInfo> xColInfo = _xColumn->getPropertySetInfo();
62 Reference<XPropertySet> xIndex;
64 Sequence< ::rtl::OUString> aSeq = _xIndexes->getElementNames();
65 const ::rtl::OUString* pBegin = aSeq.getConstArray();
66 const ::rtl::OUString* pEnd = pBegin + aSeq.getLength();
67 for(;pBegin != pEnd;++pBegin)
69 _xIndexes->getByName(*pBegin) >>= xIndex;
70 if(xIndex.is())
72 Reference<XColumnsSupplier> xColsSup(xIndex,UNO_QUERY);
73 Reference<XNameAccess> xNameAccess = xColsSup->getColumns();
74 _xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName;
75 if(xNameAccess->hasByName(sName))
77 m_xIndex = xIndex;
78 break;
80 else if(xColInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
82 _xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= sName;
83 if(xNameAccess->hasByName(sName))
85 m_xIndex = xIndex;
86 break;
94 // -------------------------------------------------------------------------
95 sal_Bool OFILEOperandAttr::isIndexed() const
97 return m_xIndex.is();
99 //------------------------------------------------------------------
100 OEvaluateSet* OFILEOperandAttr::preProcess(OBoolOperator* pOp, OOperand* pRight)
102 OEvaluateSet* pEvaluateSet = NULL;
103 if (isIndexed())
105 Reference<XUnoTunnel> xTunnel(m_xIndex,UNO_QUERY);
106 if(xTunnel.is())
108 ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
109 if(pIndex)
111 OIndexIterator* pIter = pIndex->createIterator(pOp,pRight);
113 if (pIter)
115 pEvaluateSet = new OEvaluateSet();
116 sal_uIntPtr nRec = pIter->First();
117 while (nRec != NODE_NOTFOUND)
119 (*pEvaluateSet)[nRec] = nRec;
120 nRec = pIter->Next();
123 delete pIter;
127 return pEvaluateSet;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */