LCOV - code coverage report
Current view: top level - dbaccess/source/core/misc - sdbcoretools.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 53 62.3 %
Date: 2015-06-13 12:38:46 Functions: 4 5 80.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 "sdbcoretools.hxx"
      21             : #include "dbastrings.hrc"
      22             : 
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : #include <com/sun/star/container/XChild.hpp>
      26             : #include <com/sun/star/util/XModifiable.hpp>
      27             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      28             : #include <com/sun/star/task/InteractionRequestStringResolver.hpp>
      29             : #include <com/sun/star/embed/XTransactedObject.hpp>
      30             : #include <com/sun/star/embed/ElementModes.hpp>
      31             : 
      32             : #include <tools/diagnose_ex.h>
      33             : #include <tools/debug.hxx>
      34             : #include <comphelper/interaction.hxx>
      35             : #include <rtl/ref.hxx>
      36             : #include <rtl/ustrbuf.hxx>
      37             : 
      38             : namespace dbaccess
      39             : {
      40             : 
      41             :     using namespace ::com::sun::star::uno;
      42             :     using namespace ::com::sun::star::lang;
      43             :     using namespace ::com::sun::star::util;
      44             :     using namespace ::com::sun::star::io;
      45             :     using namespace ::com::sun::star::sdbc;
      46             :     using namespace ::com::sun::star::sdb;
      47             :     using namespace ::com::sun::star::beans;
      48             :     using namespace ::com::sun::star::task;
      49             :     using namespace ::com::sun::star::embed;
      50             :     using namespace ::com::sun::star::container;
      51             : 
      52        1795 :     void notifyDataSourceModified(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject,bool _bModified)
      53             :     {
      54        1795 :         Reference< XInterface > xDs = getDataSource( _rxObject );
      55        3590 :         Reference<XDocumentDataSource> xDocumentDataSource(xDs,UNO_QUERY);
      56        1795 :         if ( xDocumentDataSource.is() )
      57        1215 :             xDs = xDocumentDataSource->getDatabaseDocument();
      58        3590 :         Reference< XModifiable > xModi( xDs, UNO_QUERY );
      59        1795 :         if ( xModi.is() )
      60        3018 :             xModi->setModified(_bModified);
      61        1795 :     }
      62             : 
      63        2080 :     Reference< XInterface > getDataSource( const Reference< XInterface >& _rxDependentObject )
      64             :     {
      65        2080 :         Reference< XInterface > xParent = _rxDependentObject;
      66        2080 :         Reference< XInterface > xReturn;
      67        8167 :         while( xParent.is() )
      68             :         {
      69        4007 :             xReturn = xParent;
      70        4007 :             Reference<XChild> xChild(xParent,UNO_QUERY);
      71        4007 :             xParent.set(xChild.is() ? xChild->getParent() : Reference< XInterface >(),UNO_QUERY);
      72        4007 :         }
      73        2080 :         return xReturn;
      74             :     }
      75             : 
      76           0 :     OUString extractExceptionMessage( const Reference<XComponentContext> & _rContext, const Any& _rError )
      77             :     {
      78           0 :         OUString sDisplayMessage;
      79             : 
      80             :         try
      81             :         {
      82           0 :             Reference< XInteractionRequestStringResolver > xStringResolver = InteractionRequestStringResolver::create(_rContext);
      83             : 
      84           0 :             ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rError ) );
      85           0 :             ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
      86           0 :             pRequest->addContinuation( pApprove.get() );
      87           0 :             Optional< OUString > aMessage = xStringResolver->getStringFromInformationalRequest( pRequest.get() );
      88           0 :             if ( aMessage.IsPresent )
      89           0 :                 sDisplayMessage = aMessage.Value;
      90             :         }
      91           0 :         catch( const Exception& )
      92             :         {
      93             :             DBG_UNHANDLED_EXCEPTION();
      94             :         }
      95             : 
      96           0 :         if ( sDisplayMessage.isEmpty() )
      97             :         {
      98           0 :             Exception aExcept;
      99           0 :             _rError >>= aExcept;
     100             : 
     101           0 :             OUStringBuffer aBuffer;
     102           0 :             aBuffer.append( _rError.getValueTypeName() );
     103           0 :             aBuffer.appendAscii( ":\n" );
     104           0 :             aBuffer.append( aExcept.Message );
     105             : 
     106           0 :             sDisplayMessage = aBuffer.makeStringAndClear();
     107             :         }
     108             : 
     109           0 :         return sDisplayMessage;
     110             :     }
     111             : 
     112             :     namespace tools { namespace stor {
     113             : 
     114         415 :     bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
     115             :     {
     116         415 :         if ( !_rxStorage.is() )
     117         145 :             return false;
     118             : 
     119         270 :         sal_Int32 nMode = ElementModes::READ;
     120             :         try
     121             :         {
     122         270 :             Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
     123         270 :             xStorageProps->getPropertyValue( "OpenMode" ) >>= nMode;
     124             :         }
     125           0 :         catch( const Exception& )
     126             :         {
     127             :             DBG_UNHANDLED_EXCEPTION();
     128             :         }
     129         270 :         return ( nMode & ElementModes::WRITE ) != 0;
     130             :     }
     131             : 
     132         165 :     bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage )
     133             :     {
     134         165 :         bool bSuccess = false;
     135         165 :         Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY );
     136         165 :         if ( xTrans.is() )
     137             :         {
     138         163 :             if ( storageIsWritable_nothrow( _rxStorage ) )
     139         163 :                 xTrans->commit();
     140         155 :             bSuccess = true;
     141             :         }
     142         157 :         return bSuccess;
     143             :     }
     144             : 
     145             :     } } // tools::stor
     146             : 
     147             : }   // namespace dbaccess
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11