From 60f355127fb93d574e30e590158fe867148762ea Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 27 Apr 2011 17:21:25 -0400 Subject: Centrally manage cached grid data for data pilot tables. This prevents cached data from getting re-generated everytime ScDPObject gets copied, which happens quite often. Without this, the performance of datapilot would really really suffer. --- sc/source/core/data/dpsdbtab.cxx | 116 +++++++-------------------------------- 1 file changed, 20 insertions(+), 96 deletions(-) (limited to 'sc/source/core/data/dpsdbtab.cxx') diff --git a/sc/source/core/data/dpsdbtab.cxx b/sc/source/core/data/dpsdbtab.cxx index 7eeb4b93e284..72c0f06911b1 100644 --- a/sc/source/core/data/dpsdbtab.cxx +++ b/sc/source/core/data/dpsdbtab.cxx @@ -33,23 +33,6 @@ // INCLUDE -------------------------------------------------------------- -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "dpsdbtab.hxx" #include "collect.hxx" #include "global.hxx" @@ -59,100 +42,41 @@ #include "document.hxx" #include "dpobject.hxx" +#include +#include + using namespace com::sun::star; using ::std::vector; using ::com::sun::star::uno::Sequence; -using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Any; -using ::com::sun::star::uno::UNO_QUERY; -#define SC_SERVICE_ROWSET "com.sun.star.sdb.RowSet" -#define SC_SERVICE_INTHANDLER "com.sun.star.task.InteractionHandler" - -//! move to a header file? -#define SC_DBPROP_DATASOURCENAME "DataSourceName" -#define SC_DBPROP_COMMAND "Command" -#define SC_DBPROP_COMMANDTYPE "CommandType" - -ScDPCache* ScImportSourceDesc::CreateCache() const +sal_Int32 ScImportSourceDesc::GetCommandType() const { - if (!mpDoc) - return NULL; - sal_Int32 nSdbType = -1; switch ( nType ) { - case sheet::DataImportMode_SQL: nSdbType = sdb::CommandType::COMMAND; break; - case sheet::DataImportMode_TABLE: nSdbType = sdb::CommandType::TABLE; break; - case sheet::DataImportMode_QUERY: nSdbType = sdb::CommandType::QUERY; break; - default: - return NULL; + case sheet::DataImportMode_SQL: nSdbType = sdb::CommandType::COMMAND; break; + case sheet::DataImportMode_TABLE: nSdbType = sdb::CommandType::TABLE; break; + case sheet::DataImportMode_QUERY: nSdbType = sdb::CommandType::QUERY; break; + default: + ; } + return nSdbType; +} - ScDPCache* pCache = new ScDPCache(mpDoc); - - uno::Reference xRowSet ; - try - { - xRowSet = uno::Reference( - comphelper::getProcessServiceFactory()->createInstance( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_SERVICE_ROWSET )) ), - uno::UNO_QUERY); - uno::Reference xRowProp( xRowSet, uno::UNO_QUERY ); - DBG_ASSERT( xRowProp.is(), "can't get RowSet" ); - if ( xRowProp.is() ) - { - // - // set source parameters - // - uno::Any aAny; - aAny <<= rtl::OUString( aDBName ); - xRowProp->setPropertyValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_DBPROP_DATASOURCENAME)), aAny ); - - aAny <<= rtl::OUString( aObject ); - xRowProp->setPropertyValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_DBPROP_COMMAND)), aAny ); - - aAny <<= nSdbType; - xRowProp->setPropertyValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_DBPROP_COMMANDTYPE)), aAny ); - - uno::Reference xExecute( xRowSet, uno::UNO_QUERY ); - if ( xExecute.is() ) - { - uno::Reference xHandler( - comphelper::getProcessServiceFactory()->createInstance( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_SERVICE_INTHANDLER )) ), - uno::UNO_QUERY); - xExecute->executeWithCompletion( xHandler ); - } - else - xRowSet->execute(); - SvNumberFormatter aFormat(mpDoc->GetServiceManager(), ScGlobal::eLnge); - pCache->InitFromDataBase( xRowSet, *aFormat.GetNullDate() ); - } - } - catch ( sdbc::SQLException& rError ) - { - //! store error message - delete pCache; - pCache = NULL; - InfoBox aInfoBox( 0, String(rError.Message) ); - aInfoBox.Execute(); - } - catch ( uno::Exception& ) - { - delete pCache; - pCache = NULL; - OSL_FAIL("Unexpected exception in database"); - } +const ScDPCache* ScImportSourceDesc::CreateCache() const +{ + if (!mpDoc) + return NULL; + sal_Int32 nSdbType = GetCommandType(); + if (nSdbType < 0) + return NULL; - ::comphelper::disposeComponent( xRowSet ); - return pCache; + ScDPCollection::DBCaches& rCaches = mpDoc->GetDPCollection()->GetDBCaches(); + return rCaches.getCache(nSdbType, aDBName, aObject); } ScDatabaseDPData::ScDatabaseDPData(ScDocument* pDoc, const ScImportSourceDesc& rImport) : -- cgit v1.2.3