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

Generated by: LCOV version 1.10