LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - FDriver.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 82 32.9 %
Date: 2014-11-03 Functions: 4 15 26.7 %
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 "file/FDriver.hxx"
      21             : #include "file/FConnection.hxx"
      22             : #include "file/fcode.hxx"
      23             : #include <com/sun/star/lang/DisposedException.hpp>
      24             : #include <comphelper/types.hxx>
      25             : #include <cppuhelper/supportsservice.hxx>
      26             : #include <connectivity/dbexception.hxx>
      27             : #include "resource/common_res.hrc"
      28             : #include "resource/sharedresources.hxx"
      29             : 
      30             : 
      31             : using namespace connectivity::file;
      32             : using namespace com::sun::star::uno;
      33             : using namespace com::sun::star::lang;
      34             : using namespace com::sun::star::beans;
      35             : using namespace com::sun::star::sdbc;
      36             : using namespace com::sun::star::sdbcx;
      37             : using namespace com::sun::star::container;
      38             : 
      39          12 : OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
      40             :     : ODriver_BASE(m_aMutex)
      41          12 :     ,m_xContext(_rxContext)
      42             : {
      43          12 : }
      44             : 
      45           0 : void OFileDriver::disposing()
      46             : {
      47           0 :     ::osl::MutexGuard aGuard(m_aMutex);
      48             : 
      49             : 
      50           0 :     for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
      51             :     {
      52           0 :         Reference< XComponent > xComp(i->get(), UNO_QUERY);
      53           0 :         if (xComp.is())
      54           0 :             xComp->dispose();
      55           0 :     }
      56           0 :     m_xConnections.clear();
      57             : 
      58           0 :     ODriver_BASE::disposing();
      59           0 : }
      60             : 
      61             : // static ServiceInfo
      62             : 
      63           0 : OUString OFileDriver::getImplementationName_Static(  ) throw(RuntimeException)
      64             : {
      65           0 :     return OUString("com.sun.star.sdbc.driver.file.Driver");
      66             : }
      67             : 
      68          12 : Sequence< OUString > OFileDriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
      69             : {
      70          12 :     Sequence< OUString > aSNS( 2 );
      71          12 :     aSNS[0] = "com.sun.star.sdbc.Driver";
      72          12 :     aSNS[1] = "com.sun.star.sdbcx.Driver";
      73          12 :     return aSNS;
      74             : }
      75             : 
      76             : 
      77           0 : OUString SAL_CALL OFileDriver::getImplementationName(  ) throw(RuntimeException, std::exception)
      78             : {
      79           0 :     return getImplementationName_Static();
      80             : }
      81             : 
      82           0 : sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
      83             : {
      84           0 :     return cppu::supportsService(this, _rServiceName);
      85             : }
      86             : 
      87             : 
      88           0 : Sequence< OUString > SAL_CALL OFileDriver::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
      89             : {
      90           0 :     return getSupportedServiceNames_Static();
      91             : }
      92             : 
      93             : 
      94           0 : Reference< XConnection > SAL_CALL OFileDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, std::exception)
      95             : {
      96           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      97           0 :     checkDisposed(ODriver_BASE::rBHelper.bDisposed);
      98             : 
      99           0 :     OConnection* pCon = new OConnection(this);
     100           0 :     Reference< XConnection > xCon = pCon;
     101           0 :     pCon->construct(url,info);
     102           0 :     m_xConnections.push_back(WeakReferenceHelper(*pCon));
     103             : 
     104           0 :     return xCon;
     105             : }
     106             : 
     107           0 : sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url )
     108             :                 throw(SQLException, RuntimeException, std::exception)
     109             : {
     110           0 :     return url.startsWith("sdbc:file:");
     111             : }
     112             : 
     113           0 : Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException, std::exception)
     114             : {
     115           0 :     if ( acceptsURL(url) )
     116             :     {
     117           0 :         ::std::vector< DriverPropertyInfo > aDriverInfo;
     118             : 
     119           0 :         Sequence< OUString > aBoolean(2);
     120           0 :         aBoolean[0] = "0";
     121           0 :         aBoolean[1] = "1";
     122             : 
     123             :         aDriverInfo.push_back(DriverPropertyInfo(
     124             :                 OUString("CharSet")
     125             :                 ,OUString("CharSet of the database.")
     126             :                 ,sal_False
     127             :                 ,OUString()
     128             :                 ,Sequence< OUString >())
     129           0 :                 );
     130             :         aDriverInfo.push_back(DriverPropertyInfo(
     131             :                 OUString("Extension")
     132             :                 ,OUString("Extension of the file format.")
     133             :                 ,sal_False
     134             :                 ,OUString(".*")
     135             :                 ,Sequence< OUString >())
     136           0 :                 );
     137             :         aDriverInfo.push_back(DriverPropertyInfo(
     138             :                 OUString("ShowDeleted")
     139             :                 ,OUString("Display inactive records.")
     140             :                 ,sal_False
     141             :                 ,OUString("0")
     142             :                 ,aBoolean)
     143           0 :                 );
     144             :         aDriverInfo.push_back(DriverPropertyInfo(
     145             :                 OUString("EnableSQL92Check")
     146             :                 ,OUString("Use SQL92 naming constraints.")
     147             :                 ,sal_False
     148             :                 ,OUString("0")
     149             :                 ,aBoolean)
     150           0 :                 );
     151             :         aDriverInfo.push_back(DriverPropertyInfo(
     152             :                 OUString("UseRelativePath")
     153             :                 ,OUString("Handle the connection url as relative path.")
     154             :                 ,sal_False
     155             :                 ,OUString("0")
     156             :                 ,aBoolean)
     157           0 :                 );
     158             :         aDriverInfo.push_back(DriverPropertyInfo(
     159             :                 OUString("URL")
     160             :                 ,OUString("The URL of the database document which is used to create an absolute path.")
     161             :                 ,sal_False
     162             :                 ,OUString()
     163             :                 ,Sequence< OUString >())
     164           0 :                 );
     165           0 :         return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
     166             :     } // if ( acceptsURL(url) )
     167             :     {
     168           0 :         ::connectivity::SharedResources aResources;
     169           0 :         const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
     170           0 :         ::dbtools::throwGenericSQLException(sMessage ,*this);
     171             :     } // if ( ! acceptsURL(url) )
     172           0 :     return Sequence< DriverPropertyInfo >();
     173             : }
     174             : 
     175           0 : sal_Int32 SAL_CALL OFileDriver::getMajorVersion(  ) throw(RuntimeException, std::exception)
     176             : {
     177           0 :     return 1;
     178             : }
     179             : 
     180           0 : sal_Int32 SAL_CALL OFileDriver::getMinorVersion(  ) throw(RuntimeException, std::exception)
     181             : {
     182           0 :     return 0;
     183             : }
     184             : 
     185             : 
     186             : // XDataDefinitionSupplier
     187          62 : Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
     188             : {
     189          62 :     ::osl::MutexGuard aGuard( m_aMutex );
     190          62 :     checkDisposed(ODriver_BASE::rBHelper.bDisposed);
     191             : 
     192          62 :     Reference< XTablesSupplier > xTab = NULL;
     193         124 :     Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
     194          62 :     if(xTunnel.is())
     195             :     {
     196          62 :         OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) );
     197          62 :         OConnection* pConnection = NULL;
     198         318 :         for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
     199             :         {
     200         318 :             if (static_cast<OConnection*>( Reference< XConnection >::query(i->get().get()).get() ) == pSearchConnection)
     201             :             {
     202          62 :                 pConnection = pSearchConnection;
     203          62 :                 break;
     204             :             }
     205             :         }
     206             : 
     207          62 :         if(pConnection)
     208          62 :             xTab = pConnection->createCatalog();
     209             :     }
     210         124 :     return xTab;
     211             : }
     212             : 
     213             : 
     214           0 : Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
     215             : {
     216           0 :     if ( ! acceptsURL(url) )
     217             :     {
     218           0 :         ::connectivity::SharedResources aResources;
     219           0 :         const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
     220           0 :         ::dbtools::throwGenericSQLException(sMessage ,*this);
     221             :     }
     222           0 :     return getDataDefinitionByConnection(connect(url,info));
     223             : }
     224             : 
     225             : 
     226          12 : OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn)
     227          12 :     : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
     228          12 :     , m_xColumn(_xColumn)
     229             : {
     230          12 : }
     231             : 
     232             : 
     233             : 
     234             : 
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10