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 "connectivity/TIndex.hxx" 31 #include "connectivity/TIndexColumns.hxx" 32 #include <com/sun/star/sdbc/XRow.hpp> 33 #include <com/sun/star/sdbc/XResultSet.hpp> 34 #include "connectivity/TTableHelper.hxx" 35 #include "TConnection.hxx" 36 37 using namespace connectivity; 38 using namespace connectivity::sdbcx; 39 using namespace ::com::sun::star::uno; 40 using namespace ::com::sun::star::beans; 41 // using namespace ::com::sun::star::sdbcx; 42 using namespace ::com::sun::star::sdbc; 43 using namespace ::com::sun::star::container; 44 using namespace ::com::sun::star::lang; 45 // ------------------------------------------------------------------------- 46 OIndexHelper::OIndexHelper( OTableHelper* _pTable) : connectivity::sdbcx::OIndex(sal_True) 47 , m_pTable(_pTable) 48 { 49 construct(); 50 ::std::vector< ::rtl::OUString> aVector; 51 m_pColumns = new OIndexColumns(this,m_aMutex,aVector); 52 } 53 // ------------------------------------------------------------------------- 54 OIndexHelper::OIndexHelper( OTableHelper* _pTable, 55 const ::rtl::OUString& _Name, 56 const ::rtl::OUString& _Catalog, 57 sal_Bool _isUnique, 58 sal_Bool _isPrimaryKeyIndex, 59 sal_Bool _isClustered 60 ) : connectivity::sdbcx::OIndex(_Name, 61 _Catalog, 62 _isUnique, 63 _isPrimaryKeyIndex, 64 _isClustered,sal_True) 65 ,m_pTable(_pTable) 66 { 67 construct(); 68 refreshColumns(); 69 } 70 // ------------------------------------------------------------------------- 71 72 void OIndexHelper::refreshColumns() 73 { 74 if ( !m_pTable ) 75 return; 76 77 ::std::vector< ::rtl::OUString> aVector; 78 if ( !isNew() ) 79 { 80 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); 81 ::rtl::OUString aSchema,aTable; 82 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema; 83 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable; 84 85 Reference< XResultSet > xResult = m_pTable->getMetaData()->getIndexInfo( 86 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)), 87 aSchema,aTable,sal_False,sal_False); 88 89 if ( xResult.is() ) 90 { 91 Reference< XRow > xRow(xResult,UNO_QUERY); 92 ::rtl::OUString aColName; 93 while( xResult->next() ) 94 { 95 if ( xRow->getString(6) == m_Name ) 96 { 97 aColName = xRow->getString(9); 98 if ( !xRow->wasNull() ) 99 aVector.push_back(aColName); 100 } 101 } 102 } 103 } 104 if(m_pColumns) 105 m_pColumns->reFill(aVector); 106 else 107 m_pColumns = new OIndexColumns(this,m_aMutex,aVector); 108 } 109 // ----------------------------------------------------------------------------- 110 111