Kaydet (Commit) 7af52182 authored tarafından Noel Grandin's avatar Noel Grandin

use rtl::Reference in mysqlc

instead of manual ref-counting

Change-Id: I7b7c350613976463620a54757add6061cf383a4c
Reviewed-on: https://gerrit.libreoffice.org/43183Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 4fc52078
......@@ -65,10 +65,9 @@ OConnection::OConnection(MysqlCDriver& _rDriver, sql::Driver * _cppDriver)
:OMetaConnection_BASE(m_aMutex)
,OSubComponent<OConnection, OConnection_BASE>(static_cast<cppu::OWeakObject*>(&_rDriver), this)
,m_xMetaData(nullptr)
,m_rDriver(_rDriver)
,m_xDriver(&_rDriver)
,cppDriver(_cppDriver)
{
m_rDriver.acquire();
}
OConnection::~OConnection()
......@@ -76,7 +75,6 @@ OConnection::~OConnection()
if (!isClosed()) {
close();
}
m_rDriver.release();
}
void SAL_CALL OConnection::release()
......@@ -536,7 +534,7 @@ rtl::OUString OConnection::transFormPreparedStatement(const rtl::OUString& _sSQL
Reference< XConnection> xCon = this;
aArgs[0] <<= NamedValue(rtl::OUString("ActiveConnection"), makeAny(xCon));
m_xParameterSubstitution.set(m_rDriver.getFactory()->createInstanceWithArguments("org.openoffice.comp.helper.ParameterSubstitution",aArgs),UNO_QUERY);
m_xParameterSubstitution.set(m_xDriver->getFactory()->createInstanceWithArguments("org.openoffice.comp.helper.ParameterSubstitution",aArgs),UNO_QUERY);
} catch(const Exception&) {}
}
if ( m_xParameterSubstitution.is() ) {
......
......@@ -41,6 +41,7 @@
#include <cppuhelper/compbase3.hxx>
#include <cppuhelper/weakref.hxx>
#include <rtl/string.hxx>
#include <rtl/ref.hxx>
#include <map>
......@@ -104,7 +105,7 @@ namespace connectivity
// of all the Statement objects
// for this Connection
MysqlCDriver& m_rDriver; // Pointer to the owning driver object
rtl::Reference<MysqlCDriver> m_xDriver; // Pointer to the owning driver object
sql::Driver* cppDriver;
public:
......@@ -185,7 +186,7 @@ namespace connectivity
const ConnectionSettings& getConnectionSettings() const { return m_settings; }
rtl::OUString transFormPreparedStatement(const rtl::OUString& _sSQL);
const MysqlCDriver& getDriver() const { return m_rDriver;}
const MysqlCDriver& getDriver() const { return *m_xDriver.get();}
}; /* OConnection */
// TODO: Not used.
......
......@@ -56,10 +56,9 @@ OCommonStatement::OCommonStatement(OConnection* _pConnection, sql::Statement *_c
:OCommonStatement_IBase(m_aMutex)
,OPropertySetHelper(OCommonStatement_IBase::rBHelper)
,OStatement_CBase( static_cast<cppu::OWeakObject*>(_pConnection), this )
,m_pConnection(_pConnection)
,m_xConnection(_pConnection)
,cppStatement(_cppStatement)
{
m_pConnection->acquire();
}
OCommonStatement::~OCommonStatement()
......@@ -79,10 +78,7 @@ void OCommonStatement::disposing()
disposeResultSet();
if (m_pConnection) {
m_pConnection->release();
m_pConnection = nullptr;
}
m_xConnection.clear();
delete cppStatement;
dispose_ChildImpl();
......@@ -136,13 +132,13 @@ sal_Bool SAL_CALL OCommonStatement::execute(const rtl::OUString& sql)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(rBHelper.bDisposed);
const rtl::OUString sSqlStatement = m_pConnection->transFormPreparedStatement( sql );
const rtl::OUString sSqlStatement = m_xConnection->transFormPreparedStatement( sql );
bool success = false;
try {
success = cppStatement->execute(rtl::OUStringToOString(sSqlStatement, m_pConnection->getConnectionSettings().encoding).getStr());
success = cppStatement->execute(rtl::OUStringToOString(sSqlStatement, m_xConnection->getConnectionSettings().encoding).getStr());
} catch (const sql::SQLException &e) {
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_xConnection->getConnectionEncoding());
}
return success;
}
......@@ -151,15 +147,15 @@ Reference< XResultSet > SAL_CALL OCommonStatement::executeQuery(const rtl::OUStr
{
MutexGuard aGuard(m_aMutex);
checkDisposed(rBHelper.bDisposed);
const rtl::OUString sSqlStatement = m_pConnection->transFormPreparedStatement(sql);
const rtl::OUString sSqlStatement = m_xConnection->transFormPreparedStatement(sql);
Reference< XResultSet > xResultSet;
try {
std::unique_ptr< sql::ResultSet > rset(cppStatement->executeQuery(rtl::OUStringToOString(sSqlStatement, m_pConnection->getConnectionEncoding()).getStr()));
xResultSet = new OResultSet(this, rset.get(), m_pConnection->getConnectionEncoding());
std::unique_ptr< sql::ResultSet > rset(cppStatement->executeQuery(rtl::OUStringToOString(sSqlStatement, m_xConnection->getConnectionEncoding()).getStr()));
xResultSet = new OResultSet(this, rset.get(), m_xConnection->getConnectionEncoding());
rset.release();
} catch (const sql::SQLException &e) {
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_xConnection->getConnectionEncoding());
}
return xResultSet;
}
......@@ -170,7 +166,7 @@ Reference< XConnection > SAL_CALL OCommonStatement::getConnection()
checkDisposed(rBHelper.bDisposed);
// just return our connection here
return m_pConnection;
return m_xConnection.get();
}
sal_Int32 SAL_CALL OCommonStatement::getUpdateCount()
......@@ -206,13 +202,13 @@ sal_Int32 SAL_CALL OCommonStatement::executeUpdate(const rtl::OUString& sql)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(rBHelper.bDisposed);
const rtl::OUString sSqlStatement = m_pConnection->transFormPreparedStatement(sql);
const rtl::OUString sSqlStatement = m_xConnection->transFormPreparedStatement(sql);
sal_Int32 affectedRows = 0;
try {
affectedRows = cppStatement->executeUpdate(rtl::OUStringToOString(sSqlStatement, m_pConnection->getConnectionEncoding()).getStr());
affectedRows = cppStatement->executeUpdate(rtl::OUStringToOString(sSqlStatement, m_xConnection->getConnectionEncoding()).getStr());
} catch (const sql::SQLException &e) {
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_xConnection->getConnectionEncoding());
}
return affectedRows;
}
......@@ -225,10 +221,10 @@ Reference< XResultSet > SAL_CALL OCommonStatement::getResultSet()
Reference< XResultSet > xResultSet;
try {
std::unique_ptr< sql::ResultSet > rset(cppStatement->getResultSet());
xResultSet = new OResultSet(this, rset.get(), m_pConnection->getConnectionEncoding());
xResultSet = new OResultSet(this, rset.get(), m_xConnection->getConnectionEncoding());
rset.release();
} catch (const sql::SQLException &e) {
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
mysqlc_sdbc_driver::translateAndThrow(e, *this, m_xConnection->getConnectionEncoding());
}
return xResultSet;
}
......
......@@ -34,6 +34,7 @@
#include <cppconn/statement.h>
#include <cppuhelper/compbase5.hxx>
#include <rtl/ref.hxx>
namespace connectivity
{
......@@ -70,7 +71,7 @@ namespace connectivity
SQLWarning m_aLastWarning;
protected:
OConnection* m_pConnection; // The owning Connection object
rtl::Reference<OConnection> m_xConnection; // The owning Connection object
sql::Statement *cppStatement;
......@@ -142,7 +143,7 @@ namespace connectivity
sal_Bool SAL_CALL getMoreResults() SAL_OVERRIDE;
// other methods
OConnection* getOwnConnection() const { return m_pConnection;}
OConnection* getOwnConnection() const { return m_xConnection.get();}
private:
using ::cppu::OPropertySetHelper::getFastPropertyValue;
......
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