Tag: cws_src680_dba30a User: oj Date: 2008-02-14 09:51:49+0000 Modified: dba/connectivity/source/drivers/calc/CCatalog.cxx dba/connectivity/source/drivers/calc/CConnection.cxx dba/connectivity/source/drivers/calc/CDatabaseMetaData.cxx dba/connectivity/source/drivers/calc/CTable.cxx dba/connectivity/source/drivers/calc/CTables.cxx dba/connectivity/source/inc/calc/CConnection.hxx dba/connectivity/source/inc/calc/CTable.hxx
Log: #i9899# refcount of doc inside the connection, will be released when the last table has gone File Changes: Directory: /dba/connectivity/source/drivers/calc/ ================================================= File [changed]: CCatalog.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/calc/CCatalog.cxx?r1=1.5&r2=1.5.194.1 Delta lines: +8 -3 ------------------- --- CCatalog.cxx 2006-09-17 02:18:09+0000 1.5 +++ CCatalog.cxx 2008-02-14 09:51:46+0000 1.5.194.1 @@ -4,9 +4,9 @@ * * $RCSfile: CCatalog.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.5.194.1 $ * - * last change: $Author: obo $ $Date: 2006/09/17 02:18:09 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -71,6 +71,7 @@ { TStringVector aVector; Sequence< ::rtl::OUString > aTypes; + OCalcConnection::ODocHolder aDocHodler(((OCalcConnection*)m_pConnection)); Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), ::rtl::OUString::createFromAscii("%"),::rtl::OUString::createFromAscii("%"),aTypes); @@ -84,6 +85,10 @@ m_pTables->reFill(aVector); else m_pTables = new OCalcTables(m_xMetaData,*this,m_aMutex,aVector); + + // this avoids that the document will be loaded a 2nd time when one table will be accessed. + if ( m_pTables && m_pTables->hasElements() ) + m_pTables->getByIndex(0); } // ----------------------------------------------------------------------------- File [changed]: CConnection.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/calc/CConnection.cxx?r1=1.15&r2=1.15.114.1 Delta lines: +45 -29 --------------------- --- CConnection.cxx 2007-05-10 09:38:01+0000 1.15 +++ CConnection.cxx 2008-02-14 09:51:46+0000 1.15.114.1 @@ -4,9 +4,9 @@ * * $RCSfile: CConnection.cxx,v $ * - * $Revision: 1.15 $ + * $Revision: 1.15.114.1 $ * - * last change: $Author: kz $ $Date: 2007/05/10 09:38:01 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -99,7 +99,7 @@ // -------------------------------------------------------------------------------- -OCalcConnection::OCalcConnection(ODriver* _pDriver) : OConnection(_pDriver) +OCalcConnection::OCalcConnection(ODriver* _pDriver) : OConnection(_pDriver),m_nDocCount(0) { // m_aFilenameExtension is not used } @@ -117,30 +117,22 @@ nLen = url.indexOf(':',nLen+1); ::rtl::OUString aDSN(url.copy(nLen+1)); - String aFileName = aDSN; + m_aFileName = aDSN; INetURLObject aURL; aURL.SetSmartProtocol(INET_PROT_FILE); { SvtPathOptions aPathOptions; - aFileName = aPathOptions.SubstituteVariable(aFileName); + m_aFileName = aPathOptions.SubstituteVariable(m_aFileName); } - aURL.SetSmartURL(aFileName); + aURL.SetSmartURL(m_aFileName); if ( aURL.GetProtocol() == INET_PROT_NOT_VALID ) { // don't pass invalid URL to loadComponentFromURL throw SQLException(); } - aFileName = aURL.GetMainURL(INetURLObject::NO_DECODE); + m_aFileName = aURL.GetMainURL(INetURLObject::NO_DECODE); - Reference< XComponentLoader > xDesktop( getDriver()->getFactory()->createInstance( - ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY ); - if (!xDesktop.is()) - { - OSL_ASSERT("no desktop"); - throw SQLException(); - } - - ::rtl::OUString sPassword; + m_sPassword = ::rtl::OUString(); const char* pPwd = "password"; const PropertyValue *pIter = info.getConstArray(); @@ -149,11 +141,19 @@ { if(!pIter->Name.compareToAscii(pPwd)) { - pIter->Value >>= sPassword; + pIter->Value >>= m_sPassword; break; } } - +} +// ----------------------------------------------------------------------------- +Reference< XSpreadsheetDocument> OCalcConnection::acquireDoc() +{ + if ( m_xDoc.is() ) + { + osl_incrementInterlockedCount(&m_nDocCount); + return m_xDoc; + } // open read-only as long as updating isn't implemented Sequence<PropertyValue> aArgs(2); aArgs[0].Name = ::rtl::OUString::createFromAscii("Hidden"); @@ -161,26 +161,34 @@ aArgs[1].Name = ::rtl::OUString::createFromAscii("ReadOnly"); aArgs[1].Value <<= (sal_Bool) sal_True; - if ( sPassword.getLength() ) + if ( m_sPassword.getLength() ) { - sal_Int32 nPos = aArgs.getLength(); + const sal_Int32 nPos = aArgs.getLength(); aArgs.realloc(nPos+1); aArgs[nPos].Name = ::rtl::OUString::createFromAscii("Password"); - aArgs[nPos].Value <<= sPassword; + aArgs[nPos].Value <<= m_sPassword; } + Reference< XComponentLoader > xDesktop( getDriver()->getFactory()->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY ); + if (!xDesktop.is()) + { + OSL_ASSERT("no desktop"); + throw SQLException(); + } Reference< XComponent > xComponent; Any aLoaderException; try { xComponent = xDesktop->loadComponentFromURL( - aFileName, ::rtl::OUString::createFromAscii("_blank"), 0, aArgs ); + m_aFileName, ::rtl::OUString::createFromAscii("_blank"), 0, aArgs ); } catch( const Exception& ) { aLoaderException = ::cppu::getCaughtException(); } - m_xDoc = Reference<XSpreadsheetDocument>( xComponent, UNO_QUERY ); + + m_xDoc.set(xComponent, UNO_QUERY ); // if the URL is not a spreadsheet document, throw the exception here // instead of at the first access to it @@ -203,14 +211,22 @@ aErrorDetails <<= aDetailException; } - ::rtl::OUString sError( aResourceLoader.getResourceStringWithSubstitution( + const ::rtl::OUString sError( aResourceLoader.getResourceStringWithSubstitution( STR_COULD_NOT_LOAD_FILE, - "$filename$", aFileName + "$filename$", m_aFileName ) ); ::dbtools::throwGenericSQLException( sError, *this, aErrorDetails ); } + osl_incrementInterlockedCount(&m_nDocCount); + return m_xDoc; } - +// ----------------------------------------------------------------------------- +void OCalcConnection::releaseDoc() +{ + if ( osl_decrementInterlockedCount(&m_nDocCount) == 0 ) + ::comphelper::disposeComponent( m_xDoc ); +} +// ----------------------------------------------------------------------------- void OCalcConnection::disposing() { ::osl::MutexGuard aGuard(m_aMutex); File [changed]: CDatabaseMetaData.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/calc/CDatabaseMetaData.cxx?r1=1.18&r2=1.18.6.1 Delta lines: +5 -4 ------------------- --- CDatabaseMetaData.cxx 2008-01-30 07:49:59+0000 1.18 +++ CDatabaseMetaData.cxx 2008-02-14 09:51:46+0000 1.18.6.1 @@ -4,9 +4,9 @@ * * $RCSfile: CDatabaseMetaData.cxx,v $ * - * $Revision: 1.18 $ + * $Revision: 1.18.6.1 $ * - * last change: $Author: rt $ $Date: 2008/01/30 07:49:59 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -465,7 +465,8 @@ // get the sheet names from the document - Reference<XSpreadsheetDocument> xDoc = ((OCalcConnection*)m_pConnection)->getDoc(); + OCalcConnection::ODocHolder aDocHodler(((OCalcConnection*)m_pConnection)); + Reference<XSpreadsheetDocument> xDoc = aDocHodler.getDoc(); if ( !xDoc.is() ) throw SQLException(); Reference<XSpreadsheets> xSheets = xDoc->getSheets(); File [changed]: CTable.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/calc/CTable.cxx?r1=1.31&r2=1.31.100.1 Delta lines: +18 -9 -------------------- --- CTable.cxx 2007-06-12 05:27:25+0000 1.31 +++ CTable.cxx 2008-02-14 09:51:46+0000 1.31.100.1 @@ -4,9 +4,9 @@ * * $RCSfile: CTable.cxx,v $ * - * $Revision: 1.31 $ + * $Revision: 1.31.100.1 $ * - * last change: $Author: obo $ $Date: 2007/06/12 05:27:25 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -126,6 +126,7 @@ #ifndef _DBHELPER_DBCONVERSION_HXX_ #include <connectivity/dbconversion.hxx> #endif +#include <comphelper/types.hxx> using namespace connectivity; using namespace connectivity::calc; @@ -582,21 +583,25 @@ _Description, _SchemaName, _CatalogName) + ,m_pConnection(_pConnection) ,m_nStartCol(0) ,m_nStartRow(0) ,m_nDataCols(0) ,m_nDataRows(0) ,m_bHasHeaders(sal_False) { +} +// ----------------------------------------------------------------------------- +void OCalcTable::construct() +{ // get sheet object - - Reference<XSpreadsheetDocument> xDoc = _pConnection->getDoc(); + Reference< XSpreadsheetDocument> xDoc = m_pConnection->acquireDoc(); if (xDoc.is()) { Reference<XSpreadsheets> xSheets = xDoc->getSheets(); - if ( xSheets.is() && xSheets->hasByName( _Name ) ) + if ( xSheets.is() && xSheets->hasByName( m_Name ) ) { - m_xSheet.set(xSheets->getByName( _Name ),UNO_QUERY); + m_xSheet.set(xSheets->getByName( m_Name ),UNO_QUERY); if ( m_xSheet.is() ) { lcl_GetDataArea( m_xSheet, m_nDataCols, m_nDataRows ); @@ -611,9 +616,9 @@ { Reference<XDatabaseRanges> xRanges(xDocProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseRanges")) ),UNO_QUERY); - if ( xRanges.is() && xRanges->hasByName( _Name ) ) + if ( xRanges.is() && xRanges->hasByName( m_Name ) ) { - Reference<XDatabaseRange> xDBRange(xRanges->getByName( _Name ),UNO_QUERY); + Reference<XDatabaseRange> xDBRange(xRanges->getByName( m_Name ),UNO_QUERY); Reference<XCellRangeReferrer> xRefer( xDBRange, UNO_QUERY ); if ( xRefer.is() ) { @@ -696,6 +701,10 @@ OFileTable::disposing(); ::osl::MutexGuard aGuard(m_aMutex); m_aColumns = NULL; + if ( m_pConnection ) + m_pConnection->releaseDoc(); + m_pConnection = NULL; + } // ------------------------------------------------------------------------- Sequence< Type > SAL_CALL OCalcTable::getTypes( ) throw(RuntimeException) File [changed]: CTables.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/calc/CTables.cxx?r1=1.10&r2=1.10.194.1 Delta lines: +7 -4 ------------------- --- CTables.cxx 2006-09-17 02:20:11+0000 1.10 +++ CTables.cxx 2008-02-14 09:51:46+0000 1.10.194.1 @@ -4,9 +4,9 @@ * * $RCSfile: CTables.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.10.194.1 $ * - * last change: $Author: obo $ $Date: 2006/09/17 02:20:11 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -69,8 +69,11 @@ sdbcx::ObjectType OCalcTables::createObject(const ::rtl::OUString& _rName) { - return new OCalcTable(this,(OCalcConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(), + OCalcTable* pTable = new OCalcTable(this,(OCalcConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(), _rName,::rtl::OUString::createFromAscii("TABLE")); + sdbcx::ObjectType xRet = pTable; + pTable->construct(); + return xRet; } // ------------------------------------------------------------------------- Directory: /dba/connectivity/source/inc/calc/ ============================================= File [changed]: CConnection.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/inc/calc/CConnection.hxx?r1=1.2&r2=1.2.352.1 Delta lines: +25 -5 -------------------- --- CConnection.hxx 2005-09-08 06:59:05+0000 1.2 +++ CConnection.hxx 2008-02-14 09:51:47+0000 1.2.352.1 @@ -4,9 +4,9 @@ * * $RCSfile: CConnection.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.352.1 $ * - * last change: $Author: rt $ $Date: 2005/09/08 06:59:05 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:47 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -54,6 +54,9 @@ { // the spreadsheet document: ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > m_xDoc; + ::rtl::OUString m_sPassword; + String m_aFileName; + oslInterlockedCount m_nDocCount; public: OCalcConnection(ODriver* _pDriver); @@ -77,8 +80,25 @@ virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // no interface methods - ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument> getDoc() const - { return m_xDoc; } + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument> acquireDoc(); + void releaseDoc(); + + class ODocHolder + { + OCalcConnection* m_pConnection; + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument> m_xDoc; + public: + ODocHolder(OCalcConnection* _pConnection) : m_pConnection(_pConnection) + { + m_xDoc = m_pConnection->acquireDoc(); + } + ~ODocHolder() + { + m_xDoc = NULL; + m_pConnection->releaseDoc(); + } + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument> getDoc() const { return m_xDoc; } + }; }; } } File [changed]: CTable.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/inc/calc/CTable.hxx?r1=1.9&r2=1.9.352.1 Delta lines: +7 -4 ------------------- --- CTable.hxx 2005-09-08 07:00:38+0000 1.9 +++ CTable.hxx 2008-02-14 09:51:47+0000 1.9.352.1 @@ -4,9 +4,9 @@ * * $RCSfile: CTable.hxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.9.352.1 $ * - * last change: $Author: rt $ $Date: 2005/09/08 07:00:38 $ + * last change: $Author: oj $ $Date: 2008/02/14 09:51:47 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -45,6 +45,7 @@ namespace com { namespace sun { namespace star { namespace sheet { class XSpreadsheet; + class XSpreadsheetDocument; } } } } namespace com { namespace sun { namespace star { namespace util { @@ -70,6 +71,7 @@ ::std::vector<sal_Int32> m_aPrecisions; // same as aboth ::std::vector<sal_Int32> m_aScales; ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet > m_xSheet; + OCalcConnection* m_pConnection; sal_Int32 m_nStartCol; sal_Int32 m_nStartRow; sal_Int32 m_nDataCols; @@ -109,6 +111,7 @@ virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); + void construct(); }; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
