From 5b74c6563cfc802b5330fb82500be9d6cd835fe2 Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Mon, 9 Sep 2013 17:28:08 +0100 Subject: Cleanup Connection and rename from OConnection. (firebird-sdbc) Change-Id: I06cfdc29d7613638d3cea080e7b39c67c74d4de0 --- .../source/drivers/firebird/Connection.cxx | 291 +++++++++++---------- .../source/drivers/firebird/Connection.hxx | 107 +++++--- .../source/drivers/firebird/DatabaseMetaData.cxx | 2 +- .../source/drivers/firebird/DatabaseMetaData.hxx | 6 +- connectivity/source/drivers/firebird/Driver.cxx | 4 +- .../source/drivers/firebird/PreparedStatement.cxx | 2 +- .../source/drivers/firebird/PreparedStatement.hxx | 2 +- connectivity/source/drivers/firebird/ResultSet.cxx | 2 +- connectivity/source/drivers/firebird/ResultSet.hxx | 4 +- .../source/drivers/firebird/ResultSetMetaData.hxx | 4 +- connectivity/source/drivers/firebird/Statement.hxx | 2 +- .../drivers/firebird/StatementCommonBase.cxx | 2 +- .../drivers/firebird/StatementCommonBase.hxx | 6 +- 13 files changed, 236 insertions(+), 198 deletions(-) (limited to 'connectivity') diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index b88420f0b6b3..dd5d52506735 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -71,47 +71,44 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::uno; -const OUString OConnection::sDBLocation( "firebird.fdb" ); - -OConnection::OConnection(FirebirdDriver* _pDriver) - :OConnection_BASE(m_aMutex), - OSubComponent((::cppu::OWeakObject*)_pDriver, this), - m_xMetaData(NULL), - m_bIsEmbedded(sal_False), - m_sConnectionURL(), - m_sURL(), - m_sUser(), - m_pDriver(_pDriver), - m_bClosed(sal_False), - m_bUseOldDateFormat(sal_False), - m_bAutoCommit(sal_False), - m_bReadOnly(sal_False), - m_aTransactionIsolation(TransactionIsolation::REPEATABLE_READ), - m_DBHandler(0), - m_transactionHandle(0), - m_xCatalog(0) -{ - SAL_INFO("connectivity.firebird", "OConnection()."); - +const OUString Connection::our_sDBLocation( "firebird.fdb" ); + +Connection::Connection(FirebirdDriver* _pDriver) + : Connection_BASE(m_aMutex) + , OSubComponent((::cppu::OWeakObject*)_pDriver, this) + , m_pDriver(_pDriver) + , m_sConnectionURL() + , m_sFirebirdURL() + , m_bIsEmbedded(sal_False) + , m_xEmbeddedStorage(0) + , m_sUser() + , m_bIsAutoCommit(sal_False) + , m_bIsReadOnly(sal_False) + , m_aTransactionIsolation(TransactionIsolation::REPEATABLE_READ) + , m_aDBHandle(0) + , m_aTransactionHandle(0) + , m_xCatalog(0) + , m_xMetaData(0) + , m_aStatements() +{ m_pDriver->acquire(); } -OConnection::~OConnection() +Connection::~Connection() { - SAL_INFO("connectivity.firebird", "~OConnection()."); - if(!isClosed()) close(); + m_pDriver->release(); - m_pDriver = NULL; + m_pDriver = 0; } -void SAL_CALL OConnection::release() throw() +void SAL_CALL Connection::release() throw() { relase_ChildImpl(); } -void OConnection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info) +void Connection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "construct()."); @@ -151,21 +148,21 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property m_pExtractedFDBFile.reset(new ::utl::TempFile(NULL, true)); m_pExtractedFDBFile->EnableKillingFile(); - m_sURL = m_pExtractedFDBFile->GetFileName() + "/firebird.fdb"; + m_sFirebirdURL = m_pExtractedFDBFile->GetFileName() + "/firebird.fdb"; - SAL_INFO("connectivity.firebird", "Temporary .fdb location: " << m_sURL); + SAL_INFO("connectivity.firebird", "Temporary .fdb location: " << m_sFirebirdURL); if (!bIsNewDatabase) { SAL_INFO("connectivity.firebird", "Extracting .fdb from .odb" ); - if (!m_xEmbeddedStorage->isStreamElement(sDBLocation)) + if (!m_xEmbeddedStorage->isStreamElement(our_sDBLocation)) { ::connectivity::SharedResources aResources; const OUString sMessage = aResources.getResourceString(STR_ERROR_NEW_VERSION); ::dbtools::throwGenericSQLException(sMessage ,*this); } - Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(sDBLocation, + Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sDBLocation, ElementModes::READ)); uno::Reference< ucb::XSimpleFileAccess2 > xFileAccess( @@ -178,7 +175,7 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property ::dbtools::throwGenericSQLException(sMessage ,*this); } - xFileAccess->writeFile(m_sURL,xDBStream->getInputStream()); + xFileAccess->writeFile(m_sFirebirdURL,xDBStream->getInputStream()); } // TOOO: Get DB properties from XML @@ -186,13 +183,13 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property // External file AND/OR remote connection else if (url.startsWith("sdbc:firebird:")) { - m_sURL = url.copy(OUString("sdbc:firebird:").getLength()); - if (m_sURL.startsWith("file://")) // TODO: are file urls really like this? + m_sFirebirdURL = url.copy(OUString("sdbc:firebird:").getLength()); + if (m_sFirebirdURL.startsWith("file://")) // TODO: are file urls really like this? { uno::Reference< ucb::XSimpleFileAccess > xFileAccess( ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY); - if (!xFileAccess->exists(m_sURL)) + if (!xFileAccess->exists(m_sFirebirdURL)) bIsNewDatabase = true; } } @@ -249,9 +246,9 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property if (bIsNewDatabase) { aErr = isc_create_database(status, - m_sURL.getLength(), - OUStringToOString(m_sURL,RTL_TEXTENCODING_UTF8).getStr(), - &m_DBHandler, + m_sFirebirdURL.getLength(), + OUStringToOString(m_sFirebirdURL,RTL_TEXTENCODING_UTF8).getStr(), + &m_aDBHandle, dpbLength, dpbBuffer, 0); @@ -263,9 +260,9 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property else { aErr = isc_attach_database(status, - m_sURL.getLength(), - OUStringToOString(m_sURL, RTL_TEXTENCODING_UTF8).getStr(), - &m_DBHandler, + m_sFirebirdURL.getLength(), + OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8).getStr(), + &m_aDBHandle, dpbLength, dpbBuffer); if (aErr) @@ -282,54 +279,65 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property // it in the .odb. rebuildIndexes(); - uno::Reference< frame::XDesktop2 > xFramesSupplier = - frame::Desktop::create(::comphelper::getProcessComponentContext()); - uno::Reference< frame::XFrames > xFrames( xFramesSupplier->getFrames(), - uno::UNO_QUERY); - uno::Sequence< uno::Reference > xFrameList = - xFrames->queryFrames( frame::FrameSearchFlag::ALL ); - for (sal_Int32 i = 0; i < xFrameList.getLength(); i++) - { - uno::Reference< frame::XFrame > xf = xFrameList[i]; + attachAsDocumentListener(aStorageURL); + } + + osl_atomic_decrement( &m_refCount ); +} + +void Connection::attachAsDocumentListener(const OUString& rStorageURL) +{ + // We can't directly access the Document that is using this connection + // (since a Connection can in fact be used independently of a DB document) + // hence we need to iterate through all Frames to find our Document. + uno::Reference< frame::XDesktop2 > xFramesSupplier = + frame::Desktop::create(::comphelper::getProcessComponentContext()); + uno::Reference< frame::XFrames > xFrames(xFramesSupplier->getFrames(), + uno::UNO_QUERY); + if (!xFrames.is()) + return; - uno::Reference< XController > xc; - if (xf.is()) - xc = xf->getController(); + uno::Sequence< uno::Reference > xFrameList = + xFrames->queryFrames( frame::FrameSearchFlag::ALL ); - uno::Reference< XModel > xm; - if (xc.is()) - xm = xc->getModel(); + for (sal_Int32 i = 0; i < xFrameList.getLength(); i++) + { + uno::Reference< frame::XFrame > xf = xFrameList[i]; + uno::Reference< XController > xc; + if (xf.is()) + xc = xf->getController(); - OUString aURL; + uno::Reference< XModel > xm; + if (xc.is()) + xm = xc->getModel(); - if (xm.is()) - aURL = xm->getURL(); - if (aURL == aStorageURL) + if (xm.is() && xm->getURL() == rStorageURL) + { + uno::Reference xBroadcaster( xm, UNO_QUERY); + if (xBroadcaster.is()) { - uno::Reference xBroadcaster( xm, UNO_QUERY); - if (xBroadcaster.is()) - xBroadcaster->addDocumentEventListener( this ); - //TODO: remove in the disposing? + xBroadcaster->addDocumentEventListener(this); + return; } + //TODO: remove in the disposing? } } - - osl_atomic_decrement( &m_refCount ); + assert(false); // If we have an embedded DB we must have a document } //----- XServiceInfo --------------------------------------------------------- -IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.firebird.OConnection", +IMPLEMENT_SERVICE_INFO(Connection, "com.sun.star.sdbc.drivers.firebird.Connection", "com.sun.star.sdbc.Connection") -Reference< XBlob> OConnection::createBlob(ISC_QUAD* pBlobId) +Reference< XBlob> Connection::createBlob(ISC_QUAD* pBlobId) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "createBlob()"); MutexGuard aGuard(m_aMutex); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); - Reference< XBlob > xReturn = new Blob(&m_DBHandler, - &m_transactionHandle, + Reference< XBlob > xReturn = new Blob(&m_aDBHandle, + &m_aTransactionHandle, *pBlobId); m_aStatements.push_back(WeakReferenceHelper(xReturn)); @@ -338,13 +346,13 @@ Reference< XBlob> OConnection::createBlob(ISC_QUAD* pBlobId) //----- XConnection ---------------------------------------------------------- -Reference< XStatement > SAL_CALL OConnection::createStatement( ) +Reference< XStatement > SAL_CALL Connection::createStatement( ) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "createStatement()."); MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); // the pre if(m_aTypeInfo.empty()) @@ -360,14 +368,14 @@ Reference< XStatement > SAL_CALL OConnection::createStatement( ) return xReturn; } -Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( +Reference< XPreparedStatement > SAL_CALL Connection::prepareStatement( const OUString& _sSql) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "prepareStatement() " "called with sql: " << _sSql); MutexGuard aGuard(m_aMutex); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); if(m_aTypeInfo.empty()) buildTypeInfo(); @@ -380,20 +388,20 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( return xReturn; } -Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( +Reference< XPreparedStatement > SAL_CALL Connection::prepareCall( const OUString& _sSql ) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "prepareCall(). " "_sSql: " << _sSql); MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); // not implemented yet :-) a task to do return NULL; } -OUString SAL_CALL OConnection::nativeSQL( const OUString& _sSql ) +OUString SAL_CALL Connection::nativeSQL( const OUString& _sSql ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); @@ -401,29 +409,29 @@ OUString SAL_CALL OConnection::nativeSQL( const OUString& _sSql ) return _sSql; } -void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) +void SAL_CALL Connection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); - m_bAutoCommit = autoCommit; + m_bIsAutoCommit = autoCommit; - if (m_transactionHandle) + if (m_aTransactionHandle) { setupTransaction(); } } -sal_Bool SAL_CALL OConnection::getAutoCommit() throw(SQLException, RuntimeException) +sal_Bool SAL_CALL Connection::getAutoCommit() throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); - return m_bAutoCommit; + return m_bIsAutoCommit; } -void OConnection::setupTransaction() +void Connection::setupTransaction() throw (SQLException) { MutexGuard aGuard( m_aMutex ); @@ -431,10 +439,10 @@ void OConnection::setupTransaction() // TODO: is this sensible? If we have changed parameters then transaction // is lost... - if (m_transactionHandle) + if (m_aTransactionHandle) { - clearStatements(); - isc_rollback_transaction(status_vector, &m_transactionHandle); + disposeStatements(); + isc_rollback_transaction(status_vector, &m_aTransactionHandle); } char aTransactionIsolation = 0; @@ -463,16 +471,16 @@ void OConnection::setupTransaction() char* pTPB = aTPB; *pTPB++ = isc_tpb_version3; - if (m_bAutoCommit) + if (m_bIsAutoCommit) *pTPB++ = isc_tpb_autocommit; - *pTPB++ = (!m_bReadOnly ? isc_tpb_write : isc_tpb_read); + *pTPB++ = (!m_bIsReadOnly ? isc_tpb_write : isc_tpb_read); *pTPB++ = aTransactionIsolation; *pTPB++ = isc_tpb_wait; isc_start_transaction(status_vector, - &m_transactionHandle, + &m_aTransactionHandle, 1, - &m_DBHandler, + &m_aDBHandle, pTPB - aTPB, // bytes used in TPB aTPB); @@ -481,59 +489,59 @@ void OConnection::setupTransaction() *this); } -isc_tr_handle& OConnection::getTransaction() +isc_tr_handle& Connection::getTransaction() throw (SQLException) { MutexGuard aGuard( m_aMutex ); - if (!m_transactionHandle) + if (!m_aTransactionHandle) { setupTransaction(); } - return m_transactionHandle; + return m_aTransactionHandle; } -void SAL_CALL OConnection::commit() throw(SQLException, RuntimeException) +void SAL_CALL Connection::commit() throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); ISC_STATUS status_vector[20]; - if (!m_bAutoCommit && m_transactionHandle) + if (!m_bIsAutoCommit && m_aTransactionHandle) { - clearStatements(); - isc_commit_transaction(status_vector, &m_transactionHandle); + disposeStatements(); + isc_commit_transaction(status_vector, &m_aTransactionHandle); evaluateStatusVector(status_vector, "isc_commit_transaction", *this); } } -void SAL_CALL OConnection::rollback() throw(SQLException, RuntimeException) +void SAL_CALL Connection::rollback() throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); ISC_STATUS status_vector[20]; - if (!m_bAutoCommit && m_transactionHandle) + if (!m_bIsAutoCommit && m_aTransactionHandle) { - isc_rollback_transaction(status_vector, &m_transactionHandle); + isc_rollback_transaction(status_vector, &m_aTransactionHandle); } } -sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException) +sal_Bool SAL_CALL Connection::isClosed( ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); // just simple -> we are close when we are disposed taht means someone called dispose(); (XComponent) - return OConnection_BASE::rBHelper.bDisposed; + return Connection_BASE::rBHelper.bDisposed; } // -------------------------------------------------------------------------------- -Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) +Reference< XDatabaseMetaData > SAL_CALL Connection::getMetaData( ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); // here we have to create the class with biggest interface // The answer is 42 :-) @@ -547,61 +555,61 @@ Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLEx return xMetaData; } -void SAL_CALL OConnection::setReadOnly(sal_Bool readOnly) +void SAL_CALL Connection::setReadOnly(sal_Bool readOnly) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); - m_bReadOnly = readOnly; + m_bIsReadOnly = readOnly; setupTransaction(); } -sal_Bool SAL_CALL OConnection::isReadOnly() throw(SQLException, RuntimeException) +sal_Bool SAL_CALL Connection::isReadOnly() throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); - return m_bReadOnly; + return m_bIsReadOnly; } -void SAL_CALL OConnection::setCatalog(const OUString& /*catalog*/) +void SAL_CALL Connection::setCatalog(const OUString& /*catalog*/) throw(SQLException, RuntimeException) { ::dbtools::throwFunctionNotSupportedException("setCatalog", *this); } -OUString SAL_CALL OConnection::getCatalog() +OUString SAL_CALL Connection::getCatalog() throw(SQLException, RuntimeException) { ::dbtools::throwFunctionNotSupportedException("getCatalog", *this); return OUString(); } -void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) +void SAL_CALL Connection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); m_aTransactionIsolation = level; setupTransaction(); } -sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) +sal_Int32 SAL_CALL Connection::getTransactionIsolation( ) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); return m_aTransactionIsolation; } -Reference< XNameAccess > SAL_CALL OConnection::getTypeMap() throw(SQLException, RuntimeException) +Reference< XNameAccess > SAL_CALL Connection::getTypeMap() throw(SQLException, RuntimeException) { ::dbtools::throwFeatureNotImplementedException( "XConnection::getTypeMap", *this ); return 0; } -void SAL_CALL OConnection::setTypeMap(const Reference< XNameAccess >& typeMap) +void SAL_CALL Connection::setTypeMap(const Reference< XNameAccess >& typeMap) throw(SQLException, RuntimeException) { ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this ); @@ -609,33 +617,33 @@ void SAL_CALL OConnection::setTypeMap(const Reference< XNameAccess >& typeMap) } //----- XCloseable ----------------------------------------------------------- -void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException) +void SAL_CALL Connection::close( ) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "close()."); // we just dispose us { MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); + checkDisposed(Connection_BASE::rBHelper.bDisposed); } dispose(); } // -------------------------------------------------------------------------------- // XWarningsSupplier -Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException) +Any SAL_CALL Connection::getWarnings( ) throw(SQLException, RuntimeException) { // when you collected some warnings -> return it return Any(); } // -------------------------------------------------------------------------------- -void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException) +void SAL_CALL Connection::clearWarnings( ) throw(SQLException, RuntimeException) { // you should clear your collected warnings here } // -------------------------------------------------------------------------------- // XDocumentEventListener -void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event ) +void SAL_CALL Connection::documentEventOccured( const DocumentEvent& _Event ) throw(RuntimeException) { MutexGuard aGuard(m_aMutex); @@ -650,7 +658,7 @@ void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event ) { SAL_INFO("connectivity.firebird", "Writing .fdb into .odb" ); - Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(sDBLocation, + Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sDBLocation, ElementModes::WRITE)); using namespace ::comphelper; @@ -658,7 +666,7 @@ void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event ) Reference< XInputStream > xInputStream; if (xContext.is()) xInputStream = - OStorageHelper::GetInputStreamFromURL(m_sURL, xContext); + OStorageHelper::GetInputStreamFromURL(m_sFirebirdURL, xContext); if (xInputStream.is()) OStorageHelper::CopyInputToOutput( xInputStream, xDBStream->getOutputStream()); @@ -667,12 +675,12 @@ void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event ) } } // XEventListener -void SAL_CALL OConnection::disposing(const EventObject& /*rSource*/) +void SAL_CALL Connection::disposing(const EventObject& /*rSource*/) throw (RuntimeException) { } //-------------------------------------------------------------------- -void OConnection::buildTypeInfo() throw( SQLException) +void Connection::buildTypeInfo() throw( SQLException) { SAL_INFO("connectivity.firebird", "buildTypeInfo()."); @@ -725,25 +733,24 @@ void OConnection::buildTypeInfo() throw( SQLException) "Closed."); } -void OConnection::disposing() +void Connection::disposing() { SAL_INFO("connectivity.firebird", "disposing()."); MutexGuard aGuard(m_aMutex); - clearStatements(); + disposeStatements(); - m_bClosed = sal_True; m_xMetaData = ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData>(); ISC_STATUS_ARRAY status; /* status vector */ - if (m_transactionHandle) + if (m_aTransactionHandle) { // TODO: confirm whether we need to ask the user here. - isc_rollback_transaction(status, &m_transactionHandle); + isc_rollback_transaction(status, &m_aTransactionHandle); } - if (isc_detach_database(status, &m_DBHandler)) + if (isc_detach_database(status, &m_aDBHandle)) { evaluateStatusVector(status, "isc_detach_database", *this); } @@ -753,7 +760,7 @@ void OConnection::disposing() cppu::WeakComponentImplHelperBase::disposing(); } -void OConnection::clearStatements() +void Connection::disposeStatements() { MutexGuard aGuard(m_aMutex); for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) @@ -765,7 +772,7 @@ void OConnection::clearStatements() m_aStatements.clear(); } -uno::Reference< XTablesSupplier > OConnection::createCatalog() +uno::Reference< XTablesSupplier > Connection::createCatalog() { MutexGuard aGuard(m_aMutex); @@ -784,7 +791,7 @@ uno::Reference< XTablesSupplier > OConnection::createCatalog() } -void OConnection::rebuildIndexes() throw(SQLException) +void Connection::rebuildIndexes() throw(SQLException) { SAL_INFO("connectivity.firebird", "rebuildIndexes()"); MutexGuard aGuard(m_aMutex); diff --git a/connectivity/source/drivers/firebird/Connection.hxx b/connectivity/source/drivers/firebird/Connection.hxx index 21da127a01da..0d4e484ea088 100644 --- a/connectivity/source/drivers/firebird/Connection.hxx +++ b/connectivity/source/drivers/firebird/Connection.hxx @@ -55,7 +55,7 @@ namespace connectivity ::com::sun::star::lang::XServiceInfo, ::com::sun::star::sdbc::XConnection, ::com::sun::star::sdbc::XWarningsSupplier - > OConnection_BASE; + > Connection_BASE; class OStatementCommonBase; class FirebirdDriver; @@ -65,57 +65,80 @@ namespace connectivity typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; - class OConnection : public OConnection_BASE, - public connectivity::OSubComponent + class Connection : public Connection_BASE, + public connectivity::OSubComponent { - friend class connectivity::OSubComponent; + friend class connectivity::OSubComponent; + /** + * Location within the .odb that an embedded .fdb will be stored. + * Only relevant for embedded dbs. + */ + static const OUString our_sDBLocation; protected: ::osl::Mutex m_aMutex; public: ::osl::Mutex& getMutex() { return m_aMutex; } protected: - ::boost::scoped_ptr< ::utl::TempFile > m_pExtractedFDBFile; - static const OUString sDBLocation; // Location within .odb container - //==================================================================== - // Data attributes - //==================================================================== + + + TTypeInfoVector m_aTypeInfo; // vector containing an entry // for each row returned by // DatabaseMetaData.getTypeInfo. - ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData; + /** The parent driver that created this connection. */ + FirebirdDriver* m_pDriver; - OWeakRefArray m_aStatements; // vector containing a list - // of all the Statement objects - // for this Connection + /** The URL passed to us when opening, i.e. of the form sdbc:* */ + ::rtl::OUString m_sConnectionURL; + /** + * The URL passed to firebird, i.e. either a local file (for a + * temporary .fdb extracted from a .odb or a normal local file) or + * a remote url. + */ + ::rtl::OUString m_sFirebirdURL; - ::com::sun::star::sdbc::SQLWarning m_aLastWarning; // Last SQLWarning generated by - // an operation - sal_Bool m_bIsEmbedded; - ::rtl::OUString m_sConnectionURL; - ::rtl::OUString m_sURL; // URL of connection - // or file path - ::rtl::OUString m_sUser; // the user name - FirebirdDriver* m_pDriver; // Pointer to the owning - // driver object + /* EMBEDDED MODE DATA */ + /** Denotes that we have a .fdb stored within a .odb file. */ + sal_Bool m_bIsEmbedded; + /** + * Handle for the folder within the .odb where we store our .fdb + * (Only used if m_bIsEmbedded is true). + */ + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + m_xEmbeddedStorage; + /** + * The temporary folder where we extract the .fdb from a .odb. + * It is only valid if m_bIsEmbedded is true. + */ + ::boost::scoped_ptr< ::utl::TempFile > m_pExtractedFDBFile; - sal_Bool m_bClosed; - sal_Bool m_bUseOldDateFormat; - sal_Bool m_bAutoCommit; - sal_Bool m_bReadOnly; - sal_Int32 m_aTransactionIsolation; + /* REMOTE CONNECTION DATA */ + ::rtl::OUString m_sUser; - isc_db_handle m_DBHandler; - isc_tr_handle m_transactionHandle; + /* CONNECTION PROPERTIES */ + sal_Bool m_bIsAutoCommit; + sal_Bool m_bIsReadOnly; + sal_Int32 m_aTransactionIsolation; + + isc_db_handle m_aDBHandle; + isc_tr_handle m_aTransactionHandle; - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > - m_xEmbeddedStorage; ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier> m_xCatalog; + ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > + m_xMetaData; + /** Statements owned by this connection. */ + OWeakRefArray m_aStatements; + /** + * If we are embedded in a .odb we need to listen to Document events + * in order to save the .fdb back into the .odb. + */ + void attachAsDocumentListener(const ::rtl::OUString& rStorageURL); /** * Firebird stores binary collations for indexes on Character based @@ -123,19 +146,27 @@ namespace connectivity * version, hence we need to rebuild the indexes when switching icu * versions. */ - void rebuildIndexes() throw( ::com::sun::star::sdbc::SQLException); - void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); + void rebuildIndexes() + throw(::com::sun::star::sdbc::SQLException); + void buildTypeInfo() + throw(::com::sun::star::sdbc::SQLException); - void setupTransaction() throw(::com::sun::star::sdbc::SQLException); - void clearStatements(); + /** + * Creates a new transaction with the desired parameters, if + * necessary discarding an existing transaction. This has to be done + * anytime we change the transaction isolation, or autocommiting. + */ + void setupTransaction() + throw(::com::sun::star::sdbc::SQLException); + void disposeStatements(); public: virtual void construct( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - OConnection(FirebirdDriver* _pDriver); - virtual ~OConnection(); + Connection(FirebirdDriver* _pDriver); + virtual ~Connection(); void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException); @@ -176,7 +207,7 @@ namespace connectivity virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); inline ::rtl::OUString getUserName() const { return m_sUser; } - inline isc_db_handle& getDBHandle() { return m_DBHandler; } + inline isc_db_handle& getDBHandle() { return m_aDBHandle; } inline FirebirdDriver* getDriver() const { return m_pDriver;} ::rtl::OUString getConnectionURL() const { return m_sConnectionURL; } diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index 19f66d5b11da..b7e1a5cb010a 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -54,7 +54,7 @@ namespace connectivity } } -ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) +ODatabaseMetaData::ODatabaseMetaData(Connection* _pCon) : m_pConnection(_pCon) { OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!"); diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.hxx b/connectivity/source/drivers/firebird/DatabaseMetaData.hxx index 54ef0db7a8f6..3004df9d3a2f 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.hxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.hxx @@ -37,12 +37,12 @@ namespace connectivity class ODatabaseMetaData : public ODatabaseMetaData_BASE { - OConnection* m_pConnection; + Connection* m_pConnection; public: - inline OConnection* getOwnConnection() const { return m_pConnection; } + inline Connection* getOwnConnection() const { return m_pConnection; } - ODatabaseMetaData(OConnection* _pCon); + ODatabaseMetaData(Connection* _pCon); virtual ~ODatabaseMetaData(); // as I mentioned before this interface is really BIG diff --git a/connectivity/source/drivers/firebird/Driver.cxx b/connectivity/source/drivers/firebird/Driver.cxx index 4480bb9be4dc..6b4913cbf42c 100644 --- a/connectivity/source/drivers/firebird/Driver.cxx +++ b/connectivity/source/drivers/firebird/Driver.cxx @@ -147,7 +147,7 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( if ( ! acceptsURL(url) ) return NULL; - OConnection* pCon = new OConnection(this); + Connection* pCon = new Connection(this); Reference< XConnection > xCon = pCon; pCon->construct(url, info); m_xConnections.push_back(WeakReferenceHelper(*pCon)); @@ -193,7 +193,7 @@ uno::Reference< XTablesSupplier > SAL_CALL FirebirdDriver::getDataDefinitionByCo const uno::Reference< XConnection >& rConnection) throw(SQLException, RuntimeException) { - OConnection* pConnection = static_cast< OConnection* >(rConnection.get()); + Connection* pConnection = static_cast< Connection* >(rConnection.get()); return uno::Reference< XTablesSupplier >(pConnection->createCatalog(), UNO_QUERY); } diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index f23871cc0a03..29d0f000160f 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -50,7 +50,7 @@ using namespace com::sun::star::util; IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.firebird.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); -OPreparedStatement::OPreparedStatement( OConnection* _pConnection, +OPreparedStatement::OPreparedStatement( Connection* _pConnection, const TTypeInfoVector& _TypeInfo, const OUString& sql) :OStatementCommonBase(_pConnection) diff --git a/connectivity/source/drivers/firebird/PreparedStatement.hxx b/connectivity/source/drivers/firebird/PreparedStatement.hxx index 1a8b0f458cba..d052b7ee4b0f 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.hxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.hxx @@ -96,7 +96,7 @@ namespace connectivity public: DECLARE_SERVICE_INFO(); // a constructor, which is required for returning objects: - OPreparedStatement( OConnection* _pConnection, + OPreparedStatement( Connection* _pConnection, const TTypeInfoVector& _TypeInfo, const ::rtl::OUString& sql); diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx index 113ba5f5b0e9..50930321823d 100644 --- a/connectivity/source/drivers/firebird/ResultSet.cxx +++ b/connectivity/source/drivers/firebird/ResultSet.cxx @@ -53,7 +53,7 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::io; using namespace ::com::sun::star::util; -OResultSet::OResultSet(OConnection* pConnection, +OResultSet::OResultSet(Connection* pConnection, const uno::Reference< XInterface >& xStatement, isc_stmt_handle& aStatementHandle, XSQLDA* pSqlda) diff --git a/connectivity/source/drivers/firebird/ResultSet.hxx b/connectivity/source/drivers/firebird/ResultSet.hxx index 129edda6042b..2963b65fde9c 100644 --- a/connectivity/source/drivers/firebird/ResultSet.hxx +++ b/connectivity/source/drivers/firebird/ResultSet.hxx @@ -74,7 +74,7 @@ namespace connectivity sal_Int32 m_nResultSetConcurrency; protected: - OConnection* m_pConnection; + Connection* m_pConnection; const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& m_xStatement; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData; @@ -113,7 +113,7 @@ namespace connectivity public: DECLARE_SERVICE_INFO(); - OResultSet(OConnection* pConnection, + OResultSet(Connection* pConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xStatement, isc_stmt_handle& aStatementHandle, XSQLDA* aSqlda); diff --git a/connectivity/source/drivers/firebird/ResultSetMetaData.hxx b/connectivity/source/drivers/firebird/ResultSetMetaData.hxx index 23a737787f06..694cbc131e92 100644 --- a/connectivity/source/drivers/firebird/ResultSetMetaData.hxx +++ b/connectivity/source/drivers/firebird/ResultSetMetaData.hxx @@ -38,7 +38,7 @@ namespace connectivity class OResultSetMetaData : public OResultSetMetaData_BASE { protected: - OConnection* m_pConnection; + Connection* m_pConnection; XSQLDA* m_pSqlda; virtual ~OResultSetMetaData(); @@ -46,7 +46,7 @@ namespace connectivity void verifyValidColumn(sal_Int32 column) throw(::com::sun::star::sdbc::SQLException); public: // a constructor, which is required for returning objects: - OResultSetMetaData(OConnection* pConnection, + OResultSetMetaData(Connection* pConnection, XSQLDA* pSqlda) : m_pConnection(pConnection) , m_pSqlda(pSqlda) diff --git a/connectivity/source/drivers/firebird/Statement.hxx b/connectivity/source/drivers/firebird/Statement.hxx index 18188020c17b..7ac6ea112fce 100644 --- a/connectivity/source/drivers/firebird/Statement.hxx +++ b/connectivity/source/drivers/firebird/Statement.hxx @@ -44,7 +44,7 @@ namespace connectivity public: // a constructor, which is required for returning objects: - OStatement( OConnection* _pConnection) + OStatement( Connection* _pConnection) : OStatementCommonBase( _pConnection), m_pSqlda(0) {} diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index 77e00522a1cb..f2b669ff20a1 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -44,7 +44,7 @@ using namespace ::osl; using namespace ::rtl; using namespace ::std; -OStatementCommonBase::OStatementCommonBase(OConnection* _pConnection) +OStatementCommonBase::OStatementCommonBase(Connection* _pConnection) : OStatementCommonBase_Base(_pConnection->getMutex()), OPropertySetHelper(OStatementCommonBase_Base::rBHelper), m_pConnection(_pConnection), diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index 46377fcf5c71..c1af319569c2 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -58,7 +58,7 @@ namespace connectivity ::std::list< ::rtl::OUString> m_aBatchList; - OConnection* m_pConnection; + Connection* m_pConnection; ISC_STATUS_ARRAY m_statusVector; isc_stmt_handle m_aStatementHandle; @@ -102,7 +102,7 @@ namespace connectivity public: ::cppu::OBroadcastHelper& rBHelper; - OStatementCommonBase(OConnection* _pConnection); + OStatementCommonBase(Connection* _pConnection); using OStatementCommonBase_Base::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >; // OComponentHelper @@ -135,7 +135,7 @@ namespace connectivity virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // other methods - OConnection* getOwnConnection() const { return m_pConnection;} + Connection* getOwnConnection() const { return m_pConnection;} }; } -- cgit