[Libreoffice-commits] core.git: dbaccess/Library_dba.mk dbaccess/source dbaccess/util
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jul 31 06:41:41 UTC 2020
dbaccess/Library_dba.mk | 1
dbaccess/source/core/dataaccess/databasecontext.cxx | 47 +++++++++------
dbaccess/source/core/inc/DatabaseDataProvider.hxx | 8 --
dbaccess/source/core/inc/databasecontext.hxx | 11 +--
dbaccess/source/core/misc/DatabaseDataProvider.cxx | 28 +++------
dbaccess/source/core/misc/services.cxx | 59 --------------------
dbaccess/source/filter/xml/dbloader2.cxx | 5 +
dbaccess/util/dba.component | 10 ++-
8 files changed, 54 insertions(+), 115 deletions(-)
New commits:
commit 6362ebab298549e8616c32cafd75cb3959ba7d65
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 9 08:51:57 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jul 31 08:41:02 2020 +0200
dbaccess: create instances with uno constructors
See tdf#74608 for motivation
Change-Id: Icbce3ef3f77a19f9174f6aa39791dcf99e51f0c2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98395
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/dbaccess/Library_dba.mk b/dbaccess/Library_dba.mk
index ecef24d3b4c2..e8f65a5e1a6b 100644
--- a/dbaccess/Library_dba.mk
+++ b/dbaccess/Library_dba.mk
@@ -120,7 +120,6 @@ $(eval $(call gb_Library_add_exception_objects,dba,\
dbaccess/source/core/misc/migrwarndlg \
dbaccess/source/core/misc/PropertyForward \
dbaccess/source/core/misc/sdbcoretools \
- dbaccess/source/core/misc/services \
dbaccess/source/core/misc/veto \
dbaccess/source/core/recovery/dbdocrecovery \
dbaccess/source/core/recovery/settingsimport \
diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx
index c7ddce73b48a..01d83bafa7ee 100644
--- a/dbaccess/source/core/dataaccess/databasecontext.cxx
+++ b/dbaccess/source/core/dataaccess/databasecontext.cxx
@@ -60,6 +60,7 @@
#include <tools/diagnose_ex.h>
#include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx>
+#include <rtl/ref.hxx>
#include <unotools/sharedunocomponent.hxx>
#include <vector>
@@ -84,6 +85,10 @@ using ::com::sun::star::ucb::InteractiveIOException;
using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING_PATH;
+static osl::Mutex g_InstanceGuard;
+static rtl::Reference<dbaccess::ODatabaseContext> g_Instance;
+static bool g_Disposed = false;
+
namespace dbaccess
{
@@ -196,26 +201,10 @@ ODatabaseContext::~ODatabaseContext()
m_xDatabaseRegistrations.clear();
}
-// Helper
-OUString ODatabaseContext::getImplementationName_static()
-{
- return "com.sun.star.comp.dba.ODatabaseContext";
-}
-
-Reference< XInterface > ODatabaseContext::Create(const Reference< XComponentContext >& _rxContext)
-{
- return *( new ODatabaseContext( _rxContext ) );
-}
-
-Sequence< OUString > ODatabaseContext::getSupportedServiceNames_static()
-{
- return { "com.sun.star.sdb.DatabaseContext" };
-}
-
// XServiceInfo
OUString ODatabaseContext::getImplementationName( )
{
- return getImplementationName_static();
+ return "com.sun.star.comp.dba.ODatabaseContext";
}
sal_Bool ODatabaseContext::supportsService( const OUString& _rServiceName )
@@ -225,7 +214,7 @@ sal_Bool ODatabaseContext::supportsService( const OUString& _rServiceName )
Sequence< OUString > ODatabaseContext::getSupportedServiceNames( )
{
- return getSupportedServiceNames_static();
+ return { "com.sun.star.sdb.DatabaseContext" };
}
Reference< XInterface > ODatabaseContext::impl_createNewDataSource()
@@ -278,6 +267,14 @@ void ODatabaseContext::disposing()
}
}
+void ODatabaseContext::dispose()
+{
+ DatabaseAccessContext_Base::dispose();
+ osl::MutexGuard aGuard(g_InstanceGuard);
+ g_Instance.clear();
+ g_Disposed = true;
+}
+
// XNamingService
Reference< XInterface > ODatabaseContext::getRegisteredObject(const OUString& _rName)
{
@@ -760,4 +757,18 @@ void ODatabaseContext::onBasicManagerCreated( const Reference< XModel >& _rxForD
} // namespace dbaccess
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_dba_ODatabaseContext_get_implementation(
+ css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
+{
+ osl::MutexGuard aGuard(g_InstanceGuard);
+ if (g_Disposed)
+ return nullptr;
+ if (!g_Instance)
+ g_Instance.set(new dbaccess::ODatabaseContext(context));
+ g_Instance->acquire();
+ return static_cast<cppu::OWeakObject*>(g_Instance.get());
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/core/inc/DatabaseDataProvider.hxx b/dbaccess/source/core/inc/DatabaseDataProvider.hxx
index 68c066412a20..3ea202a10c85 100644
--- a/dbaccess/source/core/inc/DatabaseDataProvider.hxx
+++ b/dbaccess/source/core/inc/DatabaseDataProvider.hxx
@@ -52,14 +52,6 @@ class DatabaseDataProvider: private ::cppu::BaseMutex,
public:
explicit DatabaseDataProvider(css::uno::Reference< css::uno::XComponentContext > const & context);
- // css::lang::XServiceInfo - static methods
- /// @throws css::uno::RuntimeException
- static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
- /// @throws css::uno::RuntimeException
- static OUString getImplementationName_Static();
- static css::uno::Reference< css::uno::XInterface >
- Create(css::uno::Reference< css::uno::XComponentContext > const & context);
-
private:
// css::uno::XInterface:
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) override;
diff --git a/dbaccess/source/core/inc/databasecontext.hxx b/dbaccess/source/core/inc/databasecontext.hxx
index 0c1848042b26..4b5e8aec6c94 100644
--- a/dbaccess/source/core/inc/databasecontext.hxx
+++ b/dbaccess/source/core/inc/databasecontext.hxx
@@ -116,6 +116,9 @@ public:
// OComponentHelper
virtual void SAL_CALL disposing() override;
+ // XComponent
+ virtual void SAL_CALL dispose() override;
+
// XSingleServiceFactory
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) override;
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& _rArguments ) override;
@@ -125,14 +128,6 @@ public:
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
- // XServiceInfo - static methods
- /// @throws css::uno::RuntimeException
- static css::uno::Sequence< OUString > getSupportedServiceNames_static();
- /// @throws css::uno::RuntimeException
- static OUString getImplementationName_static();
- static css::uno::Reference< css::uno::XInterface >
- Create(const css::uno::Reference< css::uno::XComponentContext >&);
-
// XElementAccess
virtual css::uno::Type SAL_CALL getElementType( ) override;
virtual sal_Bool SAL_CALL hasElements( ) override;
diff --git a/dbaccess/source/core/misc/DatabaseDataProvider.cxx b/dbaccess/source/core/misc/DatabaseDataProvider.cxx
index b5179e57b32f..185591d76203 100644
--- a/dbaccess/source/core/misc/DatabaseDataProvider.cxx
+++ b/dbaccess/source/core/misc/DatabaseDataProvider.cxx
@@ -96,15 +96,10 @@ uno::Any DatabaseDataProvider::queryInterface(uno::Type const & type)
return TDatabaseDataProvider::queryInterface(type);
}
-OUString DatabaseDataProvider::getImplementationName_Static( )
-{
- return "com.sun.star.comp.dbaccess.DatabaseDataProvider";
-}
-
// XServiceInfo
OUString SAL_CALL DatabaseDataProvider::getImplementationName( )
{
- return getImplementationName_Static();
+ return "com.sun.star.comp.dbaccess.DatabaseDataProvider";
}
sal_Bool SAL_CALL DatabaseDataProvider::supportsService( const OUString& _rServiceName )
@@ -112,19 +107,9 @@ sal_Bool SAL_CALL DatabaseDataProvider::supportsService( const OUString& _rServi
return cppu::supportsService(this, _rServiceName);
}
-uno::Sequence< OUString > DatabaseDataProvider::getSupportedServiceNames_Static( )
-{
- return { "com.sun.star.chart2.data.DatabaseDataProvider" };
-}
-
uno::Sequence< OUString > SAL_CALL DatabaseDataProvider::getSupportedServiceNames( )
{
- return getSupportedServiceNames_Static();
-}
-
-uno::Reference< uno::XInterface > DatabaseDataProvider::Create(uno::Reference< uno::XComponentContext > const & context)
-{
- return *(new DatabaseDataProvider(context)) ;
+ return { "com.sun.star.chart2.data.DatabaseDataProvider" };
}
// lang::XInitialization:
@@ -1077,4 +1062,13 @@ void DatabaseDataProvider::impl_invalidateParameter_nothrow()
} // namespace dbaccess
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_dbaccess_DatabaseDataProvider_get_implementation(
+ css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
+{
+ return cppu::acquire(new dbaccess::DatabaseDataProvider(context));
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/core/misc/services.cxx b/dbaccess/source/core/misc/services.cxx
deleted file mode 100644
index c45c1673b03e..000000000000
--- a/dbaccess/source/core/misc/services.cxx
+++ /dev/null
@@ -1,59 +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 <cppuhelper/factory.hxx>
-#include <cppuhelper/implementationentry.hxx>
-#include <DatabaseDataProvider.hxx>
-
-#include <databasecontext.hxx>
-
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::registry;
-
-namespace dba{
- ::cppu::ImplementationEntry const entries[] = {
- {
- &::dbaccess::DatabaseDataProvider::Create,
- &::dbaccess::DatabaseDataProvider::getImplementationName_Static,
- &::dbaccess::DatabaseDataProvider::getSupportedServiceNames_Static,
- &cppu::createSingleComponentFactory, nullptr, 0
- },
-
- {
- &dbaccess::ODatabaseContext::Create,
- &dbaccess::ODatabaseContext::getImplementationName_static,
- &dbaccess::ODatabaseContext::getSupportedServiceNames_static,
- &cppu::createOneInstanceComponentFactory, nullptr, 0
- },
-
- { nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
- };
-}
-
-extern "C" SAL_DLLPUBLIC_EXPORT void* dba_component_getFactory(
- const char* pImplementationName,
- void* pServiceManager,
- void* pRegistryKey)
-{
- return cppu::component_getFactoryHelper(
- pImplementationName, pServiceManager, pRegistryKey, dba::entries);
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx
index 9587647a38ff..8ccf9e5d7a02 100644
--- a/dbaccess/source/filter/xml/dbloader2.cxx
+++ b/dbaccess/source/filter/xml/dbloader2.cxx
@@ -355,10 +355,13 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU
OUString sViewName = aMediaDesc.getOrDefault( "ViewName", OUString( "Default" ) );
aMediaDesc.remove( "ViewName" );
+ // this needs to stay alive for duration of this method
+ Reference< XDatabaseContext > xDatabaseContext;
+
sal_Int32 nInitialSelection = -1;
if ( !xModel.is() )
{
- Reference< XDatabaseContext > xDatabaseContext( DatabaseContext::create(m_aContext) );
+ xDatabaseContext = DatabaseContext::create(m_aContext);
OUString sFactoryName = SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::EFactory::DATABASE);
bCreateNew = sFactoryName.match(_rURL);
diff --git a/dbaccess/util/dba.component b/dbaccess/util/dba.component
index 90ba9e3ba7e9..83795ff82f77 100644
--- a/dbaccess/util/dba.component
+++ b/dbaccess/util/dba.component
@@ -18,8 +18,9 @@
-->
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
- prefix="dba" xmlns="http://openoffice.org/2010/uno-components">
- <implementation name="com.sun.star.comp.dbaccess.DatabaseDataProvider">
+ xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="com.sun.star.comp.dbaccess.DatabaseDataProvider"
+ constructor="com_sun_star_comp_dbaccess_DatabaseDataProvider_get_implementation">
<service name="com.sun.star.chart2.data.DatabaseDataProvider"/>
</implementation>
<implementation name="com.sun.star.comp.dba.DataAccessDescriptorFactory"
@@ -35,7 +36,10 @@
constructor="com_sun_star_comp_dba_OComponentDefinition">
<service name="com.sun.star.sdb.TableDefinition"/>
</implementation>
- <implementation name="com.sun.star.comp.dba.ODatabaseContext">
+ <implementation name="com.sun.star.comp.dba.ODatabaseContext"
+ constructor="com_sun_star_comp_dba_ODatabaseContext_get_implementation">
+ <!-- fake singleton so the servicemanager calls dispose() on us so we can clean up the global -->
+ <singleton name="com.sun.star.comp.dba.theODatabaseContext"/>
<service name="com.sun.star.sdb.DatabaseContext"/>
</implementation>
<implementation name="com.sun.star.comp.dba.ODatabaseDocument"
More information about the Libreoffice-commits
mailing list