LCOV - code coverage report
Current view: top level - dbaccess/source/core/misc - sdbcoretools.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 53 0.0 %
Date: 2014-04-14 Functions: 0 5 0.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           0 :     void notifyDataSourceModified(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject,sal_Bool _bModified)
      53             :     {
      54           0 :         Reference< XInterface > xDs = getDataSource( _rxObject );
      55           0 :         Reference<XDocumentDataSource> xDocumentDataSource(xDs,UNO_QUERY);
      56           0 :         if ( xDocumentDataSource.is() )
      57           0 :             xDs = xDocumentDataSource->getDatabaseDocument();
      58           0 :         Reference< XModifiable > xModi( xDs, UNO_QUERY );
      59           0 :         if ( xModi.is() )
      60           0 :             xModi->setModified(_bModified);
      61           0 :     }
      62             : 
      63           0 :     Reference< XInterface > getDataSource( const Reference< XInterface >& _rxDependentObject )
      64             :     {
      65           0 :         Reference< XInterface > xParent = _rxDependentObject;
      66           0 :         Reference< XInterface > xReturn;
      67           0 :         while( xParent.is() )
      68             :         {
      69           0 :             xReturn = xParent;
      70           0 :             Reference<XChild> xChild(xParent,UNO_QUERY);
      71           0 :             xParent.set(xChild.is() ? xChild->getParent() : Reference< XInterface >(),UNO_QUERY);
      72           0 :         }
      73           0 :         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           0 :     bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
     115             :     {
     116           0 :         if ( !_rxStorage.is() )
     117           0 :             return false;
     118             : 
     119           0 :         sal_Int32 nMode = ElementModes::READ;
     120             :         try
     121             :         {
     122           0 :             Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
     123           0 :             xStorageProps->getPropertyValue( "OpenMode" ) >>= nMode;
     124             :         }
     125           0 :         catch( const Exception& )
     126             :         {
     127             :             DBG_UNHANDLED_EXCEPTION();
     128             :         }
     129           0 :         return ( nMode & ElementModes::WRITE ) != 0;
     130             :     }
     131             : 
     132           0 :     bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException ))
     133             :     {
     134           0 :         bool bSuccess = false;
     135           0 :         Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY );
     136           0 :         if ( xTrans.is() )
     137             :         {
     138           0 :             if ( storageIsWritable_nothrow( _rxStorage ) )
     139           0 :                 xTrans->commit();
     140           0 :             bSuccess = true;
     141             :         }
     142           0 :         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.10