From 03a2b4a80c5854bcb8520f2a43e485b98e3eba8f Mon Sep 17 00:00:00 2001 From: Lionel Elie Mamane Date: Wed, 6 Aug 2014 15:17:13 +0200 Subject: fdo#82151 when constructing column object, replace m_aCurrentRow by a function The passed m_aCurrentRow becomes out-of-date as soon as the current row changes. This also hides an implementation detail of ORowSet to ORowSet(Data)Column. Change-Id: Ib9188743e5dd6dec240e9f5fd3fd9655c6761abc Reviewed-on: https://gerrit.libreoffice.org/10792 Reviewed-by: Lionel Elie Mamane Tested-by: Lionel Elie Mamane --- dbaccess/source/core/api/CRowSetColumn.cxx | 10 +++++--- dbaccess/source/core/api/CRowSetColumn.hxx | 2 +- dbaccess/source/core/api/CRowSetDataColumn.cxx | 32 +++++++------------------- dbaccess/source/core/api/CRowSetDataColumn.hxx | 7 +++--- dbaccess/source/core/api/RowSet.cxx | 7 +++--- 5 files changed, 24 insertions(+), 34 deletions(-) diff --git a/dbaccess/source/core/api/CRowSetColumn.cxx b/dbaccess/source/core/api/CRowSetColumn.cxx index 945b15fe2f67..adc3d3835faf 100644 --- a/dbaccess/source/core/api/CRowSetColumn.cxx +++ b/dbaccess/source/core/api/CRowSetColumn.cxx @@ -36,9 +36,13 @@ using namespace ::com::sun::star::beans; namespace dbaccess { -ORowSetColumn::ORowSetColumn( const Reference < XResultSetMetaData >& _xMetaData, const Reference < XRow >& _xRow, sal_Int32 _nPos, - const Reference< XDatabaseMetaData >& _rxDBMeta, const OUString& _rDescription, const OUString& i_sLabel,ORowSetCacheIterator& _rColumnValue ) - :ORowSetDataColumn( _xMetaData, _xRow, NULL, _nPos, _rxDBMeta, _rDescription, i_sLabel,_rColumnValue ) +ORowSetColumn::ORowSetColumn( const Reference < XResultSetMetaData >& _xMetaData, + const Reference < XRow >& _xRow, sal_Int32 _nPos, + const Reference< XDatabaseMetaData >& _rxDBMeta, + const OUString& _rDescription, + const OUString& i_sLabel, + const boost::function< const ::connectivity::ORowSetValue& ( sal_Int32 ) > &_getValue ) + :ORowSetDataColumn( _xMetaData, _xRow, NULL, _nPos, _rxDBMeta, _rDescription, i_sLabel, _getValue ) { } diff --git a/dbaccess/source/core/api/CRowSetColumn.hxx b/dbaccess/source/core/api/CRowSetColumn.hxx index bba7c7d04c02..0c4ec827c996 100644 --- a/dbaccess/source/core/api/CRowSetColumn.hxx +++ b/dbaccess/source/core/api/CRowSetColumn.hxx @@ -38,7 +38,7 @@ namespace dbaccess const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxDBMeta, const OUString& _rDescription, const OUString& i_sLabel, - ORowSetCacheIterator& _rColumnValue); + const boost::function< const ::connectivity::ORowSetValue& ( sal_Int32 ) > &_getValue); virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE; virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE; diff --git a/dbaccess/source/core/api/CRowSetDataColumn.cxx b/dbaccess/source/core/api/CRowSetDataColumn.cxx index f0de794fb17d..a0477251853e 100644 --- a/dbaccess/source/core/api/CRowSetDataColumn.cxx +++ b/dbaccess/source/core/api/CRowSetDataColumn.cxx @@ -39,16 +39,16 @@ using namespace cppu; using namespace osl; -ORowSetDataColumn::ORowSetDataColumn( const Reference < XResultSetMetaData >& _xMetaData, +ORowSetDataColumn::ORowSetDataColumn( const Reference < XResultSetMetaData >& _xMetaData, const Reference < XRow >& _xRow, const Reference < XRowUpdate >& _xRowUpdate, sal_Int32 _nPos, const Reference< XDatabaseMetaData >& _rxDBMeta, const OUString& _rDescription, const OUString& i_sLabel, - const ORowSetCacheIterator& _rColumnValue) + const boost::function< const ORowSetValue& (sal_Int32)> &_getValue) :ODataColumn(_xMetaData,_xRow,_xRowUpdate,_nPos,_rxDBMeta) - ,m_aColumnValue(_rColumnValue) + ,m_pGetValue(_getValue) ,m_sLabel(i_sLabel) ,m_aDescription(_rDescription) { @@ -105,16 +105,7 @@ void SAL_CALL ORowSetDataColumn::getFastPropertyValue( Any& rValue, sal_Int32 nH { if ( PROPERTY_ID_VALUE == nHandle ) { - if ( !m_aColumnValue.isNull() && m_aColumnValue->is() ) - { - ::osl::Mutex* pMutex = m_aColumnValue.getMutex(); - ::osl::MutexGuard aGuard( *pMutex ); -#if OSL_DEBUG_LEVEL > 0 - ORowSetRow aRow = *m_aColumnValue; -#endif - OSL_ENSURE((sal_Int32)aRow->get().size() > m_nPos,"Pos is greater than size of vector"); - rValue = ((*m_aColumnValue)->get())[m_nPos].makeAny(); - } + rValue = m_pGetValue(m_nPos).makeAny(); } else if ( PROPERTY_ID_LABEL == nHandle && !m_sLabel.isEmpty() ) rValue <<= m_sLabel; @@ -179,19 +170,12 @@ Sequence< sal_Int8 > ORowSetDataColumn::getImplementationId() throw (RuntimeExce void ORowSetDataColumn::fireValueChange(const ORowSetValue& _rOldValue) { - if ( !m_aColumnValue.isNull() && m_aColumnValue->is() && (((*m_aColumnValue)->get())[m_nPos] != _rOldValue) ) + const ORowSetValue &value(m_pGetValue(m_nPos)); + if ( value != _rOldValue) { - sal_Int32 nHandle = PROPERTY_ID_VALUE; + sal_Int32 nHandle(PROPERTY_ID_VALUE); m_aOldValue = _rOldValue.makeAny(); - Any aNew = ((*m_aColumnValue)->get())[m_nPos].makeAny(); - - fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False ); - } - else if ( !m_aColumnValue.isNull() && !_rOldValue.isNull() ) - { - sal_Int32 nHandle = PROPERTY_ID_VALUE; - m_aOldValue = _rOldValue.makeAny(); - Any aNew; + Any aNew = value.makeAny(); fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False ); } diff --git a/dbaccess/source/core/api/CRowSetDataColumn.hxx b/dbaccess/source/core/api/CRowSetDataColumn.hxx index bd6e64154029..5483f167f97d 100644 --- a/dbaccess/source/core/api/CRowSetDataColumn.hxx +++ b/dbaccess/source/core/api/CRowSetDataColumn.hxx @@ -21,12 +21,13 @@ #include "datacolumn.hxx" #include "RowSetRow.hxx" -#include "RowSetCacheIterator.hxx" #include "columnsettings.hxx" #include #include +#include + namespace dbaccess { class ORowSetDataColumn; @@ -37,7 +38,7 @@ namespace dbaccess public ORowSetDataColumn_PROP { protected: - ORowSetCacheIterator m_aColumnValue; + const boost::function< const ::connectivity::ORowSetValue& ( sal_Int32 ) > m_pGetValue; ::com::sun::star::uno::Any m_aOldValue; OUString m_sLabel; @@ -52,7 +53,7 @@ namespace dbaccess const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxDBMeta, const OUString& _rDescription, const OUString& i_sLabel, - const ORowSetCacheIterator& _rColumnValue); + const boost::function< const ::connectivity::ORowSetValue& ( sal_Int32 ) > &_getValue); // com::sun::star::lang::XTypeProvider diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 388e153095cb..5912aa933fbd 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include "RowSet.hxx" @@ -1876,7 +1877,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi m_xActiveConnection->getMetaData(), aDescription, OUString(), - m_aCurrentRow); + boost::bind(&ORowSet::getInsertValue, this, _1)); aColumnMap.insert(std::make_pair(sName,0)); aColumns->get().push_back(pColumn); pColumn->setName(sName); @@ -1978,7 +1979,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi m_xActiveConnection->getMetaData(), aDescription, sParseLabel, - m_aCurrentRow); + boost::bind(&ORowSet::getInsertValue, this, _1)); aColumns->get().push_back(pColumn); pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i) != rKeyColumns.end())); @@ -2810,7 +2811,7 @@ ORowSetClone::ORowSetClone( const Reference& _rContext, ORowS rParent.m_xActiveConnection->getMetaData(), aDescription, sParseLabel, - m_aCurrentRow); + boost::bind(&ORowSetClone::getValue, this, _1)); aColumns->get().push_back(pColumn); pColumn->setName(*pIter); aNames.push_back(*pIter); -- cgit v1.2.3