diff options
Diffstat (limited to 'dbaccess/source/core/dataaccess/datasource.cxx')
-rw-r--r-- | dbaccess/source/core/dataaccess/datasource.cxx | 138 |
1 files changed, 35 insertions, 103 deletions
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index 45ad2e500d8b..fbb0ac1bd86b 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -22,6 +22,7 @@ #include <stringconstants.hxx> #include <core_resource.hxx> #include <strings.hrc> +#include <strings.hxx> #include "connection.hxx" #include "SharedConnection.hxx" #include "databasedocument.hxx" @@ -55,13 +56,12 @@ #include <connectivity/dbtools.hxx> #include <cppuhelper/typeprovider.hxx> #include <officecfg/Office/Common.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <osl/process.h> #include <sal/log.hxx> #include <tools/urlobj.hxx> #include <unotools/sharedunocomponent.hxx> -#include <rtl/digest.h> #include <algorithm> #include <iterator> @@ -249,69 +249,6 @@ void SAL_CALL OAuthenticationContinuation::setRememberAccount( RememberAuthentic SAL_WARN("dbaccess","OAuthenticationContinuation::setRememberAccount: not supported!"); } -namespace { - -/** The class OSharedConnectionManager implements a structure to share connections. - It owns the master connections which will be disposed when the last connection proxy is gone. -*/ -// need to hold the digest -struct TDigestHolder -{ - sal_uInt8 m_pBuffer[RTL_DIGEST_LENGTH_SHA1]; - TDigestHolder() - { - m_pBuffer[0] = 0; - } - -}; - -} - -class OSharedConnectionManager : public ::cppu::WeakImplHelper< XEventListener > -{ - - // contains the currently used master connections - struct TConnectionHolder - { - Reference< XConnection > xMasterConnection; - oslInterlockedCount nALiveCount; - }; - - // the less-compare functor, used for the stl::map - struct TDigestLess - { - bool operator() (const TDigestHolder& x, const TDigestHolder& y) const - { - sal_uInt32 i; - for(i=0;i < RTL_DIGEST_LENGTH_SHA1 && (x.m_pBuffer[i] >= y.m_pBuffer[i]); ++i) - ; - return i < RTL_DIGEST_LENGTH_SHA1; - } - }; - - typedef std::map< TDigestHolder,TConnectionHolder,TDigestLess> TConnectionMap; // holds the master connections - typedef std::map< Reference< XConnection >,TConnectionMap::iterator> TSharedConnectionMap;// holds the shared connections - - ::osl::Mutex m_aMutex; - TConnectionMap m_aConnections; // remember the master connection in conjunction with the digest - TSharedConnectionMap m_aSharedConnection; // the shared connections with conjunction with an iterator into the connections map - Reference< XProxyFactory > m_xProxyFactory; - -protected: - virtual ~OSharedConnectionManager() override; - -public: - explicit OSharedConnectionManager(const Reference< XComponentContext >& _rxContext); - - void SAL_CALL disposing( const css::lang::EventObject& Source ) override; - Reference<XConnection> getConnection( const OUString& url, - const OUString& user, - const OUString& password, - const Sequence< PropertyValue >& _aInfo, - ODatabaseSource* _pDataSource); - void addEventListener(const Reference<XConnection>& _rxConnection, TConnectionMap::iterator const & _rIter); -}; - OSharedConnectionManager::OSharedConnectionManager(const Reference< XComponentContext >& _rxContext) { m_xProxyFactory.set( ProxyFactory::create( _rxContext ) ); @@ -607,8 +544,7 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString if ( xModel) { //See ODbTypeWizDialogSetup::SaveDatabaseDocument - ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); - aArgs.get("IgnoreFirebirdMigration") >>= bIgnoreMigration; + ::comphelper::NamedValueCollection::get(xModel->getArgs(), u"IgnoreFirebirdMigration") >>= bIgnoreMigration; } else { @@ -642,7 +578,7 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString if (bNeedMigration) { // back up content xml file if migration was successful - static constexpr OUStringLiteral BACKUP_XML_NAME = u"content_before_migration.xml"; + static constexpr OUString BACKUP_XML_NAME = u"content_before_migration.xml"_ustr; try { if(xRootStorage->isStreamElement(BACKUP_XML_NAME)) @@ -766,11 +702,11 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString OUString sMessage = DBA_RES(pExceptionMessageId) .replaceAll("$name$", m_pImpl->m_sConnectURL); - SQLContext aContext; - aContext.Message = DBA_RES(RID_STR_CONNECTION_REQUEST). - replaceFirst("$name$", m_pImpl->m_sConnectURL); + SQLContext aContext( + DBA_RES(RID_STR_CONNECTION_REQUEST).replaceFirst("$name$", m_pImpl->m_sConnectURL), + {}, {}, 0, {}, {}); - throwGenericSQLException( sMessage, static_cast< XDataSource* >( this ), makeAny( aContext ) ); + throwGenericSQLException( sMessage, static_cast< XDataSource* >( this ), Any( aContext ) ); } #if ENABLE_FIREBIRD_SDBC @@ -796,25 +732,26 @@ Reference< XPropertySetInfo > ODatabaseSource::getPropertySetInfo() // comphelper::OPropertyArrayUsageHelper ::cppu::IPropertyArrayHelper* ODatabaseSource::createArrayHelper( ) const { - css::uno::Sequence< css::beans::Property> aDescriptor(13); - css::beans::Property* pDesc = aDescriptor.getArray(); - sal_Int32 nPos = 0; - pDesc[nPos++] = css::beans::Property(PROPERTY_INFO, PROPERTY_ID_INFO, cppu::UnoType<Sequence< PropertyValue >>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_ISPASSWORDREQUIRED, PROPERTY_ID_ISPASSWORDREQUIRED, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_ISREADONLY, PROPERTY_ID_ISREADONLY, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY); - pDesc[nPos++] = css::beans::Property(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, cppu::UnoType<Sequence< PropertyValue >>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_NAME, PROPERTY_ID_NAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY); - pDesc[nPos++] = css::beans::Property(PROPERTY_NUMBERFORMATSSUPPLIER, PROPERTY_ID_NUMBERFORMATSSUPPLIER, - cppu::UnoType<XNumberFormatsSupplier>::get(), css::beans::PropertyAttribute::READONLY | css::beans::PropertyAttribute::TRANSIENT); - pDesc[nPos++] = css::beans::Property(PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::TRANSIENT); - pDesc[nPos++] = css::beans::Property(PROPERTY_SETTINGS, PROPERTY_ID_SETTINGS, cppu::UnoType<XPropertySet>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY); - pDesc[nPos++] = css::beans::Property(PROPERTY_SUPPRESSVERSIONCL, PROPERTY_ID_SUPPRESSVERSIONCL, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_TABLEFILTER, PROPERTY_ID_TABLEFILTER, cppu::UnoType<Sequence< OUString >>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_TABLETYPEFILTER, PROPERTY_ID_TABLETYPEFILTER, cppu::UnoType<Sequence< OUString >>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_URL, PROPERTY_ID_URL, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND); - pDesc[nPos++] = css::beans::Property(PROPERTY_USER, PROPERTY_ID_USER, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND); - OSL_ENSURE(nPos == aDescriptor.getLength(), "forgot to adjust the count ?"); - return new ::cppu::OPropertyArrayHelper(aDescriptor); + return new ::cppu::OPropertyArrayHelper + { + { + // a change here means a change should also been done in OApplicationController::disposing() + { PROPERTY_INFO, PROPERTY_ID_INFO, cppu::UnoType<Sequence< PropertyValue >>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_ISPASSWORDREQUIRED, PROPERTY_ID_ISPASSWORDREQUIRED, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_ISREADONLY, PROPERTY_ID_ISREADONLY, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY }, + { PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, cppu::UnoType<Sequence< PropertyValue >>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_NAME, PROPERTY_ID_NAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY }, + { PROPERTY_NUMBERFORMATSSUPPLIER, PROPERTY_ID_NUMBERFORMATSSUPPLIER, cppu::UnoType<XNumberFormatsSupplier>::get(), + css::beans::PropertyAttribute::READONLY | css::beans::PropertyAttribute::TRANSIENT }, + { PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::TRANSIENT }, + { PROPERTY_SETTINGS, PROPERTY_ID_SETTINGS, cppu::UnoType<XPropertySet>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY }, + { PROPERTY_SUPPRESSVERSIONCL, PROPERTY_ID_SUPPRESSVERSIONCL, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_TABLEFILTER, PROPERTY_ID_TABLEFILTER, cppu::UnoType<Sequence< OUString >>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_TABLETYPEFILTER, PROPERTY_ID_TABLETYPEFILTER, cppu::UnoType<Sequence< OUString >>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_URL, PROPERTY_ID_URL, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND }, + { PROPERTY_USER, PROPERTY_ID_USER, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND } + } + }; } // cppu::OPropertySetHelper @@ -861,7 +798,7 @@ sal_Bool ODatabaseSource::convertFastPropertyValue(Any & rConvertedValue, Any & if (!(rValue >>= aValues)) throw IllegalArgumentException(); - for ( auto const & checkName : std::as_const(aValues) ) + for (auto const& checkName : aValues) { if ( checkName.Name.isEmpty() ) throw IllegalArgumentException(); @@ -1159,7 +1096,7 @@ Reference< XConnection > ODatabaseSource::connectWithCompletion( const Reference aRequest.HasUserName = aRequest.HasPassword = true; aRequest.UserName = m_pImpl->m_sUser; aRequest.Password = m_pImpl->m_sFailedPassword.isEmpty() ? m_pImpl->m_aPassword : m_pImpl->m_sFailedPassword; - rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(makeAny(aRequest)); + rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(Any(aRequest)); // some knittings pRequest->addContinuation(pAbort); pRequest->addContinuation(pAuthenticate); @@ -1234,14 +1171,9 @@ Reference< XConnection > ODatabaseSource::getConnection(const OUString& user, co { // create a new proxy for the connection if ( !m_pImpl->m_xSharedConnectionManager.is() ) { - // TODO ideally we could just have one field, but to make that work - // we'd need to move OSharedConnectionManager into its own file and header - rtl::Reference<OSharedConnectionManager> manager = - new OSharedConnectionManager( m_pImpl->m_aContext ); - m_pImpl->m_pSharedConnectionManager = manager.get(); - m_pImpl->m_xSharedConnectionManager = m_pImpl->m_pSharedConnectionManager; + m_pImpl->m_xSharedConnectionManager = new OSharedConnectionManager( m_pImpl->m_aContext ); } - xConn = m_pImpl->m_pSharedConnectionManager->getConnection( + xConn = m_pImpl->m_xSharedConnectionManager->getConnection( m_pImpl->m_sConnectURL, user, password, m_pImpl->m_xSettings->getPropertyValues(), this ); } @@ -1278,13 +1210,13 @@ Reference< XNameAccess > SAL_CALL ODatabaseSource::getQueryDefinitions( ) aValue >>= sSupportService; if ( !sSupportService.isEmpty() ) { - Sequence<Any> aArgs{ Any(NamedValue("DataSource",makeAny(xMy))) }; + Sequence<Any> aArgs{ Any(NamedValue("DataSource",Any(xMy))) }; xContainer.set( m_pImpl->m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext(sSupportService, aArgs, m_pImpl->m_aContext), UNO_QUERY); } } if ( !xContainer.is() ) { - TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::E_QUERY ) ); + TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::ObjectType::Query ) ); xContainer = new OCommandContainer( m_pImpl->m_aContext, *this, rContainerData, false ); } m_pImpl->m_xCommandDefinitions = xContainer; @@ -1300,7 +1232,7 @@ Reference< XNameAccess > ODatabaseSource::getTables() Reference< XNameAccess > xContainer = m_pImpl->m_xTableDefinitions; if ( !xContainer.is() ) { - TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::E_TABLE ) ); + TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::ObjectType::Table ) ); xContainer = new OCommandContainer( m_pImpl->m_aContext, *this, rContainerData, true ); m_pImpl->m_xTableDefinitions = xContainer; } |