LCOV - code coverage report
Current view: top level - libreoffice/svx/source/form - dbtoolsclient.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 131 6.9 %
Date: 2012-12-27 Functions: 3 27 11.1 %
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         236 :     ODbtoolsClient::ODbtoolsClient()
      59             :     {
      60         236 :         m_bCreateAlready = sal_False;
      61         236 :     }
      62             : 
      63             :     //--------------------------------------------------------------------
      64           0 :     bool ODbtoolsClient::ensureLoaded() const
      65             :     {
      66           0 :         if ( !m_bCreateAlready )
      67             :         {
      68           0 :             m_bCreateAlready = true;
      69             : 
      70           0 :             registerClient();
      71           0 :             if ( s_pFactoryCreationFunc )
      72             :             {   // loading the lib succeeded
      73           0 :                 void* pUntypedFactory = (*s_pFactoryCreationFunc)();
      74           0 :                 IDataAccessToolsFactory* pDBTFactory = static_cast< IDataAccessToolsFactory* >( pUntypedFactory );
      75             :                 OSL_ENSURE( pDBTFactory, "ODbtoolsClient::ODbtoolsClient: no factory returned!" );
      76           0 :                 if ( pDBTFactory )
      77             :                 {
      78           0 :                     m_xDataAccessFactory = pDBTFactory;
      79             :                     // by definition, the factory was aquired once
      80           0 :                     m_xDataAccessFactory->release();
      81             :                 }
      82             :             }
      83             :         }
      84           0 :         return m_xDataAccessFactory.is();
      85             :     }
      86             : 
      87             :     //--------------------------------------------------------------------
      88         126 :     ODbtoolsClient::~ODbtoolsClient()
      89             :     {
      90             :         // clear the factory _before_ revoking the client
      91             :         // (the revocation may unload the DBT lib)
      92          63 :         m_xDataAccessFactory = NULL;
      93             :         // revoke the client
      94          63 :         if ( m_bCreateAlready )
      95           0 :             revokeClient();
      96          63 :     }
      97             : 
      98             :     //--------------------------------------------------------------------
      99             : 
     100             : #ifndef DISABLE_DYNLOADING
     101             : 
     102           0 :     extern "C" { static void SAL_CALL thisModule() {} }
     103             : 
     104             : #else
     105             : 
     106             :     extern "C" void * createDataAccessToolsFactory();
     107             : 
     108             : #endif
     109             : 
     110           0 :     void ODbtoolsClient::registerClient()
     111             :     {
     112           0 :         ::osl::MutexGuard aGuard(theODbtoolsClientMutex::get());
     113           0 :         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             : #ifndef DISABLE_DYNLOADING
     119             :             const ::rtl::OUString sModuleName( SVLIBRARY( "dbtools" )
     120           0 :             );
     121             : 
     122             :             // load the dbtools library
     123             :             s_hDbtoolsModule = osl_loadModuleRelative(
     124           0 :                 &thisModule, sModuleName.pData, 0);
     125             :             OSL_ENSURE(NULL != s_hDbtoolsModule, "ODbtoolsClient::registerClient: could not load the dbtools library!");
     126           0 :             if (NULL != s_hDbtoolsModule)
     127             :             {
     128             :                 // get the symbol for the method creating the factory
     129           0 :                 const ::rtl::OUString sFactoryCreationFunc( "createDataAccessToolsFactory" );
     130             :                 //  reinterpret_cast<createDataAccessToolsFactoryFunction>
     131             :                 s_pFactoryCreationFunc = (createDataAccessToolsFactoryFunction)(
     132           0 :                     osl_getFunctionSymbol(s_hDbtoolsModule, sFactoryCreationFunc.pData));
     133             : 
     134           0 :                 if (NULL == s_pFactoryCreationFunc)
     135             :                 {   // did not find the symbol
     136             :                     OSL_FAIL("ODbtoolsClient::registerClient: could not find the symbol for creating the factory!");
     137           0 :                     osl_unloadModule(s_hDbtoolsModule);
     138           0 :                     s_hDbtoolsModule = NULL;
     139           0 :                 }
     140           0 :             }
     141             : #else
     142             :             s_pFactoryCreationFunc = createDataAccessToolsFactory;
     143             : #endif
     144           0 :         }
     145           0 :     }
     146             : 
     147             :     //--------------------------------------------------------------------
     148           0 :     void ODbtoolsClient::revokeClient()
     149             :     {
     150           0 :         ::osl::MutexGuard aGuard(theODbtoolsClientMutex::get());
     151           0 :         if (0 == --s_nClients)
     152             :         {
     153             : #ifndef DISABLE_DYNLOADING
     154           0 :             s_pFactoryCreationFunc = NULL;
     155           0 :             if (s_hDbtoolsModule)
     156           0 :                 osl_unloadModule(s_hDbtoolsModule);
     157             : #endif
     158           0 :             s_hDbtoolsModule = NULL;
     159             :         }
     160             : 
     161           0 :         OSL_ENSURE(s_nClients >= 0,"Illegall call of revokeClient()");
     162           0 :     }
     163             : 
     164             :     //====================================================================
     165             :     //= OStaticDataAccessTools
     166             :     //====================================================================
     167             :     //--------------------------------------------------------------------
     168         236 :     OStaticDataAccessTools::OStaticDataAccessTools()
     169             :     {
     170         236 :     }
     171             : 
     172             :     //--------------------------------------------------------------------
     173             : 
     174           0 :     bool OStaticDataAccessTools::ensureLoaded() const
     175             :     {
     176           0 :         if ( !ODbtoolsClient::ensureLoaded() )
     177           0 :             return false;
     178           0 :          m_xDataAccessTools = getFactory()->getDataAccessTools();
     179           0 :         return m_xDataAccessTools.is();
     180             :     }
     181             : 
     182             :     //--------------------------------------------------------------------
     183           0 :     Reference< XNumberFormatsSupplier > OStaticDataAccessTools::getNumberFormats(const Reference< XConnection>& _rxConn, sal_Bool _bAllowDefault) const
     184             :     {
     185           0 :         Reference< XNumberFormatsSupplier > xReturn;
     186           0 :         if ( ensureLoaded() )
     187           0 :             xReturn = m_xDataAccessTools->getNumberFormats(_rxConn, _bAllowDefault);
     188           0 :         return xReturn;
     189             :     }
     190             : 
     191             :     //--------------------------------------------------------------------
     192           0 :     sal_Int32 OStaticDataAccessTools::getDefaultNumberFormat( const Reference< XPropertySet >& _xColumn, const Reference< XNumberFormatTypes >& _xTypes, const Locale& _rLocale )
     193             :     {
     194           0 :         sal_Int32 nReturn = 0;
     195           0 :         if ( ensureLoaded() )
     196           0 :             nReturn = m_xDataAccessTools->getDefaultNumberFormat( _xColumn, _xTypes, _rLocale );
     197           0 :         return nReturn;
     198             :     }
     199             : 
     200             :     //--------------------------------------------------------------------
     201           0 :     Reference< XConnection> OStaticDataAccessTools::getConnection_withFeedback(const ::rtl::OUString& _rDataSourceName,
     202             :         const ::rtl::OUString& _rUser, const ::rtl::OUString& _rPwd, const Reference<XComponentContext>& _rxContext) const
     203             :             SAL_THROW ( (SQLException) )
     204             :     {
     205           0 :         Reference< XConnection > xReturn;
     206           0 :         if ( ensureLoaded() )
     207           0 :             xReturn = m_xDataAccessTools->getConnection_withFeedback(_rDataSourceName, _rUser, _rPwd, _rxContext);
     208           0 :         return xReturn;
     209             :     }
     210             : 
     211             :     //--------------------------------------------------------------------
     212           0 :     Reference< XConnection > OStaticDataAccessTools::connectRowset( const Reference< XRowSet >& _rxRowSet,
     213             :         const Reference< XComponentContext >& _rxContext, sal_Bool _bSetAsActiveConnection ) const
     214             :         SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) )
     215             :     {
     216           0 :         Reference< XConnection > xReturn;
     217           0 :         if ( ensureLoaded() )
     218           0 :             xReturn = m_xDataAccessTools->connectRowset( _rxRowSet, _rxContext, _bSetAsActiveConnection );
     219           0 :         return xReturn;
     220             :     }
     221             : 
     222             :     //--------------------------------------------------------------------
     223           0 :     Reference< XConnection > OStaticDataAccessTools::getRowSetConnection(const Reference< XRowSet >& _rxRowSet) const SAL_THROW ( (RuntimeException) )
     224             :     {
     225           0 :         Reference< XConnection > xReturn;
     226           0 :         if ( ensureLoaded() )
     227           0 :             xReturn = m_xDataAccessTools->getRowSetConnection(_rxRowSet);
     228           0 :         return xReturn;
     229             :     }
     230             : 
     231             :     //--------------------------------------------------------------------
     232           0 :     void OStaticDataAccessTools::TransferFormComponentProperties(const Reference< XPropertySet>& _rxOld,
     233             :         const Reference< XPropertySet>& _rxNew, const Locale& _rLocale) const
     234             :     {
     235           0 :         if ( ensureLoaded() )
     236           0 :             m_xDataAccessTools->TransferFormComponentProperties(_rxOld, _rxNew, _rLocale);
     237           0 :     }
     238             : 
     239             :     //--------------------------------------------------------------------
     240           0 :     ::rtl::OUString OStaticDataAccessTools::quoteName(const ::rtl::OUString& _rQuote, const ::rtl::OUString& _rName) const
     241             :     {
     242           0 :         ::rtl::OUString sReturn;
     243           0 :         if ( ensureLoaded() )
     244           0 :             sReturn = m_xDataAccessTools->quoteName(_rQuote, _rName);
     245           0 :         return sReturn;
     246             :     }
     247             : 
     248             :     // ------------------------------------------------
     249           0 :     ::rtl::OUString OStaticDataAccessTools::composeTableNameForSelect( const Reference< XConnection >& _rxConnection, const Reference< XPropertySet>& _xTable ) const
     250             :     {
     251           0 :         ::rtl::OUString sReturn;
     252           0 :         if ( ensureLoaded() )
     253           0 :             sReturn = m_xDataAccessTools->composeTableNameForSelect( _rxConnection, _xTable );
     254           0 :         return sReturn;
     255             :     }
     256             : 
     257             :     //----------------------------------------------------------------
     258           0 :     Reference< XDataSource > OStaticDataAccessTools::getDataSource( const ::rtl::OUString& _rsRegisteredName, const Reference< XComponentContext>& _rxContext ) const
     259             :     {
     260           0 :         Reference< XDataSource > xReturn;
     261           0 :         if ( ensureLoaded() )
     262           0 :             xReturn = m_xDataAccessTools->getDataSource(_rsRegisteredName,_rxContext);
     263           0 :         return xReturn;
     264             :     }
     265             : 
     266             :     //----------------------------------------------------------------
     267           0 :     sal_Bool OStaticDataAccessTools::canInsert(const Reference< XPropertySet>& _rxCursorSet) const
     268             :     {
     269           0 :         sal_Bool bRet = sal_False;
     270           0 :         if ( ensureLoaded() )
     271           0 :             bRet = m_xDataAccessTools->canInsert( _rxCursorSet );
     272           0 :         return bRet;
     273             :     }
     274             : 
     275             :     //----------------------------------------------------------------
     276           0 :     sal_Bool OStaticDataAccessTools::canUpdate(const Reference< XPropertySet>& _rxCursorSet) const
     277             :     {
     278           0 :         sal_Bool bRet = sal_False;
     279           0 :         if ( ensureLoaded() )
     280           0 :             bRet = m_xDataAccessTools->canUpdate( _rxCursorSet );
     281           0 :         return bRet;
     282             :     }
     283             : 
     284             :     //----------------------------------------------------------------
     285           0 :     Reference< XNameAccess > OStaticDataAccessTools::getFieldsByCommandDescriptor( const Reference< XConnection >& _rxConnection,
     286             :         const sal_Int32 _nCommandType, const ::rtl::OUString& _rCommand,
     287             :             Reference< XComponent >& _rxKeepFieldsAlive, ::dbtools::SQLExceptionInfo* _pErrorInfo ) SAL_THROW( ( ) )
     288             :     {
     289           0 :         Reference< XNameAccess > aFields;
     290           0 :         if ( ensureLoaded() )
     291           0 :             aFields = m_xDataAccessTools->getFieldsByCommandDescriptor( _rxConnection, _nCommandType,
     292           0 :                 _rCommand, _rxKeepFieldsAlive, _pErrorInfo );
     293             : 
     294           0 :         return aFields;
     295             :     }
     296             : 
     297             :     //----------------------------------------------------------------
     298           0 :     bool OStaticDataAccessTools::isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent, Reference< XConnection >& _rxActualConnection )
     299             :     {
     300           0 :         bool bReturn = false;
     301           0 :         if ( ensureLoaded() )
     302           0 :             bReturn = m_xDataAccessTools->isEmbeddedInDatabase( _rxComponent, _rxActualConnection );
     303           0 :         return bReturn;
     304             :     }
     305             : 
     306             :     //----------------------------------------------------------------
     307           0 :     bool OStaticDataAccessTools::isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent )
     308             :     {
     309           0 :         bool bReturn = false;
     310           0 :         if ( ensureLoaded() )
     311             :         {
     312           0 :             Reference< XConnection > xDummy;
     313           0 :             bReturn = m_xDataAccessTools->isEmbeddedInDatabase( _rxComponent, xDummy );
     314             :         }
     315           0 :         return bReturn;
     316             :     }
     317             : 
     318             :     //====================================================================
     319             :     //= DBToolsObjectFactory
     320             :     //====================================================================
     321             :     //----------------------------------------------------------------
     322           0 :     DBToolsObjectFactory::DBToolsObjectFactory()
     323             :     {
     324           0 :     }
     325             : 
     326             :     //----------------------------------------------------------------
     327           0 :     DBToolsObjectFactory::~DBToolsObjectFactory()
     328             :     {
     329           0 :     }
     330             : 
     331             :     //----------------------------------------------------------------
     332             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     333           0 :     ::std::auto_ptr< ::dbtools::FormattedColumnValue > DBToolsObjectFactory::createFormattedColumnValue(
     334             :         const ::comphelper::ComponentContext& _rContext, const Reference< XRowSet >& _rxRowSet, const Reference< XPropertySet >& _rxColumn )
     335             :     {
     336           0 :         ::std::auto_ptr< ::dbtools::FormattedColumnValue > pValue;
     337           0 :         if ( ensureLoaded() )
     338           0 :             pValue = getFactory()->createFormattedColumnValue( _rContext, _rxRowSet, _rxColumn );
     339           0 :         return pValue;
     340             :     }
     341             :     SAL_WNODEPRECATED_DECLARATIONS_POP
     342             : 
     343             : //........................................................................
     344             : }   // namespace svxform
     345             : //........................................................................
     346             : 
     347             : 
     348             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10