1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "DbAdminImpl.hxx"
33 #include <svl/poolitem.hxx>
34 #include <svl/itempool.hxx>
35 #include <svl/stritem.hxx>
36 #include <svl/intitem.hxx>
37 #include <svl/eitem.hxx>
38 #include "DriverSettings.hxx"
39 #include "IItemSetHelper.hxx"
40 #include "UITools.hxx"
41 #include "dbu_dlg.hrc"
42 #include "dbustrings.hrc"
43 #include "dsitems.hxx"
44 #include "dsnItem.hxx"
45 #include "moduledbu.hxx"
46 #include "optionalboolitem.hxx"
47 #include "propertysetitem.hxx"
48 #include "stringlistitem.hxx"
49 #include "OAuthenticationContinuation.hxx"
51 /** === begin UNO includes === **/
52 #include <com/sun/star/beans/PropertyAttribute.hpp>
53 #include <com/sun/star/frame/XStorable.hpp>
54 #include <com/sun/star/sdb/SQLContext.hpp>
55 #include <com/sun/star/sdbc/XDriver.hpp>
56 #include <com/sun/star/sdbc/XDriverAccess.hpp>
57 #include <com/sun/star/task/XInteractionHandler.hpp>
58 #include <com/sun/star/task/XInteractionRequest.hpp>
59 #include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
60 #include <com/sun/star/ucb/AuthenticationRequest.hpp>
61 /** === end UNO includes === **/
63 #include <comphelper/guarding.hxx>
64 #include <comphelper/interaction.hxx>
65 #include <comphelper/property.hxx>
66 #include <comphelper/sequence.hxx>
67 #include <comphelper/string.hxx>
68 #include <connectivity/DriversConfig.hxx>
69 #include <connectivity/dbexception.hxx>
70 #include <osl/file.hxx>
71 #include <tools/diagnose_ex.h>
72 #include <osl/diagnose.h>
73 #include <typelib/typedescription.hxx>
74 #include <vcl/svapp.hxx>
75 #include <vcl/msgbox.hxx>
76 #include <vcl/stdtext.hxx>
77 #include <vcl/waitobj.hxx>
78 #include <osl/mutex.hxx>
82 #include <o3tl/compat_functional.hxx>
84 //.........................................................................
87 //.........................................................................
88 using namespace ::dbtools
;
89 using namespace com::sun::star::uno
;
90 using namespace com::sun::star
;
91 using namespace com::sun::star::ucb
;
92 using namespace com::sun::star::task
;
93 using namespace com::sun::star::sdbc
;
94 using namespace com::sun::star::sdb
;
95 using namespace com::sun::star::lang
;
96 using namespace com::sun::star::beans
;
97 using namespace com::sun::star::util
;
98 using namespace com::sun::star::container
;
99 using namespace com::sun::star::frame
;
101 //-------------------------------------------------------------------------
104 sal_Bool
implCheckItemType( SfxItemSet
& _rSet
, const sal_uInt16 _nId
, const TypeId _nExpectedItemType
)
106 sal_Bool bCorrectType
= sal_False
;
108 SfxItemPool
* pPool
= _rSet
.GetPool();
109 OSL_ENSURE( pPool
, "implCheckItemType: invalid item pool!" );
112 const SfxPoolItem
& rDefItem
= pPool
->GetDefaultItem( _nId
);
113 bCorrectType
= rDefItem
.IsA( _nExpectedItemType
);
118 void lcl_putProperty(const Reference
< XPropertySet
>& _rxSet
, const ::rtl::OUString
& _rName
, const Any
& _rValue
)
123 _rxSet
->setPropertyValue(_rName
, _rValue
);
127 #if OSL_DEBUG_LEVEL > 0
128 ::rtl::OString
sMessage("ODbAdminDialog::implTranslateProperty: could not set the property ");
129 sMessage
+= ::rtl::OString(_rName
.getStr(), _rName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
130 sMessage
+= ::rtl::OString("!");
131 OSL_FAIL(sMessage
.getStr());
137 String
lcl_createHostWithPort(const SfxStringItem
* _pHostName
,const SfxInt32Item
* _pPortNumber
)
141 if ( _pHostName
&& _pHostName
->GetValue().Len() )
142 sNewUrl
= _pHostName
->GetValue();
146 sNewUrl
+= String::CreateFromAscii(":");
147 sNewUrl
+= String::CreateFromInt32(_pPortNumber
->GetValue());
154 //========================================================================
155 //= ODbDataSourceAdministrationHelper
156 //========================================================================
157 ODbDataSourceAdministrationHelper::ODbDataSourceAdministrationHelper(const Reference
< XMultiServiceFactory
>& _xORB
,Window
* _pParent
,IItemSetHelper
* _pItemSetHelper
)
159 , m_pParent(_pParent
)
160 , m_pItemSetHelper(_pItemSetHelper
)
162 /// initialize the property translation map
163 // direct properties of a data source
164 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONNECTURL
, PROPERTY_URL
));
165 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_NAME
, PROPERTY_NAME
));
166 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_USER
, PROPERTY_USER
));
167 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_PASSWORD
, PROPERTY_PASSWORD
));
168 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_PASSWORDREQUIRED
, PROPERTY_ISPASSWORDREQUIRED
));
169 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_TABLEFILTER
, PROPERTY_TABLEFILTER
));
170 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_READONLY
, PROPERTY_ISREADONLY
));
171 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_SUPPRESSVERSIONCL
, PROPERTY_SUPPRESSVERSIONCL
));
173 // implicit properties, to be found in the direct property "Info"
174 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_JDBCDRIVERCLASS
, INFO_JDBCDRIVERCLASS
));
175 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_TEXTFILEEXTENSION
, INFO_TEXTFILEEXTENSION
));
176 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CHARSET
, INFO_CHARSET
));
177 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_TEXTFILEHEADER
, INFO_TEXTFILEHEADER
));
178 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_FIELDDELIMITER
, INFO_FIELDDELIMITER
));
179 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_TEXTDELIMITER
, INFO_TEXTDELIMITER
));
180 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DECIMALDELIMITER
, INFO_DECIMALDELIMITER
));
181 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_THOUSANDSDELIMITER
, INFO_THOUSANDSDELIMITER
));
182 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_SHOWDELETEDROWS
, INFO_SHOWDELETEDROWS
));
183 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ALLOWLONGTABLENAMES
, INFO_ALLOWLONGTABLENAMES
));
184 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ADDITIONALOPTIONS
, INFO_ADDITIONALOPTIONS
));
185 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_SQL92CHECK
, PROPERTY_ENABLESQL92CHECK
));
186 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AUTOINCREMENTVALUE
, PROPERTY_AUTOINCREMENTCREATION
));
187 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AUTORETRIEVEVALUE
, INFO_AUTORETRIEVEVALUE
));
188 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AUTORETRIEVEENABLED
, INFO_AUTORETRIEVEENABLED
));
189 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_APPEND_TABLE_ALIAS
, INFO_APPEND_TABLE_ALIAS
));
190 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AS_BEFORE_CORRNAME
, INFO_AS_BEFORE_CORRELATION_NAME
) );
191 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CHECK_REQUIRED_FIELDS
, INFO_FORMS_CHECK_REQUIRED_FIELDS
) );
192 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ESCAPE_DATETIME
, INFO_ESCAPE_DATETIME
) );
193 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_PRIMARY_KEY_SUPPORT
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrimaryKeySupport" ) ) ) );
194 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_PARAMETERNAMESUBST
, INFO_PARAMETERNAMESUBST
));
195 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_IGNOREDRIVER_PRIV
, INFO_IGNOREDRIVER_PRIV
));
196 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_BOOLEANCOMPARISON
, PROPERTY_BOOLEANCOMPARISONMODE
));
197 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ENABLEOUTERJOIN
, PROPERTY_ENABLEOUTERJOIN
));
198 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CATALOG
, PROPERTY_USECATALOGINSELECT
));
199 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_SCHEMA
, PROPERTY_USESCHEMAINSELECT
));
200 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_INDEXAPPENDIX
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AddIndexAppendix"))));
201 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DOSLINEENDS
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreferDosLikeLineEnds" ) ) ) );
202 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_SOCKET
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LocalSocket" ) ) ) );
203 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_NAMED_PIPE
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPipe" ) ) ) );
204 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_RESPECTRESULTSETTYPE
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RespectDriverResultSetType" ) ) ) );
205 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_MAX_ROW_SCAN
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxRowScan" ) ) ) );
207 // extra settings for odbc
208 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_USECATALOG
, INFO_USECATALOG
));
209 // extra settings for a ldap address book
210 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_BASEDN
, INFO_CONN_LDAP_BASEDN
));
211 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_ROWCOUNT
, INFO_CONN_LDAP_ROWCOUNT
));
212 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_USESSL
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSSL"))));
213 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DOCUMENT_URL
, PROPERTY_URL
));
216 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_IGNORECURRENCY
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))));
220 m_xDatabaseContext
= Reference
< XNameAccess
>(m_xORB
->createInstance(SERVICE_SDB_DATABASECONTEXT
), UNO_QUERY
);
221 m_xDynamicContext
.set(m_xDatabaseContext
,UNO_QUERY
);
227 if ( !m_xDatabaseContext
.is() )
229 ShowServiceNotAvailableError(_pParent
->GetParent(), String(SERVICE_SDB_DATABASECONTEXT
), sal_True
);
232 OSL_ENSURE(m_xDynamicContext
.is(), "ODbAdminDialog::ODbAdminDialog : no XNamingService interface !");
234 //-------------------------------------------------------------------------
235 sal_Bool
ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence
< PropertyValue
>& _rDriverParam
)
237 OSL_ENSURE(m_pItemSetHelper
->getOutputSet(), "ODbDataSourceAdministrationHelper::getCurrentSettings : not to be called without an example set!");
238 if (!m_pItemSetHelper
->getOutputSet())
241 ::std::vector
< PropertyValue
> aReturn
;
242 // collecting this in a vector because it has a push_back, in opposite to sequences
244 // user: DSID_USER -> "user"
245 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pUser
, SfxStringItem
, DSID_USER
, sal_True
);
246 if (pUser
&& pUser
->GetValue().Len())
248 PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), 0,
249 makeAny(::rtl::OUString(pUser
->GetValue())), PropertyState_DIRECT_VALUE
));
251 // check if the connection type requires a password
252 if (hasAuthentication(*m_pItemSetHelper
->getOutputSet()))
254 // password: DSID_PASSWORD -> "password"
255 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPassword
, SfxStringItem
, DSID_PASSWORD
, sal_True
);
256 String sPassword
= pPassword
? pPassword
->GetValue() : String();
257 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPasswordRequired
, SfxBoolItem
, DSID_PASSWORDREQUIRED
, sal_True
);
258 // if the set does not contain a password, but the item set says it requires one, ask the user
259 if ((!pPassword
|| !pPassword
->GetValue().Len()) && (pPasswordRequired
&& pPasswordRequired
->GetValue()))
261 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pName
, SfxStringItem
, DSID_NAME
, sal_True
);
263 Reference
< XModel
> xModel( getDataSourceOrModel( m_xDatasource
), UNO_QUERY_THROW
);
264 ::comphelper::NamedValueCollection
aArgs( xModel
->getArgs() );
265 Reference
< XInteractionHandler
> xHandler( aArgs
.getOrDefault( "InteractionHandler", Reference
< XInteractionHandler
>() ) );
267 if ( !xHandler
.is() )
269 // instantiate the default SDB interaction handler
270 xHandler
= Reference
< XInteractionHandler
>( m_xORB
->createInstance( SERVICE_TASK_INTERACTION_HANDLER
), UNO_QUERY
);
271 if ( !xHandler
.is() )
272 ShowServiceNotAvailableError(m_pParent
->GetParent(), String(SERVICE_TASK_INTERACTION_HANDLER
), sal_True
);
275 String sName
= pName
? pName
->GetValue() : String();
276 String
sLoginRequest(ModuleRes(STR_ENTER_CONNECTION_PASSWORD
));
277 ::rtl::OUString sTemp
= sName
;
278 sName
= ::dbaui::getStrippedDatabaseName(NULL
,sTemp
);
280 sLoginRequest
.SearchAndReplaceAscii("$name$", sName
);
283 sLoginRequest
.SearchAndReplaceAscii("\"$name$\"", String());
284 sLoginRequest
.SearchAndReplaceAscii("$name$", String()); // just to be sure that in other languages the string will be deleted
288 AuthenticationRequest aRequest
;
289 aRequest
.ServerName
= sName
;
290 aRequest
.Diagnostic
= sLoginRequest
;
291 aRequest
.HasRealm
= aRequest
.HasAccount
= sal_False
;
293 aRequest
.HasUserName
= pUser
!= 0;
294 aRequest
.UserName
= pUser
? rtl::OUString(pUser
->GetValue()) : ::rtl::OUString();
295 aRequest
.HasPassword
= sal_True
;
297 aRequest
.HasAccount
= sal_False
;
300 comphelper::OInteractionRequest
* pRequest
= new comphelper::OInteractionRequest(makeAny(aRequest
));
301 uno::Reference
< XInteractionRequest
> xRequest(pRequest
);
303 // build an interaction request
304 // two continuations (Ok and Cancel)
305 ::rtl::Reference
< comphelper::OInteractionAbort
> pAbort
= new comphelper::OInteractionAbort
;
306 ::rtl::Reference
< dbaccess::OAuthenticationContinuation
> pAuthenticate
= new dbaccess::OAuthenticationContinuation
;
307 pAuthenticate
->setCanChangeUserName( sal_False
);
308 pAuthenticate
->setRememberPassword( RememberAuthentication_SESSION
);
311 pRequest
->addContinuation(pAbort
.get());
312 pRequest
->addContinuation(pAuthenticate
.get());
314 // handle the request
317 SolarMutexGuard aSolarGuard
;
318 // release the mutex when calling the handler, it may need to lock the SolarMutex
319 xHandler
->handle(xRequest
);
323 DBG_UNHANDLED_EXCEPTION();
325 if (!pAuthenticate
->wasSelected())
328 sPassword
= pAuthenticate
->getPassword();
329 if (pAuthenticate
->getRememberPassword())
330 m_pItemSetHelper
->getWriteOutputSet()->Put(SfxStringItem(DSID_PASSWORD
, sPassword
));
335 PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("password")), 0,
336 makeAny(::rtl::OUString(sPassword
)), PropertyState_DIRECT_VALUE
));
339 if ( !aReturn
.empty() )
340 _rDriverParam
= Sequence
< PropertyValue
>(&(*aReturn
.begin()), aReturn
.size());
342 // append all the other stuff (charset etc.)
343 fillDatasourceInfo(*m_pItemSetHelper
->getOutputSet(), _rDriverParam
);
347 //-------------------------------------------------------------------------
348 void ODbDataSourceAdministrationHelper::successfullyConnected()
350 OSL_ENSURE(m_pItemSetHelper
->getOutputSet(), "ODbDataSourceAdministrationHelper::successfullyConnected: not to be called without an example set!");
351 if (!m_pItemSetHelper
->getOutputSet())
354 if (hasAuthentication(*m_pItemSetHelper
->getOutputSet()))
356 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPassword
, SfxStringItem
, DSID_PASSWORD
, sal_True
);
357 if (pPassword
&& (0 != pPassword
->GetValue().Len()))
359 ::rtl::OUString sPassword
= pPassword
->GetValue();
361 Reference
< XPropertySet
> xCurrentDatasource
= getCurrentDataSource();
362 lcl_putProperty(xCurrentDatasource
,m_aDirectPropTranslator
[DSID_PASSWORD
], makeAny(sPassword
));
366 //-------------------------------------------------------------------------
367 void ODbDataSourceAdministrationHelper::clearPassword()
369 if (m_pItemSetHelper
->getWriteOutputSet())
370 m_pItemSetHelper
->getWriteOutputSet()->ClearItem(DSID_PASSWORD
);
372 // -----------------------------------------------------------------------------
373 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbDataSourceAdministrationHelper::createConnection()
375 ::std::pair
< Reference
<XConnection
>,sal_Bool
> aRet
;
376 aRet
.second
= sal_False
;
377 Sequence
< PropertyValue
> aConnectionParams
;
378 if ( getCurrentSettings(aConnectionParams
) )
381 // fill the table list with this connection information
382 SQLExceptionInfo aErrorInfo
;
385 WaitObject
aWaitCursor(m_pParent
);
386 aRet
.first
= getDriver()->connect(getConnectionURL(), aConnectionParams
);
387 aRet
.second
= sal_True
;
389 catch (const SQLContext
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
390 catch (const SQLWarning
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
391 catch (const SQLException
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
393 showError(aErrorInfo
,m_pParent
,getORB());
395 if ( aRet
.first
.is() )
396 successfullyConnected();// notify the admindlg to save the password
400 // -----------------------------------------------------------------------------
401 Reference
< XDriver
> ODbDataSourceAdministrationHelper::getDriver()
403 return getDriver(getConnectionURL());
405 // -----------------------------------------------------------------------------
406 Reference
< XDriver
> ODbDataSourceAdministrationHelper::getDriver(const ::rtl::OUString
& _sURL
)
408 // get the global DriverManager
409 Reference
< XDriverAccess
> xDriverManager
;
410 String sCurrentActionError
= String(ModuleRes(STR_COULDNOTCREATE_DRIVERMANAGER
));
411 // in case an error occures
412 sCurrentActionError
.SearchAndReplaceAscii("#servicename#", (::rtl::OUString
)SERVICE_SDBC_CONNECTIONPOOL
);
415 xDriverManager
= Reference
< XDriverAccess
>(getORB()->createInstance(SERVICE_SDBC_CONNECTIONPOOL
), UNO_QUERY
);
416 OSL_ENSURE(xDriverManager
.is(), "ODbDataSourceAdministrationHelper::getDriver: could not instantiate the driver manager, or it does not provide the necessary interface!");
418 catch (const Exception
& e
)
420 // wrap the exception into an SQLException
421 SQLException
aSQLWrapper(e
.Message
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
422 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, makeAny(aSQLWrapper
));
424 if (!xDriverManager
.is())
425 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
428 Reference
< XDriver
> xDriver
= xDriverManager
->getDriverByURL(_sURL
);
431 sCurrentActionError
= String(ModuleRes(STR_NOREGISTEREDDRIVER
));
432 sCurrentActionError
.SearchAndReplaceAscii("#connurl#", _sURL
);
433 // will be caught and translated into an SQLContext exception
434 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
439 // -----------------------------------------------------------------------------
440 Reference
< XPropertySet
> ODbDataSourceAdministrationHelper::getCurrentDataSource()
442 if ( !m_xDatasource
.is() )
444 Reference
<XInterface
> xIn(m_aDataSourceOrName
,UNO_QUERY
);
447 ::rtl::OUString sCurrentDatasource
;
448 m_aDataSourceOrName
>>= sCurrentDatasource
;
449 OSL_ENSURE(!sCurrentDatasource
.isEmpty(),"No datasource name given!");
452 if ( m_xDatabaseContext
.is() )
453 m_xDatasource
.set(m_xDatabaseContext
->getByName(sCurrentDatasource
),UNO_QUERY
);
456 catch(const Exception
&)
460 m_xModel
.set(getDataSourceOrModel(xIn
),UNO_QUERY
);
462 m_xDatasource
.set(xIn
,UNO_QUERY
);
465 m_xDatasource
.set(getDataSourceOrModel(xIn
),UNO_QUERY
);
466 m_xModel
.set(xIn
,UNO_QUERY
);
471 OSL_ENSURE(m_xDatasource
.is(), "ODbDataSourceAdministrationHelper::getCurrentDataSource: no data source!");
472 return m_xDatasource
;
474 //-------------------------------------------------------------------------
475 ::rtl::OUString
ODbDataSourceAdministrationHelper::getDatasourceType( const SfxItemSet
& _rSet
)
477 SFX_ITEMSET_GET( _rSet
, pConnectURL
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
478 OSL_ENSURE( pConnectURL
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!" );
479 SFX_ITEMSET_GET(_rSet
, pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
480 OSL_ENSURE(pTypeCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
481 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
482 return pCollection
->getType(pConnectURL
->GetValue());
485 //-------------------------------------------------------------------------
486 sal_Bool
ODbDataSourceAdministrationHelper::hasAuthentication(const SfxItemSet
& _rSet
) const
488 return DataSourceMetaData::getAuthentication( getDatasourceType( _rSet
) ) != AuthNone
;
490 // -----------------------------------------------------------------------------
491 String
ODbDataSourceAdministrationHelper::getConnectionURL() const
495 ::rtl::OUString eType
= getDatasourceType(*m_pItemSetHelper
->getOutputSet());
497 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
498 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
500 OSL_ENSURE(pUrlItem
,"Connection URL is NULL. -> GPF!");
501 OSL_ENSURE(pTypeCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
502 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
503 OSL_ENSURE(pCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid type collection!");
505 switch( pCollection
->determineType(eType
) )
507 case ::dbaccess::DST_DBASE
:
508 case ::dbaccess::DST_FLAT
:
509 case ::dbaccess::DST_CALC
:
511 case ::dbaccess::DST_MSACCESS
:
512 case ::dbaccess::DST_MSACCESS_2007
:
514 ::rtl::OUString sFileName
= pCollection
->cutPrefix(pUrlItem
->GetValue());
515 ::rtl::OUString sNewFileName
;
516 if ( ::osl::FileBase::getSystemPathFromFileURL( sFileName
, sNewFileName
) == ::osl::FileBase::E_None
)
518 sNewUrl
+= String(sNewFileName
);
522 case ::dbaccess::DST_MYSQL_NATIVE
:
523 case ::dbaccess::DST_MYSQL_JDBC
:
525 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
526 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_MYSQL_PORTNUMBER
, sal_True
);
527 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, sal_True
);
528 sNewUrl
= lcl_createHostWithPort(pHostName
,pPortNumber
);
529 String sDatabaseName
= pDatabaseName
? pDatabaseName
->GetValue() : String();
530 if ( !sDatabaseName
.Len() && pUrlItem
)
531 sDatabaseName
= pCollection
->cutPrefix( pUrlItem
->GetValue() );
532 // TODO: what's that? Why is the database name transported via the URL Item?
533 // Huh? Anybody there?
534 // OJ: It is needed when the connection properties are changed. There the URL is used for every type.
536 if ( sDatabaseName
.Len() )
538 sNewUrl
+= String::CreateFromAscii("/");
539 sNewUrl
+= sDatabaseName
;
543 case ::dbaccess::DST_ORACLE_JDBC
:
545 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
546 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_ORACLE_PORTNUMBER
, sal_True
);
547 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, sal_True
);
548 if ( pHostName
&& pHostName
->GetValue().Len() )
550 sNewUrl
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("@"));
551 sNewUrl
+= lcl_createHostWithPort(pHostName
,pPortNumber
);
552 String sDatabaseName
= pDatabaseName
? pDatabaseName
->GetValue() : String();
553 if ( !sDatabaseName
.Len() && pUrlItem
)
554 sDatabaseName
= pCollection
->cutPrefix( pUrlItem
->GetValue() );
555 if ( sDatabaseName
.Len() )
557 sNewUrl
+= String::CreateFromAscii(":");
558 sNewUrl
+= sDatabaseName
;
562 { // here someone entered a JDBC url which looks like oracle, so we have to use the url property
567 case ::dbaccess::DST_LDAP
:
569 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_CONN_LDAP_PORTNUMBER
, sal_True
);
570 sNewUrl
= pCollection
->cutPrefix(pUrlItem
->GetValue());
571 sNewUrl
+= lcl_createHostWithPort(NULL
,pPortNumber
);
574 case ::dbaccess::DST_JDBC
:
581 String sUrl
= pCollection
->getPrefix(eType
);
586 sNewUrl
= pUrlItem
->GetValue();
590 //-------------------------------------------------------------------------
591 struct PropertyValueLess
593 bool operator() (const PropertyValue
& x
, const PropertyValue
& y
) const
594 { return x
.Name
< y
.Name
? true : false; } // construct prevents a MSVC6 warning
596 DECLARE_STL_SET( PropertyValue
, PropertyValueLess
, PropertyValueSet
);
598 //........................................................................
599 void ODbDataSourceAdministrationHelper::translateProperties(const Reference
< XPropertySet
>& _rxSource
, SfxItemSet
& _rDest
)
601 Sequence
< ::rtl::OUString
> aTableFitler
;
605 for ( ConstMapInt2StringIterator aDirect
= m_aDirectPropTranslator
.begin();
606 aDirect
!= m_aDirectPropTranslator
.end();
610 // get the property value
614 aValue
= _rxSource
->getPropertyValue(aDirect
->second
);
618 #if OSL_DEBUG_LEVEL > 0
619 ::rtl::OString
aMessage("ODbDataSourceAdministrationHelper::translateProperties: could not extract the property ");
620 aMessage
+= ::rtl::OString(aDirect
->second
.getStr(), aDirect
->second
.getLength(), RTL_TEXTENCODING_ASCII_US
);
621 aMessage
+= ::rtl::OString("!");
622 OSL_FAIL(aMessage
.getStr());
625 // transfer it into an item
626 implTranslateProperty(_rDest
, aDirect
->first
, aValue
);
629 // get the additional informations
630 Sequence
< PropertyValue
> aAdditionalInfo
;
633 _rxSource
->getPropertyValue(PROPERTY_INFO
) >>= aAdditionalInfo
;
635 catch(Exception
&) { }
637 // collect the names of the additional settings
638 const PropertyValue
* pAdditionalInfo
= aAdditionalInfo
.getConstArray();
639 PropertyValueSet aInfos
;
640 for (sal_Int32 i
=0; i
<aAdditionalInfo
.getLength(); ++i
, ++pAdditionalInfo
)
642 if (0 == pAdditionalInfo
->Name
.compareToAscii("JDBCDRV"))
644 PropertyValue
aCompatibility(*pAdditionalInfo
);
645 aCompatibility
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"));
646 aInfos
.insert(aCompatibility
);
649 aInfos
.insert(*pAdditionalInfo
);
652 // go through all known translations and check if we have such a setting
653 if ( !aInfos
.empty() )
655 PropertyValue aSearchFor
;
656 ConstMapInt2StringIterator aEnd
= m_aIndirectPropTranslator
.end();
657 for ( ConstMapInt2StringIterator aIndirect
= m_aIndirectPropTranslator
.begin();
661 aSearchFor
.Name
= aIndirect
->second
;
662 ConstPropertyValueSetIterator aInfoPos
= aInfos
.find(aSearchFor
);
663 if (aInfos
.end() != aInfoPos
)
664 // the property is contained in the info sequence
665 // -> transfer it into an item
666 implTranslateProperty(_rDest
, aIndirect
->first
, aInfoPos
->Value
);
675 _rDest
.Put(OPropertySetItem(DSID_DATASOURCE_UNO
, _rxSource
));
676 Reference
<XStorable
> xStore(getDataSourceOrModel(_rxSource
),UNO_QUERY
);
677 _rDest
.Put(SfxBoolItem(DSID_READONLY
, !xStore
.is() || xStore
->isReadonly() ));
681 OSL_FAIL("IsReadOnly throws an exception!");
685 //-------------------------------------------------------------------------
686 void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet
& _rSource
, const Reference
< XPropertySet
>& _rxDest
)
688 OSL_ENSURE(_rxDest
.is(), "ODbDataSourceAdministrationHelper::translateProperties: invalid property set!");
692 // the property set info
693 Reference
< XPropertySetInfo
> xInfo
;
694 try { xInfo
= _rxDest
->getPropertySetInfo(); }
695 catch(Exception
&) { }
697 const ::rtl::OUString
sUrlProp(RTL_CONSTASCII_USTRINGPARAM("URL"));
698 // -----------------------------
699 // transfer the direct properties
700 for ( ConstMapInt2StringIterator aDirect
= m_aDirectPropTranslator
.begin();
701 aDirect
!= m_aDirectPropTranslator
.end();
705 const SfxPoolItem
* pCurrentItem
= _rSource
.GetItem((sal_uInt16
)aDirect
->first
);
708 sal_Int16 nAttributes
= PropertyAttribute::READONLY
;
711 try { nAttributes
= xInfo
->getPropertyByName(aDirect
->second
).Attributes
; }
712 catch(Exception
&) { }
714 if ((nAttributes
& PropertyAttribute::READONLY
) == 0)
716 if ( sUrlProp
== aDirect
->second
)
718 Any
aValue(makeAny(::rtl::OUString(getConnectionURL())));
719 // aValue <<= ::rtl::OUString();
720 lcl_putProperty(_rxDest
, aDirect
->second
,aValue
);
723 implTranslateProperty(_rxDest
, aDirect
->second
, pCurrentItem
);
728 // -------------------------------
729 // now for the indirect properties
731 Sequence
< PropertyValue
> aInfo
;
732 // the original properties
735 _rxDest
->getPropertyValue(PROPERTY_INFO
) >>= aInfo
;
737 catch(Exception
&) { }
739 // overwrite and extend them
740 fillDatasourceInfo(_rSource
, aInfo
);
741 // and propagate the (newly composed) sequence to the set
742 lcl_putProperty(_rxDest
,PROPERTY_INFO
, makeAny(aInfo
));
746 //-------------------------------------------------------------------------
747 void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet
& _rSource
, Sequence
< ::com::sun::star::beans::PropertyValue
>& _rInfo
)
749 // within the current "Info" sequence, replace the ones we can examine from the item set
750 // (we don't just fill a completely new sequence with our own items, but we preserve any properties unknown to
753 // first determine which of all the items are relevant for the data source (depends on the connection url)
754 ::rtl::OUString eType
= getDatasourceType(_rSource
);
755 ::std::vector
< sal_Int32
> aDetailIds
;
756 ODriversSettings::getSupportedIndirectSettings(eType
,getORB(),aDetailIds
);
758 // collect the translated property values for the relevant items
759 PropertyValueSet aRelevantSettings
;
760 ConstMapInt2StringIterator aTranslation
;
761 ::std::vector
< sal_Int32
>::iterator aDetailsEnd
= aDetailIds
.end();
762 for (::std::vector
< sal_Int32
>::iterator aIter
= aDetailIds
.begin();aIter
!= aDetailsEnd
; ++aIter
)
764 const SfxPoolItem
* pCurrent
= _rSource
.GetItem((sal_uInt16
)*aIter
);
765 aTranslation
= m_aIndirectPropTranslator
.find(*aIter
);
766 if ( pCurrent
&& (m_aIndirectPropTranslator
.end() != aTranslation
) )
768 if ( aTranslation
->second
== INFO_CHARSET
)
770 ::rtl::OUString sCharSet
;
771 implTranslateProperty(pCurrent
) >>= sCharSet
;
772 if ( !sCharSet
.isEmpty() )
773 aRelevantSettings
.insert(PropertyValue(aTranslation
->second
, 0, makeAny(sCharSet
), PropertyState_DIRECT_VALUE
));
776 aRelevantSettings
.insert(PropertyValue(aTranslation
->second
, 0, implTranslateProperty(pCurrent
), PropertyState_DIRECT_VALUE
));
780 // settings to preserve
781 MapInt2String aPreservedSettings
;
783 // now aRelevantSettings contains all the property values relevant for the current data source type,
784 // check the original sequence if it already contains any of these values (which have to be overwritten, then)
785 PropertyValue
* pInfo
= _rInfo
.getArray();
786 PropertyValue aSearchFor
;
787 sal_Int32 nObsoleteSetting
= -1;
788 sal_Int32 nCount
= _rInfo
.getLength();
789 for (sal_Int32 i
= 0; i
< nCount
; ++i
, ++pInfo
)
791 aSearchFor
.Name
= pInfo
->Name
;
792 PropertyValueSetIterator aOverwrittenSetting
= aRelevantSettings
.find(aSearchFor
);
793 if (aRelevantSettings
.end() != aOverwrittenSetting
)
794 { // the setting was present in the original sequence, and it is to be overwritten -> replace it
795 if ( !::comphelper::compare(pInfo
->Value
,aOverwrittenSetting
->Value
) )
796 *pInfo
= *aOverwrittenSetting
;
797 aRelevantSettings
.erase(aOverwrittenSetting
);
799 else if (0 == pInfo
->Name
.compareToAscii("JDBCDRV"))
800 { // this is a compatibility setting, remove it from the sequence (it's replaced by JavaDriverClass)
801 nObsoleteSetting
= i
;
804 aPreservedSettings
[i
] = pInfo
->Name
;
806 if (-1 != nObsoleteSetting
)
807 ::comphelper::removeElementAt(_rInfo
, nObsoleteSetting
);
809 if ( !aPreservedSettings
.empty() )
810 { // check if there are settings which
811 // * are known as indirect properties
812 // * but not relevant for the current data source type
813 // These settings have to be removed: If they're not relevant, we have no UI for changing them.
815 // for this, we need a string-controlled quick access to m_aIndirectPropTranslator
816 StringSet aIndirectProps
;
817 ::std::transform(m_aIndirectPropTranslator
.begin(),
818 m_aIndirectPropTranslator
.end(),
819 ::std::insert_iterator
<StringSet
>(aIndirectProps
,aIndirectProps
.begin()),
820 ::o3tl::select2nd
<MapInt2String::value_type
>());
822 // now check the to-be-preserved props
823 ::std::vector
< sal_Int32
> aRemoveIndexes
;
824 sal_Int32 nPositionCorrector
= 0;
825 ConstMapInt2StringIterator aPreservedEnd
= aPreservedSettings
.end();
826 for ( ConstMapInt2StringIterator aPreserved
= aPreservedSettings
.begin();
827 aPreserved
!= aPreservedEnd
;
831 if (aIndirectProps
.end() != aIndirectProps
.find(aPreserved
->second
))
833 #if OSL_DEBUG_LEVEL > 0
834 const ::rtl::OUString sName
= aPreserved
->second
;
836 aRemoveIndexes
.push_back(aPreserved
->first
- nPositionCorrector
);
837 ++nPositionCorrector
;
840 // now finally remove all such props
841 ::std::vector
< sal_Int32
>::const_iterator aRemoveEnd
= aRemoveIndexes
.end();
842 for ( ::std::vector
< sal_Int32
>::const_iterator aRemoveIndex
= aRemoveIndexes
.begin();
843 aRemoveIndex
!= aRemoveEnd
;
846 ::comphelper::removeElementAt(_rInfo
, *aRemoveIndex
);
847 #if OSL_DEBUG_LEVEL > 0
848 const PropertyValue
* pWhatsLeft
= _rInfo
.getConstArray();
849 const PropertyValue
* pWhatsLeftEnd
= pWhatsLeft
+ _rInfo
.getLength();
850 for (; pWhatsLeft
!= pWhatsLeftEnd
; ++pWhatsLeft
)
852 ::rtl::OUString sLookAtIt
= pWhatsLeft
->Name
;
857 ::connectivity::DriversConfig
aDriverConfig(getORB());
858 const ::comphelper::NamedValueCollection
& aProperties
= aDriverConfig
.getProperties(eType
);
859 Sequence
< Any
> aTypeSettings
;
860 aTypeSettings
= aProperties
.getOrDefault("TypeInfoSettings",aTypeSettings
);
861 // here we have a special entry for types from oracle
862 if ( aTypeSettings
.getLength() )
864 aRelevantSettings
.insert(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")), 0, makeAny(aTypeSettings
), PropertyState_DIRECT_VALUE
));
867 // check which values are still left ('cause they were not present in the original sequence, but are to be set)
868 if ( !aRelevantSettings
.empty() )
870 sal_Int32 nOldLength
= _rInfo
.getLength();
871 _rInfo
.realloc(nOldLength
+ aRelevantSettings
.size());
872 PropertyValue
* pAppendValues
= _rInfo
.getArray() + nOldLength
;
873 ConstPropertyValueSetIterator aRelevantEnd
= aRelevantSettings
.end();
874 for ( ConstPropertyValueSetIterator aLoop
= aRelevantSettings
.begin();
875 aLoop
!= aRelevantEnd
;
876 ++aLoop
, ++pAppendValues
879 if ( aLoop
->Name
== INFO_CHARSET
)
881 ::rtl::OUString sCharSet
;
882 aLoop
->Value
>>= sCharSet
;
883 if ( !sCharSet
.isEmpty() )
884 *pAppendValues
= *aLoop
;
887 *pAppendValues
= *aLoop
;
891 //-------------------------------------------------------------------------
892 Any
ODbDataSourceAdministrationHelper::implTranslateProperty(const SfxPoolItem
* _pItem
)
894 // translate the SfxPoolItem
897 const SfxStringItem
* pStringItem
= PTR_CAST( SfxStringItem
, _pItem
);
898 const SfxBoolItem
* pBoolItem
= PTR_CAST( SfxBoolItem
, _pItem
);
899 const OptionalBoolItem
* pOptBoolItem
= PTR_CAST( OptionalBoolItem
, _pItem
);
900 const SfxInt32Item
* pInt32Item
= PTR_CAST( SfxInt32Item
, _pItem
);
901 const OStringListItem
* pStringListItem
= PTR_CAST( OStringListItem
, _pItem
);
905 aValue
<<= ::rtl::OUString( pStringItem
->GetValue().GetBuffer() );
907 else if ( pBoolItem
)
909 aValue
<<= pBoolItem
->GetValue();
911 else if ( pOptBoolItem
)
913 if ( !pOptBoolItem
->HasValue() )
916 aValue
<<= (sal_Bool
)pOptBoolItem
->GetValue();
918 else if ( pInt32Item
)
920 aValue
<<= pInt32Item
->GetValue();
922 else if ( pStringListItem
)
924 aValue
<<= pStringListItem
->getList();
928 OSL_FAIL("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported item type!");
934 //-------------------------------------------------------------------------
935 void ODbDataSourceAdministrationHelper::implTranslateProperty(const Reference
< XPropertySet
>& _rxSet
, const ::rtl::OUString
& _rName
, const SfxPoolItem
* _pItem
)
937 Any aValue
= implTranslateProperty(_pItem
);
938 lcl_putProperty(_rxSet
, _rName
,aValue
);
941 #if OSL_DEBUG_LEVEL > 0
942 //-------------------------------------------------------------------------
943 ::rtl::OString
ODbDataSourceAdministrationHelper::translatePropertyId( sal_Int32 _nId
)
945 ::rtl::OUString aString
;
947 MapInt2String::const_iterator aPos
= m_aDirectPropTranslator
.find( _nId
);
948 if ( m_aDirectPropTranslator
.end() != aPos
)
950 aString
= aPos
->second
;
954 MapInt2String::const_iterator indirectPos
= m_aIndirectPropTranslator
.find( _nId
);
955 if ( m_aIndirectPropTranslator
.end() != indirectPos
)
956 aString
= indirectPos
->second
;
959 ::rtl::OString
aReturn( aString
.getStr(), aString
.getLength(), RTL_TEXTENCODING_ASCII_US
);
964 //-------------------------------------------------------------------------
965 void ODbDataSourceAdministrationHelper::implTranslateProperty( SfxItemSet
& _rSet
, sal_Int32 _nId
, const Any
& _rValue
)
967 switch ( _rValue
.getValueType().getTypeClass() )
969 case TypeClass_STRING
:
970 if ( implCheckItemType( _rSet
, _nId
, SfxStringItem::StaticType() ) )
972 ::rtl::OUString sValue
;
974 _rSet
.Put(SfxStringItem(_nId
, sValue
.getStr()));
978 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
979 += ::rtl::OString( translatePropertyId( _nId
) )
980 += ::rtl::OString( " should be no string)!" )
986 case TypeClass_BOOLEAN
:
987 if ( implCheckItemType( _rSet
, _nId
, SfxBoolItem::StaticType() ) )
989 sal_Bool bVal
= sal_False
;
991 _rSet
.Put(SfxBoolItem(_nId
, bVal
));
993 else if ( implCheckItemType( _rSet
, _nId
, OptionalBoolItem::StaticType() ) )
995 OptionalBoolItem
aItem( _nId
);
996 if ( _rValue
.hasValue() )
998 sal_Bool bValue
= sal_False
;
1000 aItem
.SetValue( bValue
);
1008 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1009 += ::rtl::OString( translatePropertyId( _nId
) )
1010 += ::rtl::OString( " should be no boolean)!" )
1016 case TypeClass_LONG
:
1017 if ( implCheckItemType( _rSet
, _nId
, SfxInt32Item::StaticType() ) )
1019 sal_Int32 nValue
= 0;
1021 _rSet
.Put( SfxInt32Item( _nId
, nValue
) );
1025 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1026 += ::rtl::OString( translatePropertyId( _nId
) )
1027 += ::rtl::OString( " should be no int)!" )
1033 case TypeClass_SEQUENCE
:
1034 if ( implCheckItemType( _rSet
, _nId
, OStringListItem::StaticType() ) )
1036 // determine the element type
1037 TypeDescription
aTD(_rValue
.getValueType());
1038 typelib_IndirectTypeDescription
* pSequenceTD
=
1039 reinterpret_cast< typelib_IndirectTypeDescription
* >(aTD
.get());
1040 OSL_ENSURE(pSequenceTD
&& pSequenceTD
->pType
, "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid sequence type!");
1042 Type
aElementType(pSequenceTD
->pType
);
1043 switch (aElementType
.getTypeClass())
1045 case TypeClass_STRING
:
1047 Sequence
< ::rtl::OUString
> aStringList
;
1048 _rValue
>>= aStringList
;
1049 _rSet
.Put(OStringListItem(_nId
, aStringList
));
1053 OSL_FAIL("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1058 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1059 += ::rtl::OString( translatePropertyId( _nId
) )
1060 += ::rtl::OString( " should be no string sequence)!" )
1066 case TypeClass_VOID
:
1067 _rSet
.ClearItem(_nId
);
1071 OSL_FAIL("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1076 String
ODbDataSourceAdministrationHelper::getDocumentUrl(SfxItemSet
& _rDest
)
1078 SFX_ITEMSET_GET(_rDest
, pUrlItem
, SfxStringItem
, DSID_DOCUMENT_URL
, sal_True
);
1079 OSL_ENSURE(pUrlItem
,"Document URL is NULL. -> GPF!");
1080 return pUrlItem
->GetValue();
1084 // -----------------------------------------------------------------------------
1085 void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet
& _rDest
)
1087 ::rtl::OUString eType
= getDatasourceType(_rDest
);
1089 SFX_ITEMSET_GET(_rDest
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
1090 SFX_ITEMSET_GET(_rDest
, pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
1092 OSL_ENSURE(pUrlItem
,"Connection URL is NULL. -> GPF!");
1093 OSL_ENSURE(pTypeCollection
, "ODbAdminDialog::getDatasourceType: invalid items in the source set!");
1094 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
1095 OSL_ENSURE(pCollection
, "ODbAdminDialog::getDatasourceType: invalid type collection!");
1097 sal_uInt16 nPortNumberId
= 0;
1098 sal_Int32 nPortNumber
= -1;
1099 String sNewHostName
;
1102 pCollection
->extractHostNamePort(pUrlItem
->GetValue(),sUrlPart
,sNewHostName
,nPortNumber
);
1103 const ::dbaccess::DATASOURCE_TYPE eTy
= pCollection
->determineType(eType
);
1107 case ::dbaccess::DST_MYSQL_NATIVE
:
1108 case ::dbaccess::DST_MYSQL_JDBC
:
1109 nPortNumberId
= DSID_MYSQL_PORTNUMBER
;
1111 case ::dbaccess::DST_ORACLE_JDBC
:
1112 nPortNumberId
= DSID_ORACLE_PORTNUMBER
;
1114 case ::dbaccess::DST_LDAP
:
1115 nPortNumberId
= DSID_CONN_LDAP_PORTNUMBER
;
1121 if ( sUrlPart
.Len() )
1123 if ( eTy
== ::dbaccess::DST_MYSQL_NATIVE
)
1125 _rDest
.Put( SfxStringItem( DSID_DATABASENAME
, sUrlPart
) );
1129 String sNewUrl
= pCollection
->getPrefix(eType
);
1130 sNewUrl
+= sUrlPart
;
1131 _rDest
.Put( SfxStringItem( DSID_CONNECTURL
, sNewUrl
) );
1135 if ( sNewHostName
.Len() )
1136 _rDest
.Put(SfxStringItem(DSID_CONN_HOSTNAME
, sNewHostName
));
1138 if ( nPortNumber
!= -1 && nPortNumberId
!= 0 )
1139 _rDest
.Put(SfxInt32Item(nPortNumberId
, nPortNumber
));
1142 // -----------------------------------------------------------------------------
1143 sal_Bool
ODbDataSourceAdministrationHelper::saveChanges(const SfxItemSet
& _rSource
)
1145 // put the remembered settings into the property set
1146 Reference
<XPropertySet
> xDatasource
= getCurrentDataSource();
1147 if ( !xDatasource
.is() )
1150 translateProperties(_rSource
,xDatasource
);
1154 // -----------------------------------------------------------------------------
1155 void ODbDataSourceAdministrationHelper::setDataSourceOrName( const Any
& _rDataSourceOrName
)
1157 OSL_ENSURE( !m_aDataSourceOrName
.hasValue(), "ODbDataSourceAdministrationHelper::setDataSourceOrName: already have one!" );
1158 // hmm. We could reset m_xDatasource/m_xModel, probably, and continue working
1159 m_aDataSourceOrName
= _rDataSourceOrName
;
1161 //=========================================================================
1162 //= DbuTypeCollectionItem
1163 //=========================================================================
1164 TYPEINIT1(DbuTypeCollectionItem
, SfxPoolItem
);
1165 //-------------------------------------------------------------------------
1166 DbuTypeCollectionItem::DbuTypeCollectionItem(sal_Int16 _nWhich
, ::dbaccess::ODsnTypeCollection
* _pCollection
)
1167 :SfxPoolItem(_nWhich
)
1168 ,m_pCollection(_pCollection
)
1172 //-------------------------------------------------------------------------
1173 DbuTypeCollectionItem::DbuTypeCollectionItem(const DbuTypeCollectionItem
& _rSource
)
1174 :SfxPoolItem(_rSource
)
1175 ,m_pCollection(_rSource
.getCollection())
1179 //-------------------------------------------------------------------------
1180 int DbuTypeCollectionItem::operator==(const SfxPoolItem
& _rItem
) const
1182 DbuTypeCollectionItem
* pCompare
= PTR_CAST(DbuTypeCollectionItem
, &_rItem
);
1183 return pCompare
&& (pCompare
->getCollection() == getCollection());
1186 //-------------------------------------------------------------------------
1187 SfxPoolItem
* DbuTypeCollectionItem::Clone(SfxItemPool
* /*_pPool*/) const
1189 return new DbuTypeCollectionItem(*this);
1192 //.........................................................................
1193 } // namespace dbaui
1194 //.........................................................................
1198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */