LCOV - code coverage report
Current view: top level - svx/source/form - dbtoolsclient.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 131 55.7 %
Date: 2012-08-25 Functions: 12 27 44.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 42 132 31.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/sdbc/XConnection.hpp>
      30                 :            : #include <com/sun/star/sdbc/XDataSource.hpp>
      31                 :            : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      32                 :            : #include <com/sun/star/sdb/SQLContext.hpp>
      33                 :            : #include "svx/dbtoolsclient.hxx"
      34                 :            : #include <osl/diagnose.h>
      35                 :            : #include <rtl/instance.hxx>
      36                 :            : #include <connectivity/formattedcolumnvalue.hxx>
      37                 :            : 
      38                 :            : //........................................................................
      39                 :            : namespace svxform
      40                 :            : {
      41                 :            : //........................................................................
      42                 :            : 
      43                 :            :     using namespace ::connectivity::simple;
      44                 :            :     using namespace ::com::sun::star::sdbc;
      45                 :            :     using namespace ::com::sun::star::lang;
      46                 :            :     using namespace ::com::sun::star::util;
      47                 :            :     using namespace ::com::sun::star::uno;
      48                 :            :     using namespace ::com::sun::star::beans;
      49                 :            :     using namespace ::com::sun::star::sdb;
      50                 :            :     using namespace ::com::sun::star::container;
      51                 :            : 
      52                 :            :     //====================================================================
      53                 :            :     //= ODbtoolsClient
      54                 :            :     //====================================================================
      55                 :            : 
      56                 :            :     namespace
      57                 :            :     {
      58                 :            :         struct theODbtoolsClientMutex : public rtl::Static< osl::Mutex, theODbtoolsClientMutex> {};
      59                 :            :     }
      60                 :            : 
      61                 :            :     sal_Int32       ODbtoolsClient::s_nClients = 0;
      62                 :            :     oslModule       ODbtoolsClient::s_hDbtoolsModule = NULL;
      63                 :            :     createDataAccessToolsFactoryFunction
      64                 :            :                     ODbtoolsClient::s_pFactoryCreationFunc = NULL;
      65                 :            : 
      66                 :            :     //--------------------------------------------------------------------
      67                 :       2200 :     ODbtoolsClient::ODbtoolsClient()
      68                 :            :     {
      69                 :       2200 :         m_bCreateAlready = sal_False;
      70                 :       2200 :     }
      71                 :            : 
      72                 :            :     //--------------------------------------------------------------------
      73                 :        487 :     bool ODbtoolsClient::ensureLoaded() const
      74                 :            :     {
      75         [ +  + ]:        487 :         if ( !m_bCreateAlready )
      76                 :            :         {
      77                 :        395 :             m_bCreateAlready = true;
      78                 :            : 
      79                 :        395 :             registerClient();
      80         [ +  - ]:        395 :             if ( s_pFactoryCreationFunc )
      81                 :            :             {   // loading the lib succeeded
      82                 :        395 :                 void* pUntypedFactory = (*s_pFactoryCreationFunc)();
      83                 :        395 :                 IDataAccessToolsFactory* pDBTFactory = static_cast< IDataAccessToolsFactory* >( pUntypedFactory );
      84                 :            :                 OSL_ENSURE( pDBTFactory, "ODbtoolsClient::ODbtoolsClient: no factory returned!" );
      85         [ +  - ]:        395 :                 if ( pDBTFactory )
      86                 :            :                 {
      87                 :        395 :                     m_xDataAccessFactory = pDBTFactory;
      88                 :            :                     // by definition, the factory was aquired once
      89                 :        395 :                     m_xDataAccessFactory->release();
      90                 :            :                 }
      91                 :            :             }
      92                 :            :         }
      93                 :        487 :         return m_xDataAccessFactory.is();
      94                 :            :     }
      95                 :            : 
      96                 :            :     //--------------------------------------------------------------------
      97                 :       2106 :     ODbtoolsClient::~ODbtoolsClient()
      98                 :            :     {
      99                 :            :         // clear the factory _before_ revoking the client
     100                 :            :         // (the revocation may unload the DBT lib)
     101         [ +  - ]:       2106 :         m_xDataAccessFactory = NULL;
     102                 :            :         // revoke the client
     103         [ +  + ]:       2106 :         if ( m_bCreateAlready )
     104         [ +  - ]:        395 :             revokeClient();
     105         [ -  + ]:       2106 :     }
     106                 :            : 
     107                 :            :     //--------------------------------------------------------------------
     108                 :          0 :     extern "C" { static void SAL_CALL thisModule() {} }
     109                 :            : 
     110                 :        395 :     void ODbtoolsClient::registerClient()
     111                 :            :     {
     112 [ +  - ][ +  - ]:        395 :         ::osl::MutexGuard aGuard(theODbtoolsClientMutex::get());
     113         [ +  + ]:        395 :         if (1 == ++s_nClients)
     114                 :            :         {
     115                 :            :             OSL_ENSURE(NULL == s_hDbtoolsModule, "ODbtoolsClient::registerClient: inconsistence: already have a module!");
     116                 :            :             OSL_ENSURE(NULL == s_pFactoryCreationFunc, "ODbtoolsClient::registerClient: inconsistence: already have a factory function!");
     117                 :            : 
     118                 :            :             const ::rtl::OUString sModuleName( SVLIBRARY( "dbtools" )
     119                 :        387 :             );
     120                 :            : 
     121                 :            :             // load the dbtools library
     122                 :            :             s_hDbtoolsModule = osl_loadModuleRelative(
     123         [ +  - ]:        387 :                 &thisModule, sModuleName.pData, 0);
     124                 :            :             OSL_ENSURE(NULL != s_hDbtoolsModule, "ODbtoolsClient::registerClient: could not load the dbtools library!");
     125         [ +  - ]:        387 :             if (NULL != s_hDbtoolsModule)
     126                 :            :             {
     127                 :            :                 // get the symbol for the method creating the factory
     128                 :        387 :                 const ::rtl::OUString sFactoryCreationFunc( "createDataAccessToolsFactory" );
     129                 :            :                 //  reinterpret_cast<createDataAccessToolsFactoryFunction>
     130                 :            :                 s_pFactoryCreationFunc = (createDataAccessToolsFactoryFunction)(
     131         [ +  - ]:        387 :                     osl_getFunctionSymbol(s_hDbtoolsModule, sFactoryCreationFunc.pData));
     132                 :            : 
     133         [ -  + ]:        387 :                 if (NULL == s_pFactoryCreationFunc)
     134                 :            :                 {   // did not find the symbol
     135                 :            :                     OSL_FAIL("ODbtoolsClient::registerClient: could not find the symbol for creating the factory!");
     136         [ #  # ]:          0 :                     osl_unloadModule(s_hDbtoolsModule);
     137                 :          0 :                     s_hDbtoolsModule = NULL;
     138                 :        387 :                 }
     139                 :        387 :             }
     140         [ +  - ]:        395 :         }
     141                 :        395 :     }
     142                 :            : 
     143                 :            :     //--------------------------------------------------------------------
     144                 :        395 :     void ODbtoolsClient::revokeClient()
     145                 :            :     {
     146 [ +  - ][ +  - ]:        395 :         ::osl::MutexGuard aGuard(theODbtoolsClientMutex::get());
     147         [ +  + ]:        395 :         if (0 == --s_nClients)
     148                 :            :         {
     149                 :        387 :             s_pFactoryCreationFunc = NULL;
     150         [ +  - ]:        387 :             if (s_hDbtoolsModule)
     151         [ +  - ]:        387 :                 osl_unloadModule(s_hDbtoolsModule);
     152                 :        387 :             s_hDbtoolsModule = NULL;
     153                 :            :         }
     154                 :            : 
     155         [ +  - ]:        395 :         OSL_ENSURE(s_nClients >= 0,"Illegall call of revokeClient()");
     156                 :        395 :     }
     157                 :            : 
     158                 :            :     //====================================================================
     159                 :            :     //= OStaticDataAccessTools
     160                 :            :     //====================================================================
     161                 :            :     //--------------------------------------------------------------------
     162                 :       2078 :     OStaticDataAccessTools::OStaticDataAccessTools()
     163                 :            :     {
     164                 :       2078 :     }
     165                 :            : 
     166                 :            :     //--------------------------------------------------------------------
     167                 :            : 
     168                 :        351 :     bool OStaticDataAccessTools::ensureLoaded() const
     169                 :            :     {
     170         [ -  + ]:        351 :         if ( !ODbtoolsClient::ensureLoaded() )
     171                 :          0 :             return false;
     172         [ +  - ]:        351 :          m_xDataAccessTools = getFactory()->getDataAccessTools();
     173                 :        351 :         return m_xDataAccessTools.is();
     174                 :            :     }
     175                 :            : 
     176                 :            :     //--------------------------------------------------------------------
     177                 :          2 :     Reference< XNumberFormatsSupplier > OStaticDataAccessTools::getNumberFormats(const Reference< XConnection>& _rxConn, sal_Bool _bAllowDefault) const
     178                 :            :     {
     179                 :          2 :         Reference< XNumberFormatsSupplier > xReturn;
     180 [ +  - ][ +  - ]:          2 :         if ( ensureLoaded() )
     181 [ +  - ][ +  - ]:          2 :             xReturn = m_xDataAccessTools->getNumberFormats(_rxConn, _bAllowDefault);
     182                 :          2 :         return xReturn;
     183                 :            :     }
     184                 :            : 
     185                 :            :     //--------------------------------------------------------------------
     186                 :          0 :     sal_Int32 OStaticDataAccessTools::getDefaultNumberFormat( const Reference< XPropertySet >& _xColumn, const Reference< XNumberFormatTypes >& _xTypes, const Locale& _rLocale )
     187                 :            :     {
     188                 :          0 :         sal_Int32 nReturn = 0;
     189         [ #  # ]:          0 :         if ( ensureLoaded() )
     190                 :          0 :             nReturn = m_xDataAccessTools->getDefaultNumberFormat( _xColumn, _xTypes, _rLocale );
     191                 :          0 :         return nReturn;
     192                 :            :     }
     193                 :            : 
     194                 :            :     //--------------------------------------------------------------------
     195                 :          0 :     Reference< XConnection> OStaticDataAccessTools::getConnection_withFeedback(const ::rtl::OUString& _rDataSourceName,
     196                 :            :         const ::rtl::OUString& _rUser, const ::rtl::OUString& _rPwd, const Reference< XMultiServiceFactory>& _rxFactory) const
     197                 :            :             SAL_THROW ( (SQLException) )
     198                 :            :     {
     199                 :          0 :         Reference< XConnection > xReturn;
     200 [ #  # ][ #  # ]:          0 :         if ( ensureLoaded() )
     201 [ #  # ][ #  # ]:          0 :             xReturn = m_xDataAccessTools->getConnection_withFeedback(_rDataSourceName, _rUser, _rPwd, _rxFactory);
     202                 :          0 :         return xReturn;
     203                 :            :     }
     204                 :            : 
     205                 :            :     //--------------------------------------------------------------------
     206                 :          0 :     Reference< XConnection > OStaticDataAccessTools::connectRowset( const Reference< XRowSet >& _rxRowSet,
     207                 :            :         const Reference< XMultiServiceFactory >& _rxFactory, sal_Bool _bSetAsActiveConnection ) const
     208                 :            :         SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) )
     209                 :            :     {
     210                 :          0 :         Reference< XConnection > xReturn;
     211 [ #  # ][ #  # ]:          0 :         if ( ensureLoaded() )
     212 [ #  # ][ #  # ]:          0 :             xReturn = m_xDataAccessTools->connectRowset( _rxRowSet, _rxFactory, _bSetAsActiveConnection );
     213                 :          0 :         return xReturn;
     214                 :            :     }
     215                 :            : 
     216                 :            :     //--------------------------------------------------------------------
     217                 :         23 :     Reference< XConnection > OStaticDataAccessTools::getRowSetConnection(const Reference< XRowSet >& _rxRowSet) const SAL_THROW ( (RuntimeException) )
     218                 :            :     {
     219                 :         23 :         Reference< XConnection > xReturn;
     220 [ +  - ][ +  - ]:         23 :         if ( ensureLoaded() )
     221 [ +  - ][ +  - ]:         23 :             xReturn = m_xDataAccessTools->getRowSetConnection(_rxRowSet);
     222                 :         23 :         return xReturn;
     223                 :            :     }
     224                 :            : 
     225                 :            :     //--------------------------------------------------------------------
     226                 :          0 :     void OStaticDataAccessTools::TransferFormComponentProperties(const Reference< XPropertySet>& _rxOld,
     227                 :            :         const Reference< XPropertySet>& _rxNew, const Locale& _rLocale) const
     228                 :            :     {
     229         [ #  # ]:          0 :         if ( ensureLoaded() )
     230                 :          0 :             m_xDataAccessTools->TransferFormComponentProperties(_rxOld, _rxNew, _rLocale);
     231                 :          0 :     }
     232                 :            : 
     233                 :            :     //--------------------------------------------------------------------
     234                 :          0 :     ::rtl::OUString OStaticDataAccessTools::quoteName(const ::rtl::OUString& _rQuote, const ::rtl::OUString& _rName) const
     235                 :            :     {
     236                 :          0 :         ::rtl::OUString sReturn;
     237 [ #  # ][ #  # ]:          0 :         if ( ensureLoaded() )
     238         [ #  # ]:          0 :             sReturn = m_xDataAccessTools->quoteName(_rQuote, _rName);
     239                 :          0 :         return sReturn;
     240                 :            :     }
     241                 :            : 
     242                 :            :     // ------------------------------------------------
     243                 :          0 :     ::rtl::OUString OStaticDataAccessTools::composeTableNameForSelect( const Reference< XConnection >& _rxConnection, const Reference< XPropertySet>& _xTable ) const
     244                 :            :     {
     245                 :          0 :         ::rtl::OUString sReturn;
     246 [ #  # ][ #  # ]:          0 :         if ( ensureLoaded() )
     247         [ #  # ]:          0 :             sReturn = m_xDataAccessTools->composeTableNameForSelect( _rxConnection, _xTable );
     248                 :          0 :         return sReturn;
     249                 :            :     }
     250                 :            : 
     251                 :            :     //----------------------------------------------------------------
     252                 :         52 :     Reference< XDataSource > OStaticDataAccessTools::getDataSource( const ::rtl::OUString& _rsRegisteredName, const Reference< XMultiServiceFactory>& _rxFactory ) const
     253                 :            :     {
     254                 :         52 :         Reference< XDataSource > xReturn;
     255 [ +  - ][ +  - ]:         52 :         if ( ensureLoaded() )
     256 [ +  - ][ +  - ]:         52 :             xReturn = m_xDataAccessTools->getDataSource(_rsRegisteredName,_rxFactory);
     257                 :         52 :         return xReturn;
     258                 :            :     }
     259                 :            : 
     260                 :            :     //----------------------------------------------------------------
     261                 :          0 :     sal_Bool OStaticDataAccessTools::canInsert(const Reference< XPropertySet>& _rxCursorSet) const
     262                 :            :     {
     263                 :          0 :         sal_Bool bRet = sal_False;
     264         [ #  # ]:          0 :         if ( ensureLoaded() )
     265                 :          0 :             bRet = m_xDataAccessTools->canInsert( _rxCursorSet );
     266                 :          0 :         return bRet;
     267                 :            :     }
     268                 :            : 
     269                 :            :     //----------------------------------------------------------------
     270                 :          0 :     sal_Bool OStaticDataAccessTools::canUpdate(const Reference< XPropertySet>& _rxCursorSet) const
     271                 :            :     {
     272                 :          0 :         sal_Bool bRet = sal_False;
     273         [ #  # ]:          0 :         if ( ensureLoaded() )
     274                 :          0 :             bRet = m_xDataAccessTools->canUpdate( _rxCursorSet );
     275                 :          0 :         return bRet;
     276                 :            :     }
     277                 :            : 
     278                 :            :     //----------------------------------------------------------------
     279                 :          0 :     Reference< XNameAccess > OStaticDataAccessTools::getFieldsByCommandDescriptor( const Reference< XConnection >& _rxConnection,
     280                 :            :         const sal_Int32 _nCommandType, const ::rtl::OUString& _rCommand,
     281                 :            :             Reference< XComponent >& _rxKeepFieldsAlive, ::dbtools::SQLExceptionInfo* _pErrorInfo ) SAL_THROW( ( ) )
     282                 :            :     {
     283                 :          0 :         Reference< XNameAccess > aFields;
     284 [ #  # ][ #  # ]:          0 :         if ( ensureLoaded() )
     285                 :          0 :             aFields = m_xDataAccessTools->getFieldsByCommandDescriptor( _rxConnection, _nCommandType,
     286 [ #  # ][ #  # ]:          0 :                 _rCommand, _rxKeepFieldsAlive, _pErrorInfo );
     287                 :            : 
     288                 :          0 :         return aFields;
     289                 :            :     }
     290                 :            : 
     291                 :            :     //----------------------------------------------------------------
     292                 :         15 :     bool OStaticDataAccessTools::isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent, Reference< XConnection >& _rxActualConnection )
     293                 :            :     {
     294                 :         15 :         bool bReturn = false;
     295         [ +  - ]:         15 :         if ( ensureLoaded() )
     296                 :         15 :             bReturn = m_xDataAccessTools->isEmbeddedInDatabase( _rxComponent, _rxActualConnection );
     297                 :         15 :         return bReturn;
     298                 :            :     }
     299                 :            : 
     300                 :            :     //----------------------------------------------------------------
     301                 :        259 :     bool OStaticDataAccessTools::isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent )
     302                 :            :     {
     303                 :        259 :         bool bReturn = false;
     304         [ +  - ]:        259 :         if ( ensureLoaded() )
     305                 :            :         {
     306                 :        259 :             Reference< XConnection > xDummy;
     307         [ +  - ]:        259 :             bReturn = m_xDataAccessTools->isEmbeddedInDatabase( _rxComponent, xDummy );
     308                 :            :         }
     309                 :        259 :         return bReturn;
     310                 :            :     }
     311                 :            : 
     312                 :            :     //====================================================================
     313                 :            :     //= DBToolsObjectFactory
     314                 :            :     //====================================================================
     315                 :            :     //----------------------------------------------------------------
     316                 :          0 :     DBToolsObjectFactory::DBToolsObjectFactory()
     317                 :            :     {
     318                 :          0 :     }
     319                 :            : 
     320                 :            :     //----------------------------------------------------------------
     321                 :          0 :     DBToolsObjectFactory::~DBToolsObjectFactory()
     322                 :            :     {
     323         [ #  # ]:          0 :     }
     324                 :            : 
     325                 :            :     //----------------------------------------------------------------
     326                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     327                 :          0 :     ::std::auto_ptr< ::dbtools::FormattedColumnValue > DBToolsObjectFactory::createFormattedColumnValue(
     328                 :            :         const ::comphelper::ComponentContext& _rContext, const Reference< XRowSet >& _rxRowSet, const Reference< XPropertySet >& _rxColumn )
     329                 :            :     {
     330                 :          0 :         ::std::auto_ptr< ::dbtools::FormattedColumnValue > pValue;
     331 [ #  # ][ #  # ]:          0 :         if ( ensureLoaded() )
     332 [ #  # ][ #  # ]:          0 :             pValue = getFactory()->createFormattedColumnValue( _rContext, _rxRowSet, _rxColumn );
     333                 :          0 :         return pValue;
     334                 :            :     }
     335                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
     336                 :            : 
     337                 :            : //........................................................................
     338                 :            : }   // namespace svxform
     339                 :            : //........................................................................
     340                 :            : 
     341                 :            : 
     342                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10