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 .
20 #ifndef _DBAUI_DBADMINIMPL_HXX_
21 #define _DBAUI_DBADMINIMPL_HXX_
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/sdb/XDatabaseContext.hpp>
27 #include <com/sun/star/sdbc/XConnection.hpp>
28 #include <com/sun/star/sdbc/XDriver.hpp>
29 #include <comphelper/stl_types.hxx>
30 #include "dsntypes.hxx"
31 #include <svl/itemset.hxx>
32 #include <com/sun/star/frame/XModel.hpp>
33 #include <svl/poolitem.hxx>
36 //.........................................................................
39 //.........................................................................
40 namespace DataSourceInfoConverter
42 void convert(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> & xContext
,
43 const ::dbaccess::ODsnTypeCollection
* _pCollection
,
44 const OUString
& _sOldURLPrefix
,
45 const OUString
& _sNewURLPrefix
,
46 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xDatasource
);
49 //========================================================================
50 //= ODbDataSourceAdministrationHelper
51 //========================================================================
52 class ODbDataSourceAdministrationHelper
55 DECLARE_STL_MAP(sal_Int32
, OUString
, ::std::less
< sal_Int32
>, MapInt2String
);
58 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
59 m_xContext
; /// service factory
60 ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XDatabaseContext
>
61 m_xDatabaseContext
; /// database context we're working in
62 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xDatasource
;
63 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> m_xModel
;
65 ::com::sun::star::uno::Any m_aDataSourceOrName
;
66 typedef ::std::set
< OUString
> StringSet
;
67 typedef StringSet::const_iterator ConstStringSetIterator
;
70 MapInt2String m_aDirectPropTranslator
; /// translating property id's into names (direct properties of a data source)
71 MapInt2String m_aIndirectPropTranslator
; /// translating property id's into names (indirect properties of a data source)
73 IItemSetHelper
* m_pItemSetHelper
;
76 ODbDataSourceAdministrationHelper(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _xORB
78 ,IItemSetHelper
* _pItemSetHelper
);
80 /** translate the current dialog SfxItems into driver relevant PropertyValues
81 @see successfullyConnected
83 sal_Bool
getCurrentSettings(::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rDriverParams
);
85 /** to be called if the settings got from getCurrentSettings have been used for successfully connecting
86 @see getCurrentSettings
88 void successfullyConnected();
90 /// clear the password in the current data source's item set
93 inline ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> getORB() const { return m_xContext
; }
95 ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XDatabaseContext
> getDatabaseContext() const { return m_xDatabaseContext
; }
97 /** creates a new connection. The caller is responsible to dispose it !!!!
99 ::std::pair
< ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>,sal_Bool
> createConnection();
101 /** return the corresponding driver for the selected URL
103 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> getDriver();
104 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> getDriver(const OUString
& _sURL
);
106 /** returns the data source the dialog is currently working with
108 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getCurrentDataSource();
109 // returns the Url of a database document
110 String
getDocumentUrl(SfxItemSet
& _rDest
);
112 void setDataSourceOrName( const ::com::sun::star::uno::Any
& _rDataSourceOrName
);
114 /** extracts the connection type from the given set<p/>
115 The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
117 static OUString
getDatasourceType( const SfxItemSet
& _rSet
);
119 /** returns the connection URL
123 String
getConnectionURL() const;
125 /// fill the necessary information from the url line
126 void convertUrl(SfxItemSet
& _rDest
);
128 const MapInt2String
& getIndirectProperties() const { return m_aIndirectPropTranslator
; }
130 /** translates properties of an UNO data source into SfxItems
134 The item set to fill.
136 void translateProperties(
137 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxSource
,
140 /** translate SfxItems into properties of an UNO data source
142 The item set to read from.
144 The data source to fill.
146 void translateProperties(
147 const SfxItemSet
& _rSource
,
148 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxDest
);
150 sal_Bool
saveChanges(const SfxItemSet
& _rSource
);
152 /** fill a data source info array with the settings from a given item set
154 void fillDatasourceInfo(const SfxItemSet
& _rSource
, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rInfo
);
156 /// translate the given value into an SfxPoolItem, put this into the given set under the given id
157 void implTranslateProperty(SfxItemSet
& _rSet
, sal_Int32 _nId
, const ::com::sun::star::uno::Any
& _rValue
);
159 /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
160 ::com::sun::star::uno::Any
implTranslateProperty(const SfxPoolItem
* _pItem
);
162 /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>, set it (under the given name) on the given property set
163 void implTranslateProperty(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxSet
, const OUString
& _rName
, const SfxPoolItem
* _pItem
);
165 /** check if the data source described by the given set needs authentication<p/>
166 The return value depends on the data source type only.
168 sal_Bool
hasAuthentication(const SfxItemSet
& _rSet
) const;
170 #if OSL_DEBUG_LEVEL > 0
171 OString
translatePropertyId( sal_Int32 _nId
);
175 //.........................................................................
177 //.........................................................................
179 #endif // _DBAUI_DBADMINIMPL_HXX_
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */