196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
1096de5490SAndrew Rist  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
1996de5490SAndrew Rist  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBAUI_INDEXCOLLECTION_HXX_
28cdf0e10cSrcweir #include "indexcollection.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
31cdf0e10cSrcweir #include <tools/diagnose_ex.h>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
34cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
40cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
43cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_
46cdf0e10cSrcweir #include <comphelper/extract.hxx>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
49cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
52cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //......................................................................
56cdf0e10cSrcweir namespace dbaui
57cdf0e10cSrcweir {
58cdf0e10cSrcweir //......................................................................
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
61cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
62cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
63cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
64cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	//==================================================================
67cdf0e10cSrcweir 	//= OIndexCollection
68cdf0e10cSrcweir 	//==================================================================
69cdf0e10cSrcweir 	//------------------------------------------------------------------
70cdf0e10cSrcweir 	OIndexCollection::OIndexCollection()
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	//------------------------------------------------------------------
75cdf0e10cSrcweir 	OIndexCollection::OIndexCollection(const OIndexCollection& _rSource)
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		*this = _rSource;
78cdf0e10cSrcweir 	}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	//------------------------------------------------------------------
81cdf0e10cSrcweir //	OIndexCollection::OIndexCollection(const Reference< XNameAccess >& _rxIndexes)
82cdf0e10cSrcweir //	{
83cdf0e10cSrcweir //		implConstructFrom(_rxIndexes);
84cdf0e10cSrcweir //	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	//------------------------------------------------------------------
87cdf0e10cSrcweir 	const OIndexCollection& OIndexCollection::operator=(const OIndexCollection& _rSource)
88cdf0e10cSrcweir 	{
89cdf0e10cSrcweir 		detach();
90cdf0e10cSrcweir 		m_xIndexes = _rSource.m_xIndexes;
91cdf0e10cSrcweir 		m_aIndexes = _rSource.m_aIndexes;
92cdf0e10cSrcweir 		return *this;
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	//------------------------------------------------------------------
96cdf0e10cSrcweir 	void OIndexCollection::attach(const Reference< XNameAccess >& _rxIndexes)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		implConstructFrom(_rxIndexes);
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	//------------------------------------------------------------------
102cdf0e10cSrcweir 	void OIndexCollection::detach()
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		m_xIndexes.clear();
105cdf0e10cSrcweir 		m_aIndexes.clear();
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	//------------------------------------------------------------------
109cdf0e10cSrcweir 	Indexes::const_iterator OIndexCollection::find(const String& _rName) const
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		::rtl::OUString sNameCompare(_rName);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		// loop'n'compare
114cdf0e10cSrcweir 		Indexes::const_iterator aSearch = m_aIndexes.begin();
115cdf0e10cSrcweir         Indexes::const_iterator aEnd = m_aIndexes.end();
116cdf0e10cSrcweir 		for (; aSearch != aEnd; ++aSearch)
117cdf0e10cSrcweir 			if (aSearch->sName == sNameCompare)
118cdf0e10cSrcweir 				break;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		return aSearch;
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	//------------------------------------------------------------------
124cdf0e10cSrcweir 	Indexes::iterator OIndexCollection::find(const String& _rName)
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 		::rtl::OUString sNameCompare(_rName);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		// loop'n'compare
129cdf0e10cSrcweir 		Indexes::iterator aSearch = m_aIndexes.begin();
130cdf0e10cSrcweir 		Indexes::iterator aEnd = m_aIndexes.end();
131cdf0e10cSrcweir 		for (; aSearch != aEnd; ++aSearch)
132cdf0e10cSrcweir 			if (aSearch->sName == sNameCompare)
133cdf0e10cSrcweir 				break;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		return aSearch;
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	//------------------------------------------------------------------
139cdf0e10cSrcweir 	Indexes::const_iterator OIndexCollection::findOriginal(const String& _rName) const
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		::rtl::OUString sNameCompare(_rName);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		// loop'n'compare
144cdf0e10cSrcweir 		Indexes::const_iterator aSearch = m_aIndexes.begin();
145cdf0e10cSrcweir 		Indexes::const_iterator aEnd = m_aIndexes.end();
146cdf0e10cSrcweir 		for (; aSearch != aEnd; ++aSearch)
147cdf0e10cSrcweir 			if (aSearch->getOriginalName() == sNameCompare)
148cdf0e10cSrcweir 				break;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		return aSearch;
151cdf0e10cSrcweir 	}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	//------------------------------------------------------------------
154cdf0e10cSrcweir 	Indexes::iterator OIndexCollection::findOriginal(const String& _rName)
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		::rtl::OUString sNameCompare(_rName);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		// loop'n'compare
159cdf0e10cSrcweir 		Indexes::iterator aSearch = m_aIndexes.begin();
160cdf0e10cSrcweir 		Indexes::iterator aEnd = m_aIndexes.end();
161cdf0e10cSrcweir 		for (; aSearch != aEnd; ++aSearch)
162cdf0e10cSrcweir 			if (aSearch->getOriginalName() == sNameCompare)
163cdf0e10cSrcweir 				break;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		return aSearch;
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	//------------------------------------------------------------------
169cdf0e10cSrcweir 	void OIndexCollection::commitNewIndex(const Indexes::iterator& _rPos) SAL_THROW((SQLException))
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		OSL_ENSURE(_rPos->isNew(), "OIndexCollection::commitNewIndex: index must be new!");
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		try
174cdf0e10cSrcweir 		{
175cdf0e10cSrcweir 			Reference< XDataDescriptorFactory > xIndexFactory(m_xIndexes, UNO_QUERY);
176cdf0e10cSrcweir 			Reference< XAppend > xAppendIndex(xIndexFactory, UNO_QUERY);
177cdf0e10cSrcweir 			if (!xAppendIndex.is())
178cdf0e10cSrcweir 			{
179cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OIndexCollection::commitNewIndex: missing an interface of the index container!");
180cdf0e10cSrcweir 				return;
181cdf0e10cSrcweir 			}
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 			Reference< XPropertySet > xIndexDescriptor = xIndexFactory->createDataDescriptor();
184cdf0e10cSrcweir 			Reference< XColumnsSupplier > xColsSupp(xIndexDescriptor, UNO_QUERY);
185cdf0e10cSrcweir 			Reference< XNameAccess > xCols;
186cdf0e10cSrcweir 			if (xColsSupp.is())
187cdf0e10cSrcweir 				xCols = xColsSupp->getColumns();
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			Reference< XDataDescriptorFactory > xColumnFactory(xCols, UNO_QUERY);
190cdf0e10cSrcweir 			Reference< XAppend > xAppendCols(xColumnFactory, UNO_QUERY);
191cdf0e10cSrcweir 			if (!xAppendCols.is())
192cdf0e10cSrcweir 			{
193cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OIndexCollection::commitNewIndex: invalid index descriptor returned!");
194cdf0e10cSrcweir 				return;
195cdf0e10cSrcweir 			}
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 			// set the properties
198cdf0e10cSrcweir 			static const ::rtl::OUString s_sUniquePropertyName = ::rtl::OUString::createFromAscii("IsUnique");
199cdf0e10cSrcweir 			static const ::rtl::OUString s_sSortPropertyName = ::rtl::OUString::createFromAscii("IsAscending");
200cdf0e10cSrcweir 			static const ::rtl::OUString s_sNamePropertyName = ::rtl::OUString::createFromAscii("Name");
201cdf0e10cSrcweir 			// the index' own props
202cdf0e10cSrcweir 			xIndexDescriptor->setPropertyValue(s_sUniquePropertyName, ::cppu::bool2any(_rPos->bUnique));
203cdf0e10cSrcweir 			xIndexDescriptor->setPropertyValue(s_sNamePropertyName, makeAny(_rPos->sName));
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 			// the fields
206cdf0e10cSrcweir 			for	(	ConstIndexFieldsIterator aFieldLoop = _rPos->aFields.begin();
207cdf0e10cSrcweir 					aFieldLoop != _rPos->aFields.end();
208cdf0e10cSrcweir 					++aFieldLoop
209cdf0e10cSrcweir 				)
210cdf0e10cSrcweir 			{
211cdf0e10cSrcweir 				OSL_ENSURE(!xCols->hasByName(aFieldLoop->sFieldName), "OIndexCollection::commitNewIndex: double column name (need to prevent this outside)!");
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 				Reference< XPropertySet > xColDescriptor = xColumnFactory->createDataDescriptor();
214cdf0e10cSrcweir 				OSL_ENSURE(xColDescriptor.is(), "OIndexCollection::commitNewIndex: invalid column descriptor!");
215cdf0e10cSrcweir 				if (xColDescriptor.is())
216cdf0e10cSrcweir 				{
217cdf0e10cSrcweir 					xColDescriptor->setPropertyValue(s_sSortPropertyName, ::cppu::bool2any(aFieldLoop->bSortAscending));
218cdf0e10cSrcweir 					xColDescriptor->setPropertyValue(s_sNamePropertyName, makeAny(::rtl::OUString(aFieldLoop->sFieldName)));
219cdf0e10cSrcweir 					xAppendCols->appendByDescriptor(xColDescriptor);
220cdf0e10cSrcweir 				}
221cdf0e10cSrcweir 			}
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 			xAppendIndex->appendByDescriptor(xIndexDescriptor);
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 			_rPos->flagAsCommitted(GrantIndexAccess());
226cdf0e10cSrcweir 			_rPos->clearModified();
227cdf0e10cSrcweir 		}
228cdf0e10cSrcweir 		catch(SQLException&)
229cdf0e10cSrcweir 		{	// allowed to pass
230cdf0e10cSrcweir 			throw;
231cdf0e10cSrcweir 		}
232cdf0e10cSrcweir         catch( const Exception& )
233cdf0e10cSrcweir         {
234cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir 	}
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	//------------------------------------------------------------------
239cdf0e10cSrcweir 	sal_Bool OIndexCollection::dropNoRemove(const Indexes::iterator& _rPos) SAL_THROW((SQLException))
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		try
242cdf0e10cSrcweir 		{
243cdf0e10cSrcweir 			OSL_ENSURE(m_xIndexes->hasByName(_rPos->getOriginalName()), "OIndexCollection::drop: invalid name!");
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 			Reference< XDrop > xDropIndex(m_xIndexes, UNO_QUERY);
246cdf0e10cSrcweir 			if (!xDropIndex.is())
247cdf0e10cSrcweir 			{
248cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OIndexCollection::drop: no XDrop interface!");
249cdf0e10cSrcweir 				return sal_False;
250cdf0e10cSrcweir 			}
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 			xDropIndex->dropByName(_rPos->getOriginalName());
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 		catch(SQLException&)
255cdf0e10cSrcweir 		{	// allowed to pass
256cdf0e10cSrcweir 			throw;
257cdf0e10cSrcweir 		}
258cdf0e10cSrcweir         catch( const Exception& )
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
261cdf0e10cSrcweir             return sal_False;
262cdf0e10cSrcweir 		}
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 		// adjust the OIndex structure
265cdf0e10cSrcweir 		Indexes::iterator aDropped = findOriginal(_rPos->getOriginalName());
266*07a3d7f1SPedro Giffuni 		OSL_ENSURE(aDropped != m_aIndexes.end(), "OIndexCollection::drop: invalid original name, but successful commit?!");
267cdf0e10cSrcweir 		aDropped->flagAsNew(GrantIndexAccess());
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		return sal_True;
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	//------------------------------------------------------------------
273cdf0e10cSrcweir 	sal_Bool OIndexCollection::drop(const Indexes::iterator& _rPos) SAL_THROW((SQLException))
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		OSL_ENSURE((_rPos >= m_aIndexes.begin()) && (_rPos < m_aIndexes.end()),
276cdf0e10cSrcweir 			"OIndexCollection::drop: invalid position (fasten your seatbelt .... this will crash)!");
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		if (!_rPos->isNew())
279cdf0e10cSrcweir 			if (!dropNoRemove(_rPos))
280cdf0e10cSrcweir 				return sal_False;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 		// adjust the index array
283cdf0e10cSrcweir 		m_aIndexes.erase(_rPos);
284cdf0e10cSrcweir 		return sal_True;
285cdf0e10cSrcweir 	}
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	//------------------------------------------------------------------
288cdf0e10cSrcweir 	void OIndexCollection::implFillIndexInfo(OIndex& _rIndex) SAL_THROW((Exception))
289cdf0e10cSrcweir 	{
290cdf0e10cSrcweir 		// get the UNO descriptor for the index
291cdf0e10cSrcweir 		Reference< XPropertySet > xIndex;
292cdf0e10cSrcweir 		m_xIndexes->getByName(_rIndex.getOriginalName()) >>= xIndex;
293cdf0e10cSrcweir 		if (!xIndex.is())
294cdf0e10cSrcweir 		{
295cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OIndexCollection::implFillIndexInfo: got an invalid index object!");
296cdf0e10cSrcweir 		}
297cdf0e10cSrcweir 		else
298cdf0e10cSrcweir 			implFillIndexInfo(_rIndex, xIndex);
299cdf0e10cSrcweir 	}
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 	//------------------------------------------------------------------
302cdf0e10cSrcweir 	void OIndexCollection::implFillIndexInfo(OIndex& _rIndex, Reference< XPropertySet > _rxDescriptor) SAL_THROW((Exception))
303cdf0e10cSrcweir 	{
304cdf0e10cSrcweir 		static const ::rtl::OUString s_sPrimaryIndexPropertyName = ::rtl::OUString::createFromAscii("IsPrimaryKeyIndex");
305cdf0e10cSrcweir 		static const ::rtl::OUString s_sUniquePropertyName = ::rtl::OUString::createFromAscii("IsUnique");
306cdf0e10cSrcweir 		static const ::rtl::OUString s_sSortPropertyName = ::rtl::OUString::createFromAscii("IsAscending");
307cdf0e10cSrcweir 		static const ::rtl::OUString s_sCatalogPropertyName = ::rtl::OUString::createFromAscii("Catalog");
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		_rIndex.bPrimaryKey = ::cppu::any2bool(_rxDescriptor->getPropertyValue(s_sPrimaryIndexPropertyName));
310cdf0e10cSrcweir 		_rIndex.bUnique = ::cppu::any2bool(_rxDescriptor->getPropertyValue(s_sUniquePropertyName));
311cdf0e10cSrcweir 		_rxDescriptor->getPropertyValue(s_sCatalogPropertyName) >>= _rIndex.sDescription;
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 		// the columns
314cdf0e10cSrcweir 		Reference< XColumnsSupplier > xSuppCols(_rxDescriptor, UNO_QUERY);
315cdf0e10cSrcweir 		Reference< XNameAccess > xCols;
316cdf0e10cSrcweir 		if (xSuppCols.is())
317cdf0e10cSrcweir 			xCols = xSuppCols->getColumns();
318cdf0e10cSrcweir 		OSL_ENSURE(xCols.is(), "OIndexCollection::implFillIndexInfo: the index does not have columns!");
319cdf0e10cSrcweir 		if (xCols.is())
320cdf0e10cSrcweir 		{
321cdf0e10cSrcweir 			Sequence< ::rtl::OUString > aFieldNames = xCols->getElementNames();
322cdf0e10cSrcweir 			_rIndex.aFields.resize(aFieldNames.getLength());
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 			const ::rtl::OUString* pFieldNames = aFieldNames.getConstArray();
325cdf0e10cSrcweir 			const ::rtl::OUString* pFieldNamesEnd = pFieldNames + aFieldNames.getLength();
326cdf0e10cSrcweir 			IndexFields::iterator aCopyTo = _rIndex.aFields.begin();
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 			Reference< XPropertySet > xIndexColumn;
329cdf0e10cSrcweir 			for (;pFieldNames < pFieldNamesEnd; ++pFieldNames, ++aCopyTo)
330cdf0e10cSrcweir 			{
331cdf0e10cSrcweir 				// extract the column
332cdf0e10cSrcweir 				xIndexColumn.clear();
333cdf0e10cSrcweir 				xCols->getByName(*pFieldNames) >>= xIndexColumn;
334cdf0e10cSrcweir 				if (!xIndexColumn.is())
335cdf0e10cSrcweir 				{
336cdf0e10cSrcweir 					OSL_ENSURE(sal_False, "OIndexCollection::implFillIndexInfo: invalid index column!");
337cdf0e10cSrcweir 					--aCopyTo;
338cdf0e10cSrcweir 					continue;
339cdf0e10cSrcweir 				}
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 				// get the relevant properties
342cdf0e10cSrcweir 				aCopyTo->sFieldName = *pFieldNames;
343cdf0e10cSrcweir 				aCopyTo->bSortAscending = ::cppu::any2bool(xIndexColumn->getPropertyValue(s_sSortPropertyName));
344cdf0e10cSrcweir 			}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 			_rIndex.aFields.resize(aCopyTo - _rIndex.aFields.begin());
347cdf0e10cSrcweir 				// (just in case some fields were invalid ...)
348cdf0e10cSrcweir 		}
349cdf0e10cSrcweir 	}
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	//------------------------------------------------------------------
352cdf0e10cSrcweir 	void OIndexCollection::resetIndex(const Indexes::iterator& _rPos) SAL_THROW((SQLException))
353cdf0e10cSrcweir 	{
354cdf0e10cSrcweir 		OSL_ENSURE(_rPos >= m_aIndexes.begin() && _rPos < m_aIndexes.end(),
355cdf0e10cSrcweir 			"OIndexCollection::resetIndex: invalid position!");
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 		try
358cdf0e10cSrcweir 		{
359cdf0e10cSrcweir 			_rPos->sName = _rPos->getOriginalName();
360cdf0e10cSrcweir 			implFillIndexInfo(*_rPos);
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 			_rPos->clearModified();
363cdf0e10cSrcweir 			_rPos->flagAsCommitted(GrantIndexAccess());
364cdf0e10cSrcweir 		}
365cdf0e10cSrcweir 		catch(SQLException&)
366cdf0e10cSrcweir 		{	// allowed to pass
367cdf0e10cSrcweir 			throw;
368cdf0e10cSrcweir 		}
369cdf0e10cSrcweir         catch( const Exception& )
370cdf0e10cSrcweir         {
371cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
372cdf0e10cSrcweir         }
373cdf0e10cSrcweir 	}
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	//------------------------------------------------------------------
376cdf0e10cSrcweir 	Indexes::iterator OIndexCollection::insert(const String& _rName)
377cdf0e10cSrcweir 	{
378cdf0e10cSrcweir 		OSL_ENSURE(end() == find(_rName), "OIndexCollection::insert: invalid new name!");
379cdf0e10cSrcweir 		String tmpName;
380cdf0e10cSrcweir 		OIndex aNewIndex(tmpName);	// the empty string indicates the index is a new one
381cdf0e10cSrcweir 		aNewIndex.sName = _rName;
382cdf0e10cSrcweir 		m_aIndexes.push_back(aNewIndex);
383cdf0e10cSrcweir 		return m_aIndexes.end() - 1;	// the last element is the new one ...
384cdf0e10cSrcweir 	}
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	//------------------------------------------------------------------
387cdf0e10cSrcweir 	void OIndexCollection::implConstructFrom(const Reference< XNameAccess >& _rxIndexes)
388cdf0e10cSrcweir 	{
389cdf0e10cSrcweir 		detach();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 		m_xIndexes = _rxIndexes;
392cdf0e10cSrcweir 		if (m_xIndexes.is())
393cdf0e10cSrcweir 		{
394cdf0e10cSrcweir 			// loop through all the indexes
395cdf0e10cSrcweir 			Sequence< ::rtl::OUString > aNames = m_xIndexes->getElementNames();
396cdf0e10cSrcweir 			const ::rtl::OUString* pNames = aNames.getConstArray();
397cdf0e10cSrcweir 			const ::rtl::OUString* pEnd = pNames + aNames.getLength();
398cdf0e10cSrcweir 			for (; pNames < pEnd; ++pNames)
399cdf0e10cSrcweir 			{
400cdf0e10cSrcweir 				// extract the index object
401cdf0e10cSrcweir 				Reference< XPropertySet > xIndex;
402cdf0e10cSrcweir 				m_xIndexes->getByName(*pNames) >>= xIndex;
403cdf0e10cSrcweir 				if (!xIndex.is())
404cdf0e10cSrcweir 				{
405cdf0e10cSrcweir 					OSL_ENSURE(sal_False, "OIndexCollection::implConstructFrom: got an invalid index object ... ignoring!");
406cdf0e10cSrcweir 					continue;
407cdf0e10cSrcweir 				}
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 				// fill the OIndex structure
410cdf0e10cSrcweir 				OIndex aCurrentIndex(*pNames);
411cdf0e10cSrcweir 				implFillIndexInfo(aCurrentIndex);
412cdf0e10cSrcweir 				m_aIndexes.push_back(aCurrentIndex);
413cdf0e10cSrcweir 			}
414cdf0e10cSrcweir 		}
415cdf0e10cSrcweir 	}
416cdf0e10cSrcweir 
417cdf0e10cSrcweir //......................................................................
418cdf0e10cSrcweir }	// namespace dbaui
419cdf0e10cSrcweir //......................................................................
420cdf0e10cSrcweir 
421