Kaydet (Commit) 5c7b9549 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in OTable

use rtl::Reference here since these are reference counted data
structures, and we hand out references to me via our API

Change-Id: I8f69dde2db08519cb3d9de20b4ad54462e3ecc98
Reviewed-on: https://gerrit.libreoffice.org/49180Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 68d9583d
...@@ -299,10 +299,10 @@ void OTableHelper::refreshColumns() ...@@ -299,10 +299,10 @@ void OTableHelper::refreshColumns()
); );
} }
if(m_pColumns) if(m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = createColumns(aVector); m_xColumns = createColumns(aVector);
} }
const ColumnDesc* OTableHelper::getColumnDescription(const OUString& _sName) const const ColumnDesc* OTableHelper::getColumnDescription(const OUString& _sName) const
...@@ -424,10 +424,10 @@ void OTableHelper::refreshKeys() ...@@ -424,10 +424,10 @@ void OTableHelper::refreshKeys()
{ {
refreshPrimaryKeys(aNames); refreshPrimaryKeys(aNames);
refreshForeignKeys(aNames); refreshForeignKeys(aNames);
m_pKeys = createKeys(aNames); m_xKeys = createKeys(aNames);
} // if(!isNew()) } // if(!isNew())
else if (!m_pKeys ) else if (!m_xKeys )
m_pKeys = createKeys(aNames); m_xKeys = createKeys(aNames);
/*if(m_pKeys) /*if(m_pKeys)
m_pKeys->reFill(aVector); m_pKeys->reFill(aVector);
else*/ else*/
...@@ -469,10 +469,10 @@ void OTableHelper::refreshIndexes() ...@@ -469,10 +469,10 @@ void OTableHelper::refreshIndexes()
} }
} }
if(m_pIndexes) if(m_xIndexes)
m_pIndexes->reFill(aVector); m_xIndexes->reFill(aVector);
else else
m_pIndexes = createIndexes(aVector); m_xIndexes = createIndexes(aVector);
} }
OUString OTableHelper::getRenameStart() const OUString OTableHelper::getRenameStart() const
...@@ -549,7 +549,7 @@ void SAL_CALL OTableHelper::alterColumnByIndex( sal_Int32 index, const Reference ...@@ -549,7 +549,7 @@ void SAL_CALL OTableHelper::alterColumnByIndex( sal_Int32 index, const Reference
); );
Reference< XPropertySet > xOld( Reference< XPropertySet > xOld(
m_pColumns->getByIndex(index), css::uno::UNO_QUERY); m_xColumns->getByIndex(index), css::uno::UNO_QUERY);
if(xOld.is()) if(xOld.is())
alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor); alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
} }
......
...@@ -84,10 +84,10 @@ void OAdoTable::refreshColumns() ...@@ -84,10 +84,10 @@ void OAdoTable::refreshColumns()
aColumns.fillElementNames(aVector); aColumns.fillElementNames(aVector);
} }
if(m_pColumns) if(m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection()); m_xColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection());
} }
void OAdoTable::refreshKeys() void OAdoTable::refreshKeys()
...@@ -101,10 +101,10 @@ void OAdoTable::refreshKeys() ...@@ -101,10 +101,10 @@ void OAdoTable::refreshKeys()
aKeys.fillElementNames(aVector); aKeys.fillElementNames(aVector);
} }
if(m_pKeys) if(m_xKeys)
m_pKeys->reFill(aVector); m_xKeys->reFill(aVector);
else else
m_pKeys = new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection()); m_xKeys = new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection());
} }
void OAdoTable::refreshIndexes() void OAdoTable::refreshIndexes()
...@@ -118,10 +118,10 @@ void OAdoTable::refreshIndexes() ...@@ -118,10 +118,10 @@ void OAdoTable::refreshIndexes()
aIndexes.fillElementNames(aVector); aIndexes.fillElementNames(aVector);
} }
if(m_pIndexes) if(m_xIndexes)
m_pIndexes->reFill(aVector); m_xIndexes->reFill(aVector);
else else
m_pIndexes = new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection()); m_xIndexes = new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection());
} }
Sequence< sal_Int8 > OAdoTable::getUnoTunnelImplementationId() Sequence< sal_Int8 > OAdoTable::getUnoTunnelImplementationId()
...@@ -174,7 +174,7 @@ void SAL_CALL OAdoTable::alterColumnByName( const OUString& colName, const Refer ...@@ -174,7 +174,7 @@ void SAL_CALL OAdoTable::alterColumnByName( const OUString& colName, const Refer
if(bError) if(bError)
ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this); ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this);
m_pColumns->refresh(); m_xColumns->refresh();
refreshColumns(); refreshColumns();
} }
...@@ -184,7 +184,7 @@ void SAL_CALL OAdoTable::alterColumnByIndex( sal_Int32 index, const Reference< X ...@@ -184,7 +184,7 @@ void SAL_CALL OAdoTable::alterColumnByIndex( sal_Int32 index, const Reference< X
checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed); checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
Reference< XPropertySet > xOld; Reference< XPropertySet > xOld;
m_pColumns->getByIndex(index) >>= xOld; m_xColumns->getByIndex(index) >>= xOld;
if(xOld.is()) if(xOld.is())
alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor); alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
} }
......
...@@ -90,10 +90,10 @@ void OComponentTable::refreshColumns() ...@@ -90,10 +90,10 @@ void OComponentTable::refreshColumns()
for(OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin();aIter != aEnd;++aIter) for(OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin();aIter != aEnd;++aIter)
aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName()); aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName());
if(m_pColumns) if(m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = new component::OComponentColumns(this,m_aMutex,aVector); m_xColumns = new component::OComponentColumns(this,m_aMutex,aVector);
} }
void OComponentTable::refreshIndexes() void OComponentTable::refreshIndexes()
......
...@@ -67,10 +67,10 @@ void OEvoabTable::refreshColumns() ...@@ -67,10 +67,10 @@ void OEvoabTable::refreshColumns()
aVector.push_back(xRow->getString(4)); aVector.push_back(xRow->getString(4));
} }
} }
if (m_pColumns) if (m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = new OEvoabColumns(this,m_aMutex,aVector); m_xColumns = new OEvoabColumns(this,m_aMutex,aVector);
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -89,10 +89,10 @@ void OFileTable::refreshColumns() ...@@ -89,10 +89,10 @@ void OFileTable::refreshColumns()
aVector.push_back(xRow->getString(4)); aVector.push_back(xRow->getString(4));
} }
if(m_pColumns) if(m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = new OColumns(this,m_aMutex,aVector); m_xColumns = new OColumns(this,m_aMutex,aVector);
} }
void OFileTable::refreshKeys() void OFileTable::refreshKeys()
......
...@@ -116,7 +116,7 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName, ...@@ -116,7 +116,7 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName,
MutexGuard aGuard(m_rMutex); MutexGuard aGuard(m_rMutex);
checkDisposed(WeakComponentImplHelperBase::rBHelper.bDisposed); checkDisposed(WeakComponentImplHelperBase::rBHelper.bDisposed);
uno::Reference< XPropertySet > xColumn(m_pColumns->getByName(rColName), UNO_QUERY); uno::Reference< XPropertySet > xColumn(m_xColumns->getByName(rColName), UNO_QUERY);
// sdbcx::Descriptor // sdbcx::Descriptor
const bool bNameChanged = xColumn->getPropertyValue("Name") != rDescriptor->getPropertyValue("Name"); const bool bNameChanged = xColumn->getPropertyValue("Name") != rDescriptor->getPropertyValue("Name");
...@@ -218,7 +218,7 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName, ...@@ -218,7 +218,7 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName,
} }
m_pColumns->refresh(); m_xColumns->refresh();
} }
// ----- XRename -------------------------------------------------------------- // ----- XRename --------------------------------------------------------------
......
...@@ -501,10 +501,10 @@ void OFlatTable::refreshColumns() ...@@ -501,10 +501,10 @@ void OFlatTable::refreshColumns()
for (auto const& column : m_aColumns->get()) for (auto const& column : m_aColumns->get())
aVector.push_back(Reference< XNamed>(column,UNO_QUERY)->getName()); aVector.push_back(Reference< XNamed>(column,UNO_QUERY)->getName());
if(m_pColumns) if(m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = new OFlatColumns(this,m_aMutex,aVector); m_xColumns = new OFlatColumns(this,m_aMutex,aVector);
} }
......
...@@ -154,7 +154,7 @@ void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Refe ...@@ -154,7 +154,7 @@ void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Refe
#endif #endif
); );
if ( !m_pColumns || !m_pColumns->hasByName(colName) ) if ( !m_xColumns || !m_xColumns->hasByName(colName) )
throw NoSuchElementException(colName,*this); throw NoSuchElementException(colName,*this);
...@@ -162,7 +162,7 @@ void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Refe ...@@ -162,7 +162,7 @@ void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Refe
{ {
// first we have to check what should be altered // first we have to check what should be altered
Reference<XPropertySet> xProp; Reference<XPropertySet> xProp;
m_pColumns->getByName(colName) >>= xProp; m_xColumns->getByName(colName) >>= xProp;
// first check the types // first check the types
sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0; sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0;
OUString sOldTypeName, sNewTypeName; OUString sOldTypeName, sNewTypeName;
...@@ -237,14 +237,14 @@ void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Refe ...@@ -237,14 +237,14 @@ void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Refe
else if(sOldDefault.isEmpty() && !sNewDefault.isEmpty()) else if(sOldDefault.isEmpty() && !sNewDefault.isEmpty())
alterDefaultValue(sNewDefault,sNewColumnName); alterDefaultValue(sNewDefault,sNewColumnName);
m_pColumns->refresh(); m_xColumns->refresh();
} }
else else
{ {
if(m_pColumns) if(m_xColumns)
{ {
m_pColumns->dropByName(colName); m_xColumns->dropByName(colName);
m_pColumns->appendByDescriptor(descriptor); m_xColumns->appendByDescriptor(descriptor);
} }
} }
......
...@@ -76,10 +76,10 @@ void MacabTable::refreshColumns() ...@@ -76,10 +76,10 @@ void MacabTable::refreshColumns()
} }
} }
if (m_pColumns) if (m_xColumns)
m_pColumns->reFill(aVector); m_xColumns->reFill(aVector);
else else
m_pColumns = new MacabColumns(this,m_aMutex,aVector); m_xColumns = new MacabColumns(this,m_aMutex,aVector);
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -173,7 +173,7 @@ void SAL_CALL OMySQLTable::alterColumnByName( const OUString& colName, const Ref ...@@ -173,7 +173,7 @@ void SAL_CALL OMySQLTable::alterColumnByName( const OUString& colName, const Ref
#endif #endif
); );
if ( !m_pColumns || !m_pColumns->hasByName(colName) ) if ( !m_xColumns || !m_xColumns->hasByName(colName) )
throw NoSuchElementException(colName,*this); throw NoSuchElementException(colName,*this);
...@@ -181,7 +181,7 @@ void SAL_CALL OMySQLTable::alterColumnByName( const OUString& colName, const Ref ...@@ -181,7 +181,7 @@ void SAL_CALL OMySQLTable::alterColumnByName( const OUString& colName, const Ref
{ {
// first we have to check what should be altered // first we have to check what should be altered
Reference<XPropertySet> xProp; Reference<XPropertySet> xProp;
m_pColumns->getByName(colName) >>= xProp; m_xColumns->getByName(colName) >>= xProp;
// first check the types // first check the types
sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0; sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0;
...@@ -269,14 +269,14 @@ void SAL_CALL OMySQLTable::alterColumnByName( const OUString& colName, const Ref ...@@ -269,14 +269,14 @@ void SAL_CALL OMySQLTable::alterColumnByName( const OUString& colName, const Ref
" " + OTables::adjustSQL(::dbtools::createStandardColumnPart(descriptor,getConnection(),static_cast<OTables*>(m_pTables),getTypeCreatePattern())); " " + OTables::adjustSQL(::dbtools::createStandardColumnPart(descriptor,getConnection(),static_cast<OTables*>(m_pTables),getTypeCreatePattern()));
executeStatement(sSql); executeStatement(sSql);
} }
m_pColumns->refresh(); m_xColumns->refresh();
} }
else else
{ {
if(m_pColumns) if(m_xColumns)
{ {
m_pColumns->dropByName(colName); m_xColumns->dropByName(colName);
m_pColumns->appendByDescriptor(descriptor); m_xColumns->appendByDescriptor(descriptor);
} }
} }
......
...@@ -68,9 +68,6 @@ OTable::OTable(OCollection* _pTables, ...@@ -68,9 +68,6 @@ OTable::OTable(OCollection* _pTables,
bool _bCase) bool _bCase)
: OTableDescriptor_BASE(m_aMutex) : OTableDescriptor_BASE(m_aMutex)
,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,true) ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,true)
,m_pKeys(nullptr)
,m_pColumns(nullptr)
,m_pIndexes(nullptr)
,m_pTables(_pTables) ,m_pTables(_pTables)
{ {
} }
...@@ -85,9 +82,6 @@ OTable::OTable( OCollection* _pTables, ...@@ -85,9 +82,6 @@ OTable::OTable( OCollection* _pTables,
,m_SchemaName(SchemaName) ,m_SchemaName(SchemaName)
,m_Description(Description) ,m_Description(Description)
,m_Type(Type) ,m_Type(Type)
,m_pKeys(nullptr)
,m_pColumns(nullptr)
,m_pIndexes(nullptr)
,m_pTables(_pTables) ,m_pTables(_pTables)
{ {
m_Name = Name; m_Name = Name;
...@@ -95,9 +89,6 @@ OTable::OTable( OCollection* _pTables, ...@@ -95,9 +89,6 @@ OTable::OTable( OCollection* _pTables,
OTable::~OTable() OTable::~OTable()
{ {
delete m_pKeys;
delete m_pColumns;
delete m_pIndexes;
} }
void OTable::construct() void OTable::construct()
...@@ -151,12 +142,12 @@ void SAL_CALL OTable::disposing() ...@@ -151,12 +142,12 @@ void SAL_CALL OTable::disposing()
::osl::MutexGuard aGuard(m_aMutex); ::osl::MutexGuard aGuard(m_aMutex);
if(m_pKeys) if(m_xKeys)
m_pKeys->disposing(); m_xKeys->disposing();
if(m_pColumns) if(m_xColumns)
m_pColumns->disposing(); m_xColumns->disposing();
if(m_pIndexes) if(m_xIndexes)
m_pIndexes->disposing(); m_xIndexes->disposing();
m_pTables = nullptr; m_pTables = nullptr;
} }
...@@ -169,7 +160,7 @@ Reference< XNameAccess > SAL_CALL OTable::getColumns( ) ...@@ -169,7 +160,7 @@ Reference< XNameAccess > SAL_CALL OTable::getColumns( )
try try
{ {
if ( !m_pColumns ) if ( !m_xColumns )
refreshColumns(); refreshColumns();
} }
catch( const RuntimeException& ) catch( const RuntimeException& )
...@@ -182,7 +173,7 @@ Reference< XNameAccess > SAL_CALL OTable::getColumns( ) ...@@ -182,7 +173,7 @@ Reference< XNameAccess > SAL_CALL OTable::getColumns( )
// allowed // allowed
} }
return m_pColumns; return m_xColumns.get();
} }
...@@ -196,9 +187,9 @@ Reference< XIndexAccess > SAL_CALL OTable::getKeys( ) ...@@ -196,9 +187,9 @@ Reference< XIndexAccess > SAL_CALL OTable::getKeys( )
try try
{ {
if ( !m_pKeys ) if ( !m_xKeys )
refreshKeys(); refreshKeys();
xKeys = m_pKeys; xKeys = m_xKeys.get();
} }
catch( const RuntimeException& ) catch( const RuntimeException& )
{ {
...@@ -241,7 +232,7 @@ Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) ...@@ -241,7 +232,7 @@ Reference< XNameAccess > SAL_CALL OTable::getIndexes( )
try try
{ {
if ( !m_pIndexes ) if ( !m_xIndexes )
refreshIndexes(); refreshIndexes();
} }
catch( const RuntimeException& ) catch( const RuntimeException& )
...@@ -254,7 +245,7 @@ Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) ...@@ -254,7 +245,7 @@ Reference< XNameAccess > SAL_CALL OTable::getIndexes( )
// allowed // allowed
} }
return m_pIndexes; return m_xIndexes.get();
} }
// XRename // XRename
......
...@@ -103,7 +103,7 @@ OColumn* ODBTable::createColumn(const OUString& _rName) const ...@@ -103,7 +103,7 @@ OColumn* ODBTable::createColumn(const OUString& _rName) const
} }
else else
{ {
OColumns* pColumns = static_cast<OColumns*>(m_pColumns); OColumns* pColumns = static_cast<OColumns*>(m_xColumns.get());
xProp.set(pColumns->createBaseObject(_rName),UNO_QUERY); xProp.set(pColumns->createBaseObject(_rName),UNO_QUERY);
} }
...@@ -294,12 +294,12 @@ void SAL_CALL ODBTable::alterColumnByName( const OUString& _rName, const Referen ...@@ -294,12 +294,12 @@ void SAL_CALL ODBTable::alterColumnByName( const OUString& _rName, const Referen
if ( !getAlterService().is() ) if ( !getAlterService().is() )
throw SQLException(DBA_RES(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); throw SQLException(DBA_RES(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() );
if ( !m_pColumns->hasByName(_rName) ) if ( !m_xColumns->hasByName(_rName) )
throw SQLException(DBA_RES(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any() ); throw SQLException(DBA_RES(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any() );
Reference<XPropertySet> xTable(this); Reference<XPropertySet> xTable(this);
getAlterService()->alterColumnByName(xTable,_rName,_rxDescriptor); getAlterService()->alterColumnByName(xTable,_rName,_rxDescriptor);
m_pColumns->refresh(); m_xColumns->refresh();
} }
sal_Int64 SAL_CALL ODBTable::getSomething( const Sequence< sal_Int8 >& rId ) sal_Int64 SAL_CALL ODBTable::getSomething( const Sequence< sal_Int8 >& rId )
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <connectivity/CommonTools.hxx> #include <connectivity/CommonTools.hxx>
#include <connectivity/dbtoolsdllapi.hxx> #include <connectivity/dbtoolsdllapi.hxx>
#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
#include <memory>
namespace connectivity namespace connectivity
{ {
...@@ -72,9 +73,9 @@ namespace connectivity ...@@ -72,9 +73,9 @@ namespace connectivity
OUString m_Description; OUString m_Description;
OUString m_Type; OUString m_Type;
OCollection* m_pKeys; rtl::Reference<OCollection> m_xKeys;
OCollection* m_pColumns; rtl::Reference<OCollection> m_xColumns;
OCollection* m_pIndexes; rtl::Reference<OCollection> m_xIndexes;
OCollection* m_pTables; // must hold his own container to notify him when renaming OCollection* m_pTables; // must hold his own container to notify him when renaming
using OTableDescriptor_BASE::rBHelper; using OTableDescriptor_BASE::rBHelper;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment