1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_connectivity.hxx" 26 #include "connectivity/TIndex.hxx" 27 #include "connectivity/TIndexColumns.hxx" 28 #include <com/sun/star/sdbc/XRow.hpp> 29 #include <com/sun/star/sdbc/XResultSet.hpp> 30 #include "connectivity/TTableHelper.hxx" 31 #include "TConnection.hxx" 32 33 using namespace connectivity; 34 using namespace connectivity::sdbcx; 35 using namespace ::com::sun::star::uno; 36 using namespace ::com::sun::star::beans; 37 // using namespace ::com::sun::star::sdbcx; 38 using namespace ::com::sun::star::sdbc; 39 using namespace ::com::sun::star::container; 40 using namespace ::com::sun::star::lang; 41 // ------------------------------------------------------------------------- 42 OIndexHelper::OIndexHelper( OTableHelper* _pTable) : connectivity::sdbcx::OIndex(sal_True) 43 , m_pTable(_pTable) 44 { 45 construct(); 46 ::std::vector< ::rtl::OUString> aVector; 47 m_pColumns = new OIndexColumns(this,m_aMutex,aVector); 48 } 49 // ------------------------------------------------------------------------- 50 OIndexHelper::OIndexHelper( OTableHelper* _pTable, 51 const ::rtl::OUString& _Name, 52 const ::rtl::OUString& _Catalog, 53 sal_Bool _isUnique, 54 sal_Bool _isPrimaryKeyIndex, 55 sal_Bool _isClustered 56 ) : connectivity::sdbcx::OIndex(_Name, 57 _Catalog, 58 _isUnique, 59 _isPrimaryKeyIndex, 60 _isClustered,sal_True) 61 ,m_pTable(_pTable) 62 { 63 construct(); 64 refreshColumns(); 65 } 66 // ------------------------------------------------------------------------- 67 68 void OIndexHelper::refreshColumns() 69 { 70 if ( !m_pTable ) 71 return; 72 73 ::std::vector< ::rtl::OUString> aVector; 74 if ( !isNew() ) 75 { 76 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); 77 ::rtl::OUString aSchema,aTable; 78 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema; 79 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable; 80 81 Reference< XResultSet > xResult = m_pTable->getMetaData()->getIndexInfo( 82 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)), 83 aSchema,aTable,sal_False,sal_False); 84 85 if ( xResult.is() ) 86 { 87 Reference< XRow > xRow(xResult,UNO_QUERY); 88 ::rtl::OUString aColName; 89 while( xResult->next() ) 90 { 91 if ( xRow->getString(6) == m_Name ) 92 { 93 aColName = xRow->getString(9); 94 if ( !xRow->wasNull() ) 95 aVector.push_back(aColName); 96 } 97 } 98 } 99 } 100 if(m_pColumns) 101 m_pColumns->reFill(aVector); 102 else 103 m_pColumns = new OIndexColumns(this,m_aMutex,aVector); 104 } 105 // ----------------------------------------------------------------------------- 106 107