diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-11-16 12:01:50 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-11-16 12:01:50 +0100 |
commit | adcbc9187644e1463114baa16011ad3fc8401fd4 (patch) | |
tree | 3077ee57b2fd8be397204289968de095ec84d4f8 /svx/source | |
parent | 77adaec362dbc74aa8907ae3847d96e8ecce42ba (diff) |
in preparation of #i84012#:
introduced a dedicated interface (css.sdb.XDatabaseRegistrations) for dealing with data source registrations, this way
hiding the concrete configuration details.
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/cui/dbregisterednamesconfig.cxx | 171 |
1 files changed, 59 insertions, 112 deletions
diff --git a/svx/source/cui/dbregisterednamesconfig.cxx b/svx/source/cui/dbregisterednamesconfig.cxx index 4f9cf1150422..71b776bf59fc 100644 --- a/svx/source/cui/dbregisterednamesconfig.cxx +++ b/svx/source/cui/dbregisterednamesconfig.cxx @@ -35,22 +35,22 @@ #undef SVX_DLLIMPLEMENTATION #endif +#include "connpooloptions.hxx" #include "dbregisterednamesconfig.hxx" +#include "dbregistersettings.hxx" +#include "svx/svxids.hrc" +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/sdb/XDatabaseRegistrations.hpp> -#include <svtools/itemset.hxx> -#include <tools/diagnose_ex.h> - -#include <svx/svxids.hrc> -#include <unotools/confignode.hxx> +#include <comphelper/componentcontext.hxx> #include <comphelper/extract.hxx> -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/uno/XNamingService.hpp> -#include <svtools/eitem.hxx> #include <comphelper/processfactory.hxx> +#include <svtools/eitem.hxx> +#include <svtools/itemset.hxx> #include <svtools/pathoptions.hxx> -#include "dbregistersettings.hxx" -#include "connpooloptions.hxx" +#include <tools/diagnose_ex.h> +#include <unotools/confignode.hxx> //........................................................................ namespace svx @@ -59,136 +59,83 @@ namespace svx using namespace ::utl; using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::container; - //-------------------------------------------------------------------- - 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; - } - //==================================================================== //= DbRegisteredNamesConfig //==================================================================== //-------------------------------------------------------------------- void DbRegisteredNamesConfig::GetOptions(SfxItemSet& _rFillItems) { - // the config node where all pooling relevant info are stored under - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - ::comphelper::getProcessServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_READONLY); - TNameLocationMap aSettings; - // then look for which of them settings are stored in the configuration - Sequence< ::rtl::OUString > aDriverKeys = aDbRegisteredNamesRoot.getNodeNames(); - const ::rtl::OUString* pDriverKeys = aDriverKeys.getConstArray(); - const ::rtl::OUString* pDriverKeysEnd = pDriverKeys + aDriverKeys.getLength(); - for (;pDriverKeys != pDriverKeysEnd; ++pDriverKeys) + try + { + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + Reference< XDatabaseRegistrations > xRegistrations( + aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW ); + + Sequence< ::rtl::OUString > aRegistrationNames( xRegistrations->getRegistrationNames() ); + const ::rtl::OUString* pRegistrationName = aRegistrationNames.getConstArray(); + const ::rtl::OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength(); + for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName ) + { + ::rtl::OUString sLocation( xRegistrations->getDatabaseLocation( *pRegistrationName ) ); + aSettings[ *pRegistrationName ] = sLocation; + } + } + catch( const Exception& ) { - // the name of the driver in this round - OConfigurationNode aThisDriverSettings = aDbRegisteredNamesRoot.openNode(*pDriverKeys); - ::rtl::OUString sName, sLocation; - aThisDriverSettings.getNodeValue(getDbNameNodeName()) >>= sName; - aThisDriverSettings.getNodeValue(getDbLocationNodeName()) >>= sLocation; - sLocation = SvtPathOptions().SubstituteVariable(sLocation); - - aSettings.insert(TNameLocationMap::value_type(sName,sLocation)); + DBG_UNHANDLED_EXCEPTION(); } - _rFillItems.Put(DatabaseMapItem(SID_SB_DB_REGISTER, aSettings)); + _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, aSettings ) ); } //-------------------------------------------------------------------- void DbRegisteredNamesConfig::SetOptions(const SfxItemSet& _rSourceItems) { - // the config node where all pooling relevant info are stored under - OConfigurationTreeRoot aDbRegisteredNamesRoot = OConfigurationTreeRoot::createWithServiceFactory( - ::comphelper::getProcessServiceFactory(), getDbRegisteredNamesNodeName(), -1, OConfigurationTreeRoot::CM_UPDATABLE); - - if (!aDbRegisteredNamesRoot.isValid()) - // already asserted by the OConfigurationTreeRoot + // the settings for the single drivers + SFX_ITEMSET_GET( _rSourceItems, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, sal_True ); + if ( !pRegistrations ) return; - sal_Bool bNeedCommit = sal_False; - - - // the settings for the single drivers - SFX_ITEMSET_GET( _rSourceItems, pDriverSettings, DatabaseMapItem, SID_SB_DB_REGISTER, sal_True ); - if (pDriverSettings) + try { - Reference< XNameAccess > xDatabaseContext = Reference< XNameAccess >(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatabaseContext"))), UNO_QUERY); - Reference< XNamingService> xNamingService(xDatabaseContext,UNO_QUERY); - ::rtl::OUString sName, sLocation; - OConfigurationNode aThisDriverSettings; - - const TNameLocationMap& rNewSettings = pDriverSettings->getSettings(); - TNameLocationMap::const_iterator aEnd = rNewSettings.end(); - for ( TNameLocationMap::const_iterator aLoop = rNewSettings.begin(); - aLoop != aEnd; - ++aLoop + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + Reference< XDatabaseRegistrations > xRegistrations( + aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW ); + + const TNameLocationMap& rNewRegistrations = pRegistrations->getSettings(); + for ( TNameLocationMap::const_iterator reg = rNewRegistrations.begin(); + reg != rNewRegistrations.end(); + ++reg ) { - // need the name as ::rtl::OUString - sName = aLoop->first; - - // the sub-node for this driver - if (aDbRegisteredNamesRoot.hasByName(sName)) - { - aThisDriverSettings = aDbRegisteredNamesRoot.openNode(sName); - // set the values - aThisDriverSettings.setNodeValue(getDbNameNodeName(), makeAny(sName)); - aThisDriverSettings.setNodeValue(getDbLocationNodeName(), makeAny(aLoop->second)); - bNeedCommit = sal_True; - } + const ::rtl::OUString sName = reg->first; + const ::rtl::OUString sLocation = reg->second; + + if ( xRegistrations->hasRegisteredDatabase( sName ) ) + xRegistrations->changeDatabaseLocation( sName, sLocation ); else - { - try - { - xNamingService->registerObject(sName,Reference< ::com::sun::star::uno::XInterface >(xDatabaseContext->getByName(aLoop->second),UNO_QUERY)); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } + xRegistrations->registerDatabaseLocation( sName, sLocation ); } - if (bNeedCommit) - aDbRegisteredNamesRoot.commit(); - - // delete unused entry - Sequence< ::rtl::OUString > aDriverKeys = xDatabaseContext->getElementNames(); - const ::rtl::OUString* pDriverKeys = aDriverKeys.getConstArray(); - const ::rtl::OUString* pDriverKeysEnd = pDriverKeys + aDriverKeys.getLength(); - for (;pDriverKeys != pDriverKeysEnd; ++pDriverKeys) + + // delete unused entries + Sequence< ::rtl::OUString > aRegistrationNames = xRegistrations->getRegistrationNames(); + const ::rtl::OUString* pRegistrationName = aRegistrationNames.getConstArray(); + const ::rtl::OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength(); + for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName ) { - if ( rNewSettings.find(*pDriverKeys) == rNewSettings.end() ) - { - try - { - xNamingService->revokeObject(*pDriverKeys); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } + if ( rNewRegistrations.find( *pRegistrationName ) == rNewRegistrations.end() ) + xRegistrations->revokeDatabaseLocation( *pRegistrationName ); } } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } //........................................................................ |