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