diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-06 15:57:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-06 21:29:02 +0200 |
commit | c8cbcd77484d8172d76d0758f16f9b340277fa52 (patch) | |
tree | 66fd521b7e935d451b50e3d5d35f240fa72a8301 /connectivity/source | |
parent | bab595df78bd05a45f92aa15dca058f27b86d5be (diff) |
use more rtl::Reference in connectivity
instead of manual ref counting
Change-Id: I210d4a2cd6487bd2d7d81a53106b484fe411ca9b
Reviewed-on: https://gerrit.libreoffice.org/43203
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/drivers/evoab2/NStatement.cxx | 32 | ||||
-rw-r--r-- | connectivity/source/drivers/evoab2/NStatement.hxx | 6 | ||||
-rw-r--r-- | connectivity/source/drivers/odbc/OConnection.cxx | 29 | ||||
-rw-r--r-- | connectivity/source/inc/odbc/OConnection.hxx | 7 |
4 files changed, 33 insertions, 41 deletions
diff --git a/connectivity/source/drivers/evoab2/NStatement.cxx b/connectivity/source/drivers/evoab2/NStatement.cxx index 58225437ace1..095d2abf7038 100644 --- a/connectivity/source/drivers/evoab2/NStatement.cxx +++ b/connectivity/source/drivers/evoab2/NStatement.cxx @@ -72,7 +72,7 @@ OCommonStatement::OCommonStatement(OEvoabConnection* _pConnection) , ::comphelper::OPropertyContainer(OCommonStatement_IBase::rBHelper) , OStatement_CBase( static_cast<cppu::OWeakObject*>(_pConnection), this ) , m_xResultSet(nullptr) - , m_pConnection(_pConnection) + , m_xConnection(_pConnection) , m_aParser(_pConnection->getDriver().getComponentContext()) , m_aSQLIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser ) , m_pParseTree(nullptr) @@ -85,8 +85,6 @@ OCommonStatement::OCommonStatement(OEvoabConnection* _pConnection) , m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE) , m_bEscapeProcessing(true) { - m_pConnection->acquire(); - #define REGISTER_PROP( id, member ) \ registerProperty( \ OMetaConnection::getPropMap().getNameByIndex( id ), \ @@ -126,9 +124,7 @@ void OCommonStatement::disposing() disposeResultSet(); - if (m_pConnection) - m_pConnection->release(); - m_pConnection = nullptr; + m_xConnection.clear(); dispose_ChildImpl(); OCommonStatement_IBase::disposing(); @@ -198,7 +194,7 @@ OUString OCommonStatement::impl_getColumnRefColumnName_throw( const OSQLParseNod } if ( !sColumnName.getLength() ) - m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); + m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); return sColumnName; } @@ -230,7 +226,7 @@ void OCommonStatement::orderByAnalysis( const OSQLParseNode* _pOrderByClause, So // column name -> column field if ( !SQL_ISRULE( pColumnRef, column_ref ) ) - m_pConnection->throwGenericSQLException( STR_SORT_BY_COL_ONLY, *this ); + m_xConnection->throwGenericSQLException( STR_SORT_BY_COL_ONLY, *this ); const OUString sColumnName( impl_getColumnRefColumnName_throw( *pColumnRef ) ); guint nField = evoab::findEvoabField( sColumnName ); // ascending/descending? @@ -301,14 +297,14 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) ) ) { - m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); + m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); } if ( ( pPrec->getNodeType() != SQLNodeType::Equal ) && ( pPrec->getNodeType() != SQLNodeType::NotEqual ) ) { - m_pConnection->throwGenericSQLException( STR_OPERATOR_TOO_COMPLEX, *this ); + m_xConnection->throwGenericSQLException( STR_OPERATOR_TOO_COMPLEX, *this ); } // recognize the special "0 = 1" condition @@ -342,7 +338,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) const OSQLParseNode* pPart2 = parseTree->getChild(1); if( ! SQL_ISRULE( parseTree->getChild( 0 ), column_ref) ) - m_pConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_COLUMN,*this); + m_xConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_COLUMN,*this); OUString aColumnName( impl_getColumnRefColumnName_throw( *parseTree->getChild( 0 ) ) ); @@ -358,7 +354,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) SAL_INFO( "connectivity.evoab2", "analyseSQL : pAtom->count() = " << pAtom->count()); - m_pConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,*this); + m_xConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,*this); } const sal_Unicode WILDCARD = '%'; @@ -383,7 +379,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) else if( bNotLike ) { // We currently can't handle a 'NOT LIKE' when there are '%' - m_pConnection->throwGenericSQLException(STR_QUERY_NOT_LIKE_TOO_COMPLEX,*this); + m_xConnection->throwGenericSQLException(STR_QUERY_NOT_LIKE_TOO_COMPLEX,*this); } else if( aMatchString.indexOf ( WILDCARD ) == aMatchString.lastIndexOf ( WILDCARD ) ) { // One occurrence of '%' matches... @@ -392,7 +388,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) else if ( aMatchString.indexOf ( WILDCARD ) == aMatchString.getLength() - 1 ) pResult = createTest( aColumnName, E_BOOK_QUERY_BEGINS_WITH, aMatchString.copy( 0, aMatchString.getLength() - 1 ) ); else - m_pConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD,*this); + m_xConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD,*this); } else if( aMatchString.getLength() >= 3 && aMatchString.startsWith(OUStringLiteral1(WILDCARD)) && @@ -401,7 +397,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, aMatchString.copy (1, aMatchString.getLength() - 2) ); } else - m_pConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD_MANY,*this); + m_xConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD_MANY,*this); } return pResult; @@ -552,12 +548,12 @@ QueryData OCommonStatement::impl_getEBookQuery_throw( const OUString& _rSql ) #endif if ( !aData.getQuery() ) - m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); + m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); // a postcondition of this method is that we properly determined the SELECT columns aData.xSelectColumns = m_aSQLIterator.getSelectColumns(); if ( !aData.xSelectColumns.is() ) - m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); + m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this ); return aData; } @@ -566,7 +562,7 @@ QueryData OCommonStatement::impl_getEBookQuery_throw( const OUString& _rSql ) Reference< XResultSet > OCommonStatement::impl_executeQuery_throw( const QueryData& _rQueryData ) { // create result set - OEvoabResultSet* pResult = new OEvoabResultSet( this, m_pConnection ); + OEvoabResultSet* pResult = new OEvoabResultSet( this, m_xConnection.get() ); Reference< XResultSet > xRS = pResult; pResult->construct( _rQueryData ); diff --git a/connectivity/source/drivers/evoab2/NStatement.hxx b/connectivity/source/drivers/evoab2/NStatement.hxx index 87ede6f43ed9..7779673b255f 100644 --- a/connectivity/source/drivers/evoab2/NStatement.hxx +++ b/connectivity/source/drivers/evoab2/NStatement.hxx @@ -160,7 +160,7 @@ namespace connectivity private: css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created - OEvoabConnection *m_pConnection; + rtl::Reference<OEvoabConnection> m_xConnection; connectivity::OSQLParser m_aParser; connectivity::OSQLParseTreeIterator m_aSQLIterator; connectivity::OSQLParseNode *m_pParseTree; @@ -197,7 +197,7 @@ namespace connectivity public: // other methods - OEvoabConnection* getOwnConnection() const { return m_pConnection;} + OEvoabConnection* getOwnConnection() const { return m_xConnection.get(); } using OCommonStatement_IBase::operator css::uno::Reference< css::uno::XInterface >; @@ -239,7 +239,7 @@ namespace connectivity impl_executeQuery_throw( const QueryData& _rData ); css::uno::Reference< css::sdbc::XConnection > - impl_getConnection() { return css::uno::Reference< css::sdbc::XConnection >( m_pConnection ); } + impl_getConnection() { return css::uno::Reference< css::sdbc::XConnection >( m_xConnection.get() ); } OUString impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode& _rColumnRef ); diff --git a/connectivity/source/drivers/odbc/OConnection.cxx b/connectivity/source/drivers/odbc/OConnection.cxx index 711fc1b96a5b..ea2d0e07417b 100644 --- a/connectivity/source/drivers/odbc/OConnection.cxx +++ b/connectivity/source/drivers/odbc/OConnection.cxx @@ -46,7 +46,7 @@ using namespace com::sun::star::sdbc; OConnection::OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver) : OSubComponent<OConnection, OConnection_BASE>(static_cast<cppu::OWeakObject*>(_pDriver), this) - ,m_pDriver(_pDriver) + ,m_xDriver(_pDriver) ,m_aConnectionHandle(nullptr) ,m_pDriverHandleCopy(_pDriverHandle) ,m_nStatementCount(0) @@ -58,7 +58,6 @@ OConnection::OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver) ,m_bPreventGetVersionColumns(false) ,m_bReadOnly(true) { - m_pDriver->acquire(); } OConnection::~OConnection() @@ -78,9 +77,6 @@ OConnection::~OConnection() m_aConnectionHandle = SQL_NULL_HANDLE; } - - m_pDriver->release(); - m_pDriver = nullptr; } void SAL_CALL OConnection::release() throw() @@ -90,8 +86,8 @@ void SAL_CALL OConnection::release() throw() oslGenericFunction OConnection::getOdbcFunction(ODBC3SQLFunctionId _nIndex) const { - OSL_ENSURE(m_pDriver,"OConnection::getOdbcFunction: m_pDriver is null!"); - return m_pDriver->getOdbcFunction(_nIndex); + OSL_ENSURE(m_xDriver.get(),"OConnection::getOdbcFunction: m_xDriver is null!"); + return m_xDriver->getOdbcFunction(_nIndex); } SQLRETURN OConnection::OpenConnection(const OUString& aConnectStr, sal_Int32 nTimeOut, bool bSilent) @@ -479,10 +475,10 @@ void OConnection::disposing() OConnection_BASE::disposing(); - for (std::map< SQLHANDLE,OConnection*>::iterator aConIter = m_aConnections.begin();aConIter != m_aConnections.end();++aConIter ) + for (auto aConIter = m_aConnections.begin(); aConIter != m_aConnections.end(); ++aConIter ) aConIter->second->dispose(); - std::map< SQLHANDLE,OConnection*>().swap(m_aConnections); + m_aConnections.clear(); if(!m_bClosed) N3SQLDisconnect(m_aConnectionHandle); @@ -493,17 +489,16 @@ void OConnection::disposing() SQLHANDLE OConnection::createStatementHandle() { - OConnection* pConnectionTemp = this; + rtl::Reference<OConnection> xConnectionTemp = this; bool bNew = false; try { sal_Int32 nMaxStatements = getMetaData()->getMaxStatements(); if(nMaxStatements && nMaxStatements <= m_nStatementCount) { - OConnection* pConnection = new OConnection(m_pDriverHandleCopy,m_pDriver); - pConnection->acquire(); - pConnection->Construct(m_sURL,getConnectionInfo()); - pConnectionTemp = pConnection; + rtl::Reference<OConnection> xConnection(new OConnection(m_pDriverHandleCopy,m_xDriver.get())); + xConnection->Construct(m_sURL,getConnectionInfo()); + xConnectionTemp = xConnection; bNew = true; } } @@ -512,10 +507,10 @@ SQLHANDLE OConnection::createStatementHandle() } SQLHANDLE aStatementHandle = SQL_NULL_HANDLE; - N3SQLAllocHandle(SQL_HANDLE_STMT,pConnectionTemp->getConnection(),&aStatementHandle); + N3SQLAllocHandle(SQL_HANDLE_STMT,xConnectionTemp->getConnection(),&aStatementHandle); ++m_nStatementCount; if(bNew) - m_aConnections.emplace(aStatementHandle,pConnectionTemp); + m_aConnections.emplace(aStatementHandle,xConnectionTemp); return aStatementHandle; @@ -526,7 +521,7 @@ void OConnection::freeStatementHandle(SQLHANDLE& _pHandle) if( SQL_NULL_HANDLE == _pHandle ) return; - std::map< SQLHANDLE,OConnection*>::iterator aFind = m_aConnections.find(_pHandle); + auto aFind = m_aConnections.find(_pHandle); N3SQLFreeStmt(_pHandle,SQL_RESET_PARAMS); N3SQLFreeStmt(_pHandle,SQL_UNBIND); diff --git a/connectivity/source/inc/odbc/OConnection.hxx b/connectivity/source/inc/odbc/OConnection.hxx index f93e1e42e691..ed82ea85cf59 100644 --- a/connectivity/source/inc/odbc/OConnection.hxx +++ b/connectivity/source/inc/odbc/OConnection.hxx @@ -55,11 +55,12 @@ namespace connectivity // Data attributes - std::map< SQLHANDLE,OConnection*> m_aConnections; // holds all connections which are need for several statements + std::map< SQLHANDLE, rtl::Reference<OConnection>> m_aConnections; // holds all connections which are need for several statements OUString m_sUser; // the user name - ODBCDriver* m_pDriver; // Pointer to the owning + rtl::Reference<ODBCDriver> + m_xDriver; // Pointer to the owning // driver object SQLHANDLE m_aConnectionHandle; @@ -125,7 +126,7 @@ namespace connectivity bool isIgnoreDriverPrivilegesEnabled() const { return m_bIgnoreDriverPrivileges; } bool preventGetVersionColumns() const { return m_bPreventGetVersionColumns; } bool useOldDateFormat() const { return m_bUseOldDateFormat; } - ODBCDriver* getDriver() const { return m_pDriver;} + ODBCDriver* getDriver() const { return m_xDriver.get();} SQLHANDLE createStatementHandle(); // close and free the handle and set it to SQL_NULLHANDLE |