diff options
Diffstat (limited to 'dbaccess/source/core/dataaccess')
33 files changed, 839 insertions, 1092 deletions
diff --git a/dbaccess/source/core/dataaccess/ComponentDefinition.cxx b/dbaccess/source/core/dataaccess/ComponentDefinition.cxx index a6110bdb2dab..19076507e0b3 100644 --- a/dbaccess/source/core/dataaccess/ComponentDefinition.cxx +++ b/dbaccess/source/core/dataaccess/ComponentDefinition.cxx @@ -18,18 +18,17 @@ */ #include "ComponentDefinition.hxx" -#include <apitools.hxx> #include <stringconstants.hxx> +#include <strings.hxx> #include <osl/diagnose.h> #include <com/sun/star/beans/PropertyAttribute.hpp> -#include <cppuhelper/interfacecontainer.hxx> +//#include <cppuhelper/interfacecontainer.hxx> #include <comphelper/property.hxx> #include <comphelper/propertysequence.hxx> #include <definitioncolumn.hxx> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; @@ -142,7 +141,14 @@ css::uno::Sequence<sal_Int8> OComponentDefinition::getImplementationId() return css::uno::Sequence<sal_Int8>(); } -IMPLEMENT_GETTYPES3(OComponentDefinition,ODataSettings,OContentHelper,OComponentDefinition_BASE); +css::uno::Sequence< css::uno::Type > OComponentDefinition::getTypes() +{ + return ::comphelper::concatSequences( + ODataSettings::getTypes( ), + OContentHelper::getTypes( ), + OComponentDefinition_BASE::getTypes( ) + ); +} IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE) OUString SAL_CALL OComponentDefinition::getImplementationName() @@ -213,13 +219,13 @@ Reference< XNameAccess> OComponentDefinition::getColumns() return m_pColumns.get(); } -OColumn* OComponentDefinition::createColumn(const OUString& _rName) const +rtl::Reference<OColumn> OComponentDefinition::createColumn(const OUString& _rName) const { const OComponentDefinition_Impl& rDefinition( getDefinition() ); OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName ); if ( aFind != rDefinition.end() ) { - aFind->second->addPropertyChangeListener(OUString(),m_xColumnPropertyListener.get()); + aFind->second->addPropertyChangeListener(OUString(),m_xColumnPropertyListener); return new OTableColumnWrapper( aFind->second, aFind->second, true ); } OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" ); diff --git a/dbaccess/source/core/dataaccess/ComponentDefinition.hxx b/dbaccess/source/core/dataaccess/ComponentDefinition.hxx index 014bafb0fa1a..4c10a5354b30 100644 --- a/dbaccess/source/core/dataaccess/ComponentDefinition.hxx +++ b/dbaccess/source/core/dataaccess/ComponentDefinition.hxx @@ -133,7 +133,7 @@ public: virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; // IColumnFactory - virtual OColumn* createColumn(const OUString& _rName) const override; + virtual rtl::Reference<OColumn> createColumn(const OUString& _rName) const override; virtual css::uno::Reference< css::beans::XPropertySet > createColumnDescriptor() override; virtual void columnAppended( const css::uno::Reference< css::beans::XPropertySet >& _rxSourceDescriptor ) override; virtual void columnDropped(const OUString& _sName) override; diff --git a/dbaccess/source/core/dataaccess/ContentHelper.cxx b/dbaccess/source/core/dataaccess/ContentHelper.cxx index 6e0e17b360ef..e624eb709c43 100644 --- a/dbaccess/source/core/dataaccess/ContentHelper.cxx +++ b/dbaccess/source/core/dataaccess/ContentHelper.cxx @@ -31,15 +31,14 @@ #include <com/sun/star/container/ElementExistException.hpp> #include <ucbhelper/propertyvalueset.hxx> #include <ucbhelper/contentidentifier.hxx> -#include <cppuhelper/interfacecontainer.hxx> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <tools/diagnose_ex.h> -#include <apitools.hxx> +#include <comphelper/diagnose_ex.hxx> #include <sdbcoretools.hxx> #include <stringconstants.hxx> +#include <strings.hxx> #include <map> +#include <utility> namespace dbaccess { @@ -49,8 +48,6 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::util; -using namespace ::com::sun::star::embed; using namespace ::com::sun::star::container; using namespace ::cppu; @@ -65,13 +62,13 @@ OContentHelper_Impl::~OContentHelper_Impl() OContentHelper::OContentHelper(const Reference< XComponentContext >& _xORB ,const Reference< XInterface >& _xParentContainer - ,const TContentPtr& _pImpl) + ,TContentPtr _pImpl) : OContentHelper_COMPBASE(m_aMutex) ,m_aContentListeners(m_aMutex) ,m_aPropertyChangeListeners(m_aMutex) ,m_xParentContainer( _xParentContainer ) ,m_aContext( _xORB ) - ,m_pImpl(_pImpl) + ,m_pImpl(std::move(_pImpl)) ,m_nCommandId(0) { } @@ -87,14 +84,25 @@ void SAL_CALL OContentHelper::disposing() m_xParentContainer = nullptr; } -IMPLEMENT_SERVICE_INFO1(OContentHelper,"com.sun.star.comp.sdb.Content","com.sun.star.ucb.Content"); +OUString SAL_CALL OContentHelper::getImplementationName() + { + return "com.sun.star.comp.sdb.Content"; + } +sal_Bool SAL_CALL OContentHelper::supportsService(const OUString& _rServiceName) + { + const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames()); + for (const OUString& s : aSupported) + if (s == _rServiceName) + return true; -css::uno::Sequence<sal_Int8> OContentHelper::getUnoTunnelId() + return false; + } +css::uno::Sequence< OUString > SAL_CALL OContentHelper::getSupportedServiceNames() { - static cppu::OImplementationId aId; - return aId.getImplementationId(); + return { "com.sun.star.ucb.Content" }; } + css::uno::Sequence<sal_Int8> OContentHelper::getImplementationId() { return css::uno::Sequence<sal_Int8>(); @@ -123,7 +131,7 @@ OUString OContentHelper::impl_getHierarchicalName( bool _includingRootContainer xProp->getPropertyValue( PROPERTY_NAME ) >>= sName; OUString sPrevious = aHierarchicalName.makeStringAndClear(); - aHierarchicalName.append( sName ).append( "/" ).append( sPrevious ); + aHierarchicalName.append( sName + "/" + sPrevious ); } } OUString sHierarchicalName( aHierarchicalName.makeStringAndClear() ); @@ -178,7 +186,7 @@ Any SAL_CALL OContentHelper::execute( const Command& aCommand, sal_Int32 /*Comma { OSL_FAIL( "Wrong argument type!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -196,7 +204,7 @@ Any SAL_CALL OContentHelper::execute( const Command& aCommand, sal_Int32 /*Comma { OSL_FAIL( "Wrong argument type!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -208,7 +216,7 @@ Any SAL_CALL OContentHelper::execute( const Command& aCommand, sal_Int32 /*Comma { OSL_FAIL( "No properties!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -234,7 +242,7 @@ Any SAL_CALL OContentHelper::execute( const Command& aCommand, sal_Int32 /*Comma OSL_FAIL( "Content::execute - unsupported command!" ); ucbhelper::cancelCommandExecution( - makeAny( UnsupportedCommandException( + Any( UnsupportedCommandException( OUString(), static_cast< cppu::OWeakObject * >( this ) ) ), Environment ); @@ -252,44 +260,32 @@ void SAL_CALL OContentHelper::abort( sal_Int32 /*CommandId*/ ) void SAL_CALL OContentHelper::addPropertiesChangeListener( const Sequence< OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener ) { ::osl::MutexGuard aGuard(m_aMutex); - sal_Int32 nCount = PropertyNames.getLength(); - if ( !nCount ) + if (!PropertyNames.hasElements()) { // Note: An empty sequence means a listener for "all" properties. m_aPropertyChangeListeners.addInterface(OUString(), Listener ); } else { - const OUString* pSeq = PropertyNames.getConstArray(); - - for ( sal_Int32 n = 0; n < nCount; ++n ) - { - const OUString& rName = pSeq[ n ]; + for (auto& rName : PropertyNames) if ( !rName.isEmpty() ) m_aPropertyChangeListeners.addInterface(rName, Listener ); - } } } void SAL_CALL OContentHelper::removePropertiesChangeListener( const Sequence< OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener ) { ::osl::MutexGuard aGuard(m_aMutex); - sal_Int32 nCount = PropertyNames.getLength(); - if ( !nCount ) + if (!PropertyNames.hasElements()) { // Note: An empty sequence means a listener for "all" properties. m_aPropertyChangeListeners.removeInterface( OUString(), Listener ); } else { - const OUString* pSeq = PropertyNames.getConstArray(); - - for ( sal_Int32 n = 0; n < nCount; ++n ) - { - const OUString& rName = pSeq[ n ]; + for (auto& rName : PropertyNames) if ( !rName.isEmpty() ) m_aPropertyChangeListeners.removeInterface( rName, Listener ); - } } } @@ -307,12 +303,10 @@ void SAL_CALL OContentHelper::removeProperty( const OUString& /*Name*/ ) // XInitialization void SAL_CALL OContentHelper::initialize( const Sequence< Any >& _aArguments ) { - const Any* pBegin = _aArguments.getConstArray(); - const Any* pEnd = pBegin + _aArguments.getLength(); - PropertyValue aValue; - for(;pBegin != pEnd;++pBegin) + for (auto& arg : _aArguments) { - *pBegin >>= aValue; + PropertyValue aValue; + arg >>= aValue; if ( aValue.Name == "Parent" ) { m_xParentContainer.set(aValue.Value,UNO_QUERY); @@ -333,6 +327,7 @@ Sequence< Any > OContentHelper::setPropertyValues(const Sequence< PropertyValue osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); Sequence< Any > aRet( rValues.getLength() ); + auto aRetRange = asNonConstRange(aRet); Sequence< PropertyChangeEvent > aChanges( rValues.getLength() ); sal_Int32 nChanged = 0; @@ -341,17 +336,14 @@ Sequence< Any > OContentHelper::setPropertyValues(const Sequence< PropertyValue aEvent.Further = false; aEvent.PropertyHandle = -1; - const PropertyValue* pValues = rValues.getConstArray(); - sal_Int32 nCount = rValues.getLength(); - - for ( sal_Int32 n = 0; n < nCount; ++n ) + for (sal_Int32 n = 0; n < rValues.getLength(); ++n) { - const PropertyValue& rValue = pValues[ n ]; + const PropertyValue& rValue = rValues[n]; if ( rValue.Name == "ContentType" || rValue.Name == "IsDocument" || rValue.Name == "IsFolder" ) { // Read-only property! - aRet[ n ] <<= IllegalAccessException("Property is read-only!", + aRetRange[ n ] <<= IllegalAccessException("Property is read-only!", static_cast< cppu::OWeakObject * >( this ) ); } else if ( rValue.Name == "Title" ) @@ -385,14 +377,14 @@ Sequence< Any > OContentHelper::setPropertyValues(const Sequence< PropertyValue } else { - aRet[ n ] <<= IllegalTypeException("Property value has wrong type!", + aRetRange[ n ] <<= IllegalTypeException("Property value has wrong type!", static_cast< cppu::OWeakObject * >( this ) ); } } else { - aRet[ n ] <<= Exception("No property set for storing the value!", + aRetRange[ n ] <<= Exception("No property set for storing the value!", static_cast< cppu::OWeakObject * >( this ) ); } } @@ -415,14 +407,10 @@ Reference< XRow > OContentHelper::getPropertyValues( const Sequence< Property >& rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( m_aContext ); - sal_Int32 nCount = rProperties.getLength(); - if ( nCount ) + if (rProperties.hasElements()) { - const Property* pProps = rProperties.getConstArray(); - for ( sal_Int32 n = 0; n < nCount; ++n ) + for (auto& rProp : rProperties) { - const Property& rProp = pProps[ n ]; - // Process Core properties. if ( rProp.Name == "ContentType" ) @@ -475,7 +463,7 @@ Reference< XRow > OContentHelper::getPropertyValues( const Sequence< Property >& // @@@ Append other properties supported directly. } - return Reference< XRow >( xRow.get() ); + return xRow; } void OContentHelper::notifyPropertiesChange( const Sequence< PropertyChangeEvent >& evt ) const @@ -486,38 +474,27 @@ void OContentHelper::notifyPropertiesChange( const Sequence< PropertyChangeEvent return; // First, notify listeners interested in changes of every property. - OInterfaceContainerHelper* pAllPropsContainer = m_aPropertyChangeListeners.getContainer( OUString() ); + comphelper::OInterfaceContainerHelper3<XPropertiesChangeListener>* pAllPropsContainer = m_aPropertyChangeListeners.getContainer( OUString() ); if ( pAllPropsContainer ) - { - OInterfaceIteratorHelper aIter( *pAllPropsContainer ); - while ( aIter.hasMoreElements() ) - { - // Propagate event. - Reference< XPropertiesChangeListener > xListener( aIter.next(), UNO_QUERY ); - if ( xListener.is() ) - xListener->propertiesChange( evt ); - } - } + pAllPropsContainer->notifyEach( &XPropertiesChangeListener::propertiesChange, evt ); typedef std::map< XPropertiesChangeListener*, Sequence< PropertyChangeEvent > > PropertiesEventListenerMap; PropertiesEventListenerMap aListeners; - const PropertyChangeEvent* propertyChangeEvent = evt.getConstArray(); - - for ( sal_Int32 n = 0; n < nCount; ++n, ++propertyChangeEvent ) + for (sal_Int32 n = 0; n < nCount; ++n) { - const PropertyChangeEvent& rEvent = *propertyChangeEvent; + const PropertyChangeEvent& rEvent = evt[n]; const OUString& rName = rEvent.PropertyName; - OInterfaceContainerHelper* pPropsContainer = m_aPropertyChangeListeners.getContainer( rName ); + comphelper::OInterfaceContainerHelper3<XPropertiesChangeListener>* pPropsContainer = m_aPropertyChangeListeners.getContainer( rName ); if ( pPropsContainer ) { - OInterfaceIteratorHelper aIter( *pPropsContainer ); + comphelper::OInterfaceIteratorHelper3 aIter( *pPropsContainer ); while ( aIter.hasMoreElements() ) { Sequence< PropertyChangeEvent >* propertyEvents; - XPropertiesChangeListener* pListener = static_cast< XPropertiesChangeListener * >( aIter.next() ); + XPropertiesChangeListener* pListener = aIter.next().get(); PropertiesEventListenerMap::iterator it = aListeners.find( pListener ); if ( it == aListeners.end() ) { @@ -528,7 +505,7 @@ void OContentHelper::notifyPropertiesChange( const Sequence< PropertyChangeEvent else propertyEvents = &(*it).second; - (*propertyEvents)[n] = rEvent; + asNonConstRange(*propertyEvents)[n] = rEvent; } } } @@ -544,15 +521,6 @@ void OContentHelper::notifyPropertiesChange( const Sequence< PropertyChangeEvent } } -// css::lang::XUnoTunnel -sal_Int64 OContentHelper::getSomething( const Sequence< sal_Int8 > & rId ) -{ - if (isUnoTunnelId<OContentHelper>(rId)) - return reinterpret_cast<sal_Int64>(this); - - return 0; -} - Reference< XInterface > SAL_CALL OContentHelper::getParent( ) { ::osl::MutexGuard aGuard(m_aMutex); @@ -572,14 +540,14 @@ void OContentHelper::impl_rename_throw(const OUString& _sNewName,bool _bNotify ) return; try { - Sequence< PropertyChangeEvent > aChanges( 1 ); - - aChanges[0].Source = static_cast< cppu::OWeakObject * >( this ); - aChanges[0].Further = false; - aChanges[0].PropertyName = PROPERTY_NAME; - aChanges[0].PropertyHandle = PROPERTY_ID_NAME; - aChanges[0].OldValue <<= m_pImpl->m_aProps.aTitle; - aChanges[0].NewValue <<= _sNewName; + Sequence<PropertyChangeEvent> aChanges{ + { /* Source */ static_cast<cppu::OWeakObject*>(this), + /* PropertyName */ PROPERTY_NAME, + /* Further */ false, + /* PropertyHandle */ PROPERTY_ID_NAME, + /* OldValue */ Any(m_pImpl->m_aProps.aTitle), + /* NewValue */ Any(_sNewName) } + }; aGuard.clear(); diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index c24e2376e41a..8067ef32e30a 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -48,7 +48,7 @@ #include <comphelper/processfactory.hxx> #include <sfx2/docfile.hxx> #include <sfx2/signaturestate.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/file.hxx> #include <osl/diagnose.h> #include <sal/log.hxx> @@ -58,11 +58,11 @@ #include <i18nlangtag/languagetag.hxx> #include <algorithm> +#include <utility> using namespace css; using namespace ::com::sun::star::document; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; @@ -71,9 +71,7 @@ using namespace ::com::sun::star::embed; using namespace ::com::sun::star::container; using namespace ::com::sun::star::util; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::ucb; using namespace ::com::sun::star::frame; -using namespace ::com::sun::star::view; using namespace ::com::sun::star::task; using namespace ::com::sun::star::script; using namespace ::cppu; @@ -353,14 +351,11 @@ void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& So // ODatabaseModelImpl ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _rxContext, ODatabaseContext& _rDBContext ) - :m_xModel() - ,m_xDataSource() - ,m_aContainer(4) + :m_aContainer() ,m_aMacroMode( *this ) ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE ) ,m_rDBContext( _rDBContext ) ,m_refCount(0) - ,m_aEmbeddedMacros() ,m_bModificationLock( false ) ,m_bDocumentInitialized( false ) ,m_nScriptingSignatureState(SignatureState::UNKNOWN) @@ -372,34 +367,29 @@ ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _r ,m_bModified(false) ,m_bDocumentReadOnly(false) ,m_bMacroCallsSeenWhileLoading(false) - ,m_pSharedConnectionManager(nullptr) ,m_nControllerLockCount(0) { // some kind of default m_sConnectURL = "jdbc:"; - m_aTableFilter.realloc(1); - m_aTableFilter[0] = "%"; + m_aTableFilter = { "%" }; impl_construct_nothrow(); } ODatabaseModelImpl::ODatabaseModelImpl( - const OUString& _rRegistrationName, + OUString _sRegistrationName, const Reference< XComponentContext >& _rxContext, ODatabaseContext& _rDBContext ) - :m_xModel() - ,m_xDataSource() - ,m_aContainer(4) + :m_aContainer() ,m_aMacroMode( *this ) ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE ) ,m_rDBContext( _rDBContext ) ,m_refCount(0) - ,m_aEmbeddedMacros() ,m_bModificationLock( false ) ,m_bDocumentInitialized( false ) ,m_nScriptingSignatureState(SignatureState::UNKNOWN) ,m_aContext( _rxContext ) - ,m_sName(_rRegistrationName) + ,m_sName(std::move(_sRegistrationName)) ,m_nLoginTimeout(0) ,m_bReadOnly(false) ,m_bPasswordRequired(false) @@ -407,7 +397,6 @@ ODatabaseModelImpl::ODatabaseModelImpl( ,m_bModified(false) ,m_bDocumentReadOnly(false) ,m_bMacroCallsSeenWhileLoading(false) - ,m_pSharedConnectionManager(nullptr) ,m_nControllerLockCount(0) { impl_construct_nothrow(); @@ -437,25 +426,22 @@ void ODatabaseModelImpl::impl_construct_nothrow() // insert the default settings Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW ); Reference< XSet > xSettingsSet( m_xSettings, UNO_QUERY_THROW ); - const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings(); - for ( ; pSettings->AsciiName; ++pSettings ) + for (auto& setting : getDefaultDataSourceSettings()) { - if ( !pSettings->DefaultValue.hasValue() ) + if (!setting.DefaultValue.hasValue()) { - Property aProperty( - OUString::createFromAscii( pSettings->AsciiName ), + Property aProperty(setting.Name, -1, - pSettings->ValueType, + setting.ValueType, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID ); - xSettingsSet->insert( makeAny( aProperty ) ); + xSettingsSet->insert( Any( aProperty ) ); } else { - xContainer->addProperty( - OUString::createFromAscii( pSettings->AsciiName ), + xContainer->addProperty(setting.Name, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT, - pSettings->DefaultValue + setting.DefaultValue ); } } @@ -474,10 +460,10 @@ namespace const char* pAsciiName( nullptr ); switch ( _eType ) { - case ODatabaseModelImpl::E_FORM: pAsciiName = "forms"; break; - case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break; - case ODatabaseModelImpl::E_QUERY: pAsciiName = "queries"; break; - case ODatabaseModelImpl::E_TABLE: pAsciiName = "tables"; break; + case ODatabaseModelImpl::ObjectType::Form: pAsciiName = "forms"; break; + case ODatabaseModelImpl::ObjectType::Report: pAsciiName = "reports"; break; + case ODatabaseModelImpl::ObjectType::Query: pAsciiName = "queries"; break; + case ODatabaseModelImpl::ObjectType::Table: pAsciiName = "tables"; break; default: throw RuntimeException(); } @@ -567,8 +553,8 @@ bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContai void ODatabaseModelImpl::reset() { m_bReadOnly = false; - std::vector< TContentPtr > aEmptyContainers( 4 ); - m_aContainer.swap( aEmptyContainers ); + for (auto & i : m_aContainer) + i.reset(); if ( m_pStorageAccess.is() ) { @@ -630,7 +616,6 @@ void ODatabaseModelImpl::clearConnections() } } - m_pSharedConnectionManager = nullptr; m_xSharedConnectionManager = nullptr; } @@ -657,7 +642,8 @@ void ODatabaseModelImpl::dispose() if ( elem ) elem->m_pDataSource = nullptr; } - m_aContainer.clear(); + for (auto & i : m_aContainer) + i.reset(); clearConnections(); @@ -773,9 +759,7 @@ Reference< XStorage > const & ODatabaseModelImpl::getOrCreateRootStorage() if ( aSource.hasValue() ) { - Sequence< Any > aStorageCreationArgs(2); - aStorageCreationArgs[0] = aSource; - aStorageCreationArgs[1] <<= ElementModes::READWRITE; + Sequence< Any > aStorageCreationArgs{ aSource, Any(ElementModes::READWRITE) }; Reference< XStorage > xDocumentStorage; OUString sURL; @@ -790,7 +774,7 @@ Reference< XStorage > const & ODatabaseModelImpl::getOrCreateRootStorage() catch( const Exception& ) { m_bDocumentReadOnly = true; - aStorageCreationArgs[1] <<= ElementModes::READ; + aStorageCreationArgs.getArray()[1] <<= ElementModes::READ; try { xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW ); @@ -843,7 +827,7 @@ bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits ) bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) { bool bTryToPreserveScriptSignature = false; - utl::TempFile aTempFile; + utl::TempFileNamed aTempFile; aTempFile.EnableKillingFile(); OUString sTmpFileUrl = aTempFile.GetURL(); SignatureState aSignatureState = getScriptingSignatureState(); @@ -897,7 +881,7 @@ bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< uno::Reference<embed::XStorage> xTargetMetaInf = _rxStorage->openStorageElement("META-INF", embed::ElementModes::READWRITE); - if (xMetaInf.is() && xTargetMetaInf.is()) + if (xMetaInf.is() && xTargetMetaInf.is() && xMetaInf->hasByName(aScriptSignName)) { xMetaInf->copyElementTo(aScriptSignName, xTargetMetaInf, aScriptSignName); @@ -986,7 +970,7 @@ Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership() try { Reference< XGlobalEventBroadcaster > xModelCollection = theGlobalEventBroadcaster::get( m_aContext ); - xModelCollection->insert( makeAny( xModel ) ); + xModelCollection->insert( Any( xModel ) ); } catch( const Exception& ) { @@ -1037,82 +1021,80 @@ Reference< XStorage > ODatabaseModelImpl::getStorage( const ObjectType _eType ) css::embed::ElementModes::READWRITE ); } -const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings() +// static +std::span<const DefaultPropertyValue> ODatabaseModelImpl::getDefaultDataSourceSettings() { - static const AsciiPropertyValue aKnownSettings[] = + static const DefaultPropertyValue aKnownSettings[] = { // known JDBC settings - AsciiPropertyValue( "JavaDriverClass", makeAny( OUString() ) ), - AsciiPropertyValue( "JavaDriverClassPath", makeAny( OUString() ) ), - AsciiPropertyValue( "IgnoreCurrency", makeAny( false ) ), + { u"JavaDriverClass"_ustr, Any( OUString() ) }, + { u"JavaDriverClassPath"_ustr, Any( OUString() ) }, + { u"IgnoreCurrency"_ustr, Any( false ) }, // known settings for file-based drivers - AsciiPropertyValue( "Extension", makeAny( OUString() ) ), - AsciiPropertyValue( "CharSet", makeAny( OUString() ) ), - AsciiPropertyValue( "HeaderLine", makeAny( true ) ), - AsciiPropertyValue( "FieldDelimiter", makeAny( OUString( "," ) ) ), - AsciiPropertyValue( "StringDelimiter", makeAny( OUString( "\"" ) ) ), - AsciiPropertyValue( "DecimalDelimiter", makeAny( OUString( "." ) ) ), - AsciiPropertyValue( "ThousandDelimiter", makeAny( OUString() ) ), - AsciiPropertyValue( "ShowDeleted", makeAny( false ) ), + { u"Extension"_ustr, Any( OUString() ) }, + { u"CharSet"_ustr, Any( OUString() ) }, + { u"HeaderLine"_ustr, Any( true ) }, + { u"FieldDelimiter"_ustr, Any( OUString( "," ) ) }, + { u"StringDelimiter"_ustr, Any( OUString( "\"" ) ) }, + { u"DecimalDelimiter"_ustr, Any( OUString( "." ) ) }, + { u"ThousandDelimiter"_ustr, Any( OUString() ) }, + { u"ShowDeleted"_ustr, Any( false ) }, // known ODBC settings - AsciiPropertyValue( "SystemDriverSettings", makeAny( OUString() ) ), - AsciiPropertyValue( "UseCatalog", makeAny( false ) ), - AsciiPropertyValue( "TypeInfoSettings", makeAny( Sequence< Any >()) ), + { u"SystemDriverSettings"_ustr, Any( OUString() ) }, + { u"UseCatalog"_ustr, Any( false ) }, + { u"TypeInfoSettings"_ustr, Any( Sequence< Any >()) }, // settings related to auto increment handling - AsciiPropertyValue( "AutoIncrementCreation", makeAny( OUString() ) ), - AsciiPropertyValue( "AutoRetrievingStatement", makeAny( OUString() ) ), - AsciiPropertyValue( "IsAutoRetrievingEnabled", makeAny( false ) ), + { u"AutoIncrementCreation"_ustr, Any( OUString() ) }, + { u"AutoRetrievingStatement"_ustr, Any( OUString() ) }, + { u"IsAutoRetrievingEnabled"_ustr, Any( false ) }, // known LDAP driver settings - AsciiPropertyValue( "HostName", makeAny( OUString() ) ), - AsciiPropertyValue( "PortNumber", makeAny( sal_Int32(389) ) ), - AsciiPropertyValue( "BaseDN", makeAny( OUString() ) ), - AsciiPropertyValue( "MaxRowCount", makeAny( sal_Int32(100) ) ), + { u"HostName"_ustr, Any( OUString() ) }, + { u"PortNumber"_ustr, Any( sal_Int32(389) ) }, + { u"BaseDN"_ustr, Any( OUString() ) }, + { u"MaxRowCount"_ustr, Any( sal_Int32(100) ) }, // known MySQLNative driver settings - AsciiPropertyValue( "LocalSocket", makeAny( OUString() ) ), - AsciiPropertyValue( "NamedPipe", makeAny( OUString() ) ), + { u"LocalSocket"_ustr, Any( OUString() ) }, + { u"NamedPipe"_ustr, Any( OUString() ) }, // misc known driver settings - AsciiPropertyValue( "ParameterNameSubstitution", makeAny( false ) ), - AsciiPropertyValue( "AddIndexAppendix", makeAny( true ) ), - AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( true ) ), - AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< OUString >::get() ), - AsciiPropertyValue( "ImplicitSchemaRestriction", ::cppu::UnoType< OUString >::get() ), - AsciiPropertyValue( "PrimaryKeySupport", ::cppu::UnoType< sal_Bool >::get() ), - AsciiPropertyValue( "ShowColumnDescription", makeAny( false ) ), + { u"ParameterNameSubstitution"_ustr, Any( false ) }, + { u"AddIndexAppendix"_ustr, Any( true ) }, + { u"IgnoreDriverPrivileges"_ustr, Any( true ) }, + { u"ImplicitCatalogRestriction"_ustr, ::cppu::UnoType< OUString >::get() }, + { u"ImplicitSchemaRestriction"_ustr, ::cppu::UnoType< OUString >::get() }, + { u"PrimaryKeySupport"_ustr, ::cppu::UnoType< sal_Bool >::get() }, + { u"ShowColumnDescription"_ustr, Any( false ) }, // known SDB level settings - AsciiPropertyValue( "NoNameLengthLimit", makeAny( false ) ), - AsciiPropertyValue( "AppendTableAliasName", makeAny( false ) ), - AsciiPropertyValue( "GenerateASBeforeCorrelationName", makeAny( false ) ), - AsciiPropertyValue( "ColumnAliasInOrderBy", makeAny( true ) ), - AsciiPropertyValue( "EnableSQL92Check", makeAny( false ) ), - AsciiPropertyValue( "BooleanComparisonMode", makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ), - AsciiPropertyValue( "TableTypeFilterMode", makeAny( sal_Int32(3) ) ), - AsciiPropertyValue( "RespectDriverResultSetType", makeAny( false ) ), - AsciiPropertyValue( "UseSchemaInSelect", makeAny( true ) ), - AsciiPropertyValue( "UseCatalogInSelect", makeAny( true ) ), - AsciiPropertyValue( "EnableOuterJoinEscape", makeAny( true ) ), - AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( false ) ), - AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( true ) ), - AsciiPropertyValue( "EscapeDateTime", makeAny( true ) ), + { u"NoNameLengthLimit"_ustr, Any( false ) }, + { u"AppendTableAliasName"_ustr, Any( false ) }, + { u"GenerateASBeforeCorrelationName"_ustr, Any( false ) }, + { u"ColumnAliasInOrderBy"_ustr, Any( true ) }, + { u"EnableSQL92Check"_ustr, Any( false ) }, + { u"BooleanComparisonMode"_ustr, Any( BooleanComparisonMode::EQUAL_INTEGER ) }, + { u"TableTypeFilterMode"_ustr, Any( sal_Int32(3) ) }, + { u"RespectDriverResultSetType"_ustr, Any( false ) }, + { u"UseSchemaInSelect"_ustr, Any( true ) }, + { u"UseCatalogInSelect"_ustr, Any( true ) }, + { u"EnableOuterJoinEscape"_ustr, Any( true ) }, + { u"PreferDosLikeLineEnds"_ustr, Any( false ) }, + { u"FormsCheckRequiredFields"_ustr, Any( true ) }, + { u"EscapeDateTime"_ustr, Any( true ) }, // known services to handle database tasks - AsciiPropertyValue( "TableAlterationServiceName", makeAny( OUString() ) ), - AsciiPropertyValue( "TableRenameServiceName", makeAny( OUString() ) ), - AsciiPropertyValue( "ViewAlterationServiceName", makeAny( OUString() ) ), - AsciiPropertyValue( "ViewAccessServiceName", makeAny( OUString() ) ), - AsciiPropertyValue( "CommandDefinitions", makeAny( OUString() ) ), - AsciiPropertyValue( "Forms", makeAny( OUString() ) ), - AsciiPropertyValue( "Reports", makeAny( OUString() ) ), - AsciiPropertyValue( "KeyAlterationServiceName", makeAny( OUString() ) ), - AsciiPropertyValue( "IndexAlterationServiceName", makeAny( OUString() ) ), - - AsciiPropertyValue() + { u"TableAlterationServiceName"_ustr, Any( OUString() ) }, + { u"TableRenameServiceName"_ustr, Any( OUString() ) }, + { u"ViewAlterationServiceName"_ustr, Any( OUString() ) }, + { u"ViewAccessServiceName"_ustr, Any( OUString() ) }, + { u"CommandDefinitions"_ustr, Any( OUString() ) }, + { u"Forms"_ustr, Any( OUString() ) }, + { u"Reports"_ustr, Any( OUString() ) }, + { u"KeyAlterationServiceName"_ustr, Any( OUString() ) }, + { u"IndexAlterationServiceName"_ustr, Any( OUString() ) }, }; return aKnownSettings; } TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType ) { - OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" ); TContentPtr& rContentPtr = m_aContainer[ _eType ]; if ( !rContentPtr ) @@ -1133,7 +1115,8 @@ bool ODatabaseModelImpl::checkMacrosOnLoading() { Reference< XInteractionHandler > xInteraction; xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction ); - return m_aMacroMode.checkMacrosOnLoading( xInteraction ); + const bool bHasMacros = m_aMacroMode.hasMacros(); + return m_aMacroMode.checkMacrosOnLoading(xInteraction, false /*HasValidContentSignature*/, bHasMacros); } void ODatabaseModelImpl::resetMacroExecutionMode() @@ -1204,7 +1187,7 @@ namespace if ( xModify.is() && !_bListen && _inout_rListener.is() ) { - xModify->removeModifyListener( _inout_rListener.get() ); + xModify->removeModifyListener( _inout_rListener ); } if ( _inout_rListener.is() ) @@ -1216,7 +1199,7 @@ namespace if ( xModify.is() && _bListen ) { _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex ); - xModify->addModifyListener( _inout_rListener.get() ); + xModify->addModifyListener( _inout_rListener ); } } } @@ -1331,17 +1314,17 @@ ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros() { if ( ::sfx2::DocumentMacroMode::storageHasMacros( getOrCreateRootStorage() ) ) { - m_aEmbeddedMacros = eDocumentWideMacros; + m_aEmbeddedMacros = EmbeddedMacros::DocumentWide; } - else if ( lcl_hasObjectsWithMacros_nothrow( *this, E_FORM ) - || lcl_hasObjectsWithMacros_nothrow( *this, E_REPORT ) + else if ( lcl_hasObjectsWithMacros_nothrow( *this, ObjectType::Form ) + || lcl_hasObjectsWithMacros_nothrow( *this, ObjectType::Report ) ) { - m_aEmbeddedMacros = eSubDocumentMacros; + m_aEmbeddedMacros = EmbeddedMacros::SubDocument; } else { - m_aEmbeddedMacros = eNoMacros; + m_aEmbeddedMacros = EmbeddedMacros::NONE; } } return *m_aEmbeddedMacros; @@ -1350,7 +1333,7 @@ ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros() bool ODatabaseModelImpl::documentStorageHasMacros() const { const_cast< ODatabaseModelImpl* >( this )->determineEmbeddedMacros(); - return ( *m_aEmbeddedMacros != eNoMacros ); + return ( *m_aEmbeddedMacros != EmbeddedMacros::NONE ); } bool ODatabaseModelImpl::macroCallsSeenWhileLoading() const @@ -1368,7 +1351,8 @@ SignatureState ODatabaseModelImpl::getScriptingSignatureState() return m_nScriptingSignatureState; } -bool ODatabaseModelImpl::hasTrustedScriptingSignature(bool bAllowUIToAddAuthor) +bool ODatabaseModelImpl::hasTrustedScriptingSignature( + const css::uno::Reference<css::task::XInteractionHandler>& _rxInteraction) { bool bResult = false; @@ -1383,7 +1367,7 @@ bool ODatabaseModelImpl::hasTrustedScriptingSignature(bool bAllowUIToAddAuthor) uno::Reference<security::XDocumentDigitalSignatures> xSigner( security::DocumentDigitalSignatures::createWithVersion( comphelper::getProcessComponentContext(), aODFVersion)); - uno::Sequence<security::DocumentSignatureInformation> aInfo + const uno::Sequence<security::DocumentSignatureInformation> aInfo = xSigner->verifyScriptingContentSignatures(xStorage, uno::Reference<io::XInputStream>()); @@ -1400,20 +1384,15 @@ bool ODatabaseModelImpl::hasTrustedScriptingSignature(bool bAllowUIToAddAuthor) }); } - if (!bResult && bAllowUIToAddAuthor) + if (!bResult && _rxInteraction) { - Reference<XInteractionHandler> xInteraction; - xInteraction = m_aMediaDescriptor.getOrDefault("InteractionHandler", xInteraction); - if (xInteraction.is()) - { - task::DocumentMacroConfirmationRequest aRequest; - aRequest.DocumentURL = m_sDocFileLocation; - aRequest.DocumentStorage = xStorage; - aRequest.DocumentSignatureInformation = aInfo; - aRequest.DocumentVersion = aODFVersion; - aRequest.Classification = task::InteractionClassification_QUERY; - bResult = SfxMedium::CallApproveHandler(xInteraction, uno::makeAny(aRequest), true); - } + task::DocumentMacroConfirmationRequest aRequest; + aRequest.DocumentURL = m_sDocFileLocation; + aRequest.DocumentStorage = xStorage; + aRequest.DocumentSignatureInformation = aInfo; + aRequest.DocumentVersion = aODFVersion; + aRequest.Classification = task::InteractionClassification_QUERY; + bResult = SfxMedium::CallApproveHandler(_rxInteraction, uno::Any(aRequest), true); } } catch (uno::Exception&) @@ -1428,8 +1407,8 @@ void ODatabaseModelImpl::storageIsModified() setModified( true ); } -ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model ) - :m_pImpl( _model ) +ModelDependentComponent::ModelDependentComponent( ::rtl::Reference< ODatabaseModelImpl > _model ) + :m_pImpl(std::move( _model )) { } diff --git a/dbaccess/source/core/dataaccess/SharedConnection.cxx b/dbaccess/source/core/dataaccess/SharedConnection.cxx index 31a8e68ba7b1..d893a8e298b3 100644 --- a/dbaccess/source/core/dataaccess/SharedConnection.cxx +++ b/dbaccess/source/core/dataaccess/SharedConnection.cxx @@ -38,8 +38,8 @@ OSharedConnection::~OSharedConnection() {} void SAL_CALL OSharedConnection::disposing() { - OSharedConnection_BASE::disposing(); OConnectionWrapper::disposing(); + OSharedConnection_BASE::disposing(); } Reference<XStatement> SAL_CALL OSharedConnection::createStatement() diff --git a/dbaccess/source/core/dataaccess/SharedConnection.hxx b/dbaccess/source/core/dataaccess/SharedConnection.hxx index c0ced3f1ca40..2c88e58fd55d 100644 --- a/dbaccess/source/core/dataaccess/SharedConnection.hxx +++ b/dbaccess/source/core/dataaccess/SharedConnection.hxx @@ -34,11 +34,10 @@ namespace dbaccess // datasource is asked for not isolated connection. typedef ::cppu::WeakComponentImplHelper< css::sdbc::XConnection > OSharedConnection_BASE; - typedef ::connectivity::OConnectionWrapper OSharedConnection_BASE2; class OSharedConnection : public ::cppu::BaseMutex , public OSharedConnection_BASE - , public OSharedConnection_BASE2 + , public ::connectivity::OConnectionWrapper { protected: virtual void SAL_CALL disposing() override; @@ -48,13 +47,13 @@ namespace dbaccess virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; - virtual void SAL_CALL acquire() throw() override { OSharedConnection_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { OSharedConnection_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { OSharedConnection_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { OSharedConnection_BASE::release(); } virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override { return ::comphelper::concatSequences( OSharedConnection_BASE::getTypes(), - OSharedConnection_BASE2::getTypes() + ::connectivity::OConnectionWrapper::getTypes() ); } @@ -62,7 +61,7 @@ namespace dbaccess { css::uno::Any aReturn = OSharedConnection_BASE::queryInterface(_rType); if ( !aReturn.hasValue() ) - aReturn = OSharedConnection_BASE2::queryInterface(_rType); + aReturn = ::connectivity::OConnectionWrapper::queryInterface(_rType); return aReturn; } diff --git a/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx b/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx index 647aaf557f97..a03caea57e93 100644 --- a/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx +++ b/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx @@ -19,6 +19,7 @@ #include <bookmarkcontainer.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <comphelper/enumhelper.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> @@ -45,12 +46,12 @@ OBookmarkContainer::OBookmarkContainer(OWeakObject& _rParent, Mutex& _rMutex) } -void SAL_CALL OBookmarkContainer::acquire( ) throw() +void SAL_CALL OBookmarkContainer::acquire( ) noexcept { m_rParent.acquire(); } -void SAL_CALL OBookmarkContainer::release( ) throw() +void SAL_CALL OBookmarkContainer::release( ) noexcept { m_rParent.release(); } @@ -96,10 +97,8 @@ void SAL_CALL OBookmarkContainer::insertByName( const OUString& _rName, const An // notify the listeners if (m_aContainerListeners.getLength()) { - ContainerEvent aEvent(*this, makeAny(_rName), makeAny(sNewLink), Any()); - OInterfaceIteratorHelper2 aListenerIterator(m_aContainerListeners); - while (aListenerIterator.hasMoreElements()) - static_cast< XContainerListener* >(aListenerIterator.next())->elementInserted(aEvent); + ContainerEvent aEvent(*this, Any(_rName), Any(sNewLink), Any()); + m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); } } @@ -126,10 +125,8 @@ void SAL_CALL OBookmarkContainer::removeByName( const OUString& _rName ) // notify the listeners if (m_aContainerListeners.getLength()) { - ContainerEvent aEvent(*this, makeAny(_rName), makeAny(sOldBookmark), Any()); - OInterfaceIteratorHelper2 aListenerIterator(m_aContainerListeners); - while (aListenerIterator.hasMoreElements()) - static_cast< XContainerListener* >(aListenerIterator.next())->elementRemoved(aEvent); + ContainerEvent aEvent(*this, Any(_rName), Any(sOldBookmark), Any()); + m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent ); } } @@ -161,10 +158,8 @@ void SAL_CALL OBookmarkContainer::replaceByName( const OUString& _rName, const A aGuard.clear(); if (m_aContainerListeners.getLength()) { - ContainerEvent aEvent(*this, makeAny(_rName), makeAny(sNewLink), makeAny(sOldLink)); - OInterfaceIteratorHelper2 aListenerIterator(m_aContainerListeners); - while (aListenerIterator.hasMoreElements()) - static_cast< XContainerListener* >(aListenerIterator.next())->elementReplaced(aEvent); + ContainerEvent aEvent(*this, Any(_rName), Any(sNewLink), Any(sOldLink)); + m_aContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent ); } } @@ -185,7 +180,6 @@ void SAL_CALL OBookmarkContainer::removeContainerListener( const Reference< XCon // XElementAccess Type SAL_CALL OBookmarkContainer::getElementType( ) { - MutexGuard aGuard(m_rMutex); return ::cppu::UnoType<OUString>::get(); } @@ -213,10 +207,10 @@ Any SAL_CALL OBookmarkContainer::getByIndex( sal_Int32 _nIndex ) { MutexGuard aGuard(m_rMutex); - if ((_nIndex < 0) || (_nIndex >= static_cast<sal_Int32>(m_aBookmarksIndexed.size()))) + if ((_nIndex < 0) || (o3tl::make_unsigned(_nIndex) >= m_aBookmarksIndexed.size())) throw IndexOutOfBoundsException(); - return makeAny(m_aBookmarksIndexed[_nIndex]->second); + return Any(m_aBookmarksIndexed[_nIndex]->second); } Any SAL_CALL OBookmarkContainer::getByName( const OUString& _rName ) @@ -226,7 +220,7 @@ Any SAL_CALL OBookmarkContainer::getByName( const OUString& _rName ) if (!checkExistence(_rName)) throw NoSuchElementException(); - return makeAny(m_aBookmarks[_rName]); + return Any(m_aBookmarks[_rName]); } Sequence< OUString > SAL_CALL OBookmarkContainer::getElementNames( ) diff --git a/dbaccess/source/core/dataaccess/commandcontainer.cxx b/dbaccess/source/core/dataaccess/commandcontainer.cxx index 55087272b992..7f646c61722e 100644 --- a/dbaccess/source/core/dataaccess/commandcontainer.cxx +++ b/dbaccess/source/core/dataaccess/commandcontainer.cxx @@ -24,11 +24,7 @@ #include <com/sun/star/sdb/CommandDefinition.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::container; using namespace ::com::sun::star::ucb; -using namespace ::osl; using namespace ::comphelper; using namespace ::cppu; @@ -52,7 +48,13 @@ OCommandContainer::~OCommandContainer() } IMPLEMENT_FORWARD_XINTERFACE2( OCommandContainer,ODefinitionContainer,OCommandContainer_BASE) -IMPLEMENT_GETTYPES2(OCommandContainer,ODefinitionContainer,OCommandContainer_BASE); +css::uno::Sequence< css::uno::Type > OCommandContainer::getTypes() +{ + return ::comphelper::concatSequences( + ODefinitionContainer::getTypes( ), + OCommandContainer_BASE::getTypes( ) + ); +} css::uno::Sequence<sal_Int8> OCommandContainer::getImplementationId() { diff --git a/dbaccess/source/core/dataaccess/commanddefinition.cxx b/dbaccess/source/core/dataaccess/commanddefinition.cxx index 41ce139a8dc1..b3f4fa8b0ead 100644 --- a/dbaccess/source/core/dataaccess/commanddefinition.cxx +++ b/dbaccess/source/core/dataaccess/commanddefinition.cxx @@ -18,16 +18,14 @@ */ #include "commanddefinition.hxx" -#include <apitools.hxx> #include <stringconstants.hxx> +#include <strings.hxx> #include <com/sun/star/container/ElementExistException.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; @@ -81,9 +79,30 @@ css::uno::Sequence<sal_Int8> OCommandDefinition::getImplementationId() return css::uno::Sequence<sal_Int8>(); } -IMPLEMENT_GETTYPES2(OCommandDefinition,OCommandDefinition_Base,OComponentDefinition); +css::uno::Sequence< css::uno::Type > OCommandDefinition::getTypes() +{ + return ::comphelper::concatSequences( + OCommandDefinition_Base::getTypes( ), + OComponentDefinition::getTypes( ) + ); +} IMPLEMENT_FORWARD_XINTERFACE2( OCommandDefinition,OComponentDefinition,OCommandDefinition_Base) -IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2(OCommandDefinition,OCommandDefinition_PROP) +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OCommandDefinition::getPropertySetInfo() +{ + Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} +::cppu::IPropertyArrayHelper& OCommandDefinition::getInfoHelper() +{ + return *OCommandDefinition_PROP::getArrayHelper(); +} +::cppu::IPropertyArrayHelper* OCommandDefinition::createArrayHelper( ) const +{ + css::uno::Sequence< css::beans::Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} + OUString SAL_CALL OCommandDefinition::getImplementationName() { @@ -105,9 +124,9 @@ void SAL_CALL OCommandDefinition::rename( const OUString& newName ) { sal_Int32 nHandle = PROPERTY_ID_NAME; osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex); - Any aOld = makeAny(m_pImpl->m_aProps.aTitle); + Any aOld(m_pImpl->m_aProps.aTitle); aGuard.clear(); - Any aNew = makeAny(newName); + Any aNew(newName); fire(&nHandle, &aNew, &aOld, 1, true ); m_pImpl->m_aProps.aTitle = newName; diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx index 2754a2c7d56e..fa4c934a056e 100644 --- a/dbaccess/source/core/dataaccess/connection.cxx +++ b/dbaccess/source/core/dataaccess/connection.cxx @@ -24,6 +24,7 @@ #include "connection.hxx" #include "datasource.hxx" #include <strings.hrc> +#include <strings.hxx> #include <core_resource.hxx> #include <statement.hxx> #include <preparedstatement.hxx> @@ -38,7 +39,7 @@ #include <com/sun/star/beans/NamedValue.hpp> #include <connectivity/dbtools.hxx> #include <connectivity/dbmetadata.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <comphelper/sequence.hxx> #include <comphelper/types.hxx> @@ -46,7 +47,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::util; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdb::application; using namespace ::com::sun::star::sdbc; @@ -86,7 +86,7 @@ Sequence< OUString > OConnection::getSupportedServiceNames( ) { sal_Int32 nLen = aSupported.getLength(); aSupported.realloc( nLen + 1 ); - aSupported[ nLen ] = SERVICE_SDB_CONNECTION; + aSupported.getArray()[ nLen ] = SERVICE_SDB_CONNECTION; } return aSupported; @@ -274,7 +274,7 @@ OConnection::OConnection(ODatabaseSource& _rDB try { Reference< XProxyFactory > xProxyFactory = ProxyFactory::create( m_aContext ); - Reference<XAggregation> xAgg = xProxyFactory->createProxy(_rxMaster.get()); + Reference<XAggregation> xAgg = xProxyFactory->createProxy(_rxMaster); setDelegation(xAgg,m_refCount); OSL_ENSURE(m_xConnection.is(), "OConnection::OConnection : invalid master connection !"); } @@ -426,13 +426,13 @@ Any OConnection::queryInterface( const Type & rType ) return aReturn; } -void OConnection::acquire() throw () +void OConnection::acquire() noexcept { // include this one when you want to see who calls it (call graph) OSubComponent::acquire(); } -void OConnection::release() throw () +void OConnection::release() noexcept { // include this one when you want to see who calls it (call graph) OSubComponent::release(); @@ -628,9 +628,8 @@ Reference< XInterface > SAL_CALL OConnection::createInstance( const OUString& _s TSupportServices::const_iterator aFind = m_aSupportServices.find(_sServiceSpecifier); if ( aFind == m_aSupportServices.end() ) { - Sequence<Any> aArgs(1); Reference<XConnection> xMy(this); - aArgs[0] <<= NamedValue("ActiveConnection",makeAny(xMy)); + Sequence<Any> aArgs{ Any(NamedValue("ActiveConnection",Any(xMy))) }; aFind = m_aSupportServices.emplace( _sServiceSpecifier, m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceSpecifier, aArgs, m_aContext) @@ -750,7 +749,7 @@ void OConnection::impl_checkTableQueryNames_nothrow() try { Reference< XNameAccess > xTables( getTables() ); - Sequence< OUString > aTableNames( xTables->getElementNames() ); + const Sequence< OUString > aTableNames( xTables->getElementNames() ); std::set< OUString > aSortedTableNames( aTableNames.begin(), aTableNames.end() ); Reference< XNameAccess > xQueries( getQueries() ); diff --git a/dbaccess/source/core/dataaccess/connection.hxx b/dbaccess/source/core/dataaccess/connection.hxx index 93192d7988ff..4ecfa7d709dd 100644 --- a/dbaccess/source/core/dataaccess/connection.hxx +++ b/dbaccess/source/core/dataaccess/connection.hxx @@ -115,8 +115,8 @@ public: // css::uno::XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw( ) override; - virtual void SAL_CALL release() throw( ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // OComponentHelper virtual void SAL_CALL disposing() override; diff --git a/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx b/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx index d35d6ac00e55..ef5239a6793f 100644 --- a/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx +++ b/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx @@ -35,7 +35,6 @@ #include <comphelper/uno3.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> -#include <rtl/ref.hxx> namespace { @@ -112,48 +111,29 @@ namespace // </properties> }; -#define REGISTER_PROPERTY( propname, member ) \ - registerProperty( PROPERTY_##propname, PROPERTY_ID_##propname, PropertyAttribute::BOUND, &member, cppu::UnoType<decltype(member)>::get() ) - DataAccessDescriptor::DataAccessDescriptor() - :DataAccessDescriptor_MutexBase() - ,DataAccessDescriptor_TypeBase() - ,DataAccessDescriptor_PropertyBase( m_aBHelper ) - ,m_sDataSourceName() - ,m_sDatabaseLocation() - ,m_sConnectionResource() - ,m_aConnectionInfo() - ,m_xActiveConnection() - ,m_sCommand() + :DataAccessDescriptor_PropertyBase( m_aBHelper ) ,m_nCommandType( CommandType::COMMAND ) - ,m_sFilter() - ,m_sOrder() - ,m_sHavingClause() - ,m_sGroupBy() ,m_bEscapeProcessing( true ) - ,m_xResultSet() - ,m_aSelection() ,m_bBookmarkSelection( true ) - ,m_sColumnName() - ,m_xColumn() { - REGISTER_PROPERTY( DATASOURCENAME, m_sDataSourceName ); - REGISTER_PROPERTY( DATABASE_LOCATION, m_sDatabaseLocation ); - REGISTER_PROPERTY( CONNECTION_RESOURCE, m_sConnectionResource ); - REGISTER_PROPERTY( CONNECTION_INFO, m_aConnectionInfo ); - REGISTER_PROPERTY( ACTIVE_CONNECTION, m_xActiveConnection ); - REGISTER_PROPERTY( COMMAND, m_sCommand ); - REGISTER_PROPERTY( COMMAND_TYPE, m_nCommandType ); - REGISTER_PROPERTY( FILTER, m_sFilter ); - REGISTER_PROPERTY( ORDER, m_sOrder ); - REGISTER_PROPERTY( HAVING_CLAUSE, m_sHavingClause ); - REGISTER_PROPERTY( GROUP_BY, m_sGroupBy ); - REGISTER_PROPERTY( ESCAPE_PROCESSING, m_bEscapeProcessing ); - REGISTER_PROPERTY( RESULT_SET, m_xResultSet ); - REGISTER_PROPERTY( SELECTION, m_aSelection ); - REGISTER_PROPERTY( BOOKMARK_SELECTION, m_bBookmarkSelection ); - REGISTER_PROPERTY( COLUMN_NAME, m_sColumnName ); - REGISTER_PROPERTY( COLUMN, m_xColumn ); + registerProperty(PROPERTY_DATASOURCENAME, PROPERTY_ID_DATASOURCENAME, PropertyAttribute::BOUND, &m_sDataSourceName , cppu::UnoType<decltype(m_sDataSourceName )>::get()); + registerProperty(PROPERTY_DATABASE_LOCATION, PROPERTY_ID_DATABASE_LOCATION, PropertyAttribute::BOUND, &m_sDatabaseLocation , cppu::UnoType<decltype(m_sDatabaseLocation )>::get()); + registerProperty(PROPERTY_CONNECTION_RESOURCE, PROPERTY_ID_CONNECTION_RESOURCE, PropertyAttribute::BOUND, &m_sConnectionResource , cppu::UnoType<decltype(m_sConnectionResource )>::get()); + registerProperty(PROPERTY_CONNECTION_INFO, PROPERTY_ID_CONNECTION_INFO, PropertyAttribute::BOUND, &m_aConnectionInfo , cppu::UnoType<decltype(m_aConnectionInfo )>::get()); + registerProperty(PROPERTY_ACTIVE_CONNECTION, PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::BOUND, &m_xActiveConnection , cppu::UnoType<decltype(m_xActiveConnection )>::get()); + registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND, &m_sCommand , cppu::UnoType<decltype(m_sCommand )>::get()); + registerProperty(PROPERTY_COMMAND_TYPE, PROPERTY_ID_COMMAND_TYPE, PropertyAttribute::BOUND, &m_nCommandType , cppu::UnoType<decltype(m_nCommandType )>::get()); + registerProperty(PROPERTY_FILTER, PROPERTY_ID_FILTER, PropertyAttribute::BOUND, &m_sFilter , cppu::UnoType<decltype(m_sFilter )>::get()); + registerProperty(PROPERTY_ORDER, PROPERTY_ID_ORDER, PropertyAttribute::BOUND, &m_sOrder , cppu::UnoType<decltype(m_sOrder )>::get()); + registerProperty(PROPERTY_HAVING_CLAUSE, PROPERTY_ID_HAVING_CLAUSE, PropertyAttribute::BOUND, &m_sHavingClause , cppu::UnoType<decltype(m_sHavingClause )>::get()); + registerProperty(PROPERTY_GROUP_BY, PROPERTY_ID_GROUP_BY, PropertyAttribute::BOUND, &m_sGroupBy , cppu::UnoType<decltype(m_sGroupBy )>::get()); + registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND, &m_bEscapeProcessing , cppu::UnoType<decltype(m_bEscapeProcessing )>::get()); + registerProperty(PROPERTY_RESULT_SET, PROPERTY_ID_RESULT_SET, PropertyAttribute::BOUND, &m_xResultSet , cppu::UnoType<decltype(m_xResultSet )>::get()); + registerProperty(PROPERTY_SELECTION, PROPERTY_ID_SELECTION, PropertyAttribute::BOUND, &m_aSelection , cppu::UnoType<decltype(m_aSelection )>::get()); + registerProperty(PROPERTY_BOOKMARK_SELECTION, PROPERTY_ID_BOOKMARK_SELECTION, PropertyAttribute::BOUND, &m_bBookmarkSelection , cppu::UnoType<decltype(m_bBookmarkSelection )>::get()); + registerProperty(PROPERTY_COLUMN_NAME, PROPERTY_ID_COLUMN_NAME, PropertyAttribute::BOUND, &m_sColumnName , cppu::UnoType<decltype(m_sColumnName )>::get()); + registerProperty(PROPERTY_COLUMN, PROPERTY_ID_COLUMN, PropertyAttribute::BOUND, &m_xColumn , cppu::UnoType<decltype(m_xColumn )>::get()); } DataAccessDescriptor::~DataAccessDescriptor() @@ -236,18 +216,6 @@ namespace return new DataAccessDescriptor(); } -struct Instance { - explicit Instance(): - instance(new DataAccessDescriptorFactory()) - {} - - rtl::Reference<cppu::OWeakObject> instance; -}; - -struct Singleton: - public rtl::Static<Instance, Singleton> -{}; - } extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * @@ -255,7 +223,7 @@ com_sun_star_comp_dba_DataAccessDescriptorFactory( css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const &) { - return cppu::acquire(Singleton::get().instance.get()); + return cppu::acquire(new DataAccessDescriptorFactory()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx index b57cd9be52db..54c2ae37f356 100644 --- a/dbaccess/source/core/dataaccess/databasecontext.cxx +++ b/dbaccess/source/core/dataaccess/databasecontext.cxx @@ -20,6 +20,7 @@ #include <config_features.h> #include <strings.hrc> +#include <strings.hxx> #include <core_resource.hxx> #include <databasecontext.hxx> #include "databaseregistrations.hxx" @@ -52,13 +53,12 @@ #include <comphelper/servicehelper.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> -#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/weak.hxx> #include <rtl/uri.hxx> #include <sal/log.hxx> #include <svl/filenotation.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <tools/urlobj.hxx> #include <ucbhelper/content.hxx> #include <rtl/ref.hxx> @@ -74,7 +74,6 @@ using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; using namespace ::com::sun::star::util; -using namespace ::com::sun::star::registry; using namespace ::com::sun::star; using namespace ::cppu; using namespace ::osl; @@ -177,12 +176,7 @@ ODatabaseContext::ODatabaseContext( const Reference< XComponentContext >& _rxCon #endif osl_atomic_increment( &m_refCount ); - { - m_xDBRegistrationAggregate.set( createDataSourceRegistrations( m_aContext ), UNO_SET_THROW ); - m_xDatabaseRegistrations.set( m_xDBRegistrationAggregate, UNO_QUERY_THROW ); - - m_xDBRegistrationAggregate->setDelegator( *this ); - } + m_xDatabaseRegistrations = createDataSourceRegistrations( m_aContext ); osl_atomic_decrement( &m_refCount ); } @@ -193,8 +187,6 @@ ODatabaseContext::~ODatabaseContext() #endif m_xDatabaseDocumentLoader.clear(); - m_xDBRegistrationAggregate->setDelegator( nullptr ); - m_xDBRegistrationAggregate.clear(); m_xDatabaseRegistrations.clear(); } @@ -219,7 +211,7 @@ Reference< XInterface > ODatabaseContext::impl_createNewDataSource() ::rtl::Reference pImpl( new ODatabaseModelImpl( m_aContext, *this ) ); Reference< XDataSource > xDataSource( pImpl->getOrCreateDataSource() ); - return xDataSource.get(); + return xDataSource; } Reference< XInterface > SAL_CALL ODatabaseContext::createInstance( ) @@ -314,10 +306,11 @@ Reference< XInterface > ODatabaseContext::loadObjectFromURL(const OUString& _rNa OUString sErrorMessage( DBA_RES( RID_STR_FILE_DOES_NOT_EXIST ) ); ::svt::OFileNotation aTransformer( _sURL ); - SQLException aError; - aError.Message = sErrorMessage.replaceAll( "$file$", aTransformer.get( ::svt::OFileNotation::N_SYSTEM ) ); + SQLException aError(sErrorMessage.replaceAll( + "$file$", aTransformer.get(::svt::OFileNotation::N_SYSTEM)), + {}, {}, 0, {}); - throw WrappedTargetException( _sURL, *this, makeAny( aError ) ); + throw WrappedTargetException( _sURL, *this, Any( aError ) ); } throw WrappedTargetException( _sURL, *this, ::cppu::getCaughtException() ); } @@ -374,7 +367,7 @@ Reference< XInterface > ODatabaseContext::loadObjectFromURL(const OUString& _rNa setTransientProperties( _sURL, *pModelImpl ); - return pModelImpl->getOrCreateDataSource().get(); + return pModelImpl->getOrCreateDataSource(); } void ODatabaseContext::appendAtTerminateListener(const ODatabaseModelImpl& _rDataSourceModel) @@ -440,7 +433,7 @@ void ODatabaseContext::registerObject(const OUString& _rName, const Reference< X } // notify our container listeners - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rName), makeAny(_rxObject), Any()); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_rName), Any(_rxObject), Any()); m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); } @@ -459,7 +452,7 @@ void ODatabaseContext::storeTransientProperties( ODatabaseModelImpl& _rModelImpl if (xSetInfo.is()) aProperties = xSetInfo->getProperties(); - for ( const Property& rProperty : std::as_const(aProperties) ) + for (const Property& rProperty : aProperties) { if ( ( ( rProperty.Attributes & PropertyAttribute::TRANSIENT) != 0 ) && ( ( rProperty.Attributes & PropertyAttribute::READONLY) == 0 ) @@ -528,7 +521,7 @@ void ODatabaseContext::revokeObject(const OUString& _rName) m_aDatabaseObjects.erase( aExistent ); // notify our container listeners - ContainerEvent aEvent( *this, makeAny( _rName ), Any(), Any() ); + ContainerEvent aEvent( *this, Any( _rName ), Any(), Any() ); aGuard.clear(); m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent ); } @@ -611,7 +604,7 @@ Any ODatabaseContext::getByName(const OUString& _rName) { Reference< XInterface > xExistent = getObject( _rName ); if ( xExistent.is() ) - return makeAny( xExistent ); + return Any( xExistent ); // see whether this is a registered name OUString sURL; @@ -628,7 +621,7 @@ Any ODatabaseContext::getByName(const OUString& _rName) if ( !xExistent.is() ) // try to load this as URL xExistent = loadObjectFromURL( _rName, sURL ); - return makeAny( xExistent ); + return Any( xExistent ); } catch (const NoSuchElementException&) { // let these exceptions through @@ -707,21 +700,6 @@ void ODatabaseContext::databaseDocumentURLChange( const OUString& _rOldURL, cons m_aDatabaseObjects.erase( oldPos ); } -sal_Int64 SAL_CALL ODatabaseContext::getSomething( const Sequence< sal_Int8 >& rId ) -{ - if (isUnoTunnelId<ODatabaseContext>(rId)) - return reinterpret_cast<sal_Int64>(this); - - return 0; -} - -Sequence< sal_Int8 > ODatabaseContext::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - void ODatabaseContext::onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager ) { #if !HAVE_FEATURE_SCRIPTING @@ -740,7 +718,7 @@ void ODatabaseContext::onBasicManagerCreated( const Reference< XModel >& _rxForD // ... whose BasicManager has just been created, then add the global DatabaseDocument variable to its scope. if ( xDatabaseDocument.is() ) - _rBasicManager.SetGlobalUNOConstant( "ThisDatabaseDocument", makeAny( xDatabaseDocument ) ); + _rBasicManager.SetGlobalUNOConstant( "ThisDatabaseDocument", Any( xDatabaseDocument ) ); #endif } @@ -751,7 +729,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* com_sun_star_comp_dba_ODatabaseContext_get_implementation( css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& ) { - return cppu::acquire(static_cast<cppu::OWeakObject*>(new dbaccess::ODatabaseContext(context))); + return cppu::acquire(new dbaccess::ODatabaseContext(context)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 21d0d3012077..204bad556e5d 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -24,8 +24,11 @@ #include <databasecontext.hxx> #include "documentcontainer.hxx" #include <sdbcoretools.hxx> +#include <strings.hxx> #include <recovery/dbdocrecovery.hxx> +#include <officecfg/Office/Common.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/document/XExporter.hpp> #include <com/sun/star/document/XFilter.hpp> #include <com/sun/star/document/XImporter.hpp> @@ -59,6 +62,7 @@ #include <comphelper/genericpropertyset.hxx> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/numberedcollection.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/storagehelper.hxx> #include <comphelper/propertysetinfo.hxx> #include <comphelper/types.hxx> @@ -69,7 +73,7 @@ #include <cppuhelper/supportsservice.hxx> #include <framework/titlehelper.hxx> #include <unotools/saveopt.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <vcl/GraphicObject.hxx> @@ -193,39 +197,24 @@ Any SAL_CALL ODatabaseDocument::queryInterface( const Type& _rType ) ) return Any(); - Any aReturn = ODatabaseDocument_OfficeDocument::queryInterface(_rType); - if (!aReturn.hasValue()) - aReturn = ODatabaseDocument_Title::queryInterface(_rType); - return aReturn; -} - -void SAL_CALL ODatabaseDocument::acquire( ) throw () -{ - ODatabaseDocument_OfficeDocument::acquire(); -} - -void SAL_CALL ODatabaseDocument::release( ) throw () -{ - ODatabaseDocument_OfficeDocument::release(); + return ODatabaseDocument_OfficeDocument::queryInterface(_rType); } Sequence< Type > SAL_CALL ODatabaseDocument::getTypes( ) { - Sequence< Type > aTypes = ::comphelper::concatSequences( - ODatabaseDocument_OfficeDocument::getTypes(), - ODatabaseDocument_Title::getTypes() - ); + Sequence< Type > aTypes = ODatabaseDocument_OfficeDocument::getTypes(); // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report // which already contains macros. In this case, the database document itself is not // allowed to contain macros, too. if ( !m_bAllowDocumentScripting ) { - auto newEnd = std::remove_if( aTypes.begin(), aTypes.end(), + auto [begin, end] = asNonConstRange(aTypes); + auto newEnd = std::remove_if( begin, end, [](const Type& t) { return t == cppu::UnoType<XEmbeddedScripts>::get() || t == cppu::UnoType<XScriptInvocationContext>::get();} ); - aTypes.realloc( std::distance(aTypes.begin(), newEnd) ); + aTypes.realloc( std::distance(begin, newEnd) ); } return aTypes; @@ -275,7 +264,7 @@ namespace sal_Int32 nLength = _rCallArgs.getLength(); _rCallArgs.realloc( nLength + 1 ); - _rCallArgs[ nLength ] <<= xStatusIndicator; + _rCallArgs.getArray()[ nLength ] <<= xStatusIndicator; } void lcl_extractAndStartStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments, Reference< XStatusIndicator >& _rxStatusIndicator, @@ -291,7 +280,7 @@ namespace sal_Int32 nLength = _rCallArgs.getLength(); _rCallArgs.realloc( nLength + 1 ); - _rCallArgs[ nLength ] <<= _rxStatusIndicator; + _rCallArgs.getArray()[ nLength ] <<= _rxStatusIndicator; } catch( const Exception& ) { @@ -301,17 +290,17 @@ namespace Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const ::comphelper::NamedValueCollection& _rDescriptor, const OUString& _rURL ) { + if ( _rURL.isEmpty() ) + return _rDescriptor.getPropertyValues(); + ::comphelper::NamedValueCollection aMutableDescriptor( _rDescriptor ); - if ( !_rURL.isEmpty() ) - { - aMutableDescriptor.put( "FileName", _rURL ); - aMutableDescriptor.put( "URL", _rURL ); - } + aMutableDescriptor.put( "FileName", _rURL ); + aMutableDescriptor.put( "URL", _rURL ); return aMutableDescriptor.getPropertyValues(); } } -constexpr OUStringLiteral sPictures = u"Pictures"; +constexpr OUString sPictures = u"Pictures"_ustr; // base documents seem to have a different behaviour to other documents, the // root storage contents at least seem to be re-used over different saves, thus if there is a @@ -429,9 +418,8 @@ namespace { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("UsePrettyPrinting"), 0, ::cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, - {OUString("TargetStorage"), 0, cppu::UnoType<embed::XStorage>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, - {OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, - { OUString(), 0, css::uno::Type(), 0, 0 } + { OUString("TargetStorage"), 0, cppu::UnoType<embed::XStorage>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, + { OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, }; } @@ -447,12 +435,12 @@ void ODatabaseDocument::impl_import_nolck_throw( const Reference< XComponentCont if (sBaseURI.isEmpty()) sBaseURI = _rResource.getOrDefault("URL",OUString()); assert(!sBaseURI.isEmpty()); // needed for relative URLs - xInfoSet->setPropertyValue("BaseURI", uno::makeAny(sBaseURI)); - xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("content.xml"))); + xInfoSet->setPropertyValue("BaseURI", uno::Any(sBaseURI)); + xInfoSet->setPropertyValue("StreamName", uno::Any(OUString("content.xml"))); const sal_Int32 nCount = aFilterCreationArgs.getLength(); aFilterCreationArgs.realloc(nCount + 1); - aFilterCreationArgs[nCount] <<= xInfoSet; + aFilterCreationArgs.getArray()[nCount] <<= xInfoSet; Reference< XImporter > xImporter( _rContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.sdb.DBFilter", aFilterCreationArgs, _rContext), @@ -771,7 +759,7 @@ bool ODatabaseDocument::impl_attachResource( const OUString& i_rLogicalDocumentU // determine whether the document as a whole, or sub documents, have macros. Especially the latter // controls the availability of our XEmbeddedScripts and XScriptInvocationContext interfaces, and we // should know this before anybody actually uses the object. - m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros ); + m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::EmbeddedMacros::SubDocument ); _rDocGuard.clear(); // <- SYNCHRONIZED @@ -793,6 +781,15 @@ Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) return m_pImpl->getMediaDescriptor().getPropertyValues(); } +Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs2( const ::css::uno::Sequence< ::rtl::OUString >& requestedArgs ) +{ + DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); + std::vector<PropertyValue> aRet; + for (const auto & rArgName : requestedArgs) + aRet.push_back(PropertyValue(rArgName, 0, m_pImpl->getMediaDescriptor().get(rArgName), PropertyState_DIRECT_VALUE)); + return comphelper::containerToSequence(aRet); +} + void SAL_CALL ODatabaseDocument::setArgs(const Sequence<beans::PropertyValue>& /* aArgs */) { throw NoSupportException(); @@ -1016,7 +1013,7 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph if ( !bIsInitializationProcess ) { _rGuard.clear(); - m_aEventNotifier.notifyDocumentEvent( _eType == SAVE ? "OnSave" : "OnSaveAs", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEvent( _eType == SAVE ? "OnSave" : "OnSaveAs", nullptr, Any( _rURL ) ); _rGuard.reset(); } @@ -1076,13 +1073,13 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph catch( const IOException& ) { if ( !bIsInitializationProcess ) - m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", nullptr, Any( _rURL ) ); throw; } catch( const RuntimeException& ) { if ( !bIsInitializationProcess ) - m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", nullptr, Any( _rURL ) ); throw; } catch( const Exception& ) @@ -1091,14 +1088,14 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph // notify the failure if ( !bIsInitializationProcess ) - m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", nullptr, Any( _rURL ) ); impl_throwIOExceptionCausedBySave_throw( aError, _rURL ); } // notify the document event if ( !bIsInitializationProcess ) - m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveDone" : "OnSaveAsDone", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveDone" : "OnSaveAsDone", nullptr, Any( _rURL ) ); // reset our "modified" flag, and clear the guard impl_setModified_nothrow( false, _rGuard ); @@ -1118,9 +1115,7 @@ Reference< XStorage > ODatabaseDocument::impl_createStorageFor_throw( const OUSt { xTruncate->truncate(); } - Sequence<Any> aParam(2); - aParam[0] <<= xStream; - aParam[1] <<= ElementModes::READWRITE | ElementModes::TRUNCATE; + Sequence<Any> aParam{ Any(xStream), Any(ElementModes::READWRITE | ElementModes::TRUNCATE) }; Reference< XSingleServiceFactory > xStorageFactory( m_pImpl->createStorageFactory(), UNO_SET_THROW ); return Reference< XStorage >( xStorageFactory->createInstanceWithArguments( aParam ), UNO_QUERY_THROW ); @@ -1240,7 +1235,7 @@ void SAL_CALL ODatabaseDocument::storeToURL( const OUString& _rURL, const Sequen { aGuard.clear(); - m_aEventNotifier.notifyDocumentEvent( "OnSaveTo", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEvent( "OnSaveTo", nullptr, Any( _rURL ) ); aGuard.reset(); } @@ -1272,7 +1267,7 @@ void SAL_CALL ODatabaseDocument::storeToURL( const OUString& _rURL, const Sequen impl_throwIOExceptionCausedBySave_throw( aError, _rURL ); } - m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone", nullptr, makeAny( _rURL ) ); + m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone", nullptr, Any( _rURL ) ); } // XModifyBroadcaster @@ -1402,10 +1397,10 @@ void ODatabaseDocument::clearObjectContainer( WeakReference< XNameAccess >& _rxC Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType ) { - if ( ( _eType != ODatabaseModelImpl::E_FORM ) && ( _eType != ODatabaseModelImpl::E_REPORT ) ) + if ( ( _eType != ODatabaseModelImpl::ObjectType::Form ) && ( _eType != ODatabaseModelImpl::ObjectType::Report ) ) throw IllegalArgumentException(); - bool bFormsContainer = _eType == ODatabaseModelImpl::E_FORM; + bool bFormsContainer = _eType == ODatabaseModelImpl::ObjectType::Form; WeakReference< XNameAccess >& rContainerRef( bFormsContainer ? m_xForms : m_xReports ); Reference< XNameAccess > xContainer = rContainerRef; @@ -1419,8 +1414,7 @@ Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODa aValue >>= sSupportService; if ( !sSupportService.isEmpty() ) { - Sequence<Any> aArgs(1); - aArgs[0] <<= NamedValue("DatabaseDocument",makeAny(xMy)); + Sequence<Any> aArgs{ Any(NamedValue("DatabaseDocument",Any(xMy))) }; xContainer.set( m_pImpl->m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext(sSupportService, aArgs, m_pImpl->m_aContext), UNO_QUERY); @@ -1497,7 +1491,7 @@ void SAL_CALL ODatabaseDocument::close(sal_Bool bDeliverOwnership) { // allow listeners to veto lang::EventObject aEvent( *this ); - m_aCloseListener.forEach< XCloseListener >( + m_aCloseListener.forEach( [&aEvent, &bDeliverOwnership] (uno::Reference<XCloseListener> const& xListener) { return xListener->queryClosing(aEvent, bDeliverOwnership); }); @@ -1539,13 +1533,13 @@ void SAL_CALL ODatabaseDocument::removeCloseListener( const Reference< css::util Reference< XNameAccess > SAL_CALL ODatabaseDocument::getFormDocuments( ) { DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); - return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_FORM ); + return impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType::Form ); } Reference< XNameAccess > SAL_CALL ODatabaseDocument::getReportDocuments( ) { DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); - return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_REPORT ); + return impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType::Report ); } void ODatabaseDocument::WriteThroughComponent( const Reference< XComponent >& xComponent, const char* pStreamName, @@ -1571,8 +1565,8 @@ void ODatabaseDocument::WriteThroughComponent( const Reference< XComponent >& xC xSeek->seek(0); Reference< XPropertySet > xStreamProp( xOutputStream, UNO_QUERY_THROW ); - xStreamProp->setPropertyValue( INFO_MEDIATYPE, makeAny( OUString( "text/xml" ) ) ); - xStreamProp->setPropertyValue( "Compressed", makeAny( true ) ); + xStreamProp->setPropertyValue( INFO_MEDIATYPE, Any( OUString( "text/xml" ) ) ); + xStreamProp->setPropertyValue( "Compressed", Any( true ) ); // write the stuff WriteThroughComponent( xOutputStream, xComponent, pServiceName, _rArguments, rMediaDesc ); @@ -1594,9 +1588,10 @@ void ODatabaseDocument::WriteThroughComponent( const Reference< XOutputStream >& // prepare arguments (prepend doc handler to given arguments) Sequence<Any> aArgs( 1 + _rArguments.getLength() ); - aArgs[0] <<= xSaxWriter; + auto pArgs = aArgs.getArray(); + pArgs[0] <<= xSaxWriter; for ( sal_Int32 i = 0; i < _rArguments.getLength(); ++i ) - aArgs[ i+1 ] = _rArguments[i]; + pArgs[ i+1 ] = _rArguments[i]; // get filter component Reference< XExporter > xExporter( m_pImpl->m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext(OUString::createFromAscii(pServiceName), aArgs, m_pImpl->m_aContext), UNO_QUERY_THROW ); @@ -1617,18 +1612,17 @@ void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _r uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) ); - SvtSaveOptions aSaveOpt; - xInfoSet->setPropertyValue("UsePrettyPrinting", uno::makeAny(aSaveOpt.IsPrettyPrinting())); - if ( aSaveOpt.IsSaveRelFSys() ) + xInfoSet->setPropertyValue("UsePrettyPrinting", uno::Any(officecfg::Office::Common::Save::Document::PrettyPrinting::get())); + if ( officecfg::Office::Common::Save::URL::FileSystem::get() ) { OUString sBaseURI = _rMediaDescriptor.getOrDefault("BaseURI", OUString()); if (sBaseURI.isEmpty()) sBaseURI = _rMediaDescriptor.getOrDefault("URL",OUString()); - xInfoSet->setPropertyValue("BaseURI", uno::makeAny(sBaseURI)); + xInfoSet->setPropertyValue("BaseURI", uno::Any(sBaseURI)); } // Set TargetStorage, so it doesn't have to be re-constructed based on possibly empty URL. - xInfoSet->setPropertyValue("TargetStorage", uno::makeAny(m_pImpl->getRootStorage())); + xInfoSet->setPropertyValue("TargetStorage", uno::Any(m_pImpl->getRootStorage())); // Set StreamRelPath, in case this document is an embedded one. OUString sStreamRelPath; @@ -1642,18 +1636,18 @@ void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _r sStreamRelPath = sStreamRelPath.copy(1); } if (!sStreamRelPath.isEmpty()) - xInfoSet->setPropertyValue("StreamRelPath", uno::makeAny(sStreamRelPath)); + xInfoSet->setPropertyValue("StreamRelPath", uno::Any(sStreamRelPath)); sal_Int32 nArgsLen = aDelegatorArguments.getLength(); aDelegatorArguments.realloc(nArgsLen+1); - aDelegatorArguments[nArgsLen++] <<= xInfoSet; + aDelegatorArguments.getArray()[nArgsLen++] <<= xInfoSet; Reference< XPropertySet > xProp( _rxTargetStorage, UNO_QUERY_THROW ); - xProp->setPropertyValue( INFO_MEDIATYPE, makeAny( OUString(MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII) ) ); + xProp->setPropertyValue( INFO_MEDIATYPE, Any( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ); OUString aVersion; SvtSaveOptions::ODFSaneDefaultVersion const nDefVersion = - aSaveOpt.GetODFSaneDefaultVersion(); + GetODFSaneDefaultVersion(); // older versions can not have this property set, // it exists only starting from ODF1.2 if (nDefVersion >= SvtSaveOptions::ODFSVER_013) @@ -1669,7 +1663,7 @@ void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _r { try { - xProp->setPropertyValue("Version" , uno::makeAny(aVersion)); + xProp->setPropertyValue("Version" , uno::Any(aVersion)); } catch (const uno::Exception&) { @@ -1682,11 +1676,11 @@ void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _r Sequence< PropertyValue > aMediaDescriptor; _rMediaDescriptor >>= aMediaDescriptor; - xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("settings.xml"))); + xInfoSet->setPropertyValue("StreamName", uno::Any(OUString("settings.xml"))); WriteThroughComponent( xComponent, "settings.xml", "com.sun.star.comp.sdb.XMLSettingsExporter", aDelegatorArguments, aMediaDescriptor, _rxTargetStorage ); - xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("content.xml"))); + xInfoSet->setPropertyValue("StreamName", uno::Any(OUString("content.xml"))); WriteThroughComponent( xComponent, "content.xml", "com.sun.star.comp.sdb.DBExportFilter", aDelegatorArguments, aMediaDescriptor, _rxTargetStorage ); @@ -1767,7 +1761,7 @@ void ODatabaseDocument::impl_notifyStorageChange_nolck_nothrow( const Reference< { Reference< XInterface > xMe( *this ); - m_aStorageListeners.forEach< XStorageChangeListener >( + m_aStorageListeners.forEach( [&xMe, &xNewRootStorage] (uno::Reference<XStorageChangeListener> const& xListener) { return xListener->notifyStorageChange(xMe, xNewRootStorage); }); @@ -1859,6 +1853,11 @@ void ODatabaseDocument::disposing() void SAL_CALL ODatabaseDocument::dispose( ) { ::cppu::WeakComponentImplHelperBase::dispose(); + m_xTitleHelper.clear(); + m_xModuleManager.clear(); + m_pEventExecutor.clear(); + m_xCurrentController.clear(); + m_xUIConfigurationManager.clear(); } void SAL_CALL ODatabaseDocument::addEventListener( const Reference< lang::XEventListener >& _xListener ) @@ -1901,7 +1900,6 @@ comphelper::PropertyMapEntry const aEmbeddedImportInfoMap[] = {OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, {OUString("StreamName"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, {OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, - {OUString(), 0, css::uno::Type(), 0, 0} }; } @@ -1910,13 +1908,11 @@ void SAL_CALL ODatabaseDocument::loadFromStorage(const Reference<XStorage>& xSto DocumentGuard aGuard(*this, DocumentGuard::InitMethod); uno::Reference<beans::XPropertySet> xInfoSet(comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(aEmbeddedImportInfoMap))); - comphelper::NamedValueCollection aDescriptor(rMediaDescriptor); - xInfoSet->setPropertyValue("StreamRelPath", uno::makeAny(aDescriptor.getOrDefault("HierarchicalDocumentName", OUString()))); - xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("content.xml"))); - xInfoSet->setPropertyValue("SourceStorage", uno::makeAny(xStorage)); + xInfoSet->setPropertyValue("StreamRelPath", uno::Any(comphelper::NamedValueCollection::getOrDefault(rMediaDescriptor, u"HierarchicalDocumentName", OUString()))); + xInfoSet->setPropertyValue("StreamName", uno::Any(OUString("content.xml"))); + xInfoSet->setPropertyValue("SourceStorage", uno::Any(xStorage)); - uno::Sequence<uno::Any> aFilterCreationArgs(1); - aFilterCreationArgs[0] <<= xInfoSet; + uno::Sequence<uno::Any> aFilterCreationArgs{ Any(xInfoSet) }; uno::Reference<document::XImporter> xImporter(m_pImpl->m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.sdb.DBFilter", aFilterCreationArgs, m_pImpl->m_aContext), uno::UNO_QUERY_THROW); @@ -2029,7 +2025,7 @@ struct CreateAny { Any operator() (const Reference<XController>& lhs) const { - return makeAny(lhs); + return Any(lhs); } }; @@ -2086,10 +2082,7 @@ Reference< XTitle > const & ODatabaseDocument::impl_getTitleHelper_throw() Reference< XUntitledNumbers > xDesktop(Desktop::create(m_pImpl->m_aContext), uno::UNO_QUERY_THROW); Reference< frame::XModel > xThis (getThis(), uno::UNO_QUERY_THROW); - ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(m_pImpl->m_aContext); - m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW); - pHelper->setOwner (xThis ); - pHelper->connectWithUntitledNumbers (xDesktop); + m_xTitleHelper = new ::framework::TitleHelper(m_pImpl->m_aContext, xThis, xDesktop); } return m_xTitleHelper; @@ -2101,23 +2094,17 @@ uno::Reference< frame::XUntitledNumbers > ODatabaseDocument::impl_getUntitledHel m_xModuleManager.set( ModuleManager::create(m_pImpl->m_aContext) ); OUString sModuleId; - try - { - sModuleId = m_xModuleManager->identify( _xComponent ); - } - catch(const uno::Exception&) - { - } + if (_xComponent.is()) + sModuleId = m_xModuleManager->identify(_xComponent); + uno::Reference< frame::XUntitledNumbers > xNumberedControllers; TNumberedController::const_iterator aFind = m_aNumberedControllers.find(sModuleId); if ( aFind == m_aNumberedControllers.end() ) { - uno::Reference< frame::XModel > xThis(static_cast< frame::XModel* >(this), uno::UNO_QUERY_THROW); - ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection(); - xNumberedControllers.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW); - - pHelper->setOwner (xThis); + rtl::Reference<::comphelper::NumberedCollection> pHelper = new ::comphelper::NumberedCollection(); + xNumberedControllers = pHelper; + pHelper->setOwner(uno::Reference< frame::XModel >(this)); m_aNumberedControllers.emplace( sModuleId,xNumberedControllers ); } @@ -2198,11 +2185,11 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* com_sun_star_comp_dba_ODatabaseDocument(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &) { - Reference<XUnoTunnel> xDBContextTunnel(DatabaseContext::create(context), UNO_QUERY_THROW); - dbaccess::ODatabaseContext* pContext = reinterpret_cast<dbaccess::ODatabaseContext*>( - xDBContextTunnel->getSomething( - dbaccess::ODatabaseContext::getUnoTunnelId())); - + Reference<XInterface> xDBContextTunnel(DatabaseContext::create(context), UNO_QUERY_THROW); + rtl::Reference<dbaccess::ODatabaseContext> pContext + = dynamic_cast<dbaccess::ODatabaseContext*>(xDBContextTunnel.get()); + assert(pContext); + rtl::Reference pImpl( new dbaccess::ODatabaseModelImpl(context, *pContext)); css::uno::Reference<XInterface> inst(pImpl->createNewModel_deliverOwnership()); diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 6ce35092ea5b..6278aa039a63 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -28,7 +28,7 @@ #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp> #include <com/sun/star/frame/DoubleInitializationException.hpp> -#include <com/sun/star/frame/XModel2.hpp> +#include <com/sun/star/frame/XModel3.hpp> #include <com/sun/star/frame/XTitle.hpp> #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp> #include <com/sun/star/frame/XUntitledNumbers.hpp> @@ -57,6 +57,7 @@ #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/util/XModifiable.hpp> +#include <comphelper/interfacecontainer3.hxx> #include <cppuhelper/compbase.hxx> #include <cppuhelper/implbase3.hxx> #include <rtl/ref.hxx> @@ -130,7 +131,7 @@ private: }; // ODatabaseDocument -typedef cppu::PartialWeakComponentImplHelper< css::frame::XModel2 +typedef cppu::PartialWeakComponentImplHelper< css::frame::XModel3 , css::util::XModifiable , css::frame::XStorable , css::document::XEventBroadcaster @@ -147,16 +148,13 @@ typedef cppu::PartialWeakComponentImplHelper< css::frame::XModel2 , css::document::XEventsSupplier , css::frame::XLoadable , css::document::XDocumentRecovery + , css::frame::XTitle + , css::frame::XTitleChangeBroadcaster + , css::frame::XUntitledNumbers > ODatabaseDocument_OfficeDocument; -typedef ::cppu::ImplHelper3< css::frame::XTitle - , css::frame::XTitleChangeBroadcaster - , css::frame::XUntitledNumbers - > ODatabaseDocument_Title; - class ODatabaseDocument :public ModelDependentComponent // ModelDependentComponent must be first! ,public ODatabaseDocument_OfficeDocument - ,public ODatabaseDocument_Title { enum InitState { @@ -168,9 +166,9 @@ class ODatabaseDocument :public ModelDependentComponent // ModelDepe typedef std::map< OUString, css::uno::Reference< css::frame::XUntitledNumbers > > TNumberedController; css::uno::Reference< css::ui::XUIConfigurationManager2> m_xUIConfigurationManager; - ::comphelper::OInterfaceContainerHelper2 m_aModifyListeners; - ::comphelper::OInterfaceContainerHelper2 m_aCloseListener; - ::comphelper::OInterfaceContainerHelper2 m_aStorageListeners; + ::comphelper::OInterfaceContainerHelper3<css::util::XModifyListener> m_aModifyListeners; + ::comphelper::OInterfaceContainerHelper3<css::util::XCloseListener> m_aCloseListener; + ::comphelper::OInterfaceContainerHelper3<css::document::XStorageChangeListener> m_aStorageListeners; std::unique_ptr<DocumentEvents> m_pEventContainer; ::rtl::Reference< DocumentEventExecutor > m_pEventExecutor; @@ -286,7 +284,7 @@ protected: public: struct FactoryAccess { friend class ODatabaseModelImpl; private: FactoryAccess() { } }; - static ODatabaseDocument* createDatabaseDocument( const ::rtl::Reference<ODatabaseModelImpl>& _pImpl, FactoryAccess /*accessControl*/ ) + static rtl::Reference<ODatabaseDocument> createDatabaseDocument( const ::rtl::Reference<ODatabaseModelImpl>& _pImpl, FactoryAccess /*accessControl*/ ) { return new ODatabaseDocument( _pImpl ); } @@ -298,8 +296,6 @@ public: // XInterface virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override; - virtual void SAL_CALL acquire( ) throw () override; - virtual void SAL_CALL release( ) throw () override; // XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -330,6 +326,9 @@ public: virtual css::uno::Reference< css::frame::XController2 > SAL_CALL createViewController( const OUString& ViewName, const css::uno::Sequence< css::beans::PropertyValue >& Arguments, const css::uno::Reference< css::frame::XFrame >& Frame ) override ; virtual void SAL_CALL setArgs(const css::uno::Sequence<css::beans::PropertyValue>& aArgs) override; + // XModel3 + virtual ::css::uno::Sequence< ::css::beans::PropertyValue > SAL_CALL getArgs2( const ::css::uno::Sequence< ::rtl::OUString >& requestedArgs ) override; + // XStorable virtual sal_Bool SAL_CALL hasLocation( ) override ; virtual OUString SAL_CALL getLocation( ) override ; diff --git a/dbaccess/source/core/dataaccess/databaseregistrations.cxx b/dbaccess/source/core/dataaccess/databaseregistrations.cxx index 6009653ce1a7..3b19de41c366 100644 --- a/dbaccess/source/core/dataaccess/databaseregistrations.cxx +++ b/dbaccess/source/core/dataaccess/databaseregistrations.cxx @@ -26,8 +26,8 @@ #include <com/sun/star/sdb/XDatabaseRegistrations.hpp> #include <cppuhelper/basemutex.hxx> -#include <comphelper/interfacecontainer2.hxx> -#include <cppuhelper/implbase1.hxx> +#include <comphelper/interfacecontainer3.hxx> +#include <cppuhelper/implbase.hxx> #include <osl/diagnose.h> #include <unotools/pathoptions.hxx> #include <tools/urlobj.hxx> @@ -39,7 +39,7 @@ namespace dbaccess { using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::RuntimeException; - using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::container::NoSuchElementException; @@ -51,24 +51,13 @@ namespace dbaccess using ::com::sun::star::sdb::DatabaseRegistrationEvent; using ::com::sun::star::uno::XAggregation; - static OUString getConfigurationRootPath() - { - return "org.openoffice.Office.DataAccess/RegisteredNames"; - } - - static OUString getLocationNodeName() - { - return "Location"; - } - - static OUString getNameNodeName() - { - return "Name"; - } + constexpr OUString CONF_ROOT_PATH = u"org.openoffice.Office.DataAccess/RegisteredNames"_ustr; + constexpr OUString LOCATION = u"Location"_ustr; + constexpr OUString NAME = u"Name"_ustr; // DatabaseRegistrations - declaration - typedef ::cppu::WeakAggImplHelper1 < XDatabaseRegistrations - > DatabaseRegistrations_Base; + typedef ::cppu::WeakImplHelper< XDatabaseRegistrations + > DatabaseRegistrations_Base; namespace { @@ -100,7 +89,7 @@ namespace dbaccess ::utl::OConfigurationNode impl_checkValidName_throw_must_not_exist(const OUString& _rName); - void impl_checkValidLocation_throw( const OUString& _rLocation ); + void impl_checkValidLocation_throw( std::u16string_view _rLocation ); /** retrieves the configuration node whose "Name" sub node has the given value @@ -136,7 +125,7 @@ namespace dbaccess private: Reference<XComponentContext> m_aContext; ::utl::OConfigurationTreeRoot m_aConfigurationRoot; - ::comphelper::OInterfaceContainerHelper2 m_aRegistrationListeners; + ::comphelper::OInterfaceContainerHelper3<XDatabaseRegistrationsListener> m_aRegistrationListeners; }; } @@ -144,11 +133,10 @@ namespace dbaccess // DatabaseRegistrations - implementation DatabaseRegistrations::DatabaseRegistrations( const Reference<XComponentContext> & _rxContext ) :m_aContext( _rxContext ) - ,m_aConfigurationRoot() ,m_aRegistrationListeners( m_aMutex ) { m_aConfigurationRoot = ::utl::OConfigurationTreeRoot::createWithComponentContext( - m_aContext, getConfigurationRootPath() ); + m_aContext, CONF_ROOT_PATH ); } DatabaseRegistrations::~DatabaseRegistrations() @@ -163,7 +151,7 @@ namespace dbaccess ::utl::OConfigurationNode aNodeForName = m_aConfigurationRoot.openNode( nodeName ); OUString sTestName; - OSL_VERIFY( aNodeForName.getNodeValue( getNameNodeName() ) >>= sTestName ); + OSL_VERIFY( aNodeForName.getNodeValue( NAME ) >>= sTestName ); if ( sTestName == _rName ) return aNodeForName; } @@ -197,7 +185,7 @@ namespace dbaccess } ::utl::OConfigurationNode aNewNode( m_aConfigurationRoot.createNode( sNewNodeName ) ); - aNewNode.setNodeValue( getNameNodeName(), makeAny( _rName ) ); + aNewNode.setNodeValue( NAME, Any( _rName ) ); return aNewNode; } @@ -222,9 +210,9 @@ namespace dbaccess return impl_getNodeForName_throw_must_not_exist(_rName); } - void DatabaseRegistrations::impl_checkValidLocation_throw( const OUString& _rLocation ) + void DatabaseRegistrations::impl_checkValidLocation_throw( std::u16string_view _rLocation ) { - if ( _rLocation.isEmpty() ) + if ( _rLocation.empty() ) throw IllegalArgumentException( OUString(), *this, 2 ); INetURLObject aURL( _rLocation ); @@ -252,7 +240,7 @@ namespace dbaccess for ( auto const & name : aProgrammaticNames ) { ::utl::OConfigurationNode aRegistrationNode = m_aConfigurationRoot.openNode( name ); - OSL_VERIFY( aRegistrationNode.getNodeValue( getNameNodeName() ) >>= *pDisplayName ); + OSL_VERIFY( aRegistrationNode.getNodeValue( NAME ) >>= *pDisplayName ); ++pDisplayName; } @@ -266,7 +254,7 @@ namespace dbaccess ::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw_must_exist(Name); OUString sLocation; - OSL_VERIFY( aNodeForName.getNodeValue( getLocationNodeName() ) >>= sLocation ); + OSL_VERIFY( aNodeForName.getNodeValue( LOCATION ) >>= sLocation ); sLocation = SvtPathOptions().SubstituteVariable( sLocation ); return sLocation; @@ -281,7 +269,7 @@ namespace dbaccess ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw_must_not_exist(Name); // register - aDataSourceRegistration.setNodeValue( getLocationNodeName(), makeAny( Location ) ); + aDataSourceRegistration.setNodeValue( LOCATION, Any( Location ) ); m_aConfigurationRoot.commit(); // notify @@ -299,7 +287,7 @@ namespace dbaccess // obtain properties for notification OUString sLocation; - OSL_VERIFY( aNodeForName.getNodeValue( getLocationNodeName() ) >>= sLocation ); + OSL_VERIFY( aNodeForName.getNodeValue( LOCATION ) >>= sLocation ); // revoke if ( aNodeForName.isReadonly() @@ -328,10 +316,10 @@ namespace dbaccess // obtain properties for notification OUString sOldLocation; - OSL_VERIFY( aDataSourceRegistration.getNodeValue( getLocationNodeName() ) >>= sOldLocation ); + OSL_VERIFY( aDataSourceRegistration.getNodeValue( LOCATION ) >>= sOldLocation ); // change - aDataSourceRegistration.setNodeValue( getLocationNodeName(), makeAny( NewLocation ) ); + aDataSourceRegistration.setNodeValue( LOCATION, Any( NewLocation ) ); m_aConfigurationRoot.commit(); // notify @@ -360,7 +348,7 @@ namespace dbaccess } // DatabaseRegistrations - factory - Reference< XAggregation > createDataSourceRegistrations( const Reference<XComponentContext> & _rxContext ) + Reference< XDatabaseRegistrations > createDataSourceRegistrations( const Reference<XComponentContext> & _rxContext ) { return new DatabaseRegistrations( _rxContext ); } diff --git a/dbaccess/source/core/dataaccess/databaseregistrations.hxx b/dbaccess/source/core/dataaccess/databaseregistrations.hxx index 709bc9f98490..52def1de5aa2 100644 --- a/dbaccess/source/core/dataaccess/databaseregistrations.hxx +++ b/dbaccess/source/core/dataaccess/databaseregistrations.hxx @@ -20,11 +20,11 @@ #pragma once #include <com/sun/star/uno/XAggregation.hpp> -#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/sdb/XDatabaseRegistrations.hpp> namespace dbaccess { -css::uno::Reference<css::uno::XAggregation> +css::uno::Reference<css::sdb::XDatabaseRegistrations> createDataSourceRegistrations(const css::uno::Reference<css::uno::XComponentContext>& _rxContext); } // namespace dbaccess diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index 206b8e490e6e..62cacc3b1f44 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> @@ -219,9 +219,8 @@ void SAL_CALL OAuthenticationContinuation::setPassword( const OUString& _rPasswo Sequence< RememberAuthentication > SAL_CALL OAuthenticationContinuation::getRememberPasswordModes( RememberAuthentication& _reDefault ) { - Sequence< RememberAuthentication > aReturn(1); - _reDefault = aReturn[0] = RememberAuthentication_SESSION; - return aReturn; + _reDefault = RememberAuthentication_SESSION; + return { _reDefault }; } void SAL_CALL OAuthenticationContinuation::setRememberPassword( RememberAuthentication _eRemember ) @@ -241,10 +240,8 @@ void SAL_CALL OAuthenticationContinuation::setAccount( const OUString& ) Sequence< RememberAuthentication > SAL_CALL OAuthenticationContinuation::getRememberAccountModes( RememberAuthentication& _reDefault ) { - Sequence < RememberAuthentication > aReturn(1); - aReturn[0] = RememberAuthentication_NO; _reDefault = RememberAuthentication_NO; - return aReturn; + return { RememberAuthentication_NO }; } void SAL_CALL OAuthenticationContinuation::setRememberAccount( RememberAuthentication /*Remember*/ ) @@ -252,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 ) ); @@ -352,10 +286,11 @@ Reference<XConnection> OSharedConnectionManager::getConnection( const OUString& Sequence< PropertyValue > aInfoCopy(_aInfo); sal_Int32 nPos = aInfoCopy.getLength(); aInfoCopy.realloc( nPos + 2 ); - aInfoCopy[nPos].Name = "TableFilter"; - aInfoCopy[nPos++].Value <<= _pDataSource->m_pImpl->m_aTableFilter; - aInfoCopy[nPos].Name = "TableTypeFilter"; - aInfoCopy[nPos++].Value <<= _pDataSource->m_pImpl->m_aTableTypeFilter; + auto pInfoCopy = aInfoCopy.getArray(); + pInfoCopy[nPos].Name = "TableFilter"; + pInfoCopy[nPos++].Value <<= _pDataSource->m_pImpl->m_aTableFilter; + pInfoCopy[nPos].Name = "TableTypeFilter"; + pInfoCopy[nPos++].Value <<= _pDataSource->m_pImpl->m_aTableTypeFilter; OUString sUser = user; OUString sPassword = password; @@ -381,7 +316,7 @@ Reference<XConnection> OSharedConnectionManager::getConnection( const OUString& Reference<XConnection> xRet; if ( aIter->second.xMasterConnection.is() ) { - Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(aIter->second.xMasterConnection.get()); + Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(aIter->second.xMasterConnection); xRet = new OSharedConnection(xConProxy); m_aSharedConnection.emplace(xRet,aIter); addEventListener(xRet,aIter); @@ -401,43 +336,29 @@ void OSharedConnectionManager::addEventListener(const Reference<XConnection>& _r namespace { Sequence< PropertyValue > lcl_filterDriverProperties( const Reference< XDriver >& _xDriver, const OUString& _sUrl, - const Sequence< PropertyValue >& _rDataSourceSettings, const AsciiPropertyValue* _pKnownSettings ) + const Sequence< PropertyValue >& _rDataSourceSettings ) { if ( _xDriver.is() ) { Sequence< DriverPropertyInfo > aDriverInfo(_xDriver->getPropertyInfo(_sUrl,_rDataSourceSettings)); - const PropertyValue* pDataSourceSetting = _rDataSourceSettings.getConstArray(); - const PropertyValue* pEnd = pDataSourceSetting + _rDataSourceSettings.getLength(); - std::vector< PropertyValue > aRet; - for ( ; pDataSourceSetting != pEnd ; ++pDataSourceSetting ) + for (auto& dataSourceSetting : _rDataSourceSettings) { - bool bAllowSetting = false; - const AsciiPropertyValue* pSetting = _pKnownSettings; - for ( ; pSetting->AsciiName; ++pSetting ) - { - if ( pDataSourceSetting->Name.equalsAscii( pSetting->AsciiName ) ) - { // the particular data source setting is known - - const DriverPropertyInfo* pAllowedDriverSetting = aDriverInfo.getConstArray(); - const DriverPropertyInfo* pDriverSettingsEnd = pAllowedDriverSetting + aDriverInfo.getLength(); - for ( ; pAllowedDriverSetting != pDriverSettingsEnd; ++pAllowedDriverSetting ) - { - if ( pAllowedDriverSetting->Name.equalsAscii( pSetting->AsciiName ) ) - { // the driver also allows this setting - bAllowSetting = true; - break; - } - } - break; - } - } - if ( bAllowSetting || !pSetting->AsciiName ) + auto knownSettings = dbaccess::ODatabaseModelImpl::getDefaultDataSourceSettings(); + bool isSettingKnown = std::any_of(knownSettings.begin(), knownSettings.end(), + [name = dataSourceSetting.Name](auto& setting) + { return name == setting.Name; }); + // Allow if the particular data source setting is unknown or allowed by the driver + bool bAllowSetting = !isSettingKnown + || std::any_of(aDriverInfo.begin(), aDriverInfo.end(), + [name = dataSourceSetting.Name](auto& setting) + { return name == setting.Name; }); + if (bAllowSetting) { // if the driver allows this particular setting, or if the setting is completely unknown, // we pass it to the driver - aRet.push_back( *pDataSourceSetting ); + aRet.push_back(dataSourceSetting); } } if ( !aRet.empty() ) @@ -531,12 +452,12 @@ Any ODatabaseSource::queryInterface( const Type & rType ) return aIface; } -void ODatabaseSource::acquire() throw () +void ODatabaseSource::acquire() noexcept { ODatabaseSource_Base::acquire(); } -void ODatabaseSource::release() throw () +void ODatabaseSource::release() noexcept { ODatabaseSource_Base::release(); } @@ -609,8 +530,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 { @@ -644,7 +564,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)) @@ -679,7 +599,7 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString sPwd = m_pImpl->m_aPassword; } - const char* pExceptionMessageId = RID_STR_COULDNOTCONNECT_UNSPECIFIED; + TranslateId pExceptionMessageId = RID_STR_COULDNOTCONNECT_UNSPECIFIED; if (xManager.is()) { sal_Int32 nAdditionalArgs(0); @@ -687,17 +607,18 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString if (!sPwd.isEmpty()) ++nAdditionalArgs; Sequence< PropertyValue > aUserPwd(nAdditionalArgs); + auto aUserPwdRange = asNonConstRange(aUserPwd); sal_Int32 nArgPos = 0; if (!sUser.isEmpty()) { - aUserPwd[ nArgPos ].Name = "user"; - aUserPwd[ nArgPos ].Value <<= sUser; + aUserPwdRange[ nArgPos ].Name = "user"; + aUserPwdRange[ nArgPos ].Value <<= sUser; ++nArgPos; } if (!sPwd.isEmpty()) { - aUserPwd[ nArgPos ].Name = "password"; - aUserPwd[ nArgPos ].Value <<= sPwd; + aUserPwdRange[ nArgPos ].Name = "password"; + aUserPwdRange[ nArgPos ].Value <<= sPwd; } Reference< XDriver > xDriver; try @@ -724,24 +645,24 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString Sequence< PropertyValue > aDriverInfo = lcl_filterDriverProperties( xDriver, m_pImpl->m_sConnectURL, - m_pImpl->m_xSettings->getPropertyValues(), - dbaccess::ODatabaseModelImpl::getDefaultDataSourceSettings() + m_pImpl->m_xSettings->getPropertyValues() ); if ( m_pImpl->isEmbeddedDatabase() ) { sal_Int32 nCount = aDriverInfo.getLength(); aDriverInfo.realloc(nCount + 3 ); + auto pDriverInfo = aDriverInfo.getArray(); - aDriverInfo[nCount].Name = "URL"; - aDriverInfo[nCount++].Value <<= m_pImpl->getURL(); + pDriverInfo[nCount].Name = "URL"; + pDriverInfo[nCount++].Value <<= m_pImpl->getURL(); - aDriverInfo[nCount].Name = "Storage"; + pDriverInfo[nCount].Name = "Storage"; Reference< css::document::XDocumentSubStorageSupplier> xDocSup( m_pImpl->getDocumentSubStorageSupplier() ); - aDriverInfo[nCount++].Value <<= xDocSup->getDocumentSubStorage("database",ElementModes::READWRITE); + pDriverInfo[nCount++].Value <<= xDocSup->getDocumentSubStorage("database",ElementModes::READWRITE); - aDriverInfo[nCount].Name = "Document"; - aDriverInfo[nCount++].Value <<= getDatabaseDocument(); + pDriverInfo[nCount].Name = "Document"; + pDriverInfo[nCount++].Value <<= getDatabaseDocument(); } if (nAdditionalArgs) xReturn = xManager->getConnectionWithInfo(m_pImpl->m_sConnectURL, ::comphelper::concatSequences(aUserPwd,aDriverInfo)); @@ -766,11 +687,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,21 +717,26 @@ Reference< XPropertySetInfo > ODatabaseSource::getPropertySetInfo() // comphelper::OPropertyArrayUsageHelper ::cppu::IPropertyArrayHelper* ODatabaseSource::createArrayHelper( ) const { - BEGIN_PROPERTY_HELPER(13) - DECL_PROP1(INFO, Sequence< PropertyValue >, BOUND); - DECL_PROP1_BOOL(ISPASSWORDREQUIRED, BOUND); - DECL_PROP1_BOOL(ISREADONLY, READONLY); - DECL_PROP1(LAYOUTINFORMATION, Sequence< PropertyValue >, BOUND); - DECL_PROP1(NAME, OUString, READONLY); - DECL_PROP2_IFACE(NUMBERFORMATSSUPPLIER, XNumberFormatsSupplier, READONLY, TRANSIENT); - DECL_PROP1(PASSWORD, OUString, TRANSIENT); - DECL_PROP2_IFACE(SETTINGS, XPropertySet, BOUND, READONLY); - DECL_PROP1_BOOL(SUPPRESSVERSIONCL, BOUND); - DECL_PROP1(TABLEFILTER, Sequence< OUString >,BOUND); - DECL_PROP1(TABLETYPEFILTER, Sequence< OUString >,BOUND); - DECL_PROP1(URL, OUString, BOUND); - DECL_PROP1(USER, OUString, BOUND); - END_PROPERTY_HELPER(); + 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 @@ -821,73 +747,59 @@ Reference< XPropertySetInfo > ODatabaseSource::getPropertySetInfo() sal_Bool ODatabaseSource::convertFastPropertyValue(Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) { - bool bModified(false); if ( m_pImpl.is() ) { switch (nHandle) { case PROPERTY_ID_TABLEFILTER: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aTableFilter); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aTableFilter); case PROPERTY_ID_TABLETYPEFILTER: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aTableTypeFilter); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aTableTypeFilter); case PROPERTY_ID_USER: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_sUser); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_sUser); case PROPERTY_ID_PASSWORD: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aPassword); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aPassword); case PROPERTY_ID_ISPASSWORDREQUIRED: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_bPasswordRequired); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_bPasswordRequired); case PROPERTY_ID_SUPPRESSVERSIONCL: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_bSuppressVersionColumns); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_bSuppressVersionColumns); case PROPERTY_ID_LAYOUTINFORMATION: - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aLayoutInformation); - break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_aLayoutInformation); case PROPERTY_ID_URL: - { - bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_sConnectURL); - } break; + return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_pImpl->m_sConnectURL); case PROPERTY_ID_INFO: { Sequence<PropertyValue> aValues; if (!(rValue >>= aValues)) throw IllegalArgumentException(); - for ( auto const & checkName : std::as_const(aValues) ) + for (auto const& checkName : aValues) { if ( checkName.Name.isEmpty() ) throw IllegalArgumentException(); } Sequence< PropertyValue > aSettings = m_pImpl->m_xSettings->getPropertyValues(); - bModified = aSettings.getLength() != aValues.getLength(); - if ( !bModified ) - { - const PropertyValue* pInfoIter = aSettings.getConstArray(); - const PropertyValue* checkValue = aValues.getConstArray(); - for ( ;!bModified && checkValue != aValues.end() ; ++checkValue,++pInfoIter) - { - bModified = checkValue->Name != pInfoIter->Name; - if ( !bModified ) - { - bModified = checkValue->Value != pInfoIter->Value; - } - } - } rConvertedValue = rValue; rOldValue <<= aSettings; + + if (aSettings.getLength() != aValues.getLength()) + return true; + + for (sal_Int32 i = 0; i < aSettings.getLength(); ++i) + { + if (aValues[i].Name != aSettings[i].Name + || aValues[i].Value != aSettings[i].Value) + return true; + } } break; default: SAL_WARN("dbaccess", "ODatabaseSource::convertFastPropertyValue: unknown or readonly Property!" ); } } - return bModified; + return false; } namespace @@ -1049,13 +961,15 @@ void ODatabaseSource::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) con // transform them so that only property values which fulfill certain // criteria survive Sequence< PropertyValue > aNonDefaultOrUserDefined( aValues.getLength() ); + auto [begin, end] = asNonConstRange(aValues); + auto pCopyStart = aNonDefaultOrUserDefined.getArray(); const PropertyValue* pCopyEnd = std::remove_copy_if( - aValues.begin(), - aValues.end(), - aNonDefaultOrUserDefined.getArray(), + begin, + end, + pCopyStart, IsDefaultAndNotRemoveable( aPropertyAttributes ) ); - aNonDefaultOrUserDefined.realloc( pCopyEnd - aNonDefaultOrUserDefined.getArray() ); + aNonDefaultOrUserDefined.realloc( pCopyEnd - pCopyStart ); rValue <<= aNonDefaultOrUserDefined; } catch( const Exception& ) @@ -1137,8 +1051,8 @@ Reference< XConnection > ODatabaseSource::connectWithCompletion( const Reference // build an interaction request // two continuations (Ok and Cancel) - OInteractionAbort* pAbort = new OInteractionAbort; - OAuthenticationContinuation* pAuthenticate = new OAuthenticationContinuation; + rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort; + rtl::Reference<OAuthenticationContinuation> pAuthenticate = new OAuthenticationContinuation; // the name which should be referred in the login dialog OUString sServerName( m_pImpl->m_sName ); @@ -1153,8 +1067,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; - OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); - Reference< XInteractionRequest > xRequest(pRequest); + rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(Any(aRequest)); // some knittings pRequest->addContinuation(pAbort); pRequest->addContinuation(pAuthenticate); @@ -1162,7 +1075,7 @@ Reference< XConnection > ODatabaseSource::connectWithCompletion( const Reference // handle the request try { - _rxHandler->handle(xRequest); + _rxHandler->handle(pRequest); } catch(Exception&) { @@ -1229,10 +1142,9 @@ Reference< XConnection > ODatabaseSource::getConnection(const OUString& user, co { // create a new proxy for the connection if ( !m_pImpl->m_xSharedConnectionManager.is() ) { - m_pImpl->m_pSharedConnectionManager = new OSharedConnectionManager( m_pImpl->m_aContext ); - 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 ); } @@ -1269,14 +1181,13 @@ Reference< XNameAccess > SAL_CALL ODatabaseSource::getQueryDefinitions( ) aValue >>= sSupportService; if ( !sSupportService.isEmpty() ) { - Sequence<Any> aArgs(1); - aArgs[0] <<= 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; @@ -1292,7 +1203,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; } diff --git a/dbaccess/source/core/dataaccess/datasource.hxx b/dbaccess/source/core/dataaccess/datasource.hxx index 3a5c0bc3da0f..5b5985eacd72 100644 --- a/dbaccess/source/core/dataaccess/datasource.hxx +++ b/dbaccess/source/core/dataaccess/datasource.hxx @@ -30,6 +30,7 @@ #include <com/sun/star/document/XEventListener.hpp> #include <com/sun/star/util/XFlushable.hpp> #include <cppuhelper/propshlp.hxx> +#include <comphelper/interfacecontainer3.hxx> #include <comphelper/proparrhlp.hxx> #include <cppuhelper/weakref.hxx> #include <cppuhelper/compbase.hxx> @@ -83,7 +84,7 @@ private: using ODatabaseSource_Base::rBHelper; // note: this thing uses the ref-count of "this", see OBookmarkContainer::acquire! OBookmarkContainer m_Bookmarks; - ::comphelper::OInterfaceContainerHelper2 m_aFlushListeners; + ::comphelper::OInterfaceContainerHelper3<css::util::XFlushListener> m_aFlushListeners; private: virtual ~ODatabaseSource() override; @@ -121,8 +122,8 @@ public: // css::uno::XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw( ) override; - virtual void SAL_CALL release() throw( ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // css::lang::XServiceInfo virtual OUString SAL_CALL getImplementationName( ) override; diff --git a/dbaccess/source/core/dataaccess/definitioncontainer.cxx b/dbaccess/source/core/dataaccess/definitioncontainer.cxx index 4788c4d03d7a..807dc5ec98c3 100644 --- a/dbaccess/source/core/dataaccess/definitioncontainer.cxx +++ b/dbaccess/source/core/dataaccess/definitioncontainer.cxx @@ -18,11 +18,12 @@ */ #include <definitioncontainer.hxx> -#include <apitools.hxx> #include <core_resource.hxx> #include <strings.hrc> +#include <strings.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <comphelper/enumhelper.hxx> #include <cppuhelper/exc_hlp.hxx> @@ -32,7 +33,6 @@ #include <com/sun/star/sdb/ErrorCondition.hpp> #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> -#include <cppuhelper/interfacecontainer.hxx> #include <rtl/ref.hxx> using namespace ::com::sun::star::uno; @@ -135,7 +135,14 @@ ODefinitionContainer::~ODefinitionContainer() } IMPLEMENT_FORWARD_XINTERFACE2( ODefinitionContainer,OContentHelper,ODefinitionContainer_Base) -IMPLEMENT_GETTYPES2(ODefinitionContainer,OContentHelper,ODefinitionContainer_Base); +css::uno::Sequence< css::uno::Type > ODefinitionContainer::getTypes() +{ + return ::comphelper::concatSequences( + OContentHelper::getTypes( ), + ODefinitionContainer_Base::getTypes( ) + ); +} + css::uno::Sequence<sal_Int8> ODefinitionContainer::getImplementationId() { @@ -265,7 +272,7 @@ namespace if ( eVetoDetails >>= aWrappedError ) throw aWrappedError; - throw WrappedTargetException( xVeto->getReason(), Listener.get(), eVetoDetails ); + throw WrappedTargetException( xVeto->getReason(), Listener, eVetoDetails ); } }; } @@ -280,7 +287,7 @@ void ODefinitionContainer::notifyByName( ResettableMutexGuard& _rGuard, const OU if ( !rContainer.getLength() ) return; - ContainerEvent aEvent( *this, makeAny( _rName ), makeAny( _xNewElement ), makeAny( _xOldElement ) ); + ContainerEvent aEvent( *this, Any( _rName ), Any( _xNewElement ), Any( _xOldElement ) ); _rGuard.clear(); switch ( _eOperation ) @@ -366,7 +373,7 @@ Any SAL_CALL ODefinitionContainer::getByIndex( sal_Int32 _nIndex ) { MutexGuard aGuard(m_aMutex); - if ((_nIndex < 0) || (_nIndex >= static_cast<sal_Int32>(m_aDocuments.size()))) + if ((_nIndex < 0) || (o3tl::make_unsigned(_nIndex) >= m_aDocuments.size())) throw IndexOutOfBoundsException(); Documents::iterator aPos = m_aDocuments[_nIndex]; @@ -379,14 +386,14 @@ Any SAL_CALL ODefinitionContainer::getByIndex( sal_Int32 _nIndex ) // and update the name-access map } - return makeAny(xProp); + return Any(xProp); } Any SAL_CALL ODefinitionContainer::getByName( const OUString& _rName ) { MutexGuard aGuard(m_aMutex); - return makeAny( implGetByName( _rName, true ) ); + return Any( implGetByName( _rName, true ) ); } Reference< XContent > ODefinitionContainer::implGetByName(const OUString& _rName, bool _bReadIfNecessary) @@ -526,7 +533,7 @@ void ODefinitionContainer::implAppend(const OUString& _rName, const Reference< X // #i44786# lcl_ensureName( _rxNewObject, _rName ); - ::rtl::Reference< OContentHelper > pContent = comphelper::getUnoTunnelImplementation<OContentHelper>( _rxNewObject ); + ::rtl::Reference< OContentHelper > pContent = dynamic_cast<OContentHelper*>( _rxNewObject.get() ); if ( pContent.is() ) { TContentPtr pImpl = pContent->getImpl(); @@ -585,7 +592,7 @@ void ODefinitionContainer::approveNewObject(const OUString& _sName,const Referen DBA_RES( RID_STR_NAME_ALREADY_USED ), *this ); - ::rtl::Reference< OContentHelper > pContent( comphelper::getUnoTunnelImplementation<OContentHelper>( _rxObject ) ); + ::rtl::Reference< OContentHelper > pContent( dynamic_cast<OContentHelper*>( _rxObject.get() ) ); if ( !pContent.is() ) throw IllegalArgumentException( DBA_RES( RID_STR_OBJECT_CONTAINER_MISMATCH ), diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 9d88d27222f5..e8ea1dd63869 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -34,6 +34,7 @@ #include <connectivity/sqlerror.hxx> #include <core_resource.hxx> #include <strings.hrc> +#include <strings.hxx> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/servicehelper.hxx> @@ -41,6 +42,7 @@ #include <vcl/svapp.hxx> #include <osl/mutex.hxx> +#include <o3tl/string_view.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -50,7 +52,6 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::ucb; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdb; -using namespace ::com::sun::star::io; using namespace ::osl; using namespace ::comphelper; using namespace ::cppu; @@ -115,14 +116,47 @@ css::uno::Sequence<sal_Int8> ODocumentContainer::getImplementationId() return css::uno::Sequence<sal_Int8>(); } -IMPLEMENT_GETTYPES3(ODocumentContainer,ODefinitionContainer,OPropertyStateContainer,ODocumentContainer_Base); -IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer, "com.sun.star.comp.dba.ODocumentContainer"); -IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer); -IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer) +css::uno::Sequence< css::uno::Type > ODocumentContainer::getTypes() +{ + return ::comphelper::concatSequences( + ODefinitionContainer::getTypes( ), + OPropertyStateContainer::getTypes( ), + ODocumentContainer_Base::getTypes( ) + ); +} +OUString SAL_CALL ODocumentContainer::getImplementationName() + { + return "com.sun.star.comp.dba.ODocumentContainer"; + }; +sal_Bool SAL_CALL ODocumentContainer::supportsService(const OUString& _rServiceName) + { + const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames()); + for (const OUString& s : aSupported) + if (s == _rServiceName) + return true; + + return false; + }; +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODocumentContainer::getPropertySetInfo() +{ + Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} +::cppu::IPropertyArrayHelper& ODocumentContainer::getInfoHelper() +{ + return *ODocumentContainer::getArrayHelper(); +} +::cppu::IPropertyArrayHelper* ODocumentContainer::createArrayHelper( ) const +{ + css::uno::Sequence< css::beans::Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} + Sequence< OUString > SAL_CALL ODocumentContainer::getSupportedServiceNames( ) { - return { m_bFormsContainer ? OUString(SERVICE_NAME_FORM_COLLECTION) : OUString(SERVICE_NAME_REPORT_COLLECTION) }; + return { m_bFormsContainer ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION }; } OUString ODocumentContainer::determineContentType() const @@ -218,9 +252,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments const bool bNeedClassID = !aClassID.hasElements() && sURL.isEmpty() ; if ( xCopyFrom.is() ) { - Sequence<Any> aIni(2); - aIni[0] <<= getContainerStorage(); - aIni[1] <<= sPersistentName; + Sequence<Any> aIni{ Any(getContainerStorage()), Any(sPersistentName) }; Command aCommand; aCommand.Name = "copyTo"; aCommand.Argument <<= aIni; @@ -279,8 +311,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments if ( !sURL.isEmpty() ) { - Sequence<Any> aIni(2); - aIni[0] <<= sURL; + Sequence<Any> aIni{ Any(sURL) }; Command aCommand; aCommand.Name = "insert"; aCommand.Argument <<= aIni; @@ -293,14 +324,12 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments } else if ( ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION || SERVICE_NAME_REPORT_COLLECTION == ServiceSpecifier ) { - const Any* pBegin = _aArguments.getConstArray(); - const Any* pEnd = pBegin + _aArguments.getLength(); - PropertyValue aValue; OUString sName; Reference<XNameAccess> xCopyFrom; - for(;pBegin != pEnd;++pBegin) + for (auto& arg : _aArguments) { - *pBegin >>= aValue; + PropertyValue aValue; + arg >>= aValue; if ( aValue.Name == PROPERTY_NAME) { aValue.Value >>= sName; @@ -328,21 +357,18 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments // copy children if ( xCopyFrom.is() ) { - Sequence< OUString> aSeq = xCopyFrom->getElementNames(); - const OUString* elements = aSeq.getConstArray(); - const OUString* elementsEnd = elements + aSeq.getLength(); Reference<XContent> xObjectToCopy; Reference<XMultiServiceFactory> xORB(xContent,UNO_QUERY); OSL_ENSURE(xORB.is(),"No service factory given"); if ( xORB.is() ) { - for(;elements != elementsEnd;++elements) + for (auto& element : xCopyFrom->getElementNames()) { - xCopyFrom->getByName(*elements) >>= xObjectToCopy; + xCopyFrom->getByName(element) >>= xObjectToCopy; Sequence<Any> aArguments(comphelper::InitAnyPropertySequence( { - {"Name", Any(*elements)}, // set as folder + {"Name", Any(element)}, // set as folder {"Parent", Any(xContent)}, {PROPERTY_EMBEDDEDOBJECT, Any(xObjectToCopy)}, })); @@ -361,7 +387,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments Reference<XContent > xNew(xORB->createInstanceWithArguments(sServiceName,aArguments),UNO_QUERY); Reference<XNameContainer> xNameContainer(xContent,UNO_QUERY); if ( xNameContainer.is() ) - xNameContainer->insertByName(*elements,makeAny(xNew)); + xNameContainer->insertByName(element, Any(xNew)); } } } @@ -372,11 +398,12 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments Sequence< OUString > SAL_CALL ODocumentContainer::getAvailableServiceNames( ) { - Sequence< OUString > aSe(3); - aSe[0] = SERVICE_SDB_DOCUMENTDEFINITION; - aSe[1] = SERVICE_NAME_FORM_COLLECTION; - aSe[2] = SERVICE_NAME_REPORT_COLLECTION; - return aSe; + return + { + SERVICE_SDB_DOCUMENTDEFINITION, + SERVICE_NAME_FORM_COLLECTION, + SERVICE_NAME_REPORT_COLLECTION + }; } Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) @@ -390,7 +417,7 @@ Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 Com { OSL_FAIL( "Wrong argument type!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -412,12 +439,12 @@ Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 Com aOpenCommand, Environment ); aRet <<= xSet; - } + } else { // Unsupported. ucbhelper::cancelCommandExecution( - makeAny( UnsupportedOpenModeException( + Any( UnsupportedOpenModeException( OUString(), static_cast< cppu::OWeakObject * >( this ), sal_Int16( aOpenCommand.Mode ) ) ), @@ -434,7 +461,7 @@ Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 Com { OSL_FAIL( "Wrong argument type!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -445,11 +472,8 @@ Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 Com else if ( aCommand.Name == "delete" ) { // delete - Sequence< OUString> aSeq = getElementNames(); - const OUString* pIter = aSeq.getConstArray(); - const OUString* pEnd = pIter + aSeq.getLength(); - for(;pIter != pEnd;++pIter) - removeByName(*pIter); + for (auto& name : getElementNames()) + removeByName(name); dispose(); } @@ -460,10 +484,10 @@ Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 Com namespace { - bool lcl_queryContent(const OUString& _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,OUString& _sSimpleName) + bool lcl_queryContent(std::u16string_view _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,OUString& _sSimpleName) { sal_Int32 nIndex = 0; - OUString sName = _sName.getToken(0,'/',nIndex); + OUString sName( o3tl::getToken(_sName,0,'/',nIndex) ); bool bRet = _xNameContainer->hasByName(sName); if ( bRet ) { @@ -471,7 +495,7 @@ namespace _rRet = _xNameContainer->getByName(_sSimpleName); while ( nIndex != -1 && bRet ) { - sName = _sName.getToken(0,'/',nIndex); + sName = o3tl::getToken(_sName,0,'/',nIndex); _xNameContainer.set(_rRet,UNO_QUERY); bRet = _xNameContainer.is(); if ( bRet ) @@ -579,7 +603,7 @@ void SAL_CALL ODocumentContainer::insertByHierarchicalName( const OUString& _sNa sal_Int32 index = sName.getLength(); OUString sMessage( DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirst("$folder$", - _sName.getToken(0,'/',index))); + o3tl::getToken(_sName, 0,'/',index))); throw IllegalArgumentException( sMessage, *this, 1 ); } @@ -635,7 +659,7 @@ OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const OUString& i ::rtl::Reference<OContentHelper> pContent; try { - pContent = comphelper::getUnoTunnelImplementation<OContentHelper>(const_cast<ODocumentContainer*>(this)->implGetByName( _sName, true )); + pContent = dynamic_cast<OContentHelper*>(const_cast<ODocumentContainer*>(this)->implGetByName( _sName, true ).get()); } catch(const Exception&) { @@ -679,7 +703,7 @@ void SAL_CALL ODocumentContainer::revert( ) Reference< XStorage> ODocumentContainer::getContainerStorage() const { return m_pImpl->m_pDataSource - ? m_pImpl->m_pDataSource->getStorage( m_bFormsContainer ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) + ? m_pImpl->m_pDataSource->getStorage( m_bFormsContainer ? ODatabaseModelImpl::ObjectType::Form : ODatabaseModelImpl::ObjectType::Report ) : Reference< XStorage>(); } @@ -718,8 +742,8 @@ void SAL_CALL ODocumentContainer::rename( const OUString& newName ) return; sal_Int32 nHandle = PROPERTY_ID_NAME; - Any aOld = makeAny(m_pImpl->m_aProps.aTitle); - Any aNew = makeAny(newName); + Any aOld(m_pImpl->m_aProps.aTitle); + Any aNew(newName); aGuard.clear(); fire(&nHandle, &aNew, &aOld, 1, true ); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 2778a616597e..922d10c3b595 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -21,16 +21,19 @@ #include <ModelImpl.hxx> #include <stringconstants.hxx> #include <sdbcoretools.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> +#include <comphelper/compbase.hxx> #include <comphelper/sequence.hxx> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/classids.hxx> #include <comphelper/propertysequence.hxx> +#include <comphelper/propertyvalue.hxx> #include <comphelper/types.hxx> #include <com/sun/star/frame/XUntitledNumbers.hpp> #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/XModel.hpp> @@ -75,6 +78,7 @@ #include <com/sun/star/view/XViewSettingsSupplier.hpp> #include <core_resource.hxx> #include <strings.hrc> +#include <strings.hxx> #include <com/sun/star/task/XInteractionApprove.hpp> #include <com/sun/star/task/XInteractionDisapprove.hpp> #include <com/sun/star/frame/XLayoutManager.hpp> @@ -144,22 +148,20 @@ namespace dbaccess } // OEmbedObjectHolder - typedef ::cppu::WeakComponentImplHelper< embed::XStateChangeListener > TEmbedObjectHolder; + typedef ::comphelper::WeakComponentImplHelper< embed::XStateChangeListener > TEmbedObjectHolder; namespace { - class OEmbedObjectHolder : public ::cppu::BaseMutex - ,public TEmbedObjectHolder + class OEmbedObjectHolder : public TEmbedObjectHolder { Reference< XEmbeddedObject > m_xBroadCaster; ODocumentDefinition* m_pDefinition; bool m_bInStateChange; protected: - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; public: OEmbedObjectHolder(const Reference< XEmbeddedObject >& _xBroadCaster,ODocumentDefinition* _pDefinition) - : TEmbedObjectHolder(m_aMutex) - ,m_xBroadCaster(_xBroadCaster) + : m_xBroadCaster(_xBroadCaster) ,m_pDefinition(_pDefinition) ,m_bInStateChange(false) { @@ -178,7 +180,7 @@ namespace dbaccess } - void SAL_CALL OEmbedObjectHolder::disposing() + void OEmbedObjectHolder::disposing(std::unique_lock<std::mutex>& /*rGuard*/) { if ( m_xBroadCaster.is() ) m_xBroadCaster->removeStateChangeListener(this); @@ -474,21 +476,28 @@ css::uno::Sequence<sal_Int8> ODocumentDefinition::getImplementationId() return css::uno::Sequence<sal_Int8>(); } -IMPLEMENT_GETTYPES3(ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base); +css::uno::Sequence< css::uno::Type > ODocumentDefinition::getTypes() +{ + return ::comphelper::concatSequences( + OContentHelper::getTypes( ), + OPropertyStateContainer::getTypes( ), + ODocumentDefinition_Base::getTypes( ) + ); +} IMPLEMENT_FORWARD_XINTERFACE3( ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base) void ODocumentDefinition::registerProperties() { -#define REGISTER_PROPERTY( name, location ) \ - registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::READONLY, &location, cppu::UnoType<decltype(location)>::get() ); + registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::READONLY, + &m_pImpl->m_aProps.aTitle, cppu::UnoType<decltype(m_pImpl->m_aProps.aTitle)>::get()); + + registerProperty(PROPERTY_AS_TEMPLATE, PROPERTY_ID_AS_TEMPLATE, PropertyAttribute::READONLY, &m_pImpl->m_aProps.bAsTemplate, + cppu::UnoType<decltype(m_pImpl->m_aProps.bAsTemplate)>::get()); -#define REGISTER_PROPERTY_BV( name, location ) \ - registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::READONLY, &location, cppu::UnoType<decltype(location)>::get() ); + registerProperty(PROPERTY_PERSISTENT_NAME, PROPERTY_ID_PERSISTENT_NAME, PropertyAttribute::READONLY, &m_pImpl->m_aProps.sPersistentName, + cppu::UnoType<decltype(m_pImpl->m_aProps.sPersistentName)>::get()); - REGISTER_PROPERTY_BV( NAME, m_pImpl->m_aProps.aTitle ); - REGISTER_PROPERTY ( AS_TEMPLATE, m_pImpl->m_aProps.bAsTemplate ); - REGISTER_PROPERTY ( PERSISTENT_NAME, m_pImpl->m_aProps.sPersistentName ); - REGISTER_PROPERTY ( IS_FORM, m_bForm ); + registerProperty(PROPERTY_IS_FORM, PROPERTY_ID_IS_FORM, PropertyAttribute::READONLY, &m_bForm, cppu::UnoType<decltype(m_bForm)>::get()); } void SAL_CALL ODocumentDefinition::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const @@ -498,11 +507,8 @@ void SAL_CALL ODocumentDefinition::getFastPropertyValue( Any& o_rValue, sal_Int3 OUString sPersistentPath; if ( !m_pImpl->m_aProps.sPersistentName.isEmpty() ) { - OUStringBuffer aBuffer; - aBuffer.append( ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) ); - aBuffer.append( '/' ); - aBuffer.append( m_pImpl->m_aProps.sPersistentName ); - sPersistentPath = aBuffer.makeStringAndClear(); + sPersistentPath = ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::ObjectType::Form : ODatabaseModelImpl::ObjectType::Report ) + + "/" + m_pImpl->m_aProps.sPersistentName; } o_rValue <<= sPersistentPath; return; @@ -529,11 +535,10 @@ IPropertyArrayHelper* ODocumentDefinition::createArrayHelper( ) const describeProperties( aProps ); // properties not maintained by our base class - Sequence< Property > aManualProps( 1 ); - aManualProps[0].Name = PROPERTY_PERSISTENT_PATH; - aManualProps[0].Handle = PROPERTY_ID_PERSISTENT_PATH; - aManualProps[0].Type = ::cppu::UnoType<OUString>::get(); - aManualProps[0].Attributes = PropertyAttribute::READONLY; + Sequence< Property > aManualProps{ { /* Name */ PROPERTY_PERSISTENT_PATH, + /* Handle */ PROPERTY_ID_PERSISTENT_PATH, + /* Type */ ::cppu::UnoType<OUString>::get(), + /* Attributes */ PropertyAttribute::READONLY } }; return new OPropertyArrayHelper( ::comphelper::concatSequences( aProps, aManualProps ) ); } @@ -596,7 +601,7 @@ void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( const bool i_bR // ensure that we ourself are kept alive as long as the embedded object's frame is // opened - LifetimeCoupler::couple( *this, xFrame.get() ); + LifetimeCoupler::couple( *this, xFrame ); // init the edit view if ( m_bForm && m_bOpenInDesign && !i_bReactivated ) @@ -715,14 +720,14 @@ void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& LayoutManagerLock aLockLayout( _rxController ); // setting of the visual properties - xViewSettings->setPropertyValue("ShowRulers",makeAny(true)); - xViewSettings->setPropertyValue("ShowVertRuler",makeAny(true)); - xViewSettings->setPropertyValue("ShowHoriRuler",makeAny(true)); - xViewSettings->setPropertyValue("IsRasterVisible",makeAny(true)); - xViewSettings->setPropertyValue("IsSnapToRaster",makeAny(true)); - xViewSettings->setPropertyValue("ShowOnlineLayout",makeAny(true)); - xViewSettings->setPropertyValue("RasterSubdivisionX",makeAny(sal_Int32(5))); - xViewSettings->setPropertyValue("RasterSubdivisionY",makeAny(sal_Int32(5))); + xViewSettings->setPropertyValue("ShowRulers",Any(true)); + xViewSettings->setPropertyValue("ShowVertRuler",Any(true)); + xViewSettings->setPropertyValue("ShowHoriRuler",Any(true)); + xViewSettings->setPropertyValue("IsRasterVisible",Any(true)); + xViewSettings->setPropertyValue("IsSnapToRaster",Any(true)); + xViewSettings->setPropertyValue("ShowOnlineLayout",Any(true)); + xViewSettings->setPropertyValue("RasterSubdivisionX",Any(sal_Int32(5))); + xViewSettings->setPropertyValue("RasterSubdivisionY",Any(sal_Int32(5))); } catch( const Exception& ) { @@ -786,29 +791,27 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons Sequence< PropertyValue > aArguments; if ( _rOpenArgument >>= aArguments ) { - const PropertyValue* pIter = aArguments.getConstArray(); - const PropertyValue* pEnd = pIter + aArguments.getLength(); - for ( ;pIter != pEnd; ++pIter ) + for (auto& arg : aArguments) { - if ( pIter->Name == PROPERTY_ACTIVE_CONNECTION ) + if (arg.Name == PROPERTY_ACTIVE_CONNECTION) { - xConnection.set( pIter->Value, UNO_QUERY ); + xConnection.set(arg.Value, UNO_QUERY); continue; } - if ( lcl_extractOpenMode( pIter->Value, nOpenMode ) ) + if (lcl_extractOpenMode(arg.Value, nOpenMode)) continue; - if ( pIter->Name == "MacroExecutionMode" ) + if (arg.Name == "MacroExecutionMode") { sal_Int16 nMacroExecMode( !aDocumentMacroMode ? MacroExecMode::USE_CONFIG : *aDocumentMacroMode ); - OSL_VERIFY( pIter->Value >>= nMacroExecMode ); + OSL_VERIFY(arg.Value >>= nMacroExecMode); aDocumentMacroMode = nMacroExecMode; continue; } // unknown argument -> pass to the loaded document - aDocumentArgs.put( pIter->Name, pIter->Value ); + aDocumentArgs.put(arg.Name, arg.Value); } } } @@ -846,7 +849,7 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons // So, in such a case, and with 2. above, we would silently execute those macros, // regardless of the global security settings - which would be a security issue, of // course. - if ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eNoMacros ) + if ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::EmbeddedMacros::NONE ) { // this is case 2. from above // So, pass a USE_CONFIG to the to-be-loaded document. This means that @@ -876,14 +879,14 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons { // not supported ucbhelper::cancelCommandExecution( - makeAny( UnsupportedOpenModeException( + Any( UnsupportedOpenModeException( OUString(), static_cast< cppu::OWeakObject * >( this ), sal_Int16( nOpenMode ) ) ), _rxEnvironment ); // Unreachable OSL_FAIL( "unreachable" ); - } + } OSL_ENSURE( !m_pImpl->m_aProps.sPersistentName.isEmpty(), "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!" ); @@ -924,8 +927,8 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons xReportEngine->setReportDefinition(xReportDefinition); xReportEngine->setActiveConnection(m_xLastKnownConnection); if ( bOpenHidden ) - return makeAny( xReportEngine->createDocumentModel() ); - return makeAny( xReportEngine->createDocumentAlive( nullptr ) ); + return Any( xReportEngine->createDocumentModel() ); + return Any( xReportEngine->createDocumentAlive( nullptr ) ); } if ( _bActivate && !bOpenHidden ) @@ -937,13 +940,13 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons else { // ensure that we ourself are kept alive as long as the document is open - LifetimeCoupler::couple( *this, xModel.get() ); + LifetimeCoupler::couple( *this, xModel ); } if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) ODocumentDefinition::fillReportData( m_aContext, getComponent(), xConnection ); - return makeAny( xModel ); + return Any( xModel ); } Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) @@ -990,7 +993,7 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co if ( !bIsAliveNewStyleReport ) { impl_onActivateEmbeddedObject_nothrow( true ); - return makeAny( getComponent() ); + return Any( getComponent() ); } } } @@ -1011,7 +1014,7 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co { OSL_FAIL( "Wrong argument type!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -1037,7 +1040,7 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co { OSL_FAIL( "Wrong argument count!" ); ucbhelper::cancelCommandExecution( - makeAny( IllegalArgumentException( + Any( IllegalArgumentException( OUString(), static_cast< cppu::OWeakObject * >( this ), -1 ) ), @@ -1108,7 +1111,7 @@ namespace try { Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW ); - xFormProps->setPropertyValue( PROPERTY_DATASOURCENAME, makeAny( OUString() ) ); + xFormProps->setPropertyValue( PROPERTY_DATASOURCENAME, Any( OUString() ) ); } catch( const Exception& ) { @@ -1154,7 +1157,7 @@ void ODocumentDefinition::onCommandInsert( const OUString& _sURL, const Referenc Sequence<OUString> aProps { PROPERTY_URL }; ucbhelper::cancelCommandExecution( - makeAny( MissingPropertiesException( + Any( MissingPropertiesException( OUString(), static_cast< cppu::OWeakObject * >( this ), aProps ) ), @@ -1168,9 +1171,9 @@ void ODocumentDefinition::onCommandInsert( const OUString& _sURL, const Referenc if ( xStorage.is() ) { Reference< XEmbeddedObjectCreator> xEmbedFactory = EmbeddedObjectCreator::create(m_aContext); - Sequence<PropertyValue> aEmpty,aMediaDesc(1); - aMediaDesc[0].Name = PROPERTY_URL; - aMediaDesc[0].Value <<= _sURL; + Sequence<PropertyValue> aEmpty; + Sequence<PropertyValue> aMediaDesc{ comphelper::makePropertyValue(PROPERTY_URL, + _sURL) }; m_xEmbeddedObject.set(xEmbedFactory->createInstanceInitFromMediaDescriptor( xStorage ,m_pImpl->m_aProps.sPersistentName ,aMediaDesc @@ -1224,11 +1227,10 @@ bool ODocumentDefinition::save(bool _bApprove, const css::uno::Reference<css::aw } aRequest.Content.set(m_xParentContainer,UNO_QUERY); - OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); - Reference< XInteractionRequest > xRequest(pRequest); + rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(Any(aRequest)); // some knittings // two continuations allowed: OK and Cancel - ODocumentSaveContinuation* pDocuSave = nullptr; + rtl::Reference<ODocumentSaveContinuation> pDocuSave; if ( m_pImpl->m_aProps.aTitle.isEmpty() ) { @@ -1237,21 +1239,21 @@ bool ODocumentDefinition::save(bool _bApprove, const css::uno::Reference<css::aw } if ( _bApprove ) { - OInteraction< XInteractionApprove >* pApprove = new OInteraction< XInteractionApprove >; + rtl::Reference<OInteraction< XInteractionApprove >> pApprove = new OInteraction< XInteractionApprove >; pRequest->addContinuation(pApprove); } - OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >; + rtl::Reference<OInteraction< XInteractionDisapprove >> pDisApprove = new OInteraction< XInteractionDisapprove >; pRequest->addContinuation(pDisApprove); - OInteractionAbort* pAbort = new OInteractionAbort; + rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort; pRequest->addContinuation(pAbort); Reference<XWindow> xDialogParent(rDialogParent, UNO_QUERY); // create the handler, let it handle the request Reference<XInteractionHandler2> xHandler(InteractionHandler::createWithParent(m_aContext, xDialogParent)); - xHandler->handle(xRequest); + xHandler->handle(pRequest); if ( pAbort->wasSelected() ) return false; @@ -1266,7 +1268,7 @@ bool ODocumentDefinition::save(bool _bApprove, const css::uno::Reference<css::aw m_pImpl->m_aProps.aTitle = pDocuSave->getName(); Reference< XContent> xContent = this; - xNC->insertByName(pDocuSave->getName(),makeAny(xContent)); + xNC->insertByName(pDocuSave->getName(),Any(xContent)); updateDocumentTitle(); } @@ -1311,20 +1313,19 @@ void ODocumentDefinition::saveAs() aRequest.Name = m_pImpl->m_aProps.aTitle; aRequest.Content.set(m_xParentContainer,UNO_QUERY); - OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); - Reference< XInteractionRequest > xRequest(pRequest); + rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(Any(aRequest)); // some knittings // two continuations allowed: OK and Cancel - ODocumentSaveContinuation* pDocuSave = new ODocumentSaveContinuation; + rtl::Reference<ODocumentSaveContinuation> pDocuSave = new ODocumentSaveContinuation; pRequest->addContinuation(pDocuSave); - OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >; + rtl::Reference<OInteraction< XInteractionDisapprove >> pDisApprove = new OInteraction< XInteractionDisapprove >; pRequest->addContinuation(pDisApprove); - OInteractionAbort* pAbort = new OInteractionAbort; + rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort; pRequest->addContinuation(pAbort); // create the handler, let it handle the request Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(m_aContext, nullptr) ); - xHandler->handle(xRequest); + xHandler->handle(pRequest); if ( pAbort->wasSelected() ) return; @@ -1358,7 +1359,7 @@ void ODocumentDefinition::saveAs() Reference< XMultiServiceFactory > xORB( m_xParentContainer, UNO_QUERY_THROW ); Reference< XInterface > xComponent( xORB->createInstanceWithArguments( SERVICE_SDB_DOCUMENTDEFINITION, aArguments ) ); Reference< XNameContainer > xNameContainer( m_xParentContainer, UNO_QUERY_THROW ); - xNameContainer->insertByName( sOldName, makeAny( xComponent ) ); + xNameContainer->insertByName( sOldName, Any( xComponent ) ); } catch(const Exception&) { @@ -1384,7 +1385,7 @@ namespace { void lcl_putLoadArgs( ::comphelper::NamedValueCollection& _io_rArgs, const optional_bool& _bSuppressMacros, const optional_bool& _bReadOnly ) { - if ( !!_bSuppressMacros ) + if ( _bSuppressMacros.has_value() ) { if ( *_bSuppressMacros ) { @@ -1401,7 +1402,7 @@ namespace } } - if ( !!_bReadOnly ) + if ( _bReadOnly.has_value() ) _io_rArgs.put( "ReadOnly", *_bReadOnly ); } } @@ -1427,7 +1428,7 @@ namespace bool ODocumentDefinition::objectSupportsEmbeddedScripts() const { bool bAllowDocumentMacros = !m_pImpl->m_pDataSource - || ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eSubDocumentMacros ); + || ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::EmbeddedMacros::SubDocument ); // if *any* of the objects of the database document already has macros, we // continue to allow it to have them, until the user does a migration. @@ -1446,16 +1447,14 @@ void ODocumentDefinition::separateOpenCommandArguments( const Sequence< Property { ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments ); - const char* const pObjectDescriptorArgs[] = - { - "RecoveryStorage" - }; - for (const char* pObjectDescriptorArg : pObjectDescriptorArgs) + static const std::u16string_view sObjectDescriptorArgs[] = { u"RecoveryStorage" }; + for (const auto& rObjectDescriptorArg : sObjectDescriptorArgs) { - if ( aOpenCommandArguments.has( pObjectDescriptorArg ) ) + const OUString sObjectDescriptorArg(rObjectDescriptorArg); + if ( aOpenCommandArguments.has( sObjectDescriptorArg ) ) { - o_rEmbeddedObjectDescriptor.put( pObjectDescriptorArg, aOpenCommandArguments.get( pObjectDescriptorArg ) ); - aOpenCommandArguments.remove( pObjectDescriptorArg ); + o_rEmbeddedObjectDescriptor.put( sObjectDescriptorArg, aOpenCommandArguments.get( sObjectDescriptorArg ) ); + aOpenCommandArguments.remove( sObjectDescriptorArg ); } } @@ -1473,7 +1472,7 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC } m_pInterceptor = new OInterceptor( this ); - Reference<XDispatchProviderInterceptor> xInterceptor = m_pInterceptor.get(); + Reference<XDispatchProviderInterceptor> xInterceptor = m_pInterceptor; ::comphelper::NamedValueCollection aEmbeddedDescriptor; aEmbeddedDescriptor.put( "OutplaceDispatchInterceptor", xInterceptor ); @@ -1565,9 +1564,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_ Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName); if ( !xEnumDrivers.is() || !xEnumDrivers->hasMoreElements() ) { - css::io::WrongFormatException aWFE; - aWFE.Message = DBA_RES( RID_STR_MISSING_EXTENSION ); - throw aWFE; + throw css::io::WrongFormatException(DBA_RES(RID_STR_MISSING_EXTENSION)); } } if ( !aClassID.hasElements() ) @@ -1601,8 +1598,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_ { m_pClientHelper = new OEmbeddedClientHelper; } - Reference<XEmbeddedClient> xClient = m_pClientHelper.get(); - m_xEmbeddedObject->setClientSite(xClient); + m_xEmbeddedObject->setClientSite(m_pClientHelper); m_xEmbeddedObject->changeState(EmbedStates::RUNNING); if ( bSetSize ) { @@ -1623,8 +1619,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_ { m_pClientHelper = new OEmbeddedClientHelper; } - Reference<XEmbeddedClient> xClient = m_pClientHelper.get(); - m_xEmbeddedObject->setClientSite(xClient); + m_xEmbeddedObject->setClientSite(m_pClientHelper); Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( @@ -1896,11 +1891,7 @@ OUString SAL_CALL ODocumentDefinition::getHierarchicalName() OUString SAL_CALL ODocumentDefinition::composeHierarchicalName( const OUString& i_rRelativeName ) { - OUStringBuffer aBuffer; - aBuffer.append( getHierarchicalName() ); - aBuffer.append( '/' ); - aBuffer.append( i_rRelativeName ); - return aBuffer.makeStringAndClear(); + return getHierarchicalName() + "/" + i_rRelativeName; } void SAL_CALL ODocumentDefinition::rename( const OUString& _rNewName ) @@ -1931,7 +1922,7 @@ void SAL_CALL ODocumentDefinition::rename( const OUString& _rNewName ) Reference< XStorage> ODocumentDefinition::getContainerStorage() const { return m_pImpl->m_pDataSource - ? m_pImpl->m_pDataSource->getStorage( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) + ? m_pImpl->m_pDataSource->getStorage( m_bForm ? ODatabaseModelImpl::ObjectType::Form : ODatabaseModelImpl::ObjectType::Report ) : Reference< XStorage>(); } @@ -2081,8 +2072,8 @@ void ODocumentDefinition::firePropertyChange( sal_Int32 i_nHandle, const Any& i_ NameChangeNotifier::NameChangeNotifier( ODocumentDefinition& i_rDocumentDefinition, const OUString& i_rNewName, ::osl::ResettableMutexGuard& i_rClearForNotify ) :m_rDocumentDefinition( i_rDocumentDefinition ) - ,m_aOldValue( makeAny( i_rDocumentDefinition.getCurrentName() ) ) - ,m_aNewValue( makeAny( i_rNewName ) ) + ,m_aOldValue( Any( i_rDocumentDefinition.getCurrentName() ) ) + ,m_aNewValue( Any( i_rNewName ) ) ,m_rClearForNotify( i_rClearForNotify ) { impl_fireEvent_throw( true ); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 389ab601f2ab..5569276d4a7d 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -207,7 +207,7 @@ private: @throws css::uno::RuntimeException */ static void impl_removeFrameFromDesktop_throw( - const css::uno::Reference< css::uno::XComponentContext >& _rContxt, + const css::uno::Reference< css::uno::XComponentContext >& _rContext, const css::uno::Reference< css::frame::XFrame >& _rxFrame ); diff --git a/dbaccess/source/core/dataaccess/documenteventexecutor.cxx b/dbaccess/source/core/dataaccess/documenteventexecutor.cxx index 3d16ee6ebb79..e1cb9f3f4e57 100644 --- a/dbaccess/source/core/dataaccess/documenteventexecutor.cxx +++ b/dbaccess/source/core/dataaccess/documenteventexecutor.cxx @@ -27,7 +27,7 @@ #include <comphelper/namedvaluecollection.hxx> #include <cppuhelper/weakref.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <vcl/svapp.hxx> namespace dbaccess @@ -57,24 +57,14 @@ namespace dbaccess using namespace ::com::sun::star; - // DocumentEventExecutor_Data - struct DocumentEventExecutor_Data - { - WeakReference< XEventsSupplier > xDocument; - Reference< XURLTransformer > xURLTransformer; - - explicit DocumentEventExecutor_Data( const Reference< XEventsSupplier >& _rxDocument ) - :xDocument( _rxDocument ) - { - } - }; - namespace { - void lcl_dispatchScriptURL_throw( DocumentEventExecutor_Data const & _rDocExecData, + void lcl_dispatchScriptURL_throw( + css::uno::WeakReference< css::document::XEventsSupplier > const & xWeakDocument, + css::uno::Reference< css::util::XURLTransformer > const & xURLTransformer, const OUString& _rScriptURL, const DocumentEvent& _rTrigger ) { - Reference< XModel > xDocument( _rDocExecData.xDocument.get(), UNO_QUERY_THROW ); + Reference< XModel > xDocument( xWeakDocument.get(), UNO_QUERY_THROW ); Reference< XController > xController( xDocument->getCurrentController() ); Reference< XDispatchProvider > xDispProv; @@ -88,8 +78,8 @@ namespace dbaccess URL aScriptURL; aScriptURL.Complete = _rScriptURL; - if ( _rDocExecData.xURLTransformer.is() ) - _rDocExecData.xURLTransformer->parseStrict( aScriptURL ); + if ( xURLTransformer.is() ) + xURLTransformer->parseStrict( aScriptURL ); // unfortunately, executing a script can trigger all kind of complex stuff, and unfortunately, not // every component involved into this properly cares for thread safety. To be on the safe side, @@ -113,7 +103,7 @@ namespace dbaccess // DocumentEventExecutor DocumentEventExecutor::DocumentEventExecutor( const Reference<XComponentContext> & _rContext, const Reference< XEventsSupplier >& _rxDocument ) - :m_pData( new DocumentEventExecutor_Data( _rxDocument ) ) + :mxDocument( _rxDocument ) { Reference< XDocumentEventBroadcaster > xBroadcaster( _rxDocument, UNO_QUERY_THROW ); @@ -125,7 +115,7 @@ namespace dbaccess try { - m_pData->xURLTransformer = URLTransformer::create(_rContext); + mxURLTransformer = URLTransformer::create(_rContext); } catch( const Exception& ) { @@ -139,8 +129,8 @@ namespace dbaccess void SAL_CALL DocumentEventExecutor::documentEventOccured( const DocumentEvent& Event ) { - Reference< XEventsSupplier > xEventsSupplier( m_pData->xDocument.get(), UNO_QUERY ); - if ( !xEventsSupplier.is() ) + Reference< XEventsSupplier > xEventsSupplier( mxDocument.get(), UNO_QUERY ); + if ( !xEventsSupplier ) { OSL_FAIL( "DocumentEventExecutor::documentEventOccurred: no document anymore, but still being notified?" ); return; @@ -179,7 +169,7 @@ namespace dbaccess if ( bDispatchScriptURL && bNonEmptyScript ) { - lcl_dispatchScriptURL_throw( *m_pData, sScript, Event ); + lcl_dispatchScriptURL_throw( mxDocument, mxURLTransformer, sScript, Event ); } } catch( const RuntimeException& ) { throw; } diff --git a/dbaccess/source/core/dataaccess/documenteventexecutor.hxx b/dbaccess/source/core/dataaccess/documenteventexecutor.hxx index 90dc9083c4a3..58aee4bcd590 100644 --- a/dbaccess/source/core/dataaccess/documenteventexecutor.hxx +++ b/dbaccess/source/core/dataaccess/documenteventexecutor.hxx @@ -23,15 +23,13 @@ #include <com/sun/star/document/XEventsSupplier.hpp> #include <cppuhelper/implbase.hxx> - -#include <memory> +#include <cppuhelper/weakref.hxx> namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::util { class XURLTransformer; } namespace dbaccess { - - struct DocumentEventExecutor_Data; // DocumentEventExecutor typedef ::cppu::WeakImplHelper < css::document::XDocumentEventListener > DocumentEventExecutor_Base; @@ -51,7 +49,8 @@ namespace dbaccess virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; private: - std::unique_ptr< DocumentEventExecutor_Data > m_pData; + css::uno::WeakReference< css::document::XEventsSupplier > mxDocument; + css::uno::Reference< css::util::XURLTransformer > mxURLTransformer; }; } // namespace dbaccess diff --git a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx index 13295523ef5f..475b16c0b551 100644 --- a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx +++ b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx @@ -22,9 +22,9 @@ #include <com/sun/star/frame/DoubleInitializationException.hpp> #include <comphelper/asyncnotification.hxx> -#include <comphelper/interfacecontainer2.hxx> +#include <comphelper/interfacecontainer3.hxx> #include <cppuhelper/weak.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <vcl/svapp.hxx> namespace dbaccess @@ -52,8 +52,8 @@ namespace dbaccess bool m_bInitialized; bool m_bDisposed; std::shared_ptr<::comphelper::AsyncEventNotifierAutoJoin> m_pEventBroadcaster; - ::comphelper::OInterfaceContainerHelper2 m_aLegacyEventListeners; - ::comphelper::OInterfaceContainerHelper2 m_aDocumentEventListeners; + ::comphelper::OInterfaceContainerHelper3<css::document::XEventListener> m_aLegacyEventListeners; + ::comphelper::OInterfaceContainerHelper3<XDocumentEventListener> m_aDocumentEventListeners; public: DocumentEventNotifier_Impl( ::cppu::OWeakObject& _rBroadcasterDocument, ::osl::Mutex& _rMutex ) @@ -68,8 +68,8 @@ namespace dbaccess } // IEventProcessor - virtual void SAL_CALL acquire() throw () override; - virtual void SAL_CALL release() throw () override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; void addLegacyEventListener( const Reference< document::XEventListener >& Listener ) { @@ -122,12 +122,12 @@ namespace dbaccess void impl_notifyEventAsync_nothrow( const DocumentEvent& _rEvent ); }; - void SAL_CALL DocumentEventNotifier_Impl::acquire() throw () + void SAL_CALL DocumentEventNotifier_Impl::acquire() noexcept { osl_atomic_increment( &m_refCount ); } - void SAL_CALL DocumentEventNotifier_Impl::release() throw () + void SAL_CALL DocumentEventNotifier_Impl::release() noexcept { if ( 0 == osl_atomic_decrement( &m_refCount ) ) delete this; diff --git a/dbaccess/source/core/dataaccess/documentevents.cxx b/dbaccess/source/core/dataaccess/documentevents.cxx index d3c6a03ceeec..6dbe9ad5965d 100644 --- a/dbaccess/source/core/dataaccess/documentevents.cxx +++ b/dbaccess/source/core/dataaccess/documentevents.cxx @@ -21,6 +21,7 @@ #include <com/sun/star/beans/PropertyValue.hpp> +#include <o3tl/string_view.hxx> #include <osl/diagnose.h> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/sequence.hxx> @@ -35,23 +36,6 @@ namespace dbaccess using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Type; - // DocumentEvents_Data - struct DocumentEvents_Data - { - ::cppu::OWeakObject& rParent; - ::osl::Mutex& rMutex; - DocumentEventsData& rEventsData; - - DocumentEvents_Data( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, DocumentEventsData& _rEventsData ) - :rParent( _rParent ) - ,rMutex( _rMutex ) - ,rEventsData( _rEventsData ) - { - } - DocumentEvents_Data(const DocumentEvents_Data&) = delete; - const DocumentEvents_Data& operator=(const DocumentEvents_Data&) = delete; - }; - namespace { // helper @@ -96,15 +80,15 @@ namespace dbaccess // DocumentEvents DocumentEvents::DocumentEvents( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, DocumentEventsData& _rEventsData ) - :m_pData( new DocumentEvents_Data( _rParent, _rMutex, _rEventsData ) ) + :mrParent(_rParent), mrMutex(_rMutex), mrEventsData(_rEventsData) { const DocumentEventData* pEventData = lcl_getDocumentEventData(); while ( pEventData->pAsciiEventName ) { OUString sEventName = OUString::createFromAscii( pEventData->pAsciiEventName ); - DocumentEventsData::const_iterator existingPos = m_pData->rEventsData.find( sEventName ); - if ( existingPos == m_pData->rEventsData.end() ) - m_pData->rEventsData[ sEventName ] = Sequence< PropertyValue >(); + DocumentEventsData::const_iterator existingPos = mrEventsData.find( sEventName ); + if ( existingPos == mrEventsData.end() ) + mrEventsData[ sEventName ] = Sequence< PropertyValue >(); ++pEventData; } } @@ -113,22 +97,22 @@ namespace dbaccess { } - void SAL_CALL DocumentEvents::acquire() throw() + void SAL_CALL DocumentEvents::acquire() noexcept { - m_pData->rParent.acquire(); + mrParent.acquire(); } - void SAL_CALL DocumentEvents::release() throw() + void SAL_CALL DocumentEvents::release() noexcept { - m_pData->rParent.release(); + mrParent.release(); } - bool DocumentEvents::needsSynchronousNotification( const OUString& _rEventName ) + bool DocumentEvents::needsSynchronousNotification( std::u16string_view _rEventName ) { const DocumentEventData* pEventData = lcl_getDocumentEventData(); while ( pEventData->pAsciiEventName ) { - if ( _rEventName.equalsAscii( pEventData->pAsciiEventName ) ) + if ( o3tl::equalsAscii( _rEventName, pEventData->pAsciiEventName ) ) return pEventData->bNeedsSyncNotify; ++pEventData; } @@ -139,10 +123,10 @@ namespace dbaccess void SAL_CALL DocumentEvents::replaceByName( const OUString& Name, const Any& Element ) { - ::osl::MutexGuard aGuard( m_pData->rMutex ); + ::osl::MutexGuard aGuard( mrMutex ); - DocumentEventsData::iterator elementPos = m_pData->rEventsData.find( Name ); - if ( elementPos == m_pData->rEventsData.end() ) + DocumentEventsData::iterator elementPos = mrEventsData.find( Name ); + if ( elementPos == mrEventsData.end() ) throw NoSuchElementException( Name, *this ); Sequence< PropertyValue > aEventDescriptor; @@ -172,10 +156,10 @@ namespace dbaccess Any SAL_CALL DocumentEvents::getByName( const OUString& Name ) { - ::osl::MutexGuard aGuard( m_pData->rMutex ); + ::osl::MutexGuard aGuard( mrMutex ); - DocumentEventsData::const_iterator elementPos = m_pData->rEventsData.find( Name ); - if ( elementPos == m_pData->rEventsData.end() ) + DocumentEventsData::const_iterator elementPos = mrEventsData.find( Name ); + if ( elementPos == mrEventsData.end() ) throw NoSuchElementException( Name, *this ); Any aReturn; @@ -187,16 +171,16 @@ namespace dbaccess Sequence< OUString > SAL_CALL DocumentEvents::getElementNames( ) { - ::osl::MutexGuard aGuard( m_pData->rMutex ); + ::osl::MutexGuard aGuard( mrMutex ); - return comphelper::mapKeysToSequence( m_pData->rEventsData ); + return comphelper::mapKeysToSequence( mrEventsData ); } sal_Bool SAL_CALL DocumentEvents::hasByName( const OUString& Name ) { - ::osl::MutexGuard aGuard( m_pData->rMutex ); + ::osl::MutexGuard aGuard( mrMutex ); - return m_pData->rEventsData.find( Name ) != m_pData->rEventsData.end(); + return mrEventsData.find( Name ) != mrEventsData.end(); } Type SAL_CALL DocumentEvents::getElementType( ) @@ -206,8 +190,8 @@ namespace dbaccess sal_Bool SAL_CALL DocumentEvents::hasElements( ) { - ::osl::MutexGuard aGuard( m_pData->rMutex ); - return !m_pData->rEventsData.empty(); + ::osl::MutexGuard aGuard( mrMutex ); + return !mrEventsData.empty(); } } // namespace dbaccess diff --git a/dbaccess/source/core/dataaccess/intercept.cxx b/dbaccess/source/core/dataaccess/intercept.cxx index 3b42df4ed6a1..2fce725582d3 100644 --- a/dbaccess/source/core/dataaccess/intercept.cxx +++ b/dbaccess/source/core/dataaccess/intercept.cxx @@ -20,7 +20,7 @@ #include "intercept.hxx" -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <memory> @@ -28,13 +28,11 @@ namespace dbaccess { using namespace ::com::sun::star::uno; using namespace ::com::sun::star::util; -using namespace ::com::sun::star::ucb; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::embed; using namespace ::com::sun::star::container; using namespace ::comphelper; using namespace ::cppu; @@ -65,17 +63,14 @@ void OInterceptor::dispose() OInterceptor::OInterceptor( ODocumentDefinition* _pContentHolder ) :m_pContentHolder( _pContentHolder ) - ,m_aInterceptedURL(7) + ,m_aInterceptedURL{ /* DISPATCH_SAVEAS */ ".uno:SaveAs", + /* DISPATCH_SAVE */ ".uno:Save", + /* DISPATCH_CLOSEDOC */ ".uno:CloseDoc", + /* DISPATCH_CLOSEWIN */ ".uno:CloseWin", + /* DISPATCH_CLOSEFRAME */ ".uno:CloseFrame", + /* DISPATCH_RELOAD */ ".uno:Reload" } { - OSL_ENSURE(DISPATCH_RELOAD < m_aInterceptedURL.getLength(),"Illegal size."); - - m_aInterceptedURL[DISPATCH_SAVEAS] = ".uno:SaveAs"; - m_aInterceptedURL[DISPATCH_SAVE] = ".uno:Save"; - m_aInterceptedURL[DISPATCH_CLOSEDOC] = ".uno:CloseDoc"; - m_aInterceptedURL[DISPATCH_CLOSEWIN] = ".uno:CloseWin"; - m_aInterceptedURL[DISPATCH_CLOSEFRAME] = ".uno:CloseFrame"; - m_aInterceptedURL[DISPATCH_RELOAD] = ".uno:Reload"; } @@ -131,7 +126,7 @@ void SAL_CALL OInterceptor::dispatch( const URL& URL,const Sequence<PropertyValu { if ( aNewArgs[nInd].Name == "SaveTo" ) { - aNewArgs[nInd].Value <<= true; + aNewArgs.getArray()[nInd].Value <<= true; break; } nInd++; @@ -140,8 +135,9 @@ void SAL_CALL OInterceptor::dispatch( const URL& URL,const Sequence<PropertyValu if ( nInd == aNewArgs.getLength() ) { aNewArgs.realloc( nInd + 1 ); - aNewArgs[nInd].Name = "SaveTo"; - aNewArgs[nInd].Value <<= true; + auto pNewArgs = aNewArgs.getArray(); + pNewArgs[nInd].Name = "SaveTo"; + pNewArgs[nInd].Value <<= true; } Reference< XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(URL, "_self", 0 ); @@ -210,7 +206,7 @@ void SAL_CALL OInterceptor::addStatusListener( { osl::MutexGuard aGuard(m_aMutex); if(!m_pStatCL) - m_pStatCL.reset( new PropertyChangeListenerContainer(m_aMutex) ); + m_pStatCL.reset( new StatusListenerContainer(m_aMutex) ); } m_pStatCL->addInterface(URL.Complete,Control); @@ -227,7 +223,7 @@ void SAL_CALL OInterceptor::addStatusListener( { osl::MutexGuard aGuard(m_aMutex); if(!m_pStatCL) - m_pStatCL.reset( new PropertyChangeListenerContainer(m_aMutex) ); + m_pStatCL.reset( new StatusListenerContainer(m_aMutex) ); } m_pStatCL->addInterface(URL.Complete,Control); @@ -251,7 +247,7 @@ void SAL_CALL OInterceptor::addStatusListener( { osl::MutexGuard aGuard(m_aMutex); if(!m_pStatCL) - m_pStatCL.reset( new PropertyChangeListenerContainer(m_aMutex) ); + m_pStatCL.reset( new StatusListenerContainer(m_aMutex) ); } m_pStatCL->addInterface(URL.Complete,Control); @@ -289,13 +285,9 @@ Sequence< OUString > SAL_CALL OInterceptor::getInterceptedURLs( ) Reference< XDispatch > SAL_CALL OInterceptor::queryDispatch( const URL& URL,const OUString& TargetFrameName,sal_Int32 SearchFlags ) { osl::MutexGuard aGuard(m_aMutex); - const OUString* pIter = m_aInterceptedURL.getConstArray(); - const OUString* pEnd = pIter + m_aInterceptedURL.getLength(); - for(;pIter != pEnd;++pIter) - { - if ( URL.Complete == *pIter ) + for (auto& interceptedUrl : m_aInterceptedURL) + if (URL.Complete == interceptedUrl) return static_cast<XDispatch*>(this); - } if(m_xSlaveDispatchProvider.is()) return m_xSlaveDispatchProvider->queryDispatch(URL,TargetFrameName,SearchFlags); @@ -305,22 +297,20 @@ Reference< XDispatch > SAL_CALL OInterceptor::queryDispatch( const URL& URL,cons Sequence< Reference< XDispatch > > SAL_CALL OInterceptor::queryDispatches( const Sequence<DispatchDescriptor >& Requests ) { - Sequence< Reference< XDispatch > > aRet; osl::MutexGuard aGuard(m_aMutex); - if(m_xSlaveDispatchProvider.is()) - aRet = m_xSlaveDispatchProvider->queryDispatches(Requests); - else - aRet.realloc(Requests.getLength()); + typedef Sequence<Reference<XDispatch>> DispatchSeq; + DispatchSeq aRet = m_xSlaveDispatchProvider.is() ? + m_xSlaveDispatchProvider->queryDispatches(Requests) : + DispatchSeq(Requests.getLength()); + auto aRetRange = asNonConstRange(aRet); for(sal_Int32 i = 0; i < Requests.getLength(); ++i) { - const OUString* pIter = m_aInterceptedURL.getConstArray(); - const OUString* pEnd = pIter + m_aInterceptedURL.getLength(); - for(;pIter != pEnd;++pIter) + for (auto& interceptedUrl : m_aInterceptedURL) { - if ( Requests[i].FeatureURL.Complete == *pIter ) + if (Requests[i].FeatureURL.Complete == interceptedUrl) { - aRet[i] = static_cast<XDispatch*>(this); + aRetRange[i] = static_cast<XDispatch*>(this); break; } } diff --git a/dbaccess/source/core/dataaccess/intercept.hxx b/dbaccess/source/core/dataaccess/intercept.hxx index 16077c3c9e52..7ce53752f19d 100644 --- a/dbaccess/source/core/dataaccess/intercept.hxx +++ b/dbaccess/source/core/dataaccess/intercept.hxx @@ -103,7 +103,9 @@ private: css::uno::Sequence< OUString > m_aInterceptedURL; - std::unique_ptr<PropertyChangeListenerContainer> m_pStatCL; + typedef comphelper::OMultiTypeInterfaceContainerHelperVar3<css::frame::XStatusListener, OUString> + StatusListenerContainer; + std::unique_ptr<StatusListenerContainer> m_pStatCL; }; } // namespace dbaccess diff --git a/dbaccess/source/core/dataaccess/myucp_datasupplier.cxx b/dbaccess/source/core/dataaccess/myucp_datasupplier.cxx index 52d6bd6a2b91..1b04127cf67f 100644 --- a/dbaccess/source/core/dataaccess/myucp_datasupplier.cxx +++ b/dbaccess/source/core/dataaccess/myucp_datasupplier.cxx @@ -17,82 +17,38 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <utility> #include <vector> -#include <ucbhelper/contentidentifier.hxx> - #include "myucp_datasupplier.hxx" #include <ContentHelper.hxx> #include <com/sun/star/ucb/IllegalIdentifierException.hpp> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::io; using namespace ::com::sun::star::container; -// @@@ Adjust namespace name. using namespace dbaccess; -// @@@ Adjust namespace name. -namespace dbaccess -{ - -namespace { - -// struct ResultListEntry. -struct ResultListEntry -{ - OUString aId; - Reference< XContentIdentifier > xId; - ::rtl::Reference< OContentHelper > xContent; - Reference< XRow > xRow; - const ContentProperties& rData; - - explicit ResultListEntry(const ContentProperties& rEntry) : rData( rEntry ) {} -}; - -} - -// struct DataSupplier_Impl. -struct DataSupplier_Impl -{ - osl::Mutex m_aMutex; - std::vector< std::unique_ptr<ResultListEntry> > m_aResults; - rtl::Reference< ODocumentContainer > m_xContent; - bool m_bCountFinal; - - explicit DataSupplier_Impl(const rtl::Reference< ODocumentContainer >& rContent) - : m_xContent(rContent) - , m_bCountFinal(false) - { - } -}; - -} - -// DataSupplier Implementation. DataSupplier::DataSupplier( const rtl::Reference< ODocumentContainer >& rContent ) -: m_pImpl( new DataSupplier_Impl( rContent ) ) +: m_xContent( rContent ) { - } DataSupplier::~DataSupplier() { - } OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( static_cast<size_t>(nIndex) < m_pImpl->m_aResults.size() ) + if ( static_cast<size_t>(nIndex) < m_aResults.size() ) { - OUString aId = m_pImpl->m_aResults[ nIndex ]->aId; + OUString aId = m_aResults[ nIndex ]->aId; if ( !aId.isEmpty() ) { // Already cached. @@ -102,14 +58,14 @@ OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) if ( getResult( nIndex ) ) { - OUString aId = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(); + OUString aId = m_xContent->getIdentifier()->getContentIdentifier(); if ( !aId.isEmpty() ) aId += "/"; - aId += m_pImpl->m_aResults[ nIndex ]->rData.aTitle; + aId += m_aResults[ nIndex ]->rData.aTitle; - m_pImpl->m_aResults[ nIndex ]->aId = aId; + m_aResults[ nIndex ]->aId = aId; return aId; } return OUString(); @@ -118,11 +74,11 @@ OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) Reference< XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( static_cast<size_t>(nIndex) < m_pImpl->m_aResults.size() ) + if ( static_cast<size_t>(nIndex) < m_aResults.size() ) { - Reference< XContentIdentifier > xId = m_pImpl->m_aResults[ nIndex ]->xId; + Reference< XContentIdentifier > xId = m_aResults[ nIndex ]->xId; if ( xId.is() ) { // Already cached. @@ -134,7 +90,7 @@ DataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) if ( !aId.isEmpty() ) { Reference< XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier( aId ); - m_pImpl->m_aResults[ nIndex ]->xId = xId; + m_aResults[ nIndex ]->xId = xId; return xId; } return Reference< XContentIdentifier >(); @@ -143,11 +99,11 @@ DataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) Reference< XContent > DataSupplier::queryContent( sal_uInt32 _nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( static_cast<size_t>(_nIndex) < m_pImpl->m_aResults.size() ) + if ( static_cast<size_t>(_nIndex) < m_aResults.size() ) { - Reference< XContent > xContent = m_pImpl->m_aResults[ _nIndex ]->xContent.get(); + Reference< XContent > xContent = m_aResults[ _nIndex ]->xContent; if ( xContent.is() ) { // Already cached. @@ -164,9 +120,9 @@ DataSupplier::queryContent( sal_uInt32 _nIndex ) OUString sName = xId->getContentIdentifier(); sName = sName.copy(sName.lastIndexOf('/')+1); - m_pImpl->m_aResults[ _nIndex ]->xContent = m_pImpl->m_xContent->getContent(sName); + m_aResults[ _nIndex ]->xContent = m_xContent->getContent(sName); - xContent = m_pImpl->m_aResults[ _nIndex ]->xContent.get(); + xContent = m_aResults[ _nIndex ]->xContent.get(); return xContent; } @@ -179,9 +135,9 @@ DataSupplier::queryContent( sal_uInt32 _nIndex ) bool DataSupplier::getResult( sal_uInt32 nIndex ) { - osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); - if ( static_cast<size_t>(nIndex) < m_pImpl->m_aResults.size() ) + if ( static_cast<size_t>(nIndex) < m_aResults.size() ) { // Result already present. return true; @@ -189,49 +145,41 @@ bool DataSupplier::getResult( sal_uInt32 nIndex ) // Result not (yet) present. - if ( m_pImpl->m_bCountFinal ) + if ( m_bCountFinal ) return false; // Try to obtain result... - sal_uInt32 nOldCount = m_pImpl->m_aResults.size(); + sal_uInt32 nOldCount = m_aResults.size(); bool bFound = false; - sal_uInt32 nPos = nOldCount; // @@@ Obtain data and put it into result list... - Sequence< OUString> aSeq = m_pImpl->m_xContent->getElementNames(); + Sequence< OUString> aSeq = m_xContent->getElementNames(); if ( nIndex < sal::static_int_cast< sal_uInt32 >( aSeq.getLength() ) ) { - const OUString* pIter = aSeq.getConstArray(); - const OUString* pEnd = pIter + aSeq.getLength(); - for(pIter = pIter + nPos;pIter != pEnd;++pIter,++nPos) - { - m_pImpl->m_aResults.emplace_back( - new ResultListEntry( m_pImpl->m_xContent->getContent(*pIter)->getContentProperties() ) ); - - if ( nPos == nIndex ) - { - // Result obtained. - bFound = true; - break; - } - } + m_aResults.reserve(nIndex + 1); + const OUString* pEnd = aSeq.begin() + nIndex + 1; + for (const OUString* pIter = aSeq.begin() + nOldCount; pIter != pEnd; ++pIter) + m_aResults.emplace_back( + new ResultListEntry( m_xContent->getContent(*pIter)->getContentProperties() ) ); + + // Result obtained. + bFound = true; } if ( !bFound ) - m_pImpl->m_bCountFinal = true; + m_bCountFinal = true; - rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get(); + rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet(); if ( xResultSet.is() ) { // Callbacks follow! aGuard.clear(); - if ( static_cast<size_t>(nOldCount) < m_pImpl->m_aResults.size() ) - xResultSet->rowCountChanged( - nOldCount, m_pImpl->m_aResults.size() ); + if ( static_cast<size_t>(nOldCount) < m_aResults.size() ) + xResultSet->rowCountChanged( nOldCount, m_aResults.size() ); - if ( m_pImpl->m_bCountFinal ) + if ( m_bCountFinal ) xResultSet->rowCountFinal(); } @@ -240,57 +188,56 @@ bool DataSupplier::getResult( sal_uInt32 nIndex ) sal_uInt32 DataSupplier::totalCount() { - osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); - if ( m_pImpl->m_bCountFinal ) - return m_pImpl->m_aResults.size(); + if ( m_bCountFinal ) + return m_aResults.size(); - sal_uInt32 nOldCount = m_pImpl->m_aResults.size(); + sal_uInt32 nOldCount = m_aResults.size(); // @@@ Obtain data and put it into result list... - Sequence< OUString> aSeq = m_pImpl->m_xContent->getElementNames(); - const OUString* pIter = aSeq.getConstArray(); - const OUString* pEnd = pIter + aSeq.getLength(); - for(;pIter != pEnd;++pIter) - m_pImpl->m_aResults.emplace_back( - new ResultListEntry( m_pImpl->m_xContent->getContent(*pIter)->getContentProperties() ) ); + Sequence< OUString> aSeq = m_xContent->getElementNames(); + // FIXME: this adds everything from aSeq to m_aResults, unlike similar code in getResult, + // which skips nOldCount entries in aSeq - which is correct? + for (auto& name : aSeq) + m_aResults.emplace_back( + new ResultListEntry( m_xContent->getContent(name)->getContentProperties() ) ); - m_pImpl->m_bCountFinal = true; + m_bCountFinal = true; - rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get(); + rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet(); if ( xResultSet.is() ) { // Callbacks follow! aGuard.clear(); - if ( static_cast<size_t>(nOldCount) < m_pImpl->m_aResults.size() ) - xResultSet->rowCountChanged( - nOldCount, m_pImpl->m_aResults.size() ); + if ( static_cast<size_t>(nOldCount) < m_aResults.size() ) + xResultSet->rowCountChanged( nOldCount, m_aResults.size() ); xResultSet->rowCountFinal(); } - return m_pImpl->m_aResults.size(); + return m_aResults.size(); } sal_uInt32 DataSupplier::currentCount() { - return m_pImpl->m_aResults.size(); + return m_aResults.size(); } bool DataSupplier::isCountFinal() { - return m_pImpl->m_bCountFinal; + return m_bCountFinal; } Reference< XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( static_cast<size_t>(nIndex) < m_pImpl->m_aResults.size() ) + if ( static_cast<size_t>(nIndex) < m_aResults.size() ) { - Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow; + Reference< XRow > xRow = m_aResults[ nIndex ]->xRow; if ( xRow.is() ) { // Already cached. @@ -300,11 +247,11 @@ DataSupplier::queryPropertyValues( sal_uInt32 nIndex ) if ( getResult( nIndex ) ) { - if ( !m_pImpl->m_aResults[ nIndex ]->xContent.is() ) + if ( !m_aResults[ nIndex ]->xContent.is() ) queryContent(nIndex); - Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xContent->getPropertyValues(getResultSet()->getProperties()); - m_pImpl->m_aResults[ nIndex ]->xRow = xRow; + Reference< XRow > xRow = m_aResults[ nIndex ]->xContent->getPropertyValues(getResultSet()->getProperties()); + m_aResults[ nIndex ]->xRow = xRow; return xRow; } @@ -313,10 +260,10 @@ DataSupplier::queryPropertyValues( sal_uInt32 nIndex ) void DataSupplier::releasePropertyValues( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( static_cast<size_t>(nIndex) < m_pImpl->m_aResults.size() ) - m_pImpl->m_aResults[ nIndex ]->xRow.clear(); + if ( static_cast<size_t>(nIndex) < m_aResults.size() ) + m_aResults[ nIndex ]->xRow.clear(); } void DataSupplier::close() diff --git a/dbaccess/source/core/dataaccess/myucp_datasupplier.hxx b/dbaccess/source/core/dataaccess/myucp_datasupplier.hxx index 8083f5ef59fa..65a45ad7fef6 100644 --- a/dbaccess/source/core/dataaccess/myucp_datasupplier.hxx +++ b/dbaccess/source/core/dataaccess/myucp_datasupplier.hxx @@ -20,17 +20,33 @@ #pragma once #include <rtl/ref.hxx> +#include <ucbhelper/contentidentifier.hxx> #include <ucbhelper/resultset.hxx> #include "documentcontainer.hxx" #include <memory> namespace dbaccess { -struct DataSupplier_Impl; +struct ResultListEntry +{ + OUString aId; + css::uno::Reference<css::ucb::XContentIdentifier> xId; + ::rtl::Reference<OContentHelper> xContent; + css::uno::Reference<css::sdbc::XRow> xRow; + const ContentProperties& rData; + + explicit ResultListEntry(const ContentProperties& rEntry) + : rData(rEntry) + { + } +}; class DataSupplier : public ucbhelper::ResultSetDataSupplier { - std::unique_ptr<DataSupplier_Impl> m_pImpl; + osl::Mutex m_aMutex; + std::vector<std::unique_ptr<ResultListEntry>> m_aResults; + rtl::Reference<ODocumentContainer> m_xContent; + bool m_bCountFinal = false; public: explicit DataSupplier(const rtl::Reference<ODocumentContainer>& rxContent); diff --git a/dbaccess/source/core/dataaccess/myucp_resultset.cxx b/dbaccess/source/core/dataaccess/myucp_resultset.cxx index 67c1ad7c8b4b..9ba383e0aa18 100644 --- a/dbaccess/source/core/dataaccess/myucp_resultset.cxx +++ b/dbaccess/source/core/dataaccess/myucp_resultset.cxx @@ -26,14 +26,13 @@ *************************************************************************/ +#include <utility> + #include "myucp_datasupplier.hxx" #include "myucp_resultset.hxx" using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::io; using namespace ::com::sun::star::container; @@ -42,11 +41,11 @@ using namespace dbaccess; // DynamicResultSet Implementation. DynamicResultSet::DynamicResultSet( const Reference< XComponentContext >& rxContext, - const rtl::Reference< ODocumentContainer >& rxContent, + rtl::Reference< ODocumentContainer > xContent, const OpenCommandArgument2& rCommand, const Reference< XCommandEnvironment >& rxEnv ) :ResultSetImplHelper( rxContext, rCommand ) - ,m_xContent(rxContent) + ,m_xContent(std::move(xContent)) ,m_xEnv( rxEnv ) { } diff --git a/dbaccess/source/core/dataaccess/myucp_resultset.hxx b/dbaccess/source/core/dataaccess/myucp_resultset.hxx index ae269ffb8ac9..220bdf0a70b7 100644 --- a/dbaccess/source/core/dataaccess/myucp_resultset.hxx +++ b/dbaccess/source/core/dataaccess/myucp_resultset.hxx @@ -39,7 +39,7 @@ private: public: DynamicResultSet( const css::uno::Reference< css::uno::XComponentContext >& rxContext, - const rtl::Reference< ODocumentContainer >& rxContent, + rtl::Reference< ODocumentContainer > xContent, const css::ucb::OpenCommandArgument2& rCommand, const css::uno::Reference< css::ucb::XCommandEnvironment >& rxEnv ); }; |