LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/connectivity/source/commontools - TTableHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 296 24.0 %
Date: 2013-07-09 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< 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 :         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 :         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 OUString& _sRefName) { m_aRefNames.insert(::std::map< OUString,bool>::value_type(_sRefName,true)); }
      88             : };
      89             : }
      90             : namespace connectivity
      91             : {
      92           0 :     OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const OUString& i_sSetting)
      93             :     {
      94           0 :         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           2 :         OTableHelperImpl(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection)
     117           2 :             : m_xConnection(_xConnection)
     118             :         {
     119             :             try
     120             :             {
     121           2 :                 m_xMetaData = m_xConnection->getMetaData();
     122           2 :                 Reference<XMultiServiceFactory> xFac(_xConnection,UNO_QUERY);
     123           2 :                 if ( xFac.is() )
     124             :                 {
     125           0 :                     static const OUString s_sTableRename("TableRenameServiceName");
     126           0 :                     m_xRename.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sTableRename)),UNO_QUERY);
     127           0 :                     static const OUString s_sTableAlteration("TableAlterationServiceName");
     128           0 :                     m_xAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sTableAlteration)),UNO_QUERY);
     129           0 :                     static const OUString s_sKeyAlteration("KeyAlterationServiceName");
     130           0 :                     m_xKeyAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sKeyAlteration)),UNO_QUERY);
     131           0 :                     static const OUString s_sIndexAlteration("IndexAlterationServiceName");
     132           0 :                     m_xIndexAlter.set(xFac->createInstance(lcl_getServiceNameForSetting(m_xConnection,s_sIndexAlteration)),UNO_QUERY);
     133           2 :                 }
     134             :             }
     135           0 :             catch(const Exception&)
     136             :             {
     137             :             }
     138           2 :         }
     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           2 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
     151             :                             const Reference< XConnection >& _xConnection,
     152             :                             sal_Bool _bCase,
     153             :                             const OUString& _Name,
     154             :                             const OUString& _Type,
     155             :                             const OUString& _Description ,
     156             :                             const OUString& _SchemaName,
     157             :                             const OUString& _CatalogName
     158             :                         ) : OTable_TYPEDEF(_pTables,
     159             :                                             _bCase,
     160             :                                             _Name,
     161             :                                           _Type,
     162             :                                           _Description,
     163             :                                           _SchemaName,
     164             :                                           _CatalogName)
     165           2 :                         ,m_pImpl(new OTableHelperImpl(_xConnection))
     166             : {
     167           2 : }
     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           2 :     void lcl_collectColumnDescs_throw( const Reference< XResultSet >& _rxResult, ::std::vector< ColumnDesc >& _out_rColumns )
     195             :     {
     196           2 :         Reference< XRow > xRow( _rxResult, UNO_QUERY_THROW );
     197           4 :         OUString sName;
     198           2 :         OrdinalPosition nOrdinalPosition( 0 );
     199          78 :         while ( _rxResult->next() )
     200             :         {
     201          74 :             sName = xRow->getString( 4 );           // COLUMN_NAME
     202          74 :             sal_Int32       nField5 = xRow->getInt(5);
     203          74 :             OUString aField6 = xRow->getString(6);
     204          74 :             sal_Int32       nField7 = xRow->getInt(7)
     205          74 :                         ,   nField9 = xRow->getInt(9)
     206          74 :                         ,   nField11= xRow->getInt(11);
     207         148 :             OUString  sField12 = xRow->getString(12)
     208         148 :                             ,sField13 = xRow->getString(13);
     209          74 :             nOrdinalPosition = xRow->getInt( 17 );  // ORDINAL_POSITION
     210          74 :             _out_rColumns.push_back( ColumnDesc( sName,nField5,aField6,nField7,nField9,nField11,sField12,sField13, nOrdinalPosition ) );
     211          76 :         }
     212           2 :     }
     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           2 :     void lcl_sanitizeColumnDescs( ::std::vector< ColumnDesc >& _rColumns )
     218             :     {
     219           2 :         if ( _rColumns.empty() )
     220           0 :             return;
     221             : 
     222             :         // collect all used ordinals
     223           2 :         ::std::set< OrdinalPosition > aUsedOrdinals;
     224         228 :         for (   ::std::vector< ColumnDesc >::iterator collect = _rColumns.begin();
     225         152 :                 collect != _rColumns.end();
     226             :                 ++collect
     227             :             )
     228          74 :             aUsedOrdinals.insert( collect->nOrdinalPosition );
     229             : 
     230             :         // we need to have as much different ordinals as we have different columns
     231           2 :         bool bDuplicates = aUsedOrdinals.size() != _rColumns.size();
     232             :         // and it needs to be a continuous range
     233           2 :         size_t nOrdinalsRange = *aUsedOrdinals.rbegin() - *aUsedOrdinals.begin() + 1;
     234           2 :         bool bGaps = nOrdinalsRange != _rColumns.size();
     235             : 
     236             :         // if that's not the case, normalize it
     237           2 :         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           0 :             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           2 :         size_t nOffset = *aUsedOrdinals.begin() - 1;
     253         228 :         for (   ::std::vector< ColumnDesc >::iterator offset = _rColumns.begin();
     254         152 :                 offset != _rColumns.end();
     255             :                 ++offset
     256             :             )
     257          76 :             offset->nOrdinalPosition -= nOffset;
     258             :     }
     259             : }
     260             : 
     261             : // -------------------------------------------------------------------------
     262           2 : void OTableHelper::refreshColumns()
     263             : {
     264           2 :     TStringVector aVector;
     265           2 :     if(!isNew())
     266             :     {
     267           2 :         Any aCatalog;
     268           2 :         if ( !m_CatalogName.isEmpty() )
     269           0 :             aCatalog <<= m_CatalogName;
     270             : 
     271           4 :         ::utl::SharedUNOComponent< XResultSet > xResult( getMetaData()->getColumns(
     272             :             aCatalog,
     273             :             m_SchemaName,
     274             :             m_Name,
     275             :             OUString("%")
     276           4 :         ) );
     277             : 
     278             :         // collect the column names, together with their ordinal position
     279           2 :         m_pImpl->m_aColumnDesc.clear();
     280           2 :         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           2 :         lcl_sanitizeColumnDescs( m_pImpl->m_aColumnDesc );
     284             : 
     285             :         // sort by ordinal position
     286           4 :         ::std::map< OrdinalPosition, OUString > aSortedColumns;
     287         228 :         for (   ::std::vector< ColumnDesc >::const_iterator copy = m_pImpl->m_aColumnDesc.begin();
     288         152 :                 copy != m_pImpl->m_aColumnDesc.end();
     289             :                 ++copy
     290             :             )
     291          74 :             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, OUString >::value_type >()
     299           4 :         );
     300             :     }
     301             : 
     302           2 :     if(m_pColumns)
     303           0 :         m_pColumns->reFill(aVector);
     304             :     else
     305           2 :         m_pColumns  = createColumns(aVector);
     306           2 : }
     307             : // -----------------------------------------------------------------------------
     308           0 : const ColumnDesc* OTableHelper::getColumnDescription(const 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(OUString(),KeyType::PRIMARY,0,0));
     333           0 :         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             :                 SAL_WARN_IF(xRow->wasNull(),"connectivity.commontools", "NULL Primary Key name");
     343             :                 SAL_WARN_IF(aPkName.isEmpty(),"connectivity.commontools", "empty Primary Key name");
     344           0 :                 bAlreadyFetched = true;
     345             :             }
     346             :         }
     347             : 
     348           0 :         if(bAlreadyFetched)
     349             :         {
     350             :             SAL_WARN_IF(aPkName.isEmpty(),"connectivity.commontools", "empty Primary Key name");
     351             :             SAL_WARN_IF(pKeyProps->m_aKeyColumnNames.size() == 0,"connectivity.commontools", "Primary Key has no columns");
     352           0 :             m_pImpl->m_aKeys.insert(TKeyMap::value_type(aPkName,pKeyProps));
     353           0 :             _rNames.push_back(aPkName);
     354           0 :         }
     355             :     } // if ( xResult.is() && xResult->next() )
     356           0 :     ::comphelper::disposeComponent(xResult);
     357           0 : }
     358             : // -------------------------------------------------------------------------
     359           0 : void OTableHelper::refreshForeignKeys(TStringVector& _rNames)
     360             : {
     361           0 :     Any aCatalog;
     362           0 :     if ( !m_CatalogName.isEmpty() )
     363           0 :         aCatalog <<= m_CatalogName;
     364           0 :     Reference< XResultSet > xResult = getMetaData()->getImportedKeys(aCatalog,m_SchemaName,m_Name);
     365           0 :     Reference< XRow > xRow(xResult,UNO_QUERY);
     366             : 
     367           0 :     if ( xRow.is() )
     368             :     {
     369           0 :         sdbcx::TKeyProperties pKeyProps;
     370           0 :         OUString aName,sCatalog,aSchema,sOldFKName;
     371           0 :         while( xResult->next() )
     372             :         {
     373             :             // this must be outsid the "if" because we have to call in a right order
     374           0 :             sCatalog    = xRow->getString(1);
     375           0 :             if ( xRow->wasNull() )
     376           0 :                 sCatalog = OUString();
     377           0 :             aSchema     = xRow->getString(2);
     378           0 :             aName       = xRow->getString(3);
     379             : 
     380           0 :             const OUString sForeignKeyColumn = xRow->getString(8);
     381           0 :             const sal_Int32 nUpdateRule = xRow->getInt(10);
     382           0 :             const sal_Int32 nDeleteRule = xRow->getInt(11);
     383           0 :             const OUString sFkName = xRow->getString(12);
     384             : 
     385           0 :                 if ( pKeyProps.get() )
     386             :                 {
     387             :                 }
     388             : 
     389             : 
     390           0 :             if ( !sFkName.isEmpty() && !xRow->wasNull() )
     391             :             {
     392           0 :                 if ( sOldFKName != sFkName )
     393             :                 {
     394           0 :                     if ( pKeyProps.get() )
     395           0 :                         m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
     396             : 
     397           0 :                     const OUString sReferencedName = ::dbtools::composeTableName(getMetaData(),sCatalog,aSchema,aName,sal_False,::dbtools::eInDataManipulation);
     398           0 :                     pKeyProps.reset(new sdbcx::KeyProperties(sReferencedName,KeyType::FOREIGN,nUpdateRule,nDeleteRule));
     399           0 :                     pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn);
     400           0 :                     _rNames.push_back(sFkName);
     401           0 :                     if ( m_pTables->hasByName(sReferencedName) )
     402             :                     {
     403           0 :                         if ( !m_pImpl->m_xTablePropertyListener.is() )
     404           0 :                             m_pImpl->m_xTablePropertyListener = ::comphelper::ImplementationReference< OTableContainerListener,XContainerListener>( new OTableContainerListener(this) );
     405           0 :                         m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.getRef());
     406           0 :                         m_pImpl->m_xTablePropertyListener->add(sReferencedName);
     407             :                     } // if ( m_pTables->hasByName(sReferencedName) )
     408           0 :                     sOldFKName = sFkName;
     409             :                 } // if ( sOldFKName != sFkName )
     410           0 :                 else if ( pKeyProps.get() )
     411             :                 {
     412           0 :                     pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn);
     413             :                 }
     414             :             }
     415           0 :         } // while( xResult->next() )
     416           0 :         if ( pKeyProps.get() )
     417           0 :             m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
     418           0 :         ::comphelper::disposeComponent(xResult);
     419           0 :     }
     420           0 : }
     421             : // -------------------------------------------------------------------------
     422           0 : void OTableHelper::refreshKeys()
     423             : {
     424           0 :     m_pImpl->m_aKeys.clear();
     425             : 
     426           0 :     TStringVector aNames;
     427             : 
     428           0 :     if(!isNew())
     429             :     {
     430           0 :         refreshPrimaryKeys(aNames);
     431           0 :         refreshForeignKeys(aNames);
     432           0 :         m_pKeys = createKeys(aNames);
     433             :     } // if(!isNew())
     434           0 :     else if (!m_pKeys )
     435           0 :         m_pKeys = createKeys(aNames);
     436             :     /*if(m_pKeys)
     437             :         m_pKeys->reFill(aVector);
     438             :     else*/
     439             : 
     440           0 : }
     441             : // -------------------------------------------------------------------------
     442           0 : void OTableHelper::refreshIndexes()
     443             : {
     444           0 :     TStringVector aVector;
     445           0 :     if(!isNew())
     446             :     {
     447             :         // fill indexes
     448           0 :         Any aCatalog;
     449           0 :         if ( !m_CatalogName.isEmpty() )
     450           0 :             aCatalog <<= m_CatalogName;
     451           0 :         Reference< XResultSet > xResult = getMetaData()->getIndexInfo(aCatalog,m_SchemaName,m_Name,sal_False,sal_False);
     452             : 
     453           0 :         if(xResult.is())
     454             :         {
     455           0 :             Reference< XRow > xRow(xResult,UNO_QUERY);
     456           0 :             OUString aName;
     457           0 :             OUString sCatalogSep = getMetaData()->getCatalogSeparator();
     458           0 :             OUString sPreviousRoundName;
     459           0 :             while( xResult->next() )
     460             :             {
     461           0 :                 aName = xRow->getString(5);
     462           0 :                 if(!aName.isEmpty())
     463           0 :                     aName += sCatalogSep;
     464           0 :                 aName += xRow->getString(6);
     465           0 :                 if ( !aName.isEmpty() )
     466             :                 {
     467             :                     // don't insert the name if the last one we inserted was the same
     468           0 :                     if (sPreviousRoundName != aName)
     469           0 :                         aVector.push_back(aName);
     470             :                 }
     471           0 :                 sPreviousRoundName = aName;
     472             :             }
     473           0 :             ::comphelper::disposeComponent(xResult);
     474           0 :         }
     475             :     }
     476             : 
     477           0 :     if(m_pIndexes)
     478           0 :         m_pIndexes->reFill(aVector);
     479             :     else
     480           0 :         m_pIndexes  = createIndexes(aVector);
     481           0 : }
     482             : // -----------------------------------------------------------------------------
     483           0 : OUString OTableHelper::getRenameStart() const
     484             : {
     485           0 :     OUString sSql("RENAME ");
     486           0 :     if ( m_Type == OUString("VIEW") )
     487           0 :         sSql += OUString(" VIEW ");
     488             :     else
     489           0 :         sSql += OUString(" TABLE ");
     490             : 
     491           0 :     return sSql;
     492             : }
     493             : // -------------------------------------------------------------------------
     494             : // XRename
     495           0 : void SAL_CALL OTableHelper::rename( const OUString& newName ) throw(SQLException, ElementExistException, RuntimeException)
     496             : {
     497           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     498             :     checkDisposed(
     499             : #ifdef __GNUC__
     500             :         ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
     501             : #else
     502             :         rBHelper.bDisposed
     503             : #endif
     504           0 :         );
     505             : 
     506           0 :     if(!isNew())
     507             :     {
     508           0 :         if ( m_pImpl->m_xRename.is() )
     509             :         {
     510           0 :             m_pImpl->m_xRename->rename(this,newName);
     511             :         }
     512             :         else
     513             :         {
     514           0 :             OUString sSql = getRenameStart();
     515             : 
     516           0 :             OUString sCatalog,sSchema,sTable;
     517           0 :             ::dbtools::qualifiedNameComponents(getMetaData(),newName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
     518             : 
     519           0 :             OUString sComposedName;
     520           0 :             sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,sal_True,::dbtools::eInDataManipulation);
     521             :             sSql += sComposedName
     522           0 :                  + OUString(" TO ");
     523           0 :             sComposedName = ::dbtools::composeTableName(getMetaData(),sCatalog,sSchema,sTable,sal_True,::dbtools::eInDataManipulation);
     524           0 :             sSql += sComposedName;
     525             : 
     526           0 :             Reference< XStatement > xStmt = m_pImpl->m_xConnection->createStatement(  );
     527           0 :             if ( xStmt.is() )
     528             :             {
     529           0 :                 xStmt->execute(sSql);
     530           0 :                 ::comphelper::disposeComponent(xStmt);
     531           0 :             }
     532             :         }
     533             : 
     534           0 :         OTable_TYPEDEF::rename(newName);
     535             :     }
     536             :     else
     537           0 :         ::dbtools::qualifiedNameComponents(getMetaData(),newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInTableDefinitions);
     538           0 : }
     539             : // -----------------------------------------------------------------------------
     540           4 : Reference< XDatabaseMetaData> OTableHelper::getMetaData() const
     541             : {
     542           4 :     return m_pImpl->m_xMetaData;
     543             : }
     544             : // -------------------------------------------------------------------------
     545           0 : void SAL_CALL OTableHelper::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
     546             : {
     547           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     548             :     checkDisposed(
     549             : #ifdef __GNUC__
     550             :         ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
     551             : #else
     552             :         rBHelper.bDisposed
     553             : #endif
     554           0 :         );
     555             : 
     556           0 :     Reference< XPropertySet > xOld;
     557           0 :     if(::cppu::extractInterface(xOld,m_pColumns->getByIndex(index)) && xOld.is())
     558           0 :         alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
     559           0 : }
     560             : 
     561             : // -------------------------------------------------------------------------
     562           2 : OUString SAL_CALL OTableHelper::getName() throw(RuntimeException)
     563             : {
     564           2 :     OUString sComposedName;
     565           2 :     sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,sal_False,::dbtools::eInDataManipulation);
     566           2 :     return sComposedName;
     567             : }
     568             : // -----------------------------------------------------------------------------
     569          40 : void SAL_CALL OTableHelper::acquire() throw()
     570             : {
     571          40 :     OTable_TYPEDEF::acquire();
     572          40 : }
     573             : // -----------------------------------------------------------------------------
     574          30 : void SAL_CALL OTableHelper::release() throw()
     575             : {
     576          30 :     OTable_TYPEDEF::release();
     577          30 : }
     578             : // -----------------------------------------------------------------------------
     579           0 : sdbcx::TKeyProperties OTableHelper::getKeyProperties(const OUString& _sName) const
     580             : {
     581           0 :     sdbcx::TKeyProperties pKeyProps;
     582           0 :     TKeyMap::const_iterator aFind = m_pImpl->m_aKeys.find(_sName);
     583           0 :     if ( aFind != m_pImpl->m_aKeys.end() )
     584             :     {
     585           0 :         pKeyProps = aFind->second;
     586             :     }
     587             :     else // only a fall back
     588             :     {
     589             :         OSL_FAIL("No key with the given name found");
     590           0 :         pKeyProps.reset(new sdbcx::KeyProperties());
     591             :     }
     592             : 
     593           0 :     return pKeyProps;
     594             : }
     595             : // -----------------------------------------------------------------------------
     596           0 : void OTableHelper::addKey(const OUString& _sName,const sdbcx::TKeyProperties& _aKeyProperties)
     597             : {
     598           0 :     m_pImpl->m_aKeys.insert(TKeyMap::value_type(_sName,_aKeyProperties));
     599           0 : }
     600             : // -----------------------------------------------------------------------------
     601           0 : OUString OTableHelper::getTypeCreatePattern() const
     602             : {
     603           0 :     return OUString();
     604             : }
     605             : // -----------------------------------------------------------------------------
     606           0 : Reference< XConnection> OTableHelper::getConnection() const
     607             : {
     608           0 :     return m_pImpl->m_xConnection;
     609             : }
     610             : // -----------------------------------------------------------------------------
     611           0 : Reference< ::com::sun::star::sdb::tools::XTableRename>      OTableHelper::getRenameService() const
     612             : {
     613           0 :     return m_pImpl->m_xRename;
     614             : }
     615             : // -----------------------------------------------------------------------------
     616           0 : Reference< ::com::sun::star::sdb::tools::XTableAlteration>  OTableHelper::getAlterService() const
     617             : {
     618           0 :     return m_pImpl->m_xAlter;
     619             : }
     620             : // -----------------------------------------------------------------------------
     621           0 : Reference< ::com::sun::star::sdb::tools::XKeyAlteration>  OTableHelper::getKeyService() const
     622             : {
     623           0 :     return m_pImpl->m_xKeyAlter;
     624             : }
     625             : // -----------------------------------------------------------------------------
     626           0 : Reference< ::com::sun::star::sdb::tools::XIndexAlteration>  OTableHelper::getIndexService() const
     627             : {
     628           0 :     return m_pImpl->m_xIndexAlter;
     629             : }
     630             : // -----------------------------------------------------------------------------
     631             : 
     632             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10