LCOV - code coverage report
Current view: top level - connectivity/source/drivers/firebird - Driver.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 48 95 50.5 %
Date: 2014-04-11 Functions: 11 19 57.9 %
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 "Connection.hxx"
      21             : #include "Driver.hxx"
      22             : 
      23             : #include <connectivity/dbexception.hxx>
      24             : #include <resource/common_res.hrc>
      25             : #include <resource/hsqldb_res.hrc>
      26             : #include <resource/sharedresources.hxx>
      27             : 
      28             : #include <comphelper/processfactory.hxx>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <osl/file.hxx>
      31             : #include <osl/process.h>
      32             : #include <rtl/bootstrap.hxx>
      33             : #include <svtools/miscopt.hxx>
      34             : 
      35             : using namespace com::sun::star;
      36             : using namespace com::sun::star::uno;
      37             : using namespace com::sun::star::lang;
      38             : using namespace com::sun::star::beans;
      39             : using namespace com::sun::star::sdbc;
      40             : using namespace com::sun::star::sdbcx;
      41             : 
      42             : using namespace ::osl;
      43             : 
      44             : using namespace connectivity::firebird;
      45             : 
      46             : namespace connectivity
      47             : {
      48             :     namespace firebird
      49             :     {
      50           1 :         Reference< XInterface >  SAL_CALL FirebirdDriver_CreateInstance(
      51             :             const Reference< XMultiServiceFactory >& _rxFactory) throw( Exception )
      52             :         {
      53             :             SAL_INFO("connectivity.firebird", "FirebirdDriver_CreateInstance()" );
      54           1 :             return *(new FirebirdDriver(comphelper::getComponentContext(_rxFactory)));
      55             :         }
      56             :     }
      57             : }
      58             : 
      59             : // Static const member variables
      60           2 : const OUString FirebirdDriver::our_sFirebirdTmpVar("FIREBIRD_TMP");
      61           2 : const OUString FirebirdDriver::our_sFirebirdLockVar("FIREBIRD_LOCK");
      62           2 : const OUString FirebirdDriver::our_sFirebirdMsgVar("FIREBIRD_MSG");
      63             : 
      64           1 : FirebirdDriver::FirebirdDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
      65             :     : ODriver_BASE(m_aMutex)
      66             :     , m_aContext(_rxContext)
      67             :     , m_firebirdTMPDirectory(NULL, true)
      68           1 :     , m_firebirdLockDirectory(NULL, true)
      69             : {
      70           1 :     m_firebirdTMPDirectory.EnableKillingFile();
      71           1 :     m_firebirdLockDirectory.EnableKillingFile();
      72             : 
      73             :     // ::utl::TempFile uses a unique temporary directory (subdirectory of
      74             :     // /tmp or other user specific tmp directory) per instance in which
      75             :     // we can create directories for firebird at will.
      76             : 
      77             :     // Overrides firebird's default of /tmp or c:\temp
      78           1 :     osl_setEnvironment(our_sFirebirdTmpVar.pData, m_firebirdTMPDirectory.GetFileName().pData);
      79             : 
      80             :     // Overrides firebird's default of /tmp/firebird or c:\temp\firebird
      81           1 :     osl_setEnvironment(our_sFirebirdLockVar.pData, m_firebirdLockDirectory.GetFileName().pData);
      82             : 
      83             : #ifndef SYSTEM_FIREBIRD
      84             :     // Overrides firebird's hardcoded default of /usr/local/firebird on *nix,
      85             :     // however on Windows it seems to use the current directory as a default.
      86           1 :     OUString sMsgURL("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/firebird");
      87           1 :     ::rtl::Bootstrap::expandMacros(sMsgURL);
      88           2 :     OUString sMsgPath;
      89           1 :     ::osl::FileBase::getSystemPathFromFileURL(sMsgURL, sMsgPath);
      90           2 :     osl_setEnvironment(our_sFirebirdMsgVar.pData, sMsgPath.pData);
      91             : #endif
      92           1 : }
      93             : 
      94           0 : void FirebirdDriver::disposing()
      95             : {
      96           0 :     MutexGuard aGuard(m_aMutex);
      97             : 
      98           0 :     for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
      99             :     {
     100           0 :         Reference< XComponent > xComp(i->get(), UNO_QUERY);
     101           0 :         if (xComp.is())
     102           0 :             xComp->dispose();
     103           0 :     }
     104           0 :     m_xConnections.clear();
     105             : 
     106           0 :     osl_clearEnvironment(our_sFirebirdTmpVar.pData);
     107           0 :     osl_clearEnvironment(our_sFirebirdLockVar.pData);
     108             : 
     109             : #ifndef SYSTEM_FIREBIRD
     110           0 :     osl_clearEnvironment(our_sFirebirdMsgVar.pData);
     111             : #endif
     112             : 
     113           0 :     ODriver_BASE::disposing();
     114           0 : }
     115             : 
     116             : //----- static ServiceInfo ---------------------------------------------------
     117           1 : rtl::OUString FirebirdDriver::getImplementationName_Static() throw(RuntimeException)
     118             : {
     119           1 :     return rtl::OUString("com.sun.star.comp.sdbc.firebird.Driver");
     120             : }
     121             : 
     122           1 : Sequence< OUString > FirebirdDriver::getSupportedServiceNames_Static() throw (RuntimeException)
     123             : {
     124           1 :     Sequence< OUString > aSNS( 2 );
     125           1 :     aSNS[0] = "com.sun.star.sdbc.Driver";
     126           1 :     aSNS[0] = "com.sun.star.sdbcx.Driver";
     127           1 :     return aSNS;
     128             : }
     129             : 
     130           0 : OUString SAL_CALL FirebirdDriver::getImplementationName() throw(RuntimeException, std::exception)
     131             : {
     132           0 :     return getImplementationName_Static();
     133             : }
     134             : 
     135           0 : sal_Bool SAL_CALL FirebirdDriver::supportsService(const OUString& _rServiceName)
     136             :     throw(RuntimeException, std::exception)
     137             : {
     138           0 :     return cppu::supportsService(this, _rServiceName);
     139             : }
     140             : 
     141           0 : Sequence< OUString > SAL_CALL FirebirdDriver::getSupportedServiceNames()
     142             :     throw(RuntimeException, std::exception)
     143             : {
     144           0 :     return getSupportedServiceNames_Static();
     145             : }
     146             : 
     147             : // ----  XDriver -------------------------------------------------------------
     148           2 : Reference< XConnection > SAL_CALL FirebirdDriver::connect(
     149             :     const OUString& url, const Sequence< PropertyValue >& info )
     150             :     throw(SQLException, RuntimeException, std::exception)
     151             : {
     152           2 :     Reference< XConnection > xConnection;
     153             : 
     154             :     SAL_INFO("connectivity.firebird", "connect(), URL: " << url );
     155             : 
     156           4 :     MutexGuard aGuard( m_aMutex );
     157           2 :     if (ODriver_BASE::rBHelper.bDisposed)
     158           0 :        throw DisposedException();
     159             : 
     160           2 :     if ( ! acceptsURL(url) )
     161           0 :         return NULL;
     162             : 
     163           2 :     Connection* pCon = new Connection(this);
     164           4 :     Reference< XConnection > xCon = pCon;
     165           2 :     pCon->construct(url, info);
     166           2 :     m_xConnections.push_back(WeakReferenceHelper(*pCon));
     167             : 
     168           4 :     return xCon;
     169             : }
     170             : 
     171          12 : sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const OUString& url )
     172             :     throw(SQLException, RuntimeException, std::exception)
     173             : {
     174          12 :     SvtMiscOptions aMiscOptions;
     175             : 
     176          48 :     return aMiscOptions.IsExperimentalMode() &&
     177          36 :         (url.equals("sdbc:embedded:firebird") || url.startsWith("sdbc:firebird:"));
     178             : }
     179             : 
     180           2 : Sequence< DriverPropertyInfo > SAL_CALL FirebirdDriver::getPropertyInfo(
     181             :     const OUString& url, const Sequence< PropertyValue >& info )
     182             :     throw(SQLException, RuntimeException, std::exception)
     183             : {
     184             :     (void) info;
     185           2 :     if ( ! acceptsURL(url) )
     186             :     {
     187           0 :         ::connectivity::SharedResources aResources;
     188           0 :         const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
     189           0 :         ::dbtools::throwGenericSQLException(sMessage ,*this);
     190             :     }
     191             : 
     192           2 :     return Sequence< DriverPropertyInfo >();
     193             : }
     194             : 
     195           0 : sal_Int32 SAL_CALL FirebirdDriver::getMajorVersion(  ) throw(RuntimeException, std::exception)
     196             : {
     197             :     // The major and minor version are sdbc driver specific. Must begin with 1.0
     198             :     // as per http://api.libreoffice.org/docs/common/ref/com/sun/star/sdbc/XDriver.html
     199           0 :     return 1;
     200             : }
     201             : 
     202           0 : sal_Int32 SAL_CALL FirebirdDriver::getMinorVersion(  ) throw(RuntimeException, std::exception)
     203             : {
     204           0 :     return 0;
     205             : }
     206             : 
     207             : //----- XDataDefinitionSupplier
     208           2 : uno::Reference< XTablesSupplier > SAL_CALL FirebirdDriver::getDataDefinitionByConnection(
     209             :                                     const uno::Reference< XConnection >& rConnection)
     210             :     throw(SQLException, RuntimeException, std::exception)
     211             : {
     212           2 :     Connection* pConnection = static_cast< Connection* >(rConnection.get());
     213           2 :     return uno::Reference< XTablesSupplier >(pConnection->createCatalog(), UNO_QUERY);
     214             : }
     215             : 
     216           0 : uno::Reference< XTablesSupplier > SAL_CALL FirebirdDriver::getDataDefinitionByURL(
     217             :                     const OUString& rURL,
     218             :                     const uno::Sequence< PropertyValue >& rInfo)
     219             :     throw(SQLException, RuntimeException, std::exception)
     220             : {
     221           0 :     uno::Reference< XConnection > xConnection = connect(rURL, rInfo);
     222           0 :     return getDataDefinitionByConnection(xConnection);
     223             : }
     224             : 
     225             : namespace connectivity
     226             : {
     227             :     namespace firebird
     228             :     {
     229             : 
     230           0 :         void release(oslInterlockedCount& _refCount, ::cppu::OBroadcastHelper& rBHelper,
     231             :                      Reference< XInterface >& _xInterface, XComponent* _pObject)
     232             :         {
     233           0 :             if (osl_atomic_decrement( &_refCount ) == 0)
     234             :             {
     235           0 :                 osl_atomic_increment( &_refCount );
     236             : 
     237           0 :                 if (!rBHelper.bDisposed && !rBHelper.bInDispose)
     238             :                 {
     239             :                     // remember the parent
     240           0 :                     Reference< XInterface > xParent;
     241             :                     {
     242           0 :                         MutexGuard aGuard( rBHelper.rMutex );
     243           0 :                         xParent = _xInterface;
     244           0 :                         _xInterface = NULL;
     245             :                     }
     246             : 
     247             :                     // First dispose
     248           0 :                     _pObject->dispose();
     249             : 
     250             :                     // only the alive ref holds the object
     251             :                     OSL_ASSERT( _refCount == 1 );
     252             : 
     253             :                     // release the parent in the ~
     254           0 :                     if (xParent.is())
     255             :                     {
     256           0 :                         MutexGuard aGuard( rBHelper.rMutex );
     257           0 :                         _xInterface = xParent;
     258           0 :                     }
     259             :                 }
     260             :             }
     261             :             else
     262           0 :                 osl_atomic_increment( &_refCount );
     263           0 :         }
     264             : 
     265         367 :         void checkDisposed(sal_Bool _bThrow) throw ( DisposedException )
     266             :         {
     267         367 :             if (_bThrow)
     268           0 :                 throw DisposedException();
     269             : 
     270         367 :         }
     271             : 
     272             :     }
     273           6 : } // namespace connectivity
     274             : 
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10