LCOV - code coverage report
Current view: top level - connectivity/source/commontools - warningscontainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 33 33.3 %
Date: 2015-06-13 12:38:46 Functions: 2 7 28.6 %
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             : 
      21             : #include <connectivity/warningscontainer.hxx>
      22             : #include <connectivity/dbexception.hxx>
      23             : 
      24             : #include <osl/diagnose.h>
      25             : 
      26             : 
      27             : namespace dbtools
      28             : {
      29             : 
      30             : 
      31             :     using namespace ::com::sun::star::uno;
      32             :     using namespace ::com::sun::star::sdbc;
      33             :     using namespace ::com::sun::star::sdb;
      34             : 
      35           0 :     static void lcl_concatWarnings( Any& _rChainLeft, const Any& _rChainRight )
      36             :     {
      37           0 :         if ( !_rChainLeft.hasValue() )
      38           0 :             _rChainLeft = _rChainRight;
      39             :         else
      40             :         {
      41             :             // to travel the chain by reference (and not by value), we need the getValue ...
      42             :             // looks like a hack, but the meaning of getValue is documented, and it's the only chance for reference-traveling ....
      43             : 
      44             :             OSL_ENSURE( SQLExceptionInfo( _rChainLeft ).isValid(),
      45             :                 "lcl_concatWarnings: invalid warnings chain (this will crash)!" );
      46             : 
      47           0 :             const SQLException* pChainTravel = static_cast< const SQLException* >( _rChainLeft.getValue() );
      48           0 :             SQLExceptionIteratorHelper aReferenceIterHelper( *pChainTravel );
      49           0 :             while ( aReferenceIterHelper.hasMoreElements() )
      50           0 :                 pChainTravel = aReferenceIterHelper.next();
      51             : 
      52             :             // reached the end of the chain, and pChainTravel points to the last element
      53           0 :             const_cast< SQLException* >( pChainTravel )->NextException = _rChainRight;
      54             :         }
      55           0 :     }
      56             : 
      57             : 
      58           0 :     void WarningsContainer::appendWarning(const SQLException& _rWarning)
      59             :     {
      60           0 :         lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) );
      61           0 :     }
      62             : 
      63             : 
      64           0 :     void WarningsContainer::appendWarning( const SQLContext& _rContext )
      65             :     {
      66           0 :         lcl_concatWarnings( m_aOwnWarnings, makeAny( _rContext ));
      67           0 :     }
      68             : 
      69             : 
      70           0 :     void WarningsContainer::appendWarning(const SQLWarning& _rWarning)
      71             :     {
      72           0 :         lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) );
      73           0 :     }
      74             : 
      75             : 
      76           7 :     Any SAL_CALL WarningsContainer::getWarnings(  ) const
      77             :     {
      78           7 :         Any aAllWarnings;
      79           7 :         if ( m_xExternalWarnings.is() )
      80           6 :             aAllWarnings = m_xExternalWarnings->getWarnings();
      81             : 
      82           7 :         if ( m_aOwnWarnings.hasValue() )
      83           0 :             lcl_concatWarnings( aAllWarnings, m_aOwnWarnings );
      84             : 
      85           7 :         return aAllWarnings;
      86             :     }
      87             : 
      88             : 
      89          44 :     void SAL_CALL WarningsContainer::clearWarnings(  )
      90             :     {
      91          44 :         if ( m_xExternalWarnings.is() )
      92           4 :             m_xExternalWarnings->clearWarnings();
      93          44 :         m_aOwnWarnings.clear();
      94          44 :     }
      95             : 
      96             : 
      97           0 :     void WarningsContainer::appendWarning( const OUString& _rWarning, const sal_Char* _pAsciiSQLState, const Reference< XInterface >& _rxContext )
      98             :     {
      99           0 :         appendWarning( SQLWarning( _rWarning, _rxContext, OUString::createFromAscii( _pAsciiSQLState ), 0, Any() ) );
     100           0 :     }
     101             : 
     102             : 
     103             : }   // namespace dbtools
     104             : 
     105             : 
     106             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11