LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/forms/source/component - cachedrowset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 13 56 23.2 %
Date: 2013-07-09 Functions: 5 11 45.5 %
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 "cachedrowset.hxx"
      22             : #include "services.hxx"
      23             : #include "frm_strings.hxx"
      24             : 
      25             : #include <com/sun/star/lang/XComponent.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      28             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      29             : 
      30             : #include <tools/diagnose_ex.h>
      31             : 
      32             : //........................................................................
      33             : namespace frm
      34             : {
      35             : //........................................................................
      36             : 
      37             :     using ::com::sun::star::uno::Reference;
      38             :     using ::com::sun::star::uno::UNO_QUERY;
      39             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      40             :     using ::com::sun::star::uno::UNO_SET_THROW;
      41             :     using ::com::sun::star::uno::Exception;
      42             :     using ::com::sun::star::uno::RuntimeException;
      43             :     using ::com::sun::star::uno::XComponentContext;
      44             :     using ::com::sun::star::sdbc::XConnection;
      45             :     using ::com::sun::star::lang::XComponent;
      46             :     using ::com::sun::star::beans::XPropertySet;
      47             :     using ::com::sun::star::uno::makeAny;
      48             :     using ::com::sun::star::sdbc::SQLException;
      49             :     using ::com::sun::star::uno::Any;
      50             :     using ::com::sun::star::sdb::XQueriesSupplier;
      51             :     using ::com::sun::star::container::XNameAccess;
      52             :     using ::com::sun::star::sdbc::XResultSet;
      53             :     using ::com::sun::star::sdbc::XStatement;
      54             : 
      55             :     namespace ResultSetType = ::com::sun::star::sdbc::ResultSetType;
      56             : 
      57             :     //====================================================================
      58             :     //= CachedRowSet_Data
      59             :     //====================================================================
      60          40 :     struct CachedRowSet_Data
      61             :     {
      62             :         OUString                 sCommand;
      63             :         sal_Bool                        bEscapeProcessing;
      64             :         Reference< XConnection >        xConnection;
      65             : 
      66             :         bool                            bStatementDirty;
      67             : 
      68          46 :         CachedRowSet_Data()
      69             :             :sCommand()
      70             :             ,bEscapeProcessing( sal_False )
      71             :             ,xConnection()
      72          46 :             ,bStatementDirty( true )
      73             :         {
      74          46 :         }
      75             :     };
      76             : 
      77             :     //====================================================================
      78             :     //= CachedRowSet
      79             :     //====================================================================
      80             :     //--------------------------------------------------------------------
      81          26 :     CachedRowSet::CachedRowSet()
      82          26 :         :m_pData( new CachedRowSet_Data )
      83             :     {
      84          26 :     }
      85             : 
      86             :     //--------------------------------------------------------------------
      87          40 :     CachedRowSet::~CachedRowSet()
      88             :     {
      89          20 :         dispose();
      90          20 :     }
      91             : 
      92             :     //--------------------------------------------------------------------
      93           0 :     void CachedRowSet::setCommand( const OUString& _rCommand )
      94             :     {
      95           0 :         if ( m_pData->sCommand == _rCommand )
      96           0 :             return;
      97             : 
      98           0 :         m_pData->sCommand = _rCommand;
      99           0 :         m_pData->bStatementDirty = true;
     100             :     }
     101             : 
     102             :     //--------------------------------------------------------------------
     103           0 :     void CachedRowSet::setCommandFromQuery( const OUString& _rQueryName )
     104             :     {
     105           0 :         Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW );
     106           0 :         Reference< XNameAccess >      xQueries      ( xSupplyQueries->getQueries(), UNO_QUERY_THROW );
     107           0 :         Reference< XPropertySet >     xQuery        ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW );
     108             : 
     109           0 :         sal_Bool bEscapeProcessing( sal_False );
     110           0 :         OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
     111           0 :         setEscapeProcessing( bEscapeProcessing );
     112             : 
     113           0 :         OUString sCommand;
     114           0 :         OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
     115           0 :         setCommand( sCommand );
     116           0 :     }
     117             : 
     118             :     //--------------------------------------------------------------------
     119           0 :     void CachedRowSet::setEscapeProcessing ( const sal_Bool _bEscapeProcessing )
     120             :     {
     121           0 :         if ( m_pData->bEscapeProcessing == _bEscapeProcessing )
     122           0 :             return;
     123             : 
     124           0 :         m_pData->bEscapeProcessing = _bEscapeProcessing;
     125           0 :         m_pData->bStatementDirty = true;
     126             :     }
     127             : 
     128             :     //--------------------------------------------------------------------
     129           0 :     void CachedRowSet::setConnection( const Reference< XConnection >& _rxConnection )
     130             :     {
     131           0 :         if ( m_pData->xConnection == _rxConnection )
     132           0 :             return;
     133             : 
     134           0 :         m_pData->xConnection = _rxConnection;
     135           0 :         m_pData->bStatementDirty = true;
     136             :     }
     137             : 
     138             :     //--------------------------------------------------------------------
     139           0 :     Reference< XResultSet > CachedRowSet::execute()
     140             :     {
     141           0 :         Reference< XResultSet > xResult;
     142             :         try
     143             :         {
     144             :             OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
     145           0 :             if ( !m_pData->xConnection.is() )
     146           0 :                 return xResult;
     147             : 
     148           0 :             Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW );
     149           0 :             Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW );
     150           0 :             xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( m_pData->bEscapeProcessing ) );
     151           0 :             xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( ResultSetType::FORWARD_ONLY ) );
     152             : 
     153           0 :             xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW );
     154           0 :             m_pData->bStatementDirty = false;
     155             :         }
     156           0 :         catch( const SQLException& )
     157             :         {
     158           0 :             throw;
     159             :         }
     160           0 :         catch( const Exception& )
     161             :         {
     162             :             DBG_UNHANDLED_EXCEPTION();
     163             :         }
     164           0 :         return xResult;
     165             :     }
     166             : 
     167             :     //--------------------------------------------------------------------
     168           0 :     bool CachedRowSet::isDirty() const
     169             :     {
     170           0 :         return m_pData->bStatementDirty;
     171             :     }
     172             : 
     173             :     //--------------------------------------------------------------------
     174          20 :     void CachedRowSet::dispose()
     175             :     {
     176             :         try
     177             :         {
     178          20 :             m_pData.reset( new CachedRowSet_Data );
     179             :         }
     180           0 :         catch( const Exception& )
     181             :         {
     182             :             DBG_UNHANDLED_EXCEPTION();
     183             :         }
     184          20 :     }
     185             : 
     186             : //........................................................................
     187             : } // namespace frm
     188             : //........................................................................
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10