summaryrefslogtreecommitdiff
path: root/connectivity/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2025-03-04 10:30:12 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2025-03-04 16:35:35 +0100
commite10493a24835afecbc3aa58e4c327c064abd3d02 (patch)
tree15402993da617f84709c6310a35e75cbc1e5a8c4 /connectivity/source
parente262ddf89c21966c56fe41483045b40ee461c80a (diff)
improve type safety in mysql::ODriverDelegator
we can use type-safe WeakReference wrappers classes. Also use a custom struct instead of std::pair<std::pair< Change-Id: I0debaf3b0a77e92545c39aa755ca2477cc1e8c26 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182459 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity/source')
-rw-r--r--connectivity/source/drivers/mysql_jdbc/YDriver.cxx37
-rw-r--r--connectivity/source/inc/mysql/YDriver.hxx14
2 files changed, 26 insertions, 25 deletions
diff --git a/connectivity/source/drivers/mysql_jdbc/YDriver.cxx b/connectivity/source/drivers/mysql_jdbc/YDriver.cxx
index bc2a2314b939..2707ddf7f8e8 100644
--- a/connectivity/source/drivers/mysql_jdbc/YDriver.cxx
+++ b/connectivity/source/drivers/mysql_jdbc/YDriver.cxx
@@ -80,11 +80,10 @@ void ODriverDelegator::disposing()
for (auto const& connection : m_aConnections)
{
- Reference<XInterface> xTemp = connection.first.get();
+ Reference<XConnection> xTemp(connection.xConn);
::comphelper::disposeComponent(xTemp);
}
m_aConnections.clear();
- TWeakPairVector().swap(m_aConnections);
ODriverDelegator_BASE::disposing();
}
@@ -260,9 +259,7 @@ Reference<XConnection> SAL_CALL ODriverDelegator::connect(const OUString& url,
auto pMetaConnection = comphelper::getFromUnoTunnel<OMetaConnection>(xConnection);
if (pMetaConnection)
pMetaConnection->setURL(url);
- m_aConnections.emplace_back(
- WeakReferenceHelper(xConnection),
- TWeakConnectionPair(WeakReferenceHelper(), pMetaConnection));
+ m_aConnections.push_back({ xConnection, nullptr, pMetaConnection });
}
}
}
@@ -320,40 +317,38 @@ ODriverDelegator::getDataDefinitionByConnection(const Reference<XConnection>& co
::osl::MutexGuard aGuard(m_aMutex);
checkDisposed(ODriverDelegator_BASE::rBHelper.bDisposed);
- Reference<XTablesSupplier> xTab;
+ rtl::Reference<OMySQLCatalog> xTab;
auto pConnection = comphelper::getFromUnoTunnel<OMetaConnection>(connection);
if (pConnection)
{
- TWeakPairVector::iterator i
- = std::find_if(m_aConnections.begin(), m_aConnections.end(),
- [&pConnection](const TWeakPairVector::value_type& rConnection) {
- return rConnection.second.second == pConnection;
- });
+ auto i = std::find_if(m_aConnections.begin(), m_aConnections.end(),
+ [&pConnection](const TConnectionInfo& rConnection) {
+ return rConnection.pMetaConn == pConnection;
+ });
if (i != m_aConnections.end())
{
- xTab.set(i->second.first.get(), UNO_QUERY);
+ xTab = i->xCatalog.get();
if (!xTab.is())
{
xTab = new OMySQLCatalog(connection);
- i->second.first = WeakReferenceHelper(xTab);
+ i->xCatalog = xTab.get();
}
}
} // if (pConnection)
if (!xTab.is())
{
- TWeakPairVector::iterator i
- = std::find_if(m_aConnections.begin(), m_aConnections.end(),
- [&connection](const TWeakPairVector::value_type& rConnection) {
- Reference<XConnection> xTemp(rConnection.first.get(), UNO_QUERY);
- return xTemp == connection;
- });
+ auto i = std::find_if(m_aConnections.begin(), m_aConnections.end(),
+ [&connection](const TConnectionInfo& rConnection) {
+ Reference<XConnection> xTemp(rConnection.xConn);
+ return xTemp == connection;
+ });
if (i != m_aConnections.end())
{
- xTab.set(i->second.first.get(), UNO_QUERY);
+ xTab = i->xCatalog.get();
if (!xTab.is())
{
xTab = new OMySQLCatalog(connection);
- i->second.first = WeakReferenceHelper(xTab);
+ i->xCatalog = xTab.get();
}
}
}
diff --git a/connectivity/source/inc/mysql/YDriver.hxx b/connectivity/source/inc/mysql/YDriver.hxx
index 84fad1af1c99..a03906b8dcff 100644
--- a/connectivity/source/inc/mysql/YDriver.hxx
+++ b/connectivity/source/inc/mysql/YDriver.hxx
@@ -29,6 +29,7 @@
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/basemutex.hxx>
#include <connectivity/CommonTools.hxx>
+#include <unotools/weakref.hxx>
namespace connectivity
@@ -39,14 +40,19 @@ namespace connectivity
namespace mysql
{
+ class OMySQLCatalog;
+
typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver
, css::sdbcx::XDataDefinitionSupplier
, css::lang::XServiceInfo
> ODriverDelegator_BASE;
- typedef std::pair< css::uno::WeakReferenceHelper,OMetaConnection*> TWeakConnectionPair;
- typedef std::pair< css::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair;
- typedef std::vector< TWeakPair > TWeakPairVector;
+ struct TConnectionInfo
+ {
+ css::uno::WeakReference<css::sdbc::XConnection> xConn;
+ unotools::WeakReference<OMySQLCatalog> xCatalog;
+ OMetaConnection* pMetaConn;
+ };
typedef std::map< OUString, css::uno::Reference< css::sdbc::XDriver > > TJDBCDrivers;
/** delegates all calls to the original driver and extend the existing one with the SDBCX layer.
@@ -56,7 +62,7 @@ namespace connectivity
,public ODriverDelegator_BASE
{
TJDBCDrivers m_aJdbcDrivers; // all jdbc drivers
- TWeakPairVector m_aConnections; // vector containing a list
+ std::vector<TConnectionInfo> m_aConnections; // vector containing a list
// of all the Connection objects
// for this Driver
css::uno::Reference< css::sdbc::XDriver > m_xODBCDriver;