connectivity/odbc: create instances with uno constructors

See tdf#74608 for motivation.

Change-Id: I7cc971c7a99950a05804ae73f132c68e0c5a0625
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99186
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2020-07-22 10:26:19 +02:00 committed by Noel Grandin
parent 7667525aa7
commit d812521ec4
7 changed files with 18 additions and 185 deletions

View File

@ -44,7 +44,6 @@ $(eval $(call gb_Library_use_libraries,odbc,\
))
$(eval $(call gb_Library_add_exception_objects,odbc,\
connectivity/source/drivers/odbc/oservices \
connectivity/source/drivers/odbc/ORealDriver \
connectivity/source/drivers/odbc/OFunctions \
connectivity/source/drivers/odbc/OPreparedStatement \

View File

@ -31,9 +31,9 @@ using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc;
ODBCDriver::ODBCDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory)
ODBCDriver::ODBCDriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext)
:ODriver_BASE(m_aMutex)
,m_xORB(_rxFactory)
,m_xContext(_rxContext)
,m_pDriverHandle(SQL_NULL_HANDLE)
{
}
@ -56,7 +56,7 @@ void ODBCDriver::disposing()
// static ServiceInfo
OUString ODBCDriver::getImplementationName_Static( )
OUString ODBCDriver::getImplementationName( )
{
return "com.sun.star.comp.sdbc.ODBCDriver";
// this name is referenced in the configuration and in the odbc.xml
@ -64,29 +64,18 @@ OUString ODBCDriver::getImplementationName_Static( )
}
Sequence< OUString > ODBCDriver::getSupportedServiceNames_Static( )
Sequence< OUString > ODBCDriver::getSupportedServiceNames( )
{
return { "com.sun.star.sdbc.Driver" };
}
OUString SAL_CALL ODBCDriver::getImplementationName( )
{
return getImplementationName_Static();
}
sal_Bool SAL_CALL ODBCDriver::supportsService( const OUString& _rServiceName )
{
return cppu::supportsService(this, _rServiceName);
}
Sequence< OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( )
{
return getSupportedServiceNames_Static();
}
Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, const Sequence< PropertyValue >& info )
{
if ( ! acceptsURL(url) )

View File

@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "ORealDriver.hxx"
#include <odbc/ODriver.hxx>
#include <odbc/OTools.hxx>
#include <odbc/OFunctions.hxx>
@ -32,7 +31,7 @@ namespace connectivity::odbc
virtual oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const override;
virtual SQLHANDLE EnvironmentHandle(OUString &_rPath) override;
public:
explicit ORealOdbcDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory) {}
explicit ORealOdbcDriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext) : ODBCDriver(_rxContext) {}
};
}
@ -259,11 +258,6 @@ oslGenericFunction ORealOdbcDriver::getOdbcFunction(ODBC3SQLFunctionId _nIndex)
}
css::uno::Reference< css::uno::XInterface > ODBCDriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory)
{
return *(new ORealOdbcDriver(_rxFactory));
}
// ODBC Environment (common for all Connections):
SQLHANDLE ORealOdbcDriver::EnvironmentHandle(OUString &_rPath)
{
@ -286,7 +280,12 @@ SQLHANDLE ORealOdbcDriver::EnvironmentHandle(OUString &_rPath)
return m_pDriverHandle;
}
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
connectivity_odbc_ORealOdbcDriver_get_implementation(
css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
{
return cppu::acquire(new connectivity::odbc::ORealOdbcDriver(context));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -1,42 +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 .
*/
#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_ODBC_OREALDRIVER_HXX
#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_ODBC_OREALDRIVER_HXX
#include <sal/config.h>
#include <com/sun/star/uno/Reference.hxx>
namespace com::sun::star {
namespace lang { class XMultiServiceFactory; }
namespace uno { class XInterface; }
}
namespace connectivity::odbc {
/// @throws css::uno::Exception
css::uno::Reference< css::uno::XInterface >
ODBCDriver_CreateInstance( css::uno::Reference< css::lang::XMultiServiceFactory > const & factory);
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -18,8 +18,9 @@
-->
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
prefix="odbc" xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.comp.sdbc.ODBCDriver">
xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.comp.sdbc.ODBCDriver"
constructor="connectivity_odbc_ORealOdbcDriver_get_implementation">
<service name="com.sun.star.sdbc.Driver"/>
</implementation>
</component>

View File

@ -1,108 +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 "ORealDriver.hxx"
#include <odbc/ODriver.hxx>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
using namespace connectivity::odbc;
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* odbc_component_getFactory(
const char* pImplementationName,
void* pServiceManager,
void* /*pRegistryKey*/)
{
void* pRet = nullptr;
if (pServiceManager)
{
ProviderRequest aReq(pServiceManager,pImplementationName);
aReq.CREATE_PROVIDER(
ODBCDriver::getImplementationName_Static(),
ODBCDriver::getSupportedServiceNames_Static(),
ODBCDriver_CreateInstance, ::cppu::createSingleFactory)
;
if(aReq.xRet.is())
aReq.xRet->acquire();
pRet = aReq.getProvider();
}
return pRet;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -22,7 +22,7 @@
#include <com/sun/star/sdbc/XDriver.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <cppuhelper/compbase.hxx>
#include <connectivity/odbc.hxx>
#include <odbc/odbcbasedllapi.hxx>
@ -43,24 +43,19 @@ namespace connectivity::odbc
// of all the Connection objects
// for this Driver
css::uno::Reference< css::lang::XMultiServiceFactory > m_xORB;
css::uno::Reference< css::uno::XComponentContext > m_xContext;
SQLHANDLE m_pDriverHandle;
virtual SQLHANDLE EnvironmentHandle(OUString &_rPath) = 0;
public:
ODBCDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory);
ODBCDriver(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
// only possibility to get the odbc functions
virtual oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const = 0;
// 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( );
// XServiceInfo
virtual OUString SAL_CALL getImplementationName( ) override;
@ -74,7 +69,7 @@ namespace connectivity::odbc
virtual sal_Int32 SAL_CALL getMajorVersion( ) override;
virtual sal_Int32 SAL_CALL getMinorVersion( ) override;
const css::uno::Reference< css::lang::XMultiServiceFactory >& getORB() const { return m_xORB; }
const css::uno::Reference< css::uno::XComponentContext >& getContext() const { return m_xContext; }
};
}