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

Generated by: LCOV version 1.10