LCOV - code coverage report
Current view: top level - connectivity/source/commontools - TTableHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 138 296 46.6 %
Date: 2014-11-03 Functions: 18 40 45.0 %
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 <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include <connectivity/TTableHelper.hxx>
      24             : #include <com/sun/star/sdbc/XRow.hpp>
      25             : #include <com/sun/star/sdbc/XResultSet.hpp>
      26             : #include <com/sun/star/sdbcx/KeyType.hpp>
      27             : #include <com/sun/star/sdbc/KeyRule.hpp>
      28             : #include <cppuhelper/typeprovider.hxx>
      29             : #include <com/sun/star/lang/DisposedException.hpp>
      30             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      31             : #include <comphelper/sequence.hxx>
      32             : #include <comphelper/types.hxx>
      33             : #include <connectivity/dbtools.hxx>
      34             : #include <connectivity/sdbcx/VCollection.hxx>
      35             : #include <unotools/sharedunocomponent.hxx>
      36             : #include "TConnection.hxx"
      37             : 
      38             : #include <o3tl/compat_functional.hxx>
      39             : 
      40             : #include <iterator>
      41             : #include <set>
      42             : 
      43             : using namespace ::comphelper;
      44             : using namespace connectivity;
      45             : using namespace ::com::sun::star::uno;
      46             : using namespace ::com::sun::star::beans;
      47             : using namespace ::com::sun::star::sdbcx;
      48             : using namespace ::com::sun::star::sdbc;
      49             : using namespace ::com::sun::star::container;
      50             : using namespace ::com::sun::star::lang;
      51             : namespace
      52             : {
      53             :     /// helper class for column property change events which holds the OComponentDefinition weak
      54             : typedef ::cppu::WeakImplHelper1 < XContainerListener > OTableContainerListener_BASE;
      55             : class OTableContainerListener:
      56             :     public OTableContainerListener_BASE, private boost::noncopyable
      57             : {
      58             :     OTableHelper* m_pComponent;
      59             :     ::std::map< OUString,bool> m_aRefNames;
      60             : 
      61             : protected:
      62           0 :     virtual ~OTableContainerListener(){}
      63             : public:
      64           0 :     OTableContainerListener(OTableHelper* _pComponent) : m_pComponent(_pComponent){}
      65           0 :     virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (RuntimeException, std::exception) SAL_OVERRIDE
      66             :     {
      67           0 :     }
      68           0 :     virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE
      69             :     {
      70           0 :         OUString sName;
      71           0 :         Event.Accessor  >>= sName;
      72           0 :         if ( m_aRefNames.find(sName) != m_aRefNames.end() )
      73           0 :             m_pComponent->refreshKeys();
      74           0 :     }
      75           0 :     virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE
      76             :     {
      77           0 :         OUString sOldComposedName,sNewComposedName;
      78           0 :         Event.ReplacedElement   >>= sOldComposedName;
      79           0 :         Event.Accessor          >>= sNewComposedName;
      80           0 :         if ( sOldComposedName != sNewComposedName && m_aRefNames.find(sOldComposedName) != m_aRefNames.end() )
      81           0 :             m_pComponent->refreshKeys();
      82           0 :     }
      83             :     // XEventListener
      84           0 :     virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException, std::exception) SAL_OVERRIDE
      85             :     {
      86           0 :     }
      87           0 :     void clear() { m_pComponent = NULL; }
      88           0 :     inline void add(const OUString& _sRefName) { m_aRefNames.insert(::std::map< OUString,bool>::value_type(_sRefName,true)); }
      89             : };
      90             : }
      91             : namespace connectivity
      92             : {
      93           0 :     OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const OUString& i_sSetting)
      94             :     {
      95           0 :         OUString sSupportService;
      96           0 :         Any aValue;
      97           0 :         if ( ::dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) )
      98             :         {
      99           0 :             aValue >>= sSupportService;
     100             :         }
     101           0 :         return sSupportService;
     102             :     }
     103           6 :     struct OTableHelperImpl
     104             :     {
     105             :         TKeyMap  m_aKeys;
     106             :         // helper services which can be provided by extensions
     107             :         Reference< ::com::sun::star::sdb::tools::XTableRename>      m_xRename;
     108             :         Reference< ::com::sun::star::sdb::tools::XTableAlteration>  m_xAlter;
     109             :         Reference< ::com::sun::star::sdb::tools::XKeyAlteration>    m_xKeyAlter;
     110             :         Reference< ::com::sun::star::sdb::tools::XIndexAlteration>  m_xIndexAlter;
     111             : 
     112             :         Reference< ::com::sun::star::sdbc::XDatabaseMetaData >      m_xMetaData;
     113             :         Reference< ::com::sun::star::sdbc::XConnection >            m_xConnection;
     114             :         rtl::Reference<OTableContainerListener> m_xTablePropertyListener;
     115             :         ::std::vector< ColumnDesc > m_aColumnDesc;
     116           8 :         OTableHelperImpl(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection)
     117           8 :             : m_xConnection(_xConnection)
     118             :         {
     119             :             try
     120             :             {
     121           8 :                 m_xMetaData = m_xConnection->getMetaData();
     122           8 :                 Reference<XMultiServiceFactory> xFac(_xConnection,UNO_QUERY);
     123           8 :                 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           8 :                 }
     134             :             }
     135           0 :             catch(const Exception&)
     136             :             {
     137             :             }
     138           8 :         }
     139             :     };
     140             : }
     141             : 
     142           0 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
     143             :                            const Reference< XConnection >& _xConnection,
     144             :                            bool _bCase)
     145             :     :OTable_TYPEDEF(_pTables,_bCase)
     146           0 :     ,m_pImpl(new OTableHelperImpl(_xConnection))
     147             : {
     148           0 : }
     149             : 
     150           8 : OTableHelper::OTableHelper( sdbcx::OCollection* _pTables,
     151             :                             const Reference< XConnection >& _xConnection,
     152             :                             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           8 :                         ,m_pImpl(new OTableHelperImpl(_xConnection))
     166             : {
     167           8 : }
     168             : 
     169           6 : OTableHelper::~OTableHelper()
     170             : {
     171           6 : }
     172             : 
     173           6 : void SAL_CALL OTableHelper::disposing()
     174             : {
     175           6 :     ::osl::MutexGuard aGuard(m_aMutex);
     176           6 :     if ( m_pImpl->m_xTablePropertyListener.is() )
     177             :     {
     178           0 :         m_pTables->removeContainerListener(m_pImpl->m_xTablePropertyListener.get());
     179           0 :         m_pImpl->m_xTablePropertyListener->clear();
     180           0 :         m_pImpl->m_xTablePropertyListener.clear();
     181             :     }
     182           6 :     OTable_TYPEDEF::disposing();
     183             : 
     184           6 :     m_pImpl->m_xConnection  = NULL;
     185           6 :     m_pImpl->m_xMetaData    = NULL;
     186             : 
     187           6 : }
     188             : 
     189             : 
     190             : namespace
     191             : {
     192             :     /** collects ColumnDesc's from a resultset produced by XDatabaseMetaData::getColumns
     193             :     */
     194           8 :     void lcl_collectColumnDescs_throw( const Reference< XResultSet >& _rxResult, ::std::vector< ColumnDesc >& _out_rColumns )
     195             :     {
     196           8 :         Reference< XRow > xRow( _rxResult, UNO_QUERY_THROW );
     197          16 :         OUString sName;
     198           8 :         OrdinalPosition nOrdinalPosition( 0 );
     199         182 :         while ( _rxResult->next() )
     200             :         {
     201         166 :             sName = xRow->getString( 4 );           // COLUMN_NAME
     202         166 :             sal_Int32       nField5 = xRow->getInt(5);
     203         166 :             OUString aField6 = xRow->getString(6);
     204         166 :             sal_Int32       nField7 = xRow->getInt(7)
     205         166 :                         ,   nField9 = xRow->getInt(9)
     206         166 :                         ,   nField11= xRow->getInt(11);
     207         332 :             OUString  sField12 = xRow->getString(12)
     208         332 :                             ,sField13 = xRow->getString(13);
     209         166 :             nOrdinalPosition = xRow->getInt( 17 );  // ORDINAL_POSITION
     210         166 :             _out_rColumns.push_back( ColumnDesc( sName,nField5,aField6,nField7,nField9,nField11,sField12,sField13, nOrdinalPosition ) );
     211         174 :         }
     212           8 :     }
     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           8 :     void lcl_sanitizeColumnDescs( ::std::vector< ColumnDesc >& _rColumns )
     218             :     {
     219           8 :         if ( _rColumns.empty() )
     220           0 :             return;
     221             : 
     222             :         // collect all used ordinals
     223           8 :         ::std::set< OrdinalPosition > aUsedOrdinals;
     224         522 :         for (   ::std::vector< ColumnDesc >::iterator collect = _rColumns.begin();
     225         348 :                 collect != _rColumns.end();
     226             :                 ++collect
     227             :             )
     228         166 :             aUsedOrdinals.insert( collect->nOrdinalPosition );
     229             : 
     230             :         // we need to have as much different ordinals as we have different columns
     231           8 :         bool bDuplicates = aUsedOrdinals.size() != _rColumns.size();
     232             :         // and it needs to be a continuous range
     233           8 :         size_t nOrdinalsRange = *aUsedOrdinals.rbegin() - *aUsedOrdinals.begin() + 1;
     234           8 :         bool bGaps = nOrdinalsRange != _rColumns.size();
     235             : 
     236             :         // if that's not the case, normalize it
     237           8 :         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           8 :         size_t nOffset = *aUsedOrdinals.begin() - 1;
     253         522 :         for (   ::std::vector< ColumnDesc >::iterator offset = _rColumns.begin();
     254         348 :                 offset != _rColumns.end();
     255             :                 ++offset
     256             :             )
     257         174 :             offset->nOrdinalPosition -= nOffset;
     258             :     }
     259             : }
     260             : 
     261             : 
     262           8 : void OTableHelper::refreshColumns()
     263             : {
     264           8 :     TStringVector aVector;
     265           8 :     if(!isNew())
     266             :     {
     267           8 :         Any aCatalog;
     268           8 :         if ( !m_CatalogName.isEmpty() )
     269           0 :             aCatalog <<= m_CatalogName;
     270             : 
     271          16 :         ::utl::SharedUNOComponent< XResultSet > xResult( getMetaData()->getColumns(
     272             :             aCatalog,
     273             :             m_SchemaName,
     274             :             m_Name,
     275             :             OUString("%")
     276          16 :         ) );
     277             : 
     278             :         // collect the column names, together with their ordinal position
     279           8 :         m_pImpl->m_aColumnDesc.clear();
     280           8 :         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           8 :         lcl_sanitizeColumnDescs( m_pImpl->m_aColumnDesc );
     284             : 
     285             :         // sort by ordinal position
     286          16 :         ::std::map< OrdinalPosition, OUString > aSortedColumns;
     287         522 :         for (   ::std::vector< ColumnDesc >::const_iterator copy = m_pImpl->m_aColumnDesc.begin();
     288         348 :                 copy != m_pImpl->m_aColumnDesc.end();
     289             :                 ++copy
     290             :             )
     291         166 :             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          16 :         );
     300             :     }
     301             : 
     302           8 :     if(m_pColumns)
     303           0 :         m_pColumns->reFill(aVector);
     304             :     else
     305           8 :         m_pColumns  = createColumns(aVector);
     306           8 : }
     307             : 
     308          18 : const ColumnDesc* OTableHelper::getColumnDescription(const OUString& _sName) const
     309             : {
     310          18 :     const ColumnDesc* pRet = NULL;
     311          18 :     ::std::vector< ColumnDesc >::const_iterator aEnd = m_pImpl->m_aColumnDesc.end();
     312          54 :     for (::std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter)
     313             :     {
     314          54 :         if ( aIter->sName == _sName )
     315             :         {
     316          18 :             pRet = &*aIter;
     317          18 :             break;
     318             :         }
     319             :     } // for (::std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter)
     320          18 :     return pRet;
     321             : }
     322             : 
     323           4 : void OTableHelper::refreshPrimaryKeys(TStringVector& _rNames)
     324             : {
     325           4 :     Any aCatalog;
     326           4 :     if ( !m_CatalogName.isEmpty() )
     327           0 :         aCatalog <<= m_CatalogName;
     328           8 :     Reference< XResultSet > xResult = getMetaData()->getPrimaryKeys(aCatalog,m_SchemaName,m_Name);
     329             : 
     330           4 :     if ( xResult.is() )
     331             :     {
     332           4 :         sdbcx::TKeyProperties pKeyProps(new sdbcx::KeyProperties(OUString(),KeyType::PRIMARY,0,0));
     333           8 :         OUString aPkName;
     334           4 :         bool bAlreadyFetched = false;
     335           8 :         const Reference< XRow > xRow(xResult,UNO_QUERY);
     336          12 :         while ( xResult->next() )
     337             :         {
     338           4 :             pKeyProps->m_aKeyColumnNames.push_back(xRow->getString(4));
     339           4 :             if ( !bAlreadyFetched )
     340             :             {
     341           4 :                 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           4 :                 bAlreadyFetched = true;
     345             :             }
     346             :         }
     347             : 
     348           4 :         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           4 :             m_pImpl->m_aKeys.insert(TKeyMap::value_type(aPkName,pKeyProps));
     353           4 :             _rNames.push_back(aPkName);
     354           4 :         }
     355             :     } // if ( xResult.is() && xResult->next() )
     356           8 :     ::comphelper::disposeComponent(xResult);
     357           4 : }
     358             : 
     359           4 : void OTableHelper::refreshForeignKeys(TStringVector& _rNames)
     360             : {
     361           4 :     Any aCatalog;
     362           4 :     if ( !m_CatalogName.isEmpty() )
     363           0 :         aCatalog <<= m_CatalogName;
     364           8 :     Reference< XResultSet > xResult = getMetaData()->getImportedKeys(aCatalog,m_SchemaName,m_Name);
     365           8 :     Reference< XRow > xRow(xResult,UNO_QUERY);
     366             : 
     367           4 :     if ( xRow.is() )
     368             :     {
     369           4 :         sdbcx::TKeyProperties pKeyProps;
     370           8 :         OUString aName,sCatalog,aSchema,sOldFKName;
     371           8 :         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,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 = new OTableContainerListener(this);
     405           0 :                         m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.get());
     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           4 :         if ( pKeyProps.get() )
     417           0 :             m_pImpl->m_aKeys.insert(TKeyMap::value_type(sOldFKName,pKeyProps));
     418           8 :         ::comphelper::disposeComponent(xResult);
     419           4 :     }
     420           4 : }
     421             : 
     422           4 : void OTableHelper::refreshKeys()
     423             : {
     424           4 :     m_pImpl->m_aKeys.clear();
     425             : 
     426           4 :     TStringVector aNames;
     427             : 
     428           4 :     if(!isNew())
     429             :     {
     430           4 :         refreshPrimaryKeys(aNames);
     431           4 :         refreshForeignKeys(aNames);
     432           4 :         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           4 : }
     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 == "VIEW" )
     487           0 :         sSql += " VIEW ";
     488             :     else
     489           0 :         sSql += " TABLE ";
     490             : 
     491           0 :     return sSql;
     492             : }
     493             : 
     494             : // XRename
     495           0 : void SAL_CALL OTableHelper::rename( const OUString& newName ) throw(SQLException, ElementExistException, RuntimeException, std::exception)
     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,true,::dbtools::eInDataManipulation);
     521             :             sSql += sComposedName
     522           0 :                  + " TO ";
     523           0 :             sComposedName = ::dbtools::composeTableName(getMetaData(),sCatalog,sSchema,sTable,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          20 : Reference< XDatabaseMetaData> OTableHelper::getMetaData() const
     541             : {
     542          20 :     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, std::exception)
     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             :     Reference< XPropertySet > xOld(
     557           0 :         m_pColumns->getByIndex(index), css::uno::UNO_QUERY);
     558           0 :     if(xOld.is())
     559           0 :         alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
     560           0 : }
     561             : 
     562             : 
     563           4 : OUString SAL_CALL OTableHelper::getName() throw(RuntimeException, std::exception)
     564             : {
     565           4 :     OUString sComposedName;
     566           4 :     sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,false,::dbtools::eInDataManipulation);
     567           4 :     return sComposedName;
     568             : }
     569             : 
     570        1504 : void SAL_CALL OTableHelper::acquire() throw()
     571             : {
     572        1504 :     OTable_TYPEDEF::acquire();
     573        1504 : }
     574             : 
     575        1498 : void SAL_CALL OTableHelper::release() throw()
     576             : {
     577        1498 :     OTable_TYPEDEF::release();
     578        1498 : }
     579             : 
     580           4 : sdbcx::TKeyProperties OTableHelper::getKeyProperties(const OUString& _sName) const
     581             : {
     582           4 :     sdbcx::TKeyProperties pKeyProps;
     583           4 :     TKeyMap::const_iterator aFind = m_pImpl->m_aKeys.find(_sName);
     584           4 :     if ( aFind != m_pImpl->m_aKeys.end() )
     585             :     {
     586           4 :         pKeyProps = aFind->second;
     587             :     }
     588             :     else // only a fall back
     589             :     {
     590             :         OSL_FAIL("No key with the given name found");
     591           0 :         pKeyProps.reset(new sdbcx::KeyProperties());
     592             :     }
     593             : 
     594           4 :     return pKeyProps;
     595             : }
     596             : 
     597           0 : void OTableHelper::addKey(const OUString& _sName,const sdbcx::TKeyProperties& _aKeyProperties)
     598             : {
     599           0 :     m_pImpl->m_aKeys.insert(TKeyMap::value_type(_sName,_aKeyProperties));
     600           0 : }
     601             : 
     602           0 : OUString OTableHelper::getTypeCreatePattern() const
     603             : {
     604           0 :     return OUString();
     605             : }
     606             : 
     607          18 : Reference< XConnection> OTableHelper::getConnection() const
     608             : {
     609          18 :     return m_pImpl->m_xConnection;
     610             : }
     611             : 
     612           0 : Reference< ::com::sun::star::sdb::tools::XTableRename>      OTableHelper::getRenameService() const
     613             : {
     614           0 :     return m_pImpl->m_xRename;
     615             : }
     616             : 
     617           0 : Reference< ::com::sun::star::sdb::tools::XTableAlteration>  OTableHelper::getAlterService() const
     618             : {
     619           0 :     return m_pImpl->m_xAlter;
     620             : }
     621             : 
     622           0 : Reference< ::com::sun::star::sdb::tools::XKeyAlteration>  OTableHelper::getKeyService() const
     623             : {
     624           0 :     return m_pImpl->m_xKeyAlter;
     625             : }
     626             : 
     627           0 : Reference< ::com::sun::star::sdb::tools::XIndexAlteration>  OTableHelper::getIndexService() const
     628             : {
     629           0 :     return m_pImpl->m_xIndexAlter;
     630             : }
     631             : 
     632             : 
     633             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10