From 6025e7420f7ee3f4fc87761994acce40a82ec0bd Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 16 Nov 2009 12:01:50 +0100 Subject: in preparation of #i84012#: introduced a dedicated interface (css.sdb.XDatabaseRegistrations) for dealing with data source registrations, this way hiding the concrete configuration details. --- extensions/source/abpilot/datasourcehandling.cxx | 86 +++++++++--------------- 1 file changed, 33 insertions(+), 53 deletions(-) (limited to 'extensions/source/abpilot') diff --git a/extensions/source/abpilot/datasourcehandling.cxx b/extensions/source/abpilot/datasourcehandling.cxx index 14ad3543ac51..269c84adf163 100644 --- a/extensions/source/abpilot/datasourcehandling.cxx +++ b/extensions/source/abpilot/datasourcehandling.cxx @@ -30,30 +30,34 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_extensions.hxx" + +#include "abpresid.hrc" +#include "abptypes.hxx" +#include "componentmodule.hxx" #include "datasourcehandling.hxx" + #include -#include #include -#include -#include -#include #include -#include #include -#include +#include +#include +#include #include +#include #include +#include #include -#include +#include +#include + #include -#include -#ifndef EXTENSIONS_ABPRESID_HRC -#include "abpresid.hrc" -#endif -#include "componentmodule.hxx" -#include "abptypes.hxx" +#include +#include +#include #include #include +#include //......................................................................... namespace abp @@ -76,26 +80,6 @@ namespace abp struct PackageAccessControl { }; //===================================================================== - //-------------------------------------------------------------------- - static const ::rtl::OUString& getDbRegisteredNamesNodeName() - { - static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("org.openoffice.Office.DataAccess/RegisteredNames"); - return s_sNodeName; - } - - //-------------------------------------------------------------------- - static const ::rtl::OUString& getDbNameNodeName() - { - static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("Name"); - return s_sNodeName; - } - - //-------------------------------------------------------------------- - static const ::rtl::OUString& getDbLocationNodeName() - { - static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("Location"); - return s_sNodeName; - } //--------------------------------------------------------------------- static Reference< XNameAccess > lcl_getDataSourceContext( const Reference< XMultiServiceFactory >& _rxORB ) SAL_THROW (( Exception )) { @@ -173,28 +157,24 @@ namespace abp const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _sName, const ::rtl::OUString& _sURL ) SAL_THROW (( ::com::sun::star::uno::Exception )) { - // the config node where all pooling relevant info are stored under - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - _rxORB, getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_UPDATABLE); - - if (!aDbRegisteredNamesRoot.isValid()) - // already asserted by the OConfigurationTreeRoot - return; - - OSL_ENSURE(_sName.getLength(),"No Name given!"); - OSL_ENSURE(_sURL.getLength(),"No URL given!"); - - OConfigurationNode aThisDriverSettings; - if ( aDbRegisteredNamesRoot.hasByName(_sName) ) - aThisDriverSettings = aDbRegisteredNamesRoot.openNode(_sName); - else - aThisDriverSettings = aDbRegisteredNamesRoot.createNode(_sName); + OSL_ENSURE( _sName.getLength(), "lcl_registerDataSource: invalid name!" ); + OSL_ENSURE( _sURL.getLength(), "lcl_registerDataSource: invalid URL!" ); + try + { - // set the values - aThisDriverSettings.setNodeValue(getDbNameNodeName(), makeAny(_sName)); - aThisDriverSettings.setNodeValue(getDbLocationNodeName(), makeAny(_sURL)); + ::comphelper::ComponentContext aContext( _rxORB ); + Reference< XDatabaseRegistrations > xRegistrations( + aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW ); - aDbRegisteredNamesRoot.commit(); + if ( xRegistrations->hasRegisteredDatabase( _sName ) ) + xRegistrations->changeDatabaseLocation( _sName, _sURL ); + else + xRegistrations->registerDatabaseLocation( _sName, _sURL ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } //===================================================================== -- cgit