diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-13 15:17:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-13 19:19:16 +0200 |
commit | 8435bffbcfdcdac4fe64084ac578d956e8f130fb (patch) | |
tree | 2c0aec77e168b1ad32baf3d5ee2758f2e4c56f1b /connectivity | |
parent | af97e1053f79ea4a913c3bd11cc779f355006f38 (diff) |
connectivity/postgresql: create instances with uno constructors
See tdf#74608 for motivation.
Change-Id: I88e3706d799941fae7ed74e0f5de1cde827c0487
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98665
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity')
5 files changed, 21 insertions, 208 deletions
diff --git a/connectivity/source/drivers/postgresql/postgresql-sdbc-impl.component b/connectivity/source/drivers/postgresql/postgresql-sdbc-impl.component index 89164b6e70d8..8c5a6ff052e3 100644 --- a/connectivity/source/drivers/postgresql/postgresql-sdbc-impl.component +++ b/connectivity/source/drivers/postgresql/postgresql-sdbc-impl.component @@ -9,9 +9,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="postgresql_sdbc_impl" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="org.openoffice.comp.connectivity.pq.Connection.noext"> + <implementation name="org.openoffice.comp.connectivity.pq.Connection.noext" + constructor="connectivity_postgresql_Connection_get_implementation"> <service name="com.sun.star.sdbc.Connection"/> </implementation> </component> diff --git a/connectivity/source/drivers/postgresql/postgresql-sdbc.component b/connectivity/source/drivers/postgresql/postgresql-sdbc.component index ebb200954632..0a10aa77b826 100644 --- a/connectivity/source/drivers/postgresql/postgresql-sdbc.component +++ b/connectivity/source/drivers/postgresql/postgresql-sdbc.component @@ -9,8 +9,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="postgresql_sdbc" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="org.openoffice.comp.connectivity.pq.Driver.noext"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="org.openoffice.comp.connectivity.pq.Driver.noext" + constructor="connectivity_pq_sdbc_driver_get_implementation"> <service name="com.sun.star.sdbc.Driver"/> </implementation> </component> diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx index b87939813bad..b0521d0a83a7 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.cxx +++ b/connectivity/source/drivers/postgresql/pq_connection.cxx @@ -116,15 +116,6 @@ public: } -static OUString ConnectionGetImplementationName() -{ - return "org.openoffice.comp.connectivity.pq.Connection.noext"; -} -static css::uno::Sequence<OUString> ConnectionGetSupportedServiceNames() -{ - return Sequence< OUString > { "com.sun.star.sdbc.Connection" }; -} - Connection::Connection( const rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::uno::XComponentContext > & ctx ) @@ -573,37 +564,14 @@ Reference< XNameAccess > Connection::getUsers() return m_settings.users; } -/// @throws Exception -static Reference< XInterface > ConnectionCreateInstance( - const Reference< XComponentContext > & ctx ) -{ - ::rtl::Reference< comphelper::RefCountedMutex > ref = new comphelper::RefCountedMutex; - return * new Connection( ref, ctx ); -} - } // end namespace - -const struct cppu::ImplementationEntry g_entries[] = +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_postgresql_Connection_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - { - pq_sdbc_driver::ConnectionCreateInstance, pq_sdbc_driver::ConnectionGetImplementationName, - pq_sdbc_driver::ConnectionGetSupportedServiceNames, cppu::createSingleComponentFactory, - nullptr , 0 - }, - { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } -}; - - -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * postgresql_sdbc_impl_component_getFactory( - const char * pImplName, void * pServiceManager, void * pRegistryKey ) -{ - return cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries ); -} - + ::rtl::Reference< comphelper::RefCountedMutex > ref = new comphelper::RefCountedMutex; + return cppu::acquire(new pq_sdbc_driver::Connection( ref, context )); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_driver.cxx b/connectivity/source/drivers/postgresql/pq_driver.cxx index 08877c356c19..ff63e8226db9 100644 --- a/connectivity/source/drivers/postgresql/pq_driver.cxx +++ b/connectivity/source/drivers/postgresql/pq_driver.cxx @@ -41,6 +41,7 @@ #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/lang/XSingleComponentFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <rtl/ref.hxx> #include "pq_driver.hxx" @@ -68,16 +69,6 @@ using com::sun::star::sdbcx::XTablesSupplier; namespace pq_sdbc_driver { -static OUString DriverGetImplementationName() -{ - return "org.openoffice.comp.connectivity.pq.Driver.noext"; -} - -static Sequence< OUString > DriverGetSupportedServiceNames() -{ - return Sequence< OUString > { "com.sun.star.sdbc.Driver" }; -} - Reference< XConnection > Driver::connect( const OUString& url,const Sequence< PropertyValue >& info ) { @@ -119,7 +110,7 @@ sal_Int32 Driver::getMinorVersion( ) // XServiceInfo OUString SAL_CALL Driver::getImplementationName() { - return DriverGetImplementationName(); + return "org.openoffice.comp.connectivity.pq.Driver.noext"; } sal_Bool Driver::supportsService(const OUString& ServiceName) @@ -129,7 +120,7 @@ sal_Bool Driver::supportsService(const OUString& ServiceName) Sequence< OUString > Driver::getSupportedServiceNames() { - return DriverGetSupportedServiceNames(); + return { "com.sun.star.sdbc.Driver" }; } // XComponent @@ -151,164 +142,17 @@ Reference< XTablesSupplier > Driver::getDataDefinitionByURL( return Reference< XTablesSupplier > ( connect( url, info ), UNO_QUERY ); } - -static Reference< XInterface > DriverCreateInstance( const Reference < XComponentContext > & ctx ) -{ - Reference< XInterface > ret = * new Driver( ctx ); - return ret; -} - -namespace { - -class OOneInstanceComponentFactory : - public MutexHolder, - public cppu::WeakComponentImplHelper< XSingleComponentFactory, XServiceInfo > -{ -public: - OOneInstanceComponentFactory( - const OUString & rImplementationName_, - cppu::ComponentFactoryFunc fptr, - const Sequence< OUString > & serviceNames, - const Reference< XComponentContext > & defaultContext) : - cppu::WeakComponentImplHelper< XSingleComponentFactory, XServiceInfo >( m_mutex ), - m_create( fptr ), - m_serviceNames( serviceNames ), - m_implName( rImplementationName_ ), - m_defaultContext( defaultContext ) - { - } - - // XSingleComponentFactory - virtual Reference< XInterface > SAL_CALL createInstanceWithContext( - Reference< XComponentContext > const & xContext ) override; - virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( - Sequence< Any > const & rArguments, - Reference< XComponentContext > const & xContext ) override; - - // XServiceInfo - OUString SAL_CALL getImplementationName() override - { - return m_implName; - } - sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override - { - return cppu::supportsService(this, ServiceName); - } - Sequence< OUString > SAL_CALL getSupportedServiceNames() override - { - return m_serviceNames; - } - - // XComponent - virtual void SAL_CALL disposing() override; - -private: - cppu::ComponentFactoryFunc m_create; - Sequence< OUString > m_serviceNames; - OUString m_implName; - Reference< XInterface > m_theInstance; - Reference< XComponentContext > m_defaultContext; -}; - -} - -Reference< XInterface > OOneInstanceComponentFactory::createInstanceWithArgumentsAndContext( - Sequence< Any > const &, const Reference< XComponentContext > & ctx ) -{ - return createInstanceWithContext( ctx ); -} - -Reference< XInterface > OOneInstanceComponentFactory::createInstanceWithContext( - const Reference< XComponentContext > & ctx ) -{ - if( ! m_theInstance.is() ) - { - // work around the problem in sdbc - Reference< XComponentContext > useCtx = ctx; - if( ! useCtx.is() ) - useCtx = m_defaultContext; - Reference< XInterface > theInstance = m_create( useCtx ); - MutexGuard guard( osl::Mutex::getGlobalMutex() ); - if( ! m_theInstance.is () ) - { - m_theInstance = theInstance; - } - } - return m_theInstance; } -void OOneInstanceComponentFactory::disposing() +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_pq_sdbc_driver_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - Reference< XComponent > rComp; - { - MutexGuard guard( osl::Mutex::getGlobalMutex() ); - rComp.set( m_theInstance, UNO_QUERY ); - m_theInstance.clear(); - } - if( rComp.is() ) - rComp->dispose(); -} - -// Reference< XSingleComponentFactory > createOneInstanceComponentFactory( -// cppu::ComponentFactoryFunc fptr, -// OUString const & rImplementationName, -// css::uno::Sequence< OUString > const & rServiceNames, -// rtl_ModuleCount * pModCount = 0 ) -// -// { -// return new OOneInstanceComponentFactory( rImplementationName, fptr , rServiceNames); -// } + static rtl::Reference<pq_sdbc_driver::Driver> g_Driver(new pq_sdbc_driver::Driver(context)); + g_Driver->acquire(); + return static_cast<cppu::OWeakObject*>(g_Driver.get()); } -const struct cppu::ImplementationEntry g_entries[] = -{ - { - pq_sdbc_driver::DriverCreateInstance, pq_sdbc_driver::DriverGetImplementationName, - pq_sdbc_driver::DriverGetSupportedServiceNames, nullptr, - nullptr , 0 - }, - { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } -}; - -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * postgresql_sdbc_component_getFactory( - const char * pImplName, void * pServiceManager, void * ) -{ - // need to extract the defaultcontext, because the way, sdbc - // bypasses the servicemanager, does not allow to use the - // XSingleComponentFactory interface ... - void * pRet = nullptr; - Reference< XSingleComponentFactory > xFactory; - Reference< css::lang::XMultiServiceFactory > xSmgr( - static_cast< XInterface * >(pServiceManager), - css::uno::UNO_QUERY_THROW ); - - for( sal_Int32 i = 0 ; g_entries[i].create ; i ++ ) - { - OUString implName = g_entries[i].getImplementationName(); - if( implName.equalsAscii( pImplName ) ) - { - Reference< XComponentContext > defaultContext( - comphelper::getComponentContext( xSmgr ) ); - xFactory = new pq_sdbc_driver::OOneInstanceComponentFactory( - implName, - g_entries[i].create, - g_entries[i].getSupportedServiceNames(), - defaultContext ); - } - } - - if( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; -} - -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_driver.hxx b/connectivity/source/drivers/postgresql/pq_driver.hxx index 4cd0ee736a31..3b61a7bcf269 100644 --- a/connectivity/source/drivers/postgresql/pq_driver.hxx +++ b/connectivity/source/drivers/postgresql/pq_driver.hxx @@ -91,14 +91,14 @@ public: // XDriver virtual sal_Int32 SAL_CALL getMajorVersion( ) override; virtual sal_Int32 SAL_CALL getMinorVersion( ) override; -public: // XServiceInfo +public: // XServiceInfo virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; -public: // XDataDefinitionSupplier + // XDataDefinitionSupplier virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; |