1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DbAdminImpl.cxx,v $
10 * $Revision: 1.26.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "DbAdminImpl.hxx"
37 #ifndef _SFXPOOLITEM_HXX
38 #include <svtools/poolitem.hxx>
40 #ifndef _SFXITEMPOOL_HXX
41 #include <svtools/itempool.hxx>
43 #ifndef _SFXSTRITEM_HXX
44 #include <svtools/stritem.hxx>
46 #ifndef _SFXINTITEM_HXX
47 #include <svtools/intitem.hxx>
49 #ifndef _SFXENUMITEM_HXX
50 #include <svtools/eitem.hxx>
52 #ifndef _COMPHELPER_PROPERTY_HXX_
53 #include <comphelper/property.hxx>
55 #ifndef _COMPHELPER_SEQUENCE_HXX_
56 #include <comphelper/sequence.hxx>
58 #ifndef _SVTOOLS_LOGINDLG_HXX_
59 #include <svtools/logindlg.hxx>
61 #ifndef _DBHELPER_DBEXCEPTION_HXX_
62 #include <connectivity/dbexception.hxx>
64 #include <connectivity/DriversConfig.hxx>
65 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
66 #include <com/sun/star/beans/PropertyAttribute.hpp>
68 #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
69 #include <com/sun/star/sdb/SQLContext.hpp>
71 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
72 #include <com/sun/star/sdbc/XDriverAccess.hpp>
74 #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_
75 #include <com/sun/star/sdbc/XDriver.hpp>
77 #ifndef DBAUI_DRIVERSETTINGS_HXX
78 #include "DriverSettings.hxx"
80 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
81 #include "propertysetitem.hxx"
83 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
84 #include "dsitems.hxx"
86 #ifndef DBAUI_ITEMSETHELPER_HXX
87 #include "IItemSetHelper.hxx"
90 #include "dbu_dlg.hrc"
92 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
93 #include "dbustrings.hrc"
95 #ifndef _VCL_STDTEXT_HXX
96 #include <vcl/stdtext.hxx>
98 #ifndef _SV_MSGBOX_HXX
99 #include <vcl/msgbox.hxx>
101 #ifndef _SV_WAITOBJ_HXX
102 #include <vcl/waitobj.hxx>
104 #ifndef _TYPELIB_TYPEDESCRIPTION_HXX_
105 #include <typelib/typedescription.hxx>
108 #ifndef _OSL_FILE_HXX_
109 #include <osl/file.hxx>
111 #ifndef _DBAUI_STRINGLISTITEM_HXX_
112 #include "stringlistitem.hxx"
114 #ifndef _DBAUI_MODULE_DBU_HXX_
115 #include "moduledbu.hxx"
117 #ifndef DBAUI_TOOLS_HXX
118 #include "UITools.hxx"
120 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
121 #include <com/sun/star/frame/XStorable.hpp>
123 #include "dsnItem.hxx"
126 #include <functional>
127 //.........................................................................
130 //.........................................................................
131 using namespace ::dbtools
;
132 using namespace com::sun::star::uno
;
133 using namespace com::sun::star
;
134 using namespace com::sun::star::sdbc
;
135 using namespace com::sun::star::sdb
;
136 using namespace com::sun::star::lang
;
137 using namespace com::sun::star::beans
;
138 using namespace com::sun::star::util
;
139 using namespace com::sun::star::container
;
140 using namespace com::sun::star::frame
;
142 //-------------------------------------------------------------------------
145 sal_Bool
implCheckItemType( SfxItemSet
& _rSet
, const USHORT _nId
, const TypeId _nExpectedItemType
)
147 sal_Bool bCorrectType
= sal_False
;
149 SfxItemPool
* pPool
= _rSet
.GetPool();
150 DBG_ASSERT( pPool
, "implCheckItemType: invalid item pool!" );
153 const SfxPoolItem
& rDefItem
= pPool
->GetDefaultItem( _nId
);
154 bCorrectType
= rDefItem
.IsA( _nExpectedItemType
);
159 void lcl_putProperty(const Reference
< XPropertySet
>& _rxSet
, const ::rtl::OUString
& _rName
, const Any
& _rValue
)
164 _rxSet
->setPropertyValue(_rName
, _rValue
);
169 ::rtl::OString
sMessage("ODbAdminDialog::implTranslateProperty: could not set the property ");
170 sMessage
+= ::rtl::OString(_rName
.getStr(), _rName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
171 sMessage
+= ::rtl::OString("!");
172 DBG_ERROR(sMessage
.getStr());
178 String
lcl_createHostWithPort(const SfxStringItem
* _pHostName
,const SfxInt32Item
* _pPortNumber
)
182 if ( _pHostName
&& _pHostName
->GetValue().Len() )
183 sNewUrl
= _pHostName
->GetValue();
187 sNewUrl
+= String::CreateFromAscii(":");
188 sNewUrl
+= String::CreateFromInt32(_pPortNumber
->GetValue());
195 //========================================================================
196 //= ODbDataSourceAdministrationHelper
197 //========================================================================
198 ODbDataSourceAdministrationHelper::ODbDataSourceAdministrationHelper(const Reference
< XMultiServiceFactory
>& _xORB
,Window
* _pParent
,IItemSetHelper
* _pItemSetHelper
)
200 , m_pParent(_pParent
)
201 , m_pItemSetHelper(_pItemSetHelper
)
203 /// initialize the property translation map
204 // direct properties of a data source
205 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONNECTURL
, PROPERTY_URL
));
206 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_NAME
, PROPERTY_NAME
));
207 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_USER
, PROPERTY_USER
));
208 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_PASSWORD
, PROPERTY_PASSWORD
));
209 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_PASSWORDREQUIRED
, PROPERTY_ISPASSWORDREQUIRED
));
210 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_TABLEFILTER
, PROPERTY_TABLEFILTER
));
211 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_READONLY
, PROPERTY_ISREADONLY
));
212 m_aDirectPropTranslator
.insert(MapInt2String::value_type(DSID_SUPPRESSVERSIONCL
, PROPERTY_SUPPRESSVERSIONCL
));
214 // implicit properties, to be found in the direct property "Info"
215 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_JDBCDRIVERCLASS
, INFO_JDBCDRIVERCLASS
));
216 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_TEXTFILEEXTENSION
, INFO_TEXTFILEEXTENSION
));
217 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CHARSET
, INFO_CHARSET
));
218 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_TEXTFILEHEADER
, INFO_TEXTFILEHEADER
));
219 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_FIELDDELIMITER
, INFO_FIELDDELIMITER
));
220 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_TEXTDELIMITER
, INFO_TEXTDELIMITER
));
221 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DECIMALDELIMITER
, INFO_DECIMALDELIMITER
));
222 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_THOUSANDSDELIMITER
, INFO_THOUSANDSDELIMITER
));
223 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_SHOWDELETEDROWS
, INFO_SHOWDELETEDROWS
));
224 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ALLOWLONGTABLENAMES
, INFO_ALLOWLONGTABLENAMES
));
225 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ADDITIONALOPTIONS
, INFO_ADDITIONALOPTIONS
));
226 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_SQL92CHECK
, PROPERTY_ENABLESQL92CHECK
));
227 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AUTOINCREMENTVALUE
, PROPERTY_AUTOINCREMENTCREATION
));
228 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AUTORETRIEVEVALUE
, INFO_AUTORETRIEVEVALUE
));
229 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AUTORETRIEVEENABLED
, INFO_AUTORETRIEVEENABLED
));
230 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_APPEND_TABLE_ALIAS
, INFO_APPEND_TABLE_ALIAS
));
231 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_AS_BEFORE_CORRNAME
, INFO_AS_BEFORE_CORRELATION_NAME
) );
232 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CHECK_REQUIRED_FIELDS
, INFO_FORMS_CHECK_REQUIRED_FIELDS
) );
233 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ESCAPE_DATETIME
, INFO_ESCAPE_DATETIME
) );
234 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_PARAMETERNAMESUBST
, INFO_PARAMETERNAMESUBST
));
235 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_IGNOREDRIVER_PRIV
, INFO_IGNOREDRIVER_PRIV
));
236 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_BOOLEANCOMPARISON
, PROPERTY_BOOLEANCOMPARISONMODE
));
237 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_ENABLEOUTERJOIN
, PROPERTY_ENABLEOUTERJOIN
));
238 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CATALOG
, PROPERTY_USECATALOGINSELECT
));
239 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_SCHEMA
, PROPERTY_USESCHEMAINSELECT
));
240 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_INDEXAPPENDIX
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AddIndexAppendix"))));
241 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DOSLINEENDS
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreferDosLikeLineEnds" ) ) ) );
242 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_SOCKET
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LocalSocket" ) ) ) );
244 // special settings for adabas
245 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_SHUTSERVICE
, ::rtl::OUString::createFromAscii("ShutdownDatabase")));
246 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_DATAINC
, ::rtl::OUString::createFromAscii("DataCacheSizeIncrement")));
247 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_CACHESIZE
, ::rtl::OUString::createFromAscii("DataCacheSize")));
248 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_CTRLUSER
, ::rtl::OUString::createFromAscii("ControlUser")));
249 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_CTRLPWD
, ::rtl::OUString::createFromAscii("ControlPassword")));
251 // extra settings for odbc
252 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_USECATALOG
, INFO_USECATALOG
));
253 // extra settings for a ldap address book
254 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_BASEDN
, INFO_CONN_LDAP_BASEDN
));
255 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_ROWCOUNT
, INFO_CONN_LDAP_ROWCOUNT
));
256 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_USESSL
, ::rtl::OUString::createFromAscii("UseSSL")));
257 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DOCUMENT_URL
, PROPERTY_URL
));
260 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_IGNORECURRENCY
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))));
264 m_xDatabaseContext
= Reference
< XNameAccess
>(m_xORB
->createInstance(SERVICE_SDB_DATABASECONTEXT
), UNO_QUERY
);
265 m_xDynamicContext
.set(m_xDatabaseContext
,UNO_QUERY
);
271 if ( !m_xDatabaseContext
.is() )
273 ShowServiceNotAvailableError(_pParent
->GetParent(), String(SERVICE_SDB_DATABASECONTEXT
), sal_True
);
276 DBG_ASSERT(m_xDynamicContext
.is(), "ODbAdminDialog::ODbAdminDialog : no XNamingService interface !");
278 //-------------------------------------------------------------------------
279 sal_Bool
ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence
< PropertyValue
>& _rDriverParam
)
281 DBG_ASSERT(m_pItemSetHelper
->getOutputSet(), "ODbDataSourceAdministrationHelper::getCurrentSettings : not to be called without an example set!");
282 if (!m_pItemSetHelper
->getOutputSet())
285 ::std::vector
< PropertyValue
> aReturn
;
286 // collecting this in a vector because it has a push_back, in opposite to sequences
288 // user: DSID_USER -> "user"
289 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pUser
, SfxStringItem
, DSID_USER
, sal_True
);
290 if (pUser
&& pUser
->GetValue().Len())
292 PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), 0,
293 makeAny(::rtl::OUString(pUser
->GetValue())), PropertyState_DIRECT_VALUE
));
295 // check if the connection type requires a password
296 if (hasAuthentication(*m_pItemSetHelper
->getOutputSet()))
298 // password: DSID_PASSWORD -> "password"
299 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPassword
, SfxStringItem
, DSID_PASSWORD
, sal_True
);
300 String sPassword
= pPassword
? pPassword
->GetValue() : String();
301 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPasswordRequired
, SfxBoolItem
, DSID_PASSWORDREQUIRED
, sal_True
);
302 // if the set does not contain a password, but the item set says it requires one, ask the user
303 if ((!pPassword
|| !pPassword
->GetValue().Len()) && (pPasswordRequired
&& pPasswordRequired
->GetValue()))
305 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pName
, SfxStringItem
, DSID_NAME
, sal_True
);
307 ::svt::LoginDialog
aDlg(m_pParent
,
308 LF_NO_PATH
| LF_NO_ACCOUNT
| LF_NO_ERRORTEXT
| LF_USERNAME_READONLY
,
311 aDlg
.SetName(pUser
? pUser
->GetValue() : String());
312 aDlg
.ClearPassword(); // this will give the password field the focus
314 String sName
= pName
? pName
->GetValue() : String();
315 String
sLoginRequest(ModuleRes(STR_ENTER_CONNECTION_PASSWORD
));
316 ::rtl::OUString sTemp
= sName
;
317 sName
= ::dbaui::getStrippedDatabaseName(NULL
,sTemp
);
319 sLoginRequest
.SearchAndReplaceAscii("$name$", sName
);
322 sLoginRequest
.SearchAndReplaceAscii("\"$name$\"", String());
323 sLoginRequest
.SearchAndReplaceAscii("$name$", String()); // just to be sure that in other languages the string will be deleted
325 aDlg
.SetLoginRequestText(sLoginRequest
);
327 aDlg
.SetSavePasswordText(ModuleRes(STR_REMEMBERPASSWORD_SESSION
));
328 aDlg
.SetSavePassword(sal_True
);
330 sal_Int32 nResult
= aDlg
.Execute();
331 if (nResult
!= RET_OK
)
334 sPassword
= aDlg
.GetPassword();
335 if (aDlg
.IsSavePassword())
336 m_pItemSetHelper
->getWriteOutputSet()->Put(SfxStringItem(DSID_PASSWORD
, sPassword
));
341 PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("password")), 0,
342 makeAny(::rtl::OUString(sPassword
)), PropertyState_DIRECT_VALUE
));
345 if ( !aReturn
.empty() )
346 _rDriverParam
= Sequence
< PropertyValue
>(&(*aReturn
.begin()), aReturn
.size());
348 // append all the other stuff (charset etc.)
349 fillDatasourceInfo(*m_pItemSetHelper
->getOutputSet(), _rDriverParam
);
353 //-------------------------------------------------------------------------
354 void ODbDataSourceAdministrationHelper::successfullyConnected()
356 DBG_ASSERT(m_pItemSetHelper
->getOutputSet(), "ODbDataSourceAdministrationHelper::successfullyConnected: not to be called without an example set!");
357 if (!m_pItemSetHelper
->getOutputSet())
360 if (hasAuthentication(*m_pItemSetHelper
->getOutputSet()))
362 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPassword
, SfxStringItem
, DSID_PASSWORD
, sal_True
);
363 if (pPassword
&& (0 != pPassword
->GetValue().Len()))
365 ::rtl::OUString sPassword
= pPassword
->GetValue();
367 Reference
< XPropertySet
> xCurrentDatasource
= getCurrentDataSource();
368 lcl_putProperty(xCurrentDatasource
,m_aDirectPropTranslator
[DSID_PASSWORD
], makeAny(sPassword
));
372 //-------------------------------------------------------------------------
373 void ODbDataSourceAdministrationHelper::clearPassword()
375 if (m_pItemSetHelper
->getWriteOutputSet())
376 m_pItemSetHelper
->getWriteOutputSet()->ClearItem(DSID_PASSWORD
);
378 // -----------------------------------------------------------------------------
379 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbDataSourceAdministrationHelper::createConnection()
381 ::std::pair
< Reference
<XConnection
>,sal_Bool
> aRet
;
382 aRet
.second
= sal_False
;
383 Sequence
< PropertyValue
> aConnectionParams
;
384 if ( getCurrentSettings(aConnectionParams
) )
387 // fill the table list with this connection information
388 SQLExceptionInfo aErrorInfo
;
391 WaitObject
aWaitCursor(m_pParent
);
392 aRet
.first
= getDriver()->connect(getConnectionURL(), aConnectionParams
);
393 aRet
.second
= sal_True
;
395 catch (SQLContext
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
396 catch (SQLWarning
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
397 catch (SQLException
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
399 showError(aErrorInfo
,m_pParent
,getORB());
401 if ( aRet
.first
.is() )
402 successfullyConnected();// notify the admindlg to save the password
406 // -----------------------------------------------------------------------------
407 Reference
< XDriver
> ODbDataSourceAdministrationHelper::getDriver()
409 // get the global DriverManager
410 Reference
< XDriverAccess
> xDriverManager
;
411 String sCurrentActionError
= String(ModuleRes(STR_COULDNOTCREATE_DRIVERMANAGER
));
412 // in case an error occures
413 sCurrentActionError
.SearchAndReplaceAscii("#servicename#", (::rtl::OUString
)SERVICE_SDBC_CONNECTIONPOOL
);
416 xDriverManager
= Reference
< XDriverAccess
>(getORB()->createInstance(SERVICE_SDBC_CONNECTIONPOOL
), UNO_QUERY
);
417 DBG_ASSERT(xDriverManager
.is(), "ODbDataSourceAdministrationHelper::getDriver: could not instantiate the driver manager, or it does not provide the necessary interface!");
421 // wrap the exception into an SQLException
422 SQLException
aSQLWrapper(e
.Message
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
423 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, makeAny(aSQLWrapper
));
425 if (!xDriverManager
.is())
426 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
429 Reference
< XDriver
> xDriver
= xDriverManager
->getDriverByURL(getConnectionURL());
432 sCurrentActionError
= String(ModuleRes(STR_NOREGISTEREDDRIVER
));
433 sCurrentActionError
.SearchAndReplaceAscii("#connurl#", getConnectionURL());
434 // will be caught and translated into an SQLContext exception
435 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
440 // -----------------------------------------------------------------------------
441 Reference
< XPropertySet
> ODbDataSourceAdministrationHelper::getCurrentDataSource()
443 if ( !m_xDatasource
.is() )
445 Reference
<XInterface
> xIn(m_aDataSourceOrName
,UNO_QUERY
);
448 ::rtl::OUString sCurrentDatasource
;
449 m_aDataSourceOrName
>>= sCurrentDatasource
;
450 OSL_ENSURE(sCurrentDatasource
.getLength(),"No datasource name given!");
453 if ( m_xDatabaseContext
.is() )
454 m_xDatasource
.set(m_xDatabaseContext
->getByName(sCurrentDatasource
),UNO_QUERY
);
457 catch(const Exception
&)
461 m_xModel
.set(getDataSourceOrModel(xIn
),UNO_QUERY
);
463 m_xDatasource
.set(xIn
,UNO_QUERY
);
466 m_xDatasource
.set(getDataSourceOrModel(xIn
),UNO_QUERY
);
467 m_xModel
.set(xIn
,UNO_QUERY
);
472 DBG_ASSERT(m_xDatasource
.is(), "ODbDataSourceAdministrationHelper::getCurrentDataSource: no data source!");
473 return m_xDatasource
;
475 //-------------------------------------------------------------------------
476 ::rtl::OUString
ODbDataSourceAdministrationHelper::getDatasourceType( const SfxItemSet
& _rSet
)
478 SFX_ITEMSET_GET( _rSet
, pConnectURL
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
479 DBG_ASSERT( pConnectURL
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!" );
480 SFX_ITEMSET_GET(_rSet
, pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
481 DBG_ASSERT(pTypeCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
482 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
483 return pCollection
->getType(pConnectURL
->GetValue());
486 //-------------------------------------------------------------------------
487 sal_Bool
ODbDataSourceAdministrationHelper::hasAuthentication(const SfxItemSet
& _rSet
) const
489 return DataSourceMetaData::getAuthentication( getDatasourceType( _rSet
) ) != AuthNone
;
491 // -----------------------------------------------------------------------------
492 String
ODbDataSourceAdministrationHelper::getConnectionURL() const
496 ::rtl::OUString eType
= getDatasourceType(*m_pItemSetHelper
->getOutputSet());
498 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
499 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
501 OSL_ENSURE(pUrlItem
,"Connection URL is NULL. -> GPF!");
502 DBG_ASSERT(pTypeCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
503 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
504 DBG_ASSERT(pCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid type collection!");
506 switch( pCollection
->determineType(eType
) )
508 case ::dbaccess::DST_DBASE
:
509 case ::dbaccess::DST_FLAT
:
510 case ::dbaccess::DST_CALC
:
512 case ::dbaccess::DST_ADABAS
:
514 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
515 sNewUrl
= lcl_createHostWithPort(pHostName
,NULL
);
516 String sUrl
= pCollection
->cutPrefix(pUrlItem
->GetValue());
517 if ( sUrl
.GetTokenCount(':') == 1 )
518 sNewUrl
+= String::CreateFromAscii(":");
523 case ::dbaccess::DST_MSACCESS
:
524 case ::dbaccess::DST_MSACCESS_2007
:
526 ::rtl::OUString sFileName
= pCollection
->cutPrefix(pUrlItem
->GetValue());
527 ::rtl::OUString sNewFileName
;
528 if ( ::osl::FileBase::getSystemPathFromFileURL( sFileName
, sNewFileName
) == ::osl::FileBase::E_None
)
530 sNewUrl
+= String(sNewFileName
);
534 case ::dbaccess::DST_MYSQL_NATIVE
:
535 case ::dbaccess::DST_MYSQL_JDBC
:
537 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
538 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_MYSQL_PORTNUMBER
, sal_True
);
539 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, sal_True
);
540 sNewUrl
= lcl_createHostWithPort(pHostName
,pPortNumber
);
541 String sDatabaseName
= pDatabaseName
? pDatabaseName
->GetValue() : String();
542 if ( !sDatabaseName
.Len() && pUrlItem
)
543 sDatabaseName
= pCollection
->cutPrefix( pUrlItem
->GetValue() );
544 // TODO: what's that? Why is the database name transported via the URL Item?
545 // Huh? Anybody there?
546 // OJ: It is needed when the connection properties are changed. There the URL is used for every type.
548 if ( sDatabaseName
.Len() )
550 sNewUrl
+= String::CreateFromAscii("/");
551 sNewUrl
+= sDatabaseName
;
555 case ::dbaccess::DST_ORACLE_JDBC
:
557 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
558 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_ORACLE_PORTNUMBER
, sal_True
);
559 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, sal_True
);
560 if ( pHostName
&& pHostName
->GetValue().Len() )
562 sNewUrl
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("@"));
563 sNewUrl
+= lcl_createHostWithPort(pHostName
,pPortNumber
);
564 String sDatabaseName
= pDatabaseName
? pDatabaseName
->GetValue() : String();
565 if ( !sDatabaseName
.Len() && pUrlItem
)
566 sDatabaseName
= pCollection
->cutPrefix( pUrlItem
->GetValue() );
567 if ( sDatabaseName
.Len() )
569 sNewUrl
+= String::CreateFromAscii(":");
570 sNewUrl
+= sDatabaseName
;
574 { // here someone entered a JDBC url which looks like oracle, so we have to use the url property
579 case ::dbaccess::DST_LDAP
:
581 // SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True);
582 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_CONN_LDAP_PORTNUMBER
, sal_True
);
583 sNewUrl
= pCollection
->cutPrefix(pUrlItem
->GetValue());
584 sNewUrl
+= lcl_createHostWithPort(NULL
,pPortNumber
);
587 case ::dbaccess::DST_JDBC
:
594 String sUrl
= pCollection
->getPrefix(eType
);
599 sNewUrl
= pUrlItem
->GetValue();
603 //-------------------------------------------------------------------------
604 struct PropertyValueLess
606 bool operator() (const PropertyValue
& x
, const PropertyValue
& y
) const
607 { return x
.Name
< y
.Name
? true : false; } // construct prevents a MSVC6 warning
609 DECLARE_STL_SET( PropertyValue
, PropertyValueLess
, PropertyValueSet
);
611 //........................................................................
612 void ODbDataSourceAdministrationHelper::translateProperties(const Reference
< XPropertySet
>& _rxSource
, SfxItemSet
& _rDest
)
614 ::rtl::OUString sNewConnectURL
, sName
, sUid
, sPwd
;
615 Sequence
< ::rtl::OUString
> aTableFitler
;
619 for ( ConstMapInt2StringIterator aDirect
= m_aDirectPropTranslator
.begin();
620 aDirect
!= m_aDirectPropTranslator
.end();
624 // get the property value
628 aValue
= _rxSource
->getPropertyValue(aDirect
->second
);
633 ::rtl::OString
aMessage("ODbDataSourceAdministrationHelper::translateProperties: could not extract the property ");
634 aMessage
+= ::rtl::OString(aDirect
->second
.getStr(), aDirect
->second
.getLength(), RTL_TEXTENCODING_ASCII_US
);
635 aMessage
+= ::rtl::OString("!");
636 DBG_ERROR(aMessage
.getStr());
639 // transfer it into an item
640 implTranslateProperty(_rDest
, aDirect
->first
, aValue
);
643 // get the additional informations
644 Sequence
< PropertyValue
> aAdditionalInfo
;
647 _rxSource
->getPropertyValue(PROPERTY_INFO
) >>= aAdditionalInfo
;
649 catch(Exception
&) { }
651 // collect the names of the additional settings
652 const PropertyValue
* pAdditionalInfo
= aAdditionalInfo
.getConstArray();
653 PropertyValueSet aInfos
;
654 for (sal_Int32 i
=0; i
<aAdditionalInfo
.getLength(); ++i
, ++pAdditionalInfo
)
656 if (0 == pAdditionalInfo
->Name
.compareToAscii("JDBCDRV"))
658 PropertyValue
aCompatibility(*pAdditionalInfo
);
659 aCompatibility
.Name
= ::rtl::OUString::createFromAscii("JavaDriverClass");
660 aInfos
.insert(aCompatibility
);
663 aInfos
.insert(*pAdditionalInfo
);
666 // go through all known translations and check if we have such a setting
667 if ( !aInfos
.empty() )
669 PropertyValue aSearchFor
;
670 ConstMapInt2StringIterator aEnd
= m_aIndirectPropTranslator
.end();
671 for ( ConstMapInt2StringIterator aIndirect
= m_aIndirectPropTranslator
.begin();
675 aSearchFor
.Name
= aIndirect
->second
;
676 ConstPropertyValueSetIterator aInfoPos
= aInfos
.find(aSearchFor
);
677 if (aInfos
.end() != aInfoPos
)
678 // the property is contained in the info sequence
679 // -> transfer it into an item
680 implTranslateProperty(_rDest
, aIndirect
->first
, aInfoPos
->Value
);
689 _rDest
.Put(OPropertySetItem(DSID_DATASOURCE_UNO
, _rxSource
));
690 Reference
<XStorable
> xStore(getDataSourceOrModel(_rxSource
),UNO_QUERY
);
691 _rDest
.Put(SfxBoolItem(DSID_READONLY
, !xStore
.is() || xStore
->isReadonly() ));
695 OSL_ENSURE(0,"IsReadOnly throws an exception!");
699 //-------------------------------------------------------------------------
700 void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet
& _rSource
, const Reference
< XPropertySet
>& _rxDest
)
702 DBG_ASSERT(_rxDest
.is(), "ODbDataSourceAdministrationHelper::translateProperties: invalid property set!");
706 // the property set info
707 Reference
< XPropertySetInfo
> xInfo
;
708 try { xInfo
= _rxDest
->getPropertySetInfo(); }
709 catch(Exception
&) { }
711 const ::rtl::OUString
sUrlProp(RTL_CONSTASCII_USTRINGPARAM("URL"));
712 // -----------------------------
713 // transfer the direct properties
714 for ( ConstMapInt2StringIterator aDirect
= m_aDirectPropTranslator
.begin();
715 aDirect
!= m_aDirectPropTranslator
.end();
719 const SfxPoolItem
* pCurrentItem
= _rSource
.GetItem((USHORT
)aDirect
->first
);
722 sal_Int16 nAttributes
= PropertyAttribute::READONLY
;
725 try { nAttributes
= xInfo
->getPropertyByName(aDirect
->second
).Attributes
; }
726 catch(Exception
&) { }
728 if ((nAttributes
& PropertyAttribute::READONLY
) == 0)
730 if ( sUrlProp
== aDirect
->second
)
732 Any
aValue(makeAny(::rtl::OUString(getConnectionURL())));
733 // aValue <<= ::rtl::OUString();
734 lcl_putProperty(_rxDest
, aDirect
->second
,aValue
);
737 implTranslateProperty(_rxDest
, aDirect
->second
, pCurrentItem
);
742 // -------------------------------
743 // now for the indirect properties
745 Sequence
< PropertyValue
> aInfo
;
746 // the original properties
749 _rxDest
->getPropertyValue(PROPERTY_INFO
) >>= aInfo
;
751 catch(Exception
&) { }
753 // overwrite and extend them
754 fillDatasourceInfo(_rSource
, aInfo
);
755 // and propagate the (newly composed) sequence to the set
756 lcl_putProperty(_rxDest
,PROPERTY_INFO
, makeAny(aInfo
));
760 //-------------------------------------------------------------------------
761 void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet
& _rSource
, Sequence
< ::com::sun::star::beans::PropertyValue
>& _rInfo
)
763 // within the current "Info" sequence, replace the ones we can examine from the item set
764 // (we don't just fill a completely new sequence with our own items, but we preserve any properties unknown to
767 // first determine which of all the items are relevant for the data source (depends on the connection url)
768 ::rtl::OUString eType
= getDatasourceType(_rSource
);
769 ::std::vector
< sal_Int32
> aDetailIds
;
770 ODriversSettings::getSupportedIndirectSettings(eType
,getORB(),aDetailIds
);
772 // collect the translated property values for the relevant items
773 PropertyValueSet aRelevantSettings
;
774 ConstMapInt2StringIterator aTranslation
;
775 ::std::vector
< sal_Int32
>::iterator aDetailsEnd
= aDetailIds
.end();
776 for (::std::vector
< sal_Int32
>::iterator aIter
= aDetailIds
.begin();aIter
!= aDetailsEnd
; ++aIter
)
778 const SfxPoolItem
* pCurrent
= _rSource
.GetItem((USHORT
)*aIter
);
779 aTranslation
= m_aIndirectPropTranslator
.find(*aIter
);
780 if ( pCurrent
&& (m_aIndirectPropTranslator
.end() != aTranslation
) )
782 if ( aTranslation
->second
== INFO_CHARSET
)
784 ::rtl::OUString sCharSet
;
785 implTranslateProperty(pCurrent
) >>= sCharSet
;
786 if ( sCharSet
.getLength() )
787 aRelevantSettings
.insert(PropertyValue(aTranslation
->second
, 0, makeAny(sCharSet
), PropertyState_DIRECT_VALUE
));
790 aRelevantSettings
.insert(PropertyValue(aTranslation
->second
, 0, implTranslateProperty(pCurrent
), PropertyState_DIRECT_VALUE
));
794 // settings to preserve
795 MapInt2String aPreservedSettings
;
797 // now aRelevantSettings contains all the property values relevant for the current data source type,
798 // check the original sequence if it already contains any of these values (which have to be overwritten, then)
799 PropertyValue
* pInfo
= _rInfo
.getArray();
800 PropertyValue aSearchFor
;
801 sal_Int32 nObsoleteSetting
= -1;
802 sal_Int32 nCount
= _rInfo
.getLength();
803 for (sal_Int32 i
= 0; i
< nCount
; ++i
, ++pInfo
)
805 aSearchFor
.Name
= pInfo
->Name
;
806 PropertyValueSetIterator aOverwrittenSetting
= aRelevantSettings
.find(aSearchFor
);
807 if (aRelevantSettings
.end() != aOverwrittenSetting
)
808 { // the setting was present in the original sequence, and it is to be overwritten -> replace it
809 if ( !::comphelper::compare(pInfo
->Value
,aOverwrittenSetting
->Value
) )
810 *pInfo
= *aOverwrittenSetting
;
811 aRelevantSettings
.erase(aOverwrittenSetting
);
813 else if (0 == pInfo
->Name
.compareToAscii("JDBCDRV"))
814 { // this is a compatibility setting, remove it from the sequence (it's replaced by JavaDriverClass)
815 nObsoleteSetting
= i
;
818 aPreservedSettings
[i
] = pInfo
->Name
;
820 if (-1 != nObsoleteSetting
)
821 ::comphelper::removeElementAt(_rInfo
, nObsoleteSetting
);
823 if ( !aPreservedSettings
.empty() )
824 { // check if there are settings which
825 // * are known as indirect properties
826 // * but not relevant for the current data source type
827 // These settings have to be removed: If they're not relevant, we have no UI for changing them.
828 // 25.06.2001 - 88004/87182 - frank.schoenheit@sun.com
830 // for this, we need a string-controlled quick access to m_aIndirectPropTranslator
831 StringSet aIndirectProps
;
832 ::std::transform(m_aIndirectPropTranslator
.begin(),
833 m_aIndirectPropTranslator
.end(),
834 ::std::insert_iterator
<StringSet
>(aIndirectProps
,aIndirectProps
.begin()),
835 ::std::select2nd
<MapInt2String::value_type
>());
837 // now check the to-be-preserved props
838 ::std::vector
< sal_Int32
> aRemoveIndexes
;
839 sal_Int32 nPositionCorrector
= 0;
840 ConstMapInt2StringIterator aPreservedEnd
= aPreservedSettings
.end();
841 for ( ConstMapInt2StringIterator aPreserved
= aPreservedSettings
.begin();
842 aPreserved
!= aPreservedEnd
;
846 if (aIndirectProps
.end() != aIndirectProps
.find(aPreserved
->second
))
849 const ::rtl::OUString sName
= aPreserved
->second
;
851 aRemoveIndexes
.push_back(aPreserved
->first
- nPositionCorrector
);
852 ++nPositionCorrector
;
855 // now finally remove all such props
856 ::std::vector
< sal_Int32
>::const_iterator aRemoveEnd
= aRemoveIndexes
.end();
857 for ( ::std::vector
< sal_Int32
>::const_iterator aRemoveIndex
= aRemoveIndexes
.begin();
858 aRemoveIndex
!= aRemoveEnd
;
861 ::comphelper::removeElementAt(_rInfo
, *aRemoveIndex
);
863 const PropertyValue
* pWhatsLeft
= _rInfo
.getConstArray();
864 const PropertyValue
* pWhatsLeftEnd
= pWhatsLeft
+ _rInfo
.getLength();
865 for (; pWhatsLeft
!= pWhatsLeftEnd
; ++pWhatsLeft
)
867 ::rtl::OUString sLookAtIt
= pWhatsLeft
->Name
;
872 ::connectivity::DriversConfig
aDriverConfig(getORB());
873 const ::comphelper::NamedValueCollection
& aProperties
= aDriverConfig
.getProperties(eType
);
874 Sequence
< Any
> aTypeSettings
;
875 aTypeSettings
= aProperties
.getOrDefault("TypeInfoSettings",aTypeSettings
);
876 // here we have a special entry for types from oracle
877 if ( aTypeSettings
.getLength() )
879 aRelevantSettings
.insert(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")), 0, makeAny(aTypeSettings
), PropertyState_DIRECT_VALUE
));
882 // check which values are still left ('cause they were not present in the original sequence, but are to be set)
883 if ( !aRelevantSettings
.empty() )
885 sal_Int32 nOldLength
= _rInfo
.getLength();
886 _rInfo
.realloc(nOldLength
+ aRelevantSettings
.size());
887 PropertyValue
* pAppendValues
= _rInfo
.getArray() + nOldLength
;
888 ConstPropertyValueSetIterator aRelevantEnd
= aRelevantSettings
.end();
889 for ( ConstPropertyValueSetIterator aLoop
= aRelevantSettings
.begin();
890 aLoop
!= aRelevantEnd
;
891 ++aLoop
, ++pAppendValues
894 if ( aLoop
->Name
== INFO_CHARSET
)
896 ::rtl::OUString sCharSet
;
897 aLoop
->Value
>>= sCharSet
;
898 if ( sCharSet
.getLength() )
899 *pAppendValues
= *aLoop
;
902 *pAppendValues
= *aLoop
;
906 //-------------------------------------------------------------------------
907 Any
ODbDataSourceAdministrationHelper::implTranslateProperty(const SfxPoolItem
* _pItem
)
909 // translate the SfxPoolItem
911 if (_pItem
->ISA(SfxStringItem
))
912 aValue
<<= ::rtl::OUString(PTR_CAST(SfxStringItem
, _pItem
)->GetValue().GetBuffer());
913 else if (_pItem
->ISA(SfxBoolItem
))
914 aValue
<<= PTR_CAST(SfxBoolItem
, _pItem
)->GetValue();
915 else if (_pItem
->ISA(SfxInt32Item
))
916 aValue
<<= PTR_CAST(SfxInt32Item
, _pItem
)->GetValue();
917 else if (_pItem
->ISA(OStringListItem
))
918 aValue
<<= PTR_CAST(OStringListItem
, _pItem
)->getList();
921 DBG_ERROR("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported item type!");
927 //-------------------------------------------------------------------------
928 void ODbDataSourceAdministrationHelper::implTranslateProperty(const Reference
< XPropertySet
>& _rxSet
, const ::rtl::OUString
& _rName
, const SfxPoolItem
* _pItem
)
930 Any aValue
= implTranslateProperty(_pItem
);
931 lcl_putProperty(_rxSet
, _rName
,aValue
);
934 //-------------------------------------------------------------------------
935 ::rtl::OString
ODbDataSourceAdministrationHelper::translatePropertyId( sal_Int32 _nId
)
937 ::rtl::OUString aString
;
939 MapInt2String::const_iterator aPos
= m_aDirectPropTranslator
.find( _nId
);
940 if ( m_aDirectPropTranslator
.end() != aPos
)
942 aString
= aPos
->second
;
946 MapInt2String::const_iterator indirectPos
= m_aIndirectPropTranslator
.find( _nId
);
947 if ( m_aIndirectPropTranslator
.end() != indirectPos
)
948 aString
= indirectPos
->second
;
951 ::rtl::OString
aReturn( aString
.getStr(), aString
.getLength(), RTL_TEXTENCODING_ASCII_US
);
956 //-------------------------------------------------------------------------
957 void ODbDataSourceAdministrationHelper::implTranslateProperty( SfxItemSet
& _rSet
, sal_Int32 _nId
, const Any
& _rValue
)
959 USHORT nId
= (USHORT
)_nId
;
960 switch (_rValue
.getValueType().getTypeClass())
962 case TypeClass_STRING
:
963 if ( implCheckItemType( _rSet
, nId
, SfxStringItem::StaticType() ) )
965 ::rtl::OUString sValue
;
967 _rSet
.Put(SfxStringItem(nId
, sValue
.getStr()));
971 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
972 += ::rtl::OString( translatePropertyId( _nId
) )
973 += ::rtl::OString( " should be no string)!" )
979 case TypeClass_BOOLEAN
:
980 if ( implCheckItemType( _rSet
, nId
, SfxBoolItem::StaticType() ) )
982 sal_Bool bVal
= sal_False
;
984 _rSet
.Put(SfxBoolItem(nId
, bVal
));
988 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
989 += ::rtl::OString( translatePropertyId( _nId
) )
990 += ::rtl::OString( " should be no boolean)!" )
997 if ( implCheckItemType( _rSet
, nId
, SfxInt32Item::StaticType() ) )
999 sal_Int32 nValue
= 0;
1001 _rSet
.Put( SfxInt32Item( nId
, nValue
) );
1005 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1006 += ::rtl::OString( translatePropertyId( _nId
) )
1007 += ::rtl::OString( " should be no int)!" )
1013 case TypeClass_SEQUENCE
:
1014 if ( implCheckItemType( _rSet
, nId
, OStringListItem::StaticType() ) )
1016 // determine the element type
1017 TypeDescription
aTD(_rValue
.getValueType());
1018 typelib_IndirectTypeDescription
* pSequenceTD
=
1019 reinterpret_cast< typelib_IndirectTypeDescription
* >(aTD
.get());
1020 DBG_ASSERT(pSequenceTD
&& pSequenceTD
->pType
, "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid sequence type!");
1022 Type
aElementType(pSequenceTD
->pType
);
1023 switch (aElementType
.getTypeClass())
1025 case TypeClass_STRING
:
1027 Sequence
< ::rtl::OUString
> aStringList
;
1028 _rValue
>>= aStringList
;
1029 _rSet
.Put(OStringListItem(nId
, aStringList
));
1033 DBG_ERROR("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1038 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1039 += ::rtl::OString( translatePropertyId( _nId
) )
1040 += ::rtl::OString( " should be no string sequence)!" )
1046 case TypeClass_VOID
:
1047 _rSet
.ClearItem(nId
);
1051 DBG_ERROR("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1056 String
ODbDataSourceAdministrationHelper::getDocumentUrl(SfxItemSet
& _rDest
)
1058 SFX_ITEMSET_GET(_rDest
, pUrlItem
, SfxStringItem
, DSID_DOCUMENT_URL
, sal_True
);
1059 OSL_ENSURE(pUrlItem
,"Document URL is NULL. -> GPF!");
1060 return pUrlItem
->GetValue();
1064 // -----------------------------------------------------------------------------
1065 void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet
& _rDest
)
1067 ::rtl::OUString eType
= getDatasourceType(_rDest
);
1069 SFX_ITEMSET_GET(_rDest
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
1070 SFX_ITEMSET_GET(_rDest
, pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
1072 OSL_ENSURE(pUrlItem
,"Connection URL is NULL. -> GPF!");
1073 DBG_ASSERT(pTypeCollection
, "ODbAdminDialog::getDatasourceType: invalid items in the source set!");
1074 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
1075 DBG_ASSERT(pCollection
, "ODbAdminDialog::getDatasourceType: invalid type collection!");
1077 USHORT nPortNumberId
= 0;
1078 sal_Int32 nPortNumber
= -1;
1079 String sNewHostName
;
1080 //String sUrl = pCollection->cutPrefix(pUrlItem->GetValue());
1083 pCollection
->extractHostNamePort(pUrlItem
->GetValue(),sUrlPart
,sNewHostName
,nPortNumber
);
1084 const ::dbaccess::DATASOURCE_TYPE eTy
= pCollection
->determineType(eType
);
1088 case ::dbaccess::DST_MYSQL_NATIVE
:
1089 case ::dbaccess::DST_MYSQL_JDBC
:
1090 nPortNumberId
= DSID_MYSQL_PORTNUMBER
;
1092 case ::dbaccess::DST_ORACLE_JDBC
:
1093 nPortNumberId
= DSID_ORACLE_PORTNUMBER
;
1095 case ::dbaccess::DST_LDAP
:
1096 nPortNumberId
= DSID_CONN_LDAP_PORTNUMBER
;
1102 if ( sUrlPart
.Len() )
1104 if ( eTy
== ::dbaccess::DST_MYSQL_NATIVE
)
1106 _rDest
.Put( SfxStringItem( DSID_DATABASENAME
, sUrlPart
) );
1110 String sNewUrl
= pCollection
->getPrefix(eType
);
1111 sNewUrl
+= sUrlPart
;
1112 _rDest
.Put( SfxStringItem( DSID_CONNECTURL
, sNewUrl
) );
1116 if ( sNewHostName
.Len() )
1117 _rDest
.Put(SfxStringItem(DSID_CONN_HOSTNAME
, sNewHostName
));
1119 if ( nPortNumber
!= -1 && nPortNumberId
!= 0 )
1120 _rDest
.Put(SfxInt32Item(nPortNumberId
, nPortNumber
));
1123 // -----------------------------------------------------------------------------
1124 sal_Bool
ODbDataSourceAdministrationHelper::saveChanges(const SfxItemSet
& _rSource
)
1126 // put the remembered settings into the property set
1127 Reference
<XPropertySet
> xDatasource
= getCurrentDataSource();
1128 if ( !xDatasource
.is() )
1131 translateProperties(_rSource
,xDatasource
);
1135 // -----------------------------------------------------------------------------
1136 void ODbDataSourceAdministrationHelper::setDataSourceOrName( const Any
& _rDataSourceOrName
)
1138 DBG_ASSERT( !m_aDataSourceOrName
.hasValue(), "ODbDataSourceAdministrationHelper::setDataSourceOrName: already have one!" );
1139 // hmm. We could reset m_xDatasource/m_xModel, probably, and continue working
1140 m_aDataSourceOrName
= _rDataSourceOrName
;
1142 //=========================================================================
1143 //= DbuTypeCollectionItem
1144 //=========================================================================
1145 TYPEINIT1(DbuTypeCollectionItem
, SfxPoolItem
);
1146 //-------------------------------------------------------------------------
1147 DbuTypeCollectionItem::DbuTypeCollectionItem(sal_Int16 _nWhich
, ::dbaccess::ODsnTypeCollection
* _pCollection
)
1148 :SfxPoolItem(_nWhich
)
1149 ,m_pCollection(_pCollection
)
1153 //-------------------------------------------------------------------------
1154 DbuTypeCollectionItem::DbuTypeCollectionItem(const DbuTypeCollectionItem
& _rSource
)
1155 :SfxPoolItem(_rSource
)
1156 ,m_pCollection(_rSource
.getCollection())
1160 //-------------------------------------------------------------------------
1161 int DbuTypeCollectionItem::operator==(const SfxPoolItem
& _rItem
) const
1163 DbuTypeCollectionItem
* pCompare
= PTR_CAST(DbuTypeCollectionItem
, &_rItem
);
1164 return pCompare
&& (pCompare
->getCollection() == getCollection());
1167 //-------------------------------------------------------------------------
1168 SfxPoolItem
* DbuTypeCollectionItem::Clone(SfxItemPool
* /*_pPool*/) const
1170 return new DbuTypeCollectionItem(*this);
1173 //.........................................................................
1174 } // namespace dbaui
1175 //.........................................................................