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