LCOV - code coverage report
Current view: top level - dbaccess/source/ui/relationdesign - RTableConnectionData.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 216 0.0 %
Date: 2012-08-25 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 548 0.0 %

           Branch data     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 "RTableConnectionData.hxx"
      21                 :            : #include <tools/debug.hxx>
      22                 :            : #include <com/sun/star/sdbc/KeyRule.hpp>
      23                 :            : #include <com/sun/star/sdbcx/KeyType.hpp>
      24                 :            : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      25                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      26                 :            : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      27                 :            : #include <com/sun/star/sdbcx/XAppend.hpp>
      28                 :            : #include <com/sun/star/sdbcx/XDrop.hpp>
      29                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      30                 :            : #include "dbustrings.hrc"
      31                 :            : #include "dbu_rel.hrc"
      32                 :            : #include "UITools.hxx"
      33                 :            : #include "moduledbu.hxx"
      34                 :            : #include <connectivity/dbexception.hxx>
      35                 :            : #include <connectivity/dbtools.hxx>
      36                 :            : 
      37                 :            : using namespace dbaui;
      38                 :            : using namespace ::com::sun::star::sdbc;
      39                 :            : using namespace ::com::sun::star::sdbcx;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::beans;
      42                 :            : using namespace ::com::sun::star::container;
      43                 :            : using namespace ::com::sun::star::lang;
      44                 :            : 
      45                 :            : DBG_NAME(ORelationTableConnectionData)
      46                 :            : //========================================================================
      47                 :            : // class ORelationTableConnectionData
      48                 :            : //========================================================================
      49                 :            : //------------------------------------------------------------------------
      50                 :          0 : ORelationTableConnectionData::ORelationTableConnectionData()
      51                 :            :     :OTableConnectionData()
      52                 :            :     ,m_nUpdateRules(KeyRule::NO_ACTION)
      53                 :            :     ,m_nDeleteRules(KeyRule::NO_ACTION)
      54         [ #  # ]:          0 :     ,m_nCardinality(CARDINAL_UNDEFINED)
      55                 :            : {
      56                 :            :     DBG_CTOR(ORelationTableConnectionData,NULL);
      57                 :          0 : }
      58                 :            : //------------------------------------------------------------------------
      59                 :          0 : ORelationTableConnectionData::ORelationTableConnectionData( const TTableWindowData::value_type& _pReferencingTable,
      60                 :            :                                                             const TTableWindowData::value_type& _pReferencedTable,
      61                 :            :                                                             const ::rtl::OUString& rConnName )
      62                 :            :     :OTableConnectionData( _pReferencingTable, _pReferencedTable )
      63                 :            :     ,m_nUpdateRules(KeyRule::NO_ACTION)
      64                 :            :     ,m_nDeleteRules(KeyRule::NO_ACTION)
      65 [ #  # ][ #  # ]:          0 :     ,m_nCardinality(CARDINAL_UNDEFINED)
      66                 :            : {
      67                 :            :     DBG_CTOR(ORelationTableConnectionData,NULL);
      68         [ #  # ]:          0 :     m_aConnName = rConnName;
      69                 :            : 
      70         [ #  # ]:          0 :     if ( m_aConnName.Len() )
      71         [ #  # ]:          0 :         SetCardinality();
      72                 :          0 : }
      73                 :            : 
      74                 :            : //------------------------------------------------------------------------
      75                 :          0 : ORelationTableConnectionData::ORelationTableConnectionData( const ORelationTableConnectionData& rConnData )
      76         [ #  # ]:          0 :     :OTableConnectionData( rConnData )
      77                 :            : {
      78                 :            :     DBG_CTOR(ORelationTableConnectionData,NULL);
      79         [ #  # ]:          0 :     *this = rConnData;
      80                 :          0 : }
      81                 :            : 
      82                 :            : //------------------------------------------------------------------------
      83         [ #  # ]:          0 : ORelationTableConnectionData::~ORelationTableConnectionData()
      84                 :            : {
      85                 :            :     DBG_DTOR(ORelationTableConnectionData,NULL);
      86         [ #  # ]:          0 : }
      87                 :            : 
      88                 :            : //------------------------------------------------------------------------
      89                 :          0 : sal_Bool ORelationTableConnectionData::DropRelation()
      90                 :            : {
      91                 :            :     DBG_CHKTHIS(ORelationTableConnectionData,NULL);
      92         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
      93                 :            :     ////////////////////////////////////////////////////////////
      94                 :            :     // Relation loeschen
      95 [ #  # ][ #  # ]:          0 :     Reference< XIndexAccess> xKeys = getReferencingTable()->getKeys();
                 [ #  # ]
      96 [ #  # ][ #  # ]:          0 :     if( m_aConnName.Len() && xKeys.is() )
                 [ #  # ]
      97                 :            :     {
      98 [ #  # ][ #  # ]:          0 :         const sal_Int32 nCount = xKeys->getCount();
      99         [ #  # ]:          0 :         for(sal_Int32 i = 0;i < nCount;++i)
     100                 :            :         {
     101 [ #  # ][ #  # ]:          0 :             Reference< XPropertySet> xKey(xKeys->getByIndex(i),UNO_QUERY);
                 [ #  # ]
     102                 :            :             OSL_ENSURE(xKey.is(),"Key is not valid!");
     103         [ #  # ]:          0 :             if(xKey.is())
     104                 :            :             {
     105                 :          0 :                 ::rtl::OUString sName;
     106 [ #  # ][ #  # ]:          0 :                 xKey->getPropertyValue(PROPERTY_NAME) >>= sName;
                 [ #  # ]
     107 [ #  # ][ #  # ]:          0 :                 if(String(sName) == m_aConnName)
         [ #  # ][ #  # ]
     108                 :            :                 {
     109         [ #  # ]:          0 :                     Reference< XDrop> xDrop(xKeys,UNO_QUERY);
     110                 :            :                     OSL_ENSURE(xDrop.is(),"can't drop key because we haven't a drop interface!");
     111         [ #  # ]:          0 :                     if(xDrop.is())
     112 [ #  # ][ #  # ]:          0 :                         xDrop->dropByIndex(i);
     113                 :          0 :                     break;
     114         [ #  # ]:          0 :                 }
     115                 :            :             }
     116         [ #  # ]:          0 :         }
     117                 :            :     }
     118         [ #  # ]:          0 :     return sal_True;
     119                 :            : }
     120                 :            : 
     121                 :            : //------------------------------------------------------------------------
     122                 :          0 : void ORelationTableConnectionData::ChangeOrientation()
     123                 :            : {
     124                 :            :     DBG_CHKTHIS(ORelationTableConnectionData,NULL);
     125                 :            :     //////////////////////////////////////////////////////////////////////
     126                 :            :     // Source- und DestFieldName der Linien austauschen
     127                 :          0 :     ::rtl::OUString sTempString;
     128                 :          0 :     OConnectionLineDataVec::iterator aIter = m_vConnLineData.begin();
     129                 :          0 :     OConnectionLineDataVec::iterator aEnd = m_vConnLineData.end();
     130 [ #  # ][ #  # ]:          0 :     for(;aIter != aEnd;++aIter)
     131                 :            :     {
     132                 :          0 :         sTempString = (*aIter)->GetSourceFieldName();
     133                 :          0 :         (*aIter)->SetSourceFieldName( (*aIter)->GetDestFieldName() );
     134                 :          0 :         (*aIter)->SetDestFieldName( sTempString );
     135                 :            :     }
     136                 :            : 
     137                 :            :     //////////////////////////////////////////////////////////////////////
     138                 :            :     // Member anpassen
     139         [ #  # ]:          0 :     TTableWindowData::value_type pTemp = m_pReferencingTable;
     140         [ #  # ]:          0 :     m_pReferencingTable = m_pReferencedTable;
     141 [ #  # ][ #  # ]:          0 :     m_pReferencedTable = pTemp;
     142                 :          0 : }
     143                 :            : 
     144                 :            : //------------------------------------------------------------------------
     145                 :          0 : void ORelationTableConnectionData::SetCardinality()
     146                 :            : {
     147                 :            :     DBG_CHKTHIS(ORelationTableConnectionData,NULL);
     148         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     149                 :          0 :     m_nCardinality = CARDINAL_UNDEFINED;
     150                 :            : 
     151 [ #  # ][ #  # ]:          0 :     if( IsSourcePrimKey() )
     152                 :            :     {
     153 [ #  # ][ #  # ]:          0 :         if( IsDestPrimKey() )
     154                 :          0 :             m_nCardinality = CARDINAL_ONE_ONE;
     155                 :            :         else
     156                 :          0 :             m_nCardinality = CARDINAL_ONE_MANY;
     157                 :            :     }
     158                 :            : 
     159 [ #  # ][ #  # ]:          0 :     if( IsDestPrimKey() )
     160                 :            :     {
     161 [ #  # ][ #  # ]:          0 :         if( !IsSourcePrimKey() )
     162                 :          0 :             m_nCardinality = CARDINAL_MANY_ONE;
     163         [ #  # ]:          0 :     }
     164                 :            : 
     165                 :          0 : }
     166                 :            : // -----------------------------------------------------------------------------
     167                 :          0 : sal_Bool ORelationTableConnectionData::checkPrimaryKey(const Reference< XPropertySet>& i_xTable,EConnectionSide _eEConnectionSide) const
     168                 :            : {
     169                 :            :     // check if Table has the primary key column dependig on _eEConnectionSide
     170                 :          0 :     sal_uInt16  nPrimKeysCount      = 0,
     171                 :          0 :             nValidLinesCount    = 0;
     172         [ #  # ]:          0 :     const Reference< XNameAccess> xKeyColumns = dbtools::getPrimaryKeyColumns_throw(i_xTable);
     173         [ #  # ]:          0 :     if ( xKeyColumns.is() )
     174                 :            :     {
     175 [ #  # ][ #  # ]:          0 :         Sequence< ::rtl::OUString> aKeyColumns = xKeyColumns->getElementNames();
     176                 :          0 :         const ::rtl::OUString* pKeyIter = aKeyColumns.getConstArray();
     177                 :          0 :         const ::rtl::OUString* pKeyEnd  = pKeyIter + aKeyColumns.getLength();
     178                 :            : 
     179         [ #  # ]:          0 :         for(;pKeyIter != pKeyEnd;++pKeyIter)
     180                 :            :         {
     181                 :          0 :             OConnectionLineDataVec::const_iterator aIter = m_vConnLineData.begin();
     182                 :          0 :             OConnectionLineDataVec::const_iterator aEnd = m_vConnLineData.end();
     183 [ #  # ][ #  # ]:          0 :             for(;aIter != aEnd;++aIter)
     184                 :            :             {
     185                 :          0 :                 ++nValidLinesCount;
     186         [ #  # ]:          0 :                 if ( (*aIter)->GetFieldName(_eEConnectionSide) == *pKeyIter )
     187                 :            :                 {
     188                 :          0 :                     ++nPrimKeysCount;
     189                 :          0 :                     break;
     190                 :            :                 }
     191                 :            :             }
     192                 :            :         }
     193         [ #  # ]:          0 :         if ( nPrimKeysCount != aKeyColumns.getLength() )
     194 [ #  # ][ #  # ]:          0 :             return sal_False;
     195                 :            :     }
     196 [ #  # ][ #  # ]:          0 :     if ( !nPrimKeysCount || nPrimKeysCount != nValidLinesCount )
     197                 :          0 :         return sal_False;
     198                 :            : 
     199                 :          0 :     return sal_True;
     200                 :            : }
     201                 :            : //------------------------------------------------------------------------
     202                 :          0 : sal_Bool ORelationTableConnectionData::IsConnectionPossible()
     203                 :            : {
     204                 :            :     DBG_CHKTHIS(ORelationTableConnectionData,NULL);
     205         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     206                 :            : 
     207                 :            :     //////////////////////////////////////////////////////////////////////
     208                 :            :     // Wenn die SourceFelder ein PrimKey sind, ist nur die Orientierung falsch
     209 [ #  # ][ #  # ]:          0 :     if ( IsSourcePrimKey() && !IsDestPrimKey() )
         [ #  # ][ #  # ]
                 [ #  # ]
     210         [ #  # ]:          0 :         ChangeOrientation();
     211                 :            : 
     212         [ #  # ]:          0 :     return sal_True;
     213                 :            : }
     214                 :            : 
     215                 :            : //------------------------------------------------------------------------
     216                 :          0 : OConnectionLineDataRef ORelationTableConnectionData::CreateLineDataObj()
     217                 :            : {
     218         [ #  # ]:          0 :     return new OConnectionLineData();
     219                 :            : }
     220                 :            : 
     221                 :            : //------------------------------------------------------------------------
     222                 :          0 : OConnectionLineDataRef ORelationTableConnectionData::CreateLineDataObj( const OConnectionLineData& rConnLineData )
     223                 :            : {
     224         [ #  # ]:          0 :     return new OConnectionLineData( rConnLineData );
     225                 :            : }
     226                 :            : 
     227                 :            : //------------------------------------------------------------------------
     228                 :          0 : void ORelationTableConnectionData::CopyFrom(const OTableConnectionData& rSource)
     229                 :            : {
     230                 :            :     // wie in der Basisklasse zurueckziehen auf das (nicht-virtuelle) operator=
     231                 :          0 :     *this = *static_cast<const ORelationTableConnectionData*>(&rSource);
     232                 :          0 : }
     233                 :            : 
     234                 :            : //------------------------------------------------------------------------
     235                 :          0 : ORelationTableConnectionData& ORelationTableConnectionData::operator=( const ORelationTableConnectionData& rConnData )
     236                 :            : {
     237         [ #  # ]:          0 :     if (&rConnData == this)
     238                 :          0 :         return *this;
     239                 :            : 
     240                 :          0 :     OTableConnectionData::operator=( rConnData );
     241                 :          0 :     m_nUpdateRules = rConnData.GetUpdateRules();
     242                 :          0 :     m_nDeleteRules = rConnData.GetDeleteRules();
     243                 :          0 :     m_nCardinality = rConnData.GetCardinality();
     244                 :            : 
     245                 :          0 :     return *this;
     246                 :            : }
     247                 :            : namespace dbaui
     248                 :            : {
     249                 :            : //-------------------------------------------------------------------------
     250                 :          0 : bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs)
     251                 :            : {
     252                 :            :     bool bEqual = (lhs.m_nUpdateRules == rhs.m_nUpdateRules)
     253                 :            :         && (lhs.m_nDeleteRules == rhs.m_nDeleteRules)
     254                 :            :         && (lhs.m_nCardinality == rhs.m_nCardinality)
     255 [ #  # ][ #  # ]:          0 :         && (lhs.getReferencingTable() == rhs.getReferencingTable())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     256 [ #  # ][ #  # ]:          0 :         && (lhs.getReferencedTable() == rhs.getReferencedTable())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     257         [ #  # ]:          0 :         && (lhs.m_aConnName == rhs.m_aConnName)
     258 [ #  # ][ #  # ]:          0 :         && (lhs.m_vConnLineData.size() == rhs.m_vConnLineData.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     259                 :            : 
     260         [ #  # ]:          0 :     if ( bEqual )
     261                 :            :     {
     262                 :          0 :         std::vector< OConnectionLineDataRef >::const_iterator aIter = lhs.m_vConnLineData.begin();
     263                 :          0 :         std::vector< OConnectionLineDataRef >::const_iterator aEnd = lhs.m_vConnLineData.end();
     264 [ #  # ][ #  # ]:          0 :         for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
     265                 :            :         {
     266 [ #  # ][ #  # ]:          0 :             if ( *(rhs.m_vConnLineData[i]) != **aIter )
     267                 :          0 :                 break;
     268                 :            :         }
     269         [ #  # ]:          0 :         bEqual = aIter == aEnd;
     270                 :            :     }
     271                 :          0 :     return bEqual;
     272                 :            : }
     273                 :            : }
     274                 :            : //------------------------------------------------------------------------
     275                 :          0 : sal_Bool ORelationTableConnectionData::Update()
     276                 :            : {
     277         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     278                 :            :     ////////////////////////////////////////////////////////////
     279                 :            :     // Alte Relation loeschen
     280                 :            :     {
     281         [ #  # ]:          0 :         DropRelation();
     282 [ #  # ][ #  # ]:          0 :         if( !IsConnectionPossible() )
     283                 :          0 :             return sal_False;
     284                 :            :     }
     285                 :            : 
     286                 :            :     // reassign the keys because the orientaion could be changed
     287 [ #  # ][ #  # ]:          0 :     Reference<XPropertySet> xTableProp(getReferencingTable()->getTable());
                 [ #  # ]
     288 [ #  # ][ #  # ]:          0 :     Reference< XIndexAccess> xKeys ( getReferencingTable()->getKeys());
                 [ #  # ]
     289                 :            : 
     290         [ #  # ]:          0 :     if ( !xKeys.is() )
     291                 :          0 :         return sal_False;
     292                 :            :     ////////////////////////////////////////////////////////////
     293                 :            :     // Neue Relation erzeugen
     294         [ #  # ]:          0 :     Reference<XDataDescriptorFactory> xKeyFactory(xKeys,UNO_QUERY);
     295                 :            :     OSL_ENSURE(xKeyFactory.is(),"No XDataDescriptorFactory Interface!");
     296         [ #  # ]:          0 :     Reference<XAppend> xAppend(xKeyFactory,UNO_QUERY);
     297                 :            :     OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
     298                 :            : 
     299 [ #  # ][ #  # ]:          0 :     Reference<XPropertySet> xKey = xKeyFactory->createDataDescriptor();
     300                 :            :     OSL_ENSURE(xKey.is(),"Key is null!");
     301 [ #  # ][ #  # ]:          0 :     if ( xKey.is() && xTableProp.is() )
                 [ #  # ]
     302                 :            :     {
     303                 :            :         // build a foreign key name
     304                 :          0 :         ::rtl::OUString sSourceName;
     305 [ #  # ][ #  # ]:          0 :         xTableProp->getPropertyValue(PROPERTY_NAME) >>= sSourceName;
                 [ #  # ]
     306                 :          0 :         ::rtl::OUString sKeyName = sSourceName;
     307 [ #  # ][ #  # ]:          0 :         sKeyName += getReferencedTable()->GetTableName();
     308                 :            : 
     309 [ #  # ][ #  # ]:          0 :         xKey->setPropertyValue(PROPERTY_NAME,makeAny(sKeyName));
         [ #  # ][ #  # ]
     310 [ #  # ][ #  # ]:          0 :         xKey->setPropertyValue(PROPERTY_TYPE,makeAny(KeyType::FOREIGN));
         [ #  # ][ #  # ]
     311 [ #  # ][ #  # ]:          0 :         xKey->setPropertyValue(PROPERTY_REFERENCEDTABLE,makeAny(::rtl::OUString(getReferencedTable()->GetTableName())));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     312 [ #  # ][ #  # ]:          0 :         xKey->setPropertyValue(PROPERTY_UPDATERULE, makeAny(GetUpdateRules()));
         [ #  # ][ #  # ]
     313 [ #  # ][ #  # ]:          0 :         xKey->setPropertyValue(PROPERTY_DELETERULE, makeAny(GetDeleteRules()));
         [ #  # ][ #  # ]
     314                 :            :     }
     315                 :            : 
     316         [ #  # ]:          0 :     Reference<XColumnsSupplier> xColSup(xKey,UNO_QUERY);
     317         [ #  # ]:          0 :     if ( xColSup.is() )
     318                 :            :     {
     319 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xColumns = xColSup->getColumns();
     320         [ #  # ]:          0 :         Reference<XDataDescriptorFactory> xColumnFactory(xColumns,UNO_QUERY);
     321         [ #  # ]:          0 :         Reference<XAppend> xColumnAppend(xColumns,UNO_QUERY);
     322         [ #  # ]:          0 :         if ( xColumnFactory.is() )
     323                 :            :         {
     324                 :          0 :             OConnectionLineDataVec::iterator aIter = m_vConnLineData.begin();
     325                 :          0 :             OConnectionLineDataVec::iterator aEnd = m_vConnLineData.end();
     326 [ #  # ][ #  # ]:          0 :             for(;aIter != aEnd;++aIter)
     327                 :            :             {
     328 [ #  # ][ #  # ]:          0 :                 if(!((*aIter)->GetSourceFieldName().isEmpty() || (*aIter)->GetDestFieldName().isEmpty()))
         [ #  # ][ #  # ]
                 [ #  # ]
     329                 :            :                 {
     330                 :          0 :                     Reference<XPropertySet> xColumn;
     331 [ #  # ][ #  # ]:          0 :                     xColumn = xColumnFactory->createDataDescriptor();
                 [ #  # ]
     332         [ #  # ]:          0 :                     if ( xColumn.is() )
     333                 :            :                     {
     334 [ #  # ][ #  # ]:          0 :                         xColumn->setPropertyValue(PROPERTY_NAME,makeAny((*aIter)->GetSourceFieldName()));
         [ #  # ][ #  # ]
     335 [ #  # ][ #  # ]:          0 :                         xColumn->setPropertyValue(PROPERTY_RELATEDCOLUMN,makeAny((*aIter)->GetDestFieldName()));
         [ #  # ][ #  # ]
     336 [ #  # ][ #  # ]:          0 :                         xColumnAppend->appendByDescriptor(xColumn);
     337                 :          0 :                     }
     338                 :            :                 }
     339                 :            :             }
     340                 :            : 
     341 [ #  # ][ #  # ]:          0 :             if ( xColumns->hasElements() )
                 [ #  # ]
     342 [ #  # ][ #  # ]:          0 :                 xAppend->appendByDescriptor(xKey);
     343                 :          0 :         }
     344                 :            :         // to get the key we have to reget it because after append it is no longer valid
     345                 :            :     }
     346                 :            : 
     347                 :            :     // get the name of foreign key // search for columns
     348         [ #  # ]:          0 :     m_aConnName = ::rtl::OUString();
     349                 :          0 : xKey.clear();
     350                 :          0 :     bool bDropRelation = false;
     351 [ #  # ][ #  # ]:          0 :     for(sal_Int32 i=0;i<xKeys->getCount();++i)
                 [ #  # ]
     352                 :            :     {
     353 [ #  # ][ #  # ]:          0 :         xKeys->getByIndex(i) >>= xKey;
                 [ #  # ]
     354                 :            :         OSL_ENSURE(xKey.is(),"Key is not valid!");
     355         [ #  # ]:          0 :         if ( xKey.is() )
     356                 :            :         {
     357                 :          0 :             sal_Int32 nType = 0;
     358 [ #  # ][ #  # ]:          0 :             xKey->getPropertyValue(PROPERTY_TYPE) >>= nType;
                 [ #  # ]
     359                 :          0 :             ::rtl::OUString sReferencedTable;
     360 [ #  # ][ #  # ]:          0 :             xKey->getPropertyValue(PROPERTY_REFERENCEDTABLE) >>= sReferencedTable;
                 [ #  # ]
     361 [ #  # ][ #  # ]:          0 :             if ( sReferencedTable == ::rtl::OUString(getReferencedTable()->GetTableName()) )
                 [ #  # ]
     362                 :            :             {
     363         [ #  # ]:          0 :                 xColSup.set(xKey,UNO_QUERY_THROW);
     364                 :            :                 try
     365                 :            :                 {
     366 [ #  # ][ #  # ]:          0 :                     Reference<XNameAccess> xColumns = xColSup->getColumns();
     367 [ #  # ][ #  # ]:          0 :                     Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
     368                 :          0 :                     const ::rtl::OUString* pIter = aNames.getConstArray();
     369                 :          0 :                     const ::rtl::OUString* pEnd = pIter + aNames.getLength();
     370                 :            : 
     371                 :          0 :                     Reference<XPropertySet> xColumn;
     372                 :          0 :                     ::rtl::OUString sName,sRelatedColumn;
     373         [ #  # ]:          0 :                     for ( ; pIter != pEnd ; ++pIter )
     374                 :            :                     {
     375 [ #  # ][ #  # ]:          0 :                         xColumn.set(xColumns->getByName(*pIter),UNO_QUERY_THROW);
                 [ #  # ]
     376 [ #  # ][ #  # ]:          0 :                         xColumn->getPropertyValue(PROPERTY_NAME)            >>= sName;
                 [ #  # ]
     377 [ #  # ][ #  # ]:          0 :                         xColumn->getPropertyValue(PROPERTY_RELATEDCOLUMN)   >>= sRelatedColumn;
                 [ #  # ]
     378                 :            : 
     379                 :          0 :                         OConnectionLineDataVec::iterator aIter = m_vConnLineData.begin();
     380                 :          0 :                         OConnectionLineDataVec::iterator aEnd = m_vConnLineData.end();
     381 [ #  # ][ #  # ]:          0 :                         for(;aIter != aEnd;++aIter)
     382                 :            :                         {
     383   [ #  #  #  # ]:          0 :                             if(    (*aIter)->GetSourceFieldName() == sName
         [ #  # ][ #  # ]
     384         [ #  # ]:          0 :                                 && (*aIter)->GetDestFieldName() == sRelatedColumn )
     385                 :            :                             {
     386                 :          0 :                                 break;
     387                 :            :                             }
     388                 :            :                         }
     389 [ #  # ][ #  # ]:          0 :                         if ( aIter == m_vConnLineData.end() )
     390                 :            :                             break;
     391                 :            :                     }
     392         [ #  # ]:          0 :                     if ( pIter == pEnd )
     393                 :            :                     {
     394 [ #  # ][ #  # ]:          0 :                         xKey->getPropertyValue(PROPERTY_NAME) >>= sName;
                 [ #  # ]
     395         [ #  # ]:          0 :                         m_aConnName = sName;
     396                 :          0 :                         bDropRelation = aNames.getLength() == 0; // the key contains no column, so it isn't valid and we have to drop it
     397                 :            :                         //here we already know our column structure so we don't have to recreate the table connection data
     398                 :          0 :                         xColSup.clear();
     399                 :            :                         break;
     400 [ #  # ][ #  # ]:          0 :                     }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     401                 :            :                 }
     402         [ #  # ]:          0 :                 catch(Exception&)
     403                 :            :                 {
     404                 :            :                 }
     405         [ #  # ]:          0 :             }
     406                 :            :         }
     407                 :          0 :     xKey.clear();
     408                 :            :     }
     409         [ #  # ]:          0 :     if ( bDropRelation )
     410                 :            :     {
     411         [ #  # ]:          0 :         DropRelation();
     412 [ #  # ][ #  # ]:          0 :         String sError(ModuleRes(STR_QUERY_REL_COULD_NOT_CREATE));
     413 [ #  # ][ #  # ]:          0 :         ::dbtools::throwGenericSQLException(sError,NULL);
         [ #  # ][ #  # ]
     414                 :            :     }
     415                 :            : 
     416                 :            :     // The fields the relation marks may not be the same as our LineDatas mark after the relation has been updated
     417         [ #  # ]:          0 :     if ( xColSup.is() )
     418                 :            :     {
     419         [ #  # ]:          0 :         OConnectionLineDataVec().swap(m_vConnLineData);
     420 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xColumns = xColSup->getColumns();
     421 [ #  # ][ #  # ]:          0 :         Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
     422                 :          0 :         const ::rtl::OUString* pIter = aNames.getConstArray();
     423                 :          0 :         const ::rtl::OUString* pEnd = pIter + aNames.getLength();
     424                 :            : 
     425         [ #  # ]:          0 :         m_vConnLineData.reserve( aNames.getLength() );
     426                 :          0 :         Reference<XPropertySet> xColumn;
     427                 :          0 :         ::rtl::OUString sName,sRelatedColumn;
     428                 :            : 
     429         [ #  # ]:          0 :         for(;pIter != pEnd;++pIter)
     430                 :            :         {
     431 [ #  # ][ #  # ]:          0 :             xColumns->getByName(*pIter) >>= xColumn;
                 [ #  # ]
     432         [ #  # ]:          0 :             if ( xColumn.is() )
     433                 :            :             {
     434         [ #  # ]:          0 :                 OConnectionLineDataRef pNewData = CreateLineDataObj();
     435                 :            : 
     436 [ #  # ][ #  # ]:          0 :                 xColumn->getPropertyValue(PROPERTY_NAME)            >>= sName;
                 [ #  # ]
     437 [ #  # ][ #  # ]:          0 :                 xColumn->getPropertyValue(PROPERTY_RELATEDCOLUMN)   >>= sRelatedColumn;
                 [ #  # ]
     438                 :            : 
     439                 :          0 :                 pNewData->SetSourceFieldName(sName);
     440                 :          0 :                 pNewData->SetDestFieldName(sRelatedColumn);
     441 [ #  # ][ #  # ]:          0 :                 m_vConnLineData.push_back(pNewData);
     442                 :            :             }
     443         [ #  # ]:          0 :         }
     444                 :            :     }
     445                 :            :     // NOTE : the caller is responsible for updating any other objects referencing the old LineDatas (for instance a ConnLine)
     446                 :            : 
     447                 :            :     ////////////////////////////////////////////////////////////
     448                 :            :     // Kardinalitaet bestimmen
     449         [ #  # ]:          0 :     SetCardinality();
     450                 :            : 
     451         [ #  # ]:          0 :     return sal_True;
     452                 :            : }
     453                 :            : // -----------------------------------------------------------------------------
     454                 :            : 
     455                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10