LCOV - code coverage report
Current view: top level - svx/source/form - dbtoolsclient.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 67 120 55.8 %
Date: 2014-11-03 Functions: 11 25 44.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 <com/sun/star/sdbc/XConnection.hpp>
      21             : #include <com/sun/star/sdbc/XDataSource.hpp>
      22             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      23             : #include <com/sun/star/sdb/SQLContext.hpp>
      24             : #include "svx/dbtoolsclient.hxx"
      25             : #include <osl/diagnose.h>
      26             : #include <rtl/instance.hxx>
      27             : #include <connectivity/formattedcolumnvalue.hxx>
      28             : 
      29             : 
      30             : namespace svxform
      31             : {
      32             : 
      33             : 
      34             :     using namespace ::connectivity::simple;
      35             :     using namespace ::com::sun::star::sdbc;
      36             :     using namespace ::com::sun::star::lang;
      37             :     using namespace ::com::sun::star::util;
      38             :     using namespace ::com::sun::star::uno;
      39             :     using namespace ::com::sun::star::beans;
      40             :     using namespace ::com::sun::star::sdb;
      41             :     using namespace ::com::sun::star::container;
      42             : 
      43             : 
      44             :     //= ODbtoolsClient
      45             : 
      46             : 
      47             :     namespace
      48             :     {
      49             :         struct theODbtoolsClientMutex : public rtl::Static< osl::Mutex, theODbtoolsClientMutex> {};
      50             :     }
      51             : 
      52             :     sal_Int32       ODbtoolsClient::s_nClients = 0;
      53             :     oslModule       ODbtoolsClient::s_hDbtoolsModule = NULL;
      54             :     createDataAccessToolsFactoryFunction
      55             :                     ODbtoolsClient::s_pFactoryCreationFunc = NULL;
      56             : 
      57             : 
      58        6072 :     ODbtoolsClient::ODbtoolsClient()
      59             :     {
      60        6072 :         m_bCreateAlready = false;
      61        6072 :     }
      62             : 
      63             : 
      64         474 :     bool ODbtoolsClient::ensureLoaded() const
      65             :     {
      66         474 :         if ( !m_bCreateAlready )
      67             :         {
      68         474 :             m_bCreateAlready = true;
      69             : 
      70         474 :             registerClient();
      71         474 :             if ( s_pFactoryCreationFunc )
      72             :             {   // loading the lib succeeded
      73         474 :                 void* pUntypedFactory = (*s_pFactoryCreationFunc)();
      74         474 :                 IDataAccessToolsFactory* pDBTFactory = static_cast< IDataAccessToolsFactory* >( pUntypedFactory );
      75             :                 OSL_ENSURE( pDBTFactory, "ODbtoolsClient::ODbtoolsClient: no factory returned!" );
      76         474 :                 if ( pDBTFactory )
      77             :                 {
      78         474 :                     m_xDataAccessFactory = pDBTFactory;
      79             :                     // by definition, the factory was acquired once
      80         474 :                     m_xDataAccessFactory->release();
      81             :                 }
      82             :             }
      83             :         }
      84         474 :         return m_xDataAccessFactory.is();
      85             :     }
      86             : 
      87             : 
      88       12140 :     ODbtoolsClient::~ODbtoolsClient()
      89             :     {
      90             :         // clear the factory _before_ revoking the client
      91             :         // (the revocation may unload the DBT lib)
      92        6070 :         m_xDataAccessFactory = NULL;
      93             :         // revoke the client
      94        6070 :         if ( m_bCreateAlready )
      95         474 :             revokeClient();
      96        6070 :     }
      97             : 
      98             : #if HAVE_FEATURE_DESKTOP
      99             : #ifndef DISABLE_DYNLOADING
     100           0 :     extern "C" { static void SAL_CALL thisModule() {} }
     101             : #else
     102             :     extern "C" void * createDataAccessToolsFactory();
     103             : #endif
     104             : #endif
     105             : 
     106         474 :     void ODbtoolsClient::registerClient()
     107             :     {
     108         474 :         ::osl::MutexGuard aGuard(theODbtoolsClientMutex::get());
     109         474 :         if (1 == ++s_nClients)
     110             :         {
     111             :             OSL_ENSURE(NULL == s_hDbtoolsModule, "ODbtoolsClient::registerClient: inconsistence: already have a module!");
     112             :             OSL_ENSURE(NULL == s_pFactoryCreationFunc, "ODbtoolsClient::registerClient: inconsistence: already have a factory function!");
     113             : 
     114             : #if HAVE_FEATURE_DESKTOP
     115             : #ifndef DISABLE_DYNLOADING
     116         474 :             const static OUString sModuleName( DBTOOLS_DLL_NAME );
     117             : 
     118             :             // load the dbtools library
     119             :             s_hDbtoolsModule = osl_loadModuleRelative(
     120         474 :                 &thisModule, sModuleName.pData, 0);
     121             :             OSL_ENSURE(NULL != s_hDbtoolsModule, "ODbtoolsClient::registerClient: could not load the dbtools library!");
     122         474 :             if (NULL != s_hDbtoolsModule)
     123             :             {
     124             :                 // get the symbol for the method creating the factory
     125         474 :                 const OUString sFactoryCreationFunc( "createDataAccessToolsFactory" );
     126             :                 //  reinterpret_cast<createDataAccessToolsFactoryFunction>
     127             :                 s_pFactoryCreationFunc = (createDataAccessToolsFactoryFunction)(
     128         474 :                     osl_getFunctionSymbol(s_hDbtoolsModule, sFactoryCreationFunc.pData));
     129             : 
     130         474 :                 if (NULL == s_pFactoryCreationFunc)
     131             :                 {   // did not find the symbol
     132             :                     OSL_FAIL("ODbtoolsClient::registerClient: could not find the symbol for creating the factory!");
     133           0 :                     osl_unloadModule(s_hDbtoolsModule);
     134           0 :                     s_hDbtoolsModule = NULL;
     135         474 :                 }
     136             :             }
     137             : #else
     138             :             s_pFactoryCreationFunc = createDataAccessToolsFactory;
     139             : #endif
     140             : #endif
     141         474 :         }
     142         474 :     }
     143             : 
     144             : 
     145         474 :     void ODbtoolsClient::revokeClient()
     146             :     {
     147         474 :         ::osl::MutexGuard aGuard(theODbtoolsClientMutex::get());
     148         474 :         if (0 == --s_nClients)
     149             :         {
     150             : #ifndef DISABLE_DYNLOADING
     151         474 :             s_pFactoryCreationFunc = NULL;
     152         474 :             if (s_hDbtoolsModule)
     153         474 :                 osl_unloadModule(s_hDbtoolsModule);
     154             : #endif
     155         474 :             s_hDbtoolsModule = NULL;
     156             :         }
     157             : 
     158         474 :         OSL_ENSURE(s_nClients >= 0,"Illegall call of revokeClient()");
     159         474 :     }
     160             : 
     161        5922 :     OStaticDataAccessTools::OStaticDataAccessTools()
     162             :     {
     163        5922 :     }
     164             : 
     165             : 
     166             : 
     167         472 :     bool OStaticDataAccessTools::ensureLoaded() const
     168             :     {
     169         472 :         if ( !ODbtoolsClient::ensureLoaded() )
     170           0 :             return false;
     171         472 :          m_xDataAccessTools = getFactory()->getDataAccessTools();
     172         472 :         return m_xDataAccessTools.is();
     173             :     }
     174             : 
     175             : 
     176           0 :     Reference< XNumberFormatsSupplier > OStaticDataAccessTools::getNumberFormats(const Reference< XConnection>& _rxConn, bool _bAllowDefault) const
     177             :     {
     178           0 :         Reference< XNumberFormatsSupplier > xReturn;
     179           0 :         if ( ensureLoaded() )
     180           0 :             xReturn = m_xDataAccessTools->getNumberFormats(_rxConn, _bAllowDefault);
     181           0 :         return xReturn;
     182             :     }
     183             : 
     184             : 
     185           0 :     sal_Int32 OStaticDataAccessTools::getDefaultNumberFormat( const Reference< XPropertySet >& _xColumn, const Reference< XNumberFormatTypes >& _xTypes, const Locale& _rLocale )
     186             :     {
     187           0 :         sal_Int32 nReturn = 0;
     188           0 :         if ( ensureLoaded() )
     189           0 :             nReturn = m_xDataAccessTools->getDefaultNumberFormat( _xColumn, _xTypes, _rLocale );
     190           0 :         return nReturn;
     191             :     }
     192             : 
     193             : 
     194           0 :     Reference< XConnection> OStaticDataAccessTools::getConnection_withFeedback(const OUString& _rDataSourceName,
     195             :         const OUString& _rUser, const OUString& _rPwd, const Reference<XComponentContext>& _rxContext) const
     196             :     {
     197           0 :         Reference< XConnection > xReturn;
     198           0 :         if ( ensureLoaded() )
     199           0 :             xReturn = m_xDataAccessTools->getConnection_withFeedback(_rDataSourceName, _rUser, _rPwd, _rxContext);
     200           0 :         return xReturn;
     201             :     }
     202             : 
     203             : 
     204           0 :     Reference< XConnection > OStaticDataAccessTools::connectRowset( const Reference< XRowSet >& _rxRowSet,
     205             :         const Reference< XComponentContext >& _rxContext, bool _bSetAsActiveConnection ) const
     206             :     {
     207           0 :         Reference< XConnection > xReturn;
     208           0 :         if ( ensureLoaded() )
     209           0 :             xReturn = m_xDataAccessTools->connectRowset( _rxRowSet, _rxContext, _bSetAsActiveConnection );
     210           0 :         return xReturn;
     211             :     }
     212             : 
     213             : 
     214         104 :     Reference< XConnection > OStaticDataAccessTools::getRowSetConnection(const Reference< XRowSet >& _rxRowSet) const
     215             :     {
     216         104 :         Reference< XConnection > xReturn;
     217         104 :         if ( ensureLoaded() )
     218         104 :             xReturn = m_xDataAccessTools->getRowSetConnection(_rxRowSet);
     219         104 :         return xReturn;
     220             :     }
     221             : 
     222           0 :     void OStaticDataAccessTools::TransferFormComponentProperties(const Reference< XPropertySet>& _rxOld,
     223             :         const Reference< XPropertySet>& _rxNew, const Locale& _rLocale) const
     224             :     {
     225           0 :         if ( ensureLoaded() )
     226           0 :             m_xDataAccessTools->TransferFormComponentProperties(_rxOld, _rxNew, _rLocale);
     227           0 :     }
     228             : 
     229          52 :     Reference< XDataSource > OStaticDataAccessTools::getDataSource( const OUString& _rsRegisteredName, const Reference< XComponentContext>& _rxContext ) const
     230             :     {
     231          52 :         Reference< XDataSource > xReturn;
     232          52 :         if ( ensureLoaded() )
     233          52 :             xReturn = m_xDataAccessTools->getDataSource(_rsRegisteredName,_rxContext);
     234          52 :         return xReturn;
     235             :     }
     236             : 
     237           0 :     bool OStaticDataAccessTools::canInsert(const Reference< XPropertySet>& _rxCursorSet) const
     238             :     {
     239           0 :         bool bRet = false;
     240           0 :         if ( ensureLoaded() )
     241           0 :             bRet = m_xDataAccessTools->canInsert( _rxCursorSet );
     242           0 :         return bRet;
     243             :     }
     244             : 
     245           0 :     bool OStaticDataAccessTools::canUpdate(const Reference< XPropertySet>& _rxCursorSet) const
     246             :     {
     247           0 :         bool bRet = false;
     248           0 :         if ( ensureLoaded() )
     249           0 :             bRet = m_xDataAccessTools->canUpdate( _rxCursorSet );
     250           0 :         return bRet;
     251             :     }
     252             : 
     253             : 
     254           0 :     Reference< XNameAccess > OStaticDataAccessTools::getFieldsByCommandDescriptor( const Reference< XConnection >& _rxConnection,
     255             :         const sal_Int32 _nCommandType, const OUString& _rCommand,
     256             :             Reference< XComponent >& _rxKeepFieldsAlive, ::dbtools::SQLExceptionInfo* _pErrorInfo )
     257             :     {
     258           0 :         Reference< XNameAccess > aFields;
     259           0 :         if ( ensureLoaded() )
     260           0 :             aFields = m_xDataAccessTools->getFieldsByCommandDescriptor( _rxConnection, _nCommandType,
     261           0 :                 _rCommand, _rxKeepFieldsAlive, _pErrorInfo );
     262             : 
     263           0 :         return aFields;
     264             :     }
     265             : 
     266             : 
     267          14 :     bool OStaticDataAccessTools::isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent, Reference< XConnection >& _rxActualConnection )
     268             :     {
     269          14 :         bool bReturn = false;
     270          14 :         if ( ensureLoaded() )
     271          14 :             bReturn = m_xDataAccessTools->isEmbeddedInDatabase( _rxComponent, _rxActualConnection );
     272          14 :         return bReturn;
     273             :     }
     274             : 
     275             : 
     276         302 :     bool OStaticDataAccessTools::isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent )
     277             :     {
     278         302 :         bool bReturn = false;
     279         302 :         if ( ensureLoaded() )
     280             :         {
     281         302 :             Reference< XConnection > xDummy;
     282         302 :             bReturn = m_xDataAccessTools->isEmbeddedInDatabase( _rxComponent, xDummy );
     283             :         }
     284         302 :         return bReturn;
     285             :     }
     286             : 
     287           0 :     DBToolsObjectFactory::DBToolsObjectFactory()
     288             :     {
     289           0 :     }
     290             : 
     291             : 
     292           0 :     DBToolsObjectFactory::~DBToolsObjectFactory()
     293             :     {
     294           0 :     }
     295             : 
     296             : 
     297           0 :     ::std::unique_ptr< ::dbtools::FormattedColumnValue > DBToolsObjectFactory::createFormattedColumnValue(
     298             :         const Reference<XComponentContext>& _rContext, const Reference< XRowSet >& _rxRowSet, const Reference< XPropertySet >& _rxColumn )
     299             :     {
     300           0 :         ::std::unique_ptr< ::dbtools::FormattedColumnValue > pValue;
     301           0 :         if ( ensureLoaded() )
     302           0 :             pValue = getFactory()->createFormattedColumnValue( _rContext, _rxRowSet, _rxColumn );
     303           0 :         return pValue;
     304             :     }
     305             : 
     306             : 
     307             : }   // namespace svxform
     308             : 
     309             : 
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10