diff options
author | Noel Grandin <noel@peralex.com> | 2020-07-22 12:34:59 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-23 10:14:17 +0200 |
commit | ced1dd9e2dfb92230ed0a91114956160f0e29c9a (patch) | |
tree | 5b58193ff1f930c096ab00dc791acfa210bd0b7b /connectivity/source | |
parent | c049d5336c110196886480330dba9238faee0e39 (diff) |
connectivity/ado: create instances with uno constructors
See tdf#74608 for motivation.
Change-Id: I27bfc55d401fb1a9b9c33309f4b1f00ec13a92fa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99212
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/drivers/ado/ADriver.cxx | 33 | ||||
-rw-r--r-- | connectivity/source/drivers/ado/APreparedStatement.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/ado/Aservices.cxx | 105 | ||||
-rw-r--r-- | connectivity/source/drivers/ado/ado.component | 6 | ||||
-rw-r--r-- | connectivity/source/inc/ado/ADriver.hxx | 17 |
5 files changed, 19 insertions, 144 deletions
diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx index 3fc5ce763103..ee4ec27b6f05 100644 --- a/connectivity/source/drivers/ado/ADriver.cxx +++ b/connectivity/source/drivers/ado/ADriver.cxx @@ -43,9 +43,9 @@ using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbcx; -ODriver::ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB) +ODriver::ODriver(const css::uno::Reference< css::uno::XComponentContext >& _xORB) : ODriver_BASE(m_aMutex) - ,m_xORB(_xORB) + ,m_xContext(_xORB) ,mnNbCallCoInitializeExForReinit(0) { o3tl::safeCoInitializeEx(COINIT_APARTMENTTHREADED, mnNbCallCoInitializeExForReinit); @@ -73,39 +73,21 @@ void ODriver::disposing() } // static ServiceInfo -OUString ODriver::getImplementationName_Static( ) +OUString ODriver::getImplementationName( ) { return "com.sun.star.comp.sdbc.ado.ODriver"; } -Sequence< OUString > ODriver::getSupportedServiceNames_Static( ) +Sequence< OUString > ODriver::getSupportedServiceNames( ) { return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" }; } -css::uno::Reference< css::uno::XInterface > connectivity::ado::ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) -{ - return *(new ODriver(_rxFactory)); -} - - -OUString SAL_CALL ODriver::getImplementationName( ) -{ - return getImplementationName_Static(); -} - sal_Bool SAL_CALL ODriver::supportsService( const OUString& _rServiceName ) { return cppu::supportsService(this, _rServiceName); } - -Sequence< OUString > SAL_CALL ODriver::getSupportedServiceNames( ) -{ - return getSupportedServiceNames_Static(); -} - - Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) { if ( ! acceptsURL(url) ) @@ -269,5 +251,10 @@ void ADOS::ThrowException(ADOConnection* _pAdoCon,const Reference< XInterface >& pErrors->Release(); } - +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_ado_ODriver_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new ODriver(context)); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/ado/APreparedStatement.cxx b/connectivity/source/drivers/ado/APreparedStatement.cxx index ecd4ed538d83..34697fa4388a 100644 --- a/connectivity/source/drivers/ado/APreparedStatement.cxx +++ b/connectivity/source/drivers/ado/APreparedStatement.cxx @@ -58,7 +58,7 @@ OPreparedStatement::OPreparedStatement( OConnection* _pConnection, const OUStrin { osl_atomic_increment( &m_refCount ); - OSQLParser aParser(comphelper::getComponentContext(_pConnection->getDriver()->getORB())); + OSQLParser aParser(_pConnection->getDriver()->getContext()); OUString sErrorMessage; OUString sNewSql; std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,sql); diff --git a/connectivity/source/drivers/ado/Aservices.cxx b/connectivity/source/drivers/ado/Aservices.cxx deleted file mode 100644 index 0ec3ba953fbe..000000000000 --- a/connectivity/source/drivers/ado/Aservices.cxx +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <ado/ADriver.hxx> -#include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> - -using namespace connectivity::ado; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; - -typedef Reference< XSingleServiceFactory > (*createFactoryFunc) - ( - const Reference< XMultiServiceFactory > & rServiceManager, - const OUString & rComponentName, - ::cppu::ComponentInstantiation pCreateFunction, - const Sequence< OUString > & rServiceNames , - rtl_ModuleCount* - ); - -namespace { - -struct ProviderRequest -{ - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > const xServiceManager; - OUString const sImplementationName; - - ProviderRequest( - void* pServiceManager, - char const* pImplementationName - ) - : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER( - const OUString& Implname, - const Sequence< OUString > & Services, - ::cppu::ComponentInstantiation Factory, - createFactoryFunc creator - ) - { - if (!xRet.is() && (Implname == sImplementationName)) - try - { - xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); - } - catch(...) - { - } - return xRet.is(); - } - - void* getProvider() const { return xRet.get(); } -}; - -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* ado_component_getFactory( - const char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager,pImplementationName); - - aReq.CREATE_PROVIDER( - ODriver::getImplementationName_Static(), - ODriver::getSupportedServiceNames_Static(), - ODriver_CreateInstance, ::cppu::createSingleFactory) - ; - - if(aReq.xRet.is()) - aReq.xRet->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/ado/ado.component b/connectivity/source/drivers/ado/ado.component index b90673ae8644..7c97fb2d8533 100644 --- a/connectivity/source/drivers/ado/ado.component +++ b/connectivity/source/drivers/ado/ado.component @@ -17,10 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> -<component loader="com.sun.star.loader.SharedLibrary" - environment="@CPPU_ENV@:affine" prefix="ado" +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@:affine" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.sdbc.ado.ODriver"> + <implementation name="com.sun.star.comp.sdbc.ado.ODriver" + constructor="connectivity_ado_ODriver_get_implementation"> <service name="com.sun.star.sdbc.Driver"/> <service name="com.sun.star.sdbcx.Driver"/> </implementation> diff --git a/connectivity/source/inc/ado/ADriver.hxx b/connectivity/source/inc/ado/ADriver.hxx index c7bc558fb4d3..a428ed1636ca 100644 --- a/connectivity/source/inc/ado/ADriver.hxx +++ b/connectivity/source/inc/ado/ADriver.hxx @@ -26,13 +26,10 @@ #include <cppuhelper/compbase.hxx> #include <connectivity/CommonTools.hxx> -namespace com::sun::star::lang { class XMultiServiceFactory; } +namespace com::sun::star::uno { class XComponentContext; } namespace connectivity::ado { - /// @throws css::uno::Exception - css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); - typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::sdbcx::XDataDefinitionSupplier, css::lang::XServiceInfo @@ -44,23 +41,19 @@ namespace connectivity::ado connectivity::OWeakRefArray m_xConnections; // vector containing a list // of all the Connection objects // for this Driver - css::uno::Reference< css::lang::XMultiServiceFactory > m_xORB; + css::uno::Reference< css::uno::XComponentContext > m_xContext; // to put back all the inits with COINIT_MULTITHREADED if needed int mnNbCallCoInitializeExForReinit; public: - ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB); + ODriver(const css::uno::Reference< css::uno::XComponentContext >& xContext); ~ODriver() override; // OComponentHelper virtual void SAL_CALL disposing() override; - // XInterface - /// @throws css::uno::RuntimeException - static OUString getImplementationName_Static( ); - /// @throws css::uno::RuntimeException - static css::uno::Sequence< OUString > getSupportedServiceNames_Static( ); - css::uno::Reference< css::lang::XMultiServiceFactory > getORB() const { return m_xORB; } + + css::uno::Reference< css::uno::XComponentContext > getContext() const { return m_xContext; } private: void impl_checkURL_throw(const OUString& _sUrl); |