LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/commontools - TTableHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 293 24.2 %
Date: 2012-12-17 Functions: 9 40 22.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "connectivity/TTableHelper.hxx"
      21             : #include <com/sun/star/sdbc/XRow.hpp>
      22             : #include <com/sun/star/sdbc/XResultSet.hpp>
      23             : #include <com/sun/star/sdbcx/KeyType.hpp>
      24             : #include <com/sun/star/sdbc/KeyRule.hpp>
      25             : #include <cppuhelper/typeprovider.hxx>
      26             : #include <com/sun/star/lang/DisposedException.hpp>
      27             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      28             : #include <comphelper/implementationreference.hxx>
      29             : #include <comphelper/sequence.hxx>
      30             : #include <comphelper/extract.hxx>
      31             : #include <comphelper/types.hxx>
      32             : #include "connectivity/dbtools.hxx"
      33             : #include "connectivity/sdbcx/VCollection.hxx"
      34             : #include <unotools/sharedunocomponent.hxx>
      35             : #include "TConnection.hxx"
      36             : 
      37             : #include <o3tl/compat_functional.hxx>
      38             : 
      39             : #include <iterator>
      40             : 
      41             : using namespace ::comphelper;
      42             : using namespace connectivity;
      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             : namespace
      50             : {
      51             :     /// helper class for column property change events which holds the OComponentDefinition weak
      52             : typedef ::cppu::WeakImplHelper1 < XContainerListener > OTableContainerListener_BASE;
      53             : class OTableContainerListener : public OTableContainerListener_BASE
      54             : {
      55             :     OTableHelper* m_pComponent;
      56             :     ::std::map< ::rtl::OUString,bool> m_aRefNames;
      57             : 
      58             :     OTableContainerListener(const OTableContainerListener&);
      59             :     void operator =(const OTableContainerListener&);
      60             : protected:
      61           0 :     virtual ~OTableContainerListener(){}
      62             : public:
      63           0 :     OTableContainerListener(OTableHelper* _pComponent) : m_pComponent(_pComponent){}
      64           0 :     virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (RuntimeException)
      65             :     {
      66           0 :     }
      67           0 :     virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (RuntimeException)
      68             :     {
      69           0 :         ::rtl::OUString sName;
      70           0 :         Event.Accessor  >>= sName;
      71           0 :         if ( m_aRefNames.find(sName) != m_aRefNames.end() )
      72           0 :             m_pComponent->refreshKeys();
      73           0 :     }
      74           0 :     virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw (RuntimeException)
      75             :     {
      76           0 :         ::rtl::OUString sOldComposedName,sNewComposedName;
      77           0 :         Event.ReplacedElement   >>= sOldComposedName;
      78           0 :         Event.Accessor          >>= sNewComposedName;
      79           0 :         if ( sOldComposedName != sNewComposedName && m_aRefNames.find(sOldComposedName) != m_aRefNames.end() )
      80           0 :             m_pComponent->refreshKeys();
      81           0 :     }
      82             :     // XEventListener
      83           0 :     virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException)
      84             :     {
      85           0 :     }
      86           0 :     void clear() { m_pComponent = NULL; }
      87           0 :     inline void add(const ::rtl::OUString& _sRefName) { m_aRefNames.insert(::std::map< ::rtl::OUString,bool>::value_type(_sRefName,true)); }
      88             : };
      89             : }
      90             : namespace connectivity
      91             : {
      92           0 :     ::rtl::OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const ::rtl::OUString& i_sSetting)
      93             :     {
      94           0 :         ::rtl::OUString sSupportService;
      95           0 :         Any aValue;
      96           0 :         if ( ::dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) )
      97             :         {
      98           0 :             aValue >>= sSupportService;
      99             :         }
     100           0 :         return sSupportService;
     101             :     }
     102           0 :     struct OTableHelperImpl
     103             :     {
     104             :         TKeyMap  m_aKeys;
     105             :         // helper services which can be provided by extensions
     106             :         Reference< ::com::sun::star::sdb::tools::XTableRename>      m_xRename;
     107             :         Reference< ::com::sun::star::sdb::tools::XTableAlteration>  m_xAlter;
     108             :         Reference< ::com::sun::star::sdb::tools::XKeyAlteration>    m_xKeyAlter;
     109             :         Reference< ::com::sun::star::sdb::tools::XIndexAlteration>  m_xIndexAlter;
     110             : 
     111             :         Reference< ::com::sun::star::sdbc::XDatabaseMetaData >      m_xMetaData;
     112             :         Reference< ::com::sun::star::sdbc::XConnection >            m_xConnection;
     113             :         ::comphelper::ImplementationReference< OTableContainerListener,XContainerListener>
     114             :                                     m_xTablePropertyListener;
     115             :         ::std::vector< ColumnDesc > m_aColumnDesc;
     116           4 :         OTableHelperImpl(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection)
     117           4 :             : m_xConnection(_xConnection)
     118             :         {
     119             :             try
     120             :             {
     121           4 :                 m_xMetaData = m_xConnection->getMetaData();
     122           4 :                 Reference<XMultiServiceFactory> xFac(_xConnection,UNO_QUERY);
     123           4 :                 if ( xFac.is() )
     124             :                 {
     125           0 :                     static const ::rtl::OUString s_sTableRename(RTL_CONSTASCII_USTRINGPARAM("TableRenameServiceName"));
     126           0 :                     m_xRename.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sTableRename)),UNO_QUERY);
     127           0 :                     static const ::rtl::OUString s_sTableAlteration(RTL_CONSTASCII_USTRINGPARAM("TableAlterationServiceName"));
     128           0 :                     m_xAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sTableAlteration)),UNO_QUERY);
     129           0 :                     static const ::rtl::OUString s_sKeyAlteration(RTL_CONSTASCII_USTRINGPARAM("KeyAlterationServiceName"));
     130           0 :                     m_xKeyAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sKeyAlteration)),UNO_QUERY);
     131           0 :                     static const ::rtl::OUString s_sIndexAlteration(RTL_CONSTASCII_USTRINGPARAM("IndexAlterationServiceName"));
     132           0 :                     m_xIndexAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sIndexAlteration)),UNO_QUERY);
     133           4 :                 }
     134             :             }
     135           0 :             catch(const Exception&)
     136             :             {
     137             :             }
     138           4 :         }
     139             :     };
     140             : }
     141             : 
     142           0 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
     143             :                            const Reference< XConnection >& _xConnection,
     144             :                            sal_Bool _bCase)
     145             :     :OTable_TYPEDEF(_pTables,_bCase)
     146           0 :     ,m_pImpl(new OTableHelperImpl(_xConnection))
     147             : {
     148           0 : }
     149             : // -------------------------------------------------------------------------
     150           4 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
     151             :                             const Reference< XConnection >& _xConnection,
     152             :                             sal_Bool _bCase,
     153             :                             const ::rtl::OUString& _Name,
     154             :                             const ::rtl::OUString& _Type,
     155             :                             const ::rtl::OUString& _Description ,
     156             :                             const ::rtl::OUString& _SchemaName,
     157             :                             const ::rtl::OUString& _CatalogName
     158             :                         ) : OTable_TYPEDEF(_pTables,
     159             :                                             _bCase,
     160             :                                             _Name,
     161             :                                           _Type,
     162             :                                           _Description,
     163             :                                           _SchemaName,
     164             :                                           _CatalogName)
     165           4 :                         ,m_pImpl(new OTableHelperImpl(_xConnection))
     166             : {
     167           4 : }
     168             : // -----------------------------------------------------------------------------
     169           0 : OTableHelper::~OTableHelper()
     170             : {
     171           0 : }
     172             : // -----------------------------------------------------------------------------
     173           0 : void SAL_CALL OTableHelper::disposing()
     174             : {
     175           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     176           0 :     if ( m_pImpl->m_xTablePropertyListener.is() )
     177             :     {
     178           0 :         m_pTables->removeContainerListener(m_pImpl->m_xTablePropertyListener.getRef());
     179           0 :         m_pImpl->m_xTablePropertyListener->clear();
     180           0 :         m_pImpl->m_xTablePropertyListener.dispose();
     181             :     }
     182           0 :     OTable_TYPEDEF::disposing();
     183             : 
     184           0 :     m_pImpl->m_xConnection  = NULL;
     185           0 :     m_pImpl->m_xMetaData    = NULL;
     186             : 
     187           0 : }
     188             : 
     189             : // -------------------------------------------------------------------------
     190             : namespace
     191             : {
     192             :     /** collects ColumnDesc's from a resultset produced by XDatabaseMetaData::getColumns
     193             :     */
     194           4 :     void lcl_collectColumnDescs_throw( const Reference< XResultSet >& _rxResult, ::std::vector< ColumnDesc >& _out_rColumns )
     195             :     {
     196           4 :         Reference< XRow > xRow( _rxResult, UNO_QUERY_THROW );
     197           4 :         ::rtl::OUString sName;
     198           4 :         OrdinalPosition nOrdinalPosition( 0 );
     199         156 :         while ( _rxResult->next() )
     200             :         {
     201         148 :             sName = xRow->getString( 4 );           // COLUMN_NAME
     202         148 :             sal_Int32       nField5 = xRow->getInt(5);
     203         148 :             ::rtl::OUString aField6 = xRow->getString(6);
     204         148 :             sal_Int32       nField7 = xRow->getInt(7)
     205         148 :                         ,   nField9 = xRow->getInt(9)
     206         148 :                         ,   nField11= xRow->getInt(11);
     207         148 :             ::rtl::OUString  sField12 = xRow->getString(12)
     208         148 :                             ,sField13 = xRow->getString(13);
     209         148 :             nOrdinalPosition = xRow->getInt( 17 );  // ORDINAL_POSITION
     210         148 :             _out_rColumns.push_back( ColumnDesc( sName,nField5,aField6,nField7,nField9,nField11,sField12,sField13, nOrdinalPosition ) );
     211         152 :         }
     212           4 :     }
     213             : 
     214             :     /** checks a given array of ColumnDesc's whether it has reasonable ordinal positions. If not,
     215             :         they will be normalized to be the array index.
     216             :     */
     217           4 :     void lcl_sanitizeColumnDescs( ::std::vector< ColumnDesc >& _rColumns )
     218             :     {
     219           4 :         if ( _rColumns.empty() )
     220             :             return;
     221             : 
     222             :         // collect all used ordinals
     223           4 :         ::std::set< OrdinalPosition > aUsedOrdinals;
     224         456 :         for (   ::std::vector< ColumnDesc >::iterator collect = _rColumns.begin();
     225         304 :                 collect != _rColumns.end();
     226             :                 ++collect
     227             :             )
     228         148 :             aUsedOrdinals.insert( collect->nOrdinalPosition );
     229             : 
     230             :         // we need to have as much different ordinals as we have different columns
     231           4 :         bool bDuplicates = aUsedOrdinals.size() != _rColumns.size();
     232             :         // and it needs to be a continuous range
     233           4 :         size_t nOrdinalsRange = *aUsedOrdinals.rbegin() - *aUsedOrdinals.begin() + 1;
     234           4 :         bool bGaps = nOrdinalsRange != _rColumns.size();
     235             : 
     236             :         // if that's not the case, normalize it
     237           4 :         if ( bGaps || bDuplicates )
     238             :         {
     239             :             OSL_FAIL( "lcl_sanitizeColumnDescs: database did provide invalid ORDINAL_POSITION values!" );
     240             : 
     241           0 :             OrdinalPosition nNormalizedPosition = 1;
     242           0 :             for (   ::std::vector< ColumnDesc >::iterator normalize = _rColumns.begin();
     243           0 :                     normalize != _rColumns.end();
     244             :                     ++normalize
     245             :                 )
     246           0 :                 normalize->nOrdinalPosition = nNormalizedPosition++;
     247             :             return;
     248             :         }
     249             : 
     250             :         // what's left is that the range might not be from 1 to <column count>, but for instance
     251             :         // 0 to <column count>-1.
     252           4 :         size_t nOffset = *aUsedOrdinals.begin() - 1;
     253         456 :         for (   ::std::vector< ColumnDesc >::iterator offset = _rColumns.begin();
     254         304 :                 offset != _rColumns.end();
     255             :                 ++offset
     256             :             )
     257         152 :             offset->nOrdinalPosition -= nOffset;
     258             :     }
     259             : }
     260             : 
     261             : // -------------------------------------------------------------------------
     262           4 : void OTableHelper::refreshColumns()
     263             : {
     264           4 :     TStringVector aVector;
     265           4 :     if(!isNew())
     266             :     {
     267           4 :         Any aCatalog;
     268           4 :         if ( !m_CatalogName.isEmpty() )
     269           0 :             aCatalog <<= m_CatalogName;
     270             : 
     271           8 :         ::utl::SharedUNOComponent< XResultSet > xResult( getMetaData()->getColumns(
     272             :             aCatalog,
     273             :             m_SchemaName,
     274             :             m_Name,
     275             :             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"))
     276           4 :         ) );
     277             : 
     278             :         // collect the column names, together with their ordinal position
     279           4 :         m_pImpl->m_aColumnDesc.clear();
     280           4 :         lcl_collectColumnDescs_throw( xResult, m_pImpl->m_aColumnDesc );
     281             : 
     282             :         // ensure that the ordinal positions as obtained from the meta data do make sense
     283           4 :         lcl_sanitizeColumnDescs( m_pImpl->m_aColumnDesc );
     284             : 
     285             :         // sort by ordinal position
     286           4 :         ::std::map< OrdinalPosition, ::rtl::OUString > aSortedColumns;
     287         456 :         for (   ::std::vector< ColumnDesc >::const_iterator copy = m_pImpl->m_aColumnDesc.begin();
     288         304 :                 copy != m_pImpl->m_aColumnDesc.end();
     289             :                 ++copy
     290             :             )
     291         148 :             aSortedColumns[ copy->nOrdinalPosition ] = copy->sName;
     292             : 
     293             :         // copy them to aVector, now that we have the proper ordering
     294             :         ::std::transform(
     295             :             aSortedColumns.begin(),
     296             :             aSortedColumns.end(),
     297             :             ::std::insert_iterator< TStringVector >( aVector, aVector.begin() ),
     298             :             ::o3tl::select2nd< ::std::map< OrdinalPosition, ::rtl::OUString >::value_type >()
     299           4 :         );
     300             :     }
     301             : 
     302           4 :     if(m_pColumns)
     303           0 :         m_pColumns->reFill(aVector);
     304             :     else
     305           4 :         m_pColumns  = createColumns(aVector);
     306           4 : }
     307             : // -----------------------------------------------------------------------------
     308           0 : const ColumnDesc* OTableHelper::getColumnDescription(const ::rtl::OUString& _sName) const
     309             : {
     310           0 :     const ColumnDesc* pRet = NULL;
     311           0 :     ::std::vector< ColumnDesc >::const_iterator aEnd = m_pImpl->m_aColumnDesc.end();
     312           0 :     for (::std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter)
     313             :     {
     314           0 :         if ( aIter->sName == _sName )
     315             :         {
     316           0 :             pRet = &*aIter;
     317           0 :             break;
     318             :         }
     319             :     } // for (::std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter)
     320           0 :     return pRet;
     321             : }
     322             : // -------------------------------------------------------------------------
     323           0 : void OTableHelper::refreshPrimaryKeys(TStringVector& _rNames)
     324             : {
     325           0 :     Any aCatalog;
     326           0 :     if ( !m_CatalogName.isEmpty() )
     327           0 :         aCatalog <<= m_CatalogName;
     328           0 :     Reference< XResultSet > xResult = getMetaData()->getPrimaryKeys(aCatalog,m_SchemaName,m_Name);
     329             : 
     330           0 :     if ( xResult.is() )
     331             :     {
     332           0 :         sdbcx::TKeyProperties pKeyProps(new sdbcx::KeyProperties(::rtl::OUString(),KeyType::PRIMARY,0,0));
     333           0 :         ::rtl::OUString aPkName;
     334           0 :         bool bAlreadyFetched = false;
     335           0 :         const Reference< XRow > xRow(xResult,UNO_QUERY);
     336           0 :         while ( xResult->next() )
     337             :         {
     338           0 :             pKeyProps->m_aKeyColumnNames.push_back(xRow->getString(4));
     339           0 :             if ( !bAlreadyFetched )
     340             :             {
     341           0 :                 aPkName = xRow->getString(6);
     342           0 :                 bAlreadyFetched = true;
     343             :             }
     344             :         }
     345             : 
     346           0 :         m_pImpl->m_aKeys.insert(TKeyMap::value_type(aPkName,pKeyProps));
     347           0 :         _rNames.push_back(aPkName);
     348             :     } // if ( xResult.is() && xResult->next() )
     349           0 :     ::comphelper::disposeComponent(xResult);
     350           0 : }
     351             : // -------------------------------------------------------------------------
     352           0 : void OTableHelper::refreshForeignKeys(TStringVector& _rNames)
     353             : {
     354           0 :     Any aCatalog;
     355           0 :     if ( !m_CatalogName.isEmpty() )
     356           0 :         aCatalog <<= m_CatalogName;
     357           0 :     Reference< XResultSet > xResult = getMetaData()->getImportedKeys(aCatalog,m_SchemaName,m_Name);
     358           0 :     Reference< XRow > xRow(xResult,UNO_QUERY);
     359             : 
     360           0 :     if ( xRow.is() )
     361             :     {
     362           0 :         sdbcx::TKeyProperties pKeyProps;
     363           0 :         ::rtl::OUString aName,sCatalog,aSchema,sOldFKName;
     364           0 :         while( xResult->next() )
     365             :         {
     366             :             // this must be outsid the "if" because we have to call in a right order
     367           0 :             sCatalog    = xRow->getString(1);
     368           0 :             if ( xRow->wasNull() )
     369           0 :                 sCatalog = ::rtl::OUString();
     370           0 :             aSchema     = xRow->getString(2);
     371           0 :             aName       = xRow->getString(3);
     372             : 
     373           0 :             const ::rtl::OUString sForeignKeyColumn = xRow->getString(8);
     374           0 :             const sal_Int32 nUpdateRule = xRow->getInt(10);
     375           0 :             const sal_Int32 nDeleteRule = xRow->getInt(11);
     376           0 :             const ::rtl::OUString sFkName = xRow->getString(12);
     377             : 
     378           0 :                 if ( pKeyProps.get() )
     379             :                 {
     380             :                 }
     381             : 
     382             : 
     383           0 :             if ( !sFkName.isEmpty() && !xRow->wasNull() )
     384             :             {
     385           0 :                 if ( sOldFKName != sFkName )
     386             :                 {
     387           0 :                     if ( pKeyProps.get() )
     388           0 :                         m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
     389             : 
     390           0 :                     const ::rtl::OUString sReferencedName = ::dbtools::composeTableName(getMetaData(),sCatalog,aSchema,aName,sal_False,::dbtools::eInDataManipulation);
     391           0 :                     pKeyProps.reset(new sdbcx::KeyProperties(sReferencedName,KeyType::FOREIGN,nUpdateRule,nDeleteRule));
     392           0 :                     pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn);
     393           0 :                     _rNames.push_back(sFkName);
     394           0 :                     if ( m_pTables->hasByName(sReferencedName) )
     395             :                     {
     396           0 :                         if ( !m_pImpl->m_xTablePropertyListener.is() )
     397           0 :                             m_pImpl->m_xTablePropertyListener = ::comphelper::ImplementationReference< OTableContainerListener,XContainerListener>( new OTableContainerListener(this) );
     398           0 :                         m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.getRef());
     399           0 :                         m_pImpl->m_xTablePropertyListener->add(sReferencedName);
     400             :                     } // if ( m_pTables->hasByName(sReferencedName) )
     401           0 :                     sOldFKName = sFkName;
     402             :                 } // if ( sOldFKName != sFkName )
     403           0 :                 else if ( pKeyProps.get() )
     404             :                 {
     405           0 :                     pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn);
     406             :                 }
     407             :             }
     408           0 :         } // while( xResult->next() )
     409           0 :         if ( pKeyProps.get() )
     410           0 :             m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
     411           0 :         ::comphelper::disposeComponent(xResult);
     412           0 :     }
     413           0 : }
     414             : // -------------------------------------------------------------------------
     415           0 : void OTableHelper::refreshKeys()
     416             : {
     417           0 :     m_pImpl->m_aKeys.clear();
     418             : 
     419           0 :     TStringVector aNames;
     420             : 
     421           0 :     if(!isNew())
     422             :     {
     423           0 :         refreshPrimaryKeys(aNames);
     424           0 :         refreshForeignKeys(aNames);
     425           0 :         m_pKeys = createKeys(aNames);
     426             :     } // if(!isNew())
     427           0 :     else if (!m_pKeys )
     428           0 :         m_pKeys = createKeys(aNames);
     429             :     /*if(m_pKeys)
     430             :         m_pKeys->reFill(aVector);
     431             :     else*/
     432             : 
     433           0 : }
     434             : // -------------------------------------------------------------------------
     435           0 : void OTableHelper::refreshIndexes()
     436             : {
     437           0 :     TStringVector aVector;
     438           0 :     if(!isNew())
     439             :     {
     440             :         // fill indexes
     441           0 :         Any aCatalog;
     442           0 :         if ( !m_CatalogName.isEmpty() )
     443           0 :             aCatalog <<= m_CatalogName;
     444           0 :         Reference< XResultSet > xResult = getMetaData()->getIndexInfo(aCatalog,m_SchemaName,m_Name,sal_False,sal_False);
     445             : 
     446           0 :         if(xResult.is())
     447             :         {
     448           0 :             Reference< XRow > xRow(xResult,UNO_QUERY);
     449           0 :             ::rtl::OUString aName;
     450           0 :             ::rtl::OUString sCatalogSep = getMetaData()->getCatalogSeparator();
     451           0 :             ::rtl::OUString sPreviousRoundName;
     452           0 :             while( xResult->next() )
     453             :             {
     454           0 :                 aName = xRow->getString(5);
     455           0 :                 if(!aName.isEmpty())
     456           0 :                     aName += sCatalogSep;
     457           0 :                 aName += xRow->getString(6);
     458           0 :                 if ( !aName.isEmpty() )
     459             :                 {
     460             :                     // don't insert the name if the last one we inserted was the same
     461           0 :                     if (sPreviousRoundName != aName)
     462           0 :                         aVector.push_back(aName);
     463             :                 }
     464           0 :                 sPreviousRoundName = aName;
     465             :             }
     466           0 :             ::comphelper::disposeComponent(xResult);
     467           0 :         }
     468             :     }
     469             : 
     470           0 :     if(m_pIndexes)
     471           0 :         m_pIndexes->reFill(aVector);
     472             :     else
     473           0 :         m_pIndexes  = createIndexes(aVector);
     474           0 : }
     475             : // -----------------------------------------------------------------------------
     476           0 : ::rtl::OUString OTableHelper::getRenameStart() const
     477             : {
     478           0 :     ::rtl::OUString sSql(RTL_CONSTASCII_USTRINGPARAM("RENAME "));
     479           0 :     if ( m_Type == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW")) )
     480           0 :         sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" VIEW "));
     481             :     else
     482           0 :         sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" TABLE "));
     483             : 
     484           0 :     return sSql;
     485             : }
     486             : // -------------------------------------------------------------------------
     487             : // XRename
     488           0 : void SAL_CALL OTableHelper::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException)
     489             : {
     490           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     491             :     checkDisposed(
     492             : #ifdef GCC
     493             :         ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
     494             : #else
     495             :         rBHelper.bDisposed
     496             : #endif
     497           0 :         );
     498             : 
     499           0 :     if(!isNew())
     500             :     {
     501           0 :         if ( m_pImpl->m_xRename.is() )
     502             :         {
     503           0 :             m_pImpl->m_xRename->rename(this,newName);
     504             :         }
     505             :         else
     506             :         {
     507           0 :             ::rtl::OUString sSql = getRenameStart();
     508           0 :             ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString(  );
     509             : 
     510           0 :             ::rtl::OUString sCatalog,sSchema,sTable;
     511           0 :             ::dbtools::qualifiedNameComponents(getMetaData(),newName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
     512             : 
     513           0 :             ::rtl::OUString sComposedName;
     514           0 :             sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,sal_True,::dbtools::eInDataManipulation);
     515             :             sSql += sComposedName
     516           0 :                  + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" TO "));
     517           0 :             sComposedName = ::dbtools::composeTableName(getMetaData(),sCatalog,sSchema,sTable,sal_True,::dbtools::eInDataManipulation);
     518           0 :             sSql += sComposedName;
     519             : 
     520           0 :             Reference< XStatement > xStmt = m_pImpl->m_xConnection->createStatement(  );
     521           0 :             if ( xStmt.is() )
     522             :             {
     523           0 :                 xStmt->execute(sSql);
     524           0 :                 ::comphelper::disposeComponent(xStmt);
     525           0 :             }
     526             :         }
     527             : 
     528           0 :         OTable_TYPEDEF::rename(newName);
     529             :     }
     530             :     else
     531           0 :         ::dbtools::qualifiedNameComponents(getMetaData(),newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInTableDefinitions);
     532           0 : }
     533             : // -----------------------------------------------------------------------------
     534           8 : Reference< XDatabaseMetaData> OTableHelper::getMetaData() const
     535             : {
     536           8 :     return m_pImpl->m_xMetaData;
     537             : }
     538             : // -------------------------------------------------------------------------
     539           0 : void SAL_CALL OTableHelper::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
     540             : {
     541           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     542             :     checkDisposed(
     543             : #ifdef GCC
     544             :         ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
     545             : #else
     546             :         rBHelper.bDisposed
     547             : #endif
     548           0 :         );
     549             : 
     550           0 :     Reference< XPropertySet > xOld;
     551           0 :     if(::cppu::extractInterface(xOld,m_pColumns->getByIndex(index)) && xOld.is())
     552           0 :         alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
     553           0 : }
     554             : 
     555             : // -------------------------------------------------------------------------
     556           4 : ::rtl::OUString SAL_CALL OTableHelper::getName() throw(RuntimeException)
     557             : {
     558           4 :     ::rtl::OUString sComposedName;
     559           4 :     sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,sal_False,::dbtools::eInDataManipulation);
     560           4 :     return sComposedName;
     561             : }
     562             : // -----------------------------------------------------------------------------
     563          80 : void SAL_CALL OTableHelper::acquire() throw()
     564             : {
     565          80 :     OTable_TYPEDEF::acquire();
     566          80 : }
     567             : // -----------------------------------------------------------------------------
     568          60 : void SAL_CALL OTableHelper::release() throw()
     569             : {
     570          60 :     OTable_TYPEDEF::release();
     571          60 : }
     572             : // -----------------------------------------------------------------------------
     573           0 : sdbcx::TKeyProperties OTableHelper::getKeyProperties(const ::rtl::OUString& _sName) const
     574             : {
     575           0 :     sdbcx::TKeyProperties pKeyProps;
     576           0 :     TKeyMap::const_iterator aFind = m_pImpl->m_aKeys.find(_sName);
     577           0 :     if ( aFind != m_pImpl->m_aKeys.end() )
     578             :     {
     579           0 :         pKeyProps = aFind->second;
     580             :     }
     581             :     else // only a fall back
     582             :     {
     583             :         OSL_FAIL("No key with the given name found");
     584           0 :         pKeyProps.reset(new sdbcx::KeyProperties());
     585             :     }
     586             : 
     587           0 :     return pKeyProps;
     588             : }
     589             : // -----------------------------------------------------------------------------
     590           0 : void OTableHelper::addKey(const ::rtl::OUString& _sName,const sdbcx::TKeyProperties& _aKeyProperties)
     591             : {
     592           0 :     m_pImpl->m_aKeys.insert(TKeyMap::value_type(_sName,_aKeyProperties));
     593           0 : }
     594             : // -----------------------------------------------------------------------------
     595           0 : ::rtl::OUString OTableHelper::getTypeCreatePattern() const
     596             : {
     597           0 :     return ::rtl::OUString();
     598             : }
     599             : // -----------------------------------------------------------------------------
     600           0 : Reference< XConnection> OTableHelper::getConnection() const
     601             : {
     602           0 :     return m_pImpl->m_xConnection;
     603             : }
     604             : // -----------------------------------------------------------------------------
     605           0 : Reference< ::com::sun::star::sdb::tools::XTableRename>      OTableHelper::getRenameService() const
     606             : {
     607           0 :     return m_pImpl->m_xRename;
     608             : }
     609             : // -----------------------------------------------------------------------------
     610           0 : Reference< ::com::sun::star::sdb::tools::XTableAlteration>  OTableHelper::getAlterService() const
     611             : {
     612           0 :     return m_pImpl->m_xAlter;
     613             : }
     614             : // -----------------------------------------------------------------------------
     615           0 : Reference< ::com::sun::star::sdb::tools::XKeyAlteration>  OTableHelper::getKeyService() const
     616             : {
     617           0 :     return m_pImpl->m_xKeyAlter;
     618             : }
     619             : // -----------------------------------------------------------------------------
     620           0 : Reference< ::com::sun::star::sdb::tools::XIndexAlteration>  OTableHelper::getIndexService() const
     621             : {
     622           0 :     return m_pImpl->m_xIndexAlter;
     623             : }
     624             : // -----------------------------------------------------------------------------
     625             : 
     626             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10