comphelper/Library_comphelper.mk                               |    1 
 comphelper/source/property/propertycontainer2.cxx              |   64 +++++++
 connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx |   71 +++++---
 connectivity/source/commontools/TPrivilegesResultSet.cxx       |   10 -
 connectivity/source/inc/FDatabaseMetaDataResultSet.hxx         |   23 +-
 connectivity/source/inc/TPrivilegesResultSet.hxx               |    4 
 include/comphelper/propertycontainer2.hxx                      |   81 
++++++++++
 7 files changed, 207 insertions(+), 47 deletions(-)

New commits:
commit 0321606599065a24c9cfa5c86d1cfcfbe58d11ae
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Mar 26 14:49:45 2024 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Tue Mar 26 17:17:03 2024 +0100

    convert ODatabaseMetaDataResultSet to comphelper::WeakComponentImplHelper
    
    Which means making a copy of comphelper::PropertyContainer
    
    Change-Id: I14a61fa40e2c1dfc66833e00817025397584b3ed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165345
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index d03dc06dd67f..2ab1b1bfa5d7 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -147,6 +147,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
     comphelper/source/property/propagg \
     comphelper/source/property/propertybag \
     comphelper/source/property/propertycontainer \
+    comphelper/source/property/propertycontainer2 \
     comphelper/source/property/propertycontainerhelper \
     comphelper/source/property/property \
     comphelper/source/property/propertysethelper \
diff --git a/comphelper/source/property/propertycontainer2.cxx 
b/comphelper/source/property/propertycontainer2.cxx
new file mode 100644
index 000000000000..5a3bfa4be285
--- /dev/null
+++ b/comphelper/source/property/propertycontainer2.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <comphelper/propertycontainer2.hxx>
+#include <cppuhelper/typeprovider.hxx>
+
+namespace comphelper
+{
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+
+OPropertyContainer2::OPropertyContainer2() {}
+
+OPropertyContainer2::~OPropertyContainer2() {}
+
+Sequence<Type> OPropertyContainer2::getBaseTypes()
+{
+    // just the types from our one and only base class
+    ::cppu::OTypeCollection aTypes(cppu::UnoType<XPropertySet>::get(),
+                                   cppu::UnoType<XFastPropertySet>::get(),
+                                   cppu::UnoType<XMultiPropertySet>::get());
+    return aTypes.getTypes();
+}
+
+bool 
OPropertyContainer2::convertFastPropertyValue(std::unique_lock<std::mutex>& 
/*rGuard*/,
+                                                   Any& _rConvertedValue, Any& 
_rOldValue,
+                                                   sal_Int32 _nHandle, const 
Any& _rValue)
+{
+    return 
OPropertyContainerHelper::convertFastPropertyValue(_rConvertedValue, _rOldValue,
+                                                              _nHandle, 
_rValue);
+}
+
+void 
OPropertyContainer2::setFastPropertyValue_NoBroadcast(std::unique_lock<std::mutex>&
 /*rGuard*/,
+                                                           sal_Int32 _nHandle, 
const Any& _rValue)
+{
+    OPropertyContainerHelper::setFastPropertyValue(_nHandle, _rValue);
+}
+
+void OPropertyContainer2::getFastPropertyValue(std::unique_lock<std::mutex>& 
/*rGuard*/,
+                                               Any& _rValue, sal_Int32 
_nHandle) const
+{
+    OPropertyContainerHelper::getFastPropertyValue(_rValue, _nHandle);
+}
+
+} // namespace comphelper
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx 
b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
index d4ae8760f2ce..d8745f1a0d7e 100644
--- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
+++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
@@ -43,9 +43,8 @@ using namespace ::com::sun::star::container;
 using namespace ::com::sun::star::lang;
 
 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet()
-    :ODatabaseMetaDataResultSet_BASE(m_aMutex)
-    
,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
-    ,m_nColPos(0)
+    :
+    m_nColPos(0)
     ,m_bBOF(true)
     ,m_bEOF(true)
 {
@@ -54,9 +53,8 @@ ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet()
 
 
 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet( MetaDataResultSetType 
_eType )
-    :ODatabaseMetaDataResultSet_BASE(m_aMutex)
-    
,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
-    ,m_nColPos(0)
+    :
+    m_nColPos(0)
     ,m_bBOF(true)
     ,m_bEOF(true)
 {
@@ -105,11 +103,10 @@ void 
ODatabaseMetaDataResultSet::setType(MetaDataResultSetType _eType)
     }
 }
 
-void ODatabaseMetaDataResultSet::disposing()
+void ODatabaseMetaDataResultSet::disposing(std::unique_lock<std::mutex>& 
rGuard)
 {
-    OPropertySetHelper::disposing();
+    OPropertySetHelper::disposing(rGuard);
 
-    ::osl::MutexGuard aGuard(m_aMutex);
     m_aStatement.clear();
     m_xMetaData.clear();
     m_aRowsIter = m_aRows.end();
@@ -151,11 +148,10 @@ void ODatabaseMetaDataResultSet::setRows(ORows&& _rRows)
 
 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& 
columnName )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
-
-    Reference< XResultSetMetaData > xMeta = getMetaData();
+    Reference< XResultSetMetaData > xMeta = getMetaData(aGuard);
     sal_Int32 nLen = xMeta->getColumnCount();
     sal_Int32 i = 1;
     for(;i<=nLen;++i)
@@ -170,7 +166,7 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( 
const OUString& colum
     O3TL_UNREACHABLE;
 }
 
-void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex )
+void ODatabaseMetaDataResultSet::checkIndex(std::unique_lock<std::mutex>& 
/*rGuard*/, sal_Int32 columnIndex )
 {
     if(columnIndex < 1 || o3tl::make_unsigned(columnIndex) >= 
(*m_aRowsIter).size())
         ::dbtools::throwInvalidIndexException(*this);
@@ -243,9 +239,13 @@ sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( 
sal_Int32 columnIndex )
 
 Reference< XResultSetMetaData > SAL_CALL 
ODatabaseMetaDataResultSet::getMetaData(  )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
+    std::unique_lock aGuard( m_aMutex );
+    return getMetaData(aGuard);
+}
 
+Reference< XResultSetMetaData > ODatabaseMetaDataResultSet::getMetaData( 
std::unique_lock<std::mutex>& rGuard  )
+{
+    throwIfDisposed(rGuard);
 
     if(!m_xMetaData.is())
         m_xMetaData = new ODatabaseMetaDataResultSetMetaData();
@@ -306,11 +306,15 @@ css::util::DateTime SAL_CALL 
ODatabaseMetaDataResultSet::getTimestamp( sal_Int32
 }
 
 
-sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast(  )
+sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast()
 {
     return m_bEOF;
 }
 
+bool ODatabaseMetaDataResultSet::isAfterLast( std::unique_lock<std::mutex>& 
/*rGuard*/)
+{
+    return m_bEOF;
+}
 
 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst(  )
 {
@@ -339,9 +343,8 @@ void SAL_CALL ODatabaseMetaDataResultSet::afterLast(  )
 void SAL_CALL ODatabaseMetaDataResultSet::close(  )
 {
     {
-        ::osl::MutexGuard aGuard( m_aMutex );
-        checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
-
+        std::unique_lock aGuard( m_aMutex );
+        throwIfDisposed(aGuard);
     }
     dispose();
 }
@@ -404,16 +407,25 @@ sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( 
 )
 }
 
 
-sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst(  )
+sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst()
 {
     return m_bBOF;
 }
 
+bool ODatabaseMetaDataResultSet::isBeforeFirst(std::unique_lock<std::mutex>& 
/*rGuard*/)
+{
+    return m_bBOF;
+}
 
 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next(  )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
+    std::unique_lock aGuard( m_aMutex );
+    return next(aGuard);
+}
+
+bool ODatabaseMetaDataResultSet::next( std::unique_lock<std::mutex>& rGuard )
+{
+    throwIfDisposed(rGuard);
 
     if ( m_bBOF )
     {
@@ -441,9 +453,8 @@ sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next(  )
 
 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull(  )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
-
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
     if(m_aRowsIter == m_aRows.end() || !(*m_aRowsIter)[m_nColPos].is())
         return true;
@@ -620,13 +631,13 @@ ORowSetValueDecorator& 
ORowSetValueDecorator::operator=(const ORowSetValue& _aVa
 
 const ORowSetValue& ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex)
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
-    if ( isBeforeFirst() || isAfterLast() )
+    if ( isBeforeFirst(aGuard) || isAfterLast(aGuard) )
         ::dbtools::throwFunctionSequenceException( *this );
 
-    checkIndex(columnIndex );
+    checkIndex(aGuard, columnIndex);
     m_nColPos = columnIndex;
 
     if(m_aRowsIter != m_aRows.end() && (*m_aRowsIter)[columnIndex].is())
diff --git a/connectivity/source/commontools/TPrivilegesResultSet.cxx 
b/connectivity/source/commontools/TPrivilegesResultSet.cxx
index 928e9c016a73..66e2eeff8bab 100644
--- a/connectivity/source/commontools/TPrivilegesResultSet.cxx
+++ b/connectivity/source/commontools/TPrivilegesResultSet.cxx
@@ -104,17 +104,17 @@ const ORowSetValue& 
OResultSetPrivileges::getValue(sal_Int32 columnIndex)
     return ODatabaseMetaDataResultSet::getValue(columnIndex);
 }
 
-void SAL_CALL OResultSetPrivileges::disposing()
+void OResultSetPrivileges::disposing(std::unique_lock<std::mutex>& rGuard)
 {
-    ODatabaseMetaDataResultSet::disposing();
+    ODatabaseMetaDataResultSet::disposing(rGuard);
     m_xTables.clear();
     m_xRow.clear();
 }
 
 sal_Bool SAL_CALL OResultSetPrivileges::next(  )
 {
-    ::osl::MutexGuard aGuard( m_aMutex );
-    checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
+    std::unique_lock aGuard( m_aMutex );
+    throwIfDisposed(aGuard);
 
     bool bReturn = false;
     if ( m_xTables.is() )
@@ -126,7 +126,7 @@ sal_Bool SAL_CALL OResultSetPrivileges::next(  )
                 return false;
         }
 
-        bReturn = ODatabaseMetaDataResultSet::next();
+        bReturn = ODatabaseMetaDataResultSet::next(aGuard);
         if ( !bReturn )
         {
             m_bBOF = false;
diff --git a/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx 
b/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx
index 5be3c15e318b..f0a3fef76d00 100644
--- a/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx
+++ b/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx
@@ -32,16 +32,15 @@
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
-#include <cppuhelper/compbase.hxx>
-#include <cppuhelper/basemutex.hxx>
 #include <comphelper/proparrhlp.hxx>
-#include <comphelper/propertycontainer.hxx>
+#include <comphelper/propertycontainer2.hxx>
 #include <connectivity/FValue.hxx>
 #include <connectivity/dbtoolsdllapi.hxx>
+#include <comphelper/compbase.hxx>
 
 namespace connectivity
 {
-    typedef ::cppu::WeakComponentImplHelper<   css::sdbc::XResultSet,
+    typedef ::comphelper::WeakComponentImplHelper<   css::sdbc::XResultSet,
                                                css::sdbc::XRow,
                                                
css::sdbc::XResultSetMetaDataSupplier,
                                                css::util::XCancellable,
@@ -55,9 +54,8 @@ namespace connectivity
     //  typedef ORefVector<ORow>            ORows;
 
     class SAL_DLLPUBLIC_RTTI ODatabaseMetaDataResultSet :
-                                public cppu::BaseMutex,
                                 public  ODatabaseMetaDataResultSet_BASE,
-                                public  ::comphelper::OPropertyContainer,
+                                public  ::comphelper::OPropertyContainer2,
                                 public  
::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet>
     {
 
@@ -118,8 +116,9 @@ namespace connectivity
 
         void construct();
         /// @throws css::sdbc::SQLException
-        void checkIndex(sal_Int32 columnIndex );
+        void checkIndex(std::unique_lock<std::mutex>& rGuard, sal_Int32 
columnIndex );
         void setType(MetaDataResultSetType _eType);
+        css::uno::Reference< css::sdbc::XResultSetMetaData > getMetaData( 
std::unique_lock<std::mutex>& );
 
     protected:
         ORows                           m_aRows;
@@ -132,7 +131,11 @@ namespace connectivity
         // OPropertyArrayUsageHelper
         OOO_DLLPUBLIC_DBTOOLS virtual ::cppu::IPropertyArrayHelper* 
createArrayHelper( ) const override;
         // OPropertySetHelper
-        OOO_DLLPUBLIC_DBTOOLS virtual ::cppu::IPropertyArrayHelper & SAL_CALL 
getInfoHelper() override;
+        OOO_DLLPUBLIC_DBTOOLS virtual ::cppu::IPropertyArrayHelper & 
getInfoHelper() override;
+
+        bool next(std::unique_lock<std::mutex>& );
+        bool isBeforeFirst(std::unique_lock<std::mutex>& );
+        bool isAfterLast(std::unique_lock<std::mutex>& );
 
         virtual ~ODatabaseMetaDataResultSet() override;
     public:
@@ -153,8 +156,8 @@ namespace connectivity
         virtual OUString SAL_CALL getImplementationName(  ) override;
         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName 
) override;
         virtual css::uno::Sequence< OUString > SAL_CALL 
getSupportedServiceNames(  ) override;
-        // ::cppu::OComponentHelper
-        virtual void SAL_CALL disposing() override;
+        // ::comphelper::WeakComponentImplHelper
+        virtual void disposing(std::unique_lock<std::mutex>&) override;
         // XInterface
         OOO_DLLPUBLIC_DBTOOLS virtual css::uno::Any SAL_CALL queryInterface( 
const css::uno::Type & rType ) override;
         //XTypeProvider
diff --git a/connectivity/source/inc/TPrivilegesResultSet.hxx 
b/connectivity/source/inc/TPrivilegesResultSet.hxx
index b7206b7de476..8c4070fce97a 100644
--- a/connectivity/source/inc/TPrivilegesResultSet.hxx
+++ b/connectivity/source/inc/TPrivilegesResultSet.hxx
@@ -36,8 +36,8 @@ namespace connectivity
         OResultSetPrivileges(const css::uno::Reference< 
css::sdbc::XDatabaseMetaData>& _rxMeta
             ,const css::uno::Any& catalog, const OUString& schemaPattern, 
const OUString& tableNamePattern);
 
-        // ::cppu::OComponentHelper
-        virtual void SAL_CALL disposing() override;
+        // ::comphelper::WeakComponentImplHelper
+        virtual void disposing(std::unique_lock<std::mutex>&) override;
         // XResultSet
         virtual sal_Bool SAL_CALL next(  ) override;
     };
diff --git a/include/comphelper/propertycontainer2.hxx 
b/include/comphelper/propertycontainer2.hxx
new file mode 100644
index 000000000000..e49a8a6febf2
--- /dev/null
+++ b/include/comphelper/propertycontainer2.hxx
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <comphelper/comphelperdllapi.h>
+#include <comphelper/propertycontainerhelper.hxx>
+#include <comphelper/propshlp.hxx>
+
+namespace com::sun::star::uno
+{
+class Any;
+}
+namespace com::sun::star::uno
+{
+class Type;
+}
+
+namespace comphelper
+{
+/**
+    This class is a copy of comphelper::OPropertyContainer except that it 
extends comphelper::OPropertySetHelper
+    instead of cppu::OPropertySetHelper.
+
+    An OPropertySetHelper implementation which is just a simple container for 
properties represented
+    by class members, usually in a derived class.
+    <BR>
+    A restriction of this class is that no value conversions are made on a 
setPropertyValue call. Though
+    the base class supports this with the convertFastPropertyValue method, the 
OPropertyContainer accepts only
+    values which already have the correct type, it's unable to convert, for 
instance, a long to a short.
+*/
+class COMPHELPER_DLLPUBLIC OPropertyContainer2 : public 
comphelper::OPropertySetHelper,
+                                                 public 
OPropertyContainerHelper
+{
+public:
+    // this dtor is needed otherwise we can get a wrong delete operator
+    virtual ~OPropertyContainer2();
+
+protected:
+    OPropertyContainer2();
+
+    /// for scripting : the types of the interfaces supported by this class
+    ///
+    /// @throws css::uno::RuntimeException
+    static css::uno::Sequence<css::uno::Type> getBaseTypes();
+
+    // OPropertySetHelper overridables
+    virtual bool convertFastPropertyValue(std::unique_lock<std::mutex>& rGuard,
+                                          css::uno::Any& rConvertedValue, 
css::uno::Any& rOldValue,
+                                          sal_Int32 nHandle, const 
css::uno::Any& rValue) override;
+
+    virtual void 
setFastPropertyValue_NoBroadcast(std::unique_lock<std::mutex>& rGuard,
+                                                  sal_Int32 nHandle,
+                                                  const css::uno::Any& rValue) 
override;
+
+    using OPropertySetHelper::getFastPropertyValue;
+    virtual void getFastPropertyValue(std::unique_lock<std::mutex>& rGuard, 
css::uno::Any& rValue,
+                                      sal_Int32 nHandle) const override;
+
+    // disambiguate a base class method (XFastPropertySet)
+    using OPropertySetHelper::setFastPropertyValue;
+};
+
+} // namespace comphelper
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to