LCOV - code coverage report
Current view: top level - forms/source/component - cachedrowset.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 56 23.2 %
Date: 2014-11-03 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         148 :     struct CachedRowSet_Data
      58             :     {
      59             :         OUString                 sCommand;
      60             :         bool                        bEscapeProcessing;
      61             :         Reference< XConnection >        xConnection;
      62             : 
      63             :         bool                            bStatementDirty;
      64             : 
      65         156 :         CachedRowSet_Data()
      66             :             :sCommand()
      67             :             ,bEscapeProcessing( false )
      68             :             ,xConnection()
      69         156 :             ,bStatementDirty( true )
      70             :         {
      71         156 :         }
      72             :     };
      73             : 
      74          82 :     CachedRowSet::CachedRowSet()
      75          82 :         :m_pData( new CachedRowSet_Data )
      76             :     {
      77          82 :     }
      78             : 
      79             : 
      80         148 :     CachedRowSet::~CachedRowSet()
      81             :     {
      82          74 :         dispose();
      83          74 :     }
      84             : 
      85             : 
      86           0 :     void CachedRowSet::setCommand( const OUString& _rCommand )
      87             :     {
      88           0 :         if ( m_pData->sCommand == _rCommand )
      89           0 :             return;
      90             : 
      91           0 :         m_pData->sCommand = _rCommand;
      92           0 :         m_pData->bStatementDirty = true;
      93             :     }
      94             : 
      95             : 
      96           0 :     void CachedRowSet::setCommandFromQuery( const OUString& _rQueryName )
      97             :     {
      98           0 :         Reference< XQueriesSupplier > xSupplyQueries( m_pData->xConnection, UNO_QUERY_THROW );
      99           0 :         Reference< XNameAccess >      xQueries      ( xSupplyQueries->getQueries(), UNO_QUERY_THROW );
     100           0 :         Reference< XPropertySet >     xQuery        ( xQueries->getByName( _rQueryName ), UNO_QUERY_THROW );
     101             : 
     102           0 :         bool bEscapeProcessing( false );
     103           0 :         OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
     104           0 :         setEscapeProcessing( bEscapeProcessing );
     105             : 
     106           0 :         OUString sCommand;
     107           0 :         OSL_VERIFY( xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
     108           0 :         setCommand( sCommand );
     109           0 :     }
     110             : 
     111             : 
     112           0 :     void CachedRowSet::setEscapeProcessing ( const bool _bEscapeProcessing )
     113             :     {
     114           0 :         if ( m_pData->bEscapeProcessing == _bEscapeProcessing )
     115           0 :             return;
     116             : 
     117           0 :         m_pData->bEscapeProcessing = _bEscapeProcessing;
     118           0 :         m_pData->bStatementDirty = true;
     119             :     }
     120             : 
     121             : 
     122           0 :     void CachedRowSet::setConnection( const Reference< XConnection >& _rxConnection )
     123             :     {
     124           0 :         if ( m_pData->xConnection == _rxConnection )
     125           0 :             return;
     126             : 
     127           0 :         m_pData->xConnection = _rxConnection;
     128           0 :         m_pData->bStatementDirty = true;
     129             :     }
     130             : 
     131             : 
     132           0 :     Reference< XResultSet > CachedRowSet::execute()
     133             :     {
     134           0 :         Reference< XResultSet > xResult;
     135             :         try
     136             :         {
     137             :             OSL_PRECOND( m_pData->xConnection.is(), "CachedRowSet::execute: how am I expected to do this without a connection?" );
     138           0 :             if ( !m_pData->xConnection.is() )
     139           0 :                 return xResult;
     140             : 
     141           0 :             Reference< XStatement > xStatement( m_pData->xConnection->createStatement(), UNO_SET_THROW );
     142           0 :             Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW );
     143           0 :             xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( m_pData->bEscapeProcessing ) );
     144           0 :             xStatementProps->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( ResultSetType::FORWARD_ONLY ) );
     145             : 
     146           0 :             xResult.set( xStatement->executeQuery( m_pData->sCommand ), UNO_SET_THROW );
     147           0 :             m_pData->bStatementDirty = false;
     148             :         }
     149           0 :         catch( const SQLException& )
     150             :         {
     151           0 :             throw;
     152             :         }
     153           0 :         catch( const Exception& )
     154             :         {
     155             :             DBG_UNHANDLED_EXCEPTION();
     156             :         }
     157           0 :         return xResult;
     158             :     }
     159             : 
     160             : 
     161           0 :     bool CachedRowSet::isDirty() const
     162             :     {
     163           0 :         return m_pData->bStatementDirty;
     164             :     }
     165             : 
     166             : 
     167          74 :     void CachedRowSet::dispose()
     168             :     {
     169             :         try
     170             :         {
     171          74 :             m_pData.reset( new CachedRowSet_Data );
     172             :         }
     173           0 :         catch( const Exception& )
     174             :         {
     175             :             DBG_UNHANDLED_EXCEPTION();
     176             :         }
     177          74 :     }
     178             : 
     179             : 
     180             : } // namespace frm
     181             : 
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10