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" ) ) ) );
243 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_NAMED_PIPE
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPipe" ) ) ) );
245 // special settings for adabas
246 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_SHUTSERVICE
, ::rtl::OUString::createFromAscii("ShutdownDatabase")));
247 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_DATAINC
, ::rtl::OUString::createFromAscii("DataCacheSizeIncrement")));
248 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_CACHESIZE
, ::rtl::OUString::createFromAscii("DataCacheSize")));
249 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_CTRLUSER
, ::rtl::OUString::createFromAscii("ControlUser")));
250 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_CTRLPWD
, ::rtl::OUString::createFromAscii("ControlPassword")));
252 // extra settings for odbc
253 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_USECATALOG
, INFO_USECATALOG
));
254 // extra settings for a ldap address book
255 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_BASEDN
, INFO_CONN_LDAP_BASEDN
));
256 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_ROWCOUNT
, INFO_CONN_LDAP_ROWCOUNT
));
257 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_CONN_LDAP_USESSL
, ::rtl::OUString::createFromAscii("UseSSL")));
258 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_DOCUMENT_URL
, PROPERTY_URL
));
261 m_aIndirectPropTranslator
.insert(MapInt2String::value_type(DSID_IGNORECURRENCY
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))));
265 m_xDatabaseContext
= Reference
< XNameAccess
>(m_xORB
->createInstance(SERVICE_SDB_DATABASECONTEXT
), UNO_QUERY
);
266 m_xDynamicContext
.set(m_xDatabaseContext
,UNO_QUERY
);
272 if ( !m_xDatabaseContext
.is() )
274 ShowServiceNotAvailableError(_pParent
->GetParent(), String(SERVICE_SDB_DATABASECONTEXT
), sal_True
);
277 DBG_ASSERT(m_xDynamicContext
.is(), "ODbAdminDialog::ODbAdminDialog : no XNamingService interface !");
279 //-------------------------------------------------------------------------
280 sal_Bool
ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence
< PropertyValue
>& _rDriverParam
)
282 DBG_ASSERT(m_pItemSetHelper
->getOutputSet(), "ODbDataSourceAdministrationHelper::getCurrentSettings : not to be called without an example set!");
283 if (!m_pItemSetHelper
->getOutputSet())
286 ::std::vector
< PropertyValue
> aReturn
;
287 // collecting this in a vector because it has a push_back, in opposite to sequences
289 // user: DSID_USER -> "user"
290 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pUser
, SfxStringItem
, DSID_USER
, sal_True
);
291 if (pUser
&& pUser
->GetValue().Len())
293 PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), 0,
294 makeAny(::rtl::OUString(pUser
->GetValue())), PropertyState_DIRECT_VALUE
));
296 // check if the connection type requires a password
297 if (hasAuthentication(*m_pItemSetHelper
->getOutputSet()))
299 // password: DSID_PASSWORD -> "password"
300 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPassword
, SfxStringItem
, DSID_PASSWORD
, sal_True
);
301 String sPassword
= pPassword
? pPassword
->GetValue() : String();
302 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPasswordRequired
, SfxBoolItem
, DSID_PASSWORDREQUIRED
, sal_True
);
303 // if the set does not contain a password, but the item set says it requires one, ask the user
304 if ((!pPassword
|| !pPassword
->GetValue().Len()) && (pPasswordRequired
&& pPasswordRequired
->GetValue()))
306 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pName
, SfxStringItem
, DSID_NAME
, sal_True
);
308 ::svt::LoginDialog
aDlg(m_pParent
,
309 LF_NO_PATH
| LF_NO_ACCOUNT
| LF_NO_ERRORTEXT
| LF_USERNAME_READONLY
,
312 aDlg
.SetName(pUser
? pUser
->GetValue() : String());
313 aDlg
.ClearPassword(); // this will give the password field the focus
315 String sName
= pName
? pName
->GetValue() : String();
316 String
sLoginRequest(ModuleRes(STR_ENTER_CONNECTION_PASSWORD
));
317 ::rtl::OUString sTemp
= sName
;
318 sName
= ::dbaui::getStrippedDatabaseName(NULL
,sTemp
);
320 sLoginRequest
.SearchAndReplaceAscii("$name$", sName
);
323 sLoginRequest
.SearchAndReplaceAscii("\"$name$\"", String());
324 sLoginRequest
.SearchAndReplaceAscii("$name$", String()); // just to be sure that in other languages the string will be deleted
326 aDlg
.SetLoginRequestText(sLoginRequest
);
328 aDlg
.SetSavePasswordText(ModuleRes(STR_REMEMBERPASSWORD_SESSION
));
329 aDlg
.SetSavePassword(sal_True
);
331 sal_Int32 nResult
= aDlg
.Execute();
332 if (nResult
!= RET_OK
)
335 sPassword
= aDlg
.GetPassword();
336 if (aDlg
.IsSavePassword())
337 m_pItemSetHelper
->getWriteOutputSet()->Put(SfxStringItem(DSID_PASSWORD
, sPassword
));
342 PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("password")), 0,
343 makeAny(::rtl::OUString(sPassword
)), PropertyState_DIRECT_VALUE
));
346 if ( !aReturn
.empty() )
347 _rDriverParam
= Sequence
< PropertyValue
>(&(*aReturn
.begin()), aReturn
.size());
349 // append all the other stuff (charset etc.)
350 fillDatasourceInfo(*m_pItemSetHelper
->getOutputSet(), _rDriverParam
);
354 //-------------------------------------------------------------------------
355 void ODbDataSourceAdministrationHelper::successfullyConnected()
357 DBG_ASSERT(m_pItemSetHelper
->getOutputSet(), "ODbDataSourceAdministrationHelper::successfullyConnected: not to be called without an example set!");
358 if (!m_pItemSetHelper
->getOutputSet())
361 if (hasAuthentication(*m_pItemSetHelper
->getOutputSet()))
363 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPassword
, SfxStringItem
, DSID_PASSWORD
, sal_True
);
364 if (pPassword
&& (0 != pPassword
->GetValue().Len()))
366 ::rtl::OUString sPassword
= pPassword
->GetValue();
368 Reference
< XPropertySet
> xCurrentDatasource
= getCurrentDataSource();
369 lcl_putProperty(xCurrentDatasource
,m_aDirectPropTranslator
[DSID_PASSWORD
], makeAny(sPassword
));
373 //-------------------------------------------------------------------------
374 void ODbDataSourceAdministrationHelper::clearPassword()
376 if (m_pItemSetHelper
->getWriteOutputSet())
377 m_pItemSetHelper
->getWriteOutputSet()->ClearItem(DSID_PASSWORD
);
379 // -----------------------------------------------------------------------------
380 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbDataSourceAdministrationHelper::createConnection()
382 ::std::pair
< Reference
<XConnection
>,sal_Bool
> aRet
;
383 aRet
.second
= sal_False
;
384 Sequence
< PropertyValue
> aConnectionParams
;
385 if ( getCurrentSettings(aConnectionParams
) )
388 // fill the table list with this connection information
389 SQLExceptionInfo aErrorInfo
;
392 WaitObject
aWaitCursor(m_pParent
);
393 aRet
.first
= getDriver()->connect(getConnectionURL(), aConnectionParams
);
394 aRet
.second
= sal_True
;
396 catch (SQLContext
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
397 catch (SQLWarning
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
398 catch (SQLException
& e
) { aErrorInfo
= SQLExceptionInfo(e
); }
400 showError(aErrorInfo
,m_pParent
,getORB());
402 if ( aRet
.first
.is() )
403 successfullyConnected();// notify the admindlg to save the password
407 // -----------------------------------------------------------------------------
408 Reference
< XDriver
> ODbDataSourceAdministrationHelper::getDriver()
410 // get the global DriverManager
411 Reference
< XDriverAccess
> xDriverManager
;
412 String sCurrentActionError
= String(ModuleRes(STR_COULDNOTCREATE_DRIVERMANAGER
));
413 // in case an error occures
414 sCurrentActionError
.SearchAndReplaceAscii("#servicename#", (::rtl::OUString
)SERVICE_SDBC_CONNECTIONPOOL
);
417 xDriverManager
= Reference
< XDriverAccess
>(getORB()->createInstance(SERVICE_SDBC_CONNECTIONPOOL
), UNO_QUERY
);
418 DBG_ASSERT(xDriverManager
.is(), "ODbDataSourceAdministrationHelper::getDriver: could not instantiate the driver manager, or it does not provide the necessary interface!");
422 // wrap the exception into an SQLException
423 SQLException
aSQLWrapper(e
.Message
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
424 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, makeAny(aSQLWrapper
));
426 if (!xDriverManager
.is())
427 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
430 Reference
< XDriver
> xDriver
= xDriverManager
->getDriverByURL(getConnectionURL());
433 sCurrentActionError
= String(ModuleRes(STR_NOREGISTEREDDRIVER
));
434 sCurrentActionError
.SearchAndReplaceAscii("#connurl#", getConnectionURL());
435 // will be caught and translated into an SQLContext exception
436 throw SQLException(sCurrentActionError
, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
441 // -----------------------------------------------------------------------------
442 Reference
< XPropertySet
> ODbDataSourceAdministrationHelper::getCurrentDataSource()
444 if ( !m_xDatasource
.is() )
446 Reference
<XInterface
> xIn(m_aDataSourceOrName
,UNO_QUERY
);
449 ::rtl::OUString sCurrentDatasource
;
450 m_aDataSourceOrName
>>= sCurrentDatasource
;
451 OSL_ENSURE(sCurrentDatasource
.getLength(),"No datasource name given!");
454 if ( m_xDatabaseContext
.is() )
455 m_xDatasource
.set(m_xDatabaseContext
->getByName(sCurrentDatasource
),UNO_QUERY
);
458 catch(const Exception
&)
462 m_xModel
.set(getDataSourceOrModel(xIn
),UNO_QUERY
);
464 m_xDatasource
.set(xIn
,UNO_QUERY
);
467 m_xDatasource
.set(getDataSourceOrModel(xIn
),UNO_QUERY
);
468 m_xModel
.set(xIn
,UNO_QUERY
);
473 DBG_ASSERT(m_xDatasource
.is(), "ODbDataSourceAdministrationHelper::getCurrentDataSource: no data source!");
474 return m_xDatasource
;
476 //-------------------------------------------------------------------------
477 ::rtl::OUString
ODbDataSourceAdministrationHelper::getDatasourceType( const SfxItemSet
& _rSet
)
479 SFX_ITEMSET_GET( _rSet
, pConnectURL
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
480 DBG_ASSERT( pConnectURL
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!" );
481 SFX_ITEMSET_GET(_rSet
, pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
482 DBG_ASSERT(pTypeCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
483 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
484 return pCollection
->getType(pConnectURL
->GetValue());
487 //-------------------------------------------------------------------------
488 sal_Bool
ODbDataSourceAdministrationHelper::hasAuthentication(const SfxItemSet
& _rSet
) const
490 return DataSourceMetaData::getAuthentication( getDatasourceType( _rSet
) ) != AuthNone
;
492 // -----------------------------------------------------------------------------
493 String
ODbDataSourceAdministrationHelper::getConnectionURL() const
497 ::rtl::OUString eType
= getDatasourceType(*m_pItemSetHelper
->getOutputSet());
499 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
500 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
502 OSL_ENSURE(pUrlItem
,"Connection URL is NULL. -> GPF!");
503 DBG_ASSERT(pTypeCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
504 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
505 DBG_ASSERT(pCollection
, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid type collection!");
507 switch( pCollection
->determineType(eType
) )
509 case ::dbaccess::DST_DBASE
:
510 case ::dbaccess::DST_FLAT
:
511 case ::dbaccess::DST_CALC
:
513 case ::dbaccess::DST_ADABAS
:
515 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
516 sNewUrl
= lcl_createHostWithPort(pHostName
,NULL
);
517 String sUrl
= pCollection
->cutPrefix(pUrlItem
->GetValue());
518 if ( sUrl
.GetTokenCount(':') == 1 )
519 sNewUrl
+= String::CreateFromAscii(":");
524 case ::dbaccess::DST_MSACCESS
:
525 case ::dbaccess::DST_MSACCESS_2007
:
527 ::rtl::OUString sFileName
= pCollection
->cutPrefix(pUrlItem
->GetValue());
528 ::rtl::OUString sNewFileName
;
529 if ( ::osl::FileBase::getSystemPathFromFileURL( sFileName
, sNewFileName
) == ::osl::FileBase::E_None
)
531 sNewUrl
+= String(sNewFileName
);
535 case ::dbaccess::DST_MYSQL_NATIVE
:
536 case ::dbaccess::DST_MYSQL_JDBC
:
538 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
539 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_MYSQL_PORTNUMBER
, sal_True
);
540 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, sal_True
);
541 sNewUrl
= lcl_createHostWithPort(pHostName
,pPortNumber
);
542 String sDatabaseName
= pDatabaseName
? pDatabaseName
->GetValue() : String();
543 if ( !sDatabaseName
.Len() && pUrlItem
)
544 sDatabaseName
= pCollection
->cutPrefix( pUrlItem
->GetValue() );
545 // TODO: what's that? Why is the database name transported via the URL Item?
546 // Huh? Anybody there?
547 // OJ: It is needed when the connection properties are changed. There the URL is used for every type.
549 if ( sDatabaseName
.Len() )
551 sNewUrl
+= String::CreateFromAscii("/");
552 sNewUrl
+= sDatabaseName
;
556 case ::dbaccess::DST_ORACLE_JDBC
:
558 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, sal_True
);
559 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_ORACLE_PORTNUMBER
, sal_True
);
560 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, sal_True
);
561 if ( pHostName
&& pHostName
->GetValue().Len() )
563 sNewUrl
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("@"));
564 sNewUrl
+= lcl_createHostWithPort(pHostName
,pPortNumber
);
565 String sDatabaseName
= pDatabaseName
? pDatabaseName
->GetValue() : String();
566 if ( !sDatabaseName
.Len() && pUrlItem
)
567 sDatabaseName
= pCollection
->cutPrefix( pUrlItem
->GetValue() );
568 if ( sDatabaseName
.Len() )
570 sNewUrl
+= String::CreateFromAscii(":");
571 sNewUrl
+= sDatabaseName
;
575 { // here someone entered a JDBC url which looks like oracle, so we have to use the url property
580 case ::dbaccess::DST_LDAP
:
582 // SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True);
583 SFX_ITEMSET_GET(*m_pItemSetHelper
->getOutputSet(), pPortNumber
, SfxInt32Item
, DSID_CONN_LDAP_PORTNUMBER
, sal_True
);
584 sNewUrl
= pCollection
->cutPrefix(pUrlItem
->GetValue());
585 sNewUrl
+= lcl_createHostWithPort(NULL
,pPortNumber
);
588 case ::dbaccess::DST_JDBC
:
595 String sUrl
= pCollection
->getPrefix(eType
);
600 sNewUrl
= pUrlItem
->GetValue();
604 //-------------------------------------------------------------------------
605 struct PropertyValueLess
607 bool operator() (const PropertyValue
& x
, const PropertyValue
& y
) const
608 { return x
.Name
< y
.Name
? true : false; } // construct prevents a MSVC6 warning
610 DECLARE_STL_SET( PropertyValue
, PropertyValueLess
, PropertyValueSet
);
612 //........................................................................
613 void ODbDataSourceAdministrationHelper::translateProperties(const Reference
< XPropertySet
>& _rxSource
, SfxItemSet
& _rDest
)
615 ::rtl::OUString sNewConnectURL
, sName
, sUid
, sPwd
;
616 Sequence
< ::rtl::OUString
> aTableFitler
;
620 for ( ConstMapInt2StringIterator aDirect
= m_aDirectPropTranslator
.begin();
621 aDirect
!= m_aDirectPropTranslator
.end();
625 // get the property value
629 aValue
= _rxSource
->getPropertyValue(aDirect
->second
);
634 ::rtl::OString
aMessage("ODbDataSourceAdministrationHelper::translateProperties: could not extract the property ");
635 aMessage
+= ::rtl::OString(aDirect
->second
.getStr(), aDirect
->second
.getLength(), RTL_TEXTENCODING_ASCII_US
);
636 aMessage
+= ::rtl::OString("!");
637 DBG_ERROR(aMessage
.getStr());
640 // transfer it into an item
641 implTranslateProperty(_rDest
, aDirect
->first
, aValue
);
644 // get the additional informations
645 Sequence
< PropertyValue
> aAdditionalInfo
;
648 _rxSource
->getPropertyValue(PROPERTY_INFO
) >>= aAdditionalInfo
;
650 catch(Exception
&) { }
652 // collect the names of the additional settings
653 const PropertyValue
* pAdditionalInfo
= aAdditionalInfo
.getConstArray();
654 PropertyValueSet aInfos
;
655 for (sal_Int32 i
=0; i
<aAdditionalInfo
.getLength(); ++i
, ++pAdditionalInfo
)
657 if (0 == pAdditionalInfo
->Name
.compareToAscii("JDBCDRV"))
659 PropertyValue
aCompatibility(*pAdditionalInfo
);
660 aCompatibility
.Name
= ::rtl::OUString::createFromAscii("JavaDriverClass");
661 aInfos
.insert(aCompatibility
);
664 aInfos
.insert(*pAdditionalInfo
);
667 // go through all known translations and check if we have such a setting
668 if ( !aInfos
.empty() )
670 PropertyValue aSearchFor
;
671 ConstMapInt2StringIterator aEnd
= m_aIndirectPropTranslator
.end();
672 for ( ConstMapInt2StringIterator aIndirect
= m_aIndirectPropTranslator
.begin();
676 aSearchFor
.Name
= aIndirect
->second
;
677 ConstPropertyValueSetIterator aInfoPos
= aInfos
.find(aSearchFor
);
678 if (aInfos
.end() != aInfoPos
)
679 // the property is contained in the info sequence
680 // -> transfer it into an item
681 implTranslateProperty(_rDest
, aIndirect
->first
, aInfoPos
->Value
);
690 _rDest
.Put(OPropertySetItem(DSID_DATASOURCE_UNO
, _rxSource
));
691 Reference
<XStorable
> xStore(getDataSourceOrModel(_rxSource
),UNO_QUERY
);
692 _rDest
.Put(SfxBoolItem(DSID_READONLY
, !xStore
.is() || xStore
->isReadonly() ));
696 OSL_ENSURE(0,"IsReadOnly throws an exception!");
700 //-------------------------------------------------------------------------
701 void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet
& _rSource
, const Reference
< XPropertySet
>& _rxDest
)
703 DBG_ASSERT(_rxDest
.is(), "ODbDataSourceAdministrationHelper::translateProperties: invalid property set!");
707 // the property set info
708 Reference
< XPropertySetInfo
> xInfo
;
709 try { xInfo
= _rxDest
->getPropertySetInfo(); }
710 catch(Exception
&) { }
712 const ::rtl::OUString
sUrlProp(RTL_CONSTASCII_USTRINGPARAM("URL"));
713 // -----------------------------
714 // transfer the direct properties
715 for ( ConstMapInt2StringIterator aDirect
= m_aDirectPropTranslator
.begin();
716 aDirect
!= m_aDirectPropTranslator
.end();
720 const SfxPoolItem
* pCurrentItem
= _rSource
.GetItem((USHORT
)aDirect
->first
);
723 sal_Int16 nAttributes
= PropertyAttribute::READONLY
;
726 try { nAttributes
= xInfo
->getPropertyByName(aDirect
->second
).Attributes
; }
727 catch(Exception
&) { }
729 if ((nAttributes
& PropertyAttribute::READONLY
) == 0)
731 if ( sUrlProp
== aDirect
->second
)
733 Any
aValue(makeAny(::rtl::OUString(getConnectionURL())));
734 // aValue <<= ::rtl::OUString();
735 lcl_putProperty(_rxDest
, aDirect
->second
,aValue
);
738 implTranslateProperty(_rxDest
, aDirect
->second
, pCurrentItem
);
743 // -------------------------------
744 // now for the indirect properties
746 Sequence
< PropertyValue
> aInfo
;
747 // the original properties
750 _rxDest
->getPropertyValue(PROPERTY_INFO
) >>= aInfo
;
752 catch(Exception
&) { }
754 // overwrite and extend them
755 fillDatasourceInfo(_rSource
, aInfo
);
756 // and propagate the (newly composed) sequence to the set
757 lcl_putProperty(_rxDest
,PROPERTY_INFO
, makeAny(aInfo
));
761 //-------------------------------------------------------------------------
762 void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet
& _rSource
, Sequence
< ::com::sun::star::beans::PropertyValue
>& _rInfo
)
764 // within the current "Info" sequence, replace the ones we can examine from the item set
765 // (we don't just fill a completely new sequence with our own items, but we preserve any properties unknown to
768 // first determine which of all the items are relevant for the data source (depends on the connection url)
769 ::rtl::OUString eType
= getDatasourceType(_rSource
);
770 ::std::vector
< sal_Int32
> aDetailIds
;
771 ODriversSettings::getSupportedIndirectSettings(eType
,getORB(),aDetailIds
);
773 // collect the translated property values for the relevant items
774 PropertyValueSet aRelevantSettings
;
775 ConstMapInt2StringIterator aTranslation
;
776 ::std::vector
< sal_Int32
>::iterator aDetailsEnd
= aDetailIds
.end();
777 for (::std::vector
< sal_Int32
>::iterator aIter
= aDetailIds
.begin();aIter
!= aDetailsEnd
; ++aIter
)
779 const SfxPoolItem
* pCurrent
= _rSource
.GetItem((USHORT
)*aIter
);
780 aTranslation
= m_aIndirectPropTranslator
.find(*aIter
);
781 if ( pCurrent
&& (m_aIndirectPropTranslator
.end() != aTranslation
) )
783 if ( aTranslation
->second
== INFO_CHARSET
)
785 ::rtl::OUString sCharSet
;
786 implTranslateProperty(pCurrent
) >>= sCharSet
;
787 if ( sCharSet
.getLength() )
788 aRelevantSettings
.insert(PropertyValue(aTranslation
->second
, 0, makeAny(sCharSet
), PropertyState_DIRECT_VALUE
));
791 aRelevantSettings
.insert(PropertyValue(aTranslation
->second
, 0, implTranslateProperty(pCurrent
), PropertyState_DIRECT_VALUE
));
795 // settings to preserve
796 MapInt2String aPreservedSettings
;
798 // now aRelevantSettings contains all the property values relevant for the current data source type,
799 // check the original sequence if it already contains any of these values (which have to be overwritten, then)
800 PropertyValue
* pInfo
= _rInfo
.getArray();
801 PropertyValue aSearchFor
;
802 sal_Int32 nObsoleteSetting
= -1;
803 sal_Int32 nCount
= _rInfo
.getLength();
804 for (sal_Int32 i
= 0; i
< nCount
; ++i
, ++pInfo
)
806 aSearchFor
.Name
= pInfo
->Name
;
807 PropertyValueSetIterator aOverwrittenSetting
= aRelevantSettings
.find(aSearchFor
);
808 if (aRelevantSettings
.end() != aOverwrittenSetting
)
809 { // the setting was present in the original sequence, and it is to be overwritten -> replace it
810 if ( !::comphelper::compare(pInfo
->Value
,aOverwrittenSetting
->Value
) )
811 *pInfo
= *aOverwrittenSetting
;
812 aRelevantSettings
.erase(aOverwrittenSetting
);
814 else if (0 == pInfo
->Name
.compareToAscii("JDBCDRV"))
815 { // this is a compatibility setting, remove it from the sequence (it's replaced by JavaDriverClass)
816 nObsoleteSetting
= i
;
819 aPreservedSettings
[i
] = pInfo
->Name
;
821 if (-1 != nObsoleteSetting
)
822 ::comphelper::removeElementAt(_rInfo
, nObsoleteSetting
);
824 if ( !aPreservedSettings
.empty() )
825 { // check if there are settings which
826 // * are known as indirect properties
827 // * but not relevant for the current data source type
828 // These settings have to be removed: If they're not relevant, we have no UI for changing them.
829 // 25.06.2001 - 88004/87182 - frank.schoenheit@sun.com
831 // for this, we need a string-controlled quick access to m_aIndirectPropTranslator
832 StringSet aIndirectProps
;
833 ::std::transform(m_aIndirectPropTranslator
.begin(),
834 m_aIndirectPropTranslator
.end(),
835 ::std::insert_iterator
<StringSet
>(aIndirectProps
,aIndirectProps
.begin()),
836 ::std::select2nd
<MapInt2String::value_type
>());
838 // now check the to-be-preserved props
839 ::std::vector
< sal_Int32
> aRemoveIndexes
;
840 sal_Int32 nPositionCorrector
= 0;
841 ConstMapInt2StringIterator aPreservedEnd
= aPreservedSettings
.end();
842 for ( ConstMapInt2StringIterator aPreserved
= aPreservedSettings
.begin();
843 aPreserved
!= aPreservedEnd
;
847 if (aIndirectProps
.end() != aIndirectProps
.find(aPreserved
->second
))
850 const ::rtl::OUString sName
= aPreserved
->second
;
852 aRemoveIndexes
.push_back(aPreserved
->first
- nPositionCorrector
);
853 ++nPositionCorrector
;
856 // now finally remove all such props
857 ::std::vector
< sal_Int32
>::const_iterator aRemoveEnd
= aRemoveIndexes
.end();
858 for ( ::std::vector
< sal_Int32
>::const_iterator aRemoveIndex
= aRemoveIndexes
.begin();
859 aRemoveIndex
!= aRemoveEnd
;
862 ::comphelper::removeElementAt(_rInfo
, *aRemoveIndex
);
864 const PropertyValue
* pWhatsLeft
= _rInfo
.getConstArray();
865 const PropertyValue
* pWhatsLeftEnd
= pWhatsLeft
+ _rInfo
.getLength();
866 for (; pWhatsLeft
!= pWhatsLeftEnd
; ++pWhatsLeft
)
868 ::rtl::OUString sLookAtIt
= pWhatsLeft
->Name
;
873 ::connectivity::DriversConfig
aDriverConfig(getORB());
874 const ::comphelper::NamedValueCollection
& aProperties
= aDriverConfig
.getProperties(eType
);
875 Sequence
< Any
> aTypeSettings
;
876 aTypeSettings
= aProperties
.getOrDefault("TypeInfoSettings",aTypeSettings
);
877 // here we have a special entry for types from oracle
878 if ( aTypeSettings
.getLength() )
880 aRelevantSettings
.insert(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")), 0, makeAny(aTypeSettings
), PropertyState_DIRECT_VALUE
));
883 // check which values are still left ('cause they were not present in the original sequence, but are to be set)
884 if ( !aRelevantSettings
.empty() )
886 sal_Int32 nOldLength
= _rInfo
.getLength();
887 _rInfo
.realloc(nOldLength
+ aRelevantSettings
.size());
888 PropertyValue
* pAppendValues
= _rInfo
.getArray() + nOldLength
;
889 ConstPropertyValueSetIterator aRelevantEnd
= aRelevantSettings
.end();
890 for ( ConstPropertyValueSetIterator aLoop
= aRelevantSettings
.begin();
891 aLoop
!= aRelevantEnd
;
892 ++aLoop
, ++pAppendValues
895 if ( aLoop
->Name
== INFO_CHARSET
)
897 ::rtl::OUString sCharSet
;
898 aLoop
->Value
>>= sCharSet
;
899 if ( sCharSet
.getLength() )
900 *pAppendValues
= *aLoop
;
903 *pAppendValues
= *aLoop
;
907 //-------------------------------------------------------------------------
908 Any
ODbDataSourceAdministrationHelper::implTranslateProperty(const SfxPoolItem
* _pItem
)
910 // translate the SfxPoolItem
912 if (_pItem
->ISA(SfxStringItem
))
913 aValue
<<= ::rtl::OUString(PTR_CAST(SfxStringItem
, _pItem
)->GetValue().GetBuffer());
914 else if (_pItem
->ISA(SfxBoolItem
))
915 aValue
<<= PTR_CAST(SfxBoolItem
, _pItem
)->GetValue();
916 else if (_pItem
->ISA(SfxInt32Item
))
917 aValue
<<= PTR_CAST(SfxInt32Item
, _pItem
)->GetValue();
918 else if (_pItem
->ISA(OStringListItem
))
919 aValue
<<= PTR_CAST(OStringListItem
, _pItem
)->getList();
922 DBG_ERROR("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported item type!");
928 //-------------------------------------------------------------------------
929 void ODbDataSourceAdministrationHelper::implTranslateProperty(const Reference
< XPropertySet
>& _rxSet
, const ::rtl::OUString
& _rName
, const SfxPoolItem
* _pItem
)
931 Any aValue
= implTranslateProperty(_pItem
);
932 lcl_putProperty(_rxSet
, _rName
,aValue
);
935 //-------------------------------------------------------------------------
936 ::rtl::OString
ODbDataSourceAdministrationHelper::translatePropertyId( sal_Int32 _nId
)
938 ::rtl::OUString aString
;
940 MapInt2String::const_iterator aPos
= m_aDirectPropTranslator
.find( _nId
);
941 if ( m_aDirectPropTranslator
.end() != aPos
)
943 aString
= aPos
->second
;
947 MapInt2String::const_iterator indirectPos
= m_aIndirectPropTranslator
.find( _nId
);
948 if ( m_aIndirectPropTranslator
.end() != indirectPos
)
949 aString
= indirectPos
->second
;
952 ::rtl::OString
aReturn( aString
.getStr(), aString
.getLength(), RTL_TEXTENCODING_ASCII_US
);
957 //-------------------------------------------------------------------------
958 void ODbDataSourceAdministrationHelper::implTranslateProperty( SfxItemSet
& _rSet
, sal_Int32 _nId
, const Any
& _rValue
)
960 USHORT nId
= (USHORT
)_nId
;
961 switch (_rValue
.getValueType().getTypeClass())
963 case TypeClass_STRING
:
964 if ( implCheckItemType( _rSet
, nId
, SfxStringItem::StaticType() ) )
966 ::rtl::OUString sValue
;
968 _rSet
.Put(SfxStringItem(nId
, sValue
.getStr()));
972 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
973 += ::rtl::OString( translatePropertyId( _nId
) )
974 += ::rtl::OString( " should be no string)!" )
980 case TypeClass_BOOLEAN
:
981 if ( implCheckItemType( _rSet
, nId
, SfxBoolItem::StaticType() ) )
983 sal_Bool bVal
= sal_False
;
985 _rSet
.Put(SfxBoolItem(nId
, bVal
));
989 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
990 += ::rtl::OString( translatePropertyId( _nId
) )
991 += ::rtl::OString( " should be no boolean)!" )
998 if ( implCheckItemType( _rSet
, nId
, SfxInt32Item::StaticType() ) )
1000 sal_Int32 nValue
= 0;
1002 _rSet
.Put( SfxInt32Item( nId
, nValue
) );
1006 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1007 += ::rtl::OString( translatePropertyId( _nId
) )
1008 += ::rtl::OString( " should be no int)!" )
1014 case TypeClass_SEQUENCE
:
1015 if ( implCheckItemType( _rSet
, nId
, OStringListItem::StaticType() ) )
1017 // determine the element type
1018 TypeDescription
aTD(_rValue
.getValueType());
1019 typelib_IndirectTypeDescription
* pSequenceTD
=
1020 reinterpret_cast< typelib_IndirectTypeDescription
* >(aTD
.get());
1021 DBG_ASSERT(pSequenceTD
&& pSequenceTD
->pType
, "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid sequence type!");
1023 Type
aElementType(pSequenceTD
->pType
);
1024 switch (aElementType
.getTypeClass())
1026 case TypeClass_STRING
:
1028 Sequence
< ::rtl::OUString
> aStringList
;
1029 _rValue
>>= aStringList
;
1030 _rSet
.Put(OStringListItem(nId
, aStringList
));
1034 DBG_ERROR("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1039 ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1040 += ::rtl::OString( translatePropertyId( _nId
) )
1041 += ::rtl::OString( " should be no string sequence)!" )
1047 case TypeClass_VOID
:
1048 _rSet
.ClearItem(nId
);
1052 DBG_ERROR("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1057 String
ODbDataSourceAdministrationHelper::getDocumentUrl(SfxItemSet
& _rDest
)
1059 SFX_ITEMSET_GET(_rDest
, pUrlItem
, SfxStringItem
, DSID_DOCUMENT_URL
, sal_True
);
1060 OSL_ENSURE(pUrlItem
,"Document URL is NULL. -> GPF!");
1061 return pUrlItem
->GetValue();
1065 // -----------------------------------------------------------------------------
1066 void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet
& _rDest
)
1068 ::rtl::OUString eType
= getDatasourceType(_rDest
);
1070 SFX_ITEMSET_GET(_rDest
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
1071 SFX_ITEMSET_GET(_rDest
, pTypeCollection
, DbuTypeCollectionItem
, DSID_TYPECOLLECTION
, sal_True
);
1073 OSL_ENSURE(pUrlItem
,"Connection URL is NULL. -> GPF!");
1074 DBG_ASSERT(pTypeCollection
, "ODbAdminDialog::getDatasourceType: invalid items in the source set!");
1075 ::dbaccess::ODsnTypeCollection
* pCollection
= pTypeCollection
->getCollection();
1076 DBG_ASSERT(pCollection
, "ODbAdminDialog::getDatasourceType: invalid type collection!");
1078 USHORT nPortNumberId
= 0;
1079 sal_Int32 nPortNumber
= -1;
1080 String sNewHostName
;
1081 //String sUrl = pCollection->cutPrefix(pUrlItem->GetValue());
1084 pCollection
->extractHostNamePort(pUrlItem
->GetValue(),sUrlPart
,sNewHostName
,nPortNumber
);
1085 const ::dbaccess::DATASOURCE_TYPE eTy
= pCollection
->determineType(eType
);
1089 case ::dbaccess::DST_MYSQL_NATIVE
:
1090 case ::dbaccess::DST_MYSQL_JDBC
:
1091 nPortNumberId
= DSID_MYSQL_PORTNUMBER
;
1093 case ::dbaccess::DST_ORACLE_JDBC
:
1094 nPortNumberId
= DSID_ORACLE_PORTNUMBER
;
1096 case ::dbaccess::DST_LDAP
:
1097 nPortNumberId
= DSID_CONN_LDAP_PORTNUMBER
;
1103 if ( sUrlPart
.Len() )
1105 if ( eTy
== ::dbaccess::DST_MYSQL_NATIVE
)
1107 _rDest
.Put( SfxStringItem( DSID_DATABASENAME
, sUrlPart
) );
1111 String sNewUrl
= pCollection
->getPrefix(eType
);
1112 sNewUrl
+= sUrlPart
;
1113 _rDest
.Put( SfxStringItem( DSID_CONNECTURL
, sNewUrl
) );
1117 if ( sNewHostName
.Len() )
1118 _rDest
.Put(SfxStringItem(DSID_CONN_HOSTNAME
, sNewHostName
));
1120 if ( nPortNumber
!= -1 && nPortNumberId
!= 0 )
1121 _rDest
.Put(SfxInt32Item(nPortNumberId
, nPortNumber
));
1124 // -----------------------------------------------------------------------------
1125 sal_Bool
ODbDataSourceAdministrationHelper::saveChanges(const SfxItemSet
& _rSource
)
1127 // put the remembered settings into the property set
1128 Reference
<XPropertySet
> xDatasource
= getCurrentDataSource();
1129 if ( !xDatasource
.is() )
1132 translateProperties(_rSource
,xDatasource
);
1136 // -----------------------------------------------------------------------------
1137 void ODbDataSourceAdministrationHelper::setDataSourceOrName( const Any
& _rDataSourceOrName
)
1139 DBG_ASSERT( !m_aDataSourceOrName
.hasValue(), "ODbDataSourceAdministrationHelper::setDataSourceOrName: already have one!" );
1140 // hmm. We could reset m_xDatasource/m_xModel, probably, and continue working
1141 m_aDataSourceOrName
= _rDataSourceOrName
;
1143 //=========================================================================
1144 //= DbuTypeCollectionItem
1145 //=========================================================================
1146 TYPEINIT1(DbuTypeCollectionItem
, SfxPoolItem
);
1147 //-------------------------------------------------------------------------
1148 DbuTypeCollectionItem::DbuTypeCollectionItem(sal_Int16 _nWhich
, ::dbaccess::ODsnTypeCollection
* _pCollection
)
1149 :SfxPoolItem(_nWhich
)
1150 ,m_pCollection(_pCollection
)
1154 //-------------------------------------------------------------------------
1155 DbuTypeCollectionItem::DbuTypeCollectionItem(const DbuTypeCollectionItem
& _rSource
)
1156 :SfxPoolItem(_rSource
)
1157 ,m_pCollection(_rSource
.getCollection())
1161 //-------------------------------------------------------------------------
1162 int DbuTypeCollectionItem::operator==(const SfxPoolItem
& _rItem
) const
1164 DbuTypeCollectionItem
* pCompare
= PTR_CAST(DbuTypeCollectionItem
, &_rItem
);
1165 return pCompare
&& (pCompare
->getCollection() == getCollection());
1168 //-------------------------------------------------------------------------
1169 SfxPoolItem
* DbuTypeCollectionItem::Clone(SfxItemPool
* /*_pPool*/) const
1171 return new DbuTypeCollectionItem(*this);
1174 //.........................................................................
1175 } // namespace dbaui
1176 //.........................................................................