1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "dbase/DCode.hxx"
27cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28cdf0e10cSrcweir #include "dbase/DIndex.hxx"
29cdf0e10cSrcweir #include "dbase/DIndexIter.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace connectivity::dbase;
33cdf0e10cSrcweir using namespace connectivity::file;
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::beans;
36cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
37cdf0e10cSrcweir using namespace ::com::sun::star::lang;
38cdf0e10cSrcweir using namespace ::com::sun::star::container;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir TYPEINIT1(OFILEOperandAttr, OOperandAttr);
41cdf0e10cSrcweir // -----------------------------------------------------------------------------
createOperandAttr(sal_Int32 _nPos,const Reference<XPropertySet> & _xCol,const Reference<XNameAccess> & _xIndexes)42cdf0e10cSrcweir OOperandAttr* OFILEAnalyzer::createOperandAttr(sal_Int32 _nPos,
43cdf0e10cSrcweir 											   const Reference< XPropertySet>& _xCol,
44cdf0e10cSrcweir 											   const Reference< XNameAccess>& _xIndexes)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 	return new OFILEOperandAttr((sal_uInt16)_nPos,_xCol,_xIndexes);
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //------------------------------------------------------------------
OFILEOperandAttr(sal_uInt16 _nPos,const Reference<XPropertySet> & _xColumn,const Reference<XNameAccess> & _xIndexes)50cdf0e10cSrcweir OFILEOperandAttr::OFILEOperandAttr(sal_uInt16 _nPos,
51cdf0e10cSrcweir 								   const Reference< XPropertySet>& _xColumn,
52cdf0e10cSrcweir 								   const Reference< XNameAccess>& _xIndexes)
53cdf0e10cSrcweir 	: OOperandAttr(_nPos,_xColumn)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	if(_xIndexes.is())
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		::rtl::OUString sName;
58cdf0e10cSrcweir 		Reference<XPropertySetInfo> xColInfo = _xColumn->getPropertySetInfo();
59cdf0e10cSrcweir 		Reference<XPropertySet> xIndex;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 		Sequence< ::rtl::OUString> aSeq = _xIndexes->getElementNames();
62cdf0e10cSrcweir 		const ::rtl::OUString* pBegin = aSeq.getConstArray();
63cdf0e10cSrcweir 		const ::rtl::OUString* pEnd	  = pBegin + aSeq.getLength();
64cdf0e10cSrcweir 		for(;pBegin != pEnd;++pBegin)
65cdf0e10cSrcweir 		{
66cdf0e10cSrcweir 			_xIndexes->getByName(*pBegin) >>= xIndex;
67cdf0e10cSrcweir 			if(xIndex.is())
68cdf0e10cSrcweir 			{
69cdf0e10cSrcweir 				Reference<XColumnsSupplier> xColsSup(xIndex,UNO_QUERY);
70cdf0e10cSrcweir 				Reference<XNameAccess> xNameAccess = xColsSup->getColumns();
71cdf0e10cSrcweir 				_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName;
72cdf0e10cSrcweir 				if(xNameAccess->hasByName(sName))
73cdf0e10cSrcweir 				{
74cdf0e10cSrcweir 					m_xIndex = xIndex;
75cdf0e10cSrcweir 					break;
76cdf0e10cSrcweir 				}
77cdf0e10cSrcweir 				else if(xColInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
78cdf0e10cSrcweir 				{
79cdf0e10cSrcweir 					_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= sName;
80cdf0e10cSrcweir 					if(xNameAccess->hasByName(sName))
81cdf0e10cSrcweir 					{
82cdf0e10cSrcweir 						m_xIndex = xIndex;
83cdf0e10cSrcweir 						break;
84cdf0e10cSrcweir 					}
85cdf0e10cSrcweir 				}
86cdf0e10cSrcweir 			}
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir }
91cdf0e10cSrcweir // -------------------------------------------------------------------------
isIndexed() const92cdf0e10cSrcweir sal_Bool OFILEOperandAttr::isIndexed() const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	return m_xIndex.is();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir //------------------------------------------------------------------
preProcess(OBoolOperator * pOp,OOperand * pRight)97cdf0e10cSrcweir OEvaluateSet* OFILEOperandAttr::preProcess(OBoolOperator* pOp, OOperand* pRight)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	OEvaluateSet* pEvaluateSet = NULL;
100cdf0e10cSrcweir 	if (isIndexed())
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir 		Reference<XUnoTunnel> xTunnel(m_xIndex,UNO_QUERY);
103cdf0e10cSrcweir 		if(xTunnel.is())
104cdf0e10cSrcweir 		{
105cdf0e10cSrcweir 			ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
106cdf0e10cSrcweir 			if(pIndex)
107cdf0e10cSrcweir 			{
108cdf0e10cSrcweir 				OIndexIterator* pIter = pIndex->createIterator(pOp,pRight);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 				if (pIter)
111cdf0e10cSrcweir 				{
112cdf0e10cSrcweir 					pEvaluateSet = new OEvaluateSet();
113cdf0e10cSrcweir 					sal_uIntPtr nRec = pIter->First();
114cdf0e10cSrcweir 					while (nRec != NODE_NOTFOUND)
115cdf0e10cSrcweir 					{
116cdf0e10cSrcweir 						(*pEvaluateSet)[nRec] = nRec;
117cdf0e10cSrcweir 						nRec = pIter->Next();
118cdf0e10cSrcweir 					}
119cdf0e10cSrcweir 				}
120cdf0e10cSrcweir 				delete pIter;
121cdf0e10cSrcweir 			}
122cdf0e10cSrcweir 		}
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 	return pEvaluateSet;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128