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