LCOV - code coverage report
Current view: top level - dbaccess/source/core/misc - sdbcoretools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 56 60.7 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 33 104 31.7 %

           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                 :            : 
      21                 :            : #include "sdbcoretools.hxx"
      22                 :            : #include "dbastrings.hrc"
      23                 :            : 
      24                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      25                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      26                 :            : #include <com/sun/star/container/XChild.hpp>
      27                 :            : #include <com/sun/star/util/XModifiable.hpp>
      28                 :            : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      29                 :            : #include <com/sun/star/task/XInteractionRequestStringResolver.hpp>
      30                 :            : #include <com/sun/star/embed/XTransactedObject.hpp>
      31                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      32                 :            : 
      33                 :            : #include <tools/diagnose_ex.h>
      34                 :            : #include <tools/debug.hxx>
      35                 :            : #include <comphelper/componentcontext.hxx>
      36                 :            : #include <comphelper/interaction.hxx>
      37                 :            : #include <rtl/ref.hxx>
      38                 :            : #include <rtl/ustrbuf.hxx>
      39                 :            : 
      40                 :            : //.........................................................................
      41                 :            : namespace dbaccess
      42                 :            : {
      43                 :            : //.........................................................................
      44                 :            : 
      45                 :            :     using namespace ::com::sun::star::uno;
      46                 :            :     using namespace ::com::sun::star::lang;
      47                 :            :     using namespace ::com::sun::star::util;
      48                 :            :     using namespace ::com::sun::star::io;
      49                 :            :     using namespace ::com::sun::star::sdbc;
      50                 :            :     using namespace ::com::sun::star::sdb;
      51                 :            :     using namespace ::com::sun::star::beans;
      52                 :            :     using namespace ::com::sun::star::task;
      53                 :            :     using namespace ::com::sun::star::embed;
      54                 :            :     using namespace ::com::sun::star::container;
      55                 :            : 
      56                 :            :     // =========================================================================
      57                 :            :     // -------------------------------------------------------------------------
      58                 :       2838 :     void notifyDataSourceModified(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject,sal_Bool _bModified)
      59                 :            :     {
      60         [ +  - ]:       2838 :         Reference< XInterface > xDs = getDataSource( _rxObject );
      61         [ +  - ]:       2838 :         Reference<XDocumentDataSource> xDocumentDataSource(xDs,UNO_QUERY);
      62         [ +  + ]:       2838 :         if ( xDocumentDataSource.is() )
      63 [ +  - ][ +  - ]:       1988 :             xDs = xDocumentDataSource->getDatabaseDocument();
                 [ +  - ]
      64         [ +  - ]:       2838 :         Reference< XModifiable > xModi( xDs, UNO_QUERY );
      65         [ +  + ]:       2838 :         if ( xModi.is() )
      66 [ +  - ][ +  - ]:       2838 :             xModi->setModified(_bModified);
      67                 :       2838 :     }
      68                 :            : 
      69                 :            :     // -------------------------------------------------------------------------
      70                 :       2954 :     Reference< XInterface > getDataSource( const Reference< XInterface >& _rxDependentObject )
      71                 :            :     {
      72                 :       2954 :         Reference< XInterface > xParent = _rxDependentObject;
      73                 :       2954 :         Reference< XInterface > xReturn;
      74         [ +  + ]:       8922 :         while( xParent.is() )
      75                 :            :         {
      76         [ +  - ]:       5968 :             xReturn = xParent;
      77         [ +  - ]:       5968 :             Reference<XChild> xChild(xParent,UNO_QUERY);
      78 [ +  + ][ +  - ]:       5968 :             xParent.set(xChild.is() ? xChild->getParent() : Reference< XInterface >(),UNO_QUERY);
         [ +  - ][ +  - ]
      79                 :       5968 :         }
      80                 :       2954 :         return xReturn;
      81                 :            :     }
      82                 :            : 
      83                 :            : // -----------------------------------------------------------------------------
      84                 :          0 :     ::rtl::OUString extractExceptionMessage( const ::comphelper::ComponentContext& _rContext, const Any& _rError )
      85                 :            :     {
      86                 :          0 :         ::rtl::OUString sDisplayMessage;
      87                 :            : 
      88                 :            :         try
      89                 :            :         {
      90                 :          0 :             Reference< XInteractionRequestStringResolver > xStringResolver;
      91 [ #  # ][ #  # ]:          0 :             if ( _rContext.createComponent( "com.sun.star.task.InteractionRequestStringResolver", xStringResolver ) )
      92                 :            :             {
      93         [ #  # ]:          0 :                 ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rError ) );
      94         [ #  # ]:          0 :                 ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
      95 [ #  # ][ #  # ]:          0 :                 pRequest->addContinuation( pApprove.get() );
                 [ #  # ]
      96 [ #  # ][ #  # ]:          0 :                 Optional< ::rtl::OUString > aMessage = xStringResolver->getStringFromInformationalRequest( pRequest.get() );
         [ #  # ][ #  # ]
      97         [ #  # ]:          0 :                 if ( aMessage.IsPresent )
      98                 :          0 :                     sDisplayMessage = aMessage.Value;
      99         [ #  # ]:          0 :             }
     100                 :            :         }
     101         [ #  # ]:          0 :         catch( const Exception& )
     102                 :            :         {
     103                 :            :             DBG_UNHANDLED_EXCEPTION();
     104                 :            :         }
     105                 :            : 
     106         [ #  # ]:          0 :         if ( sDisplayMessage.isEmpty() )
     107                 :            :         {
     108         [ #  # ]:          0 :             Exception aExcept;
     109         [ #  # ]:          0 :             _rError >>= aExcept;
     110                 :            : 
     111                 :          0 :             ::rtl::OUStringBuffer aBuffer;
     112         [ #  # ]:          0 :             aBuffer.append( _rError.getValueTypeName() );
     113         [ #  # ]:          0 :             aBuffer.appendAscii( ":\n" );
     114         [ #  # ]:          0 :             aBuffer.append( aExcept.Message );
     115                 :            : 
     116 [ #  # ][ #  # ]:          0 :             sDisplayMessage = aBuffer.makeStringAndClear();
     117                 :            :         }
     118                 :            : 
     119                 :          0 :         return sDisplayMessage;
     120                 :            :     }
     121                 :            : 
     122                 :            :     namespace tools { namespace stor {
     123                 :            : 
     124                 :            :     // -----------------------------------------------------------------------------
     125                 :        616 :     bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
     126                 :            :     {
     127         [ +  + ]:        616 :         if ( !_rxStorage.is() )
     128                 :        208 :             return false;
     129                 :            : 
     130                 :        408 :         sal_Int32 nMode = ElementModes::READ;
     131                 :            :         try
     132                 :            :         {
     133         [ +  - ]:        408 :             Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
     134         [ +  - ]:        408 :             xStorageProps->getPropertyValue(
     135 [ +  - ][ +  - ]:        408 :                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode;
                 [ #  # ]
     136                 :            :         }
     137         [ #  # ]:          0 :         catch( const Exception& )
     138                 :            :         {
     139                 :            :             DBG_UNHANDLED_EXCEPTION();
     140                 :            :         }
     141                 :        616 :         return ( nMode & ElementModes::WRITE ) != 0;
     142                 :            :     }
     143                 :            : 
     144                 :            :     // -----------------------------------------------------------------------------
     145                 :        222 :     bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException ))
     146                 :            :     {
     147                 :        222 :         bool bSuccess = false;
     148         [ +  - ]:        222 :         Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY );
     149         [ +  - ]:        222 :         if ( xTrans.is() )
     150                 :            :         {
     151 [ +  - ][ +  - ]:        222 :             if ( storageIsWritable_nothrow( _rxStorage ) )
     152 [ +  - ][ +  - ]:        222 :                 xTrans->commit();
     153                 :        222 :             bSuccess = true;
     154                 :            :         }
     155                 :        222 :         return bSuccess;
     156                 :            :     }
     157                 :            : 
     158                 :            :     } } // tools::stor
     159                 :            : 
     160                 :            : //.........................................................................
     161                 :            : }   // namespace dbaccess
     162                 :            : //.........................................................................
     163                 :            : 
     164                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10