diff options
Diffstat (limited to 'dbaccess/source/core/api/RowSet.cxx')
-rw-r--r-- | dbaccess/source/core/api/RowSet.cxx | 341 |
1 files changed, 150 insertions, 191 deletions
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 62383ecd5479..4f1dd11fcf5b 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -31,11 +31,13 @@ #include "CRowSetDataColumn.hxx" #include "RowSetCache.hxx" #include <strings.hrc> +#include <strings.hxx> #include <core_resource.hxx> #include <tablecontainer.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/sdb/CommandType.hpp> #include <com/sun/star/sdb/DatabaseContext.hpp> #include <com/sun/star/sdb/ErrorCondition.hpp> @@ -68,9 +70,8 @@ #include <i18nlangtag/languagetag.hxx> #include <o3tl/safeint.hxx> #include <unotools/syslocale.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> -using namespace utl; using namespace dbaccess; using namespace connectivity; using namespace comphelper; @@ -95,24 +96,6 @@ com_sun_star_comp_dba_ORowSet_get_implementation(css::uno::XComponentContext* co return cppu::acquire(new ORowSet(context)); } -#define NOTIFY_LISTENERS_CHECK(_rListeners,T,method) \ - std::vector< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \ - \ - _rGuard.clear(); \ - bool bCheck = std::all_of(aListenerSeq.rbegin(), aListenerSeq.rend(), \ - [&aEvt](Reference<XInterface>& rxItem) { \ - try \ - { \ - return static_cast<bool>(static_cast<T*>(rxItem.get())->method(aEvt)); \ - } \ - catch( RuntimeException& ) \ - { \ - return true; \ - } \ - }); \ - _rGuard.reset(); - - namespace dbaccess { ORowSet::ORowSet( const Reference< css::uno::XComponentContext >& _rxContext ) @@ -123,6 +106,7 @@ ORowSet::ORowSet( const Reference< css::uno::XComponentContext >& _rxContext ) ,m_aRowsetListeners(*m_pMutex) ,m_aApproveListeners(*m_pMutex) ,m_aRowsChangeListener(*m_pMutex) + ,m_sErrorString(ResourceManager::loadString(RID_STR_COMMAND_LEADING_TO_ERROR)) ,m_nFetchDirection(FetchDirection::FORWARD) ,m_nFetchSize(50) ,m_nMaxFieldSize(0) @@ -274,7 +258,7 @@ void SAL_CALL ORowSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const break; case PROPERTY_ID_FETCHDIRECTION: if( m_nResultSetType == ResultSetType::FORWARD_ONLY) - throw Exception("resultsettype is FORWARD_ONLY", nullptr); + throw Exception(u"resultsettype is FORWARD_ONLY"_ustr, nullptr); [[fallthrough]]; default: OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue); @@ -424,32 +408,16 @@ Any SAL_CALL ORowSet::queryInterface( const Type & rType ) return ORowSet_BASE1::queryInterface( rType); } -void SAL_CALL ORowSet::acquire() throw() +void SAL_CALL ORowSet::acquire() noexcept { ORowSet_BASE1::acquire(); } -void SAL_CALL ORowSet::release() throw() +void SAL_CALL ORowSet::release() noexcept { ORowSet_BASE1::release(); } -// css::XUnoTunnel -sal_Int64 SAL_CALL ORowSet::getSomething( const Sequence< sal_Int8 >& rId ) -{ - if (isUnoTunnelId<ORowSet>(rId)) - return reinterpret_cast<sal_Int64>(this); - - return 0; -} - -Sequence< sal_Int8 > ORowSet::getUnoTunnelId() -{ - static ::cppu::OImplementationId s_Id; - - return s_Id.getImplementationId(); -} - // css::XAggregation Any SAL_CALL ORowSet::queryAggregation( const Type& rType ) { @@ -462,7 +430,7 @@ Any SAL_CALL ORowSet::queryAggregation( const Type& rType ) // css::XServiceInfo OUString SAL_CALL ORowSet::getImplementationName() { - return "com.sun.star.comp.dba.ORowSet"; + return u"com.sun.star.comp.dba.ORowSet"_ustr; } sal_Bool SAL_CALL ORowSet::supportsService( const OUString& _rServiceName ) @@ -493,11 +461,7 @@ void SAL_CALL ORowSet::disposing() // remove myself as dispose listener Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY); if (xComponent.is()) - { - Reference<XEventListener> xEvt; - query_aggregation(this,xEvt); - xComponent->removeEventListener(xEvt); - } + xComponent->removeEventListener(query_aggregation<XEventListener>(this)); m_aActiveConnection = Any(); // the any contains a reference too if(m_bOwnConnection) @@ -515,7 +479,7 @@ void ORowSet::freeResources( bool _bComplete ) // free all clones for (auto const& clone : m_aClones) { - Reference< XComponent > xComp(clone.get(), UNO_QUERY); + rtl::Reference< ORowSetClone > xComp(clone); if (xComp.is()) xComp->dispose(); } @@ -578,11 +542,7 @@ void ORowSet::setActiveConnection( Reference< XConnection > const & _rxNewConn, // remove the event listener for the old connection Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY); if (xComponent.is()) - { - Reference<XEventListener> xListener; - query_aggregation(this, xListener); - xComponent->removeEventListener(xListener); - } + xComponent->removeEventListener(query_aggregation<XEventListener>(this)); // if we owned the connection, remember it for later disposing if(m_bOwnConnection) @@ -607,11 +567,7 @@ void ORowSet::setActiveConnection( Reference< XConnection > const & _rxNewConn, // register as event listener for the new connection xComponent.set(m_xActiveConnection,UNO_QUERY); if (xComponent.is()) - { - Reference<XEventListener> xListener; - query_aggregation(this, xListener); - xComponent->addEventListener(xListener); - } + xComponent->addEventListener(query_aggregation<XEventListener>(this)); } // css::XEventListener @@ -637,7 +593,7 @@ void SAL_CALL ORowSet::close( ) MutexGuard aGuard( m_aMutex ); ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed); } - // additionals things to set + // additional things to set freeResources( true ); } @@ -664,7 +620,7 @@ void ORowSet::updateValue(sal_Int32 columnIndex,const ORowSetValue& x) checkUpdateIterator(); ORowSetValueVector::Vector& rRow = **m_aCurrentRow; - ORowSetNotifier aNotify(this,rRow); + ORowSetNotifier aNotify(this, std::vector(rRow)); m_pCache->updateValue(columnIndex,x,rRow,aNotify.getChangedColumns()); m_bModified = m_bModified || !aNotify.getChangedColumns().empty(); aNotify.firePropertyChange(); @@ -680,7 +636,7 @@ void SAL_CALL ORowSet::updateNull( sal_Int32 columnIndex ) checkUpdateIterator(); ORowSetValueVector::Vector& rRow = **m_aCurrentRow; - ORowSetNotifier aNotify(this,rRow); + ORowSetNotifier aNotify(this, std::vector(rRow)); m_pCache->updateNull(columnIndex,rRow,aNotify.getChangedColumns()); m_bModified = m_bModified || !aNotify.getChangedColumns().empty(); aNotify.firePropertyChange(); @@ -768,7 +724,7 @@ void SAL_CALL ORowSet::updateCharacterStream( sal_Int32 columnIndex, const Refer checkUpdateConditions(columnIndex); checkUpdateIterator(); ORowSetValueVector::Vector& rRow = **m_aCurrentRow; - ORowSetNotifier aNotify(this,rRow); + ORowSetNotifier aNotify(this, std::vector(rRow)); m_pCache->updateCharacterStream(columnIndex,x,length,rRow,aNotify.getChangedColumns()); m_bModified = m_bModified || !aNotify.getChangedColumns().empty(); aNotify.firePropertyChange(); @@ -812,7 +768,7 @@ void SAL_CALL ORowSet::updateObject( sal_Int32 columnIndex, const Any& x ) if (!::dbtools::implUpdateObject(this, columnIndex, aNewValue)) { // there is no other updateXXX call which can handle the value in x ORowSetValueVector::Vector& rRow = **m_aCurrentRow; - ORowSetNotifier aNotify(this,rRow); + ORowSetNotifier aNotify(this, std::vector(rRow)); m_pCache->updateObject(columnIndex,aNewValue,rRow,aNotify.getChangedColumns()); m_bModified = m_bModified || !aNotify.getChangedColumns().empty(); aNotify.firePropertyChange(); @@ -826,7 +782,7 @@ void SAL_CALL ORowSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, checkUpdateConditions(columnIndex); checkUpdateIterator(); ORowSetValueVector::Vector& rRow = **m_aCurrentRow; - ORowSetNotifier aNotify(this,rRow); + ORowSetNotifier aNotify(this, std::vector(rRow)); m_pCache->updateNumericObject(columnIndex,x,rRow,aNotify.getChangedColumns()); m_bModified = m_bModified || !aNotify.getChangedColumns().empty(); aNotify.firePropertyChange(); @@ -993,7 +949,7 @@ void SAL_CALL ORowSet::deleteRow( ) // this call position the cache indirect Any aBookmarkToDelete( m_aBookmark ); - positionCache( MOVE_NONE ); + positionCache( CursorMoveDirection::Current ); sal_Int32 nDeletePosition = m_pCache->getRow(); notifyRowSetAndClonesRowDelete( aBookmarkToDelete ); @@ -1040,7 +996,7 @@ void ORowSet::implCancelRowUpdates( bool _bNotifyModified ) if ( m_bNew || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY ) throwFunctionSequenceException(*this); - positionCache( MOVE_NONE ); + positionCache( CursorMoveDirection::Current ); ORowSetRow aOldValues; if ( !m_bModified && _bNotifyModified && !m_aCurrentRow.isNull() ) @@ -1112,13 +1068,40 @@ void ORowSet::notifyAllListenersRowChanged(::osl::ResettableMutexGuard& _rGuard, bool ORowSet::notifyAllListenersCursorBeforeMove(::osl::ResettableMutexGuard& _rGuard) { EventObject aEvt(*m_pMySelf); - NOTIFY_LISTENERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveCursorMove); + std::vector< Reference< css::sdb::XRowSetApproveListener > > aListenerSeq = m_aApproveListeners.getElements(); + _rGuard.clear(); + bool bCheck = std::all_of(aListenerSeq.rbegin(), aListenerSeq.rend(), + [&aEvt](Reference<css::sdb::XRowSetApproveListener>& rxItem) { + try + { + return static_cast<bool>(rxItem->approveCursorMove(aEvt)); + } + catch( RuntimeException& ) + { + return true; + } + }); + _rGuard.reset(); return bCheck; } void ORowSet::notifyAllListenersRowBeforeChange(::osl::ResettableMutexGuard& _rGuard,const RowChangeEvent &aEvt) { - NOTIFY_LISTENERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveRowChange); + std::vector< Reference< css::sdb::XRowSetApproveListener > > aListenerSeq = m_aApproveListeners.getElements(); + _rGuard.clear(); + bool bCheck = std::all_of(aListenerSeq.rbegin(), aListenerSeq.rend(), + [&aEvt](Reference<css::sdb::XRowSetApproveListener>& rxItem) { + try + { + return static_cast<bool>(rxItem->approveRowChange(aEvt)); + } + catch( RuntimeException& ) + { + return true; + } + }); + _rGuard.reset(); + if ( !bCheck ) m_aErrors.raiseTypedException( sdb::ErrorCondition::ROW_SET_OPERATION_VETOED, *this, ::cppu::UnoType< RowSetVetoException >::get() ); } @@ -1163,12 +1146,12 @@ void SAL_CALL ORowSet::moveToInsertRow( ) ORowSetRow aOldValues; if ( rowDeleted() ) { - positionCache( MOVE_FORWARD ); + positionCache( CursorMoveDirection::Forward ); m_pCache->next(); setCurrentRow( true, false, aOldValues, aGuard); } else - positionCache( MOVE_NONE ); + positionCache( CursorMoveDirection::Current ); // check before because the resultset could be empty if ( !m_bBeforeFirst @@ -1218,18 +1201,18 @@ void ORowSet::impl_setDataColumnsWriteable_throw() dataColumn->getPropertyValue(PROPERTY_ISREADONLY) >>= bReadOnly; *aReadIter = bReadOnly; - dataColumn->setPropertyValue(PROPERTY_ISREADONLY,makeAny(false)); + dataColumn->setPropertyValue(PROPERTY_ISREADONLY,Any(false)); ++aReadIter; } } void ORowSet::impl_restoreDataColumnsWriteable_throw() { - assert(m_aDataColumns.size() == m_aReadOnlyDataColumns.size() || m_aReadOnlyDataColumns.size() == 0 ); + assert(m_aDataColumns.size() == m_aReadOnlyDataColumns.size() || m_aReadOnlyDataColumns.empty()); TDataColumns::const_iterator aIter = m_aDataColumns.begin(); for (bool readOnlyDataColumn : m_aReadOnlyDataColumns) { - (*aIter)->setPropertyValue(PROPERTY_ISREADONLY, makeAny(readOnlyDataColumn) ); + (*aIter)->setPropertyValue(PROPERTY_ISREADONLY, Any(readOnlyDataColumn) ); ++aIter; } m_aReadOnlyDataColumns.clear(); @@ -1257,7 +1240,7 @@ void SAL_CALL ORowSet::moveToCurrentRow( ) if ( !notifyAllListenersCursorBeforeMove( aGuard ) ) return; - positionCache( MOVE_NONE_REFRESH ); + positionCache( CursorMoveDirection::CurrentRefresh ); ORowSetNotifier aNotifier( this ); @@ -1294,74 +1277,73 @@ const ORowSetValue& ORowSet::getInsertValue(sal_Int32 columnIndex) OUString SAL_CALL ORowSet::getString( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getString(); } sal_Bool SAL_CALL ORowSet::getBoolean( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - // the extra cast is to recognise the "true" or "false" strings - return static_cast<bool>(getInsertValue(columnIndex)); + return getInsertValue(columnIndex).getBool(); } sal_Int8 SAL_CALL ORowSet::getByte( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getInt8(); } sal_Int16 SAL_CALL ORowSet::getShort( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getInt16(); } sal_Int32 SAL_CALL ORowSet::getInt( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getInt32(); } sal_Int64 SAL_CALL ORowSet::getLong( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getLong(); } float SAL_CALL ORowSet::getFloat( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getFloat(); } double SAL_CALL ORowSet::getDouble( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getDouble(); } Sequence< sal_Int8 > SAL_CALL ORowSet::getBytes( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getSequence(); } css::util::Date SAL_CALL ORowSet::getDate( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getDate(); } css::util::Time SAL_CALL ORowSet::getTime( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getTime(); } css::util::DateTime SAL_CALL ORowSet::getTimestamp( sal_Int32 columnIndex ) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getInsertValue(columnIndex); + return getInsertValue(columnIndex).getDateTime(); } Reference< css::io::XInputStream > SAL_CALL ORowSet::getBinaryStream( sal_Int32 columnIndex ) @@ -1504,7 +1486,7 @@ Reference< XIndexAccess > SAL_CALL ORowSet::getParameters( ) // our caller could change our parameters at any time m_bParametersDirty = true; - return m_pParameters.get(); + return m_pParameters; } void ORowSet::approveExecution() @@ -1512,13 +1494,13 @@ void ORowSet::approveExecution() ::osl::MutexGuard aGuard( m_aColumnsMutex ); EventObject aEvt(*this); - OInterfaceIteratorHelper2 aApproveIter( m_aApproveListeners ); + OInterfaceIteratorHelper3 aApproveIter( m_aApproveListeners ); while ( aApproveIter.hasMoreElements() ) { - Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aApproveIter.next() ) ); + Reference< XRowSetApproveListener > xListener( aApproveIter.next() ); try { - if ( xListener.is() && !xListener->approveRowSetChange( aEvt ) ) + if ( !xListener->approveRowSetChange( aEvt ) ) throw RowSetVetoException(); } catch ( const DisposedException& e ) @@ -1571,7 +1553,7 @@ void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxSta // #i15113# bool bRespectDriverRST = false; Any aSetting; - if ( getDataSourceSetting( ::dbaccess::getDataSource( m_xActiveConnection ), "RespectDriverResultSetType", aSetting ) ) + if (getDataSourceSetting(::dbaccess::getDataSource(m_xActiveConnection), u"RespectDriverResultSetType"_ustr, aSetting)) { OSL_VERIFY( aSetting >>= bRespectDriverRST ); } @@ -1609,8 +1591,8 @@ void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxSta } } - _rxStatement->setPropertyValue( PROPERTY_RESULTSETTYPE, makeAny( nResultSetType ) ); - _rxStatement->setPropertyValue( PROPERTY_RESULTSETCONCURRENCY, makeAny( nResultSetConcurrency ) ); + _rxStatement->setPropertyValue( PROPERTY_RESULTSETTYPE, Any( nResultSetType ) ); + _rxStatement->setPropertyValue( PROPERTY_RESULTSETCONCURRENCY, Any( nResultSetConcurrency ) ); } void ORowSet::impl_ensureStatement_throw() @@ -1637,8 +1619,8 @@ void ORowSet::impl_ensureStatement_throw() // set the result set type and concurrency try { - xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( true ) ); - xStatementProps->setPropertyValue( PROPERTY_MAXROWS, makeAny( m_nMaxRows ) ); + xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, Any( true ) ); + xStatementProps->setPropertyValue( PROPERTY_MAXROWS, Any( m_nMaxRows ) ); setStatementResultSetType( xStatementProps, m_nResultSetType, m_nResultSetConcurrency ); } @@ -1648,21 +1630,17 @@ void ORowSet::impl_ensureStatement_throw() // then the driver doesn't support this feature } } - catch( const SQLException& ) + catch (SQLException& rException) { - SQLExceptionInfo aError( ::cppu::getCaughtException() ); - OSL_ENSURE( aError.isValid(), "ORowSet::impl_makeNewStatement_throw: caught an SQLException which we cannot analyze!" ); + css::sdbc::SQLException* pLastExceptionInChain = SQLExceptionInfo::getLastException(&rException); + assert(pLastExceptionInChain && "will at least be &rException"); // append information about what we were actually going to execute - try - { - OUString sInfo(DBA_RES_PARAM( RID_STR_COMMAND_LEADING_TO_ERROR, "$command$", sCommandToExecute ) ); - aError.append( SQLExceptionInfo::TYPE::SQLContext, sInfo ); - } - catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION("dbaccess"); } + OUString sInfo(m_sErrorString.replaceFirst("$command$", sCommandToExecute)); + pLastExceptionInChain->NextException = SQLExceptionInfo::createException(SQLExceptionInfo::TYPE::SQLContext, sInfo, OUString(), 0); // propagate - aError.doThrow(); + throw; } } @@ -1716,8 +1694,8 @@ void ORowSet::impl_initializeColumnSettings_nothrow( const Reference< XPropertyS // a number of properties is plain copied const OUString aPropertyNames[] = { - OUString(PROPERTY_ALIGN), OUString(PROPERTY_RELATIVEPOSITION), OUString(PROPERTY_WIDTH), OUString(PROPERTY_HIDDEN), OUString(PROPERTY_CONTROLMODEL), - OUString(PROPERTY_HELPTEXT), OUString(PROPERTY_CONTROLDEFAULT) + PROPERTY_ALIGN, PROPERTY_RELATIVEPOSITION, PROPERTY_WIDTH, PROPERTY_HIDDEN, PROPERTY_CONTROLMODEL, + PROPERTY_HELPTEXT, PROPERTY_CONTROLDEFAULT }; for (const auto & aPropertyName : aPropertyNames) { @@ -1737,7 +1715,7 @@ void ORowSet::impl_initializeColumnSettings_nothrow( const Reference< XPropertyS } if ( !nFormatKey && m_xNumberFormatTypes.is() ) nFormatKey = ::dbtools::getDefaultNumberFormat( _rxTemplateColumn, m_xNumberFormatTypes, SvtSysLocale().GetLanguageTag().getLocale() ); - _rxRowSetColumn->setPropertyValue( PROPERTY_NUMBERFORMAT, makeAny( nFormatKey ) ); + _rxRowSetColumn->setPropertyValue( PROPERTY_NUMBERFORMAT, Any( nFormatKey ) ); } catch(Exception&) { @@ -1843,17 +1821,17 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi // retrieve the name of the column OUString sName = xMetaData->getColumnName(i + 1); // check for duplicate entries - if(aColumnMap.find(sName) != aColumnMap.end()) + if(aColumnMap.contains(sName)) { OUString sAlias(sName); sal_Int32 searchIndex=1; - while(aColumnMap.find(sAlias) != aColumnMap.end()) + while(aColumnMap.contains(sAlias)) { sAlias = sName + OUString::number(searchIndex++); } sName = sAlias; } - ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(), + rtl::Reference<ORowSetDataColumn> pColumn = new ORowSetDataColumn( getMetaData(), this, this, i+1, @@ -1867,9 +1845,9 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi aColumns->emplace_back(pColumn); pColumn->setName(sName); aNames.push_back(sName); - m_aDataColumns.push_back(pColumn); + m_aDataColumns.push_back(pColumn.get()); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i+1) != rKeyColumns.end())); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,Any(rKeyColumns.find(i+1) != rKeyColumns.end())); try { @@ -1878,10 +1856,10 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi nFormatKey = ::dbtools::getDefaultNumberFormat(pColumn,m_xNumberFormatTypes,aLocale); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey)); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,makeAny(sal_Int32(i+1))); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,makeAny(sal_Int32(227))); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,makeAny(sal_Int32(0))); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,Any(nFormatKey)); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,Any(sal_Int32(i+1))); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,Any(sal_Int32(227))); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,Any(sal_Int32(0))); pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN, css::uno::Any(false)); } catch(Exception&) @@ -1937,7 +1915,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi Sequence< OUString> aSeq = m_xColumns->getElementNames(); if( i <= aSeq.getLength()) { - m_xColumns->getByName(aSeq.getConstArray()[i-1]) >>= xColumn; + m_xColumns->getByName(aSeq[i-1]) >>= xColumn; } } } @@ -1957,7 +1935,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi { xColumn->getPropertyValue(PROPERTY_LABEL) >>= sParseLabel; } - ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(), + rtl::Reference<ORowSetDataColumn> pColumn = new ORowSetDataColumn( getMetaData(), this, this, i, @@ -1969,7 +1947,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi }); aColumns->emplace_back(pColumn); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i) != rKeyColumns.end())); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,Any(rKeyColumns.find(i) != rKeyColumns.end())); if(sColumnLabel.isEmpty()) { @@ -1980,7 +1958,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi } pColumn->setName(sColumnLabel); aNames.push_back(sColumnLabel); - m_aDataColumns.push_back(pColumn); + m_aDataColumns.push_back(pColumn.get()); if ( xColumn.is() ) impl_initializeColumnSettings_nothrow( xColumn, pColumn ); @@ -2066,10 +2044,9 @@ Reference< XResultSet > SAL_CALL ORowSet::createResultSet( ) if(m_xStatement.is()) { - ORowSetClone* pClone = new ORowSetClone( m_aContext, *this, m_pMutex ); - Reference< XResultSet > xRet(pClone); - m_aClones.emplace_back(xRet); - return xRet; + rtl::Reference<ORowSetClone> pClone = new ORowSetClone( m_aContext, *this, m_pMutex ); + m_aClones.emplace_back(pClone); + return pClone; } return Reference< XResultSet >(); } @@ -2096,25 +2073,23 @@ Sequence< sal_Int32 > SAL_CALL ORowSet::deleteRows( const Sequence< Any >& rows notifyAllListenersRowBeforeChange(aGuard,aEvt); Sequence< sal_Int32 > aResults( rows.getLength() ); - const Any* row = rows.getConstArray(); - const Any* rowEnd = rows.getConstArray() + rows.getLength(); sal_Int32* result = aResults.getArray(); - for ( ; row != rowEnd; ++row, ++result ) + for (sal_Int32 i = 0; i < rows.getLength(); ++i) { - *result = 0; - if ( !m_pCache->moveToBookmark( *row ) ) + result[i] = 0; + if (!m_pCache->moveToBookmark(rows[i])) continue; sal_Int32 nDeletePosition = m_pCache->getRow(); // first notify the clones so that they can save their position - notifyRowSetAndClonesRowDelete( *row ); + notifyRowSetAndClonesRowDelete(rows[i]); // now delete the row if ( !m_pCache->deleteRow() ) continue; - *result = 1; + result[i] = 1; // now notify that we have deleted - notifyRowSetAndClonesRowDeleted( *row, nDeletePosition ); + notifyRowSetAndClonesRowDeleted(rows[i], nDeletePosition); } aEvt.Rows = aResults.getLength(); @@ -2142,7 +2117,7 @@ void ORowSet::notifyRowSetAndClonesRowDelete( const Any& _rBookmark ) // notify the clones for (auto const& elem : m_aClones) { - auto pClone = comphelper::getUnoTunnelImplementation<ORowSetClone>(elem.get()); + rtl::Reference<ORowSetClone> pClone = elem.get(); if(pClone) pClone->onDeleteRow( _rBookmark ); } @@ -2155,7 +2130,7 @@ void ORowSet::notifyRowSetAndClonesRowDeleted( const Any& _rBookmark, sal_Int32 // notify the clones for (auto const& clone : m_aClones) { - auto pClone = comphelper::getUnoTunnelImplementation<ORowSetClone>(clone.get()); + rtl::Reference<ORowSetClone> pClone = clone.get(); if(pClone) pClone->onDeletedRow( _rBookmark, _nPos ); } @@ -2193,7 +2168,7 @@ Reference< XConnection > ORowSet::calcConnection(const Reference< XInteractionH { Any aError = ::cppu::getCaughtException(); OUString sMessage = ResourceManager::loadString( RID_NO_SUCH_DATA_SOURCE, - "$name$", m_aDataSourceName, "$error$", extractExceptionMessage( m_aContext, aError ) ); + u"$name$", m_aDataSourceName, u"$error$", extractExceptionMessage( m_aContext, aError ) ); ::dbtools::throwGenericSQLException( sMessage, *this, aError ); } } @@ -2232,9 +2207,9 @@ Reference< XNameAccess > ORowSet::impl_getTables_throw() DBG_UNHANDLED_EXCEPTION("dbaccess"); } - m_xTables = new OTableContainer(*this,m_aMutex,m_xActiveConnection,bCase,nullptr,nullptr,m_nInAppend); + m_xTables.reset(new OTableContainer(*this,m_aMutex,m_xActiveConnection,bCase,nullptr,nullptr,m_nInAppend)); xTables = m_xTables.get(); - Sequence<OUString> aTableFilter { "%" }; + Sequence<OUString> aTableFilter { u"%"_ustr }; m_xTables->construct(aTableFilter,Sequence< OUString>()); } @@ -2255,7 +2230,7 @@ void ORowSet::impl_resetTables_nothrow() DBG_UNHANDLED_EXCEPTION("dbaccess"); } - m_xTables.clear(); + m_xTables.reset(); } void ORowSet::impl_initComposer_throw( OUString& _out_rCommandToExecute ) @@ -2291,7 +2266,7 @@ void ORowSet::impl_initComposer_throw( OUString& _out_rCommandToExecute ) // don't simply overwrite an existent filter, this would lead to problems if this existent // filter contains parameters (since a keyset may add parameters itself) m_xComposer->setElementaryQuery( m_xComposer->getQuery( ) ); - m_xComposer->setFilter( "0 = 1" ); + m_xComposer->setFilter( u"0 = 1"_ustr ); } m_xComposer->setOrder( m_aOrder ); @@ -2404,7 +2379,7 @@ void ORowSet::impl_initParametersContainer_nothrow() { OSL_PRECOND( !m_pParameters.is(), "ORowSet::impl_initParametersContainer_nothrow: already initialized the parameters!" ); - m_pParameters = new param::ParameterWrapperContainer( m_xComposer.get() ); + m_pParameters = new param::ParameterWrapperContainer( m_xComposer ); // copy the premature parameters into the final ones size_t nParamCount( std::min( m_pParameters->size(), m_aPrematureParamValues->size() ) ); for ( size_t i=0; i<nParamCount; ++i ) @@ -2557,7 +2532,7 @@ void SAL_CALL ORowSet::setBinaryStream( sal_Int32 parameterIndex, const Referenc catch( Exception const & ) { css::uno::Any anyEx = cppu::getCaughtException(); - throw SQLException("ORowSet::setBinaryStream", *this, "S1000", 0,anyEx); + throw SQLException(u"ORowSet::setBinaryStream"_ustr, *this, u"S1000"_ustr, 0,anyEx); } } @@ -2581,7 +2556,7 @@ void SAL_CALL ORowSet::setCharacterStream( sal_Int32 parameterIndex, const Refer catch( Exception const & ) { css::uno::Any anyEx = cppu::getCaughtException(); - throw SQLException("ORowSet::setCharacterStream", *this, "S1000", 0, anyEx); + throw SQLException(u"ORowSet::setCharacterStream"_ustr, *this, u"S1000"_ustr, 0, anyEx); } } @@ -2604,22 +2579,22 @@ void SAL_CALL ORowSet::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x void SAL_CALL ORowSet::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) { - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setRef", *this ); + ::dbtools::throwFeatureNotImplementedSQLException( u"XParameters::setRef"_ustr, *this ); } void SAL_CALL ORowSet::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) { - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBlob", *this ); + ::dbtools::throwFeatureNotImplementedSQLException( u"XParameters::setBlob"_ustr, *this ); } void SAL_CALL ORowSet::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) { - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setClob", *this ); + ::dbtools::throwFeatureNotImplementedSQLException( u"XParameters::setClob"_ustr, *this ); } void SAL_CALL ORowSet::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) { - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setArray", *this ); + ::dbtools::throwFeatureNotImplementedSQLException( u"XParameters::setArray"_ustr, *this ); } void SAL_CALL ORowSet::clearParameters( ) @@ -2698,7 +2673,7 @@ void ORowSet::checkUpdateConditions(sal_Int32 columnIndex) if ( m_aCurrentRow.isNull() ) ::dbtools::throwSQLException( DBA_RES( RID_STR_INVALID_CURSOR_STATE ), StandardSQLState::INVALID_CURSOR_STATE, *this ); - if ( columnIndex <= 0 || sal_Int32((*m_aCurrentRow)->size()) <= columnIndex ) + if ( columnIndex <= 0 || (*m_aCurrentRow)->size() <= o3tl::make_unsigned(columnIndex) ) ::dbtools::throwSQLException( DBA_RES( RID_STR_INVALID_INDEX ), StandardSQLState::INVALID_DESCRIPTOR_INDEX, *this ); } @@ -2733,9 +2708,9 @@ void ORowSet::impl_rebuild_throw(::osl::ResettableMutexGuard& _rGuard) // *********************************************************** ORowSetClone::ORowSetClone( const Reference<XComponentContext>& _rContext, ORowSet& rParent, ::osl::Mutex* _pMutex ) - :OSubComponent(m_aMutex, rParent) - ,ORowSetBase( _rContext, OComponentHelper::rBHelper, _pMutex ) - ,m_pParent(&rParent) + : ::cppu::WeakComponentImplHelper<>(m_aMutex) + ,ORowSetBase( _rContext, WeakComponentImplHelper::rBHelper, _pMutex ) + ,m_xParent(&rParent) ,m_nFetchDirection(rParent.m_nFetchDirection) ,m_nFetchSize(rParent.m_nFetchSize) ,m_bIsBookmarkable(true) @@ -2763,19 +2738,19 @@ ORowSetClone::ORowSetClone( const Reference<XComponentContext>& _rContext, ORowS if ( rParent.m_pColumns ) { Sequence< OUString> aSeq = rParent.m_pColumns->getElementNames(); - const OUString* pIter = aSeq.getConstArray(); - const OUString* pEnd = pIter + aSeq.getLength(); aColumns->reserve(aSeq.getLength()+1); - for(sal_Int32 i=1;pIter != pEnd ;++pIter,++i) + sal_Int32 i = 0; + for (auto& columnName : aSeq) { + ++i; Reference<XPropertySet> xColumn; - rParent.m_pColumns->getByName(*pIter) >>= xColumn; + rParent.m_pColumns->getByName(columnName) >>= xColumn; if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION)) aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION)); OUString sParseLabel; xColumn->getPropertyValue(PROPERTY_LABEL) >>= sParseLabel; - ORowSetColumn* pColumn = new ORowSetColumn( rParent.getMetaData(), + rtl::Reference<ORowSetColumn> pColumn = new ORowSetColumn( rParent.getMetaData(), this, i, rParent.m_xActiveConnection->getMetaData(), @@ -2785,16 +2760,16 @@ ORowSetClone::ORowSetClone( const Reference<XComponentContext>& _rContext, ORowS return this->getValue(column); }); aColumns->emplace_back(pColumn); - pColumn->setName(*pIter); - aNames.push_back(*pIter); - m_aDataColumns.push_back(pColumn); + pColumn->setName(columnName); + aNames.push_back(columnName); + m_aDataColumns.push_back(pColumn.get()); pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,xColumn->getPropertyValue(PROPERTY_ALIGN)); sal_Int32 nFormatKey = 0; xColumn->getPropertyValue(PROPERTY_NUMBERFORMAT) >>= nFormatKey; if(!nFormatKey && xColumn.is() && m_xNumberFormatTypes.is()) nFormatKey = ::dbtools::getDefaultNumberFormat(xColumn,m_xNumberFormatTypes,aLocale); - pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey)); + pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,Any(nFormatKey)); pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,xColumn->getPropertyValue(PROPERTY_RELATIVEPOSITION)); pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,xColumn->getPropertyValue(PROPERTY_WIDTH)); pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,xColumn->getPropertyValue(PROPERTY_HIDDEN)); @@ -2826,7 +2801,7 @@ ORowSetClone::~ORowSetClone() // css::XTypeProvider Sequence< Type > ORowSetClone::getTypes() { - return ::comphelper::concatSequences(OSubComponent::getTypes(),ORowSetBase::getTypes()); + return ::comphelper::concatSequences(::cppu::WeakComponentImplHelper<>::getTypes(),ORowSetBase::getTypes()); } // css::XInterface @@ -2834,24 +2809,24 @@ Any ORowSetClone::queryInterface( const Type & rType ) { Any aRet = ORowSetBase::queryInterface(rType); if(!aRet.hasValue()) - aRet = OSubComponent::queryInterface(rType); + aRet = ::cppu::WeakComponentImplHelper<>::queryInterface(rType); return aRet; } -void ORowSetClone::acquire() throw() +void ORowSetClone::acquire() noexcept { - OSubComponent::acquire(); + ::cppu::WeakComponentImplHelper<>::acquire(); } -void ORowSetClone::release() throw() +void ORowSetClone::release() noexcept { - OSubComponent::release(); + ::cppu::WeakComponentImplHelper<>::release(); } // XServiceInfo OUString ORowSetClone::getImplementationName( ) { - return "com.sun.star.sdb.ORowSetClone"; + return u"com.sun.star.sdb.ORowSetClone"_ustr; } sal_Bool ORowSetClone::supportsService( const OUString& _rServiceName ) @@ -2870,9 +2845,9 @@ void ORowSetClone::disposing() MutexGuard aGuard( m_aMutex ); ORowSetBase::disposing(); - m_pParent = nullptr; + m_xParent = nullptr; m_pMutex = &m_aMutex; // this must be done here because someone could hold a ref to us and try to do something - OSubComponent::disposing(); + ::cppu::WeakComponentImplHelper<>::disposing(); } // XCloseable @@ -2880,8 +2855,8 @@ void ORowSetClone::close() { { MutexGuard aGuard( m_aMutex ); - if (OComponentHelper::rBHelper.bDisposed) - throw DisposedException(); + if (WeakComponentImplHelper::rBHelper.bDisposed) + return; } dispose(); } @@ -2900,28 +2875,12 @@ void ORowSetClone::close() return *::comphelper::OPropertyArrayUsageHelper<ORowSetClone>::getArrayHelper(); } -Sequence< sal_Int8 > ORowSetClone::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::XUnoTunnel -sal_Int64 SAL_CALL ORowSetClone::getSomething( const Sequence< sal_Int8 >& rId ) -{ - if (isUnoTunnelId<ORowSetClone>(rId)) - return reinterpret_cast<sal_Int64>(this); - - return 0; -} - void SAL_CALL ORowSetClone::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) { if ( nHandle == PROPERTY_ID_FETCHSIZE ) { - if ( m_pParent ) - m_pParent->setFastPropertyValue_NoBroadcast( nHandle, rValue ); + if ( auto xParent = m_xParent.get() ) + xParent->setFastPropertyValue_NoBroadcast( nHandle, rValue ); } OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue); @@ -2948,17 +2907,17 @@ bool ORowSetClone::isNew( ) void SAL_CALL ORowSetClone::execute( ) { - throwFunctionNotSupportedSQLException( "RowSetClone::XRowSet::execute", *this ); + throwFunctionNotSupportedSQLException( u"RowSetClone::XRowSet::execute"_ustr, *this ); } void SAL_CALL ORowSetClone::addRowSetListener( const Reference< XRowSetListener >& ) { - throwFunctionNotSupportedRuntimeException( "RowSetClone::XRowSet", *this ); + throwFunctionNotSupportedRuntimeException( u"RowSetClone::XRowSet"_ustr, *this ); } void SAL_CALL ORowSetClone::removeRowSetListener( const Reference< XRowSetListener >& ) { - throwFunctionNotSupportedRuntimeException( "RowSetClone::XRowSet", *this ); + throwFunctionNotSupportedRuntimeException( u"RowSetClone::XRowSet"_ustr, *this ); } } // dbaccess |