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/TIndexColumns.hxx" 31 #include "connectivity/sdbcx/VIndexColumn.hxx" 32 #include <com/sun/star/sdbc/XRow.hpp> 33 #include <com/sun/star/sdbc/XResultSet.hpp> 34 #include <com/sun/star/sdbc/DataType.hpp> 35 #include <com/sun/star/sdbc/ColumnValue.hpp> 36 #include <comphelper/property.hxx> 37 #include "connectivity/TIndex.hxx" 38 #include "connectivity/TTableHelper.hxx" 39 #include "TConnection.hxx" 40 41 using namespace connectivity; 42 using namespace connectivity::sdbcx; 43 using namespace ::com::sun::star::uno; 44 using namespace ::com::sun::star::beans; 45 // using namespace ::com::sun::star::sdbcx; 46 using namespace ::com::sun::star::sdbc; 47 using namespace ::com::sun::star::container; 48 using namespace ::com::sun::star::lang; 49 // ------------------------------------------------------------------------- 50 OIndexColumns::OIndexColumns( OIndexHelper* _pIndex, 51 ::osl::Mutex& _rMutex, 52 const ::std::vector< ::rtl::OUString> &_rVector) 53 : connectivity::sdbcx::OCollection(*_pIndex,sal_True,_rMutex,_rVector) 54 ,m_pIndex(_pIndex) 55 { 56 } 57 // ------------------------------------------------------------------------- 58 sdbcx::ObjectType OIndexColumns::createObject(const ::rtl::OUString& _rName) 59 { 60 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); 61 ::rtl::OUString aSchema,aTable; 62 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema; 63 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable; 64 65 Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo( 66 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)), 67 aSchema,aTable,sal_False,sal_False); 68 69 sal_Bool bAsc = sal_True; 70 if ( xResult.is() ) 71 { 72 Reference< XRow > xRow(xResult,UNO_QUERY); 73 ::rtl::OUString aD(::rtl::OUString::createFromAscii("D")); 74 while( xResult->next() ) 75 { 76 if(xRow->getString(9) == _rName) 77 bAsc = xRow->getString(10) != aD; 78 } 79 } 80 81 xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns( 82 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)), 83 aSchema,aTable,_rName); 84 85 sdbcx::ObjectType xRet; 86 if ( xResult.is() ) 87 { 88 Reference< XRow > xRow(xResult,UNO_QUERY); 89 while( xResult->next() ) 90 { 91 if ( xRow->getString(4) == _rName ) 92 { 93 sal_Int32 nDataType = xRow->getInt(5); 94 ::rtl::OUString aTypeName(xRow->getString(6)); 95 sal_Int32 nSize = xRow->getInt(7); 96 sal_Int32 nDec = xRow->getInt(9); 97 sal_Int32 nNull = xRow->getInt(11); 98 ::rtl::OUString aColumnDef(xRow->getString(13)); 99 100 OIndexColumn* pRet = new OIndexColumn(bAsc, 101 _rName, 102 aTypeName, 103 aColumnDef, 104 nNull, 105 nSize, 106 nDec, 107 nDataType, 108 sal_False,sal_False,sal_False,sal_True); 109 xRet = pRet; 110 break; 111 } 112 } 113 } 114 115 return xRet; 116 } 117 // ------------------------------------------------------------------------- 118 Reference< XPropertySet > OIndexColumns::createDescriptor() 119 { 120 return new OIndexColumn(sal_True); 121 } 122 // ------------------------------------------------------------------------- 123 void OIndexColumns::impl_refresh() throw(RuntimeException) 124 { 125 m_pIndex->refreshColumns(); 126 } 127 // ----------------------------------------------------------------------------- 128