1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sal/config.h>
27 #include <com/sun/star/sdbc/XDriverManager2.hpp>
28 #include <com/sun/star/uno/XNamingService.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
32 #include <cppuhelper/basemutex.hxx>
33 #include <cppuhelper/compbase.hxx>
34 #include <comphelper/logging.hxx>
35 #include <connectivity/DriversConfig.hxx>
37 namespace drivermanager
40 typedef std::map
< OUString
, css::uno::Reference
< css::sdbc::XDriver
> > DriverCollection
;
44 OUString sImplementationName
; /// the implementation name of the driver
45 css::uno::Reference
< css::sdbc::XDriver
> xDriver
; /// the driver itself
46 css::uno::Reference
< css::lang::XSingleComponentFactory
> xComponentFactory
; /// the factory to create the driver component (if not already done so)
50 // OSDBCDriverManager - the one-instance service for managing SDBC drivers
52 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XDriverManager2
53 , css::lang::XServiceInfo
54 , css::uno::XNamingService
55 > OSDBCDriverManager_Base
;
57 class OSDBCDriverManager final
: public cppu::BaseMutex
, public OSDBCDriverManager_Base
59 friend class ODriverEnumeration
;
61 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
62 ::comphelper::EventLogger m_aEventLogger
;
64 typedef std::vector
<DriverAccess
> DriverAccessArray
;
65 DriverAccessArray m_aDriversBS
;
67 // for drivers registered at runtime (not bootstrapped) we don't require an XServiceInfo interface,
68 // so we have to remember their impl-name in another way
69 typedef std::map
< OUString
, css::uno::Reference
< css::sdbc::XDriver
> > DriverCollection
;
70 DriverCollection m_aDriversRT
;
72 ::connectivity::DriversConfig m_aDriverConfig
;
73 sal_Int32 m_nLoginTimeout
;
77 explicit OSDBCDriverManager(
78 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
79 virtual ~OSDBCDriverManager() override
;
82 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( const OUString
& url
) override
;
83 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnectionWithInfo( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
84 virtual void SAL_CALL
setLoginTimeout( sal_Int32 seconds
) override
;
85 virtual sal_Int32 SAL_CALL
getLoginTimeout( ) override
;
88 virtual css::uno::Reference
< css::sdbc::XDriver
> SAL_CALL
getDriverByURL( const OUString
& url
) override
;
91 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration( ) override
;
94 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
95 virtual sal_Bool SAL_CALL
hasElements( ) override
;
98 virtual OUString SAL_CALL
getImplementationName( ) override
;
99 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
100 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
103 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getRegisteredObject( const OUString
& Name
) override
;
104 virtual void SAL_CALL
registerObject( const OUString
& Name
, const css::uno::Reference
< css::uno::XInterface
>& Object
) override
;
105 virtual void SAL_CALL
revokeObject( const OUString
& Name
) override
;
108 css::uno::Reference
< css::sdbc::XDriver
> implGetDriverForURL(const OUString
& _rURL
);
110 /** retrieve the driver order preferences from the configuration and
111 sort m_aDriversBS accordingly.
113 void initializeDriverPrecedence();
115 void bootstrapDrivers();
118 } // namespace drivermanager
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */