From f82ce508322002e0af815fdbfa1d102b48b2d1c0 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 23 Nov 2009 14:28:55 +0100 Subject: [CWS autorecovery] removed the dead code for loading in a separate thread Part of the code relied in the SfxCancellable, which is going to be removed. Also, this feature wasn't used anymore for a long time now, if we want to have it, again, we should better re-implement it. --- dbaccess/source/ui/browser/brwctrlr.cxx | 324 +++----------------------------- dbaccess/source/ui/browser/unodatbr.cxx | 4 - dbaccess/source/ui/inc/brwctrlr.hxx | 69 ------- 3 files changed, 30 insertions(+), 367 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index ddfb583f65c9..187ac9640286 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -493,7 +493,6 @@ SbaXDataBrowserController::SbaXDataBrowserController(const Reference< ::com::sun ,m_sStateSaveRecord(ModuleRes(RID_STR_SAVE_CURRENT_RECORD)) ,m_sStateUndoRecord(ModuleRes(RID_STR_UNDO_MODIFY_RECORD)) ,m_sModuleIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataSourceBrowser" ) ) ) - ,m_pLoadThread(NULL) ,m_pFormControllerImpl(NULL) ,m_nPendingLoadFinished(0) ,m_nFormActionNestingLevel(0) @@ -1155,45 +1154,6 @@ void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::containe sal_Bool SbaXDataBrowserController::suspend(sal_Bool /*bSuspend*/) throw( RuntimeException ) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::suspend" ); - // have a pending open operation ? - if (PendingLoad()) - { - ::vos::OGuard aGuard(Application::GetSolarMutex()); - if (m_nPendingLoadFinished != 0) - { // clean up directly. Otherwise there may be a pending asynchronous call - // to OnOpenFinishedMainThread, which won't be executed before we leave - // this method. Sounds like a classic infinite loop. - Application::RemoveUserEvent(m_nPendingLoadFinished); - LINK(this, SbaXDataBrowserController, OnOpenFinishedMainThread).Call(NULL); - } - else - { // set m_bClosingKillOpen to ensure that the our termination handler reacts according - // it's context - m_bClosingKillOpen = sal_True; - - // normally we would now just wait for termination of the load thread, but there is a small problem : - // In the current thread the global solar mutex is locked (that's for sure). If the loading of the - // form tries to acquire (blocking) the solar mutex, too, and we loop waiting for the other thread - // we have a classic deadlock. And bet your ass that ANYBODY in the foreign thread tries to lock - // the solar mutex. Almost all the UNO-capsules around normal C++ classes use the solar mutex for - // "thread safety" (which doesn't deserve that name anymore ;), e.g. the XNumberFormatter-implementation - // does. - // So we have to do a fake : we tell the loading thread that we aren't interested in the results anymore - // and the thread deletes itself (and the data source) as soon as it is done. As it holds the last - // references to the form (and thus, indirectly, to the grid) they will be cleared as soon as the thread dies. - // So all is fine. Except the small flaw that the form is still loading in the background while the - // window that should display it is already dead. - // If we could release the solar mutex in this thread and block it 'til the loader is finished we could - // solve it in a less dirty way, but uinfortunatelly we don't know how often this thread acquired the mutex. - // With high effort we could reach this with releasing the mutex until a third thread - which has to be - // created - can acquire it.Then we block, the third thread releases the mutex (and dies) and the loader - // thread would be able to finish. But that sounds difficult and fault-prone, so I think it's not worth it ... - ((LoadFormThread*)m_pLoadThread)->SetTerminationHdl(Link()); - // and of course we tell the thread to stop .... - ((LoadFormThread*)m_pLoadThread)->StopIt(); - } - - } DBG_ASSERT(m_nPendingLoadFinished == 0, "SbaXDataBrowserController::suspend : there shouldn't be a pending load !"); m_aAsyncGetCellFocus.CancelCall(); @@ -1219,42 +1179,30 @@ void SbaXDataBrowserController::disposing() // the base class SbaXDataBrowserController_Base::OGenericUnoController::disposing(); - if (!PendingLoad()) + // the data source + Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); + if (xFormSet.is()) { - // don't do the removeXxxListener calls if there is a pending load, this may lead to a deadlock : - // as in this thread the SolarMutex is locked (that's for sure) and removeXxxListener locks - // the form's mutex. But in the loading thread both mutexes are acquired in reverse order. - // That's no problem that we don't remove ourself here, as the load thread is responsible for the form - // at the moment. So if the loading is finished, the form will be disposed (by the load thread), and - // we get the "disposing" event where we can do the removeXxxListener calls. - // The alternative for this handling would be that the form has two mutexes : one for handling it's - // listeners and properties and so on, on for it's pure cursor actions - - // the data source - Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - if (xFormSet.is()) - { - xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast(this)); - xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast(this)); - } + xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast(this)); + xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast(this)); + } - Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY); - if (xFormError.is()) - xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this); + Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY); + if (xFormError.is()) + xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this); - if (m_xLoadable.is()) - m_xLoadable->removeLoadListener(this); + if (m_xLoadable.is()) + m_xLoadable->removeLoadListener(this); - Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY); - if (xFormParameter.is()) - xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this); - } + Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY); + if (xFormParameter.is()) + xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this); removeModelListeners(getControlModel()); @@ -1276,23 +1224,18 @@ void SbaXDataBrowserController::disposing() if(m_aInvalidateClipboard.IsActive()) m_aInvalidateClipboard.Stop(); - // dispose the data source - // if there is a pending load we decided to give the responsibility for the data source to the open thread - // (see ::suspend) - if (!PendingLoad()) + // dispose the row set + try { - try - { - ::comphelper::disposeComponent(m_xRowSet); + ::comphelper::disposeComponent(m_xRowSet); - m_xRowSet = NULL; - m_xColumnsSupplier = NULL; - m_xLoadable = NULL; - } - catch(Exception&) - { - OSL_ENSURE(0,"Exception thrown by dispose"); - } + m_xRowSet = NULL; + m_xColumnsSupplier = NULL; + m_xLoadable = NULL; + } + catch(Exception&) + { + OSL_ENSURE(0,"Exception thrown by dispose"); } try { @@ -1507,9 +1450,6 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength(); return aReturn; } - // no chance while loading the form - if (PendingLoad()) - return aReturn; // no chance without valid models if (isValid() && !isValidCursor()) return aReturn; @@ -2510,45 +2450,6 @@ IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformatio return 0L; } -//------------------------------------------------------------------------------ -IMPL_LINK(SbaXDataBrowserController, OnOpenFinishedMainThread, void*, EMPTYARG) -{ - ::vos::OGuard aGuard(Application::GetSolarMutex()); - if (!m_nPendingLoadFinished) - // it's possible that the direct call of this link from within suspend caused this method to be executed - // in another thread while we were waiting for the mutex in this thread - return 0; - m_nPendingLoadFinished = 0; - - if ( static_cast< LoadFormThread* >( m_pLoadThread )->WasCanceled() ) - setLoadingCancelled(); - - delete m_pLoadThread; - m_pLoadThread = NULL; - - LoadFinished(sal_False); - - return 0L; -} - -//------------------------------------------------------------------------------ -IMPL_LINK(SbaXDataBrowserController, OnOpenFinished, void*, EMPTYARG) -{ - ::osl::MutexGuard aCheckGuard(m_aAsyncLoadSafety); - - if (m_bClosingKillOpen) - { - delete m_pLoadThread; - m_pLoadThread = NULL; - } - else - // all cleaning has to run in the main thread, not here (this is called synchronously from the LoadThread) - // so we use an user event - m_nPendingLoadFinished = Application::PostUserEvent(LINK(this, SbaXDataBrowserController, OnOpenFinishedMainThread)); - - return 0L; -} - //------------------------------------------------------------------------------ IMPL_LINK(SbaXDataBrowserController, OnAsyncGetCellFocus, void*, EMPTYARG) { @@ -2905,171 +2806,6 @@ bool LoadFormHelper::WaitUntilReallyLoaded(bool _bOnlyIfLoaded) return true; } -//================================================================== -// LoadFormThread - a thread for asynchronously loading a form -//================================================================== -//------------------------------------------------------------------------------ -void LoadFormThread::run() -{ - // On instantiation of a SfxCancellable the application is notified and 'switches on' the red stop button. - // Unfortunally this is conditioned with the acquirement of the solar mutex, and the application tries - // only once and ignores the notification if it fails. - // To prevent that we get the solar mutex and _block_ 'til we got it. - // As we are in the 'top level execution' of this thread (with a rather small stack and no other mutexes locked) - // we shouldn't experience problems with deadlocks ... - ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex()); - ThreadStopper* pStopper = new ThreadStopper(this, m_sStopperCaption); - aSolarGuard.clear(); - - // we're not canceled yet - ::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety); - m_bCanceled = sal_False; - aResetGuard.clear(); - - LoadFormHelper* pHelper = new LoadFormHelper(m_xRowSet); - pHelper->acquire(); - - // start it - bool bErrorOccured = false; - Reference< XLoadable > xLoadable(m_xRowSet, UNO_QUERY); - try - { - Reference< XRowSet > xMove(m_xRowSet, UNO_QUERY); - DBG_ASSERT(xLoadable.is() && xMove.is(), "LoadFormThread::run : invalid cursor !"); - xLoadable->load(); - // go to the first record if the load was successfull. - Reference< XColumnsSupplier > xColumnsSupplier(m_xRowSet, UNO_QUERY); - Reference< ::com::sun::star::container::XNameAccess > xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > (); - if (xCols.is() && xCols->hasElements()) - xMove->first(); - else - bErrorOccured = true; - } - catch(Exception&) - { - bErrorOccured = true; - } - - // check if we were canceled - ::osl::ClearableMutexGuard aTestGuard(m_aAccessSafety); - bool bReallyCanceled = m_bCanceled ? true : false;; - aTestGuard.clear(); - - bReallyCanceled |= bErrorOccured; - - // the load on the form is "slightly asyncronous" (which isn't covered by it's specification, anyway), so wait - // some time .... - // (though me thinks that the load of the new api is synchronous, so we won't need this LoadFormHelper anymore ...) - if (!bReallyCanceled) - pHelper->WaitUntilReallyLoaded(true); - - pHelper->cancel(); - pHelper->release(); - - // yes, we were, but eventually the cancel request didn't reach the data source in time - if (bReallyCanceled && xLoadable.is() && xLoadable->isLoaded()) - xLoadable->unload(); - - pStopper->OwnerTerminated(); - // this will cause the stopper to delete itself (in the main thread) so we don't have to take care of the - // solar mutex -} - -//------------------------------------------------------------------------------ -void LoadFormThread::onTerminated() -{ - ::osl::ClearableMutexGuard aGuard(m_aAccessSafety); - if (m_aTerminationHandler.IsSet()) - { - // within the call of our termination handler we may be deleted, so do anything which is a member - // access before the call ... - // FS - #69801# - 02.12.99 - Link aHandler(m_aTerminationHandler); - aGuard.clear(); - aHandler.Call(this); - } - else - { - // we are fully responsible for the data source and for ourself, so dispose the former ... - try - { - ::comphelper::disposeComponent(m_xRowSet); - - m_xRowSet = NULL; - } - catch(Exception&) - { - OSL_ENSURE(0,"Exception thrown by dispose"); - } - // ... and delete the latter - aGuard.clear(); // like above - releasing the mutex is a member access ... - delete this; - } -} - -//------------------------------------------------------------------------------ -void LoadFormThread::StopIt() -{ - ::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety); - m_bCanceled = sal_True; - aResetGuard.clear(); - - Reference< XColumnsSupplier > xColumnsSupplier(m_xRowSet, UNO_QUERY); - if (!xColumnsSupplier.is()) - { - DBG_ERROR("LoadFormThread::StopIt : invalid data source !"); - return; - } - Reference< ::com::sun::star::container::XNameAccess > xCols(xColumnsSupplier->getColumns(), UNO_QUERY); - if (!xCols.is() || !xCols->hasElements()) - // the cursor isn't alive, don't need to cancel - return; - - Reference< ::com::sun::star::util::XCancellable > xCancel(m_xRowSet, UNO_QUERY); - if (xCancel.is()) - { - try { xCancel->cancel(); } catch(SQLException&) {} - // with this the cursor returns from it's load call, this terminates our run, this get's our termination handler to - // be called - // (the try-catch is just in case the cancel wasn't neccessary anymore) - } -} - -//------------------------------------------------------------------------------ -LoadFormThread::ThreadStopper::ThreadStopper(LoadFormThread* pOwner, const String& rTitle) - :SfxCancellable(SFX_APP()->GetCancelManager(), rTitle) - ,m_pOwner(pOwner) -{ -} - -//------------------------------------------------------------------------------ -void LoadFormThread::ThreadStopper::Cancel() -{ - if (!m_pOwner) - return; - - ::osl::MutexGuard aGuard(m_pOwner->m_aAccessSafety); - if (IsCancelled()) - // we already did pass this to our owner - return; - - SfxCancellable::Cancel(); - m_pOwner->StopIt(); -} - -//------------------------------------------------------------------------------ -void LoadFormThread::ThreadStopper::OwnerTerminated() -{ - m_pOwner = NULL; - Application::PostUserEvent(LINK(this, LoadFormThread::ThreadStopper, OnDeleteInMainThread), this); -} - -//------------------------------------------------------------------------------ -IMPL_LINK(LoadFormThread::ThreadStopper, OnDeleteInMainThread, LoadFormThread::ThreadStopper*, pThis) -{ - delete pThis; - return 0L; -} // ----------------------------------------------------------------------------- sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition() { diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index aad25f1cd7ab..eecb974ba959 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -1659,10 +1659,6 @@ FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE) return aReturn; - // no chance while loading the form - if (PendingLoad()) - return aReturn; - switch (nId) { case ID_BROWSER_INSERTCOLUMNS: diff --git a/dbaccess/source/ui/inc/brwctrlr.hxx b/dbaccess/source/ui/inc/brwctrlr.hxx index 1e796fbed624..128b20178e8a 100644 --- a/dbaccess/source/ui/inc/brwctrlr.hxx +++ b/dbaccess/source/ui/inc/brwctrlr.hxx @@ -56,7 +56,6 @@ #include #include #include -#include #include #include @@ -122,7 +121,6 @@ namespace dbaui ::rtl::OUString m_sModuleIdentifier; // members for asynchronous load operations - ::vos::OThread* m_pLoadThread; // the thread wherein the form is loaded FormControllerImpl* m_pFormControllerImpl; // implementing the XFormController ULONG m_nPendingLoadFinished; // the event used to tell ourself that the load is finished @@ -319,9 +317,6 @@ namespace dbaui // a PropertySet corresponding to the cursor field a column is bound to // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved - sal_Bool PendingLoad() const { return m_pLoadThread != NULL; } - // is there an asyncronous load operation in progress ? - void enterFormAction(); void leaveFormAction(); @@ -362,74 +357,10 @@ namespace dbaui DECL_LINK(OnFoundData, FmFoundRecordInformation*); DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*); - // callbacks for the completed loading process - DECL_LINK(OnOpenFinished, void*); - DECL_LINK(OnOpenFinishedMainThread, void*); - // OnOpenFinsihed is called in a foreign thread (the one which does the loading) so it simply posts the - // OnOpenFinishedMainThread-link (which will be called in the main thread, then) as user event. - // (the alternative would be to lock the SolarMutex in OnOpenFinished to avoid problems with the needed updates, - // but playing with this mutex seems very hazardous to me ....) DECL_LINK(OnAsyncGetCellFocus, void*); DECL_LINK( OnAsyncDisplayError, void* ); }; - - //================================================================== - // LoadFormThread - a thread for asynchronously loading a form - //================================================================== - class LoadFormThread : public ::vos::OThread - { - ::osl::Mutex m_aAccessSafety; // for securing the multi-thread access - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // the data source to be loaded - - Link m_aTerminationHandler; // the handler to be called upon termination - sal_Bool m_bCanceled; // StopIt has been called ? - String m_sStopperCaption; // the caption for the ThreadStopper - - // a ThreadStopper will be instantiated so that the open can be canceled via the UI - class ThreadStopper : protected SfxCancellable - { - LoadFormThread* m_pOwner; - - public: - ThreadStopper(LoadFormThread* pOwner, const String& rTitle); - virtual ~ThreadStopper() { } - - virtual void Cancel(); - - virtual void OwnerTerminated(); - // Normally the Owner (a LoadFormThread) would delete the stopper when terminated. - // Unfortunally the application doesn't remove the 'red light' when a SfxCancellable is deleted - // if it (the app) can't acquire the solar mutex. The deletion is IGNORED then. So we have to make - // sure that a) the stopper is deleted from inside the main thread (where the solar mutex is locked) - // and b) that in the time between the termination of the thread and the deletion of the stopper - // the latter doesn't access the former. - // The OwnerTerminated cares for both aspects. - // SO DON'T DELETE THE STOPPER EXPLICITLY ! - - protected: - // HACK HACK HACK HACK HACK : this should be private, but MSVC doesn't accept the LINK-macro then .... - DECL_LINK(OnDeleteInMainThread, ThreadStopper*); - }; - friend class LoadFormThread::ThreadStopper; - - public: - LoadFormThread(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > & _xRowSet, const String& _rStopperCaption) : m_xRowSet(_xRowSet), m_sStopperCaption(_rStopperCaption) { } - - virtual void SAL_CALL run(); - virtual void SAL_CALL onTerminated(); - - void SetTerminationHdl(const Link& aTermHdl) { m_aTerminationHandler = aTermHdl; } - // the handler will be called synchronously (the parameter is a pointer to the thread) - // if no termination handler is set, the thread disposes the data source and deletes - // itself upon termination - - // cancels the process. to be called from another thread (of course ;) - void StopIt(); - - // ask if the load canceled - sal_Bool WasCanceled() const { return m_bCanceled; } - }; } #endif // _SBA_BWRCTRLR_HXX -- cgit From 271be244a0f85264d3bd5c5f2820aa7c9b299881 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Tue, 8 Dec 2009 08:16:52 +0100 Subject: dba33e: if database is read only start with READ_ONLY concurrency --- dbaccess/source/core/api/RowSet.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 461929f68141..8675ebaf0a07 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -1679,7 +1679,11 @@ void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxSta { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::READ_ONLY }, { ResultSetType::FORWARD_ONLY, ResultSetConcurrency::READ_ONLY } }; - for ( sal_Int32 i=0; i<5; ++i ) + sal_Int32 i=0; + if ( m_xActiveConnection->getMetaData()->isReadOnly() ) + i = 2; // if the database is read-only we only should use read-only concurrency + + for ( ; i<5; ++i ) { nResultSetType = nCharacteristics[i][0]; nResultSetConcurrency = nCharacteristics[i][1]; -- cgit From 1f3b28fe29a7e59d23f9f0cee9eff8e16370df4b Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 11 Dec 2009 11:28:14 +0100 Subject: autorecovery: made JumpMark a argument of the to-be-created view. For this purpose, the loader moves this argument from the loader args to the args which are later passed to XModel2.createViewController, and the Controller implementation retrieves it from there. (In this course, XController2.getCreationArguments has been introduced, and implemented in the two known XController2 implementations in the code base.) --- dbaccess/inc/genericcontroller.hxx | 3 ++- dbaccess/source/ui/browser/genericcontroller.cxx | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/inc/genericcontroller.hxx b/dbaccess/inc/genericcontroller.hxx index b4570bc1215b..933a3314d589 100644 --- a/dbaccess/inc/genericcontroller.hxx +++ b/dbaccess/inc/genericcontroller.hxx @@ -471,8 +471,9 @@ namespace dbaui // ::com::sun::star::frame::XController2 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getComponentWindow() throw (::com::sun::star::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getViewControllerName() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getCreationArguments() throw (::com::sun::star::uno::RuntimeException); - // ::com::sun::star::frame::XController2 + // ::com::sun::star::frame::XController virtual void SAL_CALL attachFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & xFrame) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ) = 0; diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx index a24c2d4e30dc..41ea2d9a1f7f 100644 --- a/dbaccess/source/ui/browser/genericcontroller.cxx +++ b/dbaccess/source/ui/browser/genericcontroller.cxx @@ -477,6 +477,14 @@ Reference< XWindow > SAL_CALL OGenericUnoController::getComponentWindow() throw return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ); } +// ----------------------------------------------------------------------- +Sequence< PropertyValue > SAL_CALL OGenericUnoController::getCreationArguments() throw (RuntimeException) +{ + // currently we do not support any creation args, so anything passed to XModel2::createViewController would be + // lost, so we can equally return an empty sequence here + return Sequence< PropertyValue >(); +} + // ----------------------------------------------------------------------- void OGenericUnoController::attachFrame( const Reference< XFrame >& _rxFrame ) throw( RuntimeException ) { -- cgit From ae3daf0025db4af8550970d2e879f1efb2b22062 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 16 Dec 2009 12:22:02 +0100 Subject: dba33e: #i107715# check if parser is valid --- dbaccess/source/ui/browser/brwctrlr.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index f82839664973..7fd7ab89a21a 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -1709,7 +1709,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const { // a native statement can't be filtered or sorted const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING))) + if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() ) break; Reference< XPropertySet > xCurrentField = getBoundField(); @@ -1728,7 +1728,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const break; case ID_BROWSER_FILTERCRIT: - if ( m_bCannotSelectUnfiltered ) + if ( m_bCannotSelectUnfiltered && m_xParser.is() ) { aReturn.bEnabled = sal_True; break; @@ -1737,7 +1737,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const case ID_BROWSER_ORDERCRIT: { const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING))) + if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() ) break; aReturn.bEnabled = getRowSet().is() -- cgit From 6fd6b96682de8c9f2b8b10a896e71085a9914ecf Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 16 Dec 2009 12:46:33 +0100 Subject: dba33e: #i107717# impl first entry points for db extensions --- dbaccess/source/core/api/RowSet.cxx | 6 + .../source/core/api/SingleSelectQueryComposer.cxx | 22 +-- dbaccess/source/core/api/View.cxx | 151 ++++++++++++++++++ dbaccess/source/core/api/column.cxx | 19 ++- dbaccess/source/core/api/makefile.mk | 1 + dbaccess/source/core/api/resultcolumn.cxx | 22 ++- dbaccess/source/core/api/table.cxx | 177 ++++++--------------- dbaccess/source/core/api/viewcontainer.cxx | 82 +++------- dbaccess/source/core/dataaccess/ModelImpl.cxx | 11 ++ dbaccess/source/core/dataaccess/connection.cxx | 27 +++- dbaccess/source/core/dataaccess/connection.hxx | 50 +----- .../source/core/dataaccess/databasedocument.cxx | 37 +++-- dbaccess/source/core/dataaccess/datasource.cxx | 22 ++- dbaccess/source/core/inc/View.hxx | 92 +++++++++++ dbaccess/source/core/inc/sdbcoretools.hxx | 20 --- dbaccess/source/core/inc/table.hxx | 34 ---- dbaccess/source/core/misc/sdbcoretools.cxx | 33 ---- dbaccess/source/filter/xml/xmlDatabase.cxx | 66 ++++---- dbaccess/source/filter/xml/xmlExport.cxx | 112 +++++-------- dbaccess/source/ui/browser/dsEntriesNoExp.cxx | 6 + dbaccess/source/ui/browser/unodatbr.cxx | 142 +++++++++++++---- dbaccess/source/ui/inc/unodatbr.hxx | 5 +- 22 files changed, 631 insertions(+), 506 deletions(-) create mode 100644 dbaccess/source/core/api/View.cxx create mode 100644 dbaccess/source/core/inc/View.hxx (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 8675ebaf0a07..3876fe47c365 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -2422,6 +2422,12 @@ sal_Bool ORowSet::impl_buildActiveCommand_throw() { xQuery->getPropertyValue(PROPERTY_COMMAND) >>= sCommand; xQuery->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bDoEscapeProcessing; + if ( bDoEscapeProcessing != m_bUseEscapeProcessing ) + { + sal_Bool bOldValue = m_bUseEscapeProcessing; + m_bUseEscapeProcessing = bDoEscapeProcessing; + fireProperty(PROPERTY_ID_ESCAPE_PROCESSING,bOldValue,bDoEscapeProcessing); + } ::rtl::OUString aCatalog,aSchema,aTable; xQuery->getPropertyValue(PROPERTY_UPDATE_CATALOGNAME) >>= aCatalog; diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index 04c5e9d37faa..c5d34665f6c3 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -37,6 +37,7 @@ #include "dbastrings.hrc" #include "HelperCollections.hxx" #include "SingleSelectQueryComposer.hxx" +#include "sdbcoretools.hxx" /** === begin UNO includes === **/ #include @@ -228,24 +229,11 @@ OSingleSelectQueryComposer::OSingleSelectQueryComposer(const Reference< XNameAcc OSL_ENSURE(m_sDecimalSep.getLength() == 1,"OSingleSelectQueryComposer::OSingleSelectQueryComposer decimal separator is not 1 length"); try { - Reference< XChild> xChild(_xConnection, UNO_QUERY); - if(xChild.is()) + Any aValue; + Reference xDs = dbaccess::getDataSource(_xConnection); + if ( dbtools::getDataSourceSetting(xDs,static_cast (PROPERTY_BOOLEANCOMPARISONMODE),aValue) ) { - Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY); - if ( xProp.is() ) - { - Sequence< PropertyValue > aInfo; - xProp->getPropertyValue(PROPERTY_INFO) >>= aInfo; - const PropertyValue* pBegin = aInfo.getConstArray(); - const PropertyValue* pEnd = pBegin + aInfo.getLength(); - for (; pBegin != pEnd; ++pBegin) - { - if ( pBegin->Name == static_cast (PROPERTY_BOOLEANCOMPARISONMODE) ) - { - OSL_VERIFY( pBegin->Value >>= m_nBoolCompareMode ); - } - } - } + OSL_VERIFY( aValue >>= m_nBoolCompareMode ); } } catch(Exception&) diff --git a/dbaccess/source/core/api/View.cxx b/dbaccess/source/core/api/View.cxx new file mode 100644 index 000000000000..d7e5221446b0 --- /dev/null +++ b/dbaccess/source/core/api/View.cxx @@ -0,0 +1,151 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: View.cxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include "View.hxx" +#include "dbastrings.hrc" + +#include "connectivity/dbexception.hxx" +#include "connectivity/dbtools.hxx" + +/** === begin UNO includes === **/ +#include +#include +#include +/** === end UNO includes === **/ + +#include +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using namespace ::com::sun::star::uno; + using ::com::sun::star::sdbc::XDatabaseMetaData; + using ::com::sun::star::sdbc::SQLException; + using ::com::sun::star::sdbc::XConnection; + using ::com::sun::star::lang::WrappedTargetException; + using ::com::sun::star::lang::XMultiServiceFactory; + using ::com::sun::star::sdbc::XResultSet; + using ::com::sun::star::sdbc::XStatement; + using ::com::sun::star::lang::DisposedException; + using ::com::sun::star::sdbc::XRow; + /** === end UNO using === **/ + + //==================================================================== + //= View + //==================================================================== + //-------------------------------------------------------------------- + View::View( const Reference< XConnection >& _rxConnection, sal_Bool _bCaseSensitive, + const ::rtl::OUString& _rCatalogName,const ::rtl::OUString& _rSchemaName, const ::rtl::OUString& _rName ) + :View_Base( _bCaseSensitive, _rName, _rxConnection->getMetaData(), 0, ::rtl::OUString(), _rSchemaName, _rCatalogName ) + { + m_nCommandHandle = getProperty(PROPERTY_COMMAND).Handle; + try + { + Reference xFac(_rxConnection,UNO_QUERY_THROW); + static const ::rtl::OUString s_sViewSupport(RTL_CONSTASCII_USTRINGPARAM("ViewSupportServiceName")); + m_xViewSupport.set(xFac->createInstance(s_sViewSupport),UNO_QUERY); + } + catch(const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //-------------------------------------------------------------------- + View::~View() + { + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_REFCOUNT( View, View_Base ) + IMPLEMENT_GET_IMPLEMENTATION_ID( View ) + // ------------------------------------------------------------------------- + Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException) + { + if(_rType == getCppuType( (Reference*)0) && !m_xViewSupport.is() ) + return Any(); + Any aReturn = View_Base::queryInterface( _rType ); + if ( !aReturn.hasValue() ) + aReturn = View_IBASE::queryInterface( _rType ); + return aReturn; + } + // ------------------------------------------------------------------------- + Sequence< Type > SAL_CALL View::getTypes( ) throw(RuntimeException) + { + Type aAlterType = getCppuType( (Reference*)0); + + Sequence< Type > aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) ); + ::std::vector aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + + const Type* pIter = aTypes.getConstArray(); + const Type* pEnd = pIter + aTypes.getLength(); + for(;pIter != pEnd ;++pIter) + { + if( (*pIter != aAlterType || m_xViewSupport.is()) ) + aOwnTypes.push_back(*pIter); + } + + Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; + return Sequence< Type >(pTypes, aOwnTypes.size()); + } + + //-------------------------------------------------------------------- + void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException) + { + OSL_ENSURE(m_xViewSupport.is(),"Illegal call to AlterView!"); + m_xViewSupport->alterCommand(this,_rNewCommand); + } + + //-------------------------------------------------------------------- + void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const + { + if ( _nHandle == m_nCommandHandle && m_xViewSupport.is() ) + { + // retrieve the very current command, don't rely on the base classes cached value + // (which we initialized empty, anyway) + _rValue <<= m_xViewSupport->getCommand(const_cast(this)); + return; + } + + View_Base::getFastPropertyValue( _rValue, _nHandle ); + } + // ----------------------------------------------------------------------------- +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/api/column.cxx b/dbaccess/source/core/api/column.cxx index f789394d23f9..89e17d0e3ce4 100644 --- a/dbaccess/source/core/api/column.cxx +++ b/dbaccess/source/core/api/column.cxx @@ -417,7 +417,16 @@ sdbcx::ObjectType OColumns::appendObject( const ::rtl::OUString& _rForName, cons else if ( m_pTable && !m_pTable->isNew() ) { if ( m_bAddColumn ) - xReturn = OColumns_BASE::appendObject( _rForName, descriptor ); + { + Reference< ::com::sun::star::sdb::tools::XTableAlteration> xAlterService = m_pTable->getAlterService(); + if ( xAlterService.is() ) + { + xAlterService->addColumn(m_pTable,descriptor); + xReturn = createObject( _rForName ); + } + else + xReturn = OColumns_BASE::appendObject( _rForName, descriptor ); + } else ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_ADD ), static_cast(static_cast(this)) ); } @@ -443,7 +452,13 @@ void OColumns::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName) else if ( m_pTable && !m_pTable->isNew() ) { if ( m_bDropColumn ) - OColumns_BASE::dropObject(_nPos,_sElementName); + { + Reference< ::com::sun::star::sdb::tools::XTableAlteration> xAlterService = m_pTable->getAlterService(); + if ( xAlterService.is() ) + xAlterService->dropColumn(m_pTable,_sElementName); + else + OColumns_BASE::dropObject(_nPos,_sElementName); + } else ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_DROP ), static_cast(static_cast(this)) ); } diff --git a/dbaccess/source/core/api/makefile.mk b/dbaccess/source/core/api/makefile.mk index f983db38b640..df80f0423e14 100644 --- a/dbaccess/source/core/api/makefile.mk +++ b/dbaccess/source/core/api/makefile.mk @@ -74,6 +74,7 @@ SLOFILES= \ $(SLO)$/SingleSelectQueryComposer.obj \ $(SLO)$/HelperCollections.obj \ $(SLO)$/datasettings.obj \ + $(SLO)$/View.obj \ $(SLO)$/columnsettings.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/api/resultcolumn.cxx b/dbaccess/source/core/api/resultcolumn.cxx index 33cc93b02994..1f9d1938caf8 100644 --- a/dbaccess/source/core/api/resultcolumn.cxx +++ b/dbaccess/source/core/api/resultcolumn.cxx @@ -110,20 +110,26 @@ void OResultColumn::impl_determineIsRowVersion_nothrow() getPropertyValue( PROPERTY_TABLENAME ) >>= sTable; getPropertyValue( PROPERTY_NAME ) >>= sColumnName; - Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns( - makeAny( sCatalog ), sSchema, sTable ); - if ( xVersionColumns.is() ) // allowed to be NULL + try { - Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW ); - while ( xVersionColumns->next() ) + Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns( + makeAny( sCatalog ), sSchema, sTable ); + if ( xVersionColumns.is() ) // allowed to be NULL { - if ( xResultRow->getString( 2 ) == sColumnName ) + Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW ); + while ( xVersionColumns->next() ) { - m_aIsRowVersion <<= (sal_Bool)(sal_True); - break; + if ( xResultRow->getString( 2 ) == sColumnName ) + { + m_aIsRowVersion <<= (sal_Bool)(sal_True); + break; + } } } } + catch(const SQLException&) + { + } } catch( const Exception& ) { diff --git a/dbaccess/source/core/api/table.cxx b/dbaccess/source/core/api/table.cxx index 301038903b97..d88537fb72f8 100644 --- a/dbaccess/source/core/api/table.cxx +++ b/dbaccess/source/core/api/table.cxx @@ -31,77 +31,33 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef _DBA_CORE_TABLE_HXX_ #include "table.hxx" -#endif -#ifndef _DBACORE_DEFINITIONCOLUMN_HXX_ #include -#endif -#ifndef DBACCESS_SHARED_DBASTRINGS_HRC #include "dbastrings.hrc" -#endif -#ifndef _DBA_CORE_RESOURCE_HXX_ #include "core_resource.hxx" -#endif -#ifndef _DBA_CORE_RESOURCE_HRC_ #include "core_resource.hrc" -#endif -#ifndef _TOOLS_DEBUG_HXX -#include -#endif +#include "CIndexes.hxx" -#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include #include -#endif -#ifndef _COMPHELPER_ENUMHELPER_HXX_ #include -#endif -#ifndef _COMPHELPER_CONTAINER_HXX_ #include -#endif -#ifndef _COMPHELPER_SEQUENCE_HXX_ #include -#endif -#ifndef _COMPHELPER_TYPES_HXX_ #include -#endif -#ifndef _COM_SUN_STAR_UTIL_XREFRESHLISTENER_HPP_ +//#include #include -#endif -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_ #include -#endif +#include +#include + #include -#ifndef DBACCESS_INDEXES_HXX_ -#include "CIndexes.hxx" -#endif -#ifndef _CONNECTIVITY_DBTOOLS_HXX_ #include -#endif -#ifndef _DBHELPER_DBEXCEPTION_HXX_ #include -#endif -#ifndef _COMPHELPER_EXTRACT_HXX_ -#include -#endif -#ifndef DBACORE_SDBCORETOOLS_HXX + #include "sdbcoretools.hxx" -#endif -#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_ -#include -#endif -#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ -#include -#endif -#ifndef DBA_CONTAINERMEDIATOR_HXX #include "ContainerMediator.hxx" -#endif #include using namespace dbaccess; @@ -152,6 +108,7 @@ ODBTable::ODBTable(connectivity::sdbcx::OCollection* _pTables :OTable_Base(_pTables,_rxConn, _rxConn->getMetaData().is() && _rxConn->getMetaData()->supportsMixedCaseQuotedIdentifiers()) ,m_nPrivileges(-1) { + DBG_CTOR(ODBTable, NULL); RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::ODBTable" ); } // ------------------------------------------------------------------------- @@ -311,18 +268,18 @@ void ODBTable::construct() describeProperties(aProps); if(!_nId) { - Property* pBegin = aProps.getArray(); - Property* pEnd = pBegin + aProps.getLength(); - for(;pBegin != pEnd;++pBegin) + Property* pIter = aProps.getArray(); + Property* pEnd = pIter + aProps.getLength(); + for(;pIter != pEnd;++pIter) { - if (0 == pBegin->Name.compareToAscii(PROPERTY_CATALOGNAME)) - pBegin->Attributes = PropertyAttribute::READONLY; - else if (0 == pBegin->Name.compareToAscii(PROPERTY_SCHEMANAME)) - pBegin->Attributes = PropertyAttribute::READONLY; - else if (0 == pBegin->Name.compareToAscii(PROPERTY_DESCRIPTION)) - pBegin->Attributes = PropertyAttribute::READONLY; - else if (0 == pBegin->Name.compareToAscii(PROPERTY_NAME)) - pBegin->Attributes = PropertyAttribute::READONLY; + if (0 == pIter->Name.compareToAscii(PROPERTY_CATALOGNAME)) + pIter->Attributes = PropertyAttribute::READONLY; + else if (0 == pIter->Name.compareToAscii(PROPERTY_SCHEMANAME)) + pIter->Attributes = PropertyAttribute::READONLY; + else if (0 == pIter->Name.compareToAscii(PROPERTY_DESCRIPTION)) + pIter->Attributes = PropertyAttribute::READONLY; + else if (0 == pIter->Name.compareToAscii(PROPERTY_NAME)) + pIter->Attributes = PropertyAttribute::READONLY; } } @@ -340,14 +297,11 @@ IMPLEMENT_SERVICE_INFO1(ODBTable, "com.sun.star.sdb.dbaccess.ODBTable", SERVICE_ Any SAL_CALL ODBTable::queryInterface( const Type & rType ) throw(RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::getInfoHelper" ); - Any aRet; - if(rType == getCppuType( (Reference*)0)) + if(rType == getCppuType( (Reference*)0) && !getRenameService().is() ) return Any(); - if(rType == getCppuType( (Reference*)0)) + if(rType == getCppuType( (Reference*)0) && !getAlterService().is() ) return Any(); - aRet = OTable_Base::queryInterface( rType); - - return aRet; + return OTable_Base::queryInterface( rType); } // ------------------------------------------------------------------------- Sequence< Type > SAL_CALL ODBTable::getTypes( ) throw(RuntimeException) @@ -360,12 +314,12 @@ Sequence< Type > SAL_CALL ODBTable::getTypes( ) throw(RuntimeException) ::std::vector aOwnTypes; aOwnTypes.reserve(aTypes.getLength()); - const Type* pBegin = aTypes.getConstArray(); - const Type* pEnd = pBegin + aTypes.getLength(); - for(;pBegin != pEnd ;++pBegin) + const Type* pIter = aTypes.getConstArray(); + const Type* pEnd = pIter + aTypes.getLength(); + for(;pIter != pEnd ;++pIter) { - if(*pBegin != aRenameType && *pBegin != aAlterType) - aOwnTypes.push_back(*pBegin); + if( (*pIter != aRenameType || getRenameService().is()) && (*pIter != aAlterType || getAlterService().is())) + aOwnTypes.push_back(*pIter); } Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; @@ -373,10 +327,17 @@ Sequence< Type > SAL_CALL ODBTable::getTypes( ) throw(RuntimeException) } // XRename, //------------------------------------------------------------------------------ -void SAL_CALL ODBTable::rename( const ::rtl::OUString& /*_rNewName*/ ) throw(SQLException, ElementExistException, RuntimeException) +void SAL_CALL ODBTable::rename( const ::rtl::OUString& _rNewName ) throw(SQLException, ElementExistException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::rename" ); - throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed); + if ( !getRenameService().is() ) + throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); + + Reference xTable(this); + getRenameService()->rename(xTable,_rNewName); + ::connectivity::OTable_TYPEDEF::rename(_rNewName); } // XAlterTable, @@ -385,55 +346,15 @@ void SAL_CALL ODBTable::alterColumnByName( const ::rtl::OUString& _rName, const { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::alterColumnByName" ); ::osl::MutexGuard aGuard(m_aMutex); - checkDisposed( - connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed); - if(m_pColumns->hasByName(_rName)) - { - ::rtl::OUString sSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); - ::rtl::OUString aQuote; - Reference xMeta = getMetaData(); - if ( xMeta.is() ) - aQuote = xMeta->getIdentifierQuoteString( ); - ::rtl::OUString sComposedName; - - sComposedName = ::dbtools::composeTableName( xMeta, m_CatalogName, m_SchemaName, m_Name, sal_True, ::dbtools::eInTableDefinitions ); - if(!sComposedName.getLength()) - ::dbtools::throwFunctionSequenceException(*this); - - sSql += sComposedName; - sSql += ::rtl::OUString::createFromAscii(" ALTER "); - sSql += ::dbtools::quoteName(aQuote,_rName); - - ::rtl::OUString sNewDefaultValue,sDefaultValue; - - Reference xColumn; - m_pColumns->getByName(_rName) >>= xColumn; - if(_rxDescriptor->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE)) - _rxDescriptor->getPropertyValue(PROPERTY_DEFAULTVALUE) >>= sNewDefaultValue; - if(xColumn.is() && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE)) - xColumn->getPropertyValue(PROPERTY_DEFAULTVALUE) >>= sDefaultValue; - - if(sNewDefaultValue != sDefaultValue && getMetaData().is() ) - { - if(sNewDefaultValue.getLength()) - { - sSql += ::rtl::OUString::createFromAscii(" SET DEFAULT "); - sSql += sNewDefaultValue; - } - else - sSql += ::rtl::OUString::createFromAscii(" DROP DEFAULT"); - OSL_ENSURE(getMetaData()->getConnection().is(),"Connection is null!"); - Reference< XStatement > xStmt = getMetaData()->getConnection()->createStatement( ); - if(xStmt.is()) - xStmt->execute(sSql); - } - else - // not supported - throw SQLException(DBACORE_RESSTRING(RID_STR_NO_ALTER_COLUMN_DEF),*this,SQLSTATE_GENERAL,1000,Any() ); - } - else - // not supported - throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME),*this,SQLSTATE_GENERAL,1000,Any() ); + checkDisposed(connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed); + if ( !getAlterService().is() ) + throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); + + if ( !m_pColumns->hasByName(_rName) ) + throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any() ); + + Reference xTable(this); + getAlterService()->alterColumnByName(xTable,_rName,_rxDescriptor); m_pColumns->refresh(); } // ----------------------------------------------------------------------------- @@ -476,8 +397,8 @@ sdbcx::OCollection* ODBTable::createColumns(const TStringVector& _rNames) RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::createColumns" ); Reference xMeta = getMetaData(); OColumns* pCol = new OColumns(*this, m_aMutex, NULL, isCaseSensitive(), _rNames, this,this, - xMeta.is() && xMeta->supportsAlterTableWithAddColumn(), - xMeta.is() && xMeta->supportsAlterTableWithDropColumn()); + getAlterService().is() || (xMeta.is() && xMeta->supportsAlterTableWithAddColumn()), + getAlterService().is() || (xMeta.is() && xMeta->supportsAlterTableWithDropColumn())); static_cast(pCol)->setParent(this); pCol->setParent(*this); m_pColumnMediator = new OContainerMediator( pCol, m_xColumnDefinitions, getConnection(), OContainerMediator::eColumns ); @@ -497,7 +418,3 @@ sdbcx::OCollection* ODBTable::createIndexes(const TStringVector& _rNames) return new OIndexes(this,m_aMutex,_rNames,NULL); } // ----------------------------------------------------------------------------- - - - - diff --git a/dbaccess/source/core/api/viewcontainer.cxx b/dbaccess/source/core/api/viewcontainer.cxx index 342d68eea0ba..4f57aa29b4ec 100644 --- a/dbaccess/source/core/api/viewcontainer.cxx +++ b/dbaccess/source/core/api/viewcontainer.cxx @@ -31,74 +31,30 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef _DBA_CORE_VIEWCONTAINER_HXX_ #include "viewcontainer.hxx" -#endif -#ifndef DBACCESS_SHARED_DBASTRINGS_HRC #include "dbastrings.hrc" -#endif -#ifndef _TOOLS_DEBUG_HXX +#include "core_resource.hxx" +#include "core_resource.hrc" +#include "View.hxx" + #include -#endif -#ifndef _WLDCRD_HXX #include -#endif -#ifndef _COMPHELPER_ENUMHELPER_HXX_ #include -#endif -#ifndef _DBA_CORE_RESOURCE_HXX_ -#include "core_resource.hxx" -#endif -#ifndef _DBA_CORE_RESOURCE_HRC_ -#include "core_resource.hrc" -#endif +#include +#include +#include +#include +#include -#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ #include -#endif - -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ -#include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ -#include -#endif -#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ -#include -#endif -#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ #include -#endif -#ifndef _COMPHELPER_TYPES_HXX_ -#include -#endif -#ifndef _CONNECTIVITY_DBTOOLS_HXX_ -#include -#endif -#ifndef _COMPHELPER_EXTRACT_HXX_ -#include -#endif -#ifndef _DBHELPER_DBEXCEPTION_HXX_ -#include -#endif -#ifndef _CONNECTIVITY_SDBCX_VIEW_HXX_ -#include -#endif -#ifndef _RTL_USTRBUF_HXX_ -#include -#endif +#include +#include +#include using namespace dbaccess; using namespace dbtools; @@ -159,14 +115,12 @@ ObjectType OViewContainer::createObject(const ::rtl::OUString& _rName) sSchema, sTable, ::dbtools::eInDataManipulation); - return new ::connectivity::sdbcx::OView(isCaseSensitive(), - sTable, - m_xMetaData, - 0, - ::rtl::OUString(), - sSchema, - sCatalog - ); + return new View(m_xConnection, + isCaseSensitive(), + sCatalog, + sSchema, + sTable + ); } return xProp; diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 8b050effc894..b5a7b8ddf439 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -1149,6 +1149,17 @@ const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings() AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( (sal_Bool)sal_True ) ), AsciiPropertyValue( "EscapeDateTime", makeAny( (sal_Bool)sal_True ) ), + // known services to handle database tasks + AsciiPropertyValue( "TableAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "TableRenameServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "ViewAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "ViewSupportServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "CommandDefinitionSupplier", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "FormSupplier", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "ReportSupplier", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "KeyAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "IndexAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue() }; return aKnownSettings; diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx index 043198388976..41ae7e0e0b25 100644 --- a/dbaccess/source/core/dataaccess/connection.cxx +++ b/dbaccess/source/core/dataaccess/connection.cxx @@ -42,6 +42,7 @@ #include "ContainerMediator.hxx" #include "SingleSelectQueryComposer.hxx" #include "querycomposer.hxx" +#include "sdbcoretools.hxx" /** === begin UNO includes === **/ #include @@ -617,7 +618,7 @@ void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::refresh" ); if ( _rToBeRefreshed == Reference< XNameAccess >(m_pTables) ) { - if (!m_pTables->isInitialized()) + if (m_pTables && !m_pTables->isInitialized()) { impl_fillTableFilter(); // check if our "master connection" can supply tables @@ -635,7 +636,7 @@ void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) } else if ( _rToBeRefreshed == Reference< XNameAccess >(m_pViews) ) { - if (!m_pViews->isInitialized()) + if (m_pViews && !m_pViews->isInitialized()) { impl_fillTableFilter(); // check if our "master connection" can supply tables @@ -729,6 +730,28 @@ Reference< XInterface > SAL_CALL OConnection::createInstance( const ::rtl::OUStr xRet = new OSingleSelectQueryComposer( getTables(),this, m_aContext ); m_aComposers.push_back(WeakReferenceHelper(xRet)); } + else + { + Reference xDs = dbaccess::getDataSource(*this); + Any aValue; + if ( dbtools::getDataSourceSetting(xDs,_sServiceSpecifier,aValue) ) + { + ::rtl::OUString sSupportService; + aValue >>= sSupportService; + if ( sSupportService.getLength() ) + { + TSupportServices::iterator aFind = m_aSupportServices.find(sSupportService); + if ( aFind == m_aSupportServices.end()) + { + Sequence aArgs(1); + Reference xMy(this); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")),makeAny(xMy)); + aFind = m_aSupportServices.insert(TSupportServices::value_type(sSupportService,m_aContext.createComponentWithArguments(sSupportService,aArgs))).first; + } + return aFind->second; + } + } + } return Reference< XInterface >(xRet,UNO_QUERY); } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/connection.hxx b/dbaccess/source/core/dataaccess/connection.hxx index 88e59f007a25..98b8535953db 100644 --- a/dbaccess/source/core/dataaccess/connection.hxx +++ b/dbaccess/source/core/dataaccess/connection.hxx @@ -30,62 +30,25 @@ #ifndef _DBA_CORE_CONNECTION_HXX_ #define _DBA_CORE_CONNECTION_HXX_ -#ifndef _DBASHARED_APITOOLS_HXX_ #include "apitools.hxx" -#endif -#ifndef _DBA_CORE_QUERYCONTAINER_HXX_ #include "querycontainer.hxx" -#endif -#ifndef _DBA_CORE_TABLECONTAINER_HXX_ #include "tablecontainer.hxx" -#endif -#ifndef _DBA_CORE_VIEWCONTAINER_HXX_ #include "viewcontainer.hxx" -#endif -#ifndef DBA_CORE_REFRESHLISTENER_HXX #include "RefreshListener.hxx" -#endif -#ifndef DBTOOLS_WARNINGSCONTAINER_HXX -#include -#endif /** === begin UNO includes === **/ -#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSERFACTORY_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XCOMMANDPREPARATION_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XUSERSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XGROUPSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_TOOLS_XCONNECTIONTOOLS_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_APPLICATION_XTABLEUIPROVIDER_HPP_ #include -#endif /** === end UNO includes === **/ #if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14) @@ -93,14 +56,10 @@ #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 14 #include #endif - -#ifndef COMPHELPER_COMPONENTCONTEXT_HXX #include -#endif - -#ifndef _CONNECTIVITY_CONNECTIONWRAPPER_HXX_ +#include #include -#endif +#include //........................................................................ namespace dbaccess @@ -151,6 +110,11 @@ protected: ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XConnectionTools > m_xConnectionTools; ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XTableUIProvider > m_xTableUIProvider; + // defines the helper services for example to query the command of a view + // @ see com.sun.star.sdb.tools.XViewSupport + DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>, TSupportServices); + TSupportServices m_aSupportServices; + OTableContainer* m_pTables; OViewContainer* m_pViews; diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 6708dbfa56bb..2cc3f0604c6a 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -41,15 +41,6 @@ #include "databasecontext.hxx" #include "documentcontainer.hxx" -#include -#include -#include -#include -#include -#include -#include - -#include /** === begin UNO includes === **/ #include @@ -80,6 +71,13 @@ #include #include #include +#include +#include + +#include + +#include + #include #include #include @@ -1151,8 +1149,25 @@ Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODa Reference< XNameAccess > xContainer = rContainerRef; if ( !xContainer.is() ) { - TContentPtr& rContainerData( m_pImpl->getObjectContainer( _eType ) ); - rContainerRef = xContainer = new ODocumentContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, bFormsContainer ); + Any aValue; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this); + if ( dbtools::getDataSourceSetting(xMy,bFormsContainer ? "FormSupplier" : "ReportSupplier",aValue) ) + { + ::rtl::OUString sSupportService; + aValue >>= sSupportService; + if ( sSupportService.getLength() ) + { + Sequence aArgs(1); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSource")),makeAny(xMy)); + xContainer.set(m_pImpl->m_aContext.createComponentWithArguments(sSupportService,aArgs),UNO_QUERY); + rContainerRef = xContainer; + } + } + if ( !xContainer.is() ) + { + TContentPtr& rContainerData( m_pImpl->getObjectContainer( _eType ) ); + rContainerRef = xContainer = new ODocumentContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, bFormsContainer ); + } impl_reparent_nothrow( xContainer ); } return xContainer; diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index f7fc11a5d80a..94a634c652e7 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -42,6 +42,7 @@ #include "SharedConnection.hxx" #include "databasedocument.hxx" + /** === begin UNO includes === **/ #include #include @@ -70,6 +71,7 @@ #include #include #include +#include #include #include #include @@ -1357,8 +1359,24 @@ Reference< XNameAccess > SAL_CALL ODatabaseSource::getQueryDefinitions( ) throw( Reference< XNameAccess > xContainer = m_pImpl->m_xCommandDefinitions; if ( !xContainer.is() ) { - TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::E_QUERY ) ); - xContainer = new OCommandContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, sal_False ); + Any aValue; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this); + if ( dbtools::getDataSourceSetting(xMy,"CommandDefinitionSupplier",aValue) ) + { + ::rtl::OUString sSupportService; + aValue >>= sSupportService; + if ( sSupportService.getLength() ) + { + Sequence aArgs(1); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSource")),makeAny(xMy)); + xContainer.set(m_pImpl->m_aContext.createComponentWithArguments(sSupportService,aArgs),UNO_QUERY); + } + } + if ( !xContainer.is() ) + { + TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::E_QUERY ) ); + xContainer = new OCommandContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, sal_False ); + } m_pImpl->m_xCommandDefinitions = xContainer; } return xContainer; diff --git a/dbaccess/source/core/inc/View.hxx b/dbaccess/source/core/inc/View.hxx new file mode 100644 index 000000000000..90226d011d84 --- /dev/null +++ b/dbaccess/source/core/inc/View.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: View.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef DBACCESS_VIEW_HXX +#define DBACCESS_VIEW_HXX + +#include "connectivity/sdbcx/VView.hxx" + +/** === begin UNO includes === **/ +#include +#include +#include +/** === end UNO includes === **/ + +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= View + //==================================================================== + typedef ::connectivity::sdbcx::OView View_Base; + typedef ::cppu::ImplHelper1< ::com::sun::star::sdbcx::XAlterView > View_IBASE; + class View :public View_Base + ,public View_IBASE + { + public: + View( + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, + sal_Bool _bCaseSensitive, + const ::rtl::OUString& _rCatalogName, + const ::rtl::OUString& _rSchemaName, + const ::rtl::OUString& _rName + ); + + // UNO + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + + // XAlterView + virtual void SAL_CALL alterCommand( const ::rtl::OUString& NewCommand ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + + protected: + virtual ~View(); + + protected: + // OPropertyContainer + virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle ) const; + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XViewSupport> m_xViewSupport; + sal_Int32 m_nCommandHandle; + private: + using View_Base::getFastPropertyValue; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // DBACCESS_VIEW_HXX diff --git a/dbaccess/source/core/inc/sdbcoretools.hxx b/dbaccess/source/core/inc/sdbcoretools.hxx index a7e2b9986f7e..fd49f1faa387 100644 --- a/dbaccess/source/core/inc/sdbcoretools.hxx +++ b/dbaccess/source/core/inc/sdbcoretools.hxx @@ -51,26 +51,6 @@ namespace dbaccess getDataSource( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDependentObject ); // ----------------------------------------------------------------------------- - /** retrieves a particular indirect data source setting - - @param _rxDataSource - a data source component - @param _pAsciiSettingsName - the ASCII name of the setting to obtain - @param _rSettingsValue - the value of the setting, upon successfull return - - @return - if the setting is not present in the DataSource::Info - member of the data source - otherwise - */ - bool getDataSourceSetting( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDataSource, - const sal_Char* _pAsciiSettingsName, - ::com::sun::star::uno::Any& /* [out] */ _rSettingsValue - ); - //......................................................................... } // namespace dbaccess //......................................................................... diff --git a/dbaccess/source/core/inc/table.hxx b/dbaccess/source/core/inc/table.hxx index 9573f03ba40c..1f34dfd5dd9b 100644 --- a/dbaccess/source/core/inc/table.hxx +++ b/dbaccess/source/core/inc/table.hxx @@ -31,58 +31,24 @@ #ifndef _DBA_CORE_TABLE_HXX_ #define _DBA_CORE_TABLE_HXX_ -#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XINDEXESSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XALTERTABLE_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include -#endif -#ifndef _CPPUHELPER_COMPBASE2_HXX_ #include -#endif -#ifndef _DBASHARED_APITOOLS_HXX_ #include "apitools.hxx" -#endif -#ifndef _DBA_CORE_DATASETTINGS_HXX_ #include "datasettings.hxx" -#endif -#ifndef _DBA_COREAPI_COLUMN_HXX_ #include -#endif -#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ #include -#endif -#ifndef CONNECTIVITY_TABLEHELPER_HXX #include -#endif -#ifndef _COMPHELPER_UNO3_HXX_ #include -#endif -#ifndef COMPHELPER_IDPROPERTYARRAYUSAGEHELPER_HXX #include -#endif namespace dbaccess { diff --git a/dbaccess/source/core/misc/sdbcoretools.cxx b/dbaccess/source/core/misc/sdbcoretools.cxx index 75a1cd6b36eb..ab189749783e 100644 --- a/dbaccess/source/core/misc/sdbcoretools.cxx +++ b/dbaccess/source/core/misc/sdbcoretools.cxx @@ -96,39 +96,6 @@ namespace dbaccess return xReturn; } - // ------------------------------------------------------------------------- - bool getDataSourceSetting( const Reference< XInterface >& _rxDataSource, const sal_Char* _pAsciiSettingsName, - Any& /* [out] */ _rSettingsValue ) - { - bool bIsPresent = false; - try - { - Reference< XPropertySet > xDataSource( _rxDataSource, UNO_QUERY ); - OSL_ENSURE( xDataSource.is(), "getDataSourceSetting: invalid data source object!" ); - if ( !xDataSource.is() ) - return false; - - Sequence< PropertyValue > aSettings; - OSL_VERIFY( xDataSource->getPropertyValue( PROPERTY_INFO ) >>= aSettings ); - const PropertyValue* pSetting = aSettings.getConstArray(); - const PropertyValue* pSettingEnd = aSettings.getConstArray() + aSettings.getLength(); - for ( ; pSetting != pSettingEnd; ++pSetting ) - { - if ( pSetting->Name.equalsAscii( _pAsciiSettingsName ) ) - { - _rSettingsValue = pSetting->Value; - bIsPresent = true; - break; - } - } - } - catch( const Exception& ) - { - OSL_ENSURE( sal_False, "getDataSourceSetting: caught an exception!" ); - } - return bIsPresent; - } - // ----------------------------------------------------------------------------- //......................................................................... } // namespace dbaccess diff --git a/dbaccess/source/filter/xml/xmlDatabase.cxx b/dbaccess/source/filter/xml/xmlDatabase.cxx index 3f3f183ba038..89111c6e6e48 100644 --- a/dbaccess/source/filter/xml/xmlDatabase.cxx +++ b/dbaccess/source/filter/xml/xmlDatabase.cxx @@ -30,45 +30,20 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef DBA_XMLDATABASE_HXX #include "xmlDatabase.hxx" -#endif -#ifndef DBA_XMLFILTER_HXX #include "xmlfilter.hxx" -#endif -#ifndef _XMLOFF_XMLTOKEN_HXX #include -#endif -#ifndef _XMLOFF_XMLNMSPE_HXX #include -#endif -#ifndef DBA_XMLDATASOURCE_HXX #include "xmlDataSource.hxx" -#endif -#ifndef DBA_XMLDOCUMENTS_HXX #include "xmlDocuments.hxx" -#endif -#ifndef DBA_XMLENUMS_HXX #include "xmlEnums.hxx" -#endif -#ifndef _COM_SUN_STAR_SDB_XREPORTDOCUMENTSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XFORMDOCUMENTSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_ #include -#endif -#ifndef DBACCESS_SHARED_XMLSTRINGS_HRC #include "xmlstrings.hrc" -#endif -#ifndef _TOOLS_DEBUG_HXX #include -#endif +#include namespace dbaxml { @@ -111,25 +86,46 @@ SvXMLImportContext* OXMLDatabase::CreateChildContext( case XML_TOK_FORMS: { GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); - Reference xSup(GetOwnImport().GetModel(),UNO_QUERY); - if ( xSup.is() ) - pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"FormSupplier",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } } break; case XML_TOK_REPORTS: { GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); - Reference xSup(GetOwnImport().GetModel(),UNO_QUERY); - if ( xSup.is() ) - pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"ReportSupplier",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } } break; case XML_TOK_QUERIES: { GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); - Reference xSup(GetOwnImport().getDataSource(),UNO_QUERY); - if ( xSup.is() ) - pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitionSupplier",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference xSup(GetOwnImport().getDataSource(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION); + } } break; case XML_TOK_TABLES: diff --git a/dbaccess/source/filter/xml/xmlExport.cxx b/dbaccess/source/filter/xml/xmlExport.cxx index 8008416956f4..370e849c40b3 100644 --- a/dbaccess/source/filter/xml/xmlExport.cxx +++ b/dbaccess/source/filter/xml/xmlExport.cxx @@ -31,82 +31,37 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef DBA_XMLEXPORT_HXX #include "xmlExport.hxx" -#endif -#ifndef DBA_XMLAUTOSTYLE_HXX #include "xmlAutoStyle.hxx" -#endif -#ifndef _FLT_REGHELPER_HXX_ #include "flt_reghelper.hxx" -#endif -#ifndef _XMLOFF_PROGRESSBARHELPER_HXX #include -#endif -#ifndef _XMLOFF_XMLTOKEN_HXX #include -#endif -#ifndef _XMLOFF_TEXTIMP_HXX_ #include -#endif -#ifndef _XMLOFF_XMLNMSPE_HXX #include -#endif -#ifndef _XMLOFF_XMLUCONV_HXX #include -#endif -#ifndef _XMLOFF_NMSPMAP_HXX #include -#endif -#ifndef _COMPHELPER_TYPES_HXX_ #include -#endif -#ifndef DBACCESS_SHARED_XMLSTRINGS_HRC #include "xmlstrings.hrc" -#endif -#ifndef DBA_XMLENUMS_HXX #include "xmlEnums.hxx" -#endif -#ifndef _XMLOFF_NMSPMAP_HXX #include -#endif -#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XFORMDOCUMENTSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XOFFICEDATABASEDOCUMENT_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XREPORTDOCUMENTSSUPPLIER_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_ #include -#endif #include #include -#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_ #include -#endif -#ifndef _XMLOFF_XMLUCONV_HXX #include -#endif -#ifndef DBA_XMLHELPER_HXX #include "xmlHelper.hxx" -#endif -#ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_ #include -#endif #include #include #include #include +#include #include @@ -1110,47 +1065,68 @@ void ODBExport::exportColumns(const Reference& _xColSup) // ----------------------------------------------------------------------------- void ODBExport::exportForms() { - Reference xSup(GetModel(),UNO_QUERY); - if ( xSup.is() ) + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"ReportSupplier",aValue); + aValue >>= sService; + if ( !sService.getLength() ) { - Reference< XNameAccess > xCollection = xSup->getFormDocuments(); - if ( xCollection.is() && xCollection->hasElements() ) + Reference xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) { - ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportComponent); - exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + Reference< XNameAccess > xCollection = xSup->getFormDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + } } } } // ----------------------------------------------------------------------------- void ODBExport::exportReports() { - Reference xSup(GetModel(),UNO_QUERY); - if ( xSup.is() ) + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"ReportSupplier",aValue); + aValue >>= sService; + if ( !sService.getLength() ) { - Reference< XNameAccess > xCollection = xSup->getReportDocuments(); - if ( xCollection.is() && xCollection->hasElements() ) + Reference xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) { - ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportComponent); - exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + Reference< XNameAccess > xCollection = xSup->getReportDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + } } } } // ----------------------------------------------------------------------------- void ODBExport::exportQueries(sal_Bool _bExportContext) { - Reference xSup(getDataSource(),UNO_QUERY); - if ( xSup.is() ) + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitionSupplier",aValue); + aValue >>= sService; + if ( !sService.getLength() ) { - Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); - if ( xCollection.is() && xCollection->hasElements() ) + Reference xSup(getDataSource(),UNO_QUERY); + if ( xSup.is() ) { - ::std::auto_ptr< ::comphelper::mem_fun1_t > pMemFunc; - if ( _bExportContext ) - pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportQuery) ); - else - pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportAutoStyle) ); + Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::std::auto_ptr< ::comphelper::mem_fun1_t > pMemFunc; + if ( _bExportContext ) + pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportQuery) ); + else + pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportAutoStyle) ); - exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc); + exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc); + } } } } diff --git a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx index 51121b022e88..2af41d70cc13 100644 --- a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx +++ b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx @@ -119,7 +119,13 @@ SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* return etTableOrView; if (pQueries == pEntryParent) + { + DBTreeListUserData* pEntryData = static_cast(_pEntry->GetUserData()); + if ( pEntryData ) + return pEntryData->eType; + return etQuery; + } return etUnknown; } diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index b2cfbe04a515..8377edda3017 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -519,6 +519,8 @@ sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun:: DBTreeListUserData* pData = static_cast(m_pCurrentlyDisplayed->GetUserData()); OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" ); + if ( !pData->xObjectProperties.is() ) + return sal_False; ::rtl::OUString* pStringIter = aProperties.getArray(); Any* pValueIter = aValues.getArray(); @@ -732,7 +734,7 @@ Reference getColumnHelper(SvLBoxEntry* _pCurrentlyDisplayed,const ::rtl::OUString aName; _rxSource->getPropertyValue(PROPERTY_NAME) >>= aName; if(xNames.is() && xNames->hasByName(aName)) - ::cppu::extractInterface(xRet,xNames->getByName(aName)); + xRet.set(xNames->getByName(aName),UNO_QUERY); } return xRet; } @@ -1100,7 +1102,17 @@ SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataS m_pTreeView->getListBox().Expand(pCommandType); // look for the object - pObject = m_pTreeView->getListBox().GetEntryPosByName(_rCommand, pCommandType); + ::rtl::OUString sCommand = _rCommand; + sal_Int32 nIndex = 0; + do + { + ::rtl::OUString sPath = sCommand.getToken( 0, '/', nIndex ); + pObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, pCommandType); + pCommandType = pObject; + if (_bExpandAncestors && nIndex >= 0 ) + m_pTreeView->getListBox().Expand(pCommandType); + } + while ( nIndex >= 0 ); } } } @@ -1991,7 +2003,7 @@ void SbaTableQueryBrowser::initializeTreeModel() } } // ------------------------------------------------------------------------- -sal_Bool SbaTableQueryBrowser::populateTree(const Reference& _xNameAccess, +void SbaTableQueryBrowser::populateTree(const Reference& _xNameAccess, SvLBoxEntry* _pParent, EntryType _eEntryType) { @@ -2008,34 +2020,39 @@ sal_Bool SbaTableQueryBrowser::populateTree(const Reference& _xName { if(!m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent)) { + Reference xChild(_xNameAccess->getByName(*pIter),UNO_QUERY); DBTreeListUserData* pEntryData = new DBTreeListUserData; pEntryData->eType = _eEntryType; - implAppendEntry( _pParent, *pIter, pEntryData, _eEntryType ); + if ( _eEntryType == etQuery && xChild.is() ) + { + pEntryData->eType = etQueryContainer; + } + implAppendEntry( _pParent, *pIter, pEntryData, pEntryData->eType ); } } } catch(Exception&) { DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree"); - return sal_False; } - return sal_True; } //------------------------------------------------------------------------------ -void SbaTableQueryBrowser::implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType ) +SvLBoxEntry* SbaTableQueryBrowser::implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType ) { ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( _pParent ) ); Image aImage, aImageHC; pImageProvider->getImages( _rName, getDatabaseObjectType( _eEntryType ), aImage, aImageHC ); - SvLBoxEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, sal_False, LIST_APPEND, _pUserData ); + SvLBoxEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, _eEntryType == etQueryContainer , LIST_APPEND, _pUserData ); m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL ); m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL ); m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST ); m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST ); + + return pNewEntry; } //------------------------------------------------------------------------------ @@ -2166,29 +2183,54 @@ sal_Bool SbaTableQueryBrowser::ensureEntryObject( SvLBoxEntry* _pEntry ) break; } - try { - Reference< XQueryDefinitionsSupplier > xQuerySup; - m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup; - if (xQuerySup.is()) + SvLBoxEntry* pParent = m_pTreeView->getListBox().GetParent(_pEntry); + if ( pParent != pDataSourceEntry ) { - Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions(); - Reference< XContainer > xCont(xQueryDefs, UNO_QUERY); - if (xCont.is()) - // add as listener to get notified if elements are inserted or removed - xCont->addContainerListener(this); + SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING); + OSL_ENSURE(pString,"There must be a string item!"); + ::rtl::OUString aName(pString->GetText()); + DBTreeListUserData* pData = static_cast(pParent->GetUserData()); + try + { + Reference< XNameAccess > xNameAccess(pData->xContainer,UNO_QUERY); + if ( xNameAccess.is() ) + pEntryData->xContainer.set(xNameAccess->getByName(aName),UNO_QUERY); + } + catch(const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } - pEntryData->xContainer = xQueryDefs; bSuccess = pEntryData->xContainer.is(); } - else { - DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!"); + else + { + try + { + Reference< XQueryDefinitionsSupplier > xQuerySup; + m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup; + if (xQuerySup.is()) + { + Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions(); + Reference< XContainer > xCont(xQueryDefs, UNO_QUERY); + if (xCont.is()) + // add as listener to get notified if elements are inserted or removed + xCont->addContainerListener(this); + + pEntryData->xContainer = xQueryDefs; + bSuccess = pEntryData->xContainer.is(); + } + else { + DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!"); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } break; default: @@ -2343,7 +2385,18 @@ IMPL_LINK(SbaTableQueryBrowser, OnSelectionChange, void*, /*NOINTERESTEDIN*/) { return implSelect( m_pTreeView->getListBox().FirstSelected() ) ? 1L : 0L; } - +//------------------------------------------------------------------------------ +SvLBoxEntry* SbaTableQueryBrowser::implGetConnectionEntry(SvLBoxEntry* _pEntry) const +{ + SvLBoxEntry* pCurrentEntry = _pEntry; + DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() ); + while(pEntryData->eType != etDatasource ) + { + pCurrentEntry = m_pTreeModel->GetParent(pCurrentEntry); + pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() ); + } + return pCurrentEntry; +} //------------------------------------------------------------------------------ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) { @@ -2369,7 +2422,7 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) DBTreeListUserData* pContainerData = static_cast(pContainer->GetUserData()); // get the entry for the datasource - SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pContainer); + SvLBoxEntry* pConnection = implGetConnectionEntry(pContainer); DBTreeListUserData* pConData = static_cast(pConnection->GetUserData()); // reinitialize the rowset @@ -2380,12 +2433,26 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) xRowSetProps->getPropertyValue(PROPERTY_COMMAND) >>= aOldName; sal_Int32 nOldType = 0; xRowSetProps->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nOldType; - Reference xOldConnection; - ::cppu::extractInterface(xOldConnection,xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION)); + Reference xOldConnection(xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY); + // the name of the table or query SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING); OSL_ENSURE(pString,"There must be a string item!"); - ::rtl::OUString aName(pString->GetText().GetBuffer()); + const ::rtl::OUString sSimpleName = pString->GetText(); + ::rtl::OUStringBuffer sNameBuffer(sSimpleName); + if ( etQueryContainer == pContainerData->eType ) + { + SvLBoxEntry* pTemp = pContainer; + while( m_pTreeModel->GetParent(pTemp) != pConnection ) + { + sNameBuffer.insert(0,sal_Unicode('/')); + pString = (SvLBoxString*)pTemp->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING); + OSL_ENSURE(pString,"There must be a string item!"); + sNameBuffer.insert(0,pString->GetText()); + pTemp = m_pTreeModel->GetParent(pTemp); + } + } + ::rtl::OUString aName = sNameBuffer.makeStringAndClear(); sal_Int32 nCommandType = ( etTableContainer == pContainerData->eType) ? CommandType::TABLE @@ -2443,9 +2510,14 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) break; case CommandType::QUERY: { - Reference xSup( pConData->xConnection, UNO_QUERY ); - if(xSup.is()) - xNameAccess = xSup->getQueries(); + if ( pContainerData->xContainer.is() ) + xNameAccess.set( pContainerData->xContainer, UNO_QUERY ); + else + { + Reference xSup( pConData->xConnection, UNO_QUERY ); + if(xSup.is()) + xNameAccess = xSup->getQueries(); + } } break; } @@ -2453,13 +2525,13 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) sStatus.SearchAndReplaceAscii("$name$", aName); BrowserViewStatusDisplay aShowStatus(static_cast(getView()), sStatus); - if(xNameAccess.is() && xNameAccess->hasByName(aName)) + if(xNameAccess.is() && xNameAccess->hasByName(sSimpleName)) { DBTreeListUserData* pData = static_cast(_pEntry->GetUserData()); if ( !pData->xObjectProperties.is() ) { Reference xObject; - if(xNameAccess->getByName(aName) >>= xObject) // remember the table or query object + if(xNameAccess->getByName(sSimpleName) >>= xObject) // remember the table or query object { pData->xObjectProperties = pData->xObjectProperties.query( xObject ); // if the query contains a parameterized statement and preview is enabled we won't get any data. @@ -3499,7 +3571,7 @@ void SbaTableQueryBrowser::loadMenu(const Reference< XFrame >& _xFrame) { SvLBoxEntry* pContainer = m_pTreeModel->GetParent(m_pCurrentlyDisplayed); // get the entry for the datasource - SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pContainer); + SvLBoxEntry* pConnection = implGetConnectionEntry(pContainer); ::rtl::OUString sName = m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed); sTitle = GetEntryText( pConnection ); INetURLObject aURL(sTitle); diff --git a/dbaccess/source/ui/inc/unodatbr.hxx b/dbaccess/source/ui/inc/unodatbr.hxx index 23d9cfd5b542..3436d565367f 100644 --- a/dbaccess/source/ui/inc/unodatbr.hxx +++ b/dbaccess/source/ui/inc/unodatbr.hxx @@ -374,7 +374,7 @@ namespace dbaui */ void closeConnection(SvLBoxEntry* _pEntry,sal_Bool _bDisposeConnection = sal_True); - sal_Bool populateTree(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xNameAccess, SvLBoxEntry* _pParent, EntryType _eEntryType); + void populateTree(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xNameAccess, SvLBoxEntry* _pParent, EntryType _eEntryType); void initializeTreeModel(); /** search in the tree for query- or tablecontainer equal to this interface and return @@ -433,8 +433,9 @@ namespace dbaui sal_Bool _bSelectDirect = sal_False ); + SvLBoxEntry* implGetConnectionEntry(SvLBoxEntry* _pEntry) const; /// inserts an entry into the tree - void implAppendEntry( + SvLBoxEntry* implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, -- cgit From 1806dfd473c3753064d8f5d40e760783912195ab Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 16 Dec 2009 23:25:02 +0100 Subject: dba33e: #i107438# allow loading documents hidden, by ensuring the document definition stays alive as long as the document is alive --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 20d1ce157b45..f4426025c6fa 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -721,7 +721,7 @@ void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow() // ensure that we ourself are kept alive as long as the embedded object's frame is // opened - LifetimeCoupler::couple( *this, Reference< XComponent >( xFrame, UNO_QUERY_THROW ) ); + LifetimeCoupler::couple( *this, xFrame.get() ); // init the edit view if ( m_bForm && m_bOpenInDesign ) @@ -1036,6 +1036,11 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow(); } + else + { + // ensure that we ourself are kept alive as long as the document is open + LifetimeCoupler::couple( *this, xModel.get() ); + } if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) ODocumentDefinition::fillReportData( m_aContext, getComponent(), xConnection ); -- cgit From 1eac49df5c337a5832231514c7e352009f0295fd Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Fri, 18 Dec 2009 07:02:42 +0100 Subject: dba33e: remove unused header --- dbaccess/source/core/inc/View.hxx | 1 - 1 file changed, 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/inc/View.hxx b/dbaccess/source/core/inc/View.hxx index 90226d011d84..0cda27afcf82 100644 --- a/dbaccess/source/core/inc/View.hxx +++ b/dbaccess/source/core/inc/View.hxx @@ -35,7 +35,6 @@ /** === begin UNO includes === **/ #include -#include #include /** === end UNO includes === **/ -- cgit From 6f4bc5831ab4bc0be6cd1e01e038b3585770eed6 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Mon, 21 Dec 2009 14:42:31 +0100 Subject: dba33e: #i107717# allow the command definition to define the column names which should be shown --- dbaccess/source/core/api/RowSet.cxx | 4 ++++ dbaccess/source/core/api/definitioncolumn.cxx | 11 +++++++++-- dbaccess/source/core/api/query.cxx | 27 +++++++++++++++++++-------- dbaccess/source/core/inc/definitioncolumn.hxx | 3 ++- 4 files changed, 34 insertions(+), 11 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 1adddab143c1..bb500ac94ad2 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -1904,6 +1904,8 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi if(!xColumn.is()) { // no column found so we could look at the position i + bReFetchName = sal_True; + sColumnLabel = ::rtl::OUString(); Reference xIndexAccess(m_xColumns,UNO_QUERY); if(xIndexAccess.is() && i <= xIndexAccess->getCount()) { @@ -1913,7 +1915,9 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi { Sequence< ::rtl::OUString> aSeq = m_xColumns->getElementNames(); if( i <= aSeq.getLength()) + { m_xColumns->getByName(aSeq.getConstArray()[i-1]) >>= xColumn; + } } } if(bReFetchName && xColumn.is()) diff --git a/dbaccess/source/core/api/definitioncolumn.cxx b/dbaccess/source/core/api/definitioncolumn.cxx index 9f9e511fc9b4..77a29812b105 100644 --- a/dbaccess/source/core/api/definitioncolumn.cxx +++ b/dbaccess/source/core/api/definitioncolumn.cxx @@ -192,7 +192,7 @@ rtl::OUString OTableColumn::getImplementationName( ) throw (RuntimeException) DBG_NAME( OQueryColumn ); // ------------------------------------------------------------------------- -OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection ) +OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection,const ::rtl::OUString& _sNewName ) :OTableColumnDescriptor( false /* do not act as descriptor */ ) { const sal_Int32 nPropAttr = PropertyAttribute::READONLY; @@ -210,7 +210,14 @@ OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, co OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_TYPE ) >>= m_nType ); OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISAUTOINCREMENT ) >>= m_bAutoIncrement ); OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISCURRENCY ) >>= m_bCurrency ); - OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_NAME ) >>= m_sName ); + if ( _sNewName.getLength() ) + { + m_sName = _sNewName; + } + else + { + OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_NAME ) >>= m_sName ); + } m_bRowVersion = sal_False; Reference< XPropertySetInfo > xPSI( _rxParserColumn->getPropertySetInfo(), UNO_SET_THROW ); diff --git a/dbaccess/source/core/api/query.cxx b/dbaccess/source/core/api/query.cxx index 7468e88f4fff..ccd91f2a312e 100644 --- a/dbaccess/source/core/api/query.cxx +++ b/dbaccess/source/core/api/query.cxx @@ -191,9 +191,10 @@ void OQuery::rebuildColumns() m_pColumnMediator = NULL; Reference xColSup(m_xCommandDefinition,UNO_QUERY); + Reference< XNameAccess > xColumnDefinitions; if ( xColSup.is() ) { - Reference< XNameAccess > xColumnDefinitions = xColSup->getColumns(); + xColumnDefinitions = xColSup->getColumns(); if ( xColumnDefinitions.is() ) m_pColumnMediator = new OContainerMediator( m_pColumns, xColumnDefinitions, m_xConnection, OContainerMediator::eColumns ); } @@ -236,19 +237,29 @@ void OQuery::rebuildColumns() } Sequence< ::rtl::OUString> aNames = xColumns->getElementNames(); - const ::rtl::OUString* pBegin = aNames.getConstArray(); - const ::rtl::OUString* pEnd = pBegin + aNames.getLength(); - for ( ;pBegin != pEnd; ++pBegin) + Sequence< ::rtl::OUString> aDefintionNames; + bool bApplyDefinitionNames = false; + if ( xColumnDefinitions.is() ) { - Reference xSource(xColumns->getByName( *pBegin ),UNO_QUERY); - OQueryColumn* pColumn = new OQueryColumn( xSource, m_xConnection ); + aDefintionNames = xColumnDefinitions->getElementNames(); + bApplyDefinitionNames = aDefintionNames.getLength() == aNames.getLength(); + } + + ::rtl::OUString sEmpty; + const ::rtl::OUString* pIter = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aNames.getLength(); + for ( sal_Int32 i = 0;pIter != pEnd; ++pIter,++i) + { + Reference xSource(xColumns->getByName( *pIter ),UNO_QUERY); + OQueryColumn* pColumn = new OQueryColumn( xSource, m_xConnection, bApplyDefinitionNames ? aDefintionNames[i] : sEmpty); Reference< XChild > xChild( *pColumn, UNO_QUERY_THROW ); xChild->setParent( *this ); - implAppendColumn( *pBegin, pColumn ); + ::rtl::OUString sNewName = bApplyDefinitionNames ? aDefintionNames[i] : *pIter; + implAppendColumn( sNewName, pColumn ); Reference< XPropertySet > xDest( *pColumn, UNO_QUERY_THROW ); if ( m_pColumnMediator.is() ) - m_pColumnMediator->notifyElementCreated( *pBegin, xDest ); + m_pColumnMediator->notifyElementCreated( sNewName, xDest ); } } catch( const SQLContext& e ) diff --git a/dbaccess/source/core/inc/definitioncolumn.hxx b/dbaccess/source/core/inc/definitioncolumn.hxx index c5151e6bffd5..b67b0de70c59 100644 --- a/dbaccess/source/core/inc/definitioncolumn.hxx +++ b/dbaccess/source/core/inc/definitioncolumn.hxx @@ -167,7 +167,8 @@ namespace dbaccess public: OQueryColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxParserColumn, - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, + const ::rtl::OUString& _sNewName ); // XTypeProvider -- cgit From 845b04c98a87700e7443e5a16e66098103d43d46 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 5 Jan 2010 22:32:38 +0100 Subject: autorecovery: define a new css.document.XDocumentRecovery interface, implement it in both SFX and DBACCESS, and use it in the autorecovery In this course, the auto recovery learned to restore multiple views of a document. Also, in the course of the change, the LoadDispatchListener became superfluous, and was removed. Also, the loader code in dbaccess was slightly adjusted, since now the connectController call is in the responsibility of the loader, and must not happen inside the XController::attachModel call anymore. This change made the ModelControllerConnector class superfluous, so it has been removed, too. --- dbaccess/inc/documentcontroller.hxx | 133 ------------------ dbaccess/inc/singledoccontroller.hxx | 1 - .../source/core/dataaccess/databasedocument.cxx | 30 +++++ .../source/core/dataaccess/databasedocument.hxx | 14 +- dbaccess/source/filter/xml/dbloader2.cxx | 18 ++- dbaccess/source/ui/app/AppController.cxx | 27 ++-- dbaccess/source/ui/app/AppController.hxx | 8 +- dbaccess/source/ui/browser/dataview.cxx | 23 ++++ dbaccess/source/ui/misc/documentcontroller.cxx | 150 --------------------- dbaccess/source/ui/misc/makefile.mk | 1 - 10 files changed, 93 insertions(+), 312 deletions(-) delete mode 100644 dbaccess/inc/documentcontroller.hxx delete mode 100644 dbaccess/source/ui/misc/documentcontroller.cxx (limited to 'dbaccess') diff --git a/dbaccess/inc/documentcontroller.hxx b/dbaccess/inc/documentcontroller.hxx deleted file mode 100644 index a16e4c645b06..000000000000 --- a/dbaccess/inc/documentcontroller.hxx +++ /dev/null @@ -1,133 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: documentcontroller.hxx,v $ - * $Revision: 1.3.2.2 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - - -#ifndef DBACCESS_SOURCE_UI_INC_DOCUMENTCONTROLLER_HXX -#define DBACCESS_SOURCE_UI_INC_DOCUMENTCONTROLLER_HXX - -/** === begin UNO includes === **/ -#ifndef _COM_SUN_STAR_FRAME_XCONTROLLER_HPP_ -#include -#endif -#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_ -#include -#endif -#include -/** === end UNO includes === **/ - -#ifndef INCLUDED_DBACCESSDLLAPI_H -#include "dbaccessdllapi.h" -#endif -//........................................................................ -namespace dbaui -{ -//........................................................................ - - //==================================================================== - //= ModelControllerConnector - //==================================================================== - /** a helper class for controllers associated with an ->XModel - - Instances of this class take an ->XModel, which they connect to at - construction time (->XModel::connectController), and disconnect from - at destruction time (->XModel::disconnectController). - - Additionally, they keep the controller alive (by being a CloseVetoListener) - as long as they themself are alive. - */ - class DBACCESS_DLLPUBLIC ModelControllerConnector - { - private: - typedef ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > Model; - typedef ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > Controller; - - Model m_xModel; - Controller m_xController; - - public: - /** constructs the object, and connects the controller to the model - - @param _rxModel - the model to which the controller should be connected - @param _rxController - the controller which should be connected to the model - */ - ModelControllerConnector( - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxModel, - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController - ); - - /** connects the controller to the model - - @param _rxModel - the model to which the controller should be connected - @param _rxController - the controller which should be connected to the model - */ - void connect( - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxModel, - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController - ); - - /** destroys the object, and disconnects the controller from the model - */ - ~ModelControllerConnector(); - - /** determines whether the object is empty - */ - inline bool empty() const { return !m_xController.is(); } - - /** clears the object - - The controller is disconnected from the model, and references to the model and the controller - are released. - */ - inline void clear() - { - connect( NULL, NULL ); - } - - public: - ModelControllerConnector(); - ModelControllerConnector( const ModelControllerConnector& _rSource ); - ModelControllerConnector& operator=( const ModelControllerConnector& _rSource ); - - private: - void impl_connect(); - void impl_disconnect(); - void impl_copyFrom( const ModelControllerConnector& _rSource ); - }; - -//........................................................................ -} // namespace dbaui -//........................................................................ - -#endif // DBACCESS_SOURCE_UI_INC_DOCUMENTCONTROLLER_HXX - diff --git a/dbaccess/inc/singledoccontroller.hxx b/dbaccess/inc/singledoccontroller.hxx index f63d1c02fdf2..1c5017ff2013 100644 --- a/dbaccess/inc/singledoccontroller.hxx +++ b/dbaccess/inc/singledoccontroller.hxx @@ -31,7 +31,6 @@ #ifndef DBAUI_SINGLEDOCCONTROLLER_HXX #define DBAUI_SINGLEDOCCONTROLLER_HXX -#include "documentcontroller.hxx" #include "genericcontroller.hxx" #include "IEnvironment.hxx" diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 00dca6ea51c0..f6f25b4adde1 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -538,6 +538,26 @@ void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Argumen // <- SYNCHRONIZED } +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseDocument::doEmergencySave( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +{ + // for the moment, just delegate this to our "storeToURL" method + storeToURL( i_TargetLocation, i_MediaDescriptor ); +} + +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseDocument::recoverDocument( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +{ + // for the moment, just delegate this to our "load" method + ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); + + // our load implementation expects the SalvagedFile and URL to be in the media descriptor + aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile ); + aMediaDescriptor.put( "URL", i_SourceLocation ); + + load( aMediaDescriptor.getPropertyValues() ); +} + // ----------------------------------------------------------------------------- // XModel sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException) @@ -594,6 +614,16 @@ void SAL_CALL ODatabaseDocument::connectController( const Reference< XController { DocumentGuard aGuard( *this ); +#if OSL_DEBUG_LEVEL > 0 + for ( Controllers::const_iterator controller = m_aControllers.begin(); + controller != m_aControllers.end(); + ++controller + ) + { + OSL_ENSURE( *controller != _xController, "ODatabaseDocument::connectController: this controller is already connected!" ); + } +#endif + m_aControllers.push_back( _xController ); m_aEventNotifier.notifyDocumentEventAsync( "OnViewCreated", Reference< XController2 >( _xController, UNO_QUERY ) ); diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 3430a60e037d..8cdccc3561f7 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -60,11 +60,12 @@ #include #include #include +#include /** === end UNO includes === **/ -#if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_16) -#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_16 -#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 16 +#if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17) +#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17 +#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 17 #include #endif @@ -143,7 +144,7 @@ private: //============================================================ //= ODatabaseDocument //============================================================ -typedef ::comphelper::WeakComponentImplHelper16 < ::com::sun::star::frame::XModel2 +typedef ::comphelper::WeakComponentImplHelper17 < ::com::sun::star::frame::XModel2 , ::com::sun::star::util::XModifiable , ::com::sun::star::frame::XStorable , ::com::sun::star::document::XEventBroadcaster @@ -159,6 +160,7 @@ typedef ::comphelper::WeakComponentImplHelper16 < ::com::sun::star::frame::XMo , ::com::sun::star::script::provider::XScriptProviderSupplier , ::com::sun::star::document::XEventsSupplier , ::com::sun::star::frame::XLoadable + , ::com::sun::star::document::XDocumentRecovery > ODatabaseDocument_OfficeDocument; typedef ::cppu::ImplHelper3< ::com::sun::star::frame::XTitle @@ -425,6 +427,10 @@ public: virtual void SAL_CALL initNew( ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL load( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + // css.document.XDocumentRecovery + virtual void SAL_CALL doEmergencySave( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + virtual void SAL_CALL recoverDocument( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + // XTitle virtual ::rtl::OUString SAL_CALL getTitle( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setTitle( const ::rtl::OUString& sTitle ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx index 7310c2ca10ec..7f6b8286f03d 100644 --- a/dbaccess/source/filter/xml/dbloader2.cxx +++ b/dbaccess/source/filter/xml/dbloader2.cxx @@ -547,22 +547,20 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const :: } } - Reference< XController2 > xController; if ( bSuccess ) { try { Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW ); - xController = xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ); + Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_QUERY_THROW ); - bSuccess = xController.is(); - if ( bSuccess ) - { - xController->attachModel( xModel ); - rFrame->setComponent( xController->getComponentWindow(), xController.get() ); - xController->attachFrame( rFrame ); - xModel->setCurrentController( xController.get() ); - } + xController->attachModel( xModel ); + xModel->connectController( xController.get() ); + rFrame->setComponent( xController->getComponentWindow(), xController.get() ); + xController->attachFrame( rFrame ); + xModel->setCurrentController( xController.get() ); + + bSuccess = sal_True; } catch( const Exception& ) { diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index b87b7706d87f..91efd04e5daa 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -534,7 +534,8 @@ void SAL_CALL OApplicationController::disposing() } } - m_aModelConnector.clear(); + m_xModel->disconnectController( this ); + m_xModel.clear(); } } @@ -614,7 +615,6 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr else if ( _rSource.Source == m_xModel ) { m_xModel.clear(); - m_aModelConnector.clear(); } else if ( _rSource.Source == m_xDataSource ) { @@ -2675,7 +2675,7 @@ Reference< XModel > SAL_CALL OApplicationController::getModel(void) throw( Runt } // ----------------------------------------------------------------------------- -void OApplicationController::onConnectedModel() +void OApplicationController::onAttachedFrame() { sal_Int32 nConnectedControllers( 0 ); try @@ -2704,9 +2704,15 @@ void OApplicationController::onConnectedModel() // ----------------------------------------------------------------------------- IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ ) { + ::osl::MutexGuard aGuard( getMutex() ); + + if ( !m_xModel.is() ) + { + OSL_ENSURE( false, "OApplicationController::OnFirstControllerConnected: too late!" ); + } + // if we have forms or reports which contain macros/scripts, then show a warning // which suggests the user to migrate them to the database document - Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); if ( xDocumentScripts.is() ) { @@ -2751,6 +2757,14 @@ IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ ) return 1L; } +// ----------------------------------------------------------------------------- +void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException ) +{ + OApplicationController_CBASE::attachFrame( i_rxFrame ); + if ( getFrame().is() ) + onAttachedFrame(); +} + // ----------------------------------------------------------------------------- sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException ) { @@ -2767,16 +2781,13 @@ sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > // at least: remove as property change listener from the old model/data source m_xModel = _rxModel; - if ( _rxModel.is() ) + if ( m_xModel.is() ) { m_xDocumentModify.set( m_xModel, UNO_QUERY_THROW ); - m_aModelConnector.connect( _rxModel, this ); - onConnectedModel(); } else { m_xDocumentModify.clear(); - m_aModelConnector.clear(); } m_xDataSource.set(xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference(),UNO_QUERY); diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx index 96ca58d6f428..669eb181d3e3 100644 --- a/dbaccess/source/ui/app/AppController.hxx +++ b/dbaccess/source/ui/app/AppController.hxx @@ -35,7 +35,6 @@ #include "AppElementType.hxx" #include "callbacks.hxx" #include "commontypes.hxx" -#include "documentcontroller.hxx" #include "dsntypes.hxx" #include "genericcontroller.hxx" #include "linkeddocuments.hxx" @@ -123,8 +122,6 @@ namespace dbaui ::cppu::OInterfaceContainerHelper m_aContextMenuInterceptors; - ModelControllerConnector - m_aModelConnector; TContainerVector m_aCurrentContainers; // the containers where we are listener on ::rtl::Reference< SubComponentManager > m_pSubComponentManager; @@ -396,12 +393,12 @@ namespace dbaui */ void showPreviewFor( const ElementType _eType,const ::rtl::OUString& _sName ); - /** called when we just connected to a new, non-NULL model + /** called we were attached to a frame In particular, this is called *after* the controller has been announced to the model (XModel::connectController) */ - void onConnectedModel(); + void onAttachedFrame(); /// determines whether the given table name denotes a view which can be altered bool impl_isAlterableView_nothrow( const ::rtl::OUString& _rTableOrViewName ) const; @@ -455,6 +452,7 @@ namespace dbaui SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); // ::com::sun::star::frame::XController + virtual void SAL_CALL attachFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & xFrame) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException ); virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel(void) throw( ::com::sun::star::uno::RuntimeException ); diff --git a/dbaccess/source/ui/browser/dataview.cxx b/dbaccess/source/ui/browser/dataview.cxx index 538925125425..a66f6ec6d11a 100644 --- a/dbaccess/source/ui/browser/dataview.cxx +++ b/dbaccess/source/ui/browser/dataview.cxx @@ -40,6 +40,7 @@ #ifndef _COMPHELPER_TYPES_HXX_ #include #endif +#include #ifndef _SFXAPP_HXX //autogen wg. SFX_APP #include #endif @@ -61,6 +62,7 @@ #ifndef _SVTOOLS_IMGDEF_HXX #include #endif +#include //......................................................................... namespace dbaui @@ -221,6 +223,27 @@ namespace dbaui // Check if we need to get new images for normal/high contrast mode m_rController.notifyHiContrastChanged(); } + + if ( nType == STATE_CHANGE_INITSHOW ) + { + // now that there's a view which is finally visible, remove the "Hidden" value from the + // model's arguments. + try + { + Reference< XController > xController( m_rController.getXController(), UNO_SET_THROW ); + Reference< XModel > xModel( xController->getModel(), UNO_QUERY ); + if ( xModel.is() ) + { + ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); + aArgs.remove( "Hidden" ); + xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } } // ----------------------------------------------------------------------------- void ODataView::DataChanged( const DataChangedEvent& rDCEvt ) diff --git a/dbaccess/source/ui/misc/documentcontroller.cxx b/dbaccess/source/ui/misc/documentcontroller.cxx deleted file mode 100644 index 523307d55013..000000000000 --- a/dbaccess/source/ui/misc/documentcontroller.cxx +++ /dev/null @@ -1,150 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: documentcontroller.cxx,v $ - * $Revision: 1.5.178.4 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_dbaccess.hxx" - -#include "documentcontroller.hxx" - -/** === begin UNO includes === **/ -/** === end UNO includes === **/ - -#include -#include - -//........................................................................ -namespace dbaui -{ -//........................................................................ - - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::frame; - - //==================================================================== - //= ModelControllerConnector - //==================================================================== - DBG_NAME( ModelControllerConnector ) - //-------------------------------------------------------------------- - ModelControllerConnector::ModelControllerConnector() - { - DBG_CTOR( ModelControllerConnector, NULL ); - } - - //-------------------------------------------------------------------- - ModelControllerConnector::ModelControllerConnector( const Reference< XModel >& _rxModel, const Reference< XController >& _rxController ) - :m_xModel( _rxModel ) - ,m_xController( _rxController ) - { - DBG_CTOR( ModelControllerConnector, NULL ); - DBG_ASSERT( _rxModel.is() && m_xController.is(), "ModelControllerConnector::ModelControllerConnector: invalid model or controller!" ); - impl_connect(); - } - - //-------------------------------------------------------------------- - ModelControllerConnector::ModelControllerConnector( const ModelControllerConnector& _rSource ) - { - DBG_CTOR( ModelControllerConnector, NULL ); - impl_copyFrom( _rSource ); - } - - //-------------------------------------------------------------------- - ModelControllerConnector& ModelControllerConnector::operator=( const ModelControllerConnector& _rSource ) - { - if ( this != &_rSource ) - impl_copyFrom( _rSource ); - return *this; - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::connect( const Reference< XModel >& _rxModel, const Reference< XController >& _rxController ) - { - impl_disconnect(); - - m_xModel = _rxModel; - m_xController = _rxController; - - impl_connect(); - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::impl_copyFrom( const ModelControllerConnector& _rSource ) - { - Model aNewModel( _rSource.m_xModel ); - Controller aNewController( _rSource.m_xController ); - - impl_disconnect(); - - m_xModel = aNewModel; - m_xController = aNewController; - - impl_connect(); - } - - //-------------------------------------------------------------------- - ModelControllerConnector::~ModelControllerConnector() - { - impl_disconnect(); - DBG_DTOR( ModelControllerConnector, NULL ); - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::impl_connect() - { - try - { - Reference< XModel > xModel = m_xModel; - if ( xModel.is() && m_xController.is() ) - xModel->connectController( m_xController ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::impl_disconnect() - { - try - { - Reference< XModel > xModel = m_xModel; - if ( xModel.is() && m_xController.is() ) - xModel->disconnectController( m_xController ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - -//........................................................................ -} // namespace dbaui -//........................................................................ - diff --git a/dbaccess/source/ui/misc/makefile.mk b/dbaccess/source/ui/misc/makefile.mk index e5db6954ea4d..f0d2ad133fff 100644 --- a/dbaccess/source/ui/misc/makefile.mk +++ b/dbaccess/source/ui/misc/makefile.mk @@ -76,7 +76,6 @@ SLOFILES= \ $(SLO)$/WColumnSelect.obj \ $(SLO)$/WExtendPages.obj \ $(SLO)$/WNameMatch.obj \ - $(SLO)$/documentcontroller.obj \ $(SLO)$/ToolBoxHelper.obj \ $(SLO)$/stringlistitem.obj \ $(SLO)$/charsets.obj \ -- cgit From dabdaa680073a58380c02ababcbb2c1464b51ab5 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 6 Jan 2010 21:34:53 +0100 Subject: autorecovery: allow creating SFX-based documents which do not support the XDocumentRecovery interface For this purpose, the SFX document factory methods got an additional parameter respectively flag ("DocumentRecoverySupport" resp. SFXMODEL_DISABLE_DOCUMENT_RECOVERY). This flag is used by database documents to remove the interface from sub documents (aka forms/reports). In this course, some of the functionality around those SFXMODELL_* flags, previously duplicated in all applications, has been consolidated into a new SfxObjectShell constructor. --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 8a4cff9624ae..4ed7a5130dc2 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1630,6 +1630,10 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC // tell the embedded object to have (or not have) script support aEmbeddedDescriptor.put( "EmbeddedScriptSupport", (sal_Bool)objectSupportsEmbeddedScripts() ); + // ......................................................................... + // tell the embedded object to not participate in the document recovery game - the DB doc will handle it + aEmbeddedDescriptor.put( "DocumentRecoverySupport", (sal_Bool)sal_False ); + // ......................................................................... // pass the descriptor of the embedded object to the caller aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor; -- cgit From 79958d9c6f51986ff07248d91106d929720ce625 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 7 Jan 2010 09:06:53 +0100 Subject: enable hierachical queries --- dbaccess/source/core/api/RowSet.cxx | 4 ++-- dbaccess/source/core/api/query.cxx | 10 ++++---- dbaccess/source/ui/browser/dsEntriesNoExp.cxx | 8 ++++++- dbaccess/source/ui/browser/unodatbr.cxx | 34 +++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 10 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index bb500ac94ad2..937bcbe82f37 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -1904,8 +1904,8 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi if(!xColumn.is()) { // no column found so we could look at the position i - bReFetchName = sal_True; - sColumnLabel = ::rtl::OUString(); + //bReFetchName = sal_True; + //sColumnLabel = ::rtl::OUString(); Reference xIndexAccess(m_xColumns,UNO_QUERY); if(xIndexAccess.is() && i <= xIndexAccess->getCount()) { diff --git a/dbaccess/source/core/api/query.cxx b/dbaccess/source/core/api/query.cxx index ccd91f2a312e..3f3ccc57db2e 100644 --- a/dbaccess/source/core/api/query.cxx +++ b/dbaccess/source/core/api/query.cxx @@ -239,11 +239,11 @@ void OQuery::rebuildColumns() Sequence< ::rtl::OUString> aNames = xColumns->getElementNames(); Sequence< ::rtl::OUString> aDefintionNames; bool bApplyDefinitionNames = false; - if ( xColumnDefinitions.is() ) - { - aDefintionNames = xColumnDefinitions->getElementNames(); - bApplyDefinitionNames = aDefintionNames.getLength() == aNames.getLength(); - } + //if ( xColumnDefinitions.is() ) + //{ + // aDefintionNames = xColumnDefinitions->getElementNames(); + // bApplyDefinitionNames = aDefintionNames.getLength() == aNames.getLength(); + //} ::rtl::OUString sEmpty; const ::rtl::OUString* pIter = aNames.getConstArray(); diff --git a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx index 2af41d70cc13..6e522dd293f0 100644 --- a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx +++ b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx @@ -126,8 +126,14 @@ SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* return etQuery; } + while( pEntryParent != pQueries ) + { + pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent); + if ( !pEntryParent ) + return etUnknown; + } - return etUnknown; + return etQueryContainer; } //------------------------------------------------------------------------------ void SbaTableQueryBrowser::select(SvLBoxEntry* _pEntry, sal_Bool _bSelect) diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index 8377edda3017..5b32eff98d25 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -1109,8 +1109,38 @@ SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataS ::rtl::OUString sPath = sCommand.getToken( 0, '/', nIndex ); pObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, pCommandType); pCommandType = pObject; - if (_bExpandAncestors && nIndex >= 0 ) - m_pTreeView->getListBox().Expand(pCommandType); + if ( nIndex >= 0 ) + { + if (ensureEntryObject(pObject)) + { + DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( pObject->GetUserData() ); + Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY ); + sal_Int32 nIndex2 = nIndex; + sPath = sCommand.getToken( 0, '/', nIndex2 ); + try + { + if ( xCollection->hasByName(sPath) ) + { + if(!m_pTreeView->getListBox().GetEntryPosByName(sPath,pObject)) + { + Reference xChild(xCollection->getByName(sPath),UNO_QUERY); + DBTreeListUserData* pEntryData = new DBTreeListUserData; + pEntryData->eType = etQuery; + if ( xChild.is() ) + { + pEntryData->eType = etQueryContainer; + } + implAppendEntry( pObject, sPath, pEntryData, pEntryData->eType ); + } + } + } + catch(Exception&) + { + DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree"); + } + } + } + // m_pTreeView->getListBox().Expand(pCommandType); } while ( nIndex >= 0 ); } -- cgit From 8921236168eb7468d55b0961ac0a43c0e1b420ca Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 7 Jan 2010 13:00:10 +0100 Subject: dba33e: #i108037# disable column control when more than 1 is selected --- dbaccess/source/ui/misc/WTypeSelect.cxx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/misc/WTypeSelect.cxx b/dbaccess/source/ui/misc/WTypeSelect.cxx index a964b0e13d38..2d2d6e5ed241 100644 --- a/dbaccess/source/ui/misc/WTypeSelect.cxx +++ b/dbaccess/source/ui/misc/WTypeSelect.cxx @@ -323,6 +323,8 @@ IMPL_LINK( OWizTypeSelect, ColumnSelectHdl, MultiListBox *, /*pListBox*/ ) OFieldDescription* pField = static_cast(m_lbColumnNames.GetEntryData(m_lbColumnNames.GetEntryPos(aColumnName))); if(pField) m_aTypeControl.DisplayData(pField); + + m_aTypeControl.Enable(m_lbColumnNames.GetSelectEntryCount() == 1 ); return 0; } // ----------------------------------------------------------------------- -- cgit From f0ac9ba83791cfd168dbb0c87ac72098fad98b57 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 7 Jan 2010 15:12:22 +0100 Subject: dba33e: #i107782# erase leading spaces --- dbaccess/source/ui/misc/HtmlReader.cxx | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/misc/HtmlReader.cxx b/dbaccess/source/ui/misc/HtmlReader.cxx index b95423b77c24..b5733d0bebe5 100644 --- a/dbaccess/source/ui/misc/HtmlReader.cxx +++ b/dbaccess/source/ui/misc/HtmlReader.cxx @@ -509,6 +509,8 @@ sal_Bool OHTMLReader::CreateTable(int nToken) else if ( m_sCurrent.Len() ) aColumnName = m_sCurrent; + aColumnName.EraseLeadingChars(); + aColumnName.EraseTrailingChars(); CreateDefaultColumn(aColumnName); aColumnName.Erase(); m_sCurrent.Erase(); @@ -553,6 +555,8 @@ sal_Bool OHTMLReader::CreateTable(int nToken) if ( m_sCurrent.Len() ) aColumnName = m_sCurrent; + aColumnName.EraseLeadingChars(); + aColumnName.EraseTrailingChars(); if(aColumnName.Len()) CreateDefaultColumn(aColumnName); -- cgit From b2cb11ec544a9441234cbc5424dc4f36a9e84048 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Fri, 8 Jan 2010 08:41:34 +0100 Subject: dba33e: #i107654# handle functionname as well --- dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 1b468b2a69c9..16fd0a9211ef 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -757,11 +757,22 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes bool bInternational = ( nPass % 2 ) == 0; ::rtl::OUString sSql; - sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")); if ( bQuote ) sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), _sFieldName ); else sSql += _sFieldName; + + if ( _pEntry->isAggreateFunction() ) + { + DBG_ASSERT(_pEntry->GetFunction().getLength(),"Functionname darf hier nicht leer sein! ;-("); + ::rtl::OUStringBuffer aTmpStr2( _pEntry->GetFunction()); + aTmpStr2.appendAscii("("); + aTmpStr2.append(sSql); + aTmpStr2.appendAscii(")"); + sSql = aTmpStr2.makeStringAndClear(); + } + + sSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")) + sSql; if ( sFieldAlias.getLength() ) { // always quote the alias name there canbe no function in it sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")); -- cgit From 58519fbb7255ca48701d3850f4038ca549e29b27 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Fri, 8 Jan 2010 10:16:37 +0100 Subject: dba33e: #i108092# when value is null set NAN --- dbaccess/source/core/misc/DatabaseDataProvider.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/misc/DatabaseDataProvider.cxx b/dbaccess/source/core/misc/DatabaseDataProvider.cxx index b6aff3db3240..2cb2b29f8e87 100644 --- a/dbaccess/source/core/misc/DatabaseDataProvider.cxx +++ b/dbaccess/source/core/misc/DatabaseDataProvider.cxx @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -633,7 +634,14 @@ void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCat for (sal_Int32 j = _bHasCategories ? 2 : 1,i = 0; j <= nCount; ++j,++i) { aValue.fill(j,aColumnTypes[j-1],xRow); - aRow.push_back(aValue.getDouble()); + if ( aValue.isNull() ) + { + double nValue; + ::rtl::math::setNan( &nValue ); + aRow.push_back(nValue); + } + else + aRow.push_back(aValue.getDouble()); } // for (sal_Int32 j = 2,i = 0; j <= nCount; ++j,++i) aDataValues.push_back(aRow); } // while( xRes->next() && (!m_RowLimit || nRowCount < m_RowLimit) ) -- cgit From d3a4501c36c893751070c20e5a6462261269668b Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Fri, 8 Jan 2010 11:02:32 +0100 Subject: dba33e: #i108128# check if default driver is available --- dbaccess/source/ui/dlg/DbAdminImpl.cxx | 9 +++++++-- dbaccess/source/ui/dlg/DbAdminImpl.hxx | 1 + dbaccess/source/ui/dlg/dbwizsetup.cxx | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx index dd7e736240ec..fd62eba4ff5f 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx @@ -355,6 +355,11 @@ void ODbDataSourceAdministrationHelper::clearPassword() } // ----------------------------------------------------------------------------- Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver() +{ + return getDriver(getConnectionURL()); +} +// ----------------------------------------------------------------------------- +Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver(const ::rtl::OUString& _sURL) { // get the global DriverManager Reference< XDriverAccess > xDriverManager; @@ -376,11 +381,11 @@ Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver() throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any()); - Reference< XDriver > xDriver = xDriverManager->getDriverByURL(getConnectionURL()); + Reference< XDriver > xDriver = xDriverManager->getDriverByURL(_sURL); if (!xDriver.is()) { sCurrentActionError = String(ModuleRes(STR_NOREGISTEREDDRIVER)); - sCurrentActionError.SearchAndReplaceAscii("#connurl#", getConnectionURL()); + sCurrentActionError.SearchAndReplaceAscii("#connurl#", _sURL); // will be caught and translated into an SQLContext exception throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any()); } diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.hxx b/dbaccess/source/ui/dlg/DbAdminImpl.hxx index a194ebc7b23c..6c64363a1623 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.hxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.hxx @@ -140,6 +140,7 @@ namespace dbaui /** return the corresponding driver for the selected URL */ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver(); + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver(const ::rtl::OUString& _sURL); /** returns the data source the dialog is currently working with */ diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index bab1dcca3694..ced0640b928c 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -945,7 +945,7 @@ sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() { ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase(); ::connectivity::DriversConfig aDriverConfig(getORB()); - if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() ) + if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || m_pImpl->getDriver(sEmbeddedURL).is() ) sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); return sEmbeddedURL; -- cgit From ff9e369da43eaa1c89f846122943ab2c46b13c25 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 12 Jan 2010 23:32:12 +0100 Subject: autorecovery: initial implementation of a new save/recovery for database documents For the moment, the document only stores and loads itself, as before. In this course, the AutoRecovery service now delegates the decision whether or not a document needs to be stored (to the "salvage location") to the document itself, using the new method XDocumentRecovery::wasModifiedSinceLastSave, superseded the previous E_MODIFIED_SINCE_LAST_AUTOSAVE flag. XDocumentRecovery::wasModifiedSinceLastSave has been implemented for SfxBaseModel, yielding the same behavior as before. It has also been implemented for database documents, where the implementation is somewhat "sloppy", in that it returns always when any of the opened sub components of the document is modified. --- .../source/core/dataaccess/databasedocument.cxx | 132 ++++++++++++++++++++- .../source/core/dataaccess/databasedocument.hxx | 5 +- 2 files changed, 129 insertions(+), 8 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index eacc009d9bb5..36c5fbe2eb80 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -60,6 +60,8 @@ #include #include #include +#include +#include /** === end UNO includes === **/ #include @@ -110,6 +112,8 @@ using namespace ::cppu; using namespace ::osl; using ::com::sun::star::awt::XWindow; +using ::com::sun::star::ucb::XContent; +using ::com::sun::star::sdb::application::XDatabaseDocumentUI; //........................................................................ namespace dbaccess @@ -537,23 +541,139 @@ void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Argumen } // ----------------------------------------------------------------------------- -void SAL_CALL ODatabaseDocument::doEmergencySave( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +namespace { - // for the moment, just delegate this to our "storeToURL" method - storeToURL( i_TargetLocation, i_MediaDescriptor ); + // ......................................................................... + const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() + { + static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); + return s_sRecDataStorName; + } + + // ......................................................................... + bool lcl_hasAnyModifiedSubComponent_throw( const Reference< XController >& i_rController ) + { + Reference< XDatabaseDocumentUI > xDatabaseUI( i_rController, UNO_QUERY_THROW ); + Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); + + typedef ::std::vector< Reference< XComponent > > Components; + Components aSubComponents( aComponents.getLength() ); + ::std::copy( aComponents.getConstArray(), aComponents.getConstArray() + aComponents.getLength(), aSubComponents.begin() ); + + bool isAnyModified = false; + for ( Components::const_iterator comp = aSubComponents.begin(); + !isAnyModified && ( comp != aSubComponents.end() ); + ++comp + ) + { + Reference< XModifiable > xModify( *comp, UNO_QUERY ); + if ( xModify.is() ) + { + isAnyModified = xModify->isModified(); + continue; + } + + // TODO: clarify: anything else to care for? Both the sub componbents with and without model + // should support the XModifiable interface, so I think nothing more is needed here. + OSL_ENSURE( false, "lcl_hasAnyModifiedSubComponent_throw: anything left to do here?" ); + } + + return isAnyModified; + } } // ----------------------------------------------------------------------------- -void SAL_CALL ODatabaseDocument::recoverDocument( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +::sal_Bool SAL_CALL ODatabaseDocument::wasModifiedSinceLastSave() throw ( RuntimeException ) { - // for the moment, just delegate this to our "load" method - ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); + DocumentGuard aGuard( *this ); + + // The implementation here is somewhat sloppy, in that it returns whether *any* part of the whole + // database document, including opened sub components, is modified. This is more that what is requested: + // We need to return if the doc itself, or any of the opened sub components, has been modified + // since the last call to any of the save* methods, or since the document has been loaded/created. + // However, the API definition explicitly allows to be that sloppy ... + + if ( isModified() ) + return sal_True; + + // auto recovery is an "UI feature", it is to restore the UI the user knows. Thus, + // we ask our connected controllers, not simply our existing form/report definitions. + // (There is some information which even cannot be obtained without asking the controller. + // For instance, newly created, but not yet saved, forms/reports are acessible via the + // controller only, but not via the model.) + + try + { + for ( Controllers::const_iterator ctrl = m_aControllers.begin(); + ctrl != m_aControllers.end(); + ++ctrl + ) + { + if ( lcl_hasAnyModifiedSubComponent_throw( *ctrl ) ) + return sal_True; + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return sal_False; +} + +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseDocument::saveToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +{ + DocumentGuard aGuard( *this ); + ModifyLock aLock( *this ); + + try + { + // create a storage for the target location + Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( i_TargetLocation ) ); + + // first store the document as a whole into this storage + impl_storeToStorage_throw( xTargetStorage, i_MediaDescriptor, aGuard ); + + // create a sub storage for recovery data + if ( xTargetStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + xTargetStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + Reference< XStorage > xRecoveryStorage = xTargetStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); + + // store recovery data for open sub components of our controller(s) + // TODO + + // commit the root storage + ODatabaseModelImpl::commitStorageIfWriteable( xTargetStorage ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + ) + { + // allowed to leave + throw; + } + + throw WrappedTargetException( ::rtl::OUString(), *this, aError ); + } +} + +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +{ + // delegate this to our "load" method, to load the database document itself // our load implementation expects the SalvagedFile and URL to be in the media descriptor + ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile ); aMediaDescriptor.put( "URL", i_SourceLocation ); load( aMediaDescriptor.getPropertyValues() ); + + // TODO: recover any things in the "recovery" sub folder of the storage } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 8cdccc3561f7..db6c71114c18 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -428,8 +428,9 @@ public: virtual void SAL_CALL load( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); // css.document.XDocumentRecovery - virtual void SAL_CALL doEmergencySave( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); - virtual void SAL_CALL recoverDocument( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + virtual ::sal_Bool SAL_CALL wasModifiedSinceLastSave() throw ( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL saveToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + virtual void SAL_CALL recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); // XTitle virtual ::rtl::OUString SAL_CALL getTitle( ) throw (::com::sun::star::uno::RuntimeException); -- cgit From 3e8eb23621c5ee4ed9c2d7052f6682d0fbc1e0e0 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 13 Jan 2010 15:46:51 +0100 Subject: autorecovery: save open/modified (Writer-based) reports and forms, when doing a session/emergency save Still, the documents are stored only, and not loaded. For storing, there's at least one known issue: The controller is unable to deliver the proper object name for a form which has been newly created, and then saved. In this case, an empty name (from the time where the form was created) will be returned, and used in the save process. --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 45 +-- dbaccess/source/core/dataaccess/ModelImpl.hxx | 10 - .../source/core/dataaccess/databasedocument.cxx | 37 +- dbaccess/source/core/dataaccess/dbdocrecovery.cxx | 374 +++++++++++++++++++++ dbaccess/source/core/dataaccess/dbdocrecovery.hxx | 75 +++++ dbaccess/source/core/dataaccess/makefile.mk | 3 +- dbaccess/source/core/inc/sdbcoretools.hxx | 26 ++ dbaccess/source/core/misc/sdbcoretools.cxx | 43 ++- dbaccess/source/ui/app/AppController.hxx | 1 + dbaccess/source/ui/app/AppControllerGen.cxx | 24 ++ dbaccess/source/ui/app/subcomponentmanager.cxx | 28 ++ dbaccess/source/ui/app/subcomponentmanager.hxx | 18 + 12 files changed, 607 insertions(+), 77 deletions(-) create mode 100644 dbaccess/source/core/dataaccess/dbdocrecovery.cxx create mode 100644 dbaccess/source/core/dataaccess/dbdocrecovery.hxx (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 755f8f717d25..ed071e0b01a7 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -41,6 +41,7 @@ #include "dbastrings.hrc" #include "ModelImpl.hxx" #include "userinformation.hxx" +#include "sdbcoretools.hxx" /** === begin UNO includes === **/ #include @@ -299,7 +300,7 @@ void DocumentStorageAccess::commitStorages() SAL_THROW(( IOException, RuntimeExc ++aIter ) { - m_pModelImplementation->commitStorageIfWriteable( aIter->second ); + tools::stor::commitStorageIfWriteable( aIter->second ); } } catch(const WrappedTargetException&) @@ -320,7 +321,7 @@ bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits ) { NamedStorages::const_iterator pos = m_aExposedStorages.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "database" ) ) ); if ( pos != m_aExposedStorages.end() ) - bSuccess = m_pModelImplementation->commitStorageIfWriteable( pos->second ); + bSuccess = tools::stor::commitStorageIfWriteable( pos->second ); } catch( Exception& ) { @@ -952,49 +953,13 @@ bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits ) return getDocumentStorageAccess()->commitEmbeddedStorage( _bPreventRootCommits ); } -// ----------------------------------------------------------------------------- -namespace -{ - bool lcl_storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage ) - { - if ( !_rxStorage.is() ) - return false; - - sal_Int32 nMode = ElementModes::READ; - try - { - Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW ); - xStorageProps->getPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - return ( nMode & ElementModes::WRITE ) != 0; - } -} - -// ----------------------------------------------------------------------------- -bool ODatabaseModelImpl::commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException )) -{ - bool bSuccess = false; - Reference xTrans( _rxStorage, UNO_QUERY ); - if ( xTrans.is() ) - { - if ( lcl_storageIsWritable_nothrow( _rxStorage ) ) - xTrans->commit(); - bSuccess = true; - } - return bSuccess; -} // ----------------------------------------------------------------------------- bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(()) { bool bSuccess = false; try { - bSuccess = commitStorageIfWriteable( _rxStorage ); + bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage ); } catch( const Exception& ) { @@ -1346,7 +1311,7 @@ Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Refe lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() ); lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() ); - m_bReadOnly = !lcl_storageIsWritable_nothrow( m_xDocumentStorage.getTyped() ); + m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() ); // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property return m_xDocumentStorage.getTyped(); diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx index f9b38be569af..8697bf1abdc3 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.hxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx @@ -325,16 +325,6 @@ public: /// commits our storage void commitRootStorage(); - /// commits a given storage if it's not readonly - static bool commitStorageIfWriteable( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage - ) - SAL_THROW(( - ::com::sun::star::io::IOException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException - )); - /// commits a given storage if it's not readonly, ignoring (but asserting) all errors static bool commitStorageIfWriteable_ignoreErrors( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 36c5fbe2eb80..46921a583c98 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -41,6 +41,7 @@ #include "databasecontext.hxx" #include "documentcontainer.hxx" #include "sdbcoretools.hxx" +#include "dbdocrecovery.hxx" /** === begin UNO includes === **/ #include @@ -543,30 +544,19 @@ void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Argumen // ----------------------------------------------------------------------------- namespace { - // ......................................................................... - const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() - { - static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); - return s_sRecDataStorName; - } - // ......................................................................... bool lcl_hasAnyModifiedSubComponent_throw( const Reference< XController >& i_rController ) { Reference< XDatabaseDocumentUI > xDatabaseUI( i_rController, UNO_QUERY_THROW ); - Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); - typedef ::std::vector< Reference< XComponent > > Components; - Components aSubComponents( aComponents.getLength() ); - ::std::copy( aComponents.getConstArray(), aComponents.getConstArray() + aComponents.getLength(), aSubComponents.begin() ); + Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); + const Reference< XComponent >* component = aComponents.getConstArray(); + const Reference< XComponent >* componentsEnd = aComponents.getConstArray() + aComponents.getLength(); bool isAnyModified = false; - for ( Components::const_iterator comp = aSubComponents.begin(); - !isAnyModified && ( comp != aSubComponents.end() ); - ++comp - ) + for ( ; component != componentsEnd; ++component ) { - Reference< XModifiable > xModify( *comp, UNO_QUERY ); + Reference< XModifiable > xModify( *component, UNO_QUERY ); if ( xModify.is() ) { isAnyModified = xModify->isModified(); @@ -635,22 +625,19 @@ void SAL_CALL ODatabaseDocument::saveToRecoveryFile( const ::rtl::OUString& i_Ta // first store the document as a whole into this storage impl_storeToStorage_throw( xTargetStorage, i_MediaDescriptor, aGuard ); - // create a sub storage for recovery data - if ( xTargetStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) - xTargetStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); - Reference< XStorage > xRecoveryStorage = xTargetStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); - - // store recovery data for open sub components of our controller(s) - // TODO + // save the sub components which need saving + DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext, xTargetStorage ); + aDocRecovery.saveModifiedSubComponents( m_aControllers ); // commit the root storage - ODatabaseModelImpl::commitStorageIfWriteable( xTargetStorage ); + tools::stor::commitStorageIfWriteable( xTargetStorage ); } catch( const Exception& ) { Any aError = ::cppu::getCaughtException(); if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< WrappedTargetException >::get() ) ) { // allowed to leave @@ -1076,7 +1063,7 @@ void ODatabaseDocument::impl_storeToStorage_throw( const Reference< XStorage >& lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, false ); // commit target storage - OSL_VERIFY( ODatabaseModelImpl::commitStorageIfWriteable( _rxTargetStorage ) ); + OSL_VERIFY( tools::stor::commitStorageIfWriteable( _rxTargetStorage ) ); } catch( const IOException& ) { throw; } catch( const RuntimeException& ) { throw; } diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx new file mode 100644 index 000000000000..890998486424 --- /dev/null +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx @@ -0,0 +1,374 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "dbdocrecovery.hxx" +#include "sdbcoretools.hxx" + +/** === begin UNO includes === **/ +#include +#include +#include +#include +#include +#include +/** === end UNO includes === **/ + +#include +#include +#include +#include + +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::frame::XController; + using ::com::sun::star::sdb::application::XDatabaseDocumentUI; + using ::com::sun::star::frame::XModuleManager; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::document::XStorageBasedDocument; + using ::com::sun::star::beans::PropertyValue; + using ::com::sun::star::beans::Pair; + using ::com::sun::star::io::XStream; + using ::com::sun::star::io::XOutputStream; + using ::com::sun::star::io::XTextOutputStream; + using ::com::sun::star::io::XActiveDataSource; + /** === end UNO using === **/ + + namespace ElementModes = ::com::sun::star::embed::ElementModes; + + //==================================================================== + //= MapStringToString + //==================================================================== + typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash > MapStringToString; + + //==================================================================== + //= helpers + //==================================================================== + namespace + { + // ......................................................................... + const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() + { + static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); + return s_sRecDataStorName; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getFormsStorageName() + { + static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); + return s_sFormsStorageName; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getReportsStorageName() + { + static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); + return s_sReportsStorageName; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getObjectMapStreamName() + { + static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); + return s_sObjectMapStreamName; + } + + // ......................................................................... + enum SubComponentType + { + WRITER_FORM, + WRITER_REPORT, + SRB_REPORT, + TABLE_DESIGN, + QUERY_DESIGN, + TABLE_DATA_VIEW, + RELATION_DESIGN, + + UNKNOWN + }; + + // ......................................................................... + SubComponentType lcl_identifyComponent_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XComponent >& i_rComponent ) + { + Reference< XModuleManager > xModuleManager( i_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); + const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( i_rComponent ); + + struct ComponentTypeMapping + { + const sal_Char* pAsciiModuleName; + SubComponentType eComponentType; + }; + const ComponentTypeMapping aKnownCompTypes[] = + { + { "com.sun.star.sdb.FormDesign", WRITER_FORM }, + { "com.sun.star.sdb.TextReportDesign", WRITER_REPORT }, + { "com.sun.star.report.ReportDefinition", WRITER_REPORT }, + { "com.sun.star.sdb.TableDesign", TABLE_DESIGN }, + { "com.sun.star.sdb.QueryDesign", QUERY_DESIGN }, + { "com.sun.star.sdb.TableDataView", TABLE_DATA_VIEW }, + { "com.sun.star.sdb.RelationDesign", RELATION_DESIGN } + }; + + for ( size_t i=0; i < sizeof( aKnownCompTypes ) / sizeof( aKnownCompTypes[0] ); ++i ) + { + if ( sModuleIdentifier.equalsAscii( aKnownCompTypes[i].pAsciiModuleName ) ) + return aKnownCompTypes[i].eComponentType; + } + + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OStringBuffer message; + message.append( "lcl_identifyComponent_throw: unknown module identifier: '" ); + message.append( ::rtl::OUStringToOString( sModuleIdentifier, RTL_TEXTENCODING_ASCII_US ) ); + message.append( "'" ); + OSL_ENSURE( false, message.makeStringAndClear().getStr() ); + #endif + return UNKNOWN; + } + + // ......................................................................... + void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + const MapStringToString& i_mapStorageToObjectName ) + { + if ( i_mapStorageToObjectName.empty() ) + // nothing to do + return; + + ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); + Reference< XStream > xIniStream( i_rStorage->openStreamElement( + lcl_getObjectMapStreamName(), ElementModes::WRITE | ElementModes::TRUNCATE ), UNO_SET_THROW ); + + Reference< XTextOutputStream > xTextOutput( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); + xTextOutput->setEncoding( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "utf-8" ) ) ); + + Reference< XActiveDataSource > xDataSource( xTextOutput, UNO_QUERY_THROW ); + xDataSource->setOutputStream( xIniStream->getOutputStream() ); + + const ::rtl::OUString sLineFeed( sal_Unicode( '\n' ) ); + xTextOutput->writeString( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); + xTextOutput->writeString( sLineFeed ); + + for ( MapStringToString::const_iterator stor = i_mapStorageToObjectName.begin(); + stor != i_mapStorageToObjectName.end(); + ++stor + ) + { + ::rtl::OUStringBuffer aLine; + aLine.append( stor->first ); + aLine.append( sal_Unicode( '=' ) ); + aLine.append( stor->second ); + aLine.append( sLineFeed ); + xTextOutput->writeString( aLine.makeStringAndClear() ); + } + + xTextOutput->writeString( sLineFeed ); + } + } + + //==================================================================== + //= DatabaseDocumentRecovery_Data + //==================================================================== + struct DatabaseDocumentRecovery_Data + { + const ::comphelper::ComponentContext aContext; + const Reference< XStorage > xDocSalvageStorage; + + DatabaseDocumentRecovery_Data( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rDocumentSalvageStorage ) + :aContext( i_rContext ) + ,xDocSalvageStorage( i_rDocumentSalvageStorage ) + { + } + }; + + //==================================================================== + //= SubComponentRecovery + //==================================================================== + class SubComponentRecovery + { + public: + SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XDatabaseDocumentUI >& i_rController, + const Reference< XComponent >& i_rComponent ) + :m_rContext( i_rContext ) + ,m_xComponent( i_rComponent ) + { + ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); + + // retrieve the name of the object to which the component belongs to + Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = i_rController->identifySubComponent( i_rComponent ); + m_sObjectName = aComponentIdentity.Second; + } + + void saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapStringToString& io_mapStorageToObjectName ); + + private: + void impl_saveWriterSubComponent_throw( + const SubComponentType i_eType, + const Reference< XStorage >& i_rRecoveryStorage, + MapStringToString& io_mapStorageToObjectName + ); + + private: + const ::comphelper::ComponentContext& m_rContext; + const Reference< XComponent > m_xComponent; + ::rtl::OUString m_sObjectName; + }; + + //-------------------------------------------------------------------- + void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapStringToString& io_mapStorageToObjectName ) + { + SubComponentType eComponentType = lcl_identifyComponent_throw( m_rContext, m_xComponent ); + if ( eComponentType == UNKNOWN ) + // quite fatal, but has already been reported as assertion in lcl_identifyComponent_throw + return; + + switch ( eComponentType ) + { + case WRITER_FORM: + case WRITER_REPORT: + impl_saveWriterSubComponent_throw( eComponentType, i_rRecoveryStorage, io_mapStorageToObjectName ); + break; + + default: + // TODO + OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); + break; + } + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveWriterSubComponent_throw( const SubComponentType i_eType, const Reference< XStorage >& i_rRecoveryStorage, + MapStringToString& io_mapStorageToObjectName ) + { + ENSURE_OR_THROW( ( i_eType == WRITER_FORM ) || ( i_eType == WRITER_REPORT ), "illegal sub component type" ); + ENSURE_OR_THROW( i_rRecoveryStorage.is(), "illegal storage" ); + + // open the sub storage for the given kind of documents + const ::rtl::OUString& rStorageName( i_eType == WRITER_FORM ? lcl_getFormsStorageName() : lcl_getReportsStorageName() ); + const Reference< XStorage > xDocsStor( i_rRecoveryStorage->openStorageElement( rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // find a free sub storage name, and create Yet Another Sub Storage + const ::rtl::OUString sBaseName( ::rtl::OUString::createFromAscii( i_eType == WRITER_FORM ? "form" : "report" ) ); + const ::rtl::OUString sCompStorName = ::dbtools::createUniqueName( xDocsStor.get(), sBaseName, true ); + const Reference< XStorage > xCompStor( xDocsStor->openStorageElement( sCompStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // store the document into the storage + Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); + xStorageDocument->storeToStorage( xCompStor, Sequence< PropertyValue >() ); + + // remember the map from the component name to the storage name + ::rtl::OUStringBuffer aSubStoragePath; + aSubStoragePath.append( rStorageName ); + aSubStoragePath.append( sal_Unicode( '/' ) ); + aSubStoragePath.append( sCompStorName ); + const ::rtl::OUString sSubStoragePath = aSubStoragePath.makeStringAndClear(); + + OSL_ENSURE( io_mapStorageToObjectName.find( sSubStoragePath ) == io_mapStorageToObjectName.end(), + "SubComponentRecoverys::impl_saveWriterSubComponent_throw: object name already used!" ); + io_mapStorageToObjectName[ sSubStoragePath ] = m_sObjectName; + + // commit the storage for the documents collection + tools::stor::commitStorageIfWriteable( xDocsStor ); + } + + //==================================================================== + //= DatabaseDocumentRecovery + //==================================================================== + //-------------------------------------------------------------------- + DatabaseDocumentRecovery::DatabaseDocumentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rDocumentSalvageStorage ) + :m_pData( new DatabaseDocumentRecovery_Data( i_rContext, i_rDocumentSalvageStorage ) ) + { + ENSURE_OR_THROW( m_pData->xDocSalvageStorage.is(), "invalid document storage" ); + } + + //-------------------------------------------------------------------- + DatabaseDocumentRecovery::~DatabaseDocumentRecovery() + { + } + + //-------------------------------------------------------------------- + void DatabaseDocumentRecovery::saveModifiedSubComponents( const ::std::vector< Reference< XController > >& i_rControllers ) + { + // create a sub storage for recovery data + if ( m_pData->xDocSalvageStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + m_pData->xDocSalvageStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + Reference< XStorage > xRecoveryStorage = m_pData->xDocSalvageStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); + + // store recovery data for open sub components of the given controller(s) + if ( !i_rControllers.empty() ) + { + ENSURE_OR_THROW( i_rControllers.size() == 1, "can't handle more than one controller" ); + // At the moment, there can be only one view to a database document. If we ever allow for more than this, + // then we need a concept for sub documents opened from different controllers (i.e. two document views, + // and the user opens the very same form in both views). And depending on this, we need a concept for + // how those are saved to the recovery file. + + MapStringToString aMapStorageToObjectName; + + for ( ::std::vector< Reference< XController > >::const_iterator ctrl = i_rControllers.begin(); + ctrl != i_rControllers.end(); + ++ctrl + ) + { + Reference< XDatabaseDocumentUI > xDatabaseUI( *ctrl, UNO_QUERY_THROW ); + Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); + + const Reference< XComponent >* component = aComponents.getConstArray(); + const Reference< XComponent >* componentEnd = aComponents.getConstArray() + aComponents.getLength(); + for ( ; component != componentEnd; ++component ) + { + SubComponentRecovery aComponentRecovery( m_pData->aContext, xDatabaseUI, *component ); + aComponentRecovery.saveToRecoveryStorage( xRecoveryStorage, aMapStorageToObjectName ); + } + } + + lcl_writeObjectMap_throw( m_pData->aContext, xRecoveryStorage, aMapStorageToObjectName ); + } + + // commit the recovery storage + tools::stor::commitStorageIfWriteable( xRecoveryStorage ); + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.hxx b/dbaccess/source/core/dataaccess/dbdocrecovery.hxx new file mode 100644 index 000000000000..0fa4fb62758e --- /dev/null +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.hxx @@ -0,0 +1,75 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef DBACCESS_DBDOCRECOVERY_HXX +#define DBACCESS_DBDOCRECOVERY_HXX + +/** === begin UNO includes === **/ +#include +#include +/** === end UNO includes === **/ + +#include +#include + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= DatabaseDocumentRecovery + //==================================================================== + struct DatabaseDocumentRecovery_Data; + class DatabaseDocumentRecovery + { + public: + DatabaseDocumentRecovery( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rDocumentSalvageStorage + ); + ~DatabaseDocumentRecovery(); + + /** saves the modified sub components of the given controller(s) to the "recovery" sub storage of the document + storage. + */ + void saveModifiedSubComponents( + const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > >& i_rControllers + ); + + private: + const ::std::auto_ptr< DatabaseDocumentRecovery_Data > m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // DBACCESS_DBDOCRECOVERY_HXX diff --git a/dbaccess/source/core/dataaccess/makefile.mk b/dbaccess/source/core/dataaccess/makefile.mk index 580d62c08e55..f74188527c6f 100644 --- a/dbaccess/source/core/dataaccess/makefile.mk +++ b/dbaccess/source/core/dataaccess/makefile.mk @@ -64,7 +64,8 @@ SLOFILES= \ $(SLO)$/ModelImpl.obj \ $(SLO)$/documentevents.obj \ $(SLO)$/documenteventexecutor.obj \ - $(SLO)$/documenteventnotifier.obj + $(SLO)$/documenteventnotifier.obj \ + $(SLO)$/dbdocrecovery.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/inc/sdbcoretools.hxx b/dbaccess/source/core/inc/sdbcoretools.hxx index 92a163b3d24e..5e5315d128e0 100644 --- a/dbaccess/source/core/inc/sdbcoretools.hxx +++ b/dbaccess/source/core/inc/sdbcoretools.hxx @@ -31,8 +31,14 @@ #ifndef DBACORE_SDBCORETOOLS_HXX #define DBACORE_SDBCORETOOLS_HXX +/** === begin UNO includes === **/ #include #include +#include +#include +#include +#include +/** === end UNO includes === **/ namespace comphelper { @@ -77,6 +83,26 @@ namespace dbaccess */ ::rtl::OUString extractExceptionMessage( const ::comphelper::ComponentContext& _rContext, const ::com::sun::star::uno::Any& _rError ); + namespace tools + { + namespace stor + { + bool storageIsWritable_nothrow( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage + ); + + /// commits a given storage if it's not readonly + bool commitStorageIfWriteable( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage + ) + SAL_THROW(( + ::com::sun::star::io::IOException, + ::com::sun::star::lang::WrappedTargetException + )); + } + + } + //......................................................................... } // namespace dbaccess //......................................................................... diff --git a/dbaccess/source/core/misc/sdbcoretools.cxx b/dbaccess/source/core/misc/sdbcoretools.cxx index 48e08b7ff7e4..1854aa9efc9a 100644 --- a/dbaccess/source/core/misc/sdbcoretools.cxx +++ b/dbaccess/source/core/misc/sdbcoretools.cxx @@ -41,6 +41,8 @@ #include #include #include +#include +#include /** === end UNO includes === **/ #include @@ -58,10 +60,12 @@ namespace dbaccess using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::util; + using namespace ::com::sun::star::io; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::task; + using namespace ::com::sun::star::embed; using namespace ::com::sun::star::container; // ========================================================================= @@ -163,7 +167,44 @@ namespace dbaccess return sDisplayMessage; } -// ----------------------------------------------------------------------------- + namespace tools { namespace stor { + + // ----------------------------------------------------------------------------- + bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage ) + { + if ( !_rxStorage.is() ) + return false; + + sal_Int32 nMode = ElementModes::READ; + try + { + Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW ); + xStorageProps->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return ( nMode & ElementModes::WRITE ) != 0; + } + + // ----------------------------------------------------------------------------- + bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException )) + { + bool bSuccess = false; + Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY ); + if ( xTrans.is() ) + { + if ( storageIsWritable_nothrow( _rxStorage ) ) + xTrans->commit(); + bSuccess = true; + } + return bSuccess; + } + + } } // tools::stor + //......................................................................... } // namespace dbaccess //......................................................................... diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx index 97cc490411fd..27c6f3827adf 100644 --- a/dbaccess/source/ui/app/AppController.hxx +++ b/dbaccess/source/ui/app/AppController.hxx @@ -463,6 +463,7 @@ namespace dbaui virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > > SAL_CALL getSubComponents() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL connect( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL identifySubComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& SubComponent ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL closeSubComponents( ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponent( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponentWithArguments( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index a0f61642dbf0..5c9f66bd724b 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -90,6 +90,7 @@ namespace dbaui using namespace ::dbtools; using namespace ::connectivity; using namespace ::svx; +using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt; using namespace ::com::sun::star::util; @@ -107,6 +108,7 @@ using namespace ::com::sun::star::ucb; using ::com::sun::star::util::XCloseable; using ::com::sun::star::ui::XContextMenuInterceptor; /** === end UNO using === **/ + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition; @@ -385,6 +387,8 @@ Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() // ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( getMutex() ); + SQLExceptionInfo aError; SharedConnection xConnection = ensureConnection( &aError ); if ( !xConnection.is() ) @@ -399,9 +403,29 @@ void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeEx } } +// ----------------------------------------------------------------------------- +beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent ) throw (IllegalArgumentException, RuntimeException) +{ + ::osl::MutexGuard aGuard( getMutex() ); + + sal_Int32 nType = -1; + ::rtl::OUString sName; + + if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + + if ( nType == SID_DB_APP_DSRELDESIGN ) + // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such + // value for the relation design. /me thinks we should change the API definition here ... + nType = -1; + + return beans::Pair< ::sal_Int32, ::rtl::OUString >( nType, sName ); +} + // ----------------------------------------------------------------------------- ::sal_Bool SAL_CALL OApplicationController::closeSubComponents( ) throw (RuntimeException) { + ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->closeSubComponents(); } diff --git a/dbaccess/source/ui/app/subcomponentmanager.cxx b/dbaccess/source/ui/app/subcomponentmanager.cxx index a24fe29b5974..b2f7dab42958 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.cxx +++ b/dbaccess/source/ui/app/subcomponentmanager.cxx @@ -525,6 +525,34 @@ namespace dbaui return true; } + // ----------------------------------------------------------------------------- + bool SubComponentManager::lookupSubComponent( const Reference< XComponent >& i_rComponent, + ::rtl::OUString& o_rName, sal_Int32& o_rComponentType ) + { + for ( SubComponentMap::const_iterator comp = m_pData->m_aComponents.begin(); + comp != m_pData->m_aComponents.end(); + ++comp + ) + { + if ( ( comp->second.xModel.is() + && ( comp->second.xModel == i_rComponent ) + ) + || ( comp->second.xController.is() + && ( comp->second.xController == i_rComponent ) + ) + || ( comp->second.xFrame.is() + && ( comp->second.xFrame == i_rComponent ) + ) + ) + { + o_rName = comp->first.sName; + o_rComponentType = comp->first.nComponentType; + return true; + } + } + return false; + } + //........................................................................ } // namespace dbaui //........................................................................ diff --git a/dbaccess/source/ui/app/subcomponentmanager.hxx b/dbaccess/source/ui/app/subcomponentmanager.hxx index fbcdf92d4bd9..85984c8e0d14 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.hxx +++ b/dbaccess/source/ui/app/subcomponentmanager.hxx @@ -106,6 +106,24 @@ namespace dbaui const ::rtl::OUString& _rName, const sal_Int32 _nComponentType ); + + /** searches for the given sub component + + @param i_rComponent + the sub component to look up + @param o_rName + contains, upon successful return, the name of the sub component + @param o_nComponentType + contains, upon successful return, the type of the sub component + @return + if and only if the component was found + */ + bool lookupSubComponent( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rComponent, + ::rtl::OUString& o_rName, + sal_Int32& o_rComponentType + ); + private: ::std::auto_ptr< SubComponentManager_Data > m_pData; }; -- cgit From 9eba5bf7b80bd791ef9a7c0af69d6c3c9bebec80 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 14 Jan 2010 12:14:15 +0100 Subject: dba33d: #i108312# check for other function type and pasre only the first child of the condition --- dbaccess/source/ui/querydesign/QueryDesignView.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index f8f2170da555..f85928cb6805 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -712,7 +712,7 @@ namespace // if we have a none numeric field, the table alias could be in the name // otherwise we are not allowed to do this (e.g. 0.1 * PRICE ) - if ( !pEntryField->isNumeric() ) + if ( !pEntryField->isOtherFunction() ) { // we have to look if we have alias.* here but before we have to check if the column doesn't already exist String sTemp = rFieldName; @@ -1226,7 +1226,7 @@ namespace if (pParseNode.get()) { ::rtl::OUString sGroupBy; - pParseNode->parseNodeToStr( sGroupBy, + pParseNode->getChild(0)->parseNodeToStr( sGroupBy, xConnection, &rController.getParser().getContext(), sal_False, -- cgit From f620348c7bf0c66d0247009cc17214b703ef7a10 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 14 Jan 2010 15:10:17 +0100 Subject: autorecovery: initial glue code for recovering forms/reports --- .../source/core/dataaccess/databasedocument.cxx | 54 ++- .../source/core/dataaccess/databasedocument.hxx | 1 + dbaccess/source/core/dataaccess/dbdocrecovery.cxx | 493 ++++++++++++++++----- dbaccess/source/core/dataaccess/dbdocrecovery.hxx | 19 +- .../source/core/dataaccess/documentcontainer.cxx | 26 +- .../source/core/dataaccess/documentdefinition.cxx | 2 +- 6 files changed, 446 insertions(+), 149 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 46921a583c98..7a234d2ce646 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -173,6 +173,7 @@ ODatabaseDocument::ODatabaseDocument(const ::rtl::Reference& ,m_eInitState( NotInitialized ) ,m_bClosing( false ) ,m_bAllowDocumentScripting( false ) + ,m_bHasBeenRecovered( false ) { DBG_CTOR(ODatabaseDocument,NULL); OSL_TRACE( "DD: ctor: %p: %p", this, m_pImpl.get() ); @@ -626,8 +627,8 @@ void SAL_CALL ODatabaseDocument::saveToRecoveryFile( const ::rtl::OUString& i_Ta impl_storeToStorage_throw( xTargetStorage, i_MediaDescriptor, aGuard ); // save the sub components which need saving - DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext, xTargetStorage ); - aDocRecovery.saveModifiedSubComponents( m_aControllers ); + DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext); + aDocRecovery.saveModifiedSubComponents( xTargetStorage, m_aControllers ); // commit the root storage tools::stor::commitStorageIfWriteable( xTargetStorage ); @@ -651,16 +652,37 @@ void SAL_CALL ODatabaseDocument::saveToRecoveryFile( const ::rtl::OUString& i_Ta // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) { - // delegate this to our "load" method, to load the database document itself + DocumentGuard aGuard( *this, DocumentGuard::InitMethod ); + try + { + // load the document itself, by simply delegating to our "load" method + + // our load implementation expects the SalvagedFile and URL to be in the media descriptor + ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); + aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile ); + aMediaDescriptor.put( "URL", i_SourceLocation ); - // our load implementation expects the SalvagedFile and URL to be in the media descriptor - ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); - aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile ); - aMediaDescriptor.put( "URL", i_SourceLocation ); + aGuard.clear(); // (load has an own guarding scheme) + load( aMediaDescriptor.getPropertyValues() ); - load( aMediaDescriptor.getPropertyValues() ); + // Without a controller, we are unable to recover the sub components, as they're always tied to a controller. + // So, everything else is done when the first controller is connected. + m_bHasBeenRecovered = true; + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< WrappedTargetException >::get() ) + ) + { + // allowed to leave + throw; + } - // TODO: recover any things in the "recovery" sub folder of the storage + throw WrappedTargetException( ::rtl::OUString(), *this, aError ); + } } // ----------------------------------------------------------------------------- @@ -739,6 +761,20 @@ void SAL_CALL ODatabaseDocument::connectController( const Reference< XController // check/adjust our macro mode. m_pImpl->checkMacrosOnLoading(); + + // check if there are sub components to recover from our document storage + if ( !m_bHasBeenRecovered ) + return; + + try + { + DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext ); + aDocRecovery.recoverSubDocuments( m_pImpl->getRootStorage(), _xController ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index db6c71114c18..446a344dfebc 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -209,6 +209,7 @@ class ODatabaseDocument :public ModelDependentComponent // ModelDepe InitState m_eInitState; bool m_bClosing; bool m_bAllowDocumentScripting; + bool m_bHasBeenRecovered; enum StoreType { SAVE, SAVE_AS }; /** stores the document to the given URL, rebases it to the respective new storage, if necessary, resets diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx index 890998486424..6ab664d7600d 100644 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx @@ -34,7 +34,10 @@ #include #include #include +#include #include +#include +#include /** === end UNO includes === **/ #include @@ -73,14 +76,12 @@ namespace dbaccess using ::com::sun::star::io::XOutputStream; using ::com::sun::star::io::XTextOutputStream; using ::com::sun::star::io::XActiveDataSource; + using ::com::sun::star::io::XTextInputStream; + using ::com::sun::star::io::XActiveDataSink; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; - - //==================================================================== - //= MapStringToString - //==================================================================== - typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash > MapStringToString; + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; //==================================================================== //= helpers @@ -88,90 +89,143 @@ namespace dbaccess namespace { // ......................................................................... - const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() + enum SubComponentType { - static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); - return s_sRecDataStorName; - } + TABLE = DatabaseObject::TABLE, + QUERY = DatabaseObject::QUERY, + FORM = DatabaseObject::FORM, + REPORT = DatabaseObject::REPORT, + + RELATION_DESIGN = 1000, + + UNKNOWN = 10001 + }; + + struct SubComponentDescriptor + { + ::rtl::OUString sName; + bool bForEditing; + + SubComponentDescriptor() + :sName() + ,bForEditing( false ) + { + } + + SubComponentDescriptor( const ::rtl::OUString& i_rName, const bool i_bForEditing ) + :sName( i_rName ) + ,bForEditing( i_bForEditing ) + { + } + }; + + // ......................................................................... + typedef ::std::hash_map< ::rtl::OUString, SubComponentDescriptor, ::rtl::OUStringHash > MapStringToCompDesc; + typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; // ......................................................................... - const ::rtl::OUString& lcl_getFormsStorageName() + void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) { - static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); - return s_sFormsStorageName; + o_rBuffer.append( i_rComponentDesc.first ); + o_rBuffer.append( sal_Unicode( '=' ) ); + o_rBuffer.append( i_rComponentDesc.second.sName ); + o_rBuffer.append( sal_Unicode( ',' ) ); + o_rBuffer.append( sal_Unicode( i_rComponentDesc.second.bForEditing ? '1' : '0' ) ); } // ......................................................................... - const ::rtl::OUString& lcl_getReportsStorageName() + bool lcl_extractCompDesc( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rStorName, SubComponentDescriptor& o_rCompDesc ) { - static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); - return s_sReportsStorageName; + const sal_Int32 nEqualSignPos = i_rIniLine.indexOf( sal_Unicode( '=' ) ); + if ( nEqualSignPos < 1 ) + { + OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of '='" ); + return false; + } + o_rStorName = i_rIniLine.copy( 0, nEqualSignPos ); + + const sal_Int32 nCommaPos = i_rIniLine.lastIndexOf( sal_Unicode( ',' ) ); + if ( nCommaPos != i_rIniLine.getLength() - 2 ) + { + OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of ','" ); + return false; + } + o_rCompDesc.sName = i_rIniLine.copy( nEqualSignPos + 1, nCommaPos - nEqualSignPos - 1 ); + o_rCompDesc.bForEditing = ( i_rIniLine.getStr()[ nCommaPos + 1 ] == '1' ); + return true; } // ......................................................................... - const ::rtl::OUString& lcl_getObjectMapStreamName() + SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) { - static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); - return s_sObjectMapStreamName; + switch ( i_nObjectType ) + { + case DatabaseObject::TABLE: return TABLE; + case DatabaseObject::QUERY: return QUERY; + case DatabaseObject::FORM: return FORM; + case DatabaseObject::REPORT:return REPORT; + default: + break; + } + return UNKNOWN; } // ......................................................................... - enum SubComponentType + const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() { - WRITER_FORM, - WRITER_REPORT, - SRB_REPORT, - TABLE_DESIGN, - QUERY_DESIGN, - TABLE_DATA_VIEW, - RELATION_DESIGN, - - UNKNOWN - }; + static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); + return s_sRecDataStorName; + } // ......................................................................... - SubComponentType lcl_identifyComponent_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XComponent >& i_rComponent ) + const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) { - Reference< XModuleManager > xModuleManager( i_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); - const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( i_rComponent ); + static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); + static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); + static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) ); + static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) ); + static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) ); - struct ComponentTypeMapping - { - const sal_Char* pAsciiModuleName; - SubComponentType eComponentType; - }; - const ComponentTypeMapping aKnownCompTypes[] = + switch ( i_eType ) { - { "com.sun.star.sdb.FormDesign", WRITER_FORM }, - { "com.sun.star.sdb.TextReportDesign", WRITER_REPORT }, - { "com.sun.star.report.ReportDefinition", WRITER_REPORT }, - { "com.sun.star.sdb.TableDesign", TABLE_DESIGN }, - { "com.sun.star.sdb.QueryDesign", QUERY_DESIGN }, - { "com.sun.star.sdb.TableDataView", TABLE_DATA_VIEW }, - { "com.sun.star.sdb.RelationDesign", RELATION_DESIGN } - }; - - for ( size_t i=0; i < sizeof( aKnownCompTypes ) / sizeof( aKnownCompTypes[0] ); ++i ) - { - if ( sModuleIdentifier.equalsAscii( aKnownCompTypes[i].pAsciiModuleName ) ) - return aKnownCompTypes[i].eComponentType; + case FORM: + return s_sFormsStorageName; + case REPORT: + return s_sReportsStorageName; + case TABLE: + return s_sTablesStorageName; + case QUERY: + return s_sQueriesStorageName; + case RELATION_DESIGN: + return s_sRelationsStorageName; + default: + break; } - #if OSL_DEBUG_LEVEL > 0 - ::rtl::OStringBuffer message; - message.append( "lcl_identifyComponent_throw: unknown module identifier: '" ); - message.append( ::rtl::OUStringToOString( sModuleIdentifier, RTL_TEXTENCODING_ASCII_US ) ); - message.append( "'" ); - OSL_ENSURE( false, message.makeStringAndClear().getStr() ); - #endif - return UNKNOWN; + OSL_ENSURE( false, "lcl_getComponentsStorageName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getObjectMapStreamName() + { + static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); + return s_sObjectMapStreamName; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getMapStreamEncodingName() + { + static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); + return s_sMapStreamEncodingName; } // ......................................................................... void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, - const MapStringToString& i_mapStorageToObjectName ) + const MapStringToCompDesc& i_mapStorageToCompDesc ) { - if ( i_mapStorageToObjectName.empty() ) + if ( i_mapStorageToCompDesc.empty() ) // nothing to do return; @@ -180,7 +234,7 @@ namespace dbaccess lcl_getObjectMapStreamName(), ElementModes::WRITE | ElementModes::TRUNCATE ), UNO_SET_THROW ); Reference< XTextOutputStream > xTextOutput( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); - xTextOutput->setEncoding( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "utf-8" ) ) ); + xTextOutput->setEncoding( lcl_getMapStreamEncodingName() ); Reference< XActiveDataSource > xDataSource( xTextOutput, UNO_QUERY_THROW ); xDataSource->setOutputStream( xIniStream->getOutputStream() ); @@ -189,21 +243,94 @@ namespace dbaccess xTextOutput->writeString( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); xTextOutput->writeString( sLineFeed ); - for ( MapStringToString::const_iterator stor = i_mapStorageToObjectName.begin(); - stor != i_mapStorageToObjectName.end(); + for ( MapStringToCompDesc::const_iterator stor = i_mapStorageToCompDesc.begin(); + stor != i_mapStorageToCompDesc.end(); ++stor ) { ::rtl::OUStringBuffer aLine; - aLine.append( stor->first ); - aLine.append( sal_Unicode( '=' ) ); - aLine.append( stor->second ); + lcl_getPersistentRepresentation( *stor, aLine ); aLine.append( sLineFeed ); + xTextOutput->writeString( aLine.makeStringAndClear() ); } xTextOutput->writeString( sLineFeed ); } + + // ......................................................................... + bool lcl_isSectionStart( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rSectionName ) + { + const sal_Int32 nLen = i_rIniLine.getLength(); + if ( ( nLen > 0 ) && ( i_rIniLine.getStr()[0] == '[' ) && ( i_rIniLine.getStr()[ nLen - 1 ] == ']' ) ) + { + o_rSectionName = i_rIniLine.copy( 1, nLen -2 ); + return true; + } + return false; + } + + // ......................................................................... + void lcl_stripTrailingLineFeed( ::rtl::OUString& io_rLine ) + { + const sal_Int32 nLen = io_rLine.getLength(); + if ( ( nLen > 0 ) && ( io_rLine.getStr()[ nLen - 1 ] == '\n' ) ) + io_rLine = io_rLine.copy( 0, nLen - 1 ); + } + + // ......................................................................... + void lcl_readObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + MapStringToCompDesc& o_mapStorageToObjectName ) + { + ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); + if ( !i_rStorage->hasByName( lcl_getObjectMapStreamName() ) ) + { // nothing to do, though suspicious + OSL_ENSURE( false, "lcl_readObjectMap_throw: if there's no map file, then there's expected to be no storage, too!" ); + return; + } + + Reference< XStream > xIniStream( i_rStorage->openStreamElement( + lcl_getObjectMapStreamName(), ElementModes::READ ), UNO_SET_THROW ); + + Reference< XTextInputStream > xTextInput( i_rContext.createComponent( "com.sun.star.io.TextInputStream" ), UNO_QUERY_THROW ); + xTextInput->setEncoding( lcl_getMapStreamEncodingName() ); + + Reference< XActiveDataSink > xDataSink( xTextInput, UNO_QUERY_THROW ); + xDataSink->setInputStream( xIniStream->getInputStream() ); + + ::rtl::OUString sCurrentSection; + bool bCurrentSectionIsKnownToBeUnsupported = true; + while ( !xTextInput->isEOF() ) + { + ::rtl::OUString sLine = xTextInput->readLine(); + lcl_stripTrailingLineFeed( sLine ); + + if ( sLine.getLength() == 0 ) + continue; + + if ( lcl_isSectionStart( sLine, sCurrentSection ) ) + { + bCurrentSectionIsKnownToBeUnsupported = false; + continue; + } + + if ( bCurrentSectionIsKnownToBeUnsupported ) + continue; + + // the only section we support so far is "storages" + if ( !sCurrentSection.equalsAscii( "storages" ) ) + { + bCurrentSectionIsKnownToBeUnsupported = true; + continue; + } + + ::rtl::OUString sStorageName; + SubComponentDescriptor aCompDesc; + if ( !lcl_extractCompDesc( sLine, sStorageName, aCompDesc ) ) + continue; + o_mapStorageToObjectName[ sStorageName ] = aCompDesc; + } + } } //==================================================================== @@ -211,12 +338,10 @@ namespace dbaccess //==================================================================== struct DatabaseDocumentRecovery_Data { - const ::comphelper::ComponentContext aContext; - const Reference< XStorage > xDocSalvageStorage; + const ::comphelper::ComponentContext aContext; - DatabaseDocumentRecovery_Data( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rDocumentSalvageStorage ) + DatabaseDocumentRecovery_Data( const ::comphelper::ComponentContext& i_rContext ) :aContext( i_rContext ) - ,xDocSalvageStorage( i_rDocumentSalvageStorage ) { } }; @@ -231,42 +356,45 @@ namespace dbaccess const Reference< XComponent >& i_rComponent ) :m_rContext( i_rContext ) ,m_xComponent( i_rComponent ) + ,m_eType( UNKNOWN ) + ,m_aCompDesc() { - ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); - - // retrieve the name of the object to which the component belongs to - Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = i_rController->identifySubComponent( i_rComponent ); - m_sObjectName = aComponentIdentity.Second; + impl_identifyComponent_throw( i_rController ); } - void saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapStringToString& io_mapStorageToObjectName ); + void saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapCompTypeToCompDescs& io_mapCompDescs ); private: - void impl_saveWriterSubComponent_throw( - const SubComponentType i_eType, - const Reference< XStorage >& i_rRecoveryStorage, - MapStringToString& io_mapStorageToObjectName - ); + void impl_saveSubDocument_throw( + const Reference< XStorage >& i_rRecoveryStorage, + MapStringToCompDesc& io_mapStorageToCompDesc + ); + + void impl_identifyComponent_throw( + const Reference< XDatabaseDocumentUI >& i_rController + ); private: const ::comphelper::ComponentContext& m_rContext; const Reference< XComponent > m_xComponent; - ::rtl::OUString m_sObjectName; + SubComponentType m_eType; + SubComponentDescriptor m_aCompDesc; }; //-------------------------------------------------------------------- - void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapStringToString& io_mapStorageToObjectName ) + void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, + MapCompTypeToCompDescs& io_mapCompDescs ) { - SubComponentType eComponentType = lcl_identifyComponent_throw( m_rContext, m_xComponent ); - if ( eComponentType == UNKNOWN ) - // quite fatal, but has already been reported as assertion in lcl_identifyComponent_throw + + if ( m_eType == UNKNOWN ) + // quite fatal, but has already been reported (as assertion) before return; - switch ( eComponentType ) + switch ( m_eType ) { - case WRITER_FORM: - case WRITER_REPORT: - impl_saveWriterSubComponent_throw( eComponentType, i_rRecoveryStorage, io_mapStorageToObjectName ); + case FORM: + case REPORT: + impl_saveSubDocument_throw( i_rRecoveryStorage, io_mapCompDescs[ m_eType ] ); break; default: @@ -276,36 +404,86 @@ namespace dbaccess } } + // ......................................................................... + void SubComponentRecovery::impl_identifyComponent_throw( const Reference< XDatabaseDocumentUI >& i_rController ) + { + ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); + + // ask the controller + Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = i_rController->identifySubComponent( m_xComponent ); + m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First ); + m_aCompDesc.sName = aComponentIdentity.Second; + + // what the controller didn't give us is the information whether this is in edit mode or not ... + Reference< XModuleManager > xModuleManager( m_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); + const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent ); + + switch ( m_eType ) + { + case TABLE: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.TableDesign" ); + break; + + case QUERY: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.QueryDesign" ); + break; + + case REPORT: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.report.ReportDefinition" ) ) + { + // it's an SRB report desginer + m_aCompDesc.bForEditing = true; + break; + } + // fall through + + case FORM: + // TODO: how to know whether the thing is opened for editing? + break; + + default: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.sdb.RelationDesign" ) ) + { + m_eType = RELATION_DESIGN; + m_aCompDesc.bForEditing = true; + } + else + { + OSL_ENSURE( false, "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" ); + } + break; + } + + OSL_POSTCOND( m_eType != UNKNOWN, + "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" ); + } + //-------------------------------------------------------------------- - void SubComponentRecovery::impl_saveWriterSubComponent_throw( const SubComponentType i_eType, const Reference< XStorage >& i_rRecoveryStorage, - MapStringToString& io_mapStorageToObjectName ) + void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage, + MapStringToCompDesc& io_mapStorageToCompDesc ) { - ENSURE_OR_THROW( ( i_eType == WRITER_FORM ) || ( i_eType == WRITER_REPORT ), "illegal sub component type" ); + ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); ENSURE_OR_THROW( i_rRecoveryStorage.is(), "illegal storage" ); // open the sub storage for the given kind of documents - const ::rtl::OUString& rStorageName( i_eType == WRITER_FORM ? lcl_getFormsStorageName() : lcl_getReportsStorageName() ); - const Reference< XStorage > xDocsStor( i_rRecoveryStorage->openStorageElement( rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + const ::rtl::OUString& rStorageName( lcl_getComponentsStorageName( m_eType ) ); + const Reference< XStorage > xDocsStor( i_rRecoveryStorage->openStorageElement( + rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); // find a free sub storage name, and create Yet Another Sub Storage - const ::rtl::OUString sBaseName( ::rtl::OUString::createFromAscii( i_eType == WRITER_FORM ? "form" : "report" ) ); + const ::rtl::OUString sBaseName( ::rtl::OUString::createFromAscii( m_eType == FORM ? "form" : "report" ) ); const ::rtl::OUString sCompStorName = ::dbtools::createUniqueName( xDocsStor.get(), sBaseName, true ); - const Reference< XStorage > xCompStor( xDocsStor->openStorageElement( sCompStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + const Reference< XStorage > xCompStor( xDocsStor->openStorageElement( + sCompStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); // store the document into the storage Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); xStorageDocument->storeToStorage( xCompStor, Sequence< PropertyValue >() ); - // remember the map from the component name to the storage name - ::rtl::OUStringBuffer aSubStoragePath; - aSubStoragePath.append( rStorageName ); - aSubStoragePath.append( sal_Unicode( '/' ) ); - aSubStoragePath.append( sCompStorName ); - const ::rtl::OUString sSubStoragePath = aSubStoragePath.makeStringAndClear(); - - OSL_ENSURE( io_mapStorageToObjectName.find( sSubStoragePath ) == io_mapStorageToObjectName.end(), - "SubComponentRecoverys::impl_saveWriterSubComponent_throw: object name already used!" ); - io_mapStorageToObjectName[ sSubStoragePath ] = m_sObjectName; + // remember the relationship between the component name to the storage name + OSL_ENSURE( io_mapStorageToCompDesc.find( sCompStorName ) == io_mapStorageToCompDesc.end(), + "SubComponentRecoverys::impl_saveSubDocument_throw: object name already used!" ); + io_mapStorageToCompDesc[ sCompStorName ] = m_aCompDesc; // commit the storage for the documents collection tools::stor::commitStorageIfWriteable( xDocsStor ); @@ -315,10 +493,9 @@ namespace dbaccess //= DatabaseDocumentRecovery //==================================================================== //-------------------------------------------------------------------- - DatabaseDocumentRecovery::DatabaseDocumentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rDocumentSalvageStorage ) - :m_pData( new DatabaseDocumentRecovery_Data( i_rContext, i_rDocumentSalvageStorage ) ) + DatabaseDocumentRecovery::DatabaseDocumentRecovery( const ::comphelper::ComponentContext& i_rContext ) + :m_pData( new DatabaseDocumentRecovery_Data( i_rContext ) ) { - ENSURE_OR_THROW( m_pData->xDocSalvageStorage.is(), "invalid document storage" ); } //-------------------------------------------------------------------- @@ -327,12 +504,15 @@ namespace dbaccess } //-------------------------------------------------------------------- - void DatabaseDocumentRecovery::saveModifiedSubComponents( const ::std::vector< Reference< XController > >& i_rControllers ) + void DatabaseDocumentRecovery::saveModifiedSubComponents( const Reference< XStorage >& i_rTargetStorage, + const ::std::vector< Reference< XController > >& i_rControllers ) { + ENSURE_OR_THROW( i_rTargetStorage.is(), "invalid document storage" ); + // create a sub storage for recovery data - if ( m_pData->xDocSalvageStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) - m_pData->xDocSalvageStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); - Reference< XStorage > xRecoveryStorage = m_pData->xDocSalvageStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); + if ( i_rTargetStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + i_rTargetStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + Reference< XStorage > xRecoveryStorage = i_rTargetStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); // store recovery data for open sub components of the given controller(s) if ( !i_rControllers.empty() ) @@ -343,7 +523,7 @@ namespace dbaccess // and the user opens the very same form in both views). And depending on this, we need a concept for // how those are saved to the recovery file. - MapStringToString aMapStorageToObjectName; + MapCompTypeToCompDescs aMapCompDescs; for ( ::std::vector< Reference< XController > >::const_iterator ctrl = i_rControllers.begin(); ctrl != i_rControllers.end(); @@ -358,17 +538,94 @@ namespace dbaccess for ( ; component != componentEnd; ++component ) { SubComponentRecovery aComponentRecovery( m_pData->aContext, xDatabaseUI, *component ); - aComponentRecovery.saveToRecoveryStorage( xRecoveryStorage, aMapStorageToObjectName ); + aComponentRecovery.saveToRecoveryStorage( xRecoveryStorage, aMapCompDescs ); } } - lcl_writeObjectMap_throw( m_pData->aContext, xRecoveryStorage, aMapStorageToObjectName ); + for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); + map != aMapCompDescs.end(); + ++map + ) + { + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + lcl_getComponentsStorageName( map->first ), ElementModes::WRITE | ElementModes::NOCREATE ) ); + lcl_writeObjectMap_throw( m_pData->aContext, xComponentsStor, map->second ); + tools::stor::commitStorageIfWriteable( xComponentsStor ); + } } // commit the recovery storage tools::stor::commitStorageIfWriteable( xRecoveryStorage ); } + //-------------------------------------------------------------------- + void DatabaseDocumentRecovery::recoverSubDocuments( const Reference< XStorage >& i_rDocumentStorage, + const Reference< XController >& i_rTargetController ) + { + ENSURE_OR_THROW( i_rDocumentStorage.is(), "illegal document storage" ); + ENSURE_OR_THROW( i_rTargetController.is(), "illegal controller" ); + + if ( !i_rDocumentStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + // that's allowed + return; + + // the "recovery" sub storage + Reference< XStorage > xRecoveryStorage = i_rDocumentStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READ ); + + // read the map from sub storages to object names + MapCompTypeToCompDescs aMapCompDescs; + SubComponentType aKnownTypes[] = { TABLE, QUERY, FORM, REPORT, RELATION_DESIGN }; + for ( size_t i = 0; i < sizeof( aKnownTypes ) / sizeof( aKnownTypes[0] ); ++i ) + { + if ( !xRecoveryStorage->hasByName( lcl_getComponentsStorageName( aKnownTypes[i] ) ) ) + continue; + + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + lcl_getComponentsStorageName( aKnownTypes[i] ), ElementModes::READ ) ); + lcl_readObjectMap_throw( m_pData->aContext, xComponentsStor, aMapCompDescs[ aKnownTypes[i] ] ); + xComponentsStor->dispose(); + } + + // recover all sub components as indicated by the map + for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); + map != aMapCompDescs.end(); + ++map + ) + { + // the storage for all components of the current type + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + lcl_getComponentsStorageName( map->first ), ElementModes::READ ), UNO_QUERY_THROW ); + + // loop thru all components of this type + for ( MapStringToCompDesc::const_iterator stor = map->second.begin(); + stor != map->second.end(); + ++stor + ) + { + if ( !xComponentsStor->hasByName( stor->first ) ) + { + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OStringBuffer message; + message.append( "DatabaseDocumentRecovery::recoverSubDocuments: inconsistent recovery storage: storage '" ); + message.append( ::rtl::OUStringToOString( stor->first, RTL_TEXTENCODING_ASCII_US ) ); + message.append( "' not found in '" ); + message.append( ::rtl::OUStringToOString( lcl_getComponentsStorageName( map->first ), RTL_TEXTENCODING_ASCII_US ) ); + message.append( "', but required per map file!" ); + OSL_ENSURE( false, message.makeStringAndClear() ); + #endif + continue; + } + + // recover the single component + Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); + // TODO + xCompStor->dispose(); + } + + xComponentsStor->dispose(); + } + } + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.hxx b/dbaccess/source/core/dataaccess/dbdocrecovery.hxx index 0fa4fb62758e..0bf44e2bf3e8 100644 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.hxx +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.hxx @@ -52,18 +52,33 @@ namespace dbaccess { public: DatabaseDocumentRecovery( - const ::comphelper::ComponentContext& i_rContext, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rDocumentSalvageStorage + const ::comphelper::ComponentContext& i_rContext ); ~DatabaseDocumentRecovery(); /** saves the modified sub components of the given controller(s) to the "recovery" sub storage of the document storage. + + @throws ::com::sun::star::uno::Exception + in case of an error. */ void saveModifiedSubComponents( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rTargetStorage, const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > >& i_rControllers ); + /** recovery sub components from the given document storage, if applicable + + If the given document storage does not contain a recovery folder, the method silently returns. + + @throws ::com::sun::star::uno::Exception + in case of an error. + */ + void recoverSubDocuments( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rDocumentStorage, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rTargetController + ); + private: const ::std::auto_ptr< DatabaseDocumentRecovery_Data > m_pData; }; diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 9ba06976e555..806168ae5da3 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -85,6 +85,7 @@ #endif #include "core_resource.hxx" #include "core_resource.hrc" +#include #include #include @@ -570,28 +571,15 @@ Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const { Command aCommand; - static const ::rtl::OUString s_sOpenMode = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OpenMode")); - const PropertyValue* pIter = Arguments.getConstArray(); - const PropertyValue* pEnd = pIter + Arguments.getLength(); - for( ; pIter != pEnd ; ++pIter) - { - if ( pIter->Name == s_sOpenMode ) - { - pIter->Value >>= aCommand.Name; - break; - } - } - if ( !aCommand.Name.getLength() ) // default mode - aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("open")); + ::comphelper::NamedValueCollection aArgs( Arguments ); + aCommand.Name = aArgs.getOrDefault( "OpenMode", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ) ); + aArgs.remove( "OpenMode" ); + OpenCommandArgument2 aOpenCommand; aOpenCommand.Mode = OpenMode::DOCUMENT; + aArgs.put( "OpenCommandArgument", aOpenCommand ); - Sequence< PropertyValue > aArguments(Arguments); - sal_Int32 nLen = aArguments.getLength(); - aArguments.realloc(nLen + 1); - - aArguments[nLen].Value <<= aOpenCommand; - aCommand.Argument <<= aArguments; + aCommand.Argument <<= aArgs.getPropertyValues(); xComp.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY); } } diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 8643a455ce23..49b35a05e6af 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1689,7 +1689,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x // the com.sun.star.report.pentaho.SOReportJobFactory is not present. if ( !m_bForm && !sDocumentService.equalsAscii("com.sun.star.text.TextDocument")) { - // we seems to be a new report, check if report extension is present. + // we seem to be a "new style" report, check if report extension is present. Reference< XContentEnumerationAccess > xEnumAccess( m_aContext.getLegacyServiceFactory(), UNO_QUERY ); const ::rtl::OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_aContext.getLegacyServiceFactory()); Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName); -- cgit From 5d0d44c20399add14eb574e9b068dceaf081f686 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 15 Jan 2010 15:21:15 +0100 Subject: autorecovery: save/recover forms and reports Still some lose ends. Most notably, the current code contains cases for other sub component types, but has no real implementation - attempting to save/recover those other types will yield multiple assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's some work ahead here. Other known open issues: - recovering sub components immediately shows them, instead of initially hiding them, and showing only when the main document window is shown - the implementation currently is no real session save, which would require saving information about *unmodified* open sub components (though not their actual content), and restoring them upon recovery. - doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement to actually load the sub components, but might yield problems in case this requires interaction (e.g. a login). Need to investigate - the "recovery" storage is not removed from the database document storage after un/successful recovery - cancelling the recovery of a "modified" database document always suggests to store this doc somewhere --- dbaccess/source/core/dataaccess/dbdocrecovery.cxx | 62 +++++++++++++++++++-- .../source/core/dataaccess/documentdefinition.cxx | 65 +++++++++++++--------- .../source/core/dataaccess/documentdefinition.hxx | 27 ++++++++- 3 files changed, 121 insertions(+), 33 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx index 6ab664d7600d..9770808b98e5 100644 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx @@ -38,9 +38,11 @@ #include #include #include +#include /** === end UNO includes === **/ #include +#include #include #include #include @@ -78,6 +80,8 @@ namespace dbaccess using ::com::sun::star::io::XActiveDataSource; using ::com::sun::star::io::XTextInputStream; using ::com::sun::star::io::XActiveDataSink; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::util::XModifiable; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; @@ -331,6 +335,36 @@ namespace dbaccess o_mapStorageToObjectName[ sStorageName ] = aCompDesc; } } + + // ......................................................................... + bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) + { + Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); + if ( !xDocument.is() ) + { + Reference< XController > xController( i_rComponent, UNO_QUERY_THROW ); + xDocument = xController->getModel(); + } + + if ( !xDocument.is() ) + return false; + + ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() ); + return aDocArgs.getOrDefault( "ReadOnly", false ); + } + + // ......................................................................... + void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) + { + const Reference< XModifiable > xModify( i_rSubComponent, UNO_QUERY ); + if ( !xModify.is() ) + { + OSL_ENSURE( false, "lcl_markModified: unhandled case!" ); + return; + } + + xModify->setModified( sal_True ); + } } //==================================================================== @@ -404,7 +438,7 @@ namespace dbaccess } } - // ......................................................................... + //-------------------------------------------------------------------- void SubComponentRecovery::impl_identifyComponent_throw( const Reference< XDatabaseDocumentUI >& i_rController ) { ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); @@ -438,7 +472,7 @@ namespace dbaccess // fall through case FORM: - // TODO: how to know whether the thing is opened for editing? + m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent ); break; default: @@ -563,7 +597,7 @@ namespace dbaccess const Reference< XController >& i_rTargetController ) { ENSURE_OR_THROW( i_rDocumentStorage.is(), "illegal document storage" ); - ENSURE_OR_THROW( i_rTargetController.is(), "illegal controller" ); + Reference< XDatabaseDocumentUI > xDocumentUI( i_rTargetController, UNO_QUERY_THROW ); if ( !i_rDocumentStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) // that's allowed @@ -616,10 +650,28 @@ namespace dbaccess continue; } + // the controller needs to have a connection to be able to open sub components + if ( !xDocumentUI->isConnected() ) + xDocumentUI->connect(); + // recover the single component Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); - // TODO - xCompStor->dispose(); + + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "RecoverFromStorage", xCompStor ); + try + { + Reference< XComponent > xSubComponent = xDocumentUI->loadComponentWithArguments( map->first, stor->second.sName, stor->second.bForEditing, + aLoadArgs.getPropertyValues() ); + + // at the moment, we only store, during session save, sub components which are modified. So, set this + // recovered sub component to "modified", too. + lcl_markModified( xSubComponent ); + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } xComponentsStor->dispose(); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 49b35a05e6af..d2fb5b15c405 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1117,16 +1117,6 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co Reference< XStorage> xStorage = getContainerStorage(); // ----------------------------------------------------------------------------- xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName); - /*loadEmbeddedObject( true ); - Reference xPersist(m_xEmbeddedObject,UNO_QUERY); - if ( xPersist.is() ) - { - xPersist->storeToEntry(xStorage,sPersistentName,Sequence(),Sequence()); - xPersist->storeOwn(); - m_xEmbeddedObject->changeState(EmbedStates::LOADED); - } - else - throw CommandAbortedException();*/ } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preview" ) ) ) { @@ -1577,9 +1567,25 @@ sal_Bool ODocumentDefinition::objectSupportsEmbeddedScripts() const return lcl_determineContentType_nothrow( getContainerStorage(), m_pImpl->m_aProps.sPersistentName ); } +// ----------------------------------------------------------------------------- +void ODocumentDefinition::separateOpenCommandArguments( const Sequence< PropertyValue >& i_rOpenCommandArguments, + ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor ) +{ + ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments ); + o_rDocumentLoadArgs.merge( aOpenCommandArguments, false ); + + // the only OpenCommandArgument so far, which belongs into the EmbeddedObjectDescriptor, and not the document's + // media descriptor, is RecoverFromStorage + if ( aOpenCommandArguments.has( "RecoverFromStorage" ) ) + { + o_rEmbeddedObjectDescriptor.put( "RecoverFromStorage", aOpenCommandArguments.get( "RecoverFromStorage" ) ); + o_rDocumentLoadArgs.remove( "RecoverFromStorage" ); + } +} + // ----------------------------------------------------------------------------- Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly, - const Sequence< PropertyValue >& _rAdditionalArgs, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor ) + const Sequence< PropertyValue >& i_rOpenCommandArguments, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor ) { // ......................................................................... // (re-)create interceptor, and put it into the descriptor of the embedded object @@ -1597,6 +1603,10 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC ::comphelper::NamedValueCollection aEmbeddedDescriptor; aEmbeddedDescriptor.put( "OutplaceDispatchInterceptor", xInterceptor ); + // ......................................................................... + ::comphelper::NamedValueCollection aMediaDesc; + separateOpenCommandArguments( i_rOpenCommandArguments, aMediaDesc, aEmbeddedDescriptor ); + // ......................................................................... // create the OutplaceFrameProperties, and put them into the descriptor of the embedded object ::comphelper::NamedValueCollection OutplaceFrameProperties; @@ -1638,9 +1648,6 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC // pass the descriptor of the embedded object to the caller aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor; - // ......................................................................... - ::comphelper::NamedValueCollection aMediaDesc( _rAdditionalArgs ); - // ......................................................................... // create the ComponentData, and put it into the document's media descriptor { @@ -1663,7 +1670,7 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC } // ----------------------------------------------------------------------------- void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _xConnection, const Sequence< sal_Int8 >& _aClassID, - const Sequence< PropertyValue >& _rAdditionalArgs, const bool _bSuppressMacros, const bool _bReadOnly ) + const Sequence< PropertyValue >& i_rOpenCommandArguments, const bool _bSuppressMacros, const bool _bReadOnly ) { if ( !m_xEmbeddedObject.is() ) { @@ -1716,7 +1723,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( - _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) ); + _xConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID ,sDocumentService @@ -1761,7 +1768,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( - _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) ); + _xConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); Reference xCommon(m_xEmbeddedObject,UNO_QUERY); OSL_ENSURE(xCommon.is(),"unsupported interface!"); @@ -1778,21 +1785,25 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x // then just re-set some model parameters try { - Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW ); - Sequence< PropertyValue > aArgs = xModel->getArgs(); - - ::comphelper::NamedValueCollection aMediaDesc( aArgs ); - ::comphelper::NamedValueCollection aArguments( _rAdditionalArgs ); - aMediaDesc.merge( aArguments, sal_False ); - - lcl_putLoadArgs( aMediaDesc, optional_bool(), optional_bool() ); + // ensure the media descriptor doesn't contain any values which are intended for the + // EmbeddedObjectDescriptor only + ::comphelper::NamedValueCollection aEmbeddedObjectDescriptor; + ::comphelper::NamedValueCollection aNewMediaDesc; + separateOpenCommandArguments( i_rOpenCommandArguments, aNewMediaDesc, aEmbeddedObjectDescriptor ); + + // merge the new media descriptor into the existing media descriptor + const Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW ); + const Sequence< PropertyValue > aArgs = xModel->getArgs(); + ::comphelper::NamedValueCollection aExistentMediaDesc( aArgs ); + aExistentMediaDesc.merge( aNewMediaDesc, sal_False ); + + lcl_putLoadArgs( aExistentMediaDesc, optional_bool(), optional_bool() ); // don't put _bSuppressMacros and _bReadOnly here - if the document was already // loaded, we should not tamper with its settings. // #i88977# / 2008-05-05 / frank.schoenheit@sun.com // #i86872# / 2008-03-13 / frank.schoenheit@sun.com - aMediaDesc >>= aArgs; - xModel->attachResource( xModel->getURL(), aArgs ); + xModel->attachResource( xModel->getURL(), aExistentMediaDesc.getPropertyValues() ); } catch( const Exception& ) { diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 2d8d5f6df343..5b2c43521f6b 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -67,6 +67,11 @@ #include #include +namespace comphelper +{ + class NamedValueCollection; +} + //........................................................................ namespace dbaccess { @@ -247,10 +252,30 @@ private: const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rOpenCommandArguments, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor ); + /** splits the given arguments to an "open*" command into arguments for loading the document, and arguments to be + put into the EmbeddedObjectDescriptor + + Any values already present in o_rDocumentLoadArgs and o_rEmbeddedObjectDescriptor + will be overwritten by values from i_rOpenCommandArguments, if applicable, otherwise they will + be preserved. + + @param i_rOpenCommandArguments + the arguments passed to the "open*" command at the content + @param o_rDocumentLoadArgs + the arguments to be passed when actually loading the embedded document. + @param o_rEmbeddedObjectDescriptor + the EmbeddedObjectDescriptor to be passed when initializing the embedded object + */ + void separateOpenCommandArguments( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rOpenCommandArguments, + ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, + ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor + ); + /** loads the EmbeddedObject if not already loaded @param _aClassID If set, it will be used to create the embedded object. -- cgit From 5fa3246b0dca2bf3cf7767695436152e142ddf80 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 15 Jan 2010 15:26:50 +0100 Subject: autorecovery: throw an exception when no storage can be created, otherwise we end up with a broken document --- dbaccess/source/filter/xml/xmlfilter.cxx | 114 +++++++++++++++---------------- 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx index 4fa30ee6885d..9c0aec576b67 100644 --- a/dbaccess/source/filter/xml/xmlfilter.cxx +++ b/dbaccess/source/filter/xml/xmlfilter.cxx @@ -117,6 +117,7 @@ #endif #include #include +#include #ifndef _SV_SVAPP_HXX //autogen #include #endif @@ -133,6 +134,7 @@ #include #include #include +#include #include #include #include @@ -514,72 +516,64 @@ sal_Bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor ) SfxMediumRef pMedium = new SfxMedium( sFileName, ( STREAM_READ | STREAM_NOCREATE ), FALSE, 0 ); uno::Reference< embed::XStorage > xStorage; - if( pMedium ) + try { - try - { - xStorage = pMedium->GetStorage( sal_False ); - // nError = pMedium->GetError(); - } - catch(const Exception&) - { - } + xStorage.set( pMedium->GetStorage( sal_False ), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) ) + throw; + throw lang::WrappedTargetRuntimeException( ::rtl::OUString(), *this, aError ); } - OSL_ENSURE(xStorage.is(),"No Storage for read!"); - if ( xStorage.is() ) + uno::Reference xOfficeDoc(GetModel(),UNO_QUERY_THROW); + m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); + uno::Reference xListener = new DatasourceURLListener(getServiceFactory()); + m_xDataSource->addPropertyChangeListener(PROPERTY_URL,xListener); + uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); + SetNumberFormatsSupplier(xNum); + + uno::Reference xModel(GetModel(),UNO_QUERY); + sal_Int32 nRet = ReadThroughComponent( xStorage + ,xModel + ,"settings.xml" + ,"Settings.xml" + ,getServiceFactory() + ,this + ); + + if ( nRet == 0 ) + nRet = ReadThroughComponent( xStorage + ,xModel + ,"content.xml" + ,"Content.xml" + ,getServiceFactory() + ,this + ); + + bRet = nRet == 0; + + if ( bRet ) { - uno::Reference xOfficeDoc(GetModel(),UNO_QUERY_THROW); - m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); - uno::Reference xListener = new DatasourceURLListener(getServiceFactory()); - m_xDataSource->addPropertyChangeListener(PROPERTY_URL,xListener); - uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); - SetNumberFormatsSupplier(xNum); - - uno::Reference xModel(GetModel(),UNO_QUERY); - sal_Int32 nRet = ReadThroughComponent( xStorage - ,xModel - ,"settings.xml" - ,"Settings.xml" - ,getServiceFactory() - ,this - ); - - if ( nRet == 0 ) - nRet = ReadThroughComponent( xStorage - ,xModel - ,"content.xml" - ,"Content.xml" - ,getServiceFactory() - ,this - ); - - bRet = nRet == 0; - - if ( bRet ) - { - uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY); - if ( xModi.is() ) - xModi->setModified(sal_False); - } - else + uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY); + if ( xModi.is() ) + xModi->setModified(sal_False); + } + else + { + switch( nRet ) { - switch( nRet ) + case ERRCODE_IO_BROKENPACKAGE: + // TODO/LATER: no way to transport the error outside from the filter! + break; + default: { - case ERRCODE_IO_BROKENPACKAGE: - if( xStorage.is() ) - { - // TODO/LATER: no way to transport the error outside from the filter! - break; - } - // fall through intented - default: - { - // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way! - ErrorHandler::HandleError( nRet ); - if( nRet & ERRCODE_WARNING_MASK ) - bRet = sal_True; - } + // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way! + ErrorHandler::HandleError( nRet ); + if( nRet & ERRCODE_WARNING_MASK ) + bRet = sal_True; } } } -- cgit From a394db3e9271f66122854e4b73f96f26841012b8 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Fri, 22 Jan 2010 12:16:08 +0100 Subject: dba33e: wrong header included --- dbaccess/source/ui/app/AppController.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 5b9c4311b9be..aee402bdfab7 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -91,7 +91,7 @@ #include #include #include -#include +#include #include #include -- cgit From 74d5307270a229da2f6b2f5418ca0b95d6ea87fb Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 22 Jan 2010 22:49:50 +0100 Subject: autorecovery: #i108366# attachResource: correct the calculation of DocFileLocation and DocURL, in case the doc has been recovered. --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index ed071e0b01a7..26b078b2f4b0 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -816,19 +816,30 @@ const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormats void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArgs ) { ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs ); + ENSURE_OR_THROW( _rURL.getLength(), "invalid URL" ); - ::rtl::OUString sDocumentLocation( aMediaDescriptor.getOrDefault( "SalvagedFile", _rURL ) ); - if ( !sDocumentLocation.getLength() ) - // this indicates "the document is being recovered, but _rURL already is the real document URL, - // not the temporary document location" - sDocumentLocation = _rURL; + ::rtl::OUString sDocumentLocation( _rURL ); + ::rtl::OUString sDocumentURL( _rURL ); if ( aMediaDescriptor.has( "SalvagedFile" ) ) + { + const ::rtl::OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) ); + // If SalvagedFile is an empty string, this indicates "the document is being recovered, but _rURL already + // is the real document URL, not the temporary document location" + if ( sSalvagedFile.getLength() ) + { + // otherwise, SalvagedFile is the URL of the document which we should mimic, though we're loaded from + // the file denoted by _rURL. + sDocumentLocation = _rURL; + sDocumentURL = sSalvagedFile; + } + aMediaDescriptor.remove( "SalvagedFile" ); + } m_aArgs = stripLoadArguments( aMediaDescriptor ); - switchToURL( sDocumentLocation, _rURL ); + switchToURL( sDocumentLocation, sDocumentURL ); } // ----------------------------------------------------------------------------- -- cgit From 64b4e680a5af6677b4d8e5106fe02964fb305e4c Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 25 Jan 2010 09:56:57 +0100 Subject: autorecovery: do not remove SalvagedFile from DBDoc's args if it still carries information --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 5 ++++- dbaccess/source/core/dataaccess/databasedocument.cxx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 26b078b2f4b0..112da2d19505 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -834,7 +834,10 @@ void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Seq sDocumentURL = sSalvagedFile; } - aMediaDescriptor.remove( "SalvagedFile" ); + if ( sSalvagedFile == _rURL ) + // SalvagedFile doesn't carry any information anymore + aMediaDescriptor.remove( "SalvagedFile" ); + } m_aArgs = stripLoadArguments( aMediaDescriptor ); diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 7a234d2ce646..39afd5bf76b5 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -579,7 +579,7 @@ namespace DocumentGuard aGuard( *this ); // The implementation here is somewhat sloppy, in that it returns whether *any* part of the whole - // database document, including opened sub components, is modified. This is more that what is requested: + // database document, including opened sub components, is modified. This is more than what is requested: // We need to return if the doc itself, or any of the opened sub components, has been modified // since the last call to any of the save* methods, or since the document has been loaded/created. // However, the API definition explicitly allows to be that sloppy ... -- cgit From d9c96494bfc4f749840ad972d6dbebbeb1b29ed2 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Mon, 25 Jan 2010 13:20:09 +0100 Subject: dba33e: wrong header from svtools --- dbaccess/source/core/dataaccess/databasedocument.cxx | 2 -- 1 file changed, 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index ff57b3a82b06..862ebc664993 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -79,8 +79,6 @@ #include -#include - #include #include #include -- cgit From a2e88c92f9d23707d6aa72ecb635326f13a0d66a Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 25 Jan 2010 22:35:24 +0100 Subject: autorecovery: introduce PersistentPath property at the document definition object --- .../source/core/dataaccess/documentdefinition.cxx | 69 ++++++++++++++++------ .../source/core/dataaccess/documentdefinition.hxx | 6 ++ dbaccess/source/core/misc/dbastrings.cxx | 5 +- dbaccess/source/inc/dbastrings.hrc | 4 +- dbaccess/source/inc/stringconstants.hrc | 1 + 5 files changed, 64 insertions(+), 21 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index d2fb5b15c405..1ed214036d66 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -632,15 +632,39 @@ IMPLEMENT_SERVICE_INFO1(ODocumentDefinition,"com.sun.star.comp.dba.ODocumentDefi //-------------------------------------------------------------------------- void ODocumentDefinition::registerProperties() { - registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_pImpl->m_aProps.aTitle, ::getCppuType(&m_pImpl->m_aProps.aTitle)); - registerProperty(PROPERTY_AS_TEMPLATE, PROPERTY_ID_AS_TEMPLATE, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_pImpl->m_aProps.bAsTemplate, ::getCppuType(&m_pImpl->m_aProps.bAsTemplate)); - registerProperty(PROPERTY_PERSISTENT_NAME, PROPERTY_ID_PERSISTENT_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_pImpl->m_aProps.sPersistentName, ::getCppuType(&m_pImpl->m_aProps.sPersistentName)); - registerProperty(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm")), PROPERTY_ID_IS_FORM, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_bForm, ::getCppuType(&m_bForm)); +#define REGISTER_PROPERTY( name, location ) \ + registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::READONLY, &location, ::getCppuType( &location ) ); + +#define REGISTER_PROPERTY_BV( name, location ) \ + registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::READONLY, &location, ::getCppuType( &location ) ); + + REGISTER_PROPERTY_BV( NAME, m_pImpl->m_aProps.aTitle ); + REGISTER_PROPERTY ( AS_TEMPLATE, m_pImpl->m_aProps.bAsTemplate ); + REGISTER_PROPERTY ( PERSISTENT_NAME, m_pImpl->m_aProps.sPersistentName ); + REGISTER_PROPERTY ( IS_FORM, m_bForm ); } + +// ----------------------------------------------------------------------------- +void SAL_CALL ODocumentDefinition::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const +{ + if ( i_nHandle == PROPERTY_ID_PERSISTENT_PATH ) + { + ::rtl::OUString sPersistentPath; + if ( m_pImpl->m_aProps.sPersistentName.getLength() ) + { + ::rtl::OUStringBuffer aBuffer; + aBuffer.append( ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) ); + aBuffer.append( sal_Unicode( '/' ) ); + aBuffer.append( m_pImpl->m_aProps.sPersistentName ); + sPersistentPath = aBuffer.makeStringAndClear(); + } + o_rValue <<= sPersistentPath; + return; + } + + OPropertyStateContainer::getFastPropertyValue( o_rValue, i_nHandle ); +} + // ----------------------------------------------------------------------------- Reference< XPropertySetInfo > SAL_CALL ODocumentDefinition::getPropertySetInfo( ) throw(RuntimeException) { @@ -658,10 +682,21 @@ IPropertyArrayHelper& ODocumentDefinition::getInfoHelper() //-------------------------------------------------------------------------- IPropertyArrayHelper* ODocumentDefinition::createArrayHelper( ) const { + // properties maintained by our base class (see registerProperties) Sequence< Property > aProps; - describeProperties(aProps); - return new OPropertyArrayHelper(aProps); + describeProperties( aProps ); + + // properties not maintained by our base class + Sequence< Property > aManualProps( 1 ); + aManualProps[0].Name = PROPERTY_PERSISTENT_PATH; + aManualProps[0].Handle = PROPERTY_ID_PERSISTENT_PATH; + aManualProps[0].Type = ::getCppuType( static_cast< const ::rtl::OUString* >( NULL ) ); + aManualProps[0].Attributes = PropertyAttribute::READONLY; + + return new OPropertyArrayHelper( ::comphelper::concatSequences( aProps, aManualProps ) ); } + +// ----------------------------------------------------------------------------- class OExecuteImpl { sal_Bool& m_rbSet; @@ -669,6 +704,7 @@ public: OExecuteImpl(sal_Bool& _rbSet) : m_rbSet(_rbSet){ m_rbSet=sal_True; } ~OExecuteImpl(){ m_rbSet = sal_False; } }; + // ----------------------------------------------------------------------------- namespace { @@ -1569,18 +1605,15 @@ sal_Bool ODocumentDefinition::objectSupportsEmbeddedScripts() const // ----------------------------------------------------------------------------- void ODocumentDefinition::separateOpenCommandArguments( const Sequence< PropertyValue >& i_rOpenCommandArguments, - ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor ) + ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& /*o_rEmbeddedObjectDescriptor*/ ) { ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments ); o_rDocumentLoadArgs.merge( aOpenCommandArguments, false ); - // the only OpenCommandArgument so far, which belongs into the EmbeddedObjectDescriptor, and not the document's - // media descriptor, is RecoverFromStorage - if ( aOpenCommandArguments.has( "RecoverFromStorage" ) ) - { - o_rEmbeddedObjectDescriptor.put( "RecoverFromStorage", aOpenCommandArguments.get( "RecoverFromStorage" ) ); - o_rDocumentLoadArgs.remove( "RecoverFromStorage" ); - } + // This method is to separate OpenCommandArguments into args which belong into the EmbeddedObjectDescriptor, + // and args which belong into the document's media descriptor. + + // Well, there was some intermediate state where such args really existed - at the moment, they don't. } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 5b2c43521f6b..0c164fd2e30d 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -133,6 +133,12 @@ public: // ::com::sun::star::beans::XPropertySet virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + // OPropertySetHelper + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& o_rValue, + sal_Int32 i_nHandle + ) const; + // XComponentSupplier virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > SAL_CALL getComponent( ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/core/misc/dbastrings.cxx b/dbaccess/source/core/misc/dbastrings.cxx index 4caaa5650656..96e6d86145cf 100644 --- a/dbaccess/source/core/misc/dbastrings.cxx +++ b/dbaccess/source/core/misc/dbastrings.cxx @@ -46,6 +46,7 @@ namespace dbaccess //============================================================ //= Properties //============================================================ - IMPLEMENT_CONSTASCII_USTRING(PROPERTY_APPLYFORMDESIGNMODE, "ApplyFormDesignMode"); - + IMPLEMENT_CONSTASCII_USTRING( PROPERTY_APPLYFORMDESIGNMODE, "ApplyFormDesignMode" ); + IMPLEMENT_CONSTASCII_USTRING( PROPERTY_IS_FORM, "IsForm" ); + IMPLEMENT_CONSTASCII_USTRING( PROPERTY_PERSISTENT_PATH, "PersistentPath" ); } diff --git a/dbaccess/source/inc/dbastrings.hrc b/dbaccess/source/inc/dbastrings.hrc index 1e5eb7984046..a881bb039194 100644 --- a/dbaccess/source/inc/dbastrings.hrc +++ b/dbaccess/source/inc/dbastrings.hrc @@ -48,7 +48,9 @@ namespace dbaccess //============================================================ //= Properties //============================================================ - DECLARE_CONSTASCII_USTRING(PROPERTY_APPLYFORMDESIGNMODE); + DECLARE_CONSTASCII_USTRING( PROPERTY_APPLYFORMDESIGNMODE ); + DECLARE_CONSTASCII_USTRING( PROPERTY_IS_FORM ); + DECLARE_CONSTASCII_USTRING( PROPERTY_PERSISTENT_PATH ); } #endif // DBACCESS_SHARED_DBASTRINGS_HRC diff --git a/dbaccess/source/inc/stringconstants.hrc b/dbaccess/source/inc/stringconstants.hrc index 6a58ba1ddd0d..02bb911ef287 100644 --- a/dbaccess/source/inc/stringconstants.hrc +++ b/dbaccess/source/inc/stringconstants.hrc @@ -183,6 +183,7 @@ #define PROPERTY_ID_THOUSAND_DELIMITER 140 #define PROPERTY_ID_ENCODING 141 #define PROPERTY_ID_HELP_URL 142 +#define PROPERTY_ID_PERSISTENT_PATH 143 //============================================================ //= property names -- cgit From 84155f975046b221e626fbcbfd537b5ab9f44e0e Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 25 Jan 2010 22:36:18 +0100 Subject: autorecovery: broadcast name changes also when a newly created, formerly unnamed, doc is saved --- .../source/core/dataaccess/documentdefinition.cxx | 66 +++++++++++++++++----- .../source/core/dataaccess/documentdefinition.hxx | 31 +++++++++- dbaccess/source/ui/app/AppControllerGen.cxx | 21 ++++--- 3 files changed, 94 insertions(+), 24 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 1ed214036d66..385b4516ac93 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1397,16 +1397,16 @@ sal_Bool ODocumentDefinition::save(sal_Bool _bApprove) return sal_True; if ( pDocuSave && pDocuSave->wasSelected() ) { - ::osl::MutexGuard aGuard(m_aMutex); - Reference xNC(pDocuSave->getContent(),UNO_QUERY); - if ( xNC.is() ) - { - m_pImpl->m_aProps.aTitle = pDocuSave->getName(); - Reference< XContent> xContent = this; - xNC->insertByName(pDocuSave->getName(),makeAny(xContent)); + Reference xNC( pDocuSave->getContent(), UNO_QUERY_THROW ); - updateDocumentTitle(); - } + ::osl::ResettableMutexGuard aGuard( m_aMutex ); + NameChangeNotifier aNameChangeAndNotify( *this, pDocuSave->getName(), aGuard ); + m_pImpl->m_aProps.aTitle = pDocuSave->getName(); + + Reference< XContent> xContent = this; + xNC->insertByName(pDocuSave->getName(),makeAny(xContent)); + + updateDocumentTitle(); } } @@ -2069,7 +2069,7 @@ void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) th { try { - osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex); + ::osl::ResettableMutexGuard aGuard(m_aMutex); if ( _rNewName.equals( m_pImpl->m_aProps.aTitle ) ) return; @@ -2082,12 +2082,11 @@ void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) th Any aOld = makeAny( m_pImpl->m_aProps.aTitle ); Any aNew = makeAny( _rNewName ); - aGuard.clear(); - fire(&nHandle, &aNew, &aOld, 1, sal_True ); - m_pImpl->m_aProps.aTitle = _rNewName; - fire(&nHandle, &aNew, &aOld, 1, sal_False ); + { + NameChangeNotifier aNameChangeAndNotify( *this, _rNewName, aGuard ); + m_pImpl->m_aProps.aTitle = _rNewName; + } - ::osl::ClearableGuard< ::osl::Mutex > aGuard2( m_aMutex ); if ( m_xEmbeddedObject.is() && m_xEmbeddedObject->getCurrentState() == EmbedStates::ACTIVE ) updateDocumentTitle(); } @@ -2239,6 +2238,43 @@ void SAL_CALL ODocumentDefinition::notifyClosing( const lang::EventObject& /*Sou void SAL_CALL ODocumentDefinition::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) { } + +// ----------------------------------------------------------------------------- +void ODocumentDefinition::firePropertyChange( sal_Int32 i_nHandle, const Any& i_rNewValue, const Any& i_rOldValue, + sal_Bool i_bVetoable, const NotifierAccess ) +{ + fire( &i_nHandle, &i_rNewValue, &i_rOldValue, 1, i_bVetoable ); +} + +// ============================================================================= +// NameChangeNotifier +// ============================================================================= +// ----------------------------------------------------------------------------- +NameChangeNotifier::NameChangeNotifier( ODocumentDefinition& i_rDocumentDefinition, const ::rtl::OUString& i_rNewName, + ::osl::ResettableMutexGuard& i_rClearForNotify ) + :m_rDocumentDefinition( i_rDocumentDefinition ) + ,m_aOldValue( makeAny( i_rDocumentDefinition.getCurrentName() ) ) + ,m_aNewValue( makeAny( i_rNewName ) ) + ,m_rClearForNotify( i_rClearForNotify ) +{ + impl_fireEvent_throw( sal_True ); +} + +// ----------------------------------------------------------------------------- +NameChangeNotifier::~NameChangeNotifier() +{ + impl_fireEvent_throw( sal_False ); +} + +// ----------------------------------------------------------------------------- +void NameChangeNotifier::impl_fireEvent_throw( const sal_Bool i_bVetoable ) +{ + m_rClearForNotify.clear(); + m_rDocumentDefinition.firePropertyChange( + PROPERTY_ID_NAME, m_aNewValue, m_aOldValue, i_bVetoable, ODocumentDefinition::NotifierAccess() ); + m_rClearForNotify.reset(); +} + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 0c164fd2e30d..ab8f13bc2cec 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -201,6 +201,16 @@ public: ::com::sun::star::uno::Sequence< sal_Int8 >& _rClassId ); + struct NotifierAccess { friend class NameChangeNotifier; private: NotifierAccess() { } }; + const ::rtl::OUString& getCurrentName() const { return m_pImpl->m_aProps.aTitle; } + void firePropertyChange( + sal_Int32 i_nHandle, + const ::com::sun::star::uno::Any& i_rNewValue, + const ::com::sun::star::uno::Any& i_rOldValue, + sal_Bool i_bVetoable, + const NotifierAccess + ); + private: /** does necessary initializations after our embedded object has been switched to ACTIVE @param _bOpenedInDesignMode @@ -238,7 +248,6 @@ private: bool impl_close_throw(); -private: // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; @@ -250,7 +259,6 @@ private: // OContentHelper overridables virtual ::rtl::OUString determineContentType() const; -private: /** fills the load arguments */ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > @@ -347,6 +355,25 @@ private: ::osl::ClearableMutexGuard & _aClearableGuard); }; +class NameChangeNotifier +{ +public: + NameChangeNotifier( + ODocumentDefinition& i_rDocumentDefinition, + const ::rtl::OUString& i_rNewName, + ::osl::ResettableMutexGuard& i_rClearForNotify + ); + ~NameChangeNotifier(); + +private: + ODocumentDefinition& m_rDocumentDefinition; + const ::com::sun::star::uno::Any m_aOldValue; + const ::com::sun::star::uno::Any m_aNewValue; + mutable ::osl::ResettableMutexGuard& m_rClearForNotify; + + void impl_fireEvent_throw( const sal_Bool i_bVetoable ); +}; + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index 5c9f66bd724b..d919d1457331 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -330,15 +330,22 @@ void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& ::rtl::OUString sOldName,sNewName; evt.OldValue >>= sOldName; evt.NewValue >>= sNewName; - Reference xChild(evt.Source,UNO_QUERY); - if ( xChild.is() ) + + // if the old name is empty, then this is a newly inserted content. We're notified of it via the + // elementInserted method, so there's no need to handle it here. + + if ( sOldName.getLength() ) { - Reference xContent(xChild->getParent(),UNO_QUERY); - if ( xContent.is() ) - sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName; - } + Reference xChild(evt.Source,UNO_QUERY); + if ( xChild.is() ) + { + Reference xContent(xChild->getParent(),UNO_QUERY); + if ( xContent.is() ) + sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName; + } - getContainer()->elementReplaced( eType , sOldName, sNewName ); + getContainer()->elementReplaced( eType , sOldName, sNewName ); + } } } -- cgit From 6563b40e1486aaf51cf7d0463ada458a620d3c1f Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 25 Jan 2010 22:36:24 +0100 Subject: autorecovery: when the name of a document definition changes, update our component map --- dbaccess/source/ui/app/subcomponentmanager.cxx | 56 +++++++++++++++++++++++++- dbaccess/source/ui/app/subcomponentmanager.hxx | 7 +++- 2 files changed, 59 insertions(+), 4 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/subcomponentmanager.cxx b/dbaccess/source/ui/app/subcomponentmanager.cxx index b2f7dab42958..3456ff75e232 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.cxx +++ b/dbaccess/source/ui/app/subcomponentmanager.cxx @@ -29,6 +29,7 @@ #include "subcomponentmanager.hxx" #include "AppController.hxx" +#include "dbustrings.hrc" /** === begin UNO includes === **/ #include @@ -39,6 +40,7 @@ #include #include #include +#include /** === end UNO includes === **/ #include @@ -79,6 +81,8 @@ namespace dbaui using ::com::sun::star::ucb::XCommandProcessor; using ::com::sun::star::ucb::Command; using ::com::sun::star::document::XDocumentEventBroadcaster; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::beans::PropertyChangeEvent; /** === end UNO using === **/ //============================================================================== @@ -94,8 +98,10 @@ namespace dbaui Reference< XController > xController; /// the model of the sub component. Might be Reference< XModel > xModel; - /// the document definition which holds the component, if any - Reference< XCommandProcessor > xComponentCommandProcessor; + /// the document definition which holds the component, if any; as CommandProcessor + Reference< XCommandProcessor > xComponentCommandProcessor; + /// the document definition which holds the component, if any; as PropertySet + Reference< XPropertySet > xDocumentDefinitionProperties; SubComponentDescriptor() :xFrame() @@ -108,11 +114,14 @@ namespace dbaui { if ( !impl_constructFrom( _rxComponent ) ) { + // _rxComponent is neither a model, nor a controller, nor a frame + // => it must be a css.sdb.DocumentDefinition Reference< XComponentSupplier > xCompSupp( _rxComponent, UNO_QUERY_THROW ); Reference< XComponent > xComponent( xCompSupp->getComponent(), UNO_QUERY_THROW ); if ( !impl_constructFrom( xComponent ) ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal component type." ) ), NULL ); xComponentCommandProcessor.set( _rxComponent, UNO_QUERY_THROW ); + xDocumentDefinitionProperties.set( _rxComponent, UNO_QUERY_THROW ); } } @@ -361,6 +370,47 @@ namespace dbaui } } + //-------------------------------------------------------------------- + void SAL_CALL SubComponentManager::propertyChange( const PropertyChangeEvent& i_rEvent ) throw (RuntimeException) + { + if ( i_rEvent.PropertyName != PROPERTY_NAME ) + // by definition, it's allowed to broadcast more than what we've registered for + return; + + // find the sub component whose name changed + for ( SubComponentMap::iterator comp = m_pData->m_aComponents.begin(); + comp != m_pData->m_aComponents.end(); + ++comp + ) + { + if ( comp->second.xDocumentDefinitionProperties != i_rEvent.Source ) + continue; + + ::rtl::OUString sNewName; + OSL_VERIFY( i_rEvent.NewValue >>= sNewName ); + + ::rtl::OUString sOldKnownName( comp->first.sName ); + ::rtl::OUString sOldName; + OSL_VERIFY( i_rEvent.OldValue >>= sOldName ); + OSL_ENSURE( sOldName == sOldKnownName, "SubComponentManager::propertyChange: inconsistency in the old names!" ); + + // obtain old values + SubComponentAccessor aKey( comp->first ); + SubComponentDescriptor aElement( comp->second ); + + // remove old values + m_pData->m_aComponents.erase( comp ); + + // re-insert under new name + aKey.sName = sNewName; + m_pData->m_aComponents.insert( SubComponentMap::value_type( + aKey, aElement + ) ) ; + + break; + } + } + //-------------------------------------------------------------------- void SAL_CALL SubComponentManager::disposing( const EventObject& _rSource ) throw (RuntimeException) { @@ -480,6 +530,8 @@ namespace dbaui aElement.xController->addEventListener( this ); if ( aElement.xModel.is() ) aElement.xModel->addEventListener( this ); + if ( aElement.xDocumentDefinitionProperties.is() ) + aElement.xDocumentDefinitionProperties->addPropertyChangeListener( PROPERTY_NAME, this ); // notify this to interested parties aGuard.clear(); diff --git a/dbaccess/source/ui/app/subcomponentmanager.hxx b/dbaccess/source/ui/app/subcomponentmanager.hxx index 85984c8e0d14..372a0a211af5 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.hxx +++ b/dbaccess/source/ui/app/subcomponentmanager.hxx @@ -33,7 +33,7 @@ #include "AppElementType.hxx" /** === begin UNO includes === **/ -#include +#include #include /** === end UNO includes === **/ @@ -53,7 +53,7 @@ namespace dbaui //==================================================================== //= SubComponentManager //==================================================================== - typedef ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::beans::XPropertyChangeListener > SubComponentManager_Base; class SubComponentManager : public SubComponentManager_Base { @@ -63,6 +63,9 @@ namespace dbaui void disposing(); + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException); + // XEventListener virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); -- cgit From 2ed62793becce9a2830a6be70fc02be1296d4ee9 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 26 Jan 2010 09:01:50 +0100 Subject: autorecovery: unxlngi6: removed unused local variables --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 385b4516ac93..a62a85501bb9 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -2078,14 +2078,8 @@ void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) th if ( _rNewName.indexOf( '/' ) != -1 ) m_aErrorHelper.raiseException( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES, *this ); - sal_Int32 nHandle = PROPERTY_ID_NAME; - Any aOld = makeAny( m_pImpl->m_aProps.aTitle ); - Any aNew = makeAny( _rNewName ); - - { - NameChangeNotifier aNameChangeAndNotify( *this, _rNewName, aGuard ); - m_pImpl->m_aProps.aTitle = _rNewName; - } + NameChangeNotifier aNameChangeAndNotify( *this, _rNewName, aGuard ); + m_pImpl->m_aProps.aTitle = _rNewName; if ( m_xEmbeddedObject.is() && m_xEmbeddedObject->getCurrentState() == EmbedStates::ACTIVE ) updateDocumentTitle(); -- cgit From 6adaf71970a32c81ed45755a513f3cda788f2427 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 26 Jan 2010 13:19:11 +0100 Subject: autorecovery: mav sanctioned the approach of the (now so-called) RecoveryStorage --- dbaccess/source/core/dataaccess/dbdocrecovery.cxx | 21 ++++++++++++++++----- .../source/core/dataaccess/documentdefinition.cxx | 19 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx index 9770808b98e5..b2e8f0433990 100644 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx @@ -27,6 +27,7 @@ #include "dbdocrecovery.hxx" #include "sdbcoretools.hxx" +#include "dbastrings.hrc" /** === begin UNO includes === **/ #include @@ -48,6 +49,7 @@ #include #include +#include //........................................................................ namespace dbaccess @@ -626,9 +628,17 @@ namespace dbaccess ++map ) { + const SubComponentType eComponentType = map->first; + if ( ( eComponentType != FORM ) && ( eComponentType != REPORT ) ) + { + // nobody saves tables/queries/relations at the moment, so encountering those is worth an assertion + OSL_ENSURE( false, "DatabaseDocumentRecovery::recoverSubDocuments: only embedded objects can be recovered currently!" ); + continue; + } + // the storage for all components of the current type Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( map->first ), ElementModes::READ ), UNO_QUERY_THROW ); + lcl_getComponentsStorageName( eComponentType ), ElementModes::READ ), UNO_QUERY_THROW ); // loop thru all components of this type for ( MapStringToCompDesc::const_iterator stor = map->second.begin(); @@ -636,6 +646,7 @@ namespace dbaccess ++stor ) { + const ::rtl::OUString sComponentName( stor->second.sName ); if ( !xComponentsStor->hasByName( stor->first ) ) { #if OSL_DEBUG_LEVEL > 0 @@ -643,7 +654,7 @@ namespace dbaccess message.append( "DatabaseDocumentRecovery::recoverSubDocuments: inconsistent recovery storage: storage '" ); message.append( ::rtl::OUStringToOString( stor->first, RTL_TEXTENCODING_ASCII_US ) ); message.append( "' not found in '" ); - message.append( ::rtl::OUStringToOString( lcl_getComponentsStorageName( map->first ), RTL_TEXTENCODING_ASCII_US ) ); + message.append( ::rtl::OUStringToOString( lcl_getComponentsStorageName( eComponentType ), RTL_TEXTENCODING_ASCII_US ) ); message.append( "', but required per map file!" ); OSL_ENSURE( false, message.makeStringAndClear() ); #endif @@ -656,12 +667,12 @@ namespace dbaccess // recover the single component Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); - ::comphelper::NamedValueCollection aLoadArgs; - aLoadArgs.put( "RecoverFromStorage", xCompStor ); + aLoadArgs.put( "RecoveryStorage", xCompStor ); + try { - Reference< XComponent > xSubComponent = xDocumentUI->loadComponentWithArguments( map->first, stor->second.sName, stor->second.bForEditing, + Reference< XComponent > xSubComponent = xDocumentUI->loadComponentWithArguments( eComponentType, sComponentName, stor->second.bForEditing, aLoadArgs.getPropertyValues() ); // at the moment, we only store, during session save, sub components which are modified. So, set this diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index a62a85501bb9..ec2e1d1e11f6 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1605,15 +1605,24 @@ sal_Bool ODocumentDefinition::objectSupportsEmbeddedScripts() const // ----------------------------------------------------------------------------- void ODocumentDefinition::separateOpenCommandArguments( const Sequence< PropertyValue >& i_rOpenCommandArguments, - ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& /*o_rEmbeddedObjectDescriptor*/ ) + ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor ) { ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments ); - o_rDocumentLoadArgs.merge( aOpenCommandArguments, false ); - // This method is to separate OpenCommandArguments into args which belong into the EmbeddedObjectDescriptor, - // and args which belong into the document's media descriptor. + const sal_Char* pObjectDescriptorArgs[] = + { + "RecoveryStorage" + }; + for ( size_t i=0; i < sizeof( pObjectDescriptorArgs ) / sizeof( pObjectDescriptorArgs[0] ); ++i ) + { + if ( aOpenCommandArguments.has( pObjectDescriptorArgs[i] ) ) + { + o_rEmbeddedObjectDescriptor.put( pObjectDescriptorArgs[i], aOpenCommandArguments.get( pObjectDescriptorArgs[i] ) ); + aOpenCommandArguments.remove( pObjectDescriptorArgs[i] ); + } + } - // Well, there was some intermediate state where such args really existed - at the moment, they don't. + o_rDocumentLoadArgs.merge( aOpenCommandArguments, false ); } // ----------------------------------------------------------------------------- -- cgit From 61d77a767a0d519201f3a8554b343bce881c5991 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 26 Jan 2010 23:25:22 +0100 Subject: autorecovery: introduce createComponent/WithArguments at the XDatabaseDocumentUI interface --- dbaccess/source/ui/app/AppController.cxx | 77 ++++++++------- dbaccess/source/ui/app/AppController.hxx | 11 ++- dbaccess/source/ui/app/AppControllerGen.cxx | 33 ++++++- dbaccess/source/ui/app/AppDetailPageHelper.cxx | 14 +-- dbaccess/source/ui/inc/databaseobjectview.hxx | 31 +++--- dbaccess/source/ui/inc/linkeddocuments.hxx | 4 +- dbaccess/source/ui/misc/databaseobjectview.cxx | 126 ++++++++++--------------- dbaccess/source/ui/misc/linkeddocuments.cxx | 9 +- 8 files changed, 157 insertions(+), 148 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 65ff1c0a3a30..f464ebf1c8f4 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -1334,7 +1334,7 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa { ElementType eType = E_TABLE; sal_Bool bAutoPilot = sal_False; - sal_Bool bSQLView = sal_False; + ::comphelper::NamedValueCollection aCreationArgs; switch( _nId ) { @@ -1358,7 +1358,7 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa eType = E_QUERY; break; case ID_NEW_QUERY_SQL: - bSQLView = sal_True; + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_False ); // run through case ID_NEW_QUERY_DESIGN: eType = E_QUERY; @@ -1374,7 +1374,7 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa if ( bAutoPilot ) getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) ); else - newElement( eType, bSQLView ); + newElement( eType, aCreationArgs ); } break; case SID_APP_NEW_FOLDER: @@ -1983,7 +1983,7 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const aDataSource <<= getDatabaseName(); } - xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments.getPropertyValues() ) ); + xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) ); onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL ); } } @@ -2057,52 +2057,59 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) } // ----------------------------------------------------------------------------- -void OApplicationController::newElement( ElementType _eType, sal_Bool _bSQLView ) +Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments ) { OSL_ENSURE(getContainer(),"View is NULL! -> GPF"); + Reference< XComponent > xComponent; + Reference< XComponent > xDefinition; + switch ( _eType ) { case E_FORM: case E_REPORT: - { - ::std::auto_ptr aHelper = getDocumentsAccess(_eType); - if ( aHelper->isConnected() ) - { - Reference< XComponent > xComponent,xDefinition; - sal_Int32 nCommandType = -1; - const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType)); - xComponent = aHelper->newDocument(_eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT,xDefinition,nCommandType,sName); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); - } - } - break; + { + ::std::auto_ptr aHelper = getDocumentsAccess( _eType ); + if ( !aHelper->isConnected() ) + break; + + xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, xDefinition ); + } + break; + case E_QUERY: case E_TABLE: - { - ::std::auto_ptr< DatabaseObjectView > pDesigner; - SharedConnection xConnection( ensureConnection() ); - if ( xConnection.is() ) - { - if ( _eType == E_TABLE ) - { - pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); - } - else if ( _eType == E_QUERY ) - { - pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false, _bSQLView ) ); - } + { + ::std::auto_ptr< DatabaseObjectView > pDesigner; + SharedConnection xConnection( ensureConnection() ); + if ( !xConnection.is() ) + break; - Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( pDesigner->createNew( xDataSource ), UNO_QUERY ); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL ); - } + if ( _eType == E_TABLE ) + { + pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); } - break; + else if ( _eType == E_QUERY ) + { + pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false, i_rAdditionalArguments ) ); + } + + Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); + xComponent.set( pDesigner->createNew( xDataSource ), UNO_QUERY ); + } + break; + default: + OSL_ENSURE( false, "OApplicationController::newElement: illegal type!" ); break; } + + if ( xComponent.is() ) + onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); + + return xComponent; } + // ----------------------------------------------------------------------------- void OApplicationController::addContainerListener(const Reference& _xCollection) { diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx index 27c6f3827adf..16c13fad2e12 100644 --- a/dbaccess/source/ui/app/AppController.hxx +++ b/dbaccess/source/ui/app/AppController.hxx @@ -197,10 +197,11 @@ namespace dbaui /** opens a new frame for creation or auto pilot @param _eType Defines the type to open - @param _bSQLView - If the query design will be opened in SQL view, otherwise not. + @param i_rAdditionalArguments + Additional arguments to pass when creating the component */ - void newElement( ElementType _eType , sal_Bool _bSQLView ); + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments ); /** creates a new database object, using an auto pilot @param _eType @@ -402,7 +403,7 @@ namespace dbaui /** verifies the object type denotes a valid DatabaseObject, and the object name denotes an existing object of this type. Throws if not. */ - void impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::rtl::OUString& _rObjectName ); + void impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName ); protected: // ---------------------------------------------------------------- @@ -467,6 +468,8 @@ namespace dbaui virtual ::sal_Bool SAL_CALL closeSubComponents( ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponent( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponentWithArguments( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponent( ::sal_Int32 ObjectType ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponentWithArguments( ::sal_Int32 ObjectType, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // XContextMenuInterception virtual void SAL_CALL registerContextMenuInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XContextMenuInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index d919d1457331..6ae9d59c7eda 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -458,7 +458,7 @@ namespace } // ----------------------------------------------------------------------------- -void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::rtl::OUString& _rObjectName ) +void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName ) { // ensure we're connected if ( !isConnected() ) @@ -475,6 +475,9 @@ void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int ) throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + if ( !i_rObjectName ) + return; + // ensure an existing object Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) ); if ( !xContainer.is() ) @@ -487,19 +490,19 @@ void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int { case DatabaseObject::TABLE: case DatabaseObject::QUERY: - bExistentObject = xContainer->hasByName( _rObjectName ); + bExistentObject = xContainer->hasByName( *i_rObjectName ); break; case DatabaseObject::FORM: case DatabaseObject::REPORT: { Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW ); - bExistentObject = xHierarchy->hasByHierarchicalName( _rObjectName ); + bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName ); } break; } if ( !bExistentObject ) - throw NoSuchElementException( _rObjectName, *this ); + throw NoSuchElementException( *i_rObjectName, *this ); } // ----------------------------------------------------------------------------- @@ -529,6 +532,28 @@ Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArgume return xComponent; } +// ----------------------------------------------------------------------------- +Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType ) throw (IllegalArgumentException, SQLException, RuntimeException) +{ + return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >() ); +} + +// ----------------------------------------------------------------------------- +Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments ) throw (IllegalArgumentException, SQLException, RuntimeException) +{ + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( getMutex() ); + + impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< ::rtl::OUString >() ); + + Reference< XComponent > xComponent( newElement( + lcl_objectType2ElementType( i_nObjectType ), + ::comphelper::NamedValueCollection( i_rArguments ) + ) ); + + return xComponent; +} + // ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException) { diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.cxx b/dbaccess/source/ui/app/AppDetailPageHelper.cxx index 50e357b687b8..00e65eb1e09c 100644 --- a/dbaccess/source/ui/app/AppDetailPageHelper.cxx +++ b/dbaccess/source/ui/app/AppDetailPageHelper.cxx @@ -1290,15 +1290,11 @@ void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName, ) ); pDispatcher->setTargetFrame( m_xFrame ); - Sequence < PropertyValue > aArgs( 4 ); - aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Preview")); - aArgs[0].Value <<= sal_True; - aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); - aArgs[1].Value <<= sal_True; - aArgs[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); - aArgs[2].Value <<= sal_False; - aArgs[3].Name = PROPERTY_SHOWMENU; - aArgs[3].Value <<= sal_False; + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "Preview", sal_True ); + aArgs.put( "ReadOnly", sal_True ); + aArgs.put( "AsTemplate", sal_False ); + aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False ); Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY ); sal_Bool bClearPreview = !xPreview.is(); diff --git a/dbaccess/source/ui/inc/databaseobjectview.hxx b/dbaccess/source/ui/inc/databaseobjectview.hxx index 07c77e388196..9d417035437a 100644 --- a/dbaccess/source/ui/inc/databaseobjectview.hxx +++ b/dbaccess/source/ui/inc/databaseobjectview.hxx @@ -67,6 +67,7 @@ #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ #include #endif +#include #include @@ -96,7 +97,7 @@ namespace dbaui private: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doDispatch( - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments + const ::comphelper::NamedValueCollection& i_rDispatchArgs ); protected: @@ -116,11 +117,11 @@ namespace dbaui virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doCreateView( const ::com::sun::star::uno::Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rCreationArgs + const ::comphelper::NamedValueCollection& i_rCreationArgs ); virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _rDataSource, const ::rtl::OUString& _rObjectName ); @@ -176,7 +177,7 @@ namespace dbaui openExisting( const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rName, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs + const ::comphelper::NamedValueCollection& i_rDispatchArgs ); }; @@ -186,12 +187,12 @@ namespace dbaui class QueryDesigner : public DatabaseObjectView { protected: - sal_Int32 m_nCommandType; - sal_Bool m_bPreferSQLView; + sal_Int32 m_nCommandType; + ::comphelper::NamedValueCollection m_aCreationArgs; protected: virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rObjectName ); @@ -202,7 +203,15 @@ namespace dbaui const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame, bool _bCreateView, - sal_Bool _bPreferSQLView + const ::comphelper::NamedValueCollection& i_rCreationArgs + ); + + QueryDesigner( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame, + bool _bCreateView, + const bool i_bSQLView ); }; @@ -213,7 +222,7 @@ namespace dbaui { protected: virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rObjectName ); @@ -221,7 +230,7 @@ namespace dbaui virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doCreateView( const ::com::sun::star::uno::Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rCreationArgs + const ::comphelper::NamedValueCollection& i_rCreationArgs ); public: @@ -254,7 +263,7 @@ namespace dbaui protected: virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rQualifiedName ); diff --git a/dbaccess/source/ui/inc/linkeddocuments.hxx b/dbaccess/source/ui/inc/linkeddocuments.hxx index 8807e3b71840..c836121e8c60 100644 --- a/dbaccess/source/ui/inc/linkeddocuments.hxx +++ b/dbaccess/source/ui/inc/linkeddocuments.hxx @@ -114,9 +114,7 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > newDocument( sal_Int32 _nNewFormId, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, - const sal_Int32 _nCommandType, - const ::rtl::OUString& _sObjectName + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition ); ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > diff --git a/dbaccess/source/ui/misc/databaseobjectview.cxx b/dbaccess/source/ui/misc/databaseobjectview.cxx index 24debbe9bf7d..15b309d38a33 100644 --- a/dbaccess/source/ui/misc/databaseobjectview.cxx +++ b/dbaccess/source/ui/misc/databaseobjectview.cxx @@ -49,7 +49,6 @@ #include #include -#include #include #include #include @@ -100,30 +99,30 @@ namespace dbaui //---------------------------------------------------------------------- Reference< XComponent > DatabaseObjectView::createNew(const Reference< XDataSource >& _xDataSource ) { - return doCreateView( makeAny( _xDataSource ), ::rtl::OUString(), Sequence< PropertyValue >() ); + return doCreateView( makeAny( _xDataSource ), ::rtl::OUString(), ::comphelper::NamedValueCollection() ); } //---------------------------------------------------------------------- - Reference< XComponent > DatabaseObjectView::openExisting( const Any& _rDataSource, const ::rtl::OUString& _rName, const Sequence< PropertyValue >& _rArgs ) + Reference< XComponent > DatabaseObjectView::openExisting( const Any& _rDataSource, const ::rtl::OUString& _rName, + const ::comphelper::NamedValueCollection& i_rDispatchArgs ) { - return doCreateView( _rDataSource, _rName, _rArgs ); + return doCreateView( _rDataSource, _rName, i_rDispatchArgs ); } //---------------------------------------------------------------------- Reference< XComponent > DatabaseObjectView::doCreateView( const Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const Sequence< PropertyValue >& _rCreationArgs ) + const ::comphelper::NamedValueCollection& i_rCreationArgs ) { - Sequence< PropertyValue > aDispatchArgs; + ::comphelper::NamedValueCollection aDispatchArgs; fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName ); - ::comphelper::NamedValueCollection aDispArgs( aDispatchArgs ); - aDispArgs.merge( _rCreationArgs, true ); + aDispatchArgs.merge( i_rCreationArgs, true ); - return doDispatch( aDispArgs.getPropertyValues() ); + return doDispatch( aDispatchArgs ); } //---------------------------------------------------------------------- - Reference< XComponent > DatabaseObjectView::doDispatch( const Sequence< PropertyValue >& _rArgs ) + Reference< XComponent > DatabaseObjectView::doDispatch( const ::comphelper::NamedValueCollection& i_rDispatchArgs ) { Reference< XComponent > xReturn; if ( m_xORB.is() ) @@ -163,7 +162,7 @@ namespace dbaui m_sComponentURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")), 0, - _rArgs + i_rDispatchArgs.getPropertyValues() ); if ( !xReturn.is() ) @@ -179,29 +178,23 @@ namespace dbaui //---------------------------------------------------------------------- void DatabaseObjectView::fillDispatchArgs( - Sequence< PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& /* _rName */ ) { - sal_Int32 nPos = _rDispatchArguments.getLength(); - _rDispatchArguments.realloc( nPos + 2 ); - ::rtl::OUString sDataSource; Reference xDataSource; if ( _aDataSource >>= sDataSource ) { - _rDispatchArguments[nPos ].Name = PROPERTY_DATASOURCENAME; - _rDispatchArguments[nPos++].Value <<= sDataSource; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_DATASOURCENAME, sDataSource ); } else if ( _aDataSource >>= xDataSource ) { - _rDispatchArguments[nPos ].Name = PROPERTY_DATASOURCE; - _rDispatchArguments[nPos++].Value <<= xDataSource; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_DATASOURCE, xDataSource ); } - _rDispatchArguments[nPos ].Name = PROPERTY_ACTIVE_CONNECTION; - _rDispatchArguments[nPos++].Value <<= getConnection(); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, getConnection() ); } //====================================================================== @@ -209,49 +202,47 @@ namespace dbaui //====================================================================== //---------------------------------------------------------------------- QueryDesigner::QueryDesigner( const Reference< XMultiServiceFactory >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, - const Reference< XFrame >& _rxParentFrame, - bool _bCreateView, sal_Bool _bPreferSQLView ) + const Reference< XFrame >& _rxParentFrame, bool _bCreateView, const ::comphelper::NamedValueCollection& i_rCreationArgs ) :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< ::rtl::OUString >( _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ) ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY ) - ,m_bPreferSQLView( _bPreferSQLView ) + ,m_aCreationArgs( i_rCreationArgs ) { } //---------------------------------------------------------------------- - void QueryDesigner::fillDispatchArgs( Sequence< PropertyValue >& _rDispatchArguments, const Any& _aDataSource, - const ::rtl::OUString& _rObjectName ) + QueryDesigner::QueryDesigner( const Reference< XMultiServiceFactory >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, + const Reference< XFrame >& _rxParentFrame, bool _bCreateView, const bool i_bSQLView ) + :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< ::rtl::OUString >( _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ) + ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY ) { - DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rObjectName ); - - bool bIncludeQueryName = 0 != _rObjectName.getLength(); - bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && m_bPreferSQLView; - - sal_Int32 nPos = _rDispatchArguments.getLength(); + m_aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, !i_bSQLView ); + } - sal_Int32 nNewLen = _rDispatchArguments.getLength() + 2; - if ( bIncludeQueryName ) - ++nNewLen; - if ( bEditViewAsSQLCommand ) - ++nNewLen; - _rDispatchArguments.realloc( nNewLen ); + //---------------------------------------------------------------------- + void QueryDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, + const ::rtl::OUString& _rObjectName ) + { + DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName ); + i_rDispatchArgs.merge( m_aCreationArgs, false ); // false => do not overwrite - _rDispatchArguments[nPos ].Name = PROPERTY_GRAPHICAL_DESIGN; - _rDispatchArguments[nPos++].Value <<= ::cppu::bool2any( !m_bPreferSQLView ); + const bool bIncludeQueryName = 0 != _rObjectName.getLength(); + const bool bGraphicalDesign = i_rDispatchArgs.getOrDefault( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True ); + const bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && !bGraphicalDesign; - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND_TYPE; - _rDispatchArguments[nPos++].Value <<= m_nCommandType; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND_TYPE, m_nCommandType ); if ( bIncludeQueryName ) { - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND; - _rDispatchArguments[nPos++].Value <<= _rObjectName; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND, _rObjectName ); } if ( bEditViewAsSQLCommand ) { - _rDispatchArguments[nPos ].Name = PROPERTY_ESCAPE_PROCESSING; - _rDispatchArguments[nPos++].Value <<= sal_Bool( sal_False ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, sal_False ); } + + // give the args passed to our ctor the highest prio, let them overrule any self-made setting + i_rDispatchArgs.merge( m_aCreationArgs, true ); } //====================================================================== @@ -264,24 +255,20 @@ namespace dbaui } //---------------------------------------------------------------------- - void TableDesigner::fillDispatchArgs( Sequence< PropertyValue >& _rDispatchArguments, const Any& _aDataSource, + void TableDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& _rObjectName ) { - DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rObjectName ); - sal_Bool bIncludeName = 0 != _rObjectName.getLength(); + DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName ); - if (bIncludeName) + if ( 0 != _rObjectName.getLength() ) { - sal_Int32 nPos = _rDispatchArguments.getLength(); - _rDispatchArguments.realloc(_rDispatchArguments.getLength() + 1); - _rDispatchArguments[nPos ].Name = PROPERTY_CURRENTTABLE; - _rDispatchArguments[nPos++].Value <<= _rObjectName; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_CURRENTTABLE, _rObjectName ); } } //---------------------------------------------------------------------- Reference< XComponent > TableDesigner::doCreateView( const Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const Sequence< PropertyValue >& _rCreationArgs ) + const ::comphelper::NamedValueCollection& i_rCreationArgs ) { bool bIsNewDesign = ( _rObjectName.getLength() == 0 ); @@ -291,7 +278,7 @@ namespace dbaui xDesigner = impl_getConnectionProvidedDesigner_nothrow( _rObjectName ); if ( !xDesigner.is() ) - return DatabaseObjectView::doCreateView( _rDataSource, _rObjectName, _rCreationArgs ); + return DatabaseObjectView::doCreateView( _rDataSource, _rObjectName, i_rCreationArgs ); // try whether the designer is a dialog Reference< XExecutableDialog > xDialog( xDesigner, UNO_QUERY_THROW ); @@ -336,10 +323,10 @@ namespace dbaui } //---------------------------------------------------------------------- - void ResultSetBrowser::fillDispatchArgs(Sequence< PropertyValue >& _rDispatchArguments, const Any& _aDataSource, + void ResultSetBrowser::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& _rQualifiedName) { - DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rQualifiedName ); + DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rQualifiedName ); OSL_ENSURE( 0 != _rQualifiedName.getLength(),"A Table name must be set"); ::rtl::OUString sCatalog; ::rtl::OUString sSchema; @@ -347,26 +334,15 @@ namespace dbaui if ( m_bTable ) ::dbtools::qualifiedNameComponents( getConnection()->getMetaData(), _rQualifiedName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation ); - sal_Int32 nPos = _rDispatchArguments.getLength(); - _rDispatchArguments.realloc( _rDispatchArguments.getLength() + 3 + ( m_bTable ? 3 : 0 ) ); - - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND_TYPE; - _rDispatchArguments[nPos++].Value <<= (m_bTable ? CommandType::TABLE : CommandType::QUERY); - - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND; - _rDispatchArguments[nPos++].Value <<= _rQualifiedName; - - _rDispatchArguments[nPos ].Name = PROPERTY_ENABLE_BROWSER; - _rDispatchArguments[nPos++].Value <<= sal_False; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND_TYPE, (m_bTable ? CommandType::TABLE : CommandType::QUERY) ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND, _rQualifiedName ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_False ); if ( m_bTable ) { - _rDispatchArguments[nPos ].Name = PROPERTY_UPDATE_CATALOGNAME; - _rDispatchArguments[nPos++].Value <<= sCatalog; - _rDispatchArguments[nPos ].Name = PROPERTY_UPDATE_SCHEMANAME; - _rDispatchArguments[nPos++].Value <<= sSchema; - _rDispatchArguments[nPos ].Name = PROPERTY_UPDATE_TABLENAME; - _rDispatchArguments[nPos++].Value <<= sTable; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_UPDATE_CATALOGNAME, sCatalog ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_UPDATE_SCHEMANAME, sSchema ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_UPDATE_TABLENAME, sTable ); } } diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index a7be84b5e497..13fcc8a1f0d8 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -348,7 +348,7 @@ namespace dbaui return impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", xDefinition, -1, ::rtl::OUString() ); } //------------------------------------------------------------------ - Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 _nNewFormId, Reference< XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _sObjectName ) + Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 _nNewFormId, Reference< XComponent >& _xDefinition ) { OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid document container!"); // determine the URL to use for the new document @@ -367,6 +367,7 @@ namespace dbaui case ID_FORM_NEW_IMPRESS: aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID); break; + case ID_REPORT_NEW_TEXT: aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90); break; @@ -408,12 +409,6 @@ namespace dbaui aCommand.Argument <<= aOpenCommand; WaitObject aWaitCursor( m_pDialogParent ); xNewDocument.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY); - Reference xProp(xNewDocument,UNO_QUERY); - if ( xProp.is() && _sObjectName.getLength() ) - { - xProp->setPropertyValue(PROPERTY_COMMAND_TYPE,makeAny(_nCommandType)); - xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(_sObjectName)); - } } } } -- cgit From 9b89df0e30a7f16c019e267610486f7e2d00b193 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 00:07:12 +0100 Subject: autorecovery: prepareClose: do not load it component if it does not exist (anymore) --- .../source/core/dataaccess/documentdefinition.cxx | 25 ++++++++++++++++------ .../source/core/dataaccess/documentdefinition.hxx | 19 +++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index ec2e1d1e11f6..d01bb3dd5cbd 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1922,18 +1922,18 @@ void ODocumentDefinition::onCommandGetDocumentProperties( Any& _rProps ) } } // ----------------------------------------------------------------------------- -Reference< util::XCloseable> ODocumentDefinition::getComponent() throw (RuntimeException) +Reference< util::XCloseable > ODocumentDefinition::impl_getComponent_throw( const bool i_ForceCreate ) { OSL_ENSURE(m_xEmbeddedObject.is(),"Illegal call for embeddedObject"); - Reference< util::XCloseable> xComp; + Reference< util::XCloseable > xComp; if ( m_xEmbeddedObject.is() ) { - int nOldState = m_xEmbeddedObject->getCurrentState(); - int nState = nOldState; - if ( nOldState == EmbedStates::LOADED ) + int nState = m_xEmbeddedObject->getCurrentState(); + if ( ( nState == EmbedStates::LOADED ) && i_ForceCreate ) { m_xEmbeddedObject->changeState( EmbedStates::RUNNING ); - nState = EmbedStates::RUNNING; + nState = m_xEmbeddedObject->getCurrentState(); + OSL_ENSURE( nState == EmbedStates::RUNNING, "ODocumentDefinition::impl_getComponent_throw: could not switch to RUNNING!" ); } if ( nState == EmbedStates::ACTIVE || nState == EmbedStates::RUNNING ) @@ -1949,6 +1949,13 @@ Reference< util::XCloseable> ODocumentDefinition::getComponent() throw (RuntimeE return xComp; } +// ----------------------------------------------------------------------------- +Reference< util::XCloseable > ODocumentDefinition::getComponent() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return impl_getComponent_throw( true ); +} + // ----------------------------------------------------------------------------- namespace { @@ -2130,7 +2137,11 @@ bool ODocumentDefinition::prepareClose() // by the embedding component. Thus, we do the suspend call here. // #i49370# / 2005-06-09 / frank.schoenheit@sun.com - Reference< XModel > xModel( getComponent(), UNO_QUERY ); + Reference< util::XCloseable > xComponent( impl_getComponent_throw( false ) ); + if ( !xComponent.is() ) + return true; + + Reference< XModel > xModel( xComponent, UNO_QUERY ); Reference< XController > xController; if ( xModel.is() ) xController = xModel->getCurrentController(); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index ab8f13bc2cec..df4a6825fd7b 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -216,7 +216,7 @@ private: @param _bOpenedInDesignMode determines whether the embedded object has been opened for designing it or for data display */ - void impl_onActivateEmbeddedObject(); + void impl_onActivateEmbeddedObject(); /** initializes a newly created view/controller which is displaying our embedded object @@ -226,27 +226,30 @@ private: @param _rxController the controller which belongs to the XModel of our (active) embedded object */ - void impl_initObjectEditView( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); + void impl_initObjectEditView( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); /** removes the given frame from the desktop's frame collection @raises ::com::sun::star::uno::RuntimeException */ - void impl_removeFrameFromDesktop_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ); + void impl_removeFrameFromDesktop_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ); /** opens the UI for this sub document */ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - impl_openUI_nolck_throw( bool _bForEditing ); + impl_openUI_nolck_throw( bool _bForEditing ); /** stores our document, if it's already loaded */ - void - impl_store_throw(); + void impl_store_throw(); /** closes our document, if it's open */ - bool - impl_close_throw(); + bool impl_close_throw(); + + /** returns our component, creates it if necessary + */ + ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > + impl_getComponent_throw( const bool i_ForceCreate = true ); // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; -- cgit From 9bbf0a62bab06c8479deb466540a93e8d702c419 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 10:42:49 +0100 Subject: autorecovery: when creating new documents, allow for additional arguments to be passed --- dbaccess/source/ui/app/AppController.cxx | 2 +- dbaccess/source/ui/inc/linkeddocuments.hxx | 5 +-- dbaccess/source/ui/misc/linkeddocuments.cxx | 51 +++++++++++++---------------- 3 files changed, 27 insertions(+), 31 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index f464ebf1c8f4..f8a2f6562027 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -2073,7 +2073,7 @@ Reference< XComponent > OApplicationController::newElement( ElementType _eType, if ( !aHelper->isConnected() ) break; - xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, xDefinition ); + xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, xDefinition ); } break; diff --git a/dbaccess/source/ui/inc/linkeddocuments.hxx b/dbaccess/source/ui/inc/linkeddocuments.hxx index c836121e8c60..e7030312cde6 100644 --- a/dbaccess/source/ui/inc/linkeddocuments.hxx +++ b/dbaccess/source/ui/inc/linkeddocuments.hxx @@ -113,8 +113,9 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > newDocument( - sal_Int32 _nNewFormId, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition + sal_Int32 i_nActionID, + const ::comphelper::NamedValueCollection& i_rCreationArgs, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_rDefinition ); ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index 13fcc8a1f0d8..70f297f621f4 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -348,12 +348,13 @@ namespace dbaui return impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", xDefinition, -1, ::rtl::OUString() ); } //------------------------------------------------------------------ - Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 _nNewFormId, Reference< XComponent >& _xDefinition ) + Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID, + const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition ) { OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid document container!"); // determine the URL to use for the new document Sequence aClassId; - switch (_nNewFormId) + switch ( i_nActionID ) { case ID_FORM_NEW_TEXT: aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID); @@ -372,9 +373,8 @@ namespace dbaui aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90); break; - case SID_DB_FORM_NEW_PILOT: default: - OSL_ENSURE(sal_False, "OLinkedDocumentsAccess::newForm: pleas use newFormWithPilot!"); + OSL_ENSURE( sal_False, "OLinkedDocumentsAccess::newForm: please use newFormWithPilot!" ); return Reference< XComponent >(); } @@ -386,30 +386,25 @@ namespace dbaui Reference xORB(m_xDocumentContainer,UNO_QUERY); if ( xORB.is() ) { - Sequence< Any > aArguments(2); - - PropertyValue aValue; - - aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ClassID")); - aValue.Value <<= aClassId; - aArguments[0] <<= aValue; - - aValue.Name = PROPERTY_ACTIVE_CONNECTION; - aValue.Value <<= m_xConnection; - aArguments[1] <<= aValue; - - Reference xContent(xORB->createInstanceWithArguments(SERVICE_SDB_DOCUMENTDEFINITION,aArguments),UNO_QUERY); - if ( xContent.is() ) - { - _xDefinition.set(xContent,UNO_QUERY); - Command aCommand; - aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("openDesign")); - OpenCommandArgument2 aOpenCommand; - aOpenCommand.Mode = OpenMode::DOCUMENT; - aCommand.Argument <<= aOpenCommand; - WaitObject aWaitCursor( m_pDialogParent ); - xNewDocument.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY); - } + ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs ); + aCreationArgs.put( "ClassID", aClassId ); + aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection ); + + Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments( + SERVICE_SDB_DOCUMENTDEFINITION, + aCreationArgs.getWrappedPropertyValues() + ), + UNO_QUERY_THROW + ); + + o_rDefinition.set( xContent, UNO_QUERY ); + Command aCommand; + aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) ); + OpenCommandArgument2 aOpenCommand; + aOpenCommand.Mode = OpenMode::DOCUMENT; + aCommand.Argument <<= aOpenCommand; + WaitObject aWaitCursor( m_pDialogParent ); + xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY ); } } catch(const Exception& ) -- cgit From c2923112026e811b495440d8256602e2f4e173c8 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 10:43:52 +0100 Subject: autorecovery: when creating new documents, allow for additional arguments to be passed --- .../source/core/dataaccess/documentcontainer.cxx | 108 +++++++++++---------- .../source/core/dataaccess/documentdefinition.cxx | 25 +++-- .../source/core/dataaccess/documentdefinition.hxx | 16 +-- 3 files changed, 81 insertions(+), 68 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 806168ae5da3..2fe62eb420a5 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -205,6 +205,20 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstance( const ::rtl { return createInstanceWithArguments( aServiceSpecifier, Sequence< Any >() ); } + +namespace +{ + template< class TYPE > + void lcl_extractAndRemove( ::comphelper::NamedValueCollection& io_rArguments, const ::rtl::OUString& i_rName, TYPE& o_rValue ) + { + if ( io_rArguments.has( i_rName ) ) + { + io_rArguments.get_ensureType( i_rName, o_rValue ); + io_rArguments.remove( i_rName ); + } + } +} + // ----------------------------------------------------------------------------- Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException) { @@ -213,65 +227,46 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments if ( ServiceSpecifier == SERVICE_SDB_DOCUMENTDEFINITION ) { MutexGuard aGuard(m_aMutex); - ::rtl::OUString sName,sPersistentName,sURL; - Reference< XCommandProcessor > xCopyFrom; - Reference xConnection; - Sequence aClassID; - sal_Bool bAsTemplate = sal_False; - const Any* pBegin = _aArguments.getConstArray(); - const Any* pEnd = pBegin + _aArguments.getLength(); - PropertyValue aValue; - for(;pBegin != pEnd;++pBegin) + // extrat known arguments + ::rtl::OUString sName, sPersistentName, sURL; + Reference< XCommandProcessor > xCopyFrom; + Reference< XConnection > xConnection; + sal_Bool bAsTemplate; + Sequence< sal_Int8 > aClassID; + + ::comphelper::NamedValueCollection aArgs( _aArguments ); + lcl_extractAndRemove( aArgs, PROPERTY_NAME, sName ); + lcl_extractAndRemove( aArgs, PROPERTY_PERSISTENT_NAME, sPersistentName ); + lcl_extractAndRemove( aArgs, PROPERTY_URL, sURL ); + lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom ); + lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection ); + lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate ); + + // ClassID has two allowed types, so a special treatment here + Any aClassIDArg = aArgs.get( "ClassID" ); + if ( aClassIDArg.hasValue() ) { - *pBegin >>= aValue; - if ( aValue.Name.equalsAscii(PROPERTY_NAME) ) - { - aValue.Value >>= sName; - } - else if ( aValue.Name.equalsAscii(PROPERTY_PERSISTENT_NAME) ) - { - aValue.Value >>= sPersistentName; - } - else if ( aValue.Name.equalsAscii(PROPERTY_EMBEDDEDOBJECT) ) - { - xCopyFrom.set(aValue.Value,UNO_QUERY); - } - else if ( aValue.Name.equalsAscii(PROPERTY_URL) ) - { - aValue.Value >>= sURL; - } - else if ( aValue.Name.equalsAscii(PROPERTY_ACTIVE_CONNECTION) ) + if ( !( aClassIDArg >>= aClassID ) ) { - xConnection.set(aValue.Value,UNO_QUERY); - } - else if ( aValue.Name.equalsAscii("ClassID") ) - { - if (! ( aValue.Value >>= aClassID ) ) - { - // Extended for usage also with a string - ::rtl::OUString suValue; - aValue.Value >>= suValue; - aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( suValue ); + // Extended for usage also with a string + ::rtl::OUString sClassIDString; + if ( !( aClassIDArg >>= sClassIDString ) ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); - } - rtl::OUString suClassID = ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation(aClassID); - volatile int dummy = 0; - (void)dummy; - (void)suClassID; - } - else if ( aValue.Name.equalsAscii(PROPERTY_AS_TEMPLATE) ) - { - aValue.Value >>= bAsTemplate; - } - else - { - // DBG_ASSERT("unknown property exception"); + aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString ); } + +#if OSL_DEBUG_LEVEL > 0 + ::rtl::OUString sClassIDString = ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID ); + (void)sClassIDString; +#endif + aArgs.remove( "ClassID" ); } + // Everything which now is still present in the arguments is passed to the embedded object + const Sequence< PropertyValue > aCreationArgs( aArgs.getPropertyValues() ); const ODefinitionContainer_Impl& rDefinitions( getDefinitions() ); - sal_Bool bNew = ( 0 == sPersistentName.getLength() ); if ( bNew ) { @@ -317,7 +312,16 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments else pElementImpl = aFind->second; - xContent = new ODocumentDefinition( *this, m_aContext.getLegacyServiceFactory(), pElementImpl, m_bFormsContainer, aClassID, xConnection ); + ::rtl::Reference< ODocumentDefinition > pDocDef = new ODocumentDefinition( *this, m_aContext.getLegacyServiceFactory(), pElementImpl, m_bFormsContainer ); + if ( aClassID.getLength() ) + { + pDocDef->initialLoad( aClassID, aCreationArgs, xConnection ); + } + else + { + OSL_ENSURE( aCreationArgs.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." ); + } + xContent = pDocDef.get(); if ( sURL.getLength() ) { diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index d01bb3dd5cbd..50f391c64afb 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -548,14 +548,9 @@ namespace dbaccess DBG_NAME(ODocumentDefinition) //-------------------------------------------------------------------------- -ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxContainer - , const Reference< XMultiServiceFactory >& _xORB - ,const TContentPtr& _pImpl - , sal_Bool _bForm - , const Sequence< sal_Int8 >& _aClassID - ,const Reference& _xConnection - ) - :OContentHelper(_xORB,_rxContainer,_pImpl) +ODocumentDefinition::ODocumentDefinition( const Reference< XInterface >& _rxContainer, const Reference< XMultiServiceFactory >& _xORB, + const TContentPtr& _pImpl, sal_Bool _bForm ) + :OContentHelper(_xORB,_rxContainer,_pImpl) ,OPropertyStateContainer(OContentHelper::rBHelper) ,m_pInterceptor(NULL) ,m_bForm(_bForm) @@ -566,9 +561,19 @@ ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxConta { DBG_CTOR(ODocumentDefinition, NULL); registerProperties(); - if ( _aClassID.getLength() ) - loadEmbeddedObject( _xConnection, _aClassID, Sequence< PropertyValue >(), false, false ); } + +//-------------------------------------------------------------------------- +void ODocumentDefinition::initialLoad( const Sequence< sal_Int8 >& i_rClassID, const Sequence< PropertyValue >& i_rCreationArgs, + const Reference< XConnection >& i_rConnection ) +{ + OSL_ENSURE( i_rClassID.getLength(), "ODocumentDefinition::initialLoad: illegal class ID!" ); + if ( !i_rClassID.getLength() ) + return; + + loadEmbeddedObject( i_rConnection, i_rClassID, i_rCreationArgs, false, false ); +} + //-------------------------------------------------------------------------- ODocumentDefinition::~ODocumentDefinition() { diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index df4a6825fd7b..32ec2c68a083 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -113,14 +113,18 @@ protected: public: ODocumentDefinition( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer - ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& - ,const TContentPtr& _pImpl - ,sal_Bool _bForm - ,const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID = ::com::sun::star::uno::Sequence< sal_Int8 >() - ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection = ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>() + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&, + const TContentPtr& _pImpl, + sal_Bool _bForm ); + void initialLoad( + const ::com::sun::star::uno::Sequence< sal_Int8 >& i_rClassID, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rCreationArgs, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& i_rConnection + ); + // com::sun::star::lang::XTypeProvider DECLARE_TYPEPROVIDER( ); -- cgit From 6e56ff42613dcdcd5dd5421c5a810197a1e0f1da Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 10:53:54 +0100 Subject: autorecovery: also recover new forms/reports, which were not yet stored --- dbaccess/source/core/dataaccess/dbdocrecovery.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx index b2e8f0433990..2f2bdcd667d6 100644 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx +++ b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx @@ -672,8 +672,16 @@ namespace dbaccess try { - Reference< XComponent > xSubComponent = xDocumentUI->loadComponentWithArguments( eComponentType, sComponentName, stor->second.bForEditing, - aLoadArgs.getPropertyValues() ); + Reference< XComponent > xSubComponent; + if ( sComponentName.getLength() ) + { + xSubComponent = xDocumentUI->loadComponentWithArguments( eComponentType, sComponentName, + stor->second.bForEditing, aLoadArgs.getPropertyValues() ); + } + else + { + xSubComponent = xDocumentUI->createComponentWithArguments( eComponentType, aLoadArgs.getPropertyValues() ); + } // at the moment, we only store, during session save, sub components which are modified. So, set this // recovered sub component to "modified", too. -- cgit From 925a669a32688360e49ab972351fba2226a6a905 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 11:18:20 +0100 Subject: autorecovery: yet another slight refactoring of the DatabaseObjectView hierarchy, to allow the AppController, in newElement, to respect the additional args in all cases --- dbaccess/source/ui/app/AppController.cxx | 36 ++++++++++++++++++------- dbaccess/source/ui/inc/databaseobjectview.hxx | 16 +++-------- dbaccess/source/ui/misc/databaseobjectview.cxx | 37 +++++++++----------------- 3 files changed, 42 insertions(+), 47 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index f8a2f6562027..b5111d19376e 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -1357,10 +1357,10 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa bAutoPilot = sal_True; eType = E_QUERY; break; - case ID_NEW_QUERY_SQL: - aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_False ); - // run through case ID_NEW_QUERY_DESIGN: + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True ); + // run through + case ID_NEW_QUERY_SQL: eType = E_QUERY; break; case ID_NEW_TABLE_DESIGN_AUTO_PILOT: @@ -1390,10 +1390,13 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa SharedConnection xConnection( ensureConnection() ); if ( xConnection.is() ) { - QueryDesigner aDesigner( getORB(), this, getFrame(), true, SID_DB_NEW_VIEW_SQL == _nId ); + QueryDesigner aDesigner( getORB(), this, getFrame(), true ); + + ::comphelper::NamedValueCollection aArgs; + aArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId ); Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY ); + Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aArgs ), UNO_QUERY ); onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL ); } } @@ -1958,20 +1961,33 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const Any aDataSource; if ( _eOpenMode == E_OPEN_DESIGN ) { - sal_Bool bQuerySQLMode =( _nInstigatorCommand == SID_DB_APP_EDIT_SQL_VIEW ); + bool bAddViewTypeArg = false; if ( _eType == E_TABLE ) { if ( impl_isAlterableView_nothrow( _sName ) ) - pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true, bQuerySQLMode ) ); + { + pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) ); + bAddViewTypeArg = true; + } else + { pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) ); + } } else if ( _eType == E_QUERY ) { - pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false, bQuerySQLMode ) ); + pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) ); + bAddViewTypeArg = true; } aDataSource <<= m_xDataSource; + + if ( bAddViewTypeArg ) + { + const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW ); + aArguments.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode ); + } + } else { @@ -2091,11 +2107,11 @@ Reference< XComponent > OApplicationController::newElement( ElementType _eType, } else if ( _eType == E_QUERY ) { - pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false, i_rAdditionalArguments ) ); + pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) ); } Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - xComponent.set( pDesigner->createNew( xDataSource ), UNO_QUERY ); + xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY ); } break; diff --git a/dbaccess/source/ui/inc/databaseobjectview.hxx b/dbaccess/source/ui/inc/databaseobjectview.hxx index 9d417035437a..b295aae146a0 100644 --- a/dbaccess/source/ui/inc/databaseobjectview.hxx +++ b/dbaccess/source/ui/inc/databaseobjectview.hxx @@ -94,6 +94,7 @@ namespace dbaui m_xApplication; ::rtl::OUString m_sComponentURL; + private: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doDispatch( @@ -159,7 +160,8 @@ namespace dbaui */ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > createNew( - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _xDataSource + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _xDataSource, + const ::comphelper::NamedValueCollection& i_rDispatchArgs = ::comphelper::NamedValueCollection() ); /** opens a view for an existent object @@ -188,7 +190,6 @@ namespace dbaui { protected: sal_Int32 m_nCommandType; - ::comphelper::NamedValueCollection m_aCreationArgs; protected: virtual void fillDispatchArgs( @@ -202,16 +203,7 @@ namespace dbaui const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame, - bool _bCreateView, - const ::comphelper::NamedValueCollection& i_rCreationArgs - ); - - QueryDesigner( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, - const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication, - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame, - bool _bCreateView, - const bool i_bSQLView + bool _bCreateView ); }; diff --git a/dbaccess/source/ui/misc/databaseobjectview.cxx b/dbaccess/source/ui/misc/databaseobjectview.cxx index 15b309d38a33..3f9e94453d78 100644 --- a/dbaccess/source/ui/misc/databaseobjectview.cxx +++ b/dbaccess/source/ui/misc/databaseobjectview.cxx @@ -77,11 +77,11 @@ namespace dbaui const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame, const ::rtl::OUString& _rComponentURL ) - :m_xORB ( _rxORB ) - ,m_xParentFrame ( _rxParentFrame ) - ,m_xFrameLoader ( ) - ,m_xApplication ( _rxApplication ) - ,m_sComponentURL( _rComponentURL ) + :m_xORB ( _rxORB ) + ,m_xParentFrame ( _rxParentFrame ) + ,m_xFrameLoader ( ) + ,m_xApplication ( _rxApplication ) + ,m_sComponentURL ( _rComponentURL ) { OSL_ENSURE( m_xORB.is(), "DatabaseObjectView::DatabaseObjectView: invalid service factory!" ); OSL_ENSURE( m_xApplication.is(), "DatabaseObjectView::DatabaseObjectView: invalid connection!" ); @@ -97,9 +97,9 @@ namespace dbaui } //---------------------------------------------------------------------- - Reference< XComponent > DatabaseObjectView::createNew(const Reference< XDataSource >& _xDataSource ) + Reference< XComponent > DatabaseObjectView::createNew( const Reference< XDataSource >& _xDataSource, const ::comphelper::NamedValueCollection& i_rDispatchArgs ) { - return doCreateView( makeAny( _xDataSource ), ::rtl::OUString(), ::comphelper::NamedValueCollection() ); + return doCreateView( makeAny( _xDataSource ), ::rtl::OUString(), i_rDispatchArgs ); } //---------------------------------------------------------------------- @@ -114,9 +114,10 @@ namespace dbaui const ::comphelper::NamedValueCollection& i_rCreationArgs ) { ::comphelper::NamedValueCollection aDispatchArgs; - fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName ); - aDispatchArgs.merge( i_rCreationArgs, true ); + aDispatchArgs.merge( i_rCreationArgs, false ); // false => do not overwrite + fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName ); + aDispatchArgs.merge( i_rCreationArgs, true ); // true => do overwrite return doDispatch( aDispatchArgs ); } @@ -202,28 +203,17 @@ namespace dbaui //====================================================================== //---------------------------------------------------------------------- QueryDesigner::QueryDesigner( const Reference< XMultiServiceFactory >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, - const Reference< XFrame >& _rxParentFrame, bool _bCreateView, const ::comphelper::NamedValueCollection& i_rCreationArgs ) - :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< ::rtl::OUString >( _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ) + const Reference< XFrame >& _rxParentFrame, bool _bCreateView ) + :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY ) - ,m_aCreationArgs( i_rCreationArgs ) { } - //---------------------------------------------------------------------- - QueryDesigner::QueryDesigner( const Reference< XMultiServiceFactory >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, - const Reference< XFrame >& _rxParentFrame, bool _bCreateView, const bool i_bSQLView ) - :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< ::rtl::OUString >( _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ) - ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY ) - { - m_aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, !i_bSQLView ); - } - //---------------------------------------------------------------------- void QueryDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& _rObjectName ) { DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName ); - i_rDispatchArgs.merge( m_aCreationArgs, false ); // false => do not overwrite const bool bIncludeQueryName = 0 != _rObjectName.getLength(); const bool bGraphicalDesign = i_rDispatchArgs.getOrDefault( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True ); @@ -240,9 +230,6 @@ namespace dbaui { i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, sal_False ); } - - // give the args passed to our ctor the highest prio, let them overrule any self-made setting - i_rDispatchArgs.merge( m_aCreationArgs, true ); } //====================================================================== -- cgit From e10fc78fea6728cb1a8819daab3beee7823627f3 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 11:50:04 +0100 Subject: autorecovery: allow an empty URL in the attachResource call, which means 'determine the proper Location/URL yourself'. Needed so that not every client has to do this. Location precedes URL, this ensures that a recovered document, when saved, saves to the salvaged-file, not to the recovery-file --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 2 +- dbaccess/source/core/dataaccess/databasedocument.cxx | 11 +++++++++-- dbaccess/source/ui/browser/dataview.cxx | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 112da2d19505..4095a608733c 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -1048,7 +1048,7 @@ Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _b // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper // state, fires all events, and so on. // #i105505# / 2009-10-02 / frank.schoenheit@sun.com - xModel->attachResource( xModel->getURL(), m_aArgs ); + xModel->attachResource( ::rtl::OUString(), m_aArgs ); } if ( _bInitialize ) diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 39afd5bf76b5..67e97110ad0f 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -702,7 +702,14 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR // (we do not support macro signatures, so we can ignore this call) } - m_pImpl->attachResource( _rURL, _rArguments ); + // if no URL has been provided, the caller was lazy enough to not call our getLocation/getURL - which is allowed ... + ::rtl::OUString sURL( _rURL ); + if ( !sURL.getLength() ) + sURL = getLocation(); + if ( !sURL.getLength() ) + sURL = getURL(); + + m_pImpl->attachResource( sURL, _rArguments ); if ( impl_isInitializing() ) { // this means we've just been loaded, and this is the attachResource call which follows @@ -886,7 +893,7 @@ sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException) ::rtl::OUString SAL_CALL ODatabaseDocument::getLocation( ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); - return m_pImpl->getURL(); + return m_pImpl->getDocFileLocation(); } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException) diff --git a/dbaccess/source/ui/browser/dataview.cxx b/dbaccess/source/ui/browser/dataview.cxx index a66f6ec6d11a..efeb65adf442 100644 --- a/dbaccess/source/ui/browser/dataview.cxx +++ b/dbaccess/source/ui/browser/dataview.cxx @@ -236,7 +236,7 @@ namespace dbaui { ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); aArgs.remove( "Hidden" ); - xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() ); + xModel->attachResource( ::rtl::OUString(), aArgs.getPropertyValues() ); } } catch( const Exception& ) -- cgit From 42614dac6359f8ea3a3446f089f17b5054dbe50b Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 27 Jan 2010 12:11:39 +0100 Subject: autorecovery: renamed local var shadowing another local var (GCC warning) --- dbaccess/source/ui/app/AppController.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index b5111d19376e..9e6890f728eb 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -1392,11 +1392,11 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa { QueryDesigner aDesigner( getORB(), this, getFrame(), true ); - ::comphelper::NamedValueCollection aArgs; - aArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId ); + ::comphelper::NamedValueCollection aCreationArgs; + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId ); Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aArgs ), UNO_QUERY ); + Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY ); onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL ); } } -- cgit From 67f02ec2e2aea15b32883ee479457fcc1fdfc806 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 28 Jan 2010 22:19:50 +0100 Subject: autorecovery: move the responsibility for calling attachResource into recoverFromFile. This saves us from some problems with SFX-based documents, which change there Args during the load process (during macro confirmation), so a later attachResource from outside would overwrite those changed args --- .../source/core/dataaccess/databasedocument.cxx | 23 ++++++++++++++++------ .../source/core/dataaccess/databasedocument.hxx | 17 ++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 67e97110ad0f..64b667e89d14 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -668,6 +668,11 @@ void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_Sourc // Without a controller, we are unable to recover the sub components, as they're always tied to a controller. // So, everything else is done when the first controller is connected. m_bHasBeenRecovered = true; + + // by definition (of XDocumentRecovery), we're responsible for delivering a fully-initialized document, + // which includes an attachResource call. + impl_attachResource( i_SourceLocation, aMediaDescriptor.getPropertyValues(), aGuard ); + // <- SYNCHRONIZED } catch( const Exception& ) { @@ -690,10 +695,16 @@ void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_Sourc sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); + return impl_attachResource( _rURL, _rArguments, aGuard ); +} - if ( ( _rURL == getURL() ) - && ( _rArguments.getLength() == 1 ) - && ( _rArguments[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 ) +// ----------------------------------------------------------------------------- +sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rURL, const Sequence< PropertyValue >& i_rMediaDescriptor, + DocumentGuard& _rDocGuard ) +{ + if ( ( i_rURL == getURL() ) + && ( i_rMediaDescriptor.getLength() == 1 ) + && ( i_rMediaDescriptor[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 ) ) { // this is a BAD hack of the Basic importer code ... there should be a dedicated API for this, @@ -703,13 +714,13 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR } // if no URL has been provided, the caller was lazy enough to not call our getLocation/getURL - which is allowed ... - ::rtl::OUString sURL( _rURL ); + ::rtl::OUString sURL( i_rURL ); if ( !sURL.getLength() ) sURL = getLocation(); if ( !sURL.getLength() ) sURL = getURL(); - m_pImpl->attachResource( sURL, _rArguments ); + m_pImpl->attachResource( sURL, i_rMediaDescriptor ); if ( impl_isInitializing() ) { // this means we've just been loaded, and this is the attachResource call which follows @@ -721,7 +732,7 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR // should know this before anybody actually uses the object. m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros ); - aGuard.clear(); + _rDocGuard.clear(); // <- SYNCHRONIZED m_aEventNotifier.notifyDocumentEvent( "OnLoadFinished" ); } diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 446a344dfebc..f3206fbc15ae 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -609,6 +609,23 @@ private: const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, DocumentGuard& _rDocGuard ) const; + + + /** impl-version of attachResource + + @param i_rURL + denotes the URL the document was loaded from + @param i_rMediaDescriptor + denotes additional document parameters + @param _rDocGuard + is the guard which currently protects the document instance + + */ + sal_Bool impl_attachResource( + const ::rtl::OUString& i_rURL, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rMediaDescriptor, + DocumentGuard& _rDocGuard + ); }; /** an extended version of the ModelMethodGuard, which also cares for the initialization state -- cgit From 630c4139a8be53e0ae6f214a8318765fb25cba44 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 28 Jan 2010 22:34:45 +0100 Subject: autorecovery: creating dedicated core/recovery folder, taking current and future implementations regarding document recovery --- dbaccess/prj/build.lst | 3 +- .../source/core/dataaccess/databasedocument.cxx | 2 +- dbaccess/source/core/dataaccess/dbdocrecovery.cxx | 702 --------------------- dbaccess/source/core/dataaccess/dbdocrecovery.hxx | 90 --- .../source/core/inc/recovery/dbdocrecovery.hxx | 90 +++ dbaccess/source/core/recovery/dbdocrecovery.cxx | 702 +++++++++++++++++++++ dbaccess/source/core/recovery/makefile.mk | 52 ++ dbaccess/util/makefile.mk | 1 + 8 files changed, 848 insertions(+), 794 deletions(-) delete mode 100644 dbaccess/source/core/dataaccess/dbdocrecovery.cxx delete mode 100644 dbaccess/source/core/dataaccess/dbdocrecovery.hxx create mode 100644 dbaccess/source/core/inc/recovery/dbdocrecovery.hxx create mode 100644 dbaccess/source/core/recovery/dbdocrecovery.cxx create mode 100644 dbaccess/source/core/recovery/makefile.mk (limited to 'dbaccess') diff --git a/dbaccess/prj/build.lst b/dbaccess/prj/build.lst index c52076ffa4a6..f9ba2e4abd5f 100644 --- a/dbaccess/prj/build.lst +++ b/dbaccess/prj/build.lst @@ -4,6 +4,7 @@ ba dbaccess\inc nmake - all ba_inc NULL ba dbaccess\source\ui\inc nmake - all ba_uiinc ba_inc NULL ba dbaccess\source\core\api nmake - all ba_capi ba_inc NULL ba dbaccess\source\core\dataaccess nmake - all ba_cdaccess ba_capi ba_inc NULL +ba dbaccess\source\core\recovery nmake - all ba_crecovery ba_inc NULL ba dbaccess\source\core\misc nmake - all ba_cmisc ba_cdaccess ba_inc NULL ba dbaccess\source\core\resource nmake - all ba_cres ba_cmisc ba_inc NULL ba dbaccess\source\filter\xml nmake - all ba_ffilter ba_shared ba_util ba_inc NULL @@ -24,6 +25,6 @@ ba dbaccess\source\ui\relationdesign nmake - all ba_uirelationdesign ba_uiinc b ba dbaccess\source\ui\tabledesign nmake - all ba_uitabledesign ba_uiinc ba_inc NULL ba dbaccess\source\ui\uno nmake - all ba_uiuno ba_uimisc ba_inc NULL ba dbaccess\source\ui\imagelists nmake - all ba_uiimglst ba_inc NULL -ba dbaccess\util nmake - all ba_util ba_uiimglst ba_capi ba_shared ba_uibrowser ba_uiapp ba_uicontrol ba_uidlg ba_uimisc ba_uiquery ba_uitabledesign ba_uirelationdesign ba_uiuno ba_conntools ba_misctools ba_miscres ba_ext_adabasui NULL +ba dbaccess\util nmake - all ba_util ba_uiimglst ba_capi ba_crecovery ba_shared ba_uibrowser ba_uiapp ba_uicontrol ba_uidlg ba_uimisc ba_uiquery ba_uitabledesign ba_uirelationdesign ba_uiuno ba_conntools ba_misctools ba_miscres ba_ext_adabasui NULL ba dbaccess\win32\source\odbcconfig nmake - w ba_odbcconfig ba_inc NULL ba dbaccess\qa\complex\dbaccess nmake - all ba_complex_tests NULL diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 64b667e89d14..c6b6db11a20c 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -41,7 +41,7 @@ #include "databasecontext.hxx" #include "documentcontainer.hxx" #include "sdbcoretools.hxx" -#include "dbdocrecovery.hxx" +#include "recovery/dbdocrecovery.hxx" /** === begin UNO includes === **/ #include diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx b/dbaccess/source/core/dataaccess/dbdocrecovery.cxx deleted file mode 100644 index 2f2bdcd667d6..000000000000 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.cxx +++ /dev/null @@ -1,702 +0,0 @@ -/************************************************************************* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* Copyright 2009 by Sun Microsystems, Inc. -* -* OpenOffice.org - a multi-platform office productivity suite -* -* This file is part of OpenOffice.org. -* -* OpenOffice.org is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License version 3 -* only, as published by the Free Software Foundation. -* -* OpenOffice.org is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License version 3 for more details -* (a copy is included in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU Lesser General Public License -* version 3 along with OpenOffice.org. If not, see -* -* for a copy of the LGPLv3 License. -************************************************************************/ - -#include "precompiled_dbaccess.hxx" - -#include "dbdocrecovery.hxx" -#include "sdbcoretools.hxx" -#include "dbastrings.hrc" - -/** === begin UNO includes === **/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/** === end UNO includes === **/ - -#include -#include -#include -#include -#include - -#include -#include - -//........................................................................ -namespace dbaccess -{ -//........................................................................ - - /** === begin UNO using === **/ - using ::com::sun::star::uno::Reference; - using ::com::sun::star::uno::XInterface; - using ::com::sun::star::uno::UNO_QUERY; - using ::com::sun::star::uno::UNO_QUERY_THROW; - using ::com::sun::star::uno::UNO_SET_THROW; - using ::com::sun::star::uno::Exception; - using ::com::sun::star::uno::RuntimeException; - using ::com::sun::star::uno::Any; - using ::com::sun::star::uno::makeAny; - using ::com::sun::star::uno::Sequence; - using ::com::sun::star::uno::Type; - using ::com::sun::star::embed::XStorage; - using ::com::sun::star::frame::XController; - using ::com::sun::star::sdb::application::XDatabaseDocumentUI; - using ::com::sun::star::frame::XModuleManager; - using ::com::sun::star::lang::XComponent; - using ::com::sun::star::document::XStorageBasedDocument; - using ::com::sun::star::beans::PropertyValue; - using ::com::sun::star::beans::Pair; - using ::com::sun::star::io::XStream; - using ::com::sun::star::io::XOutputStream; - using ::com::sun::star::io::XTextOutputStream; - using ::com::sun::star::io::XActiveDataSource; - using ::com::sun::star::io::XTextInputStream; - using ::com::sun::star::io::XActiveDataSink; - using ::com::sun::star::frame::XModel; - using ::com::sun::star::util::XModifiable; - /** === end UNO using === **/ - - namespace ElementModes = ::com::sun::star::embed::ElementModes; - namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; - - //==================================================================== - //= helpers - //==================================================================== - namespace - { - // ......................................................................... - enum SubComponentType - { - TABLE = DatabaseObject::TABLE, - QUERY = DatabaseObject::QUERY, - FORM = DatabaseObject::FORM, - REPORT = DatabaseObject::REPORT, - - RELATION_DESIGN = 1000, - - UNKNOWN = 10001 - }; - - struct SubComponentDescriptor - { - ::rtl::OUString sName; - bool bForEditing; - - SubComponentDescriptor() - :sName() - ,bForEditing( false ) - { - } - - SubComponentDescriptor( const ::rtl::OUString& i_rName, const bool i_bForEditing ) - :sName( i_rName ) - ,bForEditing( i_bForEditing ) - { - } - }; - - // ......................................................................... - typedef ::std::hash_map< ::rtl::OUString, SubComponentDescriptor, ::rtl::OUStringHash > MapStringToCompDesc; - typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; - - // ......................................................................... - void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) - { - o_rBuffer.append( i_rComponentDesc.first ); - o_rBuffer.append( sal_Unicode( '=' ) ); - o_rBuffer.append( i_rComponentDesc.second.sName ); - o_rBuffer.append( sal_Unicode( ',' ) ); - o_rBuffer.append( sal_Unicode( i_rComponentDesc.second.bForEditing ? '1' : '0' ) ); - } - - // ......................................................................... - bool lcl_extractCompDesc( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rStorName, SubComponentDescriptor& o_rCompDesc ) - { - const sal_Int32 nEqualSignPos = i_rIniLine.indexOf( sal_Unicode( '=' ) ); - if ( nEqualSignPos < 1 ) - { - OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of '='" ); - return false; - } - o_rStorName = i_rIniLine.copy( 0, nEqualSignPos ); - - const sal_Int32 nCommaPos = i_rIniLine.lastIndexOf( sal_Unicode( ',' ) ); - if ( nCommaPos != i_rIniLine.getLength() - 2 ) - { - OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of ','" ); - return false; - } - o_rCompDesc.sName = i_rIniLine.copy( nEqualSignPos + 1, nCommaPos - nEqualSignPos - 1 ); - o_rCompDesc.bForEditing = ( i_rIniLine.getStr()[ nCommaPos + 1 ] == '1' ); - return true; - } - - // ......................................................................... - SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) - { - switch ( i_nObjectType ) - { - case DatabaseObject::TABLE: return TABLE; - case DatabaseObject::QUERY: return QUERY; - case DatabaseObject::FORM: return FORM; - case DatabaseObject::REPORT:return REPORT; - default: - break; - } - return UNKNOWN; - } - - // ......................................................................... - const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() - { - static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); - return s_sRecDataStorName; - } - - // ......................................................................... - const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) - { - static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); - static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); - static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) ); - static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) ); - static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) ); - - switch ( i_eType ) - { - case FORM: - return s_sFormsStorageName; - case REPORT: - return s_sReportsStorageName; - case TABLE: - return s_sTablesStorageName; - case QUERY: - return s_sQueriesStorageName; - case RELATION_DESIGN: - return s_sRelationsStorageName; - default: - break; - } - - OSL_ENSURE( false, "lcl_getComponentsStorageName: unimplemented case!" ); - static const ::rtl::OUString s_sFallback; - return s_sFallback; - } - - // ......................................................................... - const ::rtl::OUString& lcl_getObjectMapStreamName() - { - static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); - return s_sObjectMapStreamName; - } - - // ......................................................................... - const ::rtl::OUString& lcl_getMapStreamEncodingName() - { - static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); - return s_sMapStreamEncodingName; - } - - // ......................................................................... - void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, - const MapStringToCompDesc& i_mapStorageToCompDesc ) - { - if ( i_mapStorageToCompDesc.empty() ) - // nothing to do - return; - - ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); - Reference< XStream > xIniStream( i_rStorage->openStreamElement( - lcl_getObjectMapStreamName(), ElementModes::WRITE | ElementModes::TRUNCATE ), UNO_SET_THROW ); - - Reference< XTextOutputStream > xTextOutput( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); - xTextOutput->setEncoding( lcl_getMapStreamEncodingName() ); - - Reference< XActiveDataSource > xDataSource( xTextOutput, UNO_QUERY_THROW ); - xDataSource->setOutputStream( xIniStream->getOutputStream() ); - - const ::rtl::OUString sLineFeed( sal_Unicode( '\n' ) ); - xTextOutput->writeString( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); - xTextOutput->writeString( sLineFeed ); - - for ( MapStringToCompDesc::const_iterator stor = i_mapStorageToCompDesc.begin(); - stor != i_mapStorageToCompDesc.end(); - ++stor - ) - { - ::rtl::OUStringBuffer aLine; - lcl_getPersistentRepresentation( *stor, aLine ); - aLine.append( sLineFeed ); - - xTextOutput->writeString( aLine.makeStringAndClear() ); - } - - xTextOutput->writeString( sLineFeed ); - } - - // ......................................................................... - bool lcl_isSectionStart( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rSectionName ) - { - const sal_Int32 nLen = i_rIniLine.getLength(); - if ( ( nLen > 0 ) && ( i_rIniLine.getStr()[0] == '[' ) && ( i_rIniLine.getStr()[ nLen - 1 ] == ']' ) ) - { - o_rSectionName = i_rIniLine.copy( 1, nLen -2 ); - return true; - } - return false; - } - - // ......................................................................... - void lcl_stripTrailingLineFeed( ::rtl::OUString& io_rLine ) - { - const sal_Int32 nLen = io_rLine.getLength(); - if ( ( nLen > 0 ) && ( io_rLine.getStr()[ nLen - 1 ] == '\n' ) ) - io_rLine = io_rLine.copy( 0, nLen - 1 ); - } - - // ......................................................................... - void lcl_readObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, - MapStringToCompDesc& o_mapStorageToObjectName ) - { - ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); - if ( !i_rStorage->hasByName( lcl_getObjectMapStreamName() ) ) - { // nothing to do, though suspicious - OSL_ENSURE( false, "lcl_readObjectMap_throw: if there's no map file, then there's expected to be no storage, too!" ); - return; - } - - Reference< XStream > xIniStream( i_rStorage->openStreamElement( - lcl_getObjectMapStreamName(), ElementModes::READ ), UNO_SET_THROW ); - - Reference< XTextInputStream > xTextInput( i_rContext.createComponent( "com.sun.star.io.TextInputStream" ), UNO_QUERY_THROW ); - xTextInput->setEncoding( lcl_getMapStreamEncodingName() ); - - Reference< XActiveDataSink > xDataSink( xTextInput, UNO_QUERY_THROW ); - xDataSink->setInputStream( xIniStream->getInputStream() ); - - ::rtl::OUString sCurrentSection; - bool bCurrentSectionIsKnownToBeUnsupported = true; - while ( !xTextInput->isEOF() ) - { - ::rtl::OUString sLine = xTextInput->readLine(); - lcl_stripTrailingLineFeed( sLine ); - - if ( sLine.getLength() == 0 ) - continue; - - if ( lcl_isSectionStart( sLine, sCurrentSection ) ) - { - bCurrentSectionIsKnownToBeUnsupported = false; - continue; - } - - if ( bCurrentSectionIsKnownToBeUnsupported ) - continue; - - // the only section we support so far is "storages" - if ( !sCurrentSection.equalsAscii( "storages" ) ) - { - bCurrentSectionIsKnownToBeUnsupported = true; - continue; - } - - ::rtl::OUString sStorageName; - SubComponentDescriptor aCompDesc; - if ( !lcl_extractCompDesc( sLine, sStorageName, aCompDesc ) ) - continue; - o_mapStorageToObjectName[ sStorageName ] = aCompDesc; - } - } - - // ......................................................................... - bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) - { - Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); - if ( !xDocument.is() ) - { - Reference< XController > xController( i_rComponent, UNO_QUERY_THROW ); - xDocument = xController->getModel(); - } - - if ( !xDocument.is() ) - return false; - - ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() ); - return aDocArgs.getOrDefault( "ReadOnly", false ); - } - - // ......................................................................... - void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) - { - const Reference< XModifiable > xModify( i_rSubComponent, UNO_QUERY ); - if ( !xModify.is() ) - { - OSL_ENSURE( false, "lcl_markModified: unhandled case!" ); - return; - } - - xModify->setModified( sal_True ); - } - } - - //==================================================================== - //= DatabaseDocumentRecovery_Data - //==================================================================== - struct DatabaseDocumentRecovery_Data - { - const ::comphelper::ComponentContext aContext; - - DatabaseDocumentRecovery_Data( const ::comphelper::ComponentContext& i_rContext ) - :aContext( i_rContext ) - { - } - }; - - //==================================================================== - //= SubComponentRecovery - //==================================================================== - class SubComponentRecovery - { - public: - SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XDatabaseDocumentUI >& i_rController, - const Reference< XComponent >& i_rComponent ) - :m_rContext( i_rContext ) - ,m_xComponent( i_rComponent ) - ,m_eType( UNKNOWN ) - ,m_aCompDesc() - { - impl_identifyComponent_throw( i_rController ); - } - - void saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapCompTypeToCompDescs& io_mapCompDescs ); - - private: - void impl_saveSubDocument_throw( - const Reference< XStorage >& i_rRecoveryStorage, - MapStringToCompDesc& io_mapStorageToCompDesc - ); - - void impl_identifyComponent_throw( - const Reference< XDatabaseDocumentUI >& i_rController - ); - - private: - const ::comphelper::ComponentContext& m_rContext; - const Reference< XComponent > m_xComponent; - SubComponentType m_eType; - SubComponentDescriptor m_aCompDesc; - }; - - //-------------------------------------------------------------------- - void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, - MapCompTypeToCompDescs& io_mapCompDescs ) - { - - if ( m_eType == UNKNOWN ) - // quite fatal, but has already been reported (as assertion) before - return; - - switch ( m_eType ) - { - case FORM: - case REPORT: - impl_saveSubDocument_throw( i_rRecoveryStorage, io_mapCompDescs[ m_eType ] ); - break; - - default: - // TODO - OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); - break; - } - } - - //-------------------------------------------------------------------- - void SubComponentRecovery::impl_identifyComponent_throw( const Reference< XDatabaseDocumentUI >& i_rController ) - { - ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); - - // ask the controller - Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = i_rController->identifySubComponent( m_xComponent ); - m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First ); - m_aCompDesc.sName = aComponentIdentity.Second; - - // what the controller didn't give us is the information whether this is in edit mode or not ... - Reference< XModuleManager > xModuleManager( m_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); - const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent ); - - switch ( m_eType ) - { - case TABLE: - m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.TableDesign" ); - break; - - case QUERY: - m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.QueryDesign" ); - break; - - case REPORT: - if ( sModuleIdentifier.equalsAscii( "com.sun.star.report.ReportDefinition" ) ) - { - // it's an SRB report desginer - m_aCompDesc.bForEditing = true; - break; - } - // fall through - - case FORM: - m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent ); - break; - - default: - if ( sModuleIdentifier.equalsAscii( "com.sun.star.sdb.RelationDesign" ) ) - { - m_eType = RELATION_DESIGN; - m_aCompDesc.bForEditing = true; - } - else - { - OSL_ENSURE( false, "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" ); - } - break; - } - - OSL_POSTCOND( m_eType != UNKNOWN, - "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" ); - } - - //-------------------------------------------------------------------- - void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage, - MapStringToCompDesc& io_mapStorageToCompDesc ) - { - ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); - ENSURE_OR_THROW( i_rRecoveryStorage.is(), "illegal storage" ); - - // open the sub storage for the given kind of documents - const ::rtl::OUString& rStorageName( lcl_getComponentsStorageName( m_eType ) ); - const Reference< XStorage > xDocsStor( i_rRecoveryStorage->openStorageElement( - rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); - - // find a free sub storage name, and create Yet Another Sub Storage - const ::rtl::OUString sBaseName( ::rtl::OUString::createFromAscii( m_eType == FORM ? "form" : "report" ) ); - const ::rtl::OUString sCompStorName = ::dbtools::createUniqueName( xDocsStor.get(), sBaseName, true ); - const Reference< XStorage > xCompStor( xDocsStor->openStorageElement( - sCompStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); - - // store the document into the storage - Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); - xStorageDocument->storeToStorage( xCompStor, Sequence< PropertyValue >() ); - - // remember the relationship between the component name to the storage name - OSL_ENSURE( io_mapStorageToCompDesc.find( sCompStorName ) == io_mapStorageToCompDesc.end(), - "SubComponentRecoverys::impl_saveSubDocument_throw: object name already used!" ); - io_mapStorageToCompDesc[ sCompStorName ] = m_aCompDesc; - - // commit the storage for the documents collection - tools::stor::commitStorageIfWriteable( xDocsStor ); - } - - //==================================================================== - //= DatabaseDocumentRecovery - //==================================================================== - //-------------------------------------------------------------------- - DatabaseDocumentRecovery::DatabaseDocumentRecovery( const ::comphelper::ComponentContext& i_rContext ) - :m_pData( new DatabaseDocumentRecovery_Data( i_rContext ) ) - { - } - - //-------------------------------------------------------------------- - DatabaseDocumentRecovery::~DatabaseDocumentRecovery() - { - } - - //-------------------------------------------------------------------- - void DatabaseDocumentRecovery::saveModifiedSubComponents( const Reference< XStorage >& i_rTargetStorage, - const ::std::vector< Reference< XController > >& i_rControllers ) - { - ENSURE_OR_THROW( i_rTargetStorage.is(), "invalid document storage" ); - - // create a sub storage for recovery data - if ( i_rTargetStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) - i_rTargetStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); - Reference< XStorage > xRecoveryStorage = i_rTargetStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); - - // store recovery data for open sub components of the given controller(s) - if ( !i_rControllers.empty() ) - { - ENSURE_OR_THROW( i_rControllers.size() == 1, "can't handle more than one controller" ); - // At the moment, there can be only one view to a database document. If we ever allow for more than this, - // then we need a concept for sub documents opened from different controllers (i.e. two document views, - // and the user opens the very same form in both views). And depending on this, we need a concept for - // how those are saved to the recovery file. - - MapCompTypeToCompDescs aMapCompDescs; - - for ( ::std::vector< Reference< XController > >::const_iterator ctrl = i_rControllers.begin(); - ctrl != i_rControllers.end(); - ++ctrl - ) - { - Reference< XDatabaseDocumentUI > xDatabaseUI( *ctrl, UNO_QUERY_THROW ); - Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); - - const Reference< XComponent >* component = aComponents.getConstArray(); - const Reference< XComponent >* componentEnd = aComponents.getConstArray() + aComponents.getLength(); - for ( ; component != componentEnd; ++component ) - { - SubComponentRecovery aComponentRecovery( m_pData->aContext, xDatabaseUI, *component ); - aComponentRecovery.saveToRecoveryStorage( xRecoveryStorage, aMapCompDescs ); - } - } - - for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); - map != aMapCompDescs.end(); - ++map - ) - { - Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( map->first ), ElementModes::WRITE | ElementModes::NOCREATE ) ); - lcl_writeObjectMap_throw( m_pData->aContext, xComponentsStor, map->second ); - tools::stor::commitStorageIfWriteable( xComponentsStor ); - } - } - - // commit the recovery storage - tools::stor::commitStorageIfWriteable( xRecoveryStorage ); - } - - //-------------------------------------------------------------------- - void DatabaseDocumentRecovery::recoverSubDocuments( const Reference< XStorage >& i_rDocumentStorage, - const Reference< XController >& i_rTargetController ) - { - ENSURE_OR_THROW( i_rDocumentStorage.is(), "illegal document storage" ); - Reference< XDatabaseDocumentUI > xDocumentUI( i_rTargetController, UNO_QUERY_THROW ); - - if ( !i_rDocumentStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) - // that's allowed - return; - - // the "recovery" sub storage - Reference< XStorage > xRecoveryStorage = i_rDocumentStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READ ); - - // read the map from sub storages to object names - MapCompTypeToCompDescs aMapCompDescs; - SubComponentType aKnownTypes[] = { TABLE, QUERY, FORM, REPORT, RELATION_DESIGN }; - for ( size_t i = 0; i < sizeof( aKnownTypes ) / sizeof( aKnownTypes[0] ); ++i ) - { - if ( !xRecoveryStorage->hasByName( lcl_getComponentsStorageName( aKnownTypes[i] ) ) ) - continue; - - Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( aKnownTypes[i] ), ElementModes::READ ) ); - lcl_readObjectMap_throw( m_pData->aContext, xComponentsStor, aMapCompDescs[ aKnownTypes[i] ] ); - xComponentsStor->dispose(); - } - - // recover all sub components as indicated by the map - for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); - map != aMapCompDescs.end(); - ++map - ) - { - const SubComponentType eComponentType = map->first; - if ( ( eComponentType != FORM ) && ( eComponentType != REPORT ) ) - { - // nobody saves tables/queries/relations at the moment, so encountering those is worth an assertion - OSL_ENSURE( false, "DatabaseDocumentRecovery::recoverSubDocuments: only embedded objects can be recovered currently!" ); - continue; - } - - // the storage for all components of the current type - Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( eComponentType ), ElementModes::READ ), UNO_QUERY_THROW ); - - // loop thru all components of this type - for ( MapStringToCompDesc::const_iterator stor = map->second.begin(); - stor != map->second.end(); - ++stor - ) - { - const ::rtl::OUString sComponentName( stor->second.sName ); - if ( !xComponentsStor->hasByName( stor->first ) ) - { - #if OSL_DEBUG_LEVEL > 0 - ::rtl::OStringBuffer message; - message.append( "DatabaseDocumentRecovery::recoverSubDocuments: inconsistent recovery storage: storage '" ); - message.append( ::rtl::OUStringToOString( stor->first, RTL_TEXTENCODING_ASCII_US ) ); - message.append( "' not found in '" ); - message.append( ::rtl::OUStringToOString( lcl_getComponentsStorageName( eComponentType ), RTL_TEXTENCODING_ASCII_US ) ); - message.append( "', but required per map file!" ); - OSL_ENSURE( false, message.makeStringAndClear() ); - #endif - continue; - } - - // the controller needs to have a connection to be able to open sub components - if ( !xDocumentUI->isConnected() ) - xDocumentUI->connect(); - - // recover the single component - Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); - ::comphelper::NamedValueCollection aLoadArgs; - aLoadArgs.put( "RecoveryStorage", xCompStor ); - - try - { - Reference< XComponent > xSubComponent; - if ( sComponentName.getLength() ) - { - xSubComponent = xDocumentUI->loadComponentWithArguments( eComponentType, sComponentName, - stor->second.bForEditing, aLoadArgs.getPropertyValues() ); - } - else - { - xSubComponent = xDocumentUI->createComponentWithArguments( eComponentType, aLoadArgs.getPropertyValues() ); - } - - // at the moment, we only store, during session save, sub components which are modified. So, set this - // recovered sub component to "modified", too. - lcl_markModified( xSubComponent ); - } - catch ( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - - xComponentsStor->dispose(); - } - } - -//........................................................................ -} // namespace dbaccess -//........................................................................ diff --git a/dbaccess/source/core/dataaccess/dbdocrecovery.hxx b/dbaccess/source/core/dataaccess/dbdocrecovery.hxx deleted file mode 100644 index 0bf44e2bf3e8..000000000000 --- a/dbaccess/source/core/dataaccess/dbdocrecovery.hxx +++ /dev/null @@ -1,90 +0,0 @@ -/************************************************************************* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* Copyright 2009 by Sun Microsystems, Inc. -* -* OpenOffice.org - a multi-platform office productivity suite -* -* This file is part of OpenOffice.org. -* -* OpenOffice.org is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License version 3 -* only, as published by the Free Software Foundation. -* -* OpenOffice.org is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License version 3 for more details -* (a copy is included in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU Lesser General Public License -* version 3 along with OpenOffice.org. If not, see -* -* for a copy of the LGPLv3 License. -************************************************************************/ - -#ifndef DBACCESS_DBDOCRECOVERY_HXX -#define DBACCESS_DBDOCRECOVERY_HXX - -/** === begin UNO includes === **/ -#include -#include -/** === end UNO includes === **/ - -#include -#include - -namespace comphelper -{ - class ComponentContext; -} - -//........................................................................ -namespace dbaccess -{ -//........................................................................ - - //==================================================================== - //= DatabaseDocumentRecovery - //==================================================================== - struct DatabaseDocumentRecovery_Data; - class DatabaseDocumentRecovery - { - public: - DatabaseDocumentRecovery( - const ::comphelper::ComponentContext& i_rContext - ); - ~DatabaseDocumentRecovery(); - - /** saves the modified sub components of the given controller(s) to the "recovery" sub storage of the document - storage. - - @throws ::com::sun::star::uno::Exception - in case of an error. - */ - void saveModifiedSubComponents( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rTargetStorage, - const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > >& i_rControllers - ); - - /** recovery sub components from the given document storage, if applicable - - If the given document storage does not contain a recovery folder, the method silently returns. - - @throws ::com::sun::star::uno::Exception - in case of an error. - */ - void recoverSubDocuments( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rDocumentStorage, - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rTargetController - ); - - private: - const ::std::auto_ptr< DatabaseDocumentRecovery_Data > m_pData; - }; - -//........................................................................ -} // namespace dbaccess -//........................................................................ - -#endif // DBACCESS_DBDOCRECOVERY_HXX diff --git a/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx b/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx new file mode 100644 index 000000000000..0bf44e2bf3e8 --- /dev/null +++ b/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx @@ -0,0 +1,90 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef DBACCESS_DBDOCRECOVERY_HXX +#define DBACCESS_DBDOCRECOVERY_HXX + +/** === begin UNO includes === **/ +#include +#include +/** === end UNO includes === **/ + +#include +#include + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= DatabaseDocumentRecovery + //==================================================================== + struct DatabaseDocumentRecovery_Data; + class DatabaseDocumentRecovery + { + public: + DatabaseDocumentRecovery( + const ::comphelper::ComponentContext& i_rContext + ); + ~DatabaseDocumentRecovery(); + + /** saves the modified sub components of the given controller(s) to the "recovery" sub storage of the document + storage. + + @throws ::com::sun::star::uno::Exception + in case of an error. + */ + void saveModifiedSubComponents( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rTargetStorage, + const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > >& i_rControllers + ); + + /** recovery sub components from the given document storage, if applicable + + If the given document storage does not contain a recovery folder, the method silently returns. + + @throws ::com::sun::star::uno::Exception + in case of an error. + */ + void recoverSubDocuments( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rDocumentStorage, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rTargetController + ); + + private: + const ::std::auto_ptr< DatabaseDocumentRecovery_Data > m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // DBACCESS_DBDOCRECOVERY_HXX diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx new file mode 100644 index 000000000000..b22c19a07b6d --- /dev/null +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -0,0 +1,702 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "recovery/dbdocrecovery.hxx" +#include "sdbcoretools.hxx" +#include "dbastrings.hrc" + +/** === begin UNO includes === **/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/** === end UNO includes === **/ + +#include +#include +#include +#include +#include + +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::frame::XController; + using ::com::sun::star::sdb::application::XDatabaseDocumentUI; + using ::com::sun::star::frame::XModuleManager; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::document::XStorageBasedDocument; + using ::com::sun::star::beans::PropertyValue; + using ::com::sun::star::beans::Pair; + using ::com::sun::star::io::XStream; + using ::com::sun::star::io::XOutputStream; + using ::com::sun::star::io::XTextOutputStream; + using ::com::sun::star::io::XActiveDataSource; + using ::com::sun::star::io::XTextInputStream; + using ::com::sun::star::io::XActiveDataSink; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::util::XModifiable; + /** === end UNO using === **/ + + namespace ElementModes = ::com::sun::star::embed::ElementModes; + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; + + //==================================================================== + //= helpers + //==================================================================== + namespace + { + // ......................................................................... + enum SubComponentType + { + TABLE = DatabaseObject::TABLE, + QUERY = DatabaseObject::QUERY, + FORM = DatabaseObject::FORM, + REPORT = DatabaseObject::REPORT, + + RELATION_DESIGN = 1000, + + UNKNOWN = 10001 + }; + + struct SubComponentDescriptor + { + ::rtl::OUString sName; + bool bForEditing; + + SubComponentDescriptor() + :sName() + ,bForEditing( false ) + { + } + + SubComponentDescriptor( const ::rtl::OUString& i_rName, const bool i_bForEditing ) + :sName( i_rName ) + ,bForEditing( i_bForEditing ) + { + } + }; + + // ......................................................................... + typedef ::std::hash_map< ::rtl::OUString, SubComponentDescriptor, ::rtl::OUStringHash > MapStringToCompDesc; + typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; + + // ......................................................................... + void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) + { + o_rBuffer.append( i_rComponentDesc.first ); + o_rBuffer.append( sal_Unicode( '=' ) ); + o_rBuffer.append( i_rComponentDesc.second.sName ); + o_rBuffer.append( sal_Unicode( ',' ) ); + o_rBuffer.append( sal_Unicode( i_rComponentDesc.second.bForEditing ? '1' : '0' ) ); + } + + // ......................................................................... + bool lcl_extractCompDesc( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rStorName, SubComponentDescriptor& o_rCompDesc ) + { + const sal_Int32 nEqualSignPos = i_rIniLine.indexOf( sal_Unicode( '=' ) ); + if ( nEqualSignPos < 1 ) + { + OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of '='" ); + return false; + } + o_rStorName = i_rIniLine.copy( 0, nEqualSignPos ); + + const sal_Int32 nCommaPos = i_rIniLine.lastIndexOf( sal_Unicode( ',' ) ); + if ( nCommaPos != i_rIniLine.getLength() - 2 ) + { + OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of ','" ); + return false; + } + o_rCompDesc.sName = i_rIniLine.copy( nEqualSignPos + 1, nCommaPos - nEqualSignPos - 1 ); + o_rCompDesc.bForEditing = ( i_rIniLine.getStr()[ nCommaPos + 1 ] == '1' ); + return true; + } + + // ......................................................................... + SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) + { + switch ( i_nObjectType ) + { + case DatabaseObject::TABLE: return TABLE; + case DatabaseObject::QUERY: return QUERY; + case DatabaseObject::FORM: return FORM; + case DatabaseObject::REPORT:return REPORT; + default: + break; + } + return UNKNOWN; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() + { + static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); + return s_sRecDataStorName; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) + { + static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); + static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); + static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) ); + static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) ); + static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) ); + + switch ( i_eType ) + { + case FORM: + return s_sFormsStorageName; + case REPORT: + return s_sReportsStorageName; + case TABLE: + return s_sTablesStorageName; + case QUERY: + return s_sQueriesStorageName; + case RELATION_DESIGN: + return s_sRelationsStorageName; + default: + break; + } + + OSL_ENSURE( false, "lcl_getComponentsStorageName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getObjectMapStreamName() + { + static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); + return s_sObjectMapStreamName; + } + + // ......................................................................... + const ::rtl::OUString& lcl_getMapStreamEncodingName() + { + static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); + return s_sMapStreamEncodingName; + } + + // ......................................................................... + void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + const MapStringToCompDesc& i_mapStorageToCompDesc ) + { + if ( i_mapStorageToCompDesc.empty() ) + // nothing to do + return; + + ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); + Reference< XStream > xIniStream( i_rStorage->openStreamElement( + lcl_getObjectMapStreamName(), ElementModes::WRITE | ElementModes::TRUNCATE ), UNO_SET_THROW ); + + Reference< XTextOutputStream > xTextOutput( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); + xTextOutput->setEncoding( lcl_getMapStreamEncodingName() ); + + Reference< XActiveDataSource > xDataSource( xTextOutput, UNO_QUERY_THROW ); + xDataSource->setOutputStream( xIniStream->getOutputStream() ); + + const ::rtl::OUString sLineFeed( sal_Unicode( '\n' ) ); + xTextOutput->writeString( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); + xTextOutput->writeString( sLineFeed ); + + for ( MapStringToCompDesc::const_iterator stor = i_mapStorageToCompDesc.begin(); + stor != i_mapStorageToCompDesc.end(); + ++stor + ) + { + ::rtl::OUStringBuffer aLine; + lcl_getPersistentRepresentation( *stor, aLine ); + aLine.append( sLineFeed ); + + xTextOutput->writeString( aLine.makeStringAndClear() ); + } + + xTextOutput->writeString( sLineFeed ); + } + + // ......................................................................... + bool lcl_isSectionStart( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rSectionName ) + { + const sal_Int32 nLen = i_rIniLine.getLength(); + if ( ( nLen > 0 ) && ( i_rIniLine.getStr()[0] == '[' ) && ( i_rIniLine.getStr()[ nLen - 1 ] == ']' ) ) + { + o_rSectionName = i_rIniLine.copy( 1, nLen -2 ); + return true; + } + return false; + } + + // ......................................................................... + void lcl_stripTrailingLineFeed( ::rtl::OUString& io_rLine ) + { + const sal_Int32 nLen = io_rLine.getLength(); + if ( ( nLen > 0 ) && ( io_rLine.getStr()[ nLen - 1 ] == '\n' ) ) + io_rLine = io_rLine.copy( 0, nLen - 1 ); + } + + // ......................................................................... + void lcl_readObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + MapStringToCompDesc& o_mapStorageToObjectName ) + { + ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); + if ( !i_rStorage->hasByName( lcl_getObjectMapStreamName() ) ) + { // nothing to do, though suspicious + OSL_ENSURE( false, "lcl_readObjectMap_throw: if there's no map file, then there's expected to be no storage, too!" ); + return; + } + + Reference< XStream > xIniStream( i_rStorage->openStreamElement( + lcl_getObjectMapStreamName(), ElementModes::READ ), UNO_SET_THROW ); + + Reference< XTextInputStream > xTextInput( i_rContext.createComponent( "com.sun.star.io.TextInputStream" ), UNO_QUERY_THROW ); + xTextInput->setEncoding( lcl_getMapStreamEncodingName() ); + + Reference< XActiveDataSink > xDataSink( xTextInput, UNO_QUERY_THROW ); + xDataSink->setInputStream( xIniStream->getInputStream() ); + + ::rtl::OUString sCurrentSection; + bool bCurrentSectionIsKnownToBeUnsupported = true; + while ( !xTextInput->isEOF() ) + { + ::rtl::OUString sLine = xTextInput->readLine(); + lcl_stripTrailingLineFeed( sLine ); + + if ( sLine.getLength() == 0 ) + continue; + + if ( lcl_isSectionStart( sLine, sCurrentSection ) ) + { + bCurrentSectionIsKnownToBeUnsupported = false; + continue; + } + + if ( bCurrentSectionIsKnownToBeUnsupported ) + continue; + + // the only section we support so far is "storages" + if ( !sCurrentSection.equalsAscii( "storages" ) ) + { + bCurrentSectionIsKnownToBeUnsupported = true; + continue; + } + + ::rtl::OUString sStorageName; + SubComponentDescriptor aCompDesc; + if ( !lcl_extractCompDesc( sLine, sStorageName, aCompDesc ) ) + continue; + o_mapStorageToObjectName[ sStorageName ] = aCompDesc; + } + } + + // ......................................................................... + bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) + { + Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); + if ( !xDocument.is() ) + { + Reference< XController > xController( i_rComponent, UNO_QUERY_THROW ); + xDocument = xController->getModel(); + } + + if ( !xDocument.is() ) + return false; + + ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() ); + return aDocArgs.getOrDefault( "ReadOnly", false ); + } + + // ......................................................................... + void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) + { + const Reference< XModifiable > xModify( i_rSubComponent, UNO_QUERY ); + if ( !xModify.is() ) + { + OSL_ENSURE( false, "lcl_markModified: unhandled case!" ); + return; + } + + xModify->setModified( sal_True ); + } + } + + //==================================================================== + //= DatabaseDocumentRecovery_Data + //==================================================================== + struct DatabaseDocumentRecovery_Data + { + const ::comphelper::ComponentContext aContext; + + DatabaseDocumentRecovery_Data( const ::comphelper::ComponentContext& i_rContext ) + :aContext( i_rContext ) + { + } + }; + + //==================================================================== + //= SubComponentRecovery + //==================================================================== + class SubComponentRecovery + { + public: + SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XDatabaseDocumentUI >& i_rController, + const Reference< XComponent >& i_rComponent ) + :m_rContext( i_rContext ) + ,m_xComponent( i_rComponent ) + ,m_eType( UNKNOWN ) + ,m_aCompDesc() + { + impl_identifyComponent_throw( i_rController ); + } + + void saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapCompTypeToCompDescs& io_mapCompDescs ); + + private: + void impl_saveSubDocument_throw( + const Reference< XStorage >& i_rRecoveryStorage, + MapStringToCompDesc& io_mapStorageToCompDesc + ); + + void impl_identifyComponent_throw( + const Reference< XDatabaseDocumentUI >& i_rController + ); + + private: + const ::comphelper::ComponentContext& m_rContext; + const Reference< XComponent > m_xComponent; + SubComponentType m_eType; + SubComponentDescriptor m_aCompDesc; + }; + + //-------------------------------------------------------------------- + void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, + MapCompTypeToCompDescs& io_mapCompDescs ) + { + + if ( m_eType == UNKNOWN ) + // quite fatal, but has already been reported (as assertion) before + return; + + switch ( m_eType ) + { + case FORM: + case REPORT: + impl_saveSubDocument_throw( i_rRecoveryStorage, io_mapCompDescs[ m_eType ] ); + break; + + default: + // TODO + OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); + break; + } + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_identifyComponent_throw( const Reference< XDatabaseDocumentUI >& i_rController ) + { + ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); + + // ask the controller + Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = i_rController->identifySubComponent( m_xComponent ); + m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First ); + m_aCompDesc.sName = aComponentIdentity.Second; + + // what the controller didn't give us is the information whether this is in edit mode or not ... + Reference< XModuleManager > xModuleManager( m_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); + const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent ); + + switch ( m_eType ) + { + case TABLE: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.TableDesign" ); + break; + + case QUERY: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.QueryDesign" ); + break; + + case REPORT: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.report.ReportDefinition" ) ) + { + // it's an SRB report desginer + m_aCompDesc.bForEditing = true; + break; + } + // fall through + + case FORM: + m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent ); + break; + + default: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.sdb.RelationDesign" ) ) + { + m_eType = RELATION_DESIGN; + m_aCompDesc.bForEditing = true; + } + else + { + OSL_ENSURE( false, "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" ); + } + break; + } + + OSL_POSTCOND( m_eType != UNKNOWN, + "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" ); + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage, + MapStringToCompDesc& io_mapStorageToCompDesc ) + { + ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); + ENSURE_OR_THROW( i_rRecoveryStorage.is(), "illegal storage" ); + + // open the sub storage for the given kind of documents + const ::rtl::OUString& rStorageName( lcl_getComponentsStorageName( m_eType ) ); + const Reference< XStorage > xDocsStor( i_rRecoveryStorage->openStorageElement( + rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // find a free sub storage name, and create Yet Another Sub Storage + const ::rtl::OUString sBaseName( ::rtl::OUString::createFromAscii( m_eType == FORM ? "form" : "report" ) ); + const ::rtl::OUString sCompStorName = ::dbtools::createUniqueName( xDocsStor.get(), sBaseName, true ); + const Reference< XStorage > xCompStor( xDocsStor->openStorageElement( + sCompStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // store the document into the storage + Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); + xStorageDocument->storeToStorage( xCompStor, Sequence< PropertyValue >() ); + + // remember the relationship between the component name to the storage name + OSL_ENSURE( io_mapStorageToCompDesc.find( sCompStorName ) == io_mapStorageToCompDesc.end(), + "SubComponentRecoverys::impl_saveSubDocument_throw: object name already used!" ); + io_mapStorageToCompDesc[ sCompStorName ] = m_aCompDesc; + + // commit the storage for the documents collection + tools::stor::commitStorageIfWriteable( xDocsStor ); + } + + //==================================================================== + //= DatabaseDocumentRecovery + //==================================================================== + //-------------------------------------------------------------------- + DatabaseDocumentRecovery::DatabaseDocumentRecovery( const ::comphelper::ComponentContext& i_rContext ) + :m_pData( new DatabaseDocumentRecovery_Data( i_rContext ) ) + { + } + + //-------------------------------------------------------------------- + DatabaseDocumentRecovery::~DatabaseDocumentRecovery() + { + } + + //-------------------------------------------------------------------- + void DatabaseDocumentRecovery::saveModifiedSubComponents( const Reference< XStorage >& i_rTargetStorage, + const ::std::vector< Reference< XController > >& i_rControllers ) + { + ENSURE_OR_THROW( i_rTargetStorage.is(), "invalid document storage" ); + + // create a sub storage for recovery data + if ( i_rTargetStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + i_rTargetStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + Reference< XStorage > xRecoveryStorage = i_rTargetStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); + + // store recovery data for open sub components of the given controller(s) + if ( !i_rControllers.empty() ) + { + ENSURE_OR_THROW( i_rControllers.size() == 1, "can't handle more than one controller" ); + // At the moment, there can be only one view to a database document. If we ever allow for more than this, + // then we need a concept for sub documents opened from different controllers (i.e. two document views, + // and the user opens the very same form in both views). And depending on this, we need a concept for + // how those are saved to the recovery file. + + MapCompTypeToCompDescs aMapCompDescs; + + for ( ::std::vector< Reference< XController > >::const_iterator ctrl = i_rControllers.begin(); + ctrl != i_rControllers.end(); + ++ctrl + ) + { + Reference< XDatabaseDocumentUI > xDatabaseUI( *ctrl, UNO_QUERY_THROW ); + Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); + + const Reference< XComponent >* component = aComponents.getConstArray(); + const Reference< XComponent >* componentEnd = aComponents.getConstArray() + aComponents.getLength(); + for ( ; component != componentEnd; ++component ) + { + SubComponentRecovery aComponentRecovery( m_pData->aContext, xDatabaseUI, *component ); + aComponentRecovery.saveToRecoveryStorage( xRecoveryStorage, aMapCompDescs ); + } + } + + for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); + map != aMapCompDescs.end(); + ++map + ) + { + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + lcl_getComponentsStorageName( map->first ), ElementModes::WRITE | ElementModes::NOCREATE ) ); + lcl_writeObjectMap_throw( m_pData->aContext, xComponentsStor, map->second ); + tools::stor::commitStorageIfWriteable( xComponentsStor ); + } + } + + // commit the recovery storage + tools::stor::commitStorageIfWriteable( xRecoveryStorage ); + } + + //-------------------------------------------------------------------- + void DatabaseDocumentRecovery::recoverSubDocuments( const Reference< XStorage >& i_rDocumentStorage, + const Reference< XController >& i_rTargetController ) + { + ENSURE_OR_THROW( i_rDocumentStorage.is(), "illegal document storage" ); + Reference< XDatabaseDocumentUI > xDocumentUI( i_rTargetController, UNO_QUERY_THROW ); + + if ( !i_rDocumentStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + // that's allowed + return; + + // the "recovery" sub storage + Reference< XStorage > xRecoveryStorage = i_rDocumentStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READ ); + + // read the map from sub storages to object names + MapCompTypeToCompDescs aMapCompDescs; + SubComponentType aKnownTypes[] = { TABLE, QUERY, FORM, REPORT, RELATION_DESIGN }; + for ( size_t i = 0; i < sizeof( aKnownTypes ) / sizeof( aKnownTypes[0] ); ++i ) + { + if ( !xRecoveryStorage->hasByName( lcl_getComponentsStorageName( aKnownTypes[i] ) ) ) + continue; + + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + lcl_getComponentsStorageName( aKnownTypes[i] ), ElementModes::READ ) ); + lcl_readObjectMap_throw( m_pData->aContext, xComponentsStor, aMapCompDescs[ aKnownTypes[i] ] ); + xComponentsStor->dispose(); + } + + // recover all sub components as indicated by the map + for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); + map != aMapCompDescs.end(); + ++map + ) + { + const SubComponentType eComponentType = map->first; + if ( ( eComponentType != FORM ) && ( eComponentType != REPORT ) ) + { + // nobody saves tables/queries/relations at the moment, so encountering those is worth an assertion + OSL_ENSURE( false, "DatabaseDocumentRecovery::recoverSubDocuments: only embedded objects can be recovered currently!" ); + continue; + } + + // the storage for all components of the current type + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + lcl_getComponentsStorageName( eComponentType ), ElementModes::READ ), UNO_QUERY_THROW ); + + // loop thru all components of this type + for ( MapStringToCompDesc::const_iterator stor = map->second.begin(); + stor != map->second.end(); + ++stor + ) + { + const ::rtl::OUString sComponentName( stor->second.sName ); + if ( !xComponentsStor->hasByName( stor->first ) ) + { + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OStringBuffer message; + message.append( "DatabaseDocumentRecovery::recoverSubDocuments: inconsistent recovery storage: storage '" ); + message.append( ::rtl::OUStringToOString( stor->first, RTL_TEXTENCODING_ASCII_US ) ); + message.append( "' not found in '" ); + message.append( ::rtl::OUStringToOString( lcl_getComponentsStorageName( eComponentType ), RTL_TEXTENCODING_ASCII_US ) ); + message.append( "', but required per map file!" ); + OSL_ENSURE( false, message.makeStringAndClear() ); + #endif + continue; + } + + // the controller needs to have a connection to be able to open sub components + if ( !xDocumentUI->isConnected() ) + xDocumentUI->connect(); + + // recover the single component + Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "RecoveryStorage", xCompStor ); + + try + { + Reference< XComponent > xSubComponent; + if ( sComponentName.getLength() ) + { + xSubComponent = xDocumentUI->loadComponentWithArguments( eComponentType, sComponentName, + stor->second.bForEditing, aLoadArgs.getPropertyValues() ); + } + else + { + xSubComponent = xDocumentUI->createComponentWithArguments( eComponentType, aLoadArgs.getPropertyValues() ); + } + + // at the moment, we only store, during session save, sub components which are modified. So, set this + // recovered sub component to "modified", too. + lcl_markModified( xSubComponent ); + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + xComponentsStor->dispose(); + } + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/makefile.mk b/dbaccess/source/core/recovery/makefile.mk new file mode 100644 index 000000000000..55c1211d80d4 --- /dev/null +++ b/dbaccess/source/core/recovery/makefile.mk @@ -0,0 +1,52 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10.2.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=dbaccess +TARGET=recovery + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/dba.pmk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/dbdocrecovery.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/dbaccess/util/makefile.mk b/dbaccess/util/makefile.mk index 7b6909992c53..622d6355b65d 100644 --- a/dbaccess/util/makefile.mk +++ b/dbaccess/util/makefile.mk @@ -50,6 +50,7 @@ LIB1TARGET=$(SLB)$/$(TARGET).lib LIB1FILES=\ $(SLB)$/api.lib \ $(SLB)$/dataaccess.lib \ + $(SLB)$/recovery.lib \ $(SLB)$/misc.lib \ $(SLB)$/core_resource.lib -- cgit From 09af8ffba3b5311161092ae3d37087e001fa0e0d Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 28 Jan 2010 22:36:35 +0100 Subject: autorecovery: removed a few IMO useless dependencies --- dbaccess/prj/build.lst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/prj/build.lst b/dbaccess/prj/build.lst index f9ba2e4abd5f..0b6122d413ab 100644 --- a/dbaccess/prj/build.lst +++ b/dbaccess/prj/build.lst @@ -3,10 +3,10 @@ ba dbaccess usr1 - all ba_mkout NULL ba dbaccess\inc nmake - all ba_inc NULL ba dbaccess\source\ui\inc nmake - all ba_uiinc ba_inc NULL ba dbaccess\source\core\api nmake - all ba_capi ba_inc NULL -ba dbaccess\source\core\dataaccess nmake - all ba_cdaccess ba_capi ba_inc NULL +ba dbaccess\source\core\dataaccess nmake - all ba_cdaccess ba_inc NULL ba dbaccess\source\core\recovery nmake - all ba_crecovery ba_inc NULL -ba dbaccess\source\core\misc nmake - all ba_cmisc ba_cdaccess ba_inc NULL -ba dbaccess\source\core\resource nmake - all ba_cres ba_cmisc ba_inc NULL +ba dbaccess\source\core\misc nmake - all ba_cmisc ba_inc NULL +ba dbaccess\source\core\resource nmake - all ba_cres ba_inc NULL ba dbaccess\source\filter\xml nmake - all ba_ffilter ba_shared ba_util ba_inc NULL ba dbaccess\source\filter\migration nmake - all ba_fmigration ba_shared ba_inc NULL ba dbaccess\source\shared nmake - all ba_shared ba_cres ba_inc NULL @@ -23,8 +23,8 @@ ba dbaccess\source\ui\misc nmake - all ba_uimisc ba_inc NULL ba dbaccess\source\ui\querydesign nmake - all ba_uiquery ba_uiinc ba_inc NULL ba dbaccess\source\ui\relationdesign nmake - all ba_uirelationdesign ba_uiinc ba_inc NULL ba dbaccess\source\ui\tabledesign nmake - all ba_uitabledesign ba_uiinc ba_inc NULL -ba dbaccess\source\ui\uno nmake - all ba_uiuno ba_uimisc ba_inc NULL +ba dbaccess\source\ui\uno nmake - all ba_uiuno ba_inc NULL ba dbaccess\source\ui\imagelists nmake - all ba_uiimglst ba_inc NULL -ba dbaccess\util nmake - all ba_util ba_uiimglst ba_capi ba_crecovery ba_shared ba_uibrowser ba_uiapp ba_uicontrol ba_uidlg ba_uimisc ba_uiquery ba_uitabledesign ba_uirelationdesign ba_uiuno ba_conntools ba_misctools ba_miscres ba_ext_adabasui NULL +ba dbaccess\util nmake - all ba_util ba_uiimglst ba_capi ba_cdaccess ba_cmisc ba_crecovery ba_shared ba_uibrowser ba_uiapp ba_uicontrol ba_uidlg ba_uimisc ba_uiquery ba_uitabledesign ba_uirelationdesign ba_uiuno ba_conntools ba_misctools ba_miscres ba_ext_adabasui NULL ba dbaccess\win32\source\odbcconfig nmake - w ba_odbcconfig ba_inc NULL ba dbaccess\qa\complex\dbaccess nmake - all ba_complex_tests NULL -- cgit From 0a8fa850daff277e2fe6aef3a483ee2817bcd3db Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 29 Jan 2010 08:50:19 +0100 Subject: autorecovery: removed dbdocrecovery.obj, should have happened when the cxx file was moved --- dbaccess/source/core/dataaccess/makefile.mk | 1 - 1 file changed, 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/makefile.mk b/dbaccess/source/core/dataaccess/makefile.mk index f74188527c6f..c48056ea836f 100644 --- a/dbaccess/source/core/dataaccess/makefile.mk +++ b/dbaccess/source/core/dataaccess/makefile.mk @@ -65,7 +65,6 @@ SLOFILES= \ $(SLO)$/documentevents.obj \ $(SLO)$/documenteventexecutor.obj \ $(SLO)$/documenteventnotifier.obj \ - $(SLO)$/dbdocrecovery.obj # --- Targets ---------------------------------- -- cgit From e1e25bdd16958a72c952ccb9eb70f05636637e9d Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 29 Jan 2010 10:12:25 +0100 Subject: dba33f: when re-activating an embedded object, do not reset its modified state (plus do not the other initializations which are needed for the first activation only) --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 8 ++++---- dbaccess/source/core/dataaccess/documentdefinition.hxx | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 50f391c64afb..4687b7cfdd34 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -741,7 +741,7 @@ void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const Reference< XF } // ----------------------------------------------------------------------------- -void ODocumentDefinition::impl_onActivateEmbeddedObject() +void ODocumentDefinition::impl_onActivateEmbeddedObject( const bool i_bReactivated ) { try { @@ -771,7 +771,7 @@ void ODocumentDefinition::impl_onActivateEmbeddedObject() LifetimeCoupler::couple( *this, Reference< XComponent >( xFrame, UNO_QUERY_THROW ) ); // init the edit view - if ( m_bOpenInDesign ) + if ( m_bOpenInDesign && !i_bReactivated ) impl_initObjectEditView( xController ); } catch( const RuntimeException& ) @@ -1085,7 +1085,7 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con if ( _bActivate && !bOpenHidden ) { m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); - impl_onActivateEmbeddedObject(); + impl_onActivateEmbeddedObject( false ); } // LLA: Alle fillReportData() calls prfen, sollte es welche geben, die danach noch viel machen @@ -1126,7 +1126,7 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co if ( bIsActive && !bIsAliveNewStyleReport ) { - impl_onActivateEmbeddedObject(); + impl_onActivateEmbeddedObject( true ); return makeAny( getComponent() ); } } diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 32ec2c68a083..9fc32364cb0a 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -217,10 +217,8 @@ public: private: /** does necessary initializations after our embedded object has been switched to ACTIVE - @param _bOpenedInDesignMode - determines whether the embedded object has been opened for designing it or for data display */ - void impl_onActivateEmbeddedObject(); + void impl_onActivateEmbeddedObject( const bool i_bReactivated ); /** initializes a newly created view/controller which is displaying our embedded object -- cgit From b7b66e1606387cf439990274ce45b771085b4434 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 29 Jan 2010 13:04:04 +0100 Subject: autorecovery: recover forms/reports hidden, and show them when the main window is shown --- .../source/core/dataaccess/documentdefinition.cxx | 89 ++++++++++- .../source/core/dataaccess/documentdefinition.hxx | 6 + .../source/core/inc/recovery/dbdocrecovery.hxx | 4 +- dbaccess/source/core/recovery/dbdocrecovery.cxx | 101 ++++++++++--- dbaccess/source/core/recovery/makefile.mk | 3 +- .../source/core/recovery/subcomponentloader.cxx | 165 +++++++++++++++++++++ .../source/core/recovery/subcomponentloader.hxx | 82 ++++++++++ 7 files changed, 424 insertions(+), 26 deletions(-) create mode 100644 dbaccess/source/core/recovery/subcomponentloader.cxx create mode 100644 dbaccess/source/core/recovery/subcomponentloader.hxx (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 4687b7cfdd34..61c0463f8ba4 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -252,6 +252,7 @@ #include #include #include +#include using namespace ::com::sun::star; using namespace view; @@ -417,6 +418,40 @@ namespace dbaccess inline void resetClient(ODocumentDefinition* _pClient) { m_pClient = _pClient; } }; + //================================================================== + // LockModifiable + //================================================================== + class LockModifiable + { + public: + LockModifiable( const Reference< XInterface >& i_rModifiable ) + :m_xModifiable( i_rModifiable, UNO_QUERY ) + { + OSL_ENSURE( m_xModifiable.is(), "LockModifiable::LockModifiable: invalid component!" ); + if ( m_xModifiable.is() ) + { + if ( !m_xModifiable->isSetModifiedEnabled() ) + { + // somebody already locked that, no need to lock it, again, and no need to unlock it later + m_xModifiable.clear(); + } + else + { + m_xModifiable->disableSetModified(); + } + } + } + + ~LockModifiable() + { + if ( m_xModifiable.is() ) + m_xModifiable->enableSetModified(); + } + + private: + Reference< XModifiable2 > m_xModifiable; + }; + //================================================================== // LifetimeCoupler //================================================================== @@ -885,6 +920,9 @@ void ODocumentDefinition::impl_initObjectEditView( const Reference< XController Reference< XViewSettingsSupplier > xSettingsSupplier( _rxController, UNO_QUERY_THROW ); Reference< XPropertySet > xViewSettings( xSettingsSupplier->getViewSettings(), UNO_QUERY_THROW ); + // the below code could indirectly tamper with the "modified" flag of the model, temporarily disable this + LockModifiable aLockModify( _rxController->getModel() ); + // The visual area size can be changed by the setting of the following properties // so it should be restored later PreserveVisualAreaSize aPreserveVisAreaSize( _rxController->getModel() ); @@ -902,9 +940,6 @@ void ODocumentDefinition::impl_initObjectEditView( const Reference< XController xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")),makeAny(sal_True)); xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RasterSubdivisionX")),makeAny(sal_Int32(5))); xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RasterSubdivisionY")),makeAny(sal_Int32(5))); - - Reference< XModifiable > xModifiable( _rxController->getModel(), UNO_QUERY_THROW ); - xModifiable->setModified( sal_False ); } catch( const Exception& ) { @@ -912,6 +947,39 @@ void ODocumentDefinition::impl_initObjectEditView( const Reference< XController } } +// ----------------------------------------------------------------------------- +void ODocumentDefinition::impl_showOrHideComponent_throw( const bool i_bShow ) +{ + const sal_Int32 nCurrentState = m_xEmbeddedObject.is() ? m_xEmbeddedObject->getCurrentState() : EmbedStates::LOADED; + switch ( nCurrentState ) + { + default: + case EmbedStates::LOADED: + throw embed::WrongStateException( ::rtl::OUString(), *this ); + + case EmbedStates::RUNNING: + if ( !i_bShow ) + // fine, a running (and not yet active) object is never visible + return; + { + LockModifiable aLockModify( impl_getComponent_throw() ); + m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); + impl_onActivateEmbeddedObject( false ); + } + break; + + case EmbedStates::ACTIVE: + { + Reference< XModel > xEmbeddedDoc( impl_getComponent_throw( true ), UNO_QUERY_THROW ); + Reference< XController > xEmbeddedController( xEmbeddedDoc->getCurrentController(), UNO_SET_THROW ); + Reference< XFrame > xEmbeddedFrame( xEmbeddedController->getFrame(), UNO_SET_THROW ); + Reference< XWindow > xEmbeddedWindow( xEmbeddedFrame->getContainerWindow(), UNO_SET_THROW ); + xEmbeddedWindow->setVisible( i_bShow ); + } + break; + } +} + // ----------------------------------------------------------------------------- void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate, const Reference< XCommandEnvironment >& _rxEnvironment, Any& _out_rComponent, ::osl::ClearableMutexGuard & _aGuard ) @@ -1084,6 +1152,7 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con if ( _bActivate && !bOpenHidden ) { + LockModifiable aLockModify( impl_getComponent_throw() ); m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); impl_onActivateEmbeddedObject( false ); } @@ -1131,12 +1200,17 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co } } - // m_bOpenInDesign = bOpenInDesign; - // onCommandOpenSomething( aCommand.Argument, !bOpenForMail, Environment, aRet, aGuard ); - m_bOpenInDesign = bOpenInDesign || bOpenForMail; onCommandOpenSomething( aCommand.Argument, bActivateObject, Environment, aRet, aGuard ); } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "show" ) ) ) + { + impl_showOrHideComponent_throw( true ); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "hide" ) ) ) + { + impl_showOrHideComponent_throw( false ); + } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "copyTo" ) ) ) { Sequence aIni; @@ -1792,8 +1866,9 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x m_xEmbeddedObject->changeState(EmbedStates::RUNNING); if ( bSetSize ) { - awt::Size aSize( DEFAULT_WIDTH, DEFAULT_HEIGHT ); + LockModifiable aLockModify( impl_getComponent_throw( false ) ); + awt::Size aSize( DEFAULT_WIDTH, DEFAULT_HEIGHT ); m_xEmbeddedObject->setVisualAreaSize(Aspects::MSOLE_CONTENT,aSize); } } diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 9fc32364cb0a..28cbc34710e6 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -253,6 +253,12 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > impl_getComponent_throw( const bool i_ForceCreate = true ); + /** shows or hides our component + + The embedded object must exist, and be in state LOADED, at least. + */ + void impl_showOrHideComponent_throw( const bool i_bShow ); + // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; diff --git a/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx b/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx index 0bf44e2bf3e8..4aa124dc7015 100644 --- a/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx +++ b/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx @@ -26,6 +26,8 @@ #ifndef DBACCESS_DBDOCRECOVERY_HXX #define DBACCESS_DBDOCRECOVERY_HXX +#include "dbaccessdllapi.h" + /** === begin UNO includes === **/ #include #include @@ -48,7 +50,7 @@ namespace dbaccess //= DatabaseDocumentRecovery //==================================================================== struct DatabaseDocumentRecovery_Data; - class DatabaseDocumentRecovery + class DBACCESS_DLLPRIVATE DatabaseDocumentRecovery { public: DatabaseDocumentRecovery( diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx index b22c19a07b6d..bf2a68987bb1 100644 --- a/dbaccess/source/core/recovery/dbdocrecovery.cxx +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -27,6 +27,7 @@ #include "recovery/dbdocrecovery.hxx" #include "sdbcoretools.hxx" +#include "subcomponentloader.hxx" #include "dbastrings.hrc" /** === begin UNO includes === **/ @@ -40,6 +41,10 @@ #include #include #include +#include +#include +#include +#include /** === end UNO includes === **/ #include @@ -84,6 +89,10 @@ namespace dbaccess using ::com::sun::star::io::XActiveDataSink; using ::com::sun::star::frame::XModel; using ::com::sun::star::util::XModifiable; + using ::com::sun::star::sdb::XFormDocumentsSupplier; + using ::com::sun::star::sdb::XReportDocumentsSupplier; + using ::com::sun::star::ucb::XCommandProcessor; + using ::com::sun::star::container::XHierarchicalNameAccess; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; @@ -107,7 +116,7 @@ namespace dbaccess UNKNOWN = 10001 }; - struct SubComponentDescriptor + struct DBACCESS_DLLPRIVATE SubComponentDescriptor { ::rtl::OUString sName; bool bForEditing; @@ -130,7 +139,7 @@ namespace dbaccess typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; // ......................................................................... - void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) + static void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) { o_rBuffer.append( i_rComponentDesc.first ); o_rBuffer.append( sal_Unicode( '=' ) ); @@ -140,7 +149,7 @@ namespace dbaccess } // ......................................................................... - bool lcl_extractCompDesc( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rStorName, SubComponentDescriptor& o_rCompDesc ) + static bool lcl_extractCompDesc( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rStorName, SubComponentDescriptor& o_rCompDesc ) { const sal_Int32 nEqualSignPos = i_rIniLine.indexOf( sal_Unicode( '=' ) ); if ( nEqualSignPos < 1 ) @@ -162,7 +171,7 @@ namespace dbaccess } // ......................................................................... - SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) + static SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) { switch ( i_nObjectType ) { @@ -177,14 +186,14 @@ namespace dbaccess } // ......................................................................... - const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() + static const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() { static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); return s_sRecDataStorName; } // ......................................................................... - const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) + static const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) { static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); @@ -214,21 +223,21 @@ namespace dbaccess } // ......................................................................... - const ::rtl::OUString& lcl_getObjectMapStreamName() + static const ::rtl::OUString& lcl_getObjectMapStreamName() { static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); return s_sObjectMapStreamName; } // ......................................................................... - const ::rtl::OUString& lcl_getMapStreamEncodingName() + static const ::rtl::OUString& lcl_getMapStreamEncodingName() { static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); return s_sMapStreamEncodingName; } // ......................................................................... - void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + static void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, const MapStringToCompDesc& i_mapStorageToCompDesc ) { if ( i_mapStorageToCompDesc.empty() ) @@ -265,7 +274,7 @@ namespace dbaccess } // ......................................................................... - bool lcl_isSectionStart( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rSectionName ) + static bool lcl_isSectionStart( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rSectionName ) { const sal_Int32 nLen = i_rIniLine.getLength(); if ( ( nLen > 0 ) && ( i_rIniLine.getStr()[0] == '[' ) && ( i_rIniLine.getStr()[ nLen - 1 ] == ']' ) ) @@ -277,7 +286,7 @@ namespace dbaccess } // ......................................................................... - void lcl_stripTrailingLineFeed( ::rtl::OUString& io_rLine ) + static void lcl_stripTrailingLineFeed( ::rtl::OUString& io_rLine ) { const sal_Int32 nLen = io_rLine.getLength(); if ( ( nLen > 0 ) && ( io_rLine.getStr()[ nLen - 1 ] == '\n' ) ) @@ -285,7 +294,7 @@ namespace dbaccess } // ......................................................................... - void lcl_readObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + static void lcl_readObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, MapStringToCompDesc& o_mapStorageToObjectName ) { ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); @@ -339,7 +348,7 @@ namespace dbaccess } // ......................................................................... - bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) + static bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) { Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); if ( !xDocument.is() ) @@ -356,7 +365,7 @@ namespace dbaccess } // ......................................................................... - void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) + static void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) { const Reference< XModifiable > xModify( i_rSubComponent, UNO_QUERY ); if ( !xModify.is() ) @@ -367,6 +376,36 @@ namespace dbaccess xModify->setModified( sal_True ); } + + // ......................................................................... + static Reference< XCommandProcessor > lcl_getSubComponentDef_nothrow( const Reference< XController >& i_rAppUI, + SubComponentType i_eType, const ::rtl::OUString& i_rName ) + { + ENSURE_OR_RETURN( i_rAppUI.is(), "lcl_getSubComponentDef_nothrow: illegal controller", NULL ); + ENSURE_OR_RETURN( ( i_eType == FORM ) || ( i_eType == REPORT ), "lcl_getSubComponentDef_nothrow: illegal controller", NULL ); + + Reference< XCommandProcessor > xCommandProcessor; + try + { + Reference< XHierarchicalNameAccess > xDefinitionContainer; + if ( i_eType == FORM ) + { + Reference< XFormDocumentsSupplier > xSuppForms( i_rAppUI->getModel(), UNO_QUERY_THROW ); + xDefinitionContainer.set( xSuppForms->getFormDocuments(), UNO_QUERY_THROW ); + } + else + { + Reference< XReportDocumentsSupplier > xSuppReports( i_rAppUI->getModel(), UNO_QUERY_THROW ); + xDefinitionContainer.set( xSuppReports->getReportDocuments(), UNO_QUERY_THROW ); + } + xCommandProcessor.set( xDefinitionContainer->getByHierarchicalName( i_rName ), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return xCommandProcessor; + } } //==================================================================== @@ -670,17 +709,45 @@ namespace dbaccess ::comphelper::NamedValueCollection aLoadArgs; aLoadArgs.put( "RecoveryStorage", xCompStor ); + // load/create the sub component hidden. We'll show it when the main app window is shown. + aLoadArgs.put( "Hidden", true ); + try { Reference< XComponent > xSubComponent; + Reference< XCommandProcessor > xDocDefinition; + if ( sComponentName.getLength() ) { - xSubComponent = xDocumentUI->loadComponentWithArguments( eComponentType, sComponentName, - stor->second.bForEditing, aLoadArgs.getPropertyValues() ); + xDocDefinition = lcl_getSubComponentDef_nothrow( i_rTargetController, eComponentType, sComponentName ); + xSubComponent.set( xDocumentUI->loadComponentWithArguments( + eComponentType, + sComponentName, + stor->second.bForEditing, + aLoadArgs.getPropertyValues() + ), + UNO_SET_THROW + ); } else { - xSubComponent = xDocumentUI->createComponentWithArguments( eComponentType, aLoadArgs.getPropertyValues() ); + Reference< XComponent > xDocDefComponent; + xSubComponent.set( xDocumentUI->createComponentWithArguments( + eComponentType, + aLoadArgs.getPropertyValues(), + xDocDefComponent + ), + UNO_SET_THROW + ); + + xDocDefinition.set( xDocDefComponent, UNO_QUERY ); + OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" ); + } + + if ( xDocDefinition.is() ) + { + Reference< XInterface > xLoader( *new SubComponentLoader( i_rTargetController, xDocDefinition ) ); + (void)xLoader; } // at the moment, we only store, during session save, sub components which are modified. So, set this diff --git a/dbaccess/source/core/recovery/makefile.mk b/dbaccess/source/core/recovery/makefile.mk index 55c1211d80d4..2a69495c4044 100644 --- a/dbaccess/source/core/recovery/makefile.mk +++ b/dbaccess/source/core/recovery/makefile.mk @@ -44,7 +44,8 @@ ENABLE_EXCEPTIONS=TRUE # --- Files ------------------------------------- SLOFILES= \ - $(SLO)$/dbdocrecovery.obj + $(SLO)$/dbdocrecovery.obj \ + $(SLO)$/subcomponentloader.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/recovery/subcomponentloader.cxx b/dbaccess/source/core/recovery/subcomponentloader.cxx new file mode 100644 index 000000000000..53d27bb93d47 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentloader.cxx @@ -0,0 +1,165 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "subcomponentloader.hxx" + +/** === begin UNO includes === **/ +#include +#include +/** === end UNO includes === **/ + +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::frame::XController; + using ::com::sun::star::frame::XFrame; + using ::com::sun::star::awt::XWindow; + using ::com::sun::star::awt::WindowEvent; + using ::com::sun::star::lang::EventObject; + using ::com::sun::star::ucb::Command; + using ::com::sun::star::ucb::XCommandProcessor; + using ::com::sun::star::frame::XController2; + /** === end UNO using === **/ + + //==================================================================== + //= SubComponentLoader + //==================================================================== + struct DBACCESS_DLLPRIVATE SubComponentLoader_Data + { + const Reference< XCommandProcessor > xDocDefCommands; + Reference< XWindow > xAppComponentWindow; + + SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition ) + :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW ) + { + } + }; + + //==================================================================== + //= helper + //==================================================================== + namespace + { + //................................................................ + void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData ) + { + try + { + Command aCommandOpen; + aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) ); + + const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier(); + i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } + + //==================================================================== + //= SubComponentLoader + //==================================================================== + //-------------------------------------------------------------------- + SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController, + const Reference< XCommandProcessor >& i_rSubDocumentDefinition ) + :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) ) + { + // add as window listener to the controller's container window, so we get notified when it is shown + Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW ); + m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW ); + + osl_incrementInterlockedCount( &m_refCount ); + { + m_pData->xAppComponentWindow->addWindowListener( this ); + } + osl_decrementInterlockedCount( &m_refCount ); + } + + //-------------------------------------------------------------------- + SubComponentLoader::~SubComponentLoader() + { + delete m_pData, m_pData = NULL; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException) + { + (void)i_rEvent; + + lcl_onWindowShown_nothrow( *m_pData ); + m_pData->xAppComponentWindow->removeWindowListener( this ); + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/subcomponentloader.hxx b/dbaccess/source/core/recovery/subcomponentloader.hxx new file mode 100644 index 000000000000..7efaea016724 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentloader.hxx @@ -0,0 +1,82 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef SUBCOMPONENTLOADER_HXX +#define SUBCOMPONENTLOADER_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include +#include +#include +#include +/** === end UNO includes === **/ + +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= SubComponentLoader + //==================================================================== + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::awt::XWindowListener + > SubComponentLoader_Base; + struct SubComponentLoader_Data; + /** is a helper class which loads/opens a given sub component as soon as the main application + window becomes visible. + */ + class DBACCESS_DLLPRIVATE SubComponentLoader : public SubComponentLoader_Base + { + public: + SubComponentLoader( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rApplicationController, + const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandProcessor >& i_rSubDocumentDefinition + ); + + // XWindowListener + virtual void SAL_CALL windowResized( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL windowMoved( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL windowShown( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL windowHidden( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + protected: + virtual ~SubComponentLoader(); + + private: + SubComponentLoader_Data* m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SUBCOMPONENTLOADER_HXX -- cgit From f2478cdcebdb39d87e81f18d1bc3aa73198fc344 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 29 Jan 2010 13:06:38 +0100 Subject: autorecovery: recover-hidden now also available for new (yet unsaved) forms/reports --- dbaccess/source/ui/app/AppController.cxx | 14 +++++++++----- dbaccess/source/ui/app/AppController.hxx | 10 +++++++--- dbaccess/source/ui/app/AppControllerGen.cxx | 9 +++++---- dbaccess/source/ui/misc/linkeddocuments.cxx | 23 +++++++++++++++++------ 4 files changed, 38 insertions(+), 18 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 9e6890f728eb..8af3a6692c53 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -1374,7 +1374,10 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa if ( bAutoPilot ) getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) ); else - newElement( eType, aCreationArgs ); + { + Reference< XComponent > xDocDefinition; + newElement( eType, aCreationArgs, xDocDefinition ); + } } break; case SID_APP_NEW_FOLDER: @@ -2073,12 +2076,13 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) } // ----------------------------------------------------------------------------- -Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments ) +Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments, + Reference< XComponent >& o_rDocumentDefinition ) { OSL_ENSURE(getContainer(),"View is NULL! -> GPF"); Reference< XComponent > xComponent; - Reference< XComponent > xDefinition; + o_rDocumentDefinition.clear(); switch ( _eType ) { @@ -2089,7 +2093,7 @@ Reference< XComponent > OApplicationController::newElement( ElementType _eType, if ( !aHelper->isConnected() ) break; - xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, xDefinition ); + xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition ); } break; @@ -2121,7 +2125,7 @@ Reference< XComponent > OApplicationController::newElement( ElementType _eType, } if ( xComponent.is() ) - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); + onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition ); return xComponent; } diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx index 16c13fad2e12..de0d6d6599f3 100644 --- a/dbaccess/source/ui/app/AppController.hxx +++ b/dbaccess/source/ui/app/AppController.hxx @@ -201,7 +201,11 @@ namespace dbaui Additional arguments to pass when creating the component */ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments ); + newElement( + ElementType _eType, + const ::comphelper::NamedValueCollection& i_rAdditionalArguments, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_rDocumentDefinition + ); /** creates a new database object, using an auto pilot @param _eType @@ -468,8 +472,8 @@ namespace dbaui virtual ::sal_Bool SAL_CALL closeSubComponents( ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponent( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponentWithArguments( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponent( ::sal_Int32 ObjectType ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponentWithArguments( ::sal_Int32 ObjectType, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponent( ::sal_Int32 ObjectType, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_DocumentDefinition ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponentWithArguments( ::sal_Int32 ObjectType, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_DocumentDefinition ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // XContextMenuInterception virtual void SAL_CALL registerContextMenuInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XContextMenuInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index 6ae9d59c7eda..53a4440ee321 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -533,13 +533,13 @@ Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArgume } // ----------------------------------------------------------------------------- -Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType ) throw (IllegalArgumentException, SQLException, RuntimeException) +Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException) { - return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >() ); + return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition ); } // ----------------------------------------------------------------------------- -Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments ) throw (IllegalArgumentException, SQLException, RuntimeException) +Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException) { ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); ::osl::MutexGuard aGuard( getMutex() ); @@ -548,7 +548,8 @@ Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArgu Reference< XComponent > xComponent( newElement( lcl_objectType2ElementType( i_nObjectType ), - ::comphelper::NamedValueCollection( i_rArguments ) + ::comphelper::NamedValueCollection( i_rArguments ), + o_DocumentDefinition ) ); return xComponent; diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index 70f297f621f4..9cb8f5b1745f 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -67,8 +67,8 @@ #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ #include #endif -#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ -#include +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT_HPP_ +#include #endif #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ #include @@ -390,19 +390,30 @@ namespace dbaui aCreationArgs.put( "ClassID", aClassId ); aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection ); + // separate values which are real creation args from args relevant for opening the doc + ::comphelper::NamedValueCollection aCommandArgs; + if ( aCreationArgs.has( "Hidden" ) ) + { + aCommandArgs.put( "Hidden", aCreationArgs.get( "Hidden" ) ); + aCreationArgs.remove( "Hidden" ); + } + Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments( SERVICE_SDB_DOCUMENTDEFINITION, aCreationArgs.getWrappedPropertyValues() ), UNO_QUERY_THROW ); - o_rDefinition.set( xContent, UNO_QUERY ); + + // put the OpenMode into the OpenArgs + OpenCommandArgument aOpenModeArg; + aOpenModeArg.Mode = OpenMode::DOCUMENT; + aCommandArgs.put( "OpenMode", aOpenModeArg ); + Command aCommand; aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) ); - OpenCommandArgument2 aOpenCommand; - aOpenCommand.Mode = OpenMode::DOCUMENT; - aCommand.Argument <<= aOpenCommand; + aCommand.Argument <<= aCommandArgs.getPropertyValues(); WaitObject aWaitCursor( m_pDialogParent ); xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY ); } -- cgit From 321086abdf8a3efaa161d7027d141bd3654b0dca Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 29 Jan 2010 13:54:37 +0100 Subject: autorecovery: respect a media descriptor member "ForceRecovery". When set to , then an attempt to recover sub documents in the "recovery" folder is made. In this course, the m_aArgs member of the ModelImpl was replaced with m_aMediaDescriptor, being a NamedValueCollection, for easier access. --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 36 ++++++-------------- dbaccess/source/core/dataaccess/ModelImpl.hxx | 9 ++--- .../source/core/dataaccess/databasedocument.cxx | 38 +++++++++++++--------- .../source/core/dataaccess/databasedocument.hxx | 2 +- .../source/core/dataaccess/documentdefinition.cxx | 2 +- 5 files changed, 39 insertions(+), 48 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 4095a608733c..cccea2f1821f 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -57,7 +57,6 @@ #include #include -#include #include #include #include @@ -840,13 +839,13 @@ void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Seq } - m_aArgs = stripLoadArguments( aMediaDescriptor ); + m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor ); switchToURL( sDocumentLocation, sDocumentURL ); } // ----------------------------------------------------------------------------- -Sequence< PropertyValue > ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ) +::comphelper::NamedValueCollection ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ) { OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" ); OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" ); @@ -854,7 +853,7 @@ Sequence< PropertyValue > ODatabaseModelImpl::stripLoadArguments( const ::comphe ::comphelper::NamedValueCollection aMutableArgs( _rArguments ); aMutableArgs.remove( "Model" ); aMutableArgs.remove( "ViewName" ); - return aMutableArgs.getPropertyValues(); + return aMutableArgs; } // ----------------------------------------------------------------------------- @@ -888,11 +887,9 @@ Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage() if ( xStorageFactory.is() ) { Any aSource; - ::comphelper::NamedValueCollection aArgs( m_aArgs ); - - aSource = aArgs.get( "Stream" ); + aSource = m_aMediaDescriptor.get( "Stream" ); if ( !aSource.hasValue() ) - aSource = aArgs.get( "InputStream" ); + aSource = m_aMediaDescriptor.get( "InputStream" ); if ( !aSource.hasValue() && m_sDocFileLocation.getLength() ) aSource <<= m_sDocFileLocation; // TODO: shouldn't we also check URL? @@ -1048,7 +1045,7 @@ Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _b // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper // state, fires all events, and so on. // #i105505# / 2009-10-02 / frank.schoenheit@sun.com - xModel->attachResource( ::rtl::OUString(), m_aArgs ); + xModel->attachResource( ::rtl::OUString(), m_aMediaDescriptor.getPropertyValues() ); } if ( _bInitialize ) @@ -1197,9 +1194,8 @@ bool ODatabaseModelImpl::adjustMacroMode_AutoReject() // ----------------------------------------------------------------------------- bool ODatabaseModelImpl::checkMacrosOnLoading() { - ::comphelper::NamedValueCollection aArgs( m_aArgs ); Reference< XInteractionHandler > xInteraction; - xInteraction = aArgs.getOrDefault( "InteractionHandler", xInteraction ); + xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction ); return m_aMacroMode.checkMacrosOnLoading( xInteraction ); } @@ -1377,8 +1373,7 @@ sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE; try { - ::comphelper::NamedValueCollection aArgs( m_aArgs ); - nCurrentMode = aArgs.getOrDefault( "MacroExecutionMode", nCurrentMode ); + nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode ); } catch( const Exception& ) { @@ -1390,19 +1385,8 @@ sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const // ----------------------------------------------------------------------------- sal_Bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode ) { - try - { - ::comphelper::NamedValueCollection aArgs( m_aArgs ); - aArgs.put( "MacroExecutionMode", nMacroMode ); - aArgs >>= m_aArgs; - return sal_True; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - return sal_False; + m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode ); + return sal_True; } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx index 8697bf1abdc3..12b3edbd115d 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.hxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx @@ -73,6 +73,7 @@ /** === end UNO includes === **/ #include +#include #include #include #include @@ -191,7 +192,7 @@ private: ODatabaseContext* m_pDBContext; DocumentEventsData m_aDocumentEvents; - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aArgs; + ::comphelper::NamedValueCollection m_aMediaDescriptor; /// the URL the document was loaded from ::rtl::OUString m_sDocFileLocation; @@ -302,14 +303,14 @@ public: DocumentEventsData& getDocumentEvents() { return m_aDocumentEvents; } - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& - getResource() const { return m_aArgs; } + const ::comphelper::NamedValueCollection& + getMediaDescriptor() const { return m_aMediaDescriptor; } void attachResource( const ::rtl::OUString& _rURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs ); - static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + static ::comphelper::NamedValueCollection stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ); // other stuff diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index c6b6db11a20c..09db7ccb2e82 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -378,15 +378,15 @@ namespace } // ----------------------------------------------------------------------------- - static Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const Sequence< PropertyValue >& _rDescriptor, const ::rtl::OUString _rURL ) + static Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const ::comphelper::NamedValueCollection& _rDescriptor, const ::rtl::OUString _rURL ) { - ::comphelper::NamedValueCollection aMediaDescriptor( _rDescriptor ); + ::comphelper::NamedValueCollection aMutableDescriptor( _rDescriptor ); if ( _rURL.getLength() ) { - aMediaDescriptor.put( "FileName", _rURL ); - aMediaDescriptor.put( "URL", _rURL ); + aMutableDescriptor.put( "FileName", _rURL ); + aMutableDescriptor.put( "URL", _rURL ); } - return aMediaDescriptor.getPropertyValues(); + return aMutableDescriptor.getPropertyValues(); } } @@ -428,9 +428,9 @@ void ODatabaseDocument::impl_reset_nothrow() void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentContext _rContext, const Reference< XInterface >& _rxTargetComponent, const ::comphelper::NamedValueCollection& _rResource ) { - Sequence< Any > aFilterArgs; + Sequence< Any > aFilterCreationArgs; Reference< XStatusIndicator > xStatusIndicator; - lcl_extractAndStartStatusIndicator( _rResource, xStatusIndicator, aFilterArgs ); + lcl_extractAndStartStatusIndicator( _rResource, xStatusIndicator, aFilterCreationArgs ); /** property map for import info set */ comphelper::PropertyMapEntry aExportInfoMap[] = @@ -443,19 +443,20 @@ void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentCo xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rResource.getOrDefault("URL",::rtl::OUString()))); xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml")))); - const sal_Int32 nCount = aFilterArgs.getLength(); - aFilterArgs.realloc(nCount + 1); - aFilterArgs[nCount] <<= xInfoSet; + const sal_Int32 nCount = aFilterCreationArgs.getLength(); + aFilterCreationArgs.realloc(nCount + 1); + aFilterCreationArgs[nCount] <<= xInfoSet; Reference< XImporter > xImporter( - _rContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterArgs ), + _rContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterCreationArgs ), UNO_QUERY_THROW ); Reference< XComponent > xComponent( _rxTargetComponent, UNO_QUERY_THROW ); xImporter->setTargetDocument( xComponent ); Reference< XFilter > xFilter( xImporter, UNO_QUERY_THROW ); - xFilter->filter( ODatabaseModelImpl::stripLoadArguments( _rResource ) ); + Sequence< PropertyValue > aFilterArgs( ODatabaseModelImpl::stripLoadArguments( _rResource ).getPropertyValues() ); + xFilter->filter( aFilterArgs ); if ( xStatusIndicator.is() ) xStatusIndicator->end(); @@ -751,7 +752,7 @@ sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rURL, Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); - return m_pImpl->getResource(); + return m_pImpl->getMediaDescriptor().getPropertyValues(); } // ----------------------------------------------------------------------------- @@ -781,7 +782,12 @@ void SAL_CALL ODatabaseDocument::connectController( const Reference< XController m_pImpl->checkMacrosOnLoading(); // check if there are sub components to recover from our document storage - if ( !m_bHasBeenRecovered ) + bool bAttemptRecovery = m_bHasBeenRecovered; + if ( !bAttemptRecovery && m_pImpl->getMediaDescriptor().has( "ForceRecovery" ) ) + // do not use getOrDefault, it will throw for invalid types, which is not desired here + m_pImpl->getMediaDescriptor().get( "ForceRecovery" ) >>= bAttemptRecovery; + + if ( !bAttemptRecovery ) return; try @@ -921,11 +927,11 @@ void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException) if ( m_pImpl->m_bDocumentReadOnly ) throw IOException(); - impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getResource(), SAVE, aGuard ); + impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getMediaDescriptor(), SAVE, aGuard ); } // ----------------------------------------------------------------------------- -void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const Sequence< PropertyValue>& _rArguments, +void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const ::comphelper::NamedValueCollection& _rArguments, const StoreType _eType, DocumentGuard& _rGuard ) throw ( IOException, RuntimeException ) { OSL_PRECOND( ( _eType == SAVE ) || ( _eType == SAVE_AS ), diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index f3206fbc15ae..6df14398d7d1 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -227,7 +227,7 @@ class ODatabaseDocument :public ModelDependentComponent // ModelDepe */ void impl_storeAs_throw( const ::rtl::OUString& _rURL, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rArguments, + const ::comphelper::NamedValueCollection& _rArguments, const StoreType _eType, DocumentGuard& _rGuard ) diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 61c0463f8ba4..1cacaa802259 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -993,7 +993,7 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con // for the document, default to the interaction handler as used for loading the DB doc // This might be overwritten below, when examining _rOpenArgument. - ::comphelper::NamedValueCollection aDBDocArgs( m_pImpl->m_pDataSource->getResource() ); + const ::comphelper::NamedValueCollection& aDBDocArgs( m_pImpl->m_pDataSource->getMediaDescriptor() ); aDocumentArgs.put( "InteractionHandler", aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); ::boost::optional< sal_Int16 > aDocumentMacroMode; -- cgit From 893f3398cac0ce641ad60e049becd57e20d726b2 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 29 Jan 2010 15:38:20 +0100 Subject: autorecovery: saveToRecoveryFile => storeToRecoveryFile --- dbaccess/source/core/dataaccess/databasedocument.cxx | 2 +- dbaccess/source/core/dataaccess/databasedocument.hxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 09db7ccb2e82..8ab6fefa71e3 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -614,7 +614,7 @@ namespace } // ----------------------------------------------------------------------------- -void SAL_CALL ODatabaseDocument::saveToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +void SAL_CALL ODatabaseDocument::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) { DocumentGuard aGuard( *this ); ModifyLock aLock( *this ); diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 6df14398d7d1..4fd0823774b9 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -430,7 +430,7 @@ public: // css.document.XDocumentRecovery virtual ::sal_Bool SAL_CALL wasModifiedSinceLastSave() throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL saveToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + virtual void SAL_CALL storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); virtual void SAL_CALL recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); // XTitle -- cgit From 02c9c9960f61f53970f886558796ae87ee7a92cd Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 1 Feb 2010 11:43:40 +0100 Subject: autorecovery: recoverSubDocuments: propagate exceptions to the caller, this way aborting the complete recovery process --- dbaccess/source/core/recovery/dbdocrecovery.cxx | 77 +++++++++++-------------- 1 file changed, 35 insertions(+), 42 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx index bf2a68987bb1..7e102dd84eb4 100644 --- a/dbaccess/source/core/recovery/dbdocrecovery.cxx +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -712,52 +712,45 @@ namespace dbaccess // load/create the sub component hidden. We'll show it when the main app window is shown. aLoadArgs.put( "Hidden", true ); - try + Reference< XComponent > xSubComponent; + Reference< XCommandProcessor > xDocDefinition; + + if ( sComponentName.getLength() ) + { + xDocDefinition = lcl_getSubComponentDef_nothrow( i_rTargetController, eComponentType, sComponentName ); + xSubComponent.set( xDocumentUI->loadComponentWithArguments( + eComponentType, + sComponentName, + stor->second.bForEditing, + aLoadArgs.getPropertyValues() + ), + UNO_SET_THROW + ); + } + else { - Reference< XComponent > xSubComponent; - Reference< XCommandProcessor > xDocDefinition; - - if ( sComponentName.getLength() ) - { - xDocDefinition = lcl_getSubComponentDef_nothrow( i_rTargetController, eComponentType, sComponentName ); - xSubComponent.set( xDocumentUI->loadComponentWithArguments( - eComponentType, - sComponentName, - stor->second.bForEditing, - aLoadArgs.getPropertyValues() - ), - UNO_SET_THROW - ); - } - else - { - Reference< XComponent > xDocDefComponent; - xSubComponent.set( xDocumentUI->createComponentWithArguments( - eComponentType, - aLoadArgs.getPropertyValues(), - xDocDefComponent - ), - UNO_SET_THROW - ); - - xDocDefinition.set( xDocDefComponent, UNO_QUERY ); - OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" ); - } - - if ( xDocDefinition.is() ) - { - Reference< XInterface > xLoader( *new SubComponentLoader( i_rTargetController, xDocDefinition ) ); - (void)xLoader; - } - - // at the moment, we only store, during session save, sub components which are modified. So, set this - // recovered sub component to "modified", too. - lcl_markModified( xSubComponent ); + Reference< XComponent > xDocDefComponent; + xSubComponent.set( xDocumentUI->createComponentWithArguments( + eComponentType, + aLoadArgs.getPropertyValues(), + xDocDefComponent + ), + UNO_SET_THROW + ); + + xDocDefinition.set( xDocDefComponent, UNO_QUERY ); + OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" ); } - catch ( const Exception& ) + + if ( xDocDefinition.is() ) { - DBG_UNHANDLED_EXCEPTION(); + Reference< XInterface > xLoader( *new SubComponentLoader( i_rTargetController, xDocDefinition ) ); + (void)xLoader; } + + // at the moment, we only store, during session save, sub components which are modified. So, set this + // recovered sub component to "modified", too. + lcl_markModified( xSubComponent ); } xComponentsStor->dispose(); -- cgit From 13e8f2a69bb63c490d048005f0fb2ae35e62ee8a Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 1 Feb 2010 21:32:33 +0100 Subject: autorecovery: more sophisticated configuration data for interaction handlers The generic css.task.InteractionHandler implementation in module uui is now able to instantiate "sub handlers", i.e. components to delegate a request to, based on the type of the request, and some configuration data. The "old" (and now deprecated) configuration scheme at org.openoffice.ucb.InteractionHandler did not contain type information, so any handlers registered there were always called when no default implementation for a given request was available. The "new" configuration scheme at org.openoffice.Interaction contains UNO type information. That is, a given handler implementation can declare itself responsible for an arbitrary set of UNO types, and for each of those types, whether it is also responsible for sub types. The generic interaction handler implementation uses this configuration data, when it encounteres an interaction request it cannot fullfill itself, to instantiate a component to delegate the request to. As with the "old" data, such a component is required to support the css.task.XInteractionHandler2 interface. Also, if it supports css.lang.XInitialization, then it will be initialized with a name-value pair, the name being "Parent", the value being the XWindow interface of the parent window for any message boxes. As an examplary implementation for this feature, the css.sdb.InteractionHandler has been deprecated. Now the css.sdb.DatabaseInteractionHandler is reponsible for database-related interactions, and the new configuration scheme is pre-filled with data assigning this responsibility. Consequently, a lot of places previously creating an css.sdb.InteractionHandler have been modified to create the default css.task.InteractionHandler. --- .../source/core/dataaccess/databasecontext.cxx | 2 +- .../source/core/dataaccess/documentdefinition.cxx | 4 +- dbaccess/source/filter/xml/dbloader2.cxx | 2 +- dbaccess/source/inc/stringconstants.hrc | 1 - dbaccess/source/inc/stringconstants.inc | 1 - dbaccess/source/ui/browser/brwctrlr.cxx | 2 +- dbaccess/source/ui/browser/unodatbr.cxx | 2 +- dbaccess/source/ui/dlg/dbwizsetup.cxx | 2 +- dbaccess/source/ui/misc/UITools.cxx | 4 +- dbaccess/source/ui/misc/datasourceconnector.cxx | 4 +- dbaccess/source/ui/uno/copytablewizard.cxx | 2 +- dbaccess/source/ui/uno/dbinteraction.cxx | 102 ++++++++++++--------- dbaccess/source/ui/uno/dbinteraction.hxx | 102 +++++++++++++++------ 13 files changed, 144 insertions(+), 86 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx index 84dbdff17d13..ca8fe4e0eda7 100644 --- a/dbaccess/source/core/dataaccess/databasecontext.cxx +++ b/dbaccess/source/core/dataaccess/databasecontext.cxx @@ -420,7 +420,7 @@ Reference< XInterface > ODatabaseContext::loadObjectFromURL(const ::rtl::OUStrin ::comphelper::NamedValueCollection aArgs; aArgs.put( "URL", _sURL ); aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG ); - aArgs.put( "InteractionHandler", m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ) ); + aArgs.put( "InteractionHandler", m_aContext.createComponent( "com.sun.star.task.InteractionHandler" ) ); Sequence< PropertyValue > aResource( aArgs.getPropertyValues() ); xLoad->load( aResource ); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 1cacaa802259..46b77e87b021 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1466,7 +1466,7 @@ sal_Bool ODocumentDefinition::save(sal_Bool _bApprove) pRequest->addContinuation(pAbort); // create the handler, let it handle the request - Reference< XInteractionHandler > xHandler( m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY ); + Reference< XInteractionHandler > xHandler( m_aContext.createComponent( (::rtl::OUString)SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY ); if ( xHandler.is() ) xHandler->handle(xRequest); @@ -1541,7 +1541,7 @@ sal_Bool ODocumentDefinition::saveAs() pRequest->addContinuation(pAbort); // create the handler, let it handle the request - Reference< XInteractionHandler > xHandler(m_aContext.createComponent(::rtl::OUString(SERVICE_SDB_INTERACTION_HANDLER)), UNO_QUERY); + Reference< XInteractionHandler > xHandler(m_aContext.createComponent(::rtl::OUString(SERVICE_TASK_INTERACTION_HANDLER)), UNO_QUERY); if ( xHandler.is() ) xHandler->handle(xRequest); diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx index d3ec0d3ed356..781531a0e2a8 100644 --- a/dbaccess/source/filter/xml/dbloader2.cxx +++ b/dbaccess/source/filter/xml/dbloader2.cxx @@ -448,7 +448,7 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const :: if ( !aMediaDesc.has( "InteractionHandler" ) ) { Reference< XInteractionHandler > xHandler; - if ( m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler", xHandler ) ) + if ( m_aContext.createComponent( "com.sun.star.task.InteractionHandler", xHandler ) ) aMediaDesc.put( "InteractionHandler", xHandler ); } diff --git a/dbaccess/source/inc/stringconstants.hrc b/dbaccess/source/inc/stringconstants.hrc index 02bb911ef287..384d669226dc 100644 --- a/dbaccess/source/inc/stringconstants.hrc +++ b/dbaccess/source/inc/stringconstants.hrc @@ -379,7 +379,6 @@ DECLARE_CONSTASCII_USTRING(SERVICE_SDBCX_TABLES); DECLARE_CONSTASCII_USTRING(SERVICE_SDB_QUERIES); DECLARE_CONSTASCII_USTRING(SERVICE_SDBC_DRIVERMANAGER); DECLARE_CONSTASCII_USTRING(SERVICE_SDBC_CONNECTIONPOOL); -DECLARE_CONSTASCII_USTRING(SERVICE_SDB_INTERACTION_HANDLER); DECLARE_CONSTASCII_USTRING(SERVICE_TASK_INTERACTION_HANDLER); DECLARE_CONSTASCII_USTRING(SERVICE_FRAME_DESKTOP); DECLARE_CONSTASCII_USTRING(SERVICE_SDB_ADABASCREATIONDIALOG); diff --git a/dbaccess/source/inc/stringconstants.inc b/dbaccess/source/inc/stringconstants.inc index 8803d0e0edc7..6d285e44564f 100644 --- a/dbaccess/source/inc/stringconstants.inc +++ b/dbaccess/source/inc/stringconstants.inc @@ -222,7 +222,6 @@ IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBC_DRIVERMANAGER, "com.sun.star.sdbc.Driv IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBC_CONNECTIONPOOL, "com.sun.star.sdbc.ConnectionPool"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBCX_INDEXCOLUMN, "com.sun.star.sdbcx.IndexColumn"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBCX_KEYCOLUMN, "com.sun.star.sdbcx.KeyColumn"); -IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDB_INTERACTION_HANDLER, "com.sun.star.sdb.InteractionHandler"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_TASK_INTERACTION_HANDLER, "com.sun.star.task.InteractionHandler"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_FRAME_DESKTOP, "com.sun.star.frame.Desktop"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDB_ADABASCREATIONDIALOG, "com.sun.star.sdb.AdabasCreationDialog"); diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index a437c06812e2..68a8cbccd75f 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -1355,7 +1355,7 @@ sal_Bool SbaXDataBrowserController::approveParameter(const ::com::sun::star::for pParamRequest->addContinuation(pAbort); // create the handler, let it handle the request - Reference< XInteractionHandler > xHandler(getORB()->createInstance(SERVICE_SDB_INTERACTION_HANDLER), UNO_QUERY); + Reference< XInteractionHandler > xHandler(getORB()->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY); if (xHandler.is()) xHandler->handle(xParamRequest); diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index 2dffccfc8148..f0e58fcccbd8 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -3410,7 +3410,7 @@ void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo ) { Reference< XInteractionHandler > xInteractionHandler( getORB()->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), UNO_QUERY ); OSL_ENSURE( xInteractionHandler.is(), "SbaTableQueryBrowser::implAdministrate: no interaction handler available!" ); diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index 149d0c2d2f7a..efca1883fd00 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -1121,7 +1121,7 @@ sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW ); m_xInteractionHandler.set( _rxORB->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) ) + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), UNO_QUERY_THROW ); } diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx index 55691d4164ff..b805b6f0daff 100644 --- a/dbaccess/source/ui/misc/UITools.cxx +++ b/dbaccess/source/ui/misc/UITools.cxx @@ -378,11 +378,11 @@ SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XP } else { // instantiate the default SDB interaction handler - Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_SDB_INTERACTION_HANDLER), UNO_QUERY); + Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY); if (!xHandler.is()) { OSL_ENSURE(sal_False, "createConnection: could not instantiate an interaction handler!"); - // ShowServiceNotAvailableError(NULL, String(SERVICE_SDB_INTERACTION_HANDLER), sal_True); + // ShowServiceNotAvailableError(NULL, String(SERVICE_TASK_INTERACTION_HANDLER), sal_True); // TODO: a real parent! } else diff --git a/dbaccess/source/ui/misc/datasourceconnector.cxx b/dbaccess/source/ui/misc/datasourceconnector.cxx index 409e86150843..1fc25a14702c 100644 --- a/dbaccess/source/ui/misc/datasourceconnector.cxx +++ b/dbaccess/source/ui/misc/datasourceconnector.cxx @@ -195,9 +195,9 @@ namespace dbaui if ( !xHandler.is() ) { // instantiate the default SDB interaction handler - xHandler = Reference< XInteractionHandler >( m_xORB->createInstance( SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY ); + xHandler = Reference< XInteractionHandler >( m_xORB->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY ); if ( !xHandler.is() ) - ShowServiceNotAvailableError(m_pErrorMessageParent, String(SERVICE_SDB_INTERACTION_HANDLER), sal_True); + ShowServiceNotAvailableError(m_pErrorMessageParent, (::rtl::OUString)SERVICE_TASK_INTERACTION_HANDLER, sal_True); } if ( xHandler.is() ) diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 26f859cf2045..0f656c7c372a 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -1511,7 +1511,7 @@ void SAL_CALL CopyTableWizard::initialize( const Sequence< Any >& _rArguments ) ); } if ( !m_xInteractionHandler.is() ) - m_xInteractionHandler.set( m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ), UNO_QUERY_THROW ); + m_xInteractionHandler.set( m_aContext.createComponent( "com.sun.star.task.InteractionHandler" ), UNO_QUERY_THROW ); InteractionHandler xSourceDocHandler; Reference< XPropertySet > xSourceDescriptor( impl_ensureDataAccessDescriptor_throw( _rArguments, 0, m_xSourceConnection, xSourceDocHandler ) ); diff --git a/dbaccess/source/ui/uno/dbinteraction.cxx b/dbaccess/source/ui/uno/dbinteraction.cxx index b1290f9ee0be..12aee39f308a 100644 --- a/dbaccess/source/ui/uno/dbinteraction.cxx +++ b/dbaccess/source/ui/uno/dbinteraction.cxx @@ -100,7 +100,8 @@ extern "C" void SAL_CALL createRegistryInfo_OInteractionHandler() { - static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OInteractionHandler > aOInteractionHandler_AutoRegistration; + static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::SQLExceptionInteractionHandler > aSQLExceptionInteractionHandler_AutoRegistration; + static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::LegacyInteractionHandler > aLegacyInteractionHandler_AutoRegistration; } //......................................................................... @@ -116,62 +117,70 @@ namespace dbaui using namespace ::dbtools; //========================================================================= - //= OInteractionHandler + //= BasicInteractionHandler //========================================================================= //------------------------------------------------------------------------- - OInteractionHandler::OInteractionHandler(const Reference< XMultiServiceFactory >& _rxORB) - :m_xORB(_rxORB) + BasicInteractionHandler::BasicInteractionHandler( const Reference< XMultiServiceFactory >& _rxORB, const bool i_bFallbackToGeneric ) + :m_xORB( _rxORB ) + ,m_bFallbackToGeneric( i_bFallbackToGeneric ) { + OSL_ENSURE( !m_bFallbackToGeneric, + "BasicInteractionHandler::BasicInteractionHandler: enabling legacy behavior, there should be no clients of this anymore!" ); } //------------------------------------------------------------------------- - IMPLEMENT_SERVICE_INFO1_STATIC(OInteractionHandler, "com.sun.star.comp.dbu.OInteractionHandler", "com.sun.star.sdb.InteractionHandler"); + ::sal_Bool SAL_CALL BasicInteractionHandler::handleInteractionRequest( const Reference< XInteractionRequest >& i_rRequest ) throw (RuntimeException) + { + return impl_handle_throw( i_rRequest ); + } //------------------------------------------------------------------------- - void SAL_CALL OInteractionHandler::handle(const Reference< XInteractionRequest >& _rxRequest) throw(RuntimeException) + void SAL_CALL BasicInteractionHandler::handle( const Reference< XInteractionRequest >& i_rRequest ) throw(RuntimeException) { - Any aRequest; - if (_rxRequest.is()) - { - try { aRequest = _rxRequest->getRequest(); } - catch(RuntimeException&) { } - } - DBG_ASSERT(aRequest.hasValue(), "OInteractionHandler::handle: invalid request!"); - if (!aRequest.hasValue()) + impl_handle_throw( i_rRequest ); + } + + //------------------------------------------------------------------------- + sal_Bool BasicInteractionHandler::impl_handle_throw( const Reference< XInteractionRequest >& i_Request ) + { + Any aRequest( i_Request->getRequest() ); + DBG_ASSERT(aRequest.hasValue(), "BasicInteractionHandler::handle: invalid request!"); + if ( !aRequest.hasValue() ) // no request -> no handling - return; + return sal_False; - Sequence< Reference< XInteractionContinuation > > aContinuations; - try { aContinuations = _rxRequest->getContinuations(); } - catch(RuntimeException&) { } + Sequence< Reference< XInteractionContinuation > > aContinuations( i_Request->getContinuations() ); // try to extract an SQLException (or one of it's derived members - SQLExceptionInfo aInfo(aRequest); - if (aInfo.isValid()) + SQLExceptionInfo aInfo( aRequest ); + if ( aInfo.isValid() ) { - implHandle(aInfo, aContinuations); - return; + implHandle( aInfo, aContinuations ); + return sal_True; } ParametersRequest aParamRequest; - if (aRequest >>= aParamRequest) - { // it's an authentication request - implHandle(aParamRequest, aContinuations); - return; + if ( aRequest >>= aParamRequest ) + { + implHandle( aParamRequest, aContinuations ); + return sal_True; } DocumentSaveRequest aDocuRequest; - if (aRequest >>= aDocuRequest) - { // it's an document request - implHandle(aDocuRequest, aContinuations); - return; + if ( aRequest >>= aDocuRequest ) + { + implHandle( aDocuRequest, aContinuations ); + return sal_True; } - OSL_VERIFY( implHandleUnknown( _rxRequest ) ); + if ( m_bFallbackToGeneric ) + return implHandleUnknown( i_Request ); + + return sal_False; } //------------------------------------------------------------------------- - void OInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + void BasicInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { ::vos::OGuard aGuard(Application::GetSolarMutex()); // want to open a dialog .... @@ -182,7 +191,7 @@ namespace dbaui Reference< XInteractionSupplyParameters > xParamCallback; if (-1 != nParamPos) xParamCallback = Reference< XInteractionSupplyParameters >(_rContinuations[nParamPos], UNO_QUERY); - DBG_ASSERT(xParamCallback.is(), "OInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s"); + DBG_ASSERT(xParamCallback.is(), "BasicInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s"); // determine the style of the dialog, dependent on the present continuation types WinBits nDialogStyle = WB_OK | WB_DEF_OK; @@ -215,7 +224,7 @@ namespace dbaui } //------------------------------------------------------------------------- - void OInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + void BasicInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { ::vos::OGuard aGuard(Application::GetSolarMutex()); // want to open a dialog .... @@ -257,14 +266,14 @@ namespace dbaui if ( nApprovePos != -1 ) _rContinuations[ nApprovePos ]->select(); else - OSL_ENSURE( nResult != RET_YES, "OInteractionHandler::implHandle: no handler for YES!" ); + OSL_ENSURE( nResult != RET_YES, "BasicInteractionHandler::implHandle: no handler for YES!" ); break; case RET_NO: if ( nDisapprovePos != -1 ) _rContinuations[ nDisapprovePos ]->select(); else - OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for NO!" ); + OSL_ENSURE( false, "BasicInteractionHandler::implHandle: no handler for NO!" ); break; case RET_CANCEL: @@ -273,13 +282,13 @@ namespace dbaui else if ( nDisapprovePos != -1 ) _rContinuations[ nDisapprovePos ]->select(); else - OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for CANCEL!" ); + OSL_ENSURE( false, "BasicInteractionHandler::implHandle: no handler for CANCEL!" ); break; case RET_RETRY: if ( nRetryPos != -1 ) _rContinuations[ nRetryPos ]->select(); else - OSL_ENSURE( false, "OInteractionHandler::implHandle: where does the RETRY come from?" ); + OSL_ENSURE( false, "BasicInteractionHandler::implHandle: where does the RETRY come from?" ); break; } } @@ -289,7 +298,7 @@ namespace dbaui } } //------------------------------------------------------------------------- - void OInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + void BasicInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { ::vos::OGuard aGuard(Application::GetSolarMutex()); // want to open a dialog .... @@ -318,7 +327,7 @@ namespace dbaui if (-1 != nDocuPos) { Reference< XInteractionDocumentSave > xCallback(_rContinuations[nDocuPos], UNO_QUERY); - DBG_ASSERT(xCallback.is(), "OInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s"); + DBG_ASSERT(xCallback.is(), "BasicInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s"); // determine the style of the dialog, dependent on the present continuation types WinBits nDialogStyle = WB_OK | WB_DEF_OK; @@ -357,7 +366,7 @@ namespace dbaui } //------------------------------------------------------------------------- - bool OInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest ) + bool BasicInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest ) { Reference< XInteractionHandler > xFallbackHandler; if ( m_xORB.is() ) @@ -371,7 +380,7 @@ namespace dbaui } //------------------------------------------------------------------------- - sal_Int32 OInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + sal_Int32 BasicInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { const Reference< XInteractionContinuation >* pContinuations = _rContinuations.getConstArray(); for (sal_Int32 i=0; i<_rContinuations.getLength(); ++i, ++pContinuations) @@ -408,6 +417,15 @@ namespace dbaui return -1; } + //========================================================================== + //= SQLExceptionInteractionHandler + //========================================================================== + IMPLEMENT_SERVICE_INFO1_STATIC( SQLExceptionInteractionHandler, "com.sun.star.comp.dbaccess.DatabaseInteractionHandler", "com.sun.star.sdb.DatabaseInteractionHandler" ); + + //========================================================================== + //= LegacyInteractionHandler + //========================================================================== + IMPLEMENT_SERVICE_INFO1_STATIC( LegacyInteractionHandler, "com.sun.star.comp.dbaccess.LegacyInteractionHandler", "com.sun.star.sdb.InteractionHandler" ); //......................................................................... } // namespace dbaui diff --git a/dbaccess/source/ui/uno/dbinteraction.hxx b/dbaccess/source/ui/uno/dbinteraction.hxx index 8c7bba539129..822a55a36a95 100644 --- a/dbaccess/source/ui/uno/dbinteraction.hxx +++ b/dbaccess/source/ui/uno/dbinteraction.hxx @@ -35,30 +35,17 @@ #include #endif -#ifndef _DBAUI_MODULE_DBU_HXX_ #include "moduledbu.hxx" -#endif -#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include "apitools.hxx" + +/** === begin UNO includes === **/ #include -#endif -#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ -#include -#endif -#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include #include -#endif -#ifndef _COM_SUN_STAR_UCB_AUTHENTICATIONREQUEST_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_ #include -#endif -#ifndef _COM_SUN_STAR_SDB_DOCUMENTSAVEREQUEST_HPP_ #include -#endif -#ifndef _DBASHARED_APITOOLS_HXX_ -#include "apitools.hxx" -#endif +/** === end UNO includes === **/ namespace dbtools { @@ -71,11 +58,11 @@ namespace dbaui //......................................................................... //========================================================================= - //= OInteractionHandler + //= BasicInteractionHandler //========================================================================= typedef ::cppu::WeakImplHelper2 < ::com::sun::star::lang::XServiceInfo - , ::com::sun::star::task::XInteractionHandler - > OInteractionHandler_Base; + , ::com::sun::star::task::XInteractionHandler2 + > BasicInteractionHandler_Base; /** implements an XInteractionHandler for database related interaction requests.

@@ -87,22 +74,30 @@ namespace dbaui standard error dialog for the (maybe chained) exception given */ - class OInteractionHandler - :public OInteractionHandler_Base + class BasicInteractionHandler + :public BasicInteractionHandler_Base { - OModuleClient m_aModuleClient; - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - m_xORB; + const OModuleClient m_aModuleClient; + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xORB; + const bool m_bFallbackToGeneric; + public: - OInteractionHandler(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB); + BasicInteractionHandler( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB, + const bool i_bFallbackToGeneric + ); - // XServiceInfo - DECLARE_SERVICE_INFO_STATIC(); + // XInteractionHandler2 + virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw (::com::sun::star::uno::RuntimeException); - // XInteractionHandler + // XInteractionHandler virtual void SAL_CALL handle( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw(::com::sun::star::uno::RuntimeException); protected: + sal_Bool + impl_handle_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& i_Request ); + /// handle SQLExceptions (and derived classes) void implHandle( const ::dbtools::SQLExceptionInfo& _rSqlInfo, @@ -141,6 +136,53 @@ namespace dbaui const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations); }; + //========================================================================= + //= SQLExceptionInteractionHandler + //========================================================================= + class SQLExceptionInteractionHandler : public BasicInteractionHandler + { + public: + SQLExceptionInteractionHandler( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB + ) + :BasicInteractionHandler( i_rORB, false ) + { + } + + // XServiceInfo + DECLARE_SERVICE_INFO_STATIC(); + }; + + //========================================================================= + //= SQLExceptionInteractionHandler + //========================================================================= + /** an implementation for the legacy css.sdb.InteractionHandler + + css.sdb.InteractionHandler is deprecated, as it does not only handle database related interactions, + but also delegates all kind of unknown requests to a css.task.InteractionHandler. + + In today's architecture, there's only one central css.task.InteractionHandler, which is to be used + for all requests. Depending on configuration information, it decides which handler implementation + to delegate a request to. + + SQLExceptionInteractionHandler is the delegatee which handles only database related interactions. + LegacyInteractionHandler is the version which first checks for a database related interaction, and + forwards everything else to the css.task.InteractionHandler. + */ + class LegacyInteractionHandler : public BasicInteractionHandler + { + public: + LegacyInteractionHandler( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB + ) + :BasicInteractionHandler( i_rORB, true ) + { + } + + // XServiceInfo + DECLARE_SERVICE_INFO_STATIC(); + }; + //......................................................................... } // namespace dbaui //......................................................................... -- cgit From 51d6afeb3776bab6ed0768e0bf088736a4eb110f Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 2 Feb 2010 10:12:38 +0100 Subject: autorecovery: this slipped through my previous attempt to replace all instantiations of the deprecated sdb.InteractionHandler with task.InteractionHandler --- dbaccess/qa/complex/dbaccess/DatabaseDocument.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java index 8ce063bcdb2a..4781bb5fc644 100644 --- a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java +++ b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java @@ -213,7 +213,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. try { m_defaultHandler = (XInteractionHandler) UnoRuntime.queryInterface(XInteractionHandler.class, - _factory.createInstance("com.sun.star.sdb.InteractionHandler")); + _factory.createInstance("com.sun.star.task.InteractionHandler")); } catch (Exception ex) { -- cgit From 2d3fb08873366434e2b33888e6acd6a8a41c949e Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 2 Feb 2010 10:49:34 +0100 Subject: autorecovery: (caught by complex test) store: when we do not (yet) have an URL, store to storage, not to URL --- .../source/core/dataaccess/databasedocument.cxx | 65 +++++++++++++++------- .../source/core/dataaccess/databasedocument.hxx | 8 +++ 2 files changed, 52 insertions(+), 21 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 8ab6fefa71e3..fb265f93cb9b 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -923,11 +923,49 @@ void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException) { DocumentGuard aGuard( *this ); - if ( m_pImpl->getDocFileLocation() == m_pImpl->getURL() ) - if ( m_pImpl->m_bDocumentReadOnly ) - throw IOException(); + ::rtl::OUString sDocumentURL( m_pImpl->getURL() ); + if ( sDocumentURL.getLength() ) + { + if ( m_pImpl->getDocFileLocation() == m_pImpl->getURL() ) + if ( m_pImpl->m_bDocumentReadOnly ) + throw IOException(); + + impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getMediaDescriptor(), SAVE, aGuard ); + return; + } - impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getMediaDescriptor(), SAVE, aGuard ); + // if we have no URL, but did survive the DocumentGuard above, then we've been inited via XLoadable::initNew, + // i.e. we're based on a temporary storage + OSL_ENSURE( m_pImpl->getDocFileLocation().getLength() == 0, "ODatabaseDocument::store: unexpected URL inconsistency!" ); + + try + { + impl_storeToStorage_throw( m_pImpl->getRootStorage(), m_pImpl->getMediaDescriptor().getPropertyValues(), aGuard ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + ) + { + // allowed to leave + throw; + } + impl_throwIOExceptionCausedBySave_throw( aError, ::rtl::OUString() ); + } +} + +// ----------------------------------------------------------------------------- +void ODatabaseDocument::impl_throwIOExceptionCausedBySave_throw( const Any& i_rError, const ::rtl::OUString& i_rTargetURL ) const +{ + ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, i_rError ); + sErrorMessage = ResourceManager::loadString( + RID_STR_ERROR_WHILE_SAVING, + "$location$", i_rTargetURL, + "$message$", sErrorMessage + ); + throw IOException( sErrorMessage, *const_cast< ODatabaseDocument* >( this ) ); } // ----------------------------------------------------------------------------- @@ -1010,13 +1048,7 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const throw; } - ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, aError ); - sErrorMessage = ResourceManager::loadString( - RID_STR_ERROR_WHILE_SAVING, - "$location$", _rURL, - "$message$", sErrorMessage - ); - throw IOException( sErrorMessage, *this ); + impl_throwIOExceptionCausedBySave_throw( aError, _rURL ); } // notify the document event @@ -1169,16 +1201,7 @@ void SAL_CALL ODatabaseDocument::storeToURL( const ::rtl::OUString& _rURL, const throw; } - Exception aExcept; - aError >>= aExcept; - - ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, aError ); - sErrorMessage = ResourceManager::loadString( - RID_STR_ERROR_WHILE_SAVING, - "$location$", _rURL, - "$message$", sErrorMessage - ); - throw IOException( sErrorMessage, *this ); + impl_throwIOExceptionCausedBySave_throw( aError, _rURL ); } m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone", NULL, makeAny( _rURL ) ); diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 4fd0823774b9..8110b9ceee02 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -626,6 +626,14 @@ private: const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rMediaDescriptor, DocumentGuard& _rDocGuard ); + + /** throws an IOException with the message as defined in the RID_STR_ERROR_WHILE_SAVING resource, wrapping + the given caught non-IOException error + */ + void impl_throwIOExceptionCausedBySave_throw( + const ::com::sun::star::uno::Any& i_rError, + const ::rtl::OUString& i_rTargetURL + ) const; }; /** an extended version of the ModelMethodGuard, which also cares for the initialization state -- cgit From 25d525177127c0d75c1e68bc3ba0ea107794d13e Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 2 Feb 2010 13:53:13 +0100 Subject: autorecovery: execute(open*): do not call getComponent just for checking whether it is a report definition, this implicitly changes the state of the embedded object, which can have side effects --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 46b77e87b021..9d809cf83620 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1189,14 +1189,17 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState(); bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE ); - // exception: new-style reports always create a new document when "open" is executed - Reference< report::XReportDefinition > xReportDefinition( getComponent(), UNO_QUERY ); - bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) ); - - if ( bIsActive && !bIsAliveNewStyleReport ) + if ( bIsActive ) { - impl_onActivateEmbeddedObject( true ); - return makeAny( getComponent() ); + // exception: new-style reports always create a new document when "open" is executed + Reference< report::XReportDefinition > xReportDefinition( impl_getComponent_throw( false ), UNO_QUERY ); + bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) ); + + if ( !bIsAliveNewStyleReport ) + { + impl_onActivateEmbeddedObject( true ); + return makeAny( getComponent() ); + } } } -- cgit From 7af941376a1c06ca8285fc67f92e545ddd62d0cd Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 2 Feb 2010 13:57:03 +0100 Subject: autorecovery: allow the sub component manager to hold multiple objects of the same type, which are new and yet-unsaved (i.e. do not have a name, yet) --- dbaccess/source/ui/app/AppController.cxx | 15 +- dbaccess/source/ui/app/subcomponentmanager.cxx | 245 ++++++++++++------------- 2 files changed, 130 insertions(+), 130 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 8af3a6692c53..11e2b1115d8d 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -1938,14 +1938,17 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const case E_REPORT: case E_FORM: { - ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); - if ( !aHelper->isConnected() ) - break; + if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode ) ) + { + ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); + if ( !aHelper->isConnected() ) + break; - Reference< XComponent > xDefinition; - xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); + Reference< XComponent > xDefinition; + xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); - onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); + onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); + } } break; diff --git a/dbaccess/source/ui/app/subcomponentmanager.cxx b/dbaccess/source/ui/app/subcomponentmanager.cxx index 3456ff75e232..dbc0f432efef 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.cxx +++ b/dbaccess/source/ui/app/subcomponentmanager.cxx @@ -51,10 +51,10 @@ #include #include -//........................................................................ +//...................................................................................................................... namespace dbaui { -//........................................................................ +//...................................................................................................................... /** === begin UNO using === **/ using ::com::sun::star::uno::Reference; @@ -85,13 +85,20 @@ namespace dbaui using ::com::sun::star::beans::PropertyChangeEvent; /** === end UNO using === **/ - //============================================================================== + //================================================================================================================== //= helper structs - //============================================================================== + //================================================================================================================== namespace { + //.............................................................................................................. struct SubComponentDescriptor { + /// the name of the sub component, empty if it is yet unsaved + ::rtl::OUString sName; + /// type of the component - an ElementType value, except for relation design + sal_Int32 nComponentType; + /// the mode in which the sub component has been opened + ElementOpenMode eOpenMode; /// the frame which the component resides in. Must not be Reference< XFrame > xFrame; /// the controller of the sub component. Must not be @@ -104,24 +111,31 @@ namespace dbaui Reference< XPropertySet > xDocumentDefinitionProperties; SubComponentDescriptor() - :xFrame() + :sName() + ,nComponentType( -1 ) + ,eOpenMode( E_OPEN_NORMAL ) + ,xFrame() ,xController() ,xModel() { } - SubComponentDescriptor( const Reference< XComponent >& _rxComponent ) + SubComponentDescriptor( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType, + const ElementOpenMode i_eOpenMode, const Reference< XComponent >& i_rComponent ) + :sName( i_rName ) + ,nComponentType( i_nComponentType ) + ,eOpenMode( i_eOpenMode ) { - if ( !impl_constructFrom( _rxComponent ) ) + if ( !impl_constructFrom( i_rComponent ) ) { - // _rxComponent is neither a model, nor a controller, nor a frame + // i_rComponent is neither a model, nor a controller, nor a frame // => it must be a css.sdb.DocumentDefinition - Reference< XComponentSupplier > xCompSupp( _rxComponent, UNO_QUERY_THROW ); + Reference< XComponentSupplier > xCompSupp( i_rComponent, UNO_QUERY_THROW ); Reference< XComponent > xComponent( xCompSupp->getComponent(), UNO_QUERY_THROW ); if ( !impl_constructFrom( xComponent ) ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal component type." ) ), NULL ); - xComponentCommandProcessor.set( _rxComponent, UNO_QUERY_THROW ); - xDocumentDefinitionProperties.set( _rxComponent, UNO_QUERY_THROW ); + xComponentCommandProcessor.set( i_rComponent, UNO_QUERY_THROW ); + xDocumentDefinitionProperties.set( i_rComponent, UNO_QUERY_THROW ); } } @@ -165,6 +179,7 @@ namespace dbaui } }; + //.............................................................................................................. struct SelectSubComponent : public ::std::unary_function< SubComponentDescriptor, Reference< XComponent > > { Reference< XComponent > operator()( const SubComponentDescriptor _desc ) const @@ -176,55 +191,37 @@ namespace dbaui } }; - struct SubComponentAccessor - { - /// the name of the sub component - ::rtl::OUString sName; - /// type of the component - usually an ElementType value - sal_Int32 nComponentType; - /// the mode in which the sub component has been opened - ElementOpenMode eOpenMode; - - SubComponentAccessor() - :sName() - ,nComponentType( sal_Int32( E_NONE ) ) - ,eOpenMode( E_OPEN_NORMAL ) - { - } + //.............................................................................................................. + typedef ::std::vector< SubComponentDescriptor > SubComponents; - SubComponentAccessor( const ::rtl::OUString& _rName, const sal_Int32 _nCompType, const ElementOpenMode _eMode ) - :sName( _rName ) - ,nComponentType( _nCompType ) - ,eOpenMode( _eMode ) - { - } - }; - - struct SubComponentAccessorHash : public ::std::unary_function< SubComponentAccessor, size_t > + //.............................................................................................................. + struct SubComponentMatch : public ::std::unary_function< SubComponentDescriptor, bool > { - size_t operator()( const SubComponentAccessor& _lhs ) const + public: + SubComponentMatch( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType, + const ElementOpenMode i_eOpenMode ) + :m_sName( i_rName ) + ,m_nComponentType( i_nComponentType ) + ,m_eOpenMode( i_eOpenMode ) { - return _lhs.sName.hashCode() + _lhs.nComponentType + size_t( _lhs.eOpenMode ); } - }; - struct SubComponentAccessorEqual : public ::std::binary_function< SubComponentAccessor, SubComponentAccessor, bool > - { - bool operator()( const SubComponentAccessor& _lhs, const SubComponentAccessor& _rhs ) const + + bool operator()( const SubComponentDescriptor& i_rCompareWith ) const { - return ( _lhs.sName == _rhs.sName ) - && ( _lhs.nComponentType == _rhs.nComponentType ) - && ( _lhs.eOpenMode == _rhs.eOpenMode ); + return ( m_sName == i_rCompareWith.sName ) + && ( m_nComponentType == i_rCompareWith.nComponentType ) + && ( m_eOpenMode == i_rCompareWith.eOpenMode ); } + private: + const ::rtl::OUString m_sName; + const sal_Int32 m_nComponentType; + const ElementOpenMode m_eOpenMode; }; - - typedef ::std::hash_map< SubComponentAccessor, SubComponentDescriptor, SubComponentAccessorHash, SubComponentAccessorEqual > - SubComponentMap; - } - //============================================================================== + //================================================================================================================== //= SubComponentManager_Data - //============================================================================== + //================================================================================================================== struct SubComponentManager_Data { SubComponentManager_Data( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex ) @@ -235,35 +232,36 @@ namespace dbaui OApplicationController& m_rController; mutable ::comphelper::SharedMutex m_aMutex; - SubComponentMap m_aComponents; + SubComponents m_aComponents; ::osl::Mutex& getMutex() const { return m_aMutex; } }; - //==================================================================== + //================================================================================================================== //= SubComponentManager - //==================================================================== - //-------------------------------------------------------------------- + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ SubComponentManager::SubComponentManager( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex ) :m_pData( new SubComponentManager_Data( _rController, _rMutex ) ) { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ SubComponentManager::~SubComponentManager() { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SubComponentManager::disposing() { ::osl::MutexGuard aGuard( m_pData->getMutex() ); m_pData->m_aComponents.clear(); } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ namespace { + //.............................................................................................................. bool lcl_fallbackToAnotherController( SubComponentDescriptor& _rCompDesc ) { Reference< XController > xFallback; @@ -301,7 +299,7 @@ namespace dbaui return false; } - //---------------------------------------------------------------- + //.............................................................................................................. bool lcl_closeComponent( const Reference< XCommandProcessor >& _rxCommandProcessor ) { bool bSuccess = false; @@ -322,7 +320,7 @@ namespace dbaui return bSuccess; } - //---------------------------------------------------------------- + //.............................................................................................................. bool lcl_closeComponent( const SubComponentDescriptor& _rComponent ) { if ( _rComponent.xComponentCommandProcessor.is() ) @@ -350,7 +348,7 @@ namespace dbaui return bSuccess; } - // ----------------------------------------------------------------------------- + //.............................................................................................................. void lcl_notifySubComponentEvent( const SubComponentManager_Data& _rData, const sal_Char* _pAsciiEventName, const SubComponentDescriptor& _rComponent ) { @@ -370,7 +368,7 @@ namespace dbaui } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SAL_CALL SubComponentManager::propertyChange( const PropertyChangeEvent& i_rEvent ) throw (RuntimeException) { if ( i_rEvent.PropertyName != PROPERTY_NAME ) @@ -378,76 +376,66 @@ namespace dbaui return; // find the sub component whose name changed - for ( SubComponentMap::iterator comp = m_pData->m_aComponents.begin(); + for ( SubComponents::iterator comp = m_pData->m_aComponents.begin(); comp != m_pData->m_aComponents.end(); ++comp ) { - if ( comp->second.xDocumentDefinitionProperties != i_rEvent.Source ) + if ( comp->xDocumentDefinitionProperties != i_rEvent.Source ) continue; ::rtl::OUString sNewName; OSL_VERIFY( i_rEvent.NewValue >>= sNewName ); - ::rtl::OUString sOldKnownName( comp->first.sName ); + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OUString sOldKnownName( comp->sName ); ::rtl::OUString sOldName; OSL_VERIFY( i_rEvent.OldValue >>= sOldName ); OSL_ENSURE( sOldName == sOldKnownName, "SubComponentManager::propertyChange: inconsistency in the old names!" ); + #endif - // obtain old values - SubComponentAccessor aKey( comp->first ); - SubComponentDescriptor aElement( comp->second ); - - // remove old values - m_pData->m_aComponents.erase( comp ); - - // re-insert under new name - aKey.sName = sNewName; - m_pData->m_aComponents.insert( SubComponentMap::value_type( - aKey, aElement - ) ) ; - + comp->sName = sNewName; break; } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SAL_CALL SubComponentManager::disposing( const EventObject& _rSource ) throw (RuntimeException) { ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() ); SubComponentDescriptor aClosedComponent; - for ( SubComponentMap::iterator comp = m_pData->m_aComponents.begin(); + for ( SubComponents::iterator comp = m_pData->m_aComponents.begin(); comp != m_pData->m_aComponents.end(); ++comp ) { bool bRemove = false; - if ( comp->second.xController == _rSource.Source ) + if ( comp->xController == _rSource.Source ) { - if ( !comp->second.xModel.is() ) + if ( !comp->xModel.is() ) { bRemove = true; } else { // maybe this is just one view to the sub document, and only this view is closed - if ( !lcl_fallbackToAnotherController( comp->second ) ) + if ( !lcl_fallbackToAnotherController( *comp ) ) { bRemove = true; } } } - else if ( comp->second.xModel == _rSource.Source ) + else if ( comp->xModel == _rSource.Source ) { bRemove = true; } if ( bRemove ) { - aClosedComponent = comp->second; + aClosedComponent = *comp; m_pData->m_aComponents.erase( comp ); break; } @@ -460,7 +448,7 @@ namespace dbaui } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ Sequence< Reference< XComponent> > SubComponentManager::getSubComponents() const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); @@ -470,12 +458,12 @@ namespace dbaui m_pData->m_aComponents.begin(), m_pData->m_aComponents.end(), aComponents.getArray(), - ::std::compose1( SelectSubComponent(), ::std::select2nd< SubComponentMap::value_type >() ) + SelectSubComponent() ); return aComponents; } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ sal_Bool SubComponentManager::closeSubComponents() { ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); @@ -483,16 +471,13 @@ namespace dbaui try { - typedef ::std::vector< SubComponentAccessor > ComponentAccessors; - ComponentAccessors aClosedComponents; - - SubComponentMap aComponents( m_pData->m_aComponents ); - for ( SubComponentMap::const_iterator comp = aComponents.begin(); - comp != aComponents.end(); + SubComponents aWorkingCopy( m_pData->m_aComponents ); + for ( SubComponents::const_iterator comp = aWorkingCopy.begin(); + comp != aWorkingCopy.end(); ++comp ) { - lcl_closeComponent( comp->second ); + lcl_closeComponent( *comp ); } } catch ( const Exception& ) @@ -503,27 +488,35 @@ namespace dbaui return empty(); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::empty() const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); return m_pData->m_aComponents.empty(); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SubComponentManager::onSubComponentOpened( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode, const Reference< XComponent >& _rxComponent ) { ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() ); - // put into map - SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode ); - SubComponentDescriptor aElement( _rxComponent ); +#if OSL_DEBUG_LEVEL > 0 + if ( _rName.getLength() ) + { + // check there does not already exist such a component + SubComponents::const_iterator existentPos = ::std::find_if( + m_pData->m_aComponents.begin(), + m_pData->m_aComponents.end(), + SubComponentMatch( _rName, _nComponentType, _eOpenMode ) + ); + OSL_ENSURE( existentPos == m_pData->m_aComponents.end(), "already existent!" ); + } +#endif + SubComponentDescriptor aElement( _rName, _nComponentType, _eOpenMode, _rxComponent ); ENSURE_OR_THROW( aElement.xModel.is() || aElement.xController.is(), "illegal component" ); - m_pData->m_aComponents.insert( SubComponentMap::value_type( - aKey, aElement - ) ) ; + m_pData->m_aComponents.push_back( aElement ); // add as listener if ( aElement.xController.is() ) @@ -538,73 +531,77 @@ namespace dbaui lcl_notifySubComponentEvent( *m_pData, "OnSubComponentOpened", aElement ); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::activateSubFrame( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode ) const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); - SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode ); - SubComponentMap::const_iterator pos = m_pData->m_aComponents.find( aKey ); + SubComponents::const_iterator pos = ::std::find_if( + m_pData->m_aComponents.begin(), + m_pData->m_aComponents.end(), + SubComponentMatch( _rName, _nComponentType, _eOpenMode ) + ); if ( pos == m_pData->m_aComponents.end() ) // no component with this name/type/open mode return false; - const Reference< XFrame > xFrame( pos->second.xFrame, UNO_SET_THROW ); + const Reference< XFrame > xFrame( pos->xFrame, UNO_SET_THROW ); const Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW ); xTopWindow->toFront(); return true; } - // ----------------------------------------------------------------------------- - bool SubComponentManager::closeSubFrames( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType ) + //------------------------------------------------------------------------------------------------------------------ + bool SubComponentManager::closeSubFrames( const ::rtl::OUString& i_rName, const sal_Int32 _nComponentType ) { ::osl::MutexGuard aGuard( m_pData->getMutex() ); + ENSURE_OR_RETURN_FALSE( i_rName.getLength(), "SubComponentManager::closeSubFrames: illegal name!" ); - SubComponentMap aWorkingCopy( m_pData->m_aComponents ); - for ( SubComponentMap::const_iterator comp = aWorkingCopy.begin(); + SubComponents aWorkingCopy( m_pData->m_aComponents ); + for ( SubComponents::const_iterator comp = aWorkingCopy.begin(); comp != aWorkingCopy.end(); ++comp ) { - if ( ( comp->first.sName != _rName ) || ( comp->first.nComponentType != _nComponentType ) ) + if ( ( comp->sName != i_rName ) || ( comp->nComponentType != _nComponentType ) ) continue; - if ( !lcl_closeComponent( comp->second ) ) + if ( !lcl_closeComponent( *comp ) ) return false; } return true; } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::lookupSubComponent( const Reference< XComponent >& i_rComponent, ::rtl::OUString& o_rName, sal_Int32& o_rComponentType ) { - for ( SubComponentMap::const_iterator comp = m_pData->m_aComponents.begin(); + for ( SubComponents::const_iterator comp = m_pData->m_aComponents.begin(); comp != m_pData->m_aComponents.end(); ++comp ) { - if ( ( comp->second.xModel.is() - && ( comp->second.xModel == i_rComponent ) + if ( ( comp->xModel.is() + && ( comp->xModel == i_rComponent ) ) - || ( comp->second.xController.is() - && ( comp->second.xController == i_rComponent ) + || ( comp->xController.is() + && ( comp->xController == i_rComponent ) ) - || ( comp->second.xFrame.is() - && ( comp->second.xFrame == i_rComponent ) + || ( comp->xFrame.is() + && ( comp->xFrame == i_rComponent ) ) ) { - o_rName = comp->first.sName; - o_rComponentType = comp->first.nComponentType; + o_rName = comp->sName; + o_rComponentType = comp->nComponentType; return true; } } return false; } -//........................................................................ +//...................................................................................................................... } // namespace dbaui -//........................................................................ +//...................................................................................................................... -- cgit From 7de2856ae13e5d1b9f6c6a0d950ca163413b7584 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 2 Feb 2010 23:05:16 +0100 Subject: autorecovery: let definition contents support the XHierarchicalName property, so clients can easily retrieve the hierarchical name of a content --- dbaccess/source/core/dataaccess/documentcontainer.cxx | 18 ++++++++++++++++++ dbaccess/source/core/dataaccess/documentcontainer.hxx | 14 +++++++++++--- dbaccess/source/core/dataaccess/documentdefinition.cxx | 16 ++++++++++++++++ dbaccess/source/core/dataaccess/documentdefinition.hxx | 12 +++++++++--- dbaccess/source/core/inc/ContentHelper.hxx | 8 +++++--- 5 files changed, 59 insertions(+), 9 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 2fe62eb420a5..03cb9326809e 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -666,6 +666,24 @@ void SAL_CALL ODocumentContainer::replaceByHierarchicalName( const ::rtl::OUStri xNameContainer->replaceByName(sName,_aElement); } + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentContainer::getHierarchicalName() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return impl_getHierarchicalName( false ); +} + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const ::rtl::OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException) +{ + ::rtl::OUStringBuffer aBuffer; + aBuffer.append( getHierarchicalName() ); + aBuffer.append( sal_Unicode( '/' ) ); + aBuffer.append( i_rRelativeName ); + return aBuffer.makeStringAndClear(); +} + // ----------------------------------------------------------------------------- ::rtl::Reference ODocumentContainer::getContent(const ::rtl::OUString& _sName) const { diff --git a/dbaccess/source/core/dataaccess/documentcontainer.hxx b/dbaccess/source/core/dataaccess/documentcontainer.hxx index c4f4aa24642c..d6986d6c9f66 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.hxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.hxx @@ -34,8 +34,8 @@ #ifndef _DBA_CORE_DEFINITIONCONTAINER_HXX_ #include "definitioncontainer.hxx" #endif -#ifndef _CPPUHELPER_IMPLBASE4_HXX_ -#include +#ifndef _CPPUHELPER_IMPLBASE5_HXX_ +#include #endif #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include @@ -46,6 +46,9 @@ #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_ #include #endif +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAME_HPP_ +#include +#endif #ifndef _COM_SUN_STAR_EMBED_XTRANSACTEDOBJECT_HPP_ #include #endif @@ -63,9 +66,10 @@ namespace dbaccess { //........................................................................ -typedef ::cppu::ImplHelper4 < ::com::sun::star::frame::XComponentLoader +typedef ::cppu::ImplHelper5 < ::com::sun::star::frame::XComponentLoader , ::com::sun::star::lang::XMultiServiceFactory , ::com::sun::star::container::XHierarchicalNameContainer + , ::com::sun::star::container::XHierarchicalName , ::com::sun::star::embed::XTransactedObject > ODocumentContainer_Base; //========================================================================== @@ -114,6 +118,10 @@ public: virtual void SAL_CALL insertByHierarchicalName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL removeByHierarchicalName( const ::rtl::OUString& Name ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XHierarchicalName + virtual ::rtl::OUString SAL_CALL getHierarchicalName( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL composeHierarchicalName( const ::rtl::OUString& aRelativeName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); + // XNameContainer virtual void SAL_CALL removeByName( const ::rtl::OUString& _rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 9d809cf83620..4a6813bee2af 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -2162,6 +2162,22 @@ void SAL_CALL ODocumentDefinition::store( ) throw (WrappedTargetException, Runt return bSuccess; } +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentDefinition::getHierarchicalName() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return impl_getHierarchicalName( false ); +} + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentDefinition::composeHierarchicalName( const ::rtl::OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException) +{ + ::rtl::OUStringBuffer aBuffer; + aBuffer.append( getHierarchicalName() ); + aBuffer.append( sal_Unicode( '/' ) ); + aBuffer.append( i_rRelativeName ); + return aBuffer.makeStringAndClear(); +} // ----------------------------------------------------------------------------- void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) throw (SQLException, ElementExistException, RuntimeException) diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index 28cbc34710e6..2b561fa7edbd 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -34,8 +34,8 @@ #ifndef _CPPUHELPER_PROPSHLP_HXX #include #endif -#ifndef _CPPUHELPER_IMPLBASE3_HXX_ -#include +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include #endif #ifndef DBA_CONTENTHELPER_HXX #include "ContentHelper.hxx" @@ -66,6 +66,7 @@ #endif #include #include +#include namespace comphelper { @@ -84,9 +85,10 @@ namespace dbaccess //= document //========================================================================== -typedef ::cppu::ImplHelper3 < ::com::sun::star::embed::XComponentSupplier +typedef ::cppu::ImplHelper4 < ::com::sun::star::embed::XComponentSupplier , ::com::sun::star::sdb::XSubDocument , ::com::sun::star::util::XCloseListener + , ::com::sun::star::container::XHierarchicalName > ODocumentDefinition_Base; class ODocumentDefinition @@ -152,6 +154,10 @@ public: virtual void SAL_CALL store( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL close( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XHierarchicalName + virtual ::rtl::OUString SAL_CALL getHierarchicalName( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL composeHierarchicalName( const ::rtl::OUString& aRelativeName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); + // OPropertySetHelper virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); diff --git a/dbaccess/source/core/inc/ContentHelper.hxx b/dbaccess/source/core/inc/ContentHelper.hxx index 227110bd324d..367186dc4cb8 100644 --- a/dbaccess/source/core/inc/ContentHelper.hxx +++ b/dbaccess/source/core/inc/ContentHelper.hxx @@ -110,10 +110,12 @@ namespace dbaccess sal_Bool bAsTemplate; // AsTemplate ::rtl::OUString sPersistentName;// persistent name of the document - // @@@ Add other properties supported by your content. - ContentProperties() - : bIsDocument( sal_True ), bIsFolder( sal_False ), bAsTemplate( sal_False ) {} + :bIsDocument( sal_True ) + ,bIsFolder( sal_False ) + ,bAsTemplate( sal_False ) + { + } }; class OContentHelper_Impl -- cgit From aefb13e5d8ffb2835936a2af848005cfb6fe5b9a Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 2 Feb 2010 23:05:43 +0100 Subject: autorecovery: when creating a new form/report by wizard, ensure that our sub component manager knows it by its proper name --- dbaccess/source/ui/app/AppController.cxx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 11e2b1115d8d..076b4429abd4 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -78,6 +78,7 @@ #include #include #include +#include /** === end UNO includes === **/ #ifndef _TOOLS_DEBUG_HXX @@ -2046,14 +2047,27 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) if ( aHelper->isConnected() ) { sal_Int32 nCommandType = -1; - const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType)); + const ::rtl::OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) ); Reference< XComponent > xComponent,xDefinition; if ( E_REPORT == _eType ) - xComponent = aHelper->newReportWithPilot(xDefinition,nCommandType,sName); + xComponent = aHelper->newReportWithPilot( xDefinition, nCommandType, sCurrentSelected ); else - xComponent = aHelper->newFormWithPilot(xDefinition,nCommandType,sName); + xComponent = aHelper->newFormWithPilot( xDefinition, nCommandType, sCurrentSelected ); + OSL_POSTCOND( xComponent.is() && xDefinition.is(), "OApplicationController::newElementWithPilot:" + "invalid component/docdef!" ); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); + ::rtl::OUString sName; + try + { + Reference< XHierarchicalName > xName( xDefinition, UNO_QUERY_THROW ); + sName = xName->getHierarchicalName(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + if ( xComponent.is() && xDefinition.is() ) + onDocumentOpened( sName, _eType, E_OPEN_DESIGN, xComponent, xDefinition ); } } break; -- cgit From 28b38d73e582a9909be16101ec0bb93a41b86f13 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 3 Feb 2010 11:46:23 +0100 Subject: autorecovery: when calling a pilot to create a database object, pass the XDatabaseDocumentUI, too --- dbaccess/source/ui/app/AppControllerDnD.cxx | 2 +- dbaccess/source/ui/inc/linkeddocuments.hxx | 19 +++++---- dbaccess/source/ui/misc/linkeddocuments.cxx | 65 ++++++++++++++--------------- 3 files changed, 42 insertions(+), 44 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppControllerDnD.cxx b/dbaccess/source/ui/app/AppControllerDnD.cxx index ed8c5a15dd89..0e8b3c8d647c 100644 --- a/dbaccess/source/ui/app/AppControllerDnD.cxx +++ b/dbaccess/source/ui/app/AppControllerDnD.cxx @@ -613,7 +613,7 @@ void OApplicationController::getSelectionElementNames(::std::vector< ::rtl::OUSt } ::std::auto_ptr< OLinkedDocumentsAccess > pDocuments( new OLinkedDocumentsAccess( - getView(), m_aCurrentFrame.getFrame(), getORB(), xDocContainer, xConnection, getDatabaseName() + getView(), this, getORB(), xDocContainer, xConnection, getDatabaseName() ) ); return pDocuments; } diff --git a/dbaccess/source/ui/inc/linkeddocuments.hxx b/dbaccess/source/ui/inc/linkeddocuments.hxx index e7030312cde6..b91aca78fff2 100644 --- a/dbaccess/source/ui/inc/linkeddocuments.hxx +++ b/dbaccess/source/ui/inc/linkeddocuments.hxx @@ -55,6 +55,7 @@ #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_ #include #endif +#include #ifndef _LINK_HXX #include #endif @@ -83,8 +84,8 @@ namespace dbaui m_xDocumentContainer; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection; - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > - m_xParentFrame; + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI > + m_xDocumentUI; Window* m_pDialogParent; String m_sCurrentlyEditing; ::rtl::OUString @@ -92,13 +93,13 @@ namespace dbaui public: OLinkedDocumentsAccess( - Window* _pDialogParent - ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame - ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB - ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainer - ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection - ,const ::rtl::OUString& _sDataSourceName - ); + Window* _pDialogParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rDocumentUI, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainer, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, + const ::rtl::OUString& _sDataSourceName + ); ~OLinkedDocumentsAccess(); inline sal_Bool isConnected() const { return m_xConnection.is(); } diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index 9cb8f5b1745f..9dc35a684041 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -155,6 +155,7 @@ namespace dbaui using namespace ::com::sun::star::util; using namespace ::com::sun::star::ucb; using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::sdb::application; using namespace ::com::sun::star::task; using namespace ::svt; @@ -192,17 +193,13 @@ namespace dbaui //================================================================== DBG_NAME(OLinkedDocumentsAccess) //------------------------------------------------------------------ - OLinkedDocumentsAccess::OLinkedDocumentsAccess(Window* _pDialogParent - , const Reference< XFrame >& _rxParentFrame - , const Reference< XMultiServiceFactory >& _rxORB - , const Reference< XNameAccess >& _rxContainer - , const Reference< XConnection>& _xConnection - , const ::rtl::OUString& _sDataSourceName - ) + OLinkedDocumentsAccess::OLinkedDocumentsAccess( Window* _pDialogParent, const Reference< XDatabaseDocumentUI >& i_rDocumentUI, + const Reference< XMultiServiceFactory >& _rxORB, const Reference< XNameAccess >& _rxContainer, + const Reference< XConnection>& _xConnection, const ::rtl::OUString& _sDataSourceName ) :m_xORB(_rxORB) ,m_xDocumentContainer(_rxContainer) ,m_xConnection(_xConnection) - ,m_xParentFrame(_rxParentFrame) + ,m_xDocumentUI( i_rDocumentUI ) ,m_pDialogParent(_pDialogParent) ,m_sDataSourceName(_sDataSourceName) { @@ -277,44 +274,44 @@ namespace dbaui Reference< XComponent> xRet; try { - ::svx::ODataAccessDescriptor aDesc; - aDesc.setDataSource(m_sDataSourceName); + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "DataSourceName", m_sDataSourceName ); + if ( _rObjectName.getLength() && ( _nCommandType != -1 ) ) { - aDesc[::svx::daCommandType] <<= _nCommandType; - aDesc[::svx::daCommand] <<= _rObjectName; + aArgs.put( "CommandType", _nCommandType ); + aArgs.put( "Command", _rObjectName ); } if ( m_xConnection.is() ) - aDesc[::svx::daConnection] <<= m_xConnection; + aArgs.put( "ActiveConnection", m_xConnection ); + + aArgs.put( "DocumentUI", m_xDocumentUI ); - Sequence aSeq = aDesc.createAnySequence(); - const sal_Int32 nLength = aSeq.getLength(); - aSeq.realloc(nLength + 1 ); - PropertyValue aVal; - aVal.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentFrame")); - aVal.Value <<= m_xParentFrame; - aSeq[nLength] <<= aVal; + Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW ); + aArgs.put( "ParentFrame", xController->getFrame() ); + // (legacy, 'til not all wizards migrated to the DocumentUI parameter) - Reference< XJobExecutor > xFormWizard; + Reference< XJobExecutor > xWizard; { WaitObject aWaitCursor( m_pDialogParent ); - xFormWizard.set(m_xORB->createInstanceWithArguments(::rtl::OUString::createFromAscii(_pWizardService),aSeq),UNO_QUERY); + xWizard.set( m_xORB->createInstanceWithArguments( + ::rtl::OUString::createFromAscii(_pWizardService), + aArgs.getWrappedPropertyValues() + ), UNO_QUERY ); } - if ( xFormWizard.is() ) + + if ( xWizard.is() ) { - xFormWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("start"))); - Reference xProp(xFormWizard,UNO_QUERY); - if ( xProp.is() ) + xWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("start"))); + Reference xProp( xWizard, UNO_QUERY_THROW ); + Reference xInfo( xProp->getPropertySetInfo(), UNO_SET_THROW ); + if ( xInfo->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))) ) { - Reference xInfo = xProp->getPropertySetInfo(); - if ( xInfo->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))) ) - { - _xDefinition.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentDefinition"))),UNO_QUERY); - xRet.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))),UNO_QUERY); - } + _xDefinition.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentDefinition"))),UNO_QUERY); + xRet.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))),UNO_QUERY); } - xFormWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("end"))); - ::comphelper::disposeComponent(xFormWizard); + xWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("end"))); + ::comphelper::disposeComponent(xWizard); } } catch(const Exception& e) -- cgit From ed853a88ff6e0bfae048bb19615ab2cd255f07eb Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 3 Feb 2010 11:52:40 +0100 Subject: autorecovery: re-work the table wizard so that it does not open the table itself, but uses XDatabaseDocumentUI Consequently, it does not need to return the created model/controller anymore. This way, the application controller has full control over its sub components, which didn't work reliably before. Other wizards (query/form/report) are to follow. For this purpose, they're also to be based on the newly introduced DatabaseObjectWizard class. --- dbaccess/source/ui/app/AppController.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 076b4429abd4..cc040cabe11c 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -2083,7 +2083,8 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) else xComponent = aHelper->newTableWithPilot(); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL ); + // no need for onDocumentOpened, the table wizard opens the created table by using + // XDatabaseDocumentUI::loadComponent method. } } break; -- cgit From 500131391fc5777193565f57610f07c7a22bf7ee Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 4 Feb 2010 14:13:58 +0100 Subject: autorecovery: post-rebase build problems solved --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 6 +++--- dbaccess/source/ui/misc/WCopyTable.cxx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 93f57a122244..abffdb374b3e 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -954,7 +954,7 @@ void ODocumentDefinition::impl_showOrHideComponent_throw( const bool i_bShow ) { LockModifiable aLockModify( impl_getComponent_throw() ); m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); - impl_onActivateEmbeddedObject( false ); + impl_onActivateEmbeddedObject_nothrow( false ); } break; @@ -1144,7 +1144,7 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons { LockModifiable aLockModify( impl_getComponent_throw() ); m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); - ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( false ); + impl_onActivateEmbeddedObject_nothrow( false ); } if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) @@ -1198,7 +1198,7 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co if ( !bIsAliveNewStyleReport ) { - impl_onActivateEmbeddedObject( true ); + impl_onActivateEmbeddedObject_nothrow( true ); return makeAny( getComponent() ); } } diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index b178947bf5f9..43c2b10e9f9e 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -709,7 +709,7 @@ OCopyTableWizard::OCopyTableWizard( Window* pParent, const ::rtl::OUString& _rDe ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex ); ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex ); - m_xInteractionHandler.set( m_xFactory->createInstance( SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY); + m_xInteractionHandler.set( m_xFactory->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY); OCopyTable* pPage1( new OCopyTable( this ) ); pPage1->disallowViews(); -- cgit From 538e41ebb44726aa666c92b79d0000aca8c41ae4 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 4 Feb 2010 16:04:06 +0100 Subject: autorecovery: form and report wizzard now also using XDatabaseDocumentUI, instead of manipulating document definitions All database object wizards by now employ XDatabaseDocumentUI. This way, it is ensured that the controller has the full control over the opened sub components. Still, other third-party code could use direct access to the document definitions, and open sub documents this way. This would go unnoticed by the application controller at the moment. I would be possible to fix this, by introducing broadcasts from the document definitions, listened to by the controller. But as this sounds like a rare case, and XDatabaseDocumentUI is the preferred way for third-party components, too, such an implementation is deferred to Later ... --- .../source/core/dataaccess/documentcontainer.cxx | 2 +- .../source/core/dataaccess/documentdefinition.cxx | 13 +++-- dbaccess/source/ui/app/AppController.cxx | 33 ++++--------- dbaccess/source/ui/inc/linkeddocuments.hxx | 21 +++------ dbaccess/source/ui/misc/linkeddocuments.cxx | 55 +++++++--------------- 5 files changed, 39 insertions(+), 85 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 03cb9326809e..9646c36499d3 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -232,7 +232,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments ::rtl::OUString sName, sPersistentName, sURL; Reference< XCommandProcessor > xCopyFrom; Reference< XConnection > xConnection; - sal_Bool bAsTemplate; + sal_Bool bAsTemplate( sal_False ); Sequence< sal_Int8 > aClassID; ::comphelper::NamedValueCollection aArgs( _aArguments ); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 4a6813bee2af..ee0fb347f6d6 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -1083,10 +1083,6 @@ void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, con } aDocumentArgs.put( "MacroExecutionMode", *aDocumentMacroMode ); - - if ( xConnection.is() ) - m_xLastKnownConnection = xConnection; - if ( ( nOpenMode == OpenMode::ALL ) || ( nOpenMode == OpenMode::FOLDERS ) || ( nOpenMode == OpenMode::DOCUMENTS ) @@ -1793,7 +1789,7 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC return aMediaDesc.getPropertyValues(); } // ----------------------------------------------------------------------------- -void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _xConnection, const Sequence< sal_Int8 >& _aClassID, +void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_rConnection, const Sequence< sal_Int8 >& _aClassID, const Sequence< PropertyValue >& i_rOpenCommandArguments, const bool _bSuppressMacros, const bool _bReadOnly ) { if ( !m_xEmbeddedObject.is() ) @@ -1847,7 +1843,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( - _xConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); + i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID ,sDocumentService @@ -1893,7 +1889,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( - _xConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); + i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); Reference xCommon(m_xEmbeddedObject,UNO_QUERY); OSL_ENSURE(xCommon.is(),"unsupported interface!"); @@ -1954,6 +1950,9 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x DBG_UNHANDLED_EXCEPTION(); } } + + if ( i_rConnection.is() ) + m_xLastKnownConnection = i_rConnection; } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index cc040cabe11c..b15832a7ee7d 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -2048,26 +2048,10 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) { sal_Int32 nCommandType = -1; const ::rtl::OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) ); - Reference< XComponent > xComponent,xDefinition; if ( E_REPORT == _eType ) - xComponent = aHelper->newReportWithPilot( xDefinition, nCommandType, sCurrentSelected ); + aHelper->newReportWithPilot( nCommandType, sCurrentSelected ); else - xComponent = aHelper->newFormWithPilot( xDefinition, nCommandType, sCurrentSelected ); - OSL_POSTCOND( xComponent.is() && xDefinition.is(), "OApplicationController::newElementWithPilot:" - "invalid component/docdef!" ); - - ::rtl::OUString sName; - try - { - Reference< XHierarchicalName > xName( xDefinition, UNO_QUERY_THROW ); - sName = xName->getHierarchicalName(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - if ( xComponent.is() && xDefinition.is() ) - onDocumentOpened( sName, _eType, E_OPEN_DESIGN, xComponent, xDefinition ); + aHelper->newFormWithPilot( nCommandType, sCurrentSelected ); } } break; @@ -2077,20 +2061,19 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) ::std::auto_ptr aHelper = getDocumentsAccess(_eType); if ( aHelper->isConnected() ) { - Reference< XComponent > xComponent; if ( E_QUERY == _eType ) - xComponent = aHelper->newQueryWithPilot(); + aHelper->newQueryWithPilot(); else - xComponent = aHelper->newTableWithPilot(); - - // no need for onDocumentOpened, the table wizard opens the created table by using - // XDatabaseDocumentUI::loadComponent method. + aHelper->newTableWithPilot(); } } break; case E_NONE: break; } + + // no need for onDocumentOpened, the table wizard opens the created table by using + // XDatabaseDocumentUI::loadComponent method. } // ----------------------------------------------------------------------------- @@ -2908,7 +2891,7 @@ void OApplicationController::containerFound( const Reference< XContainer >& _xCo try { sName = getContainer()->getQualifiedName( NULL ); - OSL_ENSURE( sName.getLength(), "OApplicationController::newElementWithPilot: no name given!" ); + OSL_ENSURE( sName.getLength(), "OApplicationController::getCurrentlySelectedName: no name given!" ); } catch( const Exception& ) { diff --git a/dbaccess/source/ui/inc/linkeddocuments.hxx b/dbaccess/source/ui/inc/linkeddocuments.hxx index b91aca78fff2..cc4824058000 100644 --- a/dbaccess/source/ui/inc/linkeddocuments.hxx +++ b/dbaccess/source/ui/inc/linkeddocuments.hxx @@ -119,24 +119,16 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_rDefinition ); - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newFormWithPilot( - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, + void newFormWithPilot( const sal_Int32 _nCommandType = -1, const ::rtl::OUString& _rObjectName = ::rtl::OUString() ); - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newReportWithPilot( - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, + void newReportWithPilot( const sal_Int32 _nCommandType = -1, const ::rtl::OUString& _rObjectName = ::rtl::OUString() ); - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newQueryWithPilot(); - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newTableWithPilot(); + void newQueryWithPilot(); + void newTableWithPilot(); enum RESULT { @@ -148,15 +140,14 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > impl_open( const ::rtl::OUString& _rLinkName, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDefinition, ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs ); - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + void impl_newWithPilot( const char* _pWizardService, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ); diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index 9dc35a684041..85f8eb635947 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -268,81 +268,62 @@ namespace dbaui return xRet; } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService, - Reference< XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) + void OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService, + const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) { - Reference< XComponent> xRet; try { ::comphelper::NamedValueCollection aArgs; aArgs.put( "DataSourceName", m_sDataSourceName ); + if ( m_xConnection.is() ) + aArgs.put( "ActiveConnection", m_xConnection ); + if ( _rObjectName.getLength() && ( _nCommandType != -1 ) ) { aArgs.put( "CommandType", _nCommandType ); aArgs.put( "Command", _rObjectName ); } - if ( m_xConnection.is() ) - aArgs.put( "ActiveConnection", m_xConnection ); aArgs.put( "DocumentUI", m_xDocumentUI ); - Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW ); - aArgs.put( "ParentFrame", xController->getFrame() ); - // (legacy, 'til not all wizards migrated to the DocumentUI parameter) - Reference< XJobExecutor > xWizard; { WaitObject aWaitCursor( m_pDialogParent ); xWizard.set( m_xORB->createInstanceWithArguments( - ::rtl::OUString::createFromAscii(_pWizardService), + ::rtl::OUString::createFromAscii( _pWizardService ), aArgs.getWrappedPropertyValues() - ), UNO_QUERY ); + ), UNO_QUERY_THROW ); } - if ( xWizard.is() ) - { - xWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("start"))); - Reference xProp( xWizard, UNO_QUERY_THROW ); - Reference xInfo( xProp->getPropertySetInfo(), UNO_SET_THROW ); - if ( xInfo->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))) ) - { - _xDefinition.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentDefinition"))),UNO_QUERY); - xRet.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))),UNO_QUERY); - } - xWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("end"))); - ::comphelper::disposeComponent(xWizard); - } + xWizard->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "start" ) ) ); + ::comphelper::disposeComponent( xWizard ); } catch(const Exception& e) { - (void) e; - OSL_ENSURE(sal_False, "OLinkedDocumentsAccess::newWithPilot: caught an exception while loading the object!"); + DBG_UNHANDLED_EXCEPTION(); } - return xRet; } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newFormWithPilot(Reference< XComponent >& _xDefinition,const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName) + void OLinkedDocumentsAccess::newFormWithPilot( const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName ) { - return impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _xDefinition, _nCommandType, _rObjectName ); + impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _nCommandType, _rObjectName ); } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newReportWithPilot( Reference< XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) + void OLinkedDocumentsAccess::newReportWithPilot( const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) { - return impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _xDefinition, _nCommandType, _rObjectName ); + impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _nCommandType, _rObjectName ); } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newTableWithPilot() + void OLinkedDocumentsAccess::newTableWithPilot() { - Reference< XComponent > xDefinition; - return impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", xDefinition, -1, ::rtl::OUString() ); + impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", -1, ::rtl::OUString() ); } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newQueryWithPilot() + void OLinkedDocumentsAccess::newQueryWithPilot() { - Reference< XComponent > xDefinition; - return impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", xDefinition, -1, ::rtl::OUString() ); + impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", -1, ::rtl::OUString() ); } //------------------------------------------------------------------ Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID, -- cgit From bc49437f5fc053abe0f17f576db3996c44befb78 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 5 Feb 2010 14:07:26 +0100 Subject: autorecovery: post-rebase conflicts solved (namespace tools is ambiguous now) --- dbaccess/source/core/dataaccess/connection.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx index 41ae7e0e0b25..2a28df1c2871 100644 --- a/dbaccess/source/core/dataaccess/connection.cxx +++ b/dbaccess/source/core/dataaccess/connection.cxx @@ -78,6 +78,10 @@ using namespace ::comphelper; using namespace ::cppu; using namespace ::dbtools; +using ::com::sun::star::sdb::tools::XTableName; +using ::com::sun::star::sdb::tools::XObjectNames; +using ::com::sun::star::sdb::tools::XDataSourceMetaData; + //........................................................................ namespace dbaccess { @@ -821,7 +825,7 @@ void OConnection::impl_loadConnectionTools_throw() } // ----------------------------------------------------------------------------- -Reference< tools::XTableName > SAL_CALL OConnection::createTableName( ) throw (RuntimeException) +Reference< XTableName > SAL_CALL OConnection::createTableName( ) throw (RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::createTableName" ); MutexGuard aGuard(m_aMutex); @@ -832,7 +836,7 @@ Reference< tools::XTableName > SAL_CALL OConnection::createTableName( ) throw ( } // ----------------------------------------------------------------------------- -Reference< tools::XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw (RuntimeException) +Reference< XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw (RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::getObjectNames" ); MutexGuard aGuard(m_aMutex); @@ -843,7 +847,7 @@ Reference< tools::XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw } // ----------------------------------------------------------------------------- -Reference< tools::XDataSourceMetaData > SAL_CALL OConnection::getDataSourceMetaData( ) throw (RuntimeException) +Reference< XDataSourceMetaData > SAL_CALL OConnection::getDataSourceMetaData( ) throw (RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::getDataSourceMetaData" ); MutexGuard aGuard(m_aMutex); -- cgit From 56cc145c6e9fc00cfc8d173cd8335003169269b4 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 5 Feb 2010 22:03:01 +0100 Subject: autorecovery: allow for a human-readable DocumentServiceName instead of this strange class ID when creating a document definition --- .../source/core/dataaccess/documentcontainer.cxx | 17 ++++++-- dbaccess/source/ui/misc/linkeddocuments.cxx | 46 +++++++++++++--------- 2 files changed, 41 insertions(+), 22 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index 2e7cfd6b340f..c7d7778d9fd1 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -230,7 +230,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments MutexGuard aGuard(m_aMutex); // extrat known arguments - ::rtl::OUString sName, sPersistentName, sURL, sMediaType; + ::rtl::OUString sName, sPersistentName, sURL, sMediaType, sDocServiceName; Reference< XCommandProcessor > xCopyFrom; Reference< XConnection > xConnection; sal_Bool bAsTemplate( sal_False ); @@ -244,6 +244,7 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection ); lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate ); lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType ); + lcl_extractAndRemove( aArgs, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentServiceName" ) ), sDocServiceName ); // ClassID has two allowed types, so a special treatment here Any aClassIDArg = aArgs.get( "ClassID" ); @@ -301,8 +302,18 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments } else { - if ( bNeedClassID && sMediaType.getLength() ) - ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID ); + if ( bNeedClassID ) + { + if ( sMediaType.getLength() ) + ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID ); + else if ( sDocServiceName.getLength() ) + { + ::comphelper::MimeConfigurationHelper aConfigHelper( m_aContext.getLegacyServiceFactory() ); + const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByDocumentName( sDocServiceName ) ); + const ::comphelper::NamedValueCollection aMediaTypeProps( aProps ); + aClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() ); + } + } } } diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index ee8145845004..68bf52c49e5c 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -330,32 +330,39 @@ namespace dbaui const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition ) { OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::newDocument: invalid document container!"); - // determine the URL to use for the new document + // determine the class ID to use for the new document Sequence aClassId; - switch ( i_nActionID ) + if ( !i_rCreationArgs.has( "ClassID" ) + && !i_rCreationArgs.has( "MediaType" ) + && !i_rCreationArgs.has( "DocumentServiceName" ) + ) { - case ID_FORM_NEW_TEXT: - aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID); - OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal"); - break; + switch ( i_nActionID ) + { + case ID_FORM_NEW_TEXT: + aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID); + OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal"); + break; - case ID_FORM_NEW_CALC: - aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID); - break; + case ID_FORM_NEW_CALC: + aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID); + break; - case ID_FORM_NEW_IMPRESS: - aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID); - break; + case ID_FORM_NEW_IMPRESS: + aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID); + break; - case ID_REPORT_NEW_TEXT: - aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90); - break; + case ID_REPORT_NEW_TEXT: + aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90); + break; - default: - OSL_ENSURE( sal_False, "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" ); - return Reference< XComponent >(); + default: + OSL_ENSURE( sal_False, "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" ); + return Reference< XComponent >(); + } } + // load the document as template Reference< XComponent > xNewDocument; try @@ -365,7 +372,8 @@ namespace dbaui if ( xORB.is() ) { ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs ); - aCreationArgs.put( "ClassID", aClassId ); + if ( aClassId.getLength() ) + aCreationArgs.put( "ClassID", aClassId ); aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection ); // separate values which are real creation args from args relevant for opening the doc -- cgit From d8352bc6e00ae778fb060a0124ee98db3c76d6cf Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 9 Feb 2010 17:26:40 +0100 Subject: autorecovery: make m_pView a private member of the GenericController, with defined access methods --- dbaccess/inc/genericcontroller.hxx | 8 +++++--- dbaccess/source/ui/app/AppController.cxx | 14 +++++++------- dbaccess/source/ui/browser/brwctrlr.cxx | 4 ++-- dbaccess/source/ui/browser/genericcontroller.cxx | 6 +++--- dbaccess/source/ui/inc/RelationController.hxx | 2 +- dbaccess/source/ui/inc/brwctrlr.hxx | 2 +- dbaccess/source/ui/inc/querycontroller.hxx | 2 +- dbaccess/source/ui/querydesign/JoinController.cxx | 2 +- dbaccess/source/ui/querydesign/querycontroller.cxx | 2 +- dbaccess/source/ui/relationdesign/RelationController.cxx | 6 ++---- dbaccess/source/ui/tabledesign/TableController.cxx | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/inc/genericcontroller.hxx b/dbaccess/inc/genericcontroller.hxx index 33c315a843a2..c35e166d374a 100644 --- a/dbaccess/inc/genericcontroller.hxx +++ b/dbaccess/inc/genericcontroller.hxx @@ -222,9 +222,10 @@ namespace dbaui ::std::auto_ptr< OGenericUnoController_Data > m_pData; + ODataView* m_pView; // our (VCL) "main window" #ifdef DBG_UTIL - bool m_bDescribingSupportedFeatures; + bool m_bDescribingSupportedFeatures; #endif protected: @@ -258,7 +259,6 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xDatabaseContext; ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > m_xTitleHelper; - ODataView* m_pView; // our (VCL) "main window" sal_Bool m_bPreview; sal_Bool m_bReadOnly; @@ -416,7 +416,9 @@ namespace dbaui public: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const { return m_xServiceFactory; } - ODataView* getView() const { return m_pView; } + ODataView* getView() const { return m_pView; } + void setView( ODataView& i_rView ) { m_pView = &i_rView; } + void clearView() { m_pView = NULL; } // shows a error box if the SQLExceptionInfo is valid void showError(const ::dbtools::SQLExceptionInfo& _rInfo); diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 47547413d90d..a274b29d2bc9 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -345,8 +345,8 @@ OApplicationController::~OApplicationController() osl_incrementInterlockedCount( &m_refCount ); dispose(); } - ::std::auto_ptr< Window> aTemp(m_pView); - m_pView = NULL; + ::std::auto_ptr< Window> aTemp( getView() ); + clearView(); DBG_DTOR(OApplicationController,NULL); } @@ -455,15 +455,15 @@ void SAL_CALL OApplicationController::disposing() DBG_UNHANDLED_EXCEPTION(); } - m_pView = NULL; + clearView(); OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5 } //-------------------------------------------------------------------- sal_Bool OApplicationController::Construct(Window* _pParent) { - m_pView = new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ); - m_pView->SetUniqueId(UID_APP_VIEW); + setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) ); + getView()->SetUniqueId(UID_APP_VIEW); // late construction sal_Bool bSuccess = sal_False; @@ -482,8 +482,8 @@ sal_Bool OApplicationController::Construct(Window* _pParent) if ( !bSuccess ) { - ::std::auto_ptr< Window> aTemp(m_pView); - m_pView = NULL; + ::std::auto_ptr< Window> aTemp( getView() ); + clearView(); return sal_False; } diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index 20523c1339f8..5277afb37500 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -829,7 +829,7 @@ sal_Bool SbaXDataBrowserController::Construct(Window* pParent) // --------------- // create the view - m_pView = new UnoDataBrowserView( pParent, *this, getORB() ); + setView( * new UnoDataBrowserView( pParent, *this, getORB() ) ); if (!getBrowserView()) return sal_False; @@ -1345,7 +1345,7 @@ void SbaXDataBrowserController::disposing() { removeControlListeners(getBrowserView()->getGridControl()); // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...) - m_pView = NULL; + clearView(); } if(m_aInvalidateClipboard.IsActive()) diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx index 052aaf34e7fa..150c701aab20 100644 --- a/dbaccess/source/ui/browser/genericcontroller.cxx +++ b/dbaccess/source/ui/browser/genericcontroller.cxx @@ -251,6 +251,7 @@ DBG_NAME(OGenericUnoController) // ------------------------------------------------------------------------- OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFactory >& _rM) :OGenericUnoController_Base( getMutex() ) + ,m_pView(NULL) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) #endif @@ -258,7 +259,6 @@ OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFacto ,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask)) ,m_xServiceFactory(_rM) ,m_aCurrentFrame( *this ) - ,m_pView(NULL) ,m_bPreview(sal_False) ,m_bReadOnly(sal_False) ,m_bCurrentlyModified(sal_False) @@ -286,13 +286,13 @@ OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFacto // ----------------------------------------------------------------------------- OGenericUnoController::OGenericUnoController() :OGenericUnoController_Base( getMutex() ) + ,m_pView(NULL) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) #endif ,m_aAsyncInvalidateAll(LINK(this, OGenericUnoController, OnAsyncInvalidateAll)) ,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask)) ,m_aCurrentFrame( *this ) - ,m_pView(NULL) ,m_bPreview(sal_False) ,m_bReadOnly(sal_False) ,m_bCurrentlyModified(sal_False) @@ -415,7 +415,7 @@ void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArgumen // no one clears my view if I won't ::std::auto_ptr aTemp(m_pView); m_pView = NULL; - throw e; + throw; } } diff --git a/dbaccess/source/ui/inc/RelationController.hxx b/dbaccess/source/ui/inc/RelationController.hxx index 6bc1561e0785..fe080672a5bf 100644 --- a/dbaccess/source/ui/inc/RelationController.hxx +++ b/dbaccess/source/ui/inc/RelationController.hxx @@ -60,7 +60,7 @@ namespace dbaui // execute a feature virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); - ORelationDesignView* getRelationView() { return static_cast(m_pView); } + ORelationDesignView* getRelationView() { return static_cast( getView() ); } void loadData(); TTableWindowData::value_type existsTable(const ::rtl::OUString& _rComposedTableName,sal_Bool _bCase) const; diff --git a/dbaccess/source/ui/inc/brwctrlr.hxx b/dbaccess/source/ui/inc/brwctrlr.hxx index 128b20178e8a..a4f05670252b 100644 --- a/dbaccess/source/ui/inc/brwctrlr.hxx +++ b/dbaccess/source/ui/inc/brwctrlr.hxx @@ -164,7 +164,7 @@ namespace dbaui public: SbaXDataBrowserController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); - UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(m_pView); } + UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(getView()); } // late construction virtual sal_Bool Construct(Window* pParent); diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx index 6db721095c15..42382f41277d 100644 --- a/dbaccess/source/ui/inc/querycontroller.hxx +++ b/dbaccess/source/ui/inc/querycontroller.hxx @@ -142,7 +142,7 @@ namespace dbaui virtual void reconnect( sal_Bool _bUI ); virtual ::rtl::OUString getPrivateTitle( ) const; - OQueryContainerWindow* getContainer() const { return static_cast< OQueryContainerWindow* >( getView() ); } + OQueryContainerWindow* getContainer() const { return static_cast< OQueryContainerWindow* >( getView() ); } public: OQueryController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); diff --git a/dbaccess/source/ui/querydesign/JoinController.cxx b/dbaccess/source/ui/querydesign/JoinController.cxx index 95531ed3bbaa..00f537686d38 100644 --- a/dbaccess/source/ui/querydesign/JoinController.cxx +++ b/dbaccess/source/ui/querydesign/JoinController.cxx @@ -283,7 +283,7 @@ void OJoinController::disposing() OJoinController_BASE::disposing(); - m_pView = NULL; + clearView(); m_vTableConnectionData.clear(); m_vTableData.clear(); diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx index ca1bc56f01ef..79adb58af366 100644 --- a/dbaccess/source/ui/querydesign/querycontroller.cxx +++ b/dbaccess/source/ui/querydesign/querycontroller.cxx @@ -1014,7 +1014,7 @@ sal_Bool OQueryController::Construct(Window* pParent) { // TODO: we have to check if we should create the text- or the design- view - m_pView = new OQueryContainerWindow( pParent, *this, getORB() ); + setView( * new OQueryContainerWindow( pParent, *this, getORB() ) ); return OJoinController::Construct(pParent); } diff --git a/dbaccess/source/ui/relationdesign/RelationController.cxx b/dbaccess/source/ui/relationdesign/RelationController.cxx index 3bd2aa12a8ae..96a426a06bd8 100644 --- a/dbaccess/source/ui/relationdesign/RelationController.cxx +++ b/dbaccess/source/ui/relationdesign/RelationController.cxx @@ -202,7 +202,7 @@ void ORelationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue } break; case SID_RELATION_ADD_RELATION: - static_cast(static_cast(m_pView)->getTableView())->AddNewRelation(); + static_cast(static_cast( getView() )->getTableView())->AddNewRelation(); break; default: OJoinController::Execute(_nId,aArgs); @@ -263,10 +263,8 @@ void ORelationController::impl_initialize() // ----------------------------------------------------------------------------- sal_Bool ORelationController::Construct(Window* pParent) { - m_pView = new ORelationDesignView( pParent, *this, getORB() ); + setView( * new ORelationDesignView( pParent, *this, getORB() ) ); OJoinController::Construct(pParent); -// m_pView->Construct(); -// m_pView->Show(); return sal_True; } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index 1eed02543cda..4296082b1c7b 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -207,7 +207,7 @@ void OTableController::stopTableListening() void OTableController::disposing() { OTableController_BASE::disposing(); - m_pView = NULL; + clearView(); m_vRowList.clear(); } @@ -579,7 +579,7 @@ void OTableController::impl_initialize() // ----------------------------------------------------------------------------- sal_Bool OTableController::Construct(Window* pParent) { - m_pView = new OTableDesignView( pParent, getORB(), *this ); + setView( * new OTableDesignView( pParent, getORB(), *this ) ); OTableController_BASE::Construct(pParent); // m_pView->Construct(); // m_pView->Show(); -- cgit From 5f0d3499f04328f9419da976f7cb8552155a45ed Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 9 Feb 2010 23:12:40 +0100 Subject: autorecovery: GetDocumentServiceFromMediaType: try alternative, seemingly equivalent approach --- dbaccess/source/core/dataaccess/documentdefinition.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index 7a2e24484050..733f5d16a5f2 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -569,6 +569,15 @@ namespace dbaccess } } } +#if OSL_DEBUG_LEVEL > 0 + // alternative, shorter approach + const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByMediaType( _rMediaType ) ); + const ::comphelper::NamedValueCollection aMediaTypeProps( aProps ); + const ::rtl::OUString sAlternativeResult = aMediaTypeProps.getOrDefault( "ObjectDocumentServiceName", ::rtl::OUString() ); + OSL_ENSURE( sAlternativeResult == sResult, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (1)!" ); + const Sequence< sal_Int8 > aAlternativeClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() ); + OSL_ENSURE( aAlternativeClassID == _rClassId, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (2)!" ); +#endif } catch ( Exception& ) { -- cgit From 876b084e800056097a71f75fe134511ccacce227 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 9 Feb 2010 23:46:32 +0100 Subject: autorecovery: corrected assertion --- dbaccess/source/ui/app/AppController.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index a274b29d2bc9..dbe5f54733fc 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -512,8 +512,8 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr Reference xCon(_rSource.Source, UNO_QUERY); if ( xCon.is() ) { - DBG_ASSERT( ( m_xDataSourceConnection == xCon ) && getContainer() && ( getContainer()->getElementType() == E_TABLE ), - "OApplicationController::disposing: the below code will ignore this call - why?" ); + DBG_ASSERT( m_xDataSourceConnection == xCon, + "OApplicationController::disposing: which connection does this come from?" ); if ( getContainer() && getContainer()->getElementType() == E_TABLE ) getContainer()->clearPages(); -- cgit From 72285cf677cba7d9ef3e8d0207f1bcf9c72672f2 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 10 Feb 2010 09:44:20 +0100 Subject: dba33e: fix not operator --- dbaccess/source/ui/dlg/dbwizsetup.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index 9c14bfabd17a..a092109efe80 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -945,7 +945,7 @@ sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() { ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase(); ::connectivity::DriversConfig aDriverConfig(getORB()); - if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || m_pImpl->getDriver(sEmbeddedURL).is() ) + if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() ) sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); return sEmbeddedURL; -- cgit From c7f5a15eb8d58e60a6abbef4c2d5bc976c096103 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 10 Feb 2010 10:50:53 +0100 Subject: dba33f: #i102366# parse function as predicate --- dbaccess/source/ui/querydesign/QueryDesignView.cxx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index b7e005e420aa..f482c99c5bb4 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -2235,11 +2235,17 @@ namespace SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct)) { ::rtl::OUString aColumns; - pColumnRef->parseNodeToStr( aColumns, - xConnection, - &rController.getParser().getContext(), - sal_True, - sal_True); // quote is to true because we need quoted elements inside the function + pColumnRef->parseNodeToPredicateStr(aColumns, + xConnection, + rController.getNumberFormatter(), + _pView->getLocale(), + static_cast(_pView->getDecimalSeparator().toChar()), + &rController.getParser().getContext()); + //pColumnRef->parseNodeToStr( aColumns, + // xConnection, + // &rController.getParser().getContext(), + // sal_True, + // sal_True); // quote is to true because we need quoted elements inside the function sal_Int32 nFunctionType = FKT_NONE; ::connectivity::OSQLParseNode* pParamRef = NULL; -- cgit From 4f8f578855d93e0821ade20218ec8269e4cb8b8c Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 10 Feb 2010 11:29:34 +0100 Subject: autorecovery: when saving to a new location, dispose the forms/reports container after disposing the storages they're based on --- dbaccess/source/core/dataaccess/databasedocument.cxx | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 33ecdf3311ce..c4355d5bdc1b 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -1023,6 +1023,12 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const m_pImpl->disposeStorages(); + // each and every document definition obtained via m_xForms and m_xReports depends + // on the sub storages which we just disposed. So, dispose the forms/reports collections, too. + // This ensures that they're re-created when needed. + clearObjectContainer( m_xForms ); + clearObjectContainer( m_xReports ); + xNewRootStorage = m_pImpl->switchToStorage( xTargetStorage ); m_pImpl->m_bDocumentReadOnly = sal_False; -- cgit From 02df552c45b05d00d656d4aaba73907469f5958e Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 10 Feb 2010 13:08:22 +0100 Subject: dba33e: #i107717# some renaming and wording changed --- dbaccess/source/core/api/View.cxx | 26 +++++++++++++++------- dbaccess/source/core/dataaccess/ModelImpl.cxx | 8 +++---- dbaccess/source/core/dataaccess/connection.cxx | 23 +++++++------------ dbaccess/source/core/dataaccess/connection.hxx | 2 +- .../source/core/dataaccess/databasedocument.cxx | 4 ++-- dbaccess/source/core/dataaccess/datasource.cxx | 2 +- dbaccess/source/core/inc/View.hxx | 4 ++-- dbaccess/source/filter/xml/xmlDatabase.cxx | 6 ++--- dbaccess/source/filter/xml/xmlExport.cxx | 6 ++--- 9 files changed, 42 insertions(+), 39 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/View.cxx b/dbaccess/source/core/api/View.cxx index d7e5221446b0..4d770c867817 100644 --- a/dbaccess/source/core/api/View.cxx +++ b/dbaccess/source/core/api/View.cxx @@ -65,6 +65,16 @@ namespace dbaccess using ::com::sun::star::sdbc::XRow; /** === end UNO using === **/ + ::rtl::OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const ::rtl::OUString& i_sSetting) + { + ::rtl::OUString sSupportService; + Any aValue; + if ( dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) ) + { + aValue >>= sSupportService; + } + return sSupportService; + } //==================================================================== //= View //==================================================================== @@ -77,8 +87,8 @@ namespace dbaccess try { Reference xFac(_rxConnection,UNO_QUERY_THROW); - static const ::rtl::OUString s_sViewSupport(RTL_CONSTASCII_USTRINGPARAM("ViewSupportServiceName")); - m_xViewSupport.set(xFac->createInstance(s_sViewSupport),UNO_QUERY); + static const ::rtl::OUString s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName")); + m_XViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY); } catch(const Exception& ) { @@ -97,7 +107,7 @@ namespace dbaccess // ------------------------------------------------------------------------- Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException) { - if(_rType == getCppuType( (Reference*)0) && !m_xViewSupport.is() ) + if(_rType == getCppuType( (Reference*)0) && !m_XViewAccess.is() ) return Any(); Any aReturn = View_Base::queryInterface( _rType ); if ( !aReturn.hasValue() ) @@ -117,7 +127,7 @@ namespace dbaccess const Type* pEnd = pIter + aTypes.getLength(); for(;pIter != pEnd ;++pIter) { - if( (*pIter != aAlterType || m_xViewSupport.is()) ) + if( (*pIter != aAlterType || m_XViewAccess.is()) ) aOwnTypes.push_back(*pIter); } @@ -128,18 +138,18 @@ namespace dbaccess //-------------------------------------------------------------------- void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException) { - OSL_ENSURE(m_xViewSupport.is(),"Illegal call to AlterView!"); - m_xViewSupport->alterCommand(this,_rNewCommand); + OSL_ENSURE(m_XViewAccess.is(),"Illegal call to AlterView!"); + m_XViewAccess->alterCommand(this,_rNewCommand); } //-------------------------------------------------------------------- void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const { - if ( _nHandle == m_nCommandHandle && m_xViewSupport.is() ) + if ( _nHandle == m_nCommandHandle && m_XViewAccess.is() ) { // retrieve the very current command, don't rely on the base classes cached value // (which we initialized empty, anyway) - _rValue <<= m_xViewSupport->getCommand(const_cast(this)); + _rValue <<= m_XViewAccess->getCommand(const_cast(this)); return; } diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 5abf774e1d92..0283757ad7c9 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -1187,10 +1187,10 @@ const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings() AsciiPropertyValue( "TableAlterationServiceName", makeAny( ::rtl::OUString() ) ), AsciiPropertyValue( "TableRenameServiceName", makeAny( ::rtl::OUString() ) ), AsciiPropertyValue( "ViewAlterationServiceName", makeAny( ::rtl::OUString() ) ), - AsciiPropertyValue( "ViewSupportServiceName", makeAny( ::rtl::OUString() ) ), - AsciiPropertyValue( "CommandDefinitionSupplier", makeAny( ::rtl::OUString() ) ), - AsciiPropertyValue( "FormSupplier", makeAny( ::rtl::OUString() ) ), - AsciiPropertyValue( "ReportSupplier", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "ViewAccessServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "CommandDefinitions", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "Forms", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "Reports", makeAny( ::rtl::OUString() ) ), AsciiPropertyValue( "KeyAlterationServiceName", makeAny( ::rtl::OUString() ) ), AsciiPropertyValue( "IndexAlterationServiceName", makeAny( ::rtl::OUString() ) ), diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx index 41ae7e0e0b25..c6a713880f1c 100644 --- a/dbaccess/source/core/dataaccess/connection.cxx +++ b/dbaccess/source/core/dataaccess/connection.cxx @@ -732,24 +732,17 @@ Reference< XInterface > SAL_CALL OConnection::createInstance( const ::rtl::OUStr } else { - Reference xDs = dbaccess::getDataSource(*this); - Any aValue; - if ( dbtools::getDataSourceSetting(xDs,_sServiceSpecifier,aValue) ) + if ( _sServiceSpecifier.getLength() ) { - ::rtl::OUString sSupportService; - aValue >>= sSupportService; - if ( sSupportService.getLength() ) + TSupportServices::iterator aFind = m_aSupportServices.find(_sServiceSpecifier); + if ( aFind == m_aSupportServices.end() ) { - TSupportServices::iterator aFind = m_aSupportServices.find(sSupportService); - if ( aFind == m_aSupportServices.end()) - { - Sequence aArgs(1); - Reference xMy(this); - aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")),makeAny(xMy)); - aFind = m_aSupportServices.insert(TSupportServices::value_type(sSupportService,m_aContext.createComponentWithArguments(sSupportService,aArgs))).first; - } - return aFind->second; + Sequence aArgs(1); + Reference xMy(this); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")),makeAny(xMy)); + aFind = m_aSupportServices.insert(TSupportServices::value_type(_sServiceSpecifier,m_aContext.createComponentWithArguments(_sServiceSpecifier,aArgs))).first; } + return aFind->second; } } return Reference< XInterface >(xRet,UNO_QUERY); diff --git a/dbaccess/source/core/dataaccess/connection.hxx b/dbaccess/source/core/dataaccess/connection.hxx index 98b8535953db..3de59df5f134 100644 --- a/dbaccess/source/core/dataaccess/connection.hxx +++ b/dbaccess/source/core/dataaccess/connection.hxx @@ -111,7 +111,7 @@ protected: ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XTableUIProvider > m_xTableUIProvider; // defines the helper services for example to query the command of a view - // @ see com.sun.star.sdb.tools.XViewSupport + // @ see com.sun.star.sdb.tools.XViewAccess DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>, TSupportServices); TSupportServices m_aSupportServices; diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 862ebc664993..97903a613852 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -1155,14 +1155,14 @@ Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODa { Any aValue; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this); - if ( dbtools::getDataSourceSetting(xMy,bFormsContainer ? "FormSupplier" : "ReportSupplier",aValue) ) + if ( dbtools::getDataSourceSetting(xMy,bFormsContainer ? "Forms" : "Reports",aValue) ) { ::rtl::OUString sSupportService; aValue >>= sSupportService; if ( sSupportService.getLength() ) { Sequence aArgs(1); - aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSource")),makeAny(xMy)); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseDocument")),makeAny(xMy)); xContainer.set(m_pImpl->m_aContext.createComponentWithArguments(sSupportService,aArgs),UNO_QUERY); rContainerRef = xContainer; } diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index f0cca707fc3b..bc635824bfd2 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -1344,7 +1344,7 @@ Reference< XNameAccess > SAL_CALL ODatabaseSource::getQueryDefinitions( ) throw( { Any aValue; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this); - if ( dbtools::getDataSourceSetting(xMy,"CommandDefinitionSupplier",aValue) ) + if ( dbtools::getDataSourceSetting(xMy,"CommandDefinitions",aValue) ) { ::rtl::OUString sSupportService; aValue >>= sSupportService; diff --git a/dbaccess/source/core/inc/View.hxx b/dbaccess/source/core/inc/View.hxx index 0cda27afcf82..4e96a1882423 100644 --- a/dbaccess/source/core/inc/View.hxx +++ b/dbaccess/source/core/inc/View.hxx @@ -35,7 +35,7 @@ /** === begin UNO includes === **/ #include -#include +#include /** === end UNO includes === **/ #include @@ -78,7 +78,7 @@ namespace dbaccess virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle ) const; private: - ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XViewSupport> m_xViewSupport; + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XViewAccess> m_xViewAccess; sal_Int32 m_nCommandHandle; private: using View_Base::getFastPropertyValue; diff --git a/dbaccess/source/filter/xml/xmlDatabase.cxx b/dbaccess/source/filter/xml/xmlDatabase.cxx index 89111c6e6e48..842a598340cc 100644 --- a/dbaccess/source/filter/xml/xmlDatabase.cxx +++ b/dbaccess/source/filter/xml/xmlDatabase.cxx @@ -88,7 +88,7 @@ SvXMLImportContext* OXMLDatabase::CreateChildContext( GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); Any aValue; ::rtl::OUString sService; - dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"FormSupplier",aValue); + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Forms",aValue); aValue >>= sService; if ( !sService.getLength() ) { @@ -103,7 +103,7 @@ SvXMLImportContext* OXMLDatabase::CreateChildContext( GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); Any aValue; ::rtl::OUString sService; - dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"ReportSupplier",aValue); + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Reports",aValue); aValue >>= sService; if ( !sService.getLength() ) { @@ -118,7 +118,7 @@ SvXMLImportContext* OXMLDatabase::CreateChildContext( GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); Any aValue; ::rtl::OUString sService; - dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitionSupplier",aValue); + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitions",aValue); aValue >>= sService; if ( !sService.getLength() ) { diff --git a/dbaccess/source/filter/xml/xmlExport.cxx b/dbaccess/source/filter/xml/xmlExport.cxx index 28c85bcb5043..d9d6f671e57e 100644 --- a/dbaccess/source/filter/xml/xmlExport.cxx +++ b/dbaccess/source/filter/xml/xmlExport.cxx @@ -1067,7 +1067,7 @@ void ODBExport::exportForms() { Any aValue; ::rtl::OUString sService; - dbtools::getDataSourceSetting(getDataSource(),"ReportSupplier",aValue); + dbtools::getDataSourceSetting(getDataSource(),"Forms",aValue); aValue >>= sService; if ( !sService.getLength() ) { @@ -1088,7 +1088,7 @@ void ODBExport::exportReports() { Any aValue; ::rtl::OUString sService; - dbtools::getDataSourceSetting(getDataSource(),"ReportSupplier",aValue); + dbtools::getDataSourceSetting(getDataSource(),"Reports",aValue); aValue >>= sService; if ( !sService.getLength() ) { @@ -1109,7 +1109,7 @@ void ODBExport::exportQueries(sal_Bool _bExportContext) { Any aValue; ::rtl::OUString sService; - dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitionSupplier",aValue); + dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitions",aValue); aValue >>= sService; if ( !sService.getLength() ) { -- cgit From 0c2bd96304ff4b6a5d2d811ddac283709e105dda Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 10 Feb 2010 13:09:56 +0100 Subject: dba33e: #i107717# some renaming and wording changed --- dbaccess/source/core/api/View.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/View.cxx b/dbaccess/source/core/api/View.cxx index 4d770c867817..fa528d203466 100644 --- a/dbaccess/source/core/api/View.cxx +++ b/dbaccess/source/core/api/View.cxx @@ -88,7 +88,7 @@ namespace dbaccess { Reference xFac(_rxConnection,UNO_QUERY_THROW); static const ::rtl::OUString s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName")); - m_XViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY); + m_xViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY); } catch(const Exception& ) { @@ -107,7 +107,7 @@ namespace dbaccess // ------------------------------------------------------------------------- Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException) { - if(_rType == getCppuType( (Reference*)0) && !m_XViewAccess.is() ) + if(_rType == getCppuType( (Reference*)0) && !m_xViewAccess.is() ) return Any(); Any aReturn = View_Base::queryInterface( _rType ); if ( !aReturn.hasValue() ) @@ -127,7 +127,7 @@ namespace dbaccess const Type* pEnd = pIter + aTypes.getLength(); for(;pIter != pEnd ;++pIter) { - if( (*pIter != aAlterType || m_XViewAccess.is()) ) + if( (*pIter != aAlterType || m_xViewAccess.is()) ) aOwnTypes.push_back(*pIter); } @@ -138,18 +138,18 @@ namespace dbaccess //-------------------------------------------------------------------- void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException) { - OSL_ENSURE(m_XViewAccess.is(),"Illegal call to AlterView!"); - m_XViewAccess->alterCommand(this,_rNewCommand); + OSL_ENSURE(m_xViewAccess.is(),"Illegal call to AlterView!"); + m_xViewAccess->alterCommand(this,_rNewCommand); } //-------------------------------------------------------------------- void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const { - if ( _nHandle == m_nCommandHandle && m_XViewAccess.is() ) + if ( _nHandle == m_nCommandHandle && m_xViewAccess.is() ) { // retrieve the very current command, don't rely on the base classes cached value // (which we initialized empty, anyway) - _rValue <<= m_XViewAccess->getCommand(const_cast(this)); + _rValue <<= m_xViewAccess->getCommand(const_cast(this)); return; } -- cgit From f4ba6a75910f44a8b98de1243fbd5a9dfef5aa49 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 10 Feb 2010 14:05:19 +0100 Subject: autorecovery: let the SingleDocController, and derived classes, support XModifiable --- dbaccess/inc/singledoccontroller.hxx | 21 ++++-- dbaccess/source/ui/inc/JoinController.hxx | 2 +- dbaccess/source/ui/inc/TableController.hxx | 2 +- dbaccess/source/ui/inc/querycontroller.hxx | 10 ++- dbaccess/source/ui/misc/singledoccontroller.cxx | 77 +++++++++++++++++----- dbaccess/source/ui/querydesign/JoinController.cxx | 9 +-- dbaccess/source/ui/querydesign/QueryDesignView.cxx | 2 +- .../source/ui/querydesign/SelectionBrowseBox.cxx | 14 ++-- dbaccess/source/ui/querydesign/querycontroller.cxx | 76 ++++++++++----------- .../ui/relationdesign/RelationController.cxx | 2 +- dbaccess/source/ui/tabledesign/TableController.cxx | 10 +-- 11 files changed, 134 insertions(+), 91 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/inc/singledoccontroller.hxx b/dbaccess/inc/singledoccontroller.hxx index 6f98979a1a65..eb21ad5b0ddc 100644 --- a/dbaccess/inc/singledoccontroller.hxx +++ b/dbaccess/inc/singledoccontroller.hxx @@ -40,13 +40,14 @@ #include #include #include +#include /** === end UNO includes === **/ #include #include #include #include -#include +#include #include #include @@ -61,8 +62,9 @@ namespace dbaui //==================================================================== class OSingleDocumentController; - typedef ::cppu::ImplInheritanceHelper1 < OGenericUnoController + typedef ::cppu::ImplInheritanceHelper2 < OGenericUnoController , ::com::sun::star::document::XScriptInvocationContext + , ::com::sun::star::util::XModifiable > OSingleDocumentController_Base; struct OSingleDocumentControllerImpl; @@ -93,15 +95,14 @@ namespace dbaui virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getPrivateModel() const; + sal_Bool impl_isModified() const; + virtual void impl_onModifyChanged(); + public: sal_Bool isReadOnly() const; sal_Bool isEditable() const; void setEditable(sal_Bool _bEditable); - sal_Bool isModified() const; - - virtual void setModified(sal_Bool _bModified=sal_True); - // need for undo's and redo's SfxUndoManager* getUndoMgr(); @@ -181,6 +182,14 @@ namespace dbaui // XScriptInvocationContext virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > SAL_CALL getScriptContainer() throw (::com::sun::star::uno::RuntimeException); + // XModifiable + virtual ::sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException); + + // XModifyBroadcaster + virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + // XTitle virtual ::rtl::OUString SAL_CALL getTitle( ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/ui/inc/JoinController.hxx b/dbaccess/source/ui/inc/JoinController.hxx index 786839e4e6fc..88fc32ee8c07 100644 --- a/dbaccess/source/ui/inc/JoinController.hxx +++ b/dbaccess/source/ui/inc/JoinController.hxx @@ -112,7 +112,7 @@ namespace dbaui // --------------------------------------------------------------- // OSingleDocumentController overridables virtual void reconnect( sal_Bool _bUI ); - virtual void setModified( sal_Bool _bModified = sal_True ); + virtual void impl_onModifyChanged(); // --------------------------------------------------------------- // own overridables diff --git a/dbaccess/source/ui/inc/TableController.hxx b/dbaccess/source/ui/inc/TableController.hxx index 736fd7bdf6a8..1ccc72668dc9 100644 --- a/dbaccess/source/ui/inc/TableController.hxx +++ b/dbaccess/source/ui/inc/TableController.hxx @@ -130,7 +130,7 @@ namespace dbaui inline sal_Bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; } inline const ::rtl::OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; } - virtual void setModified(sal_Bool _bModified=sal_True); + virtual void impl_onModifyChanged(); // const ::connectivity::OSQLParseNode* getParseTree() const { return m_aSqlIterator.getParseTree();} // need for undo's and redo's diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx index 42382f41277d..5a1d2b24b82b 100644 --- a/dbaccess/source/ui/inc/querycontroller.hxx +++ b/dbaccess/source/ui/inc/querycontroller.hxx @@ -125,8 +125,8 @@ namespace dbaui void executeQuery(); bool doSaveAsDoc(sal_Bool _bSaveAs); - void saveViewSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps); - void loadViewSettings(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps); + void saveViewSettings( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& o_rViewData ); + void loadViewSettings( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rViewData ); ::rtl::OUString translateStatement( bool _bFireStatementChange = true ); ::rtl::OUString getDefaultName() const; @@ -153,7 +153,7 @@ namespace dbaui void clearFields(); - virtual void setModified(sal_Bool _bModified=sal_True); + virtual void impl_onModifyChanged(); // should the statement be parsed by our own sql parser sal_Bool isEsacpeProcessing() const { return m_bEscapeProcessing; } @@ -195,6 +195,10 @@ namespace dbaui static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); + // XController + virtual ::com::sun::star::uno::Any SAL_CALL getViewData(void) throw( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL restoreViewData(const ::com::sun::star::uno::Any& Data) throw( ::com::sun::star::uno::RuntimeException ); + private: virtual void onLoadedMenu(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager); // OPropertyArrayUsageHelper diff --git a/dbaccess/source/ui/misc/singledoccontroller.cxx b/dbaccess/source/ui/misc/singledoccontroller.cxx index ecc898cbecbc..1ff0a7953989 100644 --- a/dbaccess/source/ui/misc/singledoccontroller.cxx +++ b/dbaccess/source/ui/misc/singledoccontroller.cxx @@ -97,6 +97,7 @@ namespace dbaui using ::com::sun::star::uno::UNO_SET_THROW; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::frame::XUntitledNumbers; + using ::com::sun::star::beans::PropertyVetoException; /** === end UNO using === **/ class DataSourceHolder @@ -143,6 +144,9 @@ namespace dbaui OModuleClient m_aModuleClient; ::dbtools::SQLExceptionInfo m_aCurrentError; // contains the current error which can be set through IEnvironment + ::cppu::OInterfaceContainerHelper + m_aModifyListeners; + // SharedConnection m_xConnection; ::dbtools::DatabaseMetaData m_aSdbMetaData; @@ -157,8 +161,9 @@ namespace dbaui sal_Bool m_bModified; // is the data modified bool m_bNotAttached; - OSingleDocumentControllerImpl() - :m_aDocScriptSupport() + OSingleDocumentControllerImpl( ::osl::Mutex& i_rMutex ) + :m_aModifyListeners( i_rMutex ) + ,m_aDocScriptSupport() ,m_nDocStartNumber(0) ,m_bSuspended( sal_False ) ,m_bEditable(sal_True) @@ -188,7 +193,7 @@ namespace dbaui //-------------------------------------------------------------------- OSingleDocumentController::OSingleDocumentController(const Reference< XMultiServiceFactory >& _rxORB) :OSingleDocumentController_Base( _rxORB ) - ,m_pImpl(new OSingleDocumentControllerImpl()) + ,m_pImpl( new OSingleDocumentControllerImpl( getMutex() ) ) { } @@ -543,15 +548,6 @@ namespace dbaui InvalidateFeature(ID_BROWSER_UNDO); InvalidateFeature(ID_BROWSER_REDO); } - // ----------------------------------------------------------------------------- - void OSingleDocumentController::setModified(sal_Bool _bModified) - { - m_pImpl->m_bModified = _bModified; - InvalidateFeature(ID_BROWSER_SAVEDOC); - - if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) ) - InvalidateFeature(ID_BROWSER_SAVEASDOC); - } // ----------------------------------------------------------------------------- ::rtl::OUString OSingleDocumentController::getDataSourceName() const @@ -593,12 +589,6 @@ namespace dbaui return m_pImpl->m_bEditable; } - // ----------------------------------------------------------------------------- - sal_Bool OSingleDocumentController::isModified() const - { - return m_pImpl->m_bModified; - } - // ----------------------------------------------------------------------------- void OSingleDocumentController::setEditable(sal_Bool _bEditable) { @@ -705,6 +695,57 @@ namespace dbaui return Reference< XEmbeddedScripts >( getDatabaseDocument(), UNO_QUERY_THROW ); } + // ----------------------------------------------------------------------------- + void SAL_CALL OSingleDocumentController::addModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + m_pImpl->m_aModifyListeners.addInterface( i_Listener ); + } + + // ----------------------------------------------------------------------------- + void SAL_CALL OSingleDocumentController::removeModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + m_pImpl->m_aModifyListeners.removeInterface( i_Listener ); + } + + // ----------------------------------------------------------------------------- + ::sal_Bool SAL_CALL OSingleDocumentController::isModified( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + return impl_isModified(); + } + + // ----------------------------------------------------------------------------- + void SAL_CALL OSingleDocumentController::setModified( ::sal_Bool i_bModified ) throw (PropertyVetoException, RuntimeException) + { + ::osl::ClearableMutexGuard aGuard( getMutex() ); + + if ( m_pImpl->m_bModified == i_bModified ) + return; + + m_pImpl->m_bModified = i_bModified; + impl_onModifyChanged(); + + EventObject aEvent( *this ); + aGuard.clear(); + m_pImpl->m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent ); + } + + // ----------------------------------------------------------------------------- + sal_Bool OSingleDocumentController::impl_isModified() const + { + return m_pImpl->m_bModified; + } + + // ----------------------------------------------------------------------------- + void OSingleDocumentController::impl_onModifyChanged() + { + InvalidateFeature( ID_BROWSER_SAVEDOC ); + if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) ) + InvalidateFeature( ID_BROWSER_SAVEASDOC ); + } + //........................................................................ } // namespace dbaui //........................................................................ diff --git a/dbaccess/source/ui/querydesign/JoinController.cxx b/dbaccess/source/ui/querydesign/JoinController.cxx index 00f537686d38..0c5367165530 100644 --- a/dbaccess/source/ui/querydesign/JoinController.cxx +++ b/dbaccess/source/ui/querydesign/JoinController.cxx @@ -297,10 +297,10 @@ void OJoinController::reconnect( sal_Bool _bUI ) } // ----------------------------------------------------------------------------- -void OJoinController::setModified(sal_Bool _bModified) +void OJoinController::impl_onModifyChanged() { - OJoinController_BASE::setModified(_bModified); - InvalidateFeature(SID_RELATION_ADD_RELATION); + OJoinController_BASE::impl_onModifyChanged(); + InvalidateFeature( SID_RELATION_ADD_RELATION ); } // ----------------------------------------------------------------------------- void OJoinController::SaveTabWinPosSize(OTableWindow* pTabWin, long nOffsetX, long nOffsetY) @@ -329,9 +329,6 @@ FeatureState OJoinController::GetState(sal_uInt16 _nId) const case ID_BROWSER_EDITDOC: aReturn.bChecked = isEditable(); break; - case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = isConnected() && isModified(); - break; case ID_BROWSER_ADDTABLE: aReturn.bEnabled = ( getView() != NULL ) && const_cast< OJoinController* >( this )->getJoinView()->getTableView()->IsAddAllowed(); diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index b7e005e420aa..d38f708091f1 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -2599,7 +2599,7 @@ IMPL_LINK( OQueryDesignView, SplitHdl, void*, /*p*/ ) m_bInSplitHandler = sal_True; m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),m_aSplitter.GetSplitPosPixel() ) ); static_cast(getController()).setSplitPos(m_aSplitter.GetSplitPosPixel()); - static_cast(getController()).setModified(); + static_cast(getController()).setModified( sal_True ); Resize(); m_bInSplitHandler = sal_True; } diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 16fd0a9211ef..0b37832245ae 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -1371,7 +1371,7 @@ void OSelectionBrowseBox::RemoveColumn(USHORT _nColumnId) ActivateCell( nCurrentRow, nCurCol ); - rController.setModified(); + rController.setModified( sal_True ); invalidateUndoRedo(); } @@ -1658,7 +1658,7 @@ void OSelectionBrowseBox::InsertColumn(OTableFieldDescRef pEntry, USHORT& _nColu Invalidate( aInvalidRect ); ActivateCell( nCurrentRow, nCurCol ); - static_cast(getDesignView()->getController()).setModified(); + static_cast(getDesignView()->getController()).setModified( sal_True ); invalidateUndoRedo(); } @@ -2036,7 +2036,7 @@ void OSelectionBrowseBox::CellModified() } break; } - static_cast(getDesignView()->getController()).setModified(); + static_cast(getDesignView()->getController()).setModified( sal_True ); } //------------------------------------------------------------------------------ @@ -2141,12 +2141,12 @@ void OSelectionBrowseBox::Command(const CommandEvent& rEvt) break; case ID_QUERY_DISTINCT: static_cast(getDesignView()->getController()).setDistinct(!static_cast(getDesignView()->getController()).isDistinct()); - static_cast(getDesignView()->getController()).setModified(); + static_cast(getDesignView()->getController()).setModified( sal_True ); static_cast(getDesignView()->getController()).InvalidateFeature( SID_QUERY_DISTINCT_VALUES ); break; } - static_cast(getDesignView()->getController()).setModified(); + static_cast(getDesignView()->getController()).setModified( sal_True ); } } else @@ -2479,7 +2479,7 @@ void OSelectionBrowseBox::SetCellContents(sal_Int32 nRow, USHORT nColId, const S if (bWasEditing) ActivateCell(nCellIndex, nColId); - static_cast(getDesignView()->getController()).setModified(); + static_cast(getDesignView()->getController()).setModified( sal_True ); } //------------------------------------------------------------------------------ sal_uInt32 OSelectionBrowseBox::GetTotalCellWidth(long nRow, sal_uInt16 nColId) const @@ -2507,7 +2507,7 @@ void OSelectionBrowseBox::ColumnResized(sal_uInt16 nColId) DBG_ASSERT(nPos <= getFields().size(),"ColumnResized:: nColId sollte nicht groesser als List::count sein!"); OTableFieldDescRef pEntry = getEntry(nPos-1); DBG_ASSERT(pEntry.isValid(), "OSelectionBrowseBox::ColumnResized : keine FieldDescription !"); - static_cast(getDesignView()->getController()).setModified(); + static_cast(getDesignView()->getController()).setModified( sal_True ); EditBrowseBox::ColumnResized(nColId); if ( pEntry.isValid()) diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx index 79adb58af366..e907a9edff2a 100644 --- a/dbaccess/source/ui/querydesign/querycontroller.cxx +++ b/dbaccess/source/ui/querydesign/querycontroller.cxx @@ -448,7 +448,7 @@ FeatureState OQueryController::GetState(sal_uInt16 _nId) const aReturn.bEnabled = !editingCommand() && !editingView() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty())); break; case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = isModified() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty())); + aReturn.bEnabled = impl_isModified() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty())); break; case SID_PRINTDOCDIRECT: break; @@ -1046,9 +1046,9 @@ void OQueryController::describeSupportedFeatures() #endif } // ----------------------------------------------------------------------------- -void OQueryController::setModified(sal_Bool _bModified) +void OQueryController::impl_onModifyChanged() { - OJoinController::setModified(_bModified); + OJoinController::impl_onModifyChanged(); InvalidateFeature(SID_BROWSER_CLEAR_QUERY); InvalidateFeature(ID_BROWSER_SAVEASDOC); InvalidateFeature(ID_BROWSER_QUERY_EXECUTE); @@ -1097,8 +1097,10 @@ void OQueryController::reconnect(sal_Bool _bUI) } } // ----------------------------------------------------------------------------- -void OQueryController::saveViewSettings(Sequence& _rViewProps) +void OQueryController::saveViewSettings( Sequence< PropertyValue >& o_rViewData ) { + saveTableWindows( o_rViewData ); + OTableFields::const_iterator aFieldIter = m_vTableFieldDesc.begin(); OTableFields::const_iterator aFieldEnd = m_vTableFieldDesc.end(); sal_Int32 nCount = 0; @@ -1108,15 +1110,9 @@ void OQueryController::saveViewSettings(Sequence& _rViewProps) ++nCount; } - sal_Int32 nLen = _rViewProps.getLength(); - - _rViewProps.realloc( nLen + 2 + (nCount != 0 ? 1 : 0) ); - PropertyValue *pIter = _rViewProps.getArray() + nLen; - + ::comphelper::NamedValueCollection aViewData( o_rViewData ); if ( nCount != 0 ) { - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fields")); - Sequence aFields(nCount); PropertyValue *pFieldsIter = aFields.getArray(); // the fielddata @@ -1129,36 +1125,21 @@ void OQueryController::saveViewSettings(Sequence& _rViewProps) (*aFieldIter)->Save(*pFieldsIter++); } } - pIter->Value <<= aFields; - ++pIter; + + aViewData.put( "Fields", aFields ); } - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SplitterPosition")); - pIter->Value <<= m_nSplitPos; - ++pIter; - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VisibleRows")); - pIter->Value <<= m_nVisibleRows; + aViewData.put( "SplitterPosition", m_nSplitPos ); + aViewData.put( "VisibleRows", m_nVisibleRows ); + o_rViewData = aViewData.getPropertyValues(); } // ----------------------------------------------------------------------------- -void OQueryController::loadViewSettings(const Sequence& _rViewProps) +void OQueryController::loadViewSettings( const Sequence< PropertyValue >& i_rViewData ) { - const PropertyValue *pIter = _rViewProps.getConstArray(); - const PropertyValue *pEnd = pIter + _rViewProps.getLength(); - for (; pIter != pEnd; ++pIter) - { - if ( pIter->Name.equalsAscii("SplitterPosition") ) - { - pIter->Value >>= m_nSplitPos; - } - else if ( pIter->Name.equalsAscii("VisibleRows") ) - { - pIter->Value >>= m_nVisibleRows; - } - else if ( pIter->Name.equalsAscii("Fields") ) - { - pIter->Value >>= m_aFieldInformation; - } - } + const ::comphelper::NamedValueCollection aViewData( i_rViewData ); + m_nSplitPos = aViewData.getOrDefault( "SplitterPosition", m_nSplitPos ); + m_nVisibleRows = aViewData.getOrDefault( "VisibleRows", m_nVisibleRows ); + m_aFieldInformation = aViewData.getOrDefault( "Fields", m_aFieldInformation ); } // ----------------------------------------------------------------------------- sal_Int32 OQueryController::getColWidth(sal_uInt16 _nColPos) const @@ -1438,12 +1419,7 @@ bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs) xQuery->setPropertyValue( PROPERTY_UPDATE_TABLENAME, makeAny( m_sUpdateTableName ) ); xQuery->setPropertyValue( PROPERTY_ESCAPE_PROCESSING,::cppu::bool2any( m_bEscapeProcessing ) ); - // layout information - getContainer()->SaveUIConfig(); - Sequence< PropertyValue > aLayout; - saveTableWindows( aLayout ); - saveViewSettings( aLayout ); - xQuery->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aLayout ) ); + xQuery->setPropertyValue( PROPERTY_LAYOUTINFORMATION, getViewData() ); } } @@ -1776,6 +1752,22 @@ bool OQueryController::allowQueries() const } // ----------------------------------------------------------------------------- +Any SAL_CALL OQueryController::getViewData() throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( getMutex() ); + + getContainer()->SaveUIConfig(); + + Sequence< PropertyValue > aLayout; + saveViewSettings( aLayout ); + return makeAny( aLayout ); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OQueryController::restoreViewData(const Any& /*Data*/) throw( RuntimeException ) +{ + // TODO +} + // ----------------------------------------------------------------------------- } // namespace dbaui // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/relationdesign/RelationController.cxx b/dbaccess/source/ui/relationdesign/RelationController.cxx index 96a426a06bd8..3f259d867844 100644 --- a/dbaccess/source/ui/relationdesign/RelationController.cxx +++ b/dbaccess/source/ui/relationdesign/RelationController.cxx @@ -160,7 +160,7 @@ FeatureState ORelationController::GetState(sal_uInt16 _nId) const aReturn.bChecked = false; break; case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = haveDataSource() && isModified(); + aReturn.bEnabled = haveDataSource() && impl_isModified(); break; default: aReturn = OJoinController::GetState(_nId); diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index 4296082b1c7b..7bce4d10ec70 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -227,7 +227,7 @@ FeatureState OTableController::GetState(sal_uInt16 _nId) const aReturn.bEnabled = m_bNew || isEditable();// the editable flag is set through this one -> || isAddAllowed() || isDropAllowed() || isAlterAllowed(); break; case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = isModified(); + aReturn.bEnabled = impl_isModified(); if ( aReturn.bEnabled ) { ::std::vector< ::boost::shared_ptr >::const_iterator aIter = ::std::find_if(m_vRowList.begin(),m_vRowList.end(), @@ -256,7 +256,7 @@ FeatureState OTableController::GetState(sal_uInt16 _nId) const break; case SID_INDEXDESIGN: aReturn.bEnabled = - ( ( ((!m_bNew && isModified()) || isModified()) + ( ( ((!m_bNew && impl_isModified()) || impl_isModified()) || Reference< XIndexesSupplier >(m_xTable, UNO_QUERY).is() ) && isConnected() @@ -671,10 +671,10 @@ SfxUndoManager* OTableController::getUndoMgr() return &m_aUndoManager; } // ----------------------------------------------------------------------------- -void OTableController::setModified(sal_Bool _bModified) +void OTableController::impl_onModifyChanged() { - OSingleDocumentController::setModified(_bModified); - InvalidateFeature(SID_INDEXDESIGN); + OSingleDocumentController::impl_onModifyChanged(); + InvalidateFeature( SID_INDEXDESIGN ); } // ----------------------------------------------------------------------------- void SAL_CALL OTableController::disposing( const EventObject& _rSource ) throw(RuntimeException) -- cgit From 009ab0e80350627a53b6f69a8d4f85ab26af8de4 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 15 Feb 2010 14:34:48 +0100 Subject: autorecovery: when saving recovery information for a DB doc, export query designers, too --- dbaccess/source/core/recovery/dbdocrecovery.cxx | 244 +++++++++++++++++---- dbaccess/source/core/recovery/makefile.mk | 5 +- dbaccess/source/core/recovery/storagestream.cxx | 93 ++++++++ dbaccess/source/core/recovery/storagestream.hxx | 79 +++++++ .../source/core/recovery/storagetextstream.cxx | 130 +++++++++++ .../source/core/recovery/storagetextstream.hxx | 66 ++++++ dbaccess/source/core/recovery/storagexmlstream.cxx | 155 +++++++++++++ dbaccess/source/core/recovery/storagexmlstream.hxx | 85 +++++++ dbaccess/source/inc/stringconstants.hrc | 1 + dbaccess/source/ui/inc/JoinController.hxx | 7 +- dbaccess/source/ui/inc/TableFieldDescription.hxx | 7 +- dbaccess/source/ui/inc/querycontroller.hxx | 23 +- dbaccess/source/ui/querydesign/JoinController.cxx | 61 ++---- .../ui/querydesign/TableFieldDescription.cxx | 47 ++-- dbaccess/source/ui/querydesign/querycontroller.cxx | 131 ++++++++--- .../ui/relationdesign/RelationController.cxx | 9 +- dbaccess/util/makefile.mk | 3 +- 17 files changed, 989 insertions(+), 157 deletions(-) create mode 100644 dbaccess/source/core/recovery/storagestream.cxx create mode 100644 dbaccess/source/core/recovery/storagestream.hxx create mode 100644 dbaccess/source/core/recovery/storagetextstream.cxx create mode 100644 dbaccess/source/core/recovery/storagetextstream.hxx create mode 100644 dbaccess/source/core/recovery/storagexmlstream.cxx create mode 100644 dbaccess/source/core/recovery/storagexmlstream.hxx (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx index 7e102dd84eb4..296f3ba901d5 100644 --- a/dbaccess/source/core/recovery/dbdocrecovery.cxx +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -27,6 +27,8 @@ #include "recovery/dbdocrecovery.hxx" #include "sdbcoretools.hxx" +#include "storagexmlstream.hxx" +#include "storagetextstream.hxx" #include "subcomponentloader.hxx" #include "dbastrings.hrc" @@ -45,6 +47,7 @@ #include #include #include +#include /** === end UNO includes === **/ #include @@ -52,6 +55,8 @@ #include #include #include +#include +#include #include #include @@ -82,7 +87,6 @@ namespace dbaccess using ::com::sun::star::beans::PropertyValue; using ::com::sun::star::beans::Pair; using ::com::sun::star::io::XStream; - using ::com::sun::star::io::XOutputStream; using ::com::sun::star::io::XTextOutputStream; using ::com::sun::star::io::XActiveDataSource; using ::com::sun::star::io::XTextInputStream; @@ -93,6 +97,8 @@ namespace dbaccess using ::com::sun::star::sdb::XReportDocumentsSupplier; using ::com::sun::star::ucb::XCommandProcessor; using ::com::sun::star::container::XHierarchicalNameAccess; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::lang::XMultiServiceFactory; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; @@ -191,6 +197,32 @@ namespace dbaccess static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); return s_sRecDataStorName; } + // ......................................................................... + static const ::rtl::OUString& lcl_getComponentStorageBaseName( const SubComponentType i_eType ) + { + static const ::rtl::OUString s_sFormBaseName( RTL_CONSTASCII_USTRINGPARAM( "form" ) ); + static const ::rtl::OUString s_sReportBaseName( RTL_CONSTASCII_USTRINGPARAM( "report" ) ); + static const ::rtl::OUString s_sTableBaseName( RTL_CONSTASCII_USTRINGPARAM( "table" ) ); + static const ::rtl::OUString s_sQueryBaseName( RTL_CONSTASCII_USTRINGPARAM( "query" ) ); + + switch ( i_eType ) + { + case FORM: + return s_sFormBaseName; + case REPORT: + return s_sReportBaseName; + case TABLE: + return s_sTableBaseName; + case QUERY: + return s_sQueryBaseName; + default: + break; + } + + OSL_ENSURE( false, "lcl_getComponentStorageBaseName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } // ......................................................................... static const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) @@ -229,6 +261,27 @@ namespace dbaccess return s_sObjectMapStreamName; } + // ......................................................................... + static const ::rtl::OUString& lcl_getStatementStreamName() + { + static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "statement.txt" ) ); + return s_sStatementStreamName; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getSettingsStreamName() + { + static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "settings.xml" ) ); + return s_sStatementStreamName; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getCurrentQueryDesignName() + { + static const ::rtl::OUString s_sQuerySettingsName( RTL_CONSTASCII_USTRINGPARAM( "ooo:current-query-design" ) ); + return s_sQuerySettingsName; + } + // ......................................................................... static const ::rtl::OUString& lcl_getMapStreamEncodingName() { @@ -244,19 +297,9 @@ namespace dbaccess // nothing to do return; - ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); - Reference< XStream > xIniStream( i_rStorage->openStreamElement( - lcl_getObjectMapStreamName(), ElementModes::WRITE | ElementModes::TRUNCATE ), UNO_SET_THROW ); + StorageTextOutputStream aTextOutput( i_rContext, i_rStorage, lcl_getObjectMapStreamName() ); - Reference< XTextOutputStream > xTextOutput( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); - xTextOutput->setEncoding( lcl_getMapStreamEncodingName() ); - - Reference< XActiveDataSource > xDataSource( xTextOutput, UNO_QUERY_THROW ); - xDataSource->setOutputStream( xIniStream->getOutputStream() ); - - const ::rtl::OUString sLineFeed( sal_Unicode( '\n' ) ); - xTextOutput->writeString( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); - xTextOutput->writeString( sLineFeed ); + aTextOutput.writeLine( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); for ( MapStringToCompDesc::const_iterator stor = i_mapStorageToCompDesc.begin(); stor != i_mapStorageToCompDesc.end(); @@ -265,12 +308,11 @@ namespace dbaccess { ::rtl::OUStringBuffer aLine; lcl_getPersistentRepresentation( *stor, aLine ); - aLine.append( sLineFeed ); - xTextOutput->writeString( aLine.makeStringAndClear() ); + aTextOutput.writeLine( aLine.makeStringAndClear() ); } - xTextOutput->writeString( sLineFeed ); + aTextOutput.writeLine(); } // ......................................................................... @@ -411,7 +453,7 @@ namespace dbaccess //==================================================================== //= DatabaseDocumentRecovery_Data //==================================================================== - struct DatabaseDocumentRecovery_Data + struct DBACCESS_DLLPRIVATE DatabaseDocumentRecovery_Data { const ::comphelper::ComponentContext aContext; @@ -421,10 +463,89 @@ namespace dbaccess } }; + //==================================================================== + //= SettingsExportContext + //==================================================================== + class DBACCESS_DLLPRIVATE SettingsExportContext : public ::xmloff::XMLSettingsExportContext + { + public: + SettingsExportContext( const ::comphelper::ComponentContext& i_rContext, const StorageXMLOutputStream& i_rDelegator ) + :m_rContext( i_rContext ) + ,m_rDelegator( i_rDelegator ) + ,m_aNamespace( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_NP_CONFIG ) ) + { + } + + public: + virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ); + virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ); + virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ); + virtual void EndElement ( const sal_Bool i_bIgnoreWhitespace ); + virtual void Characters( const ::rtl::OUString& i_rCharacters ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + GetServiceFactory() const; + + private: + ::rtl::OUString impl_prefix( const ::xmloff::token::XMLTokenEnum i_eToken ) + { + ::rtl::OUStringBuffer aQualifiedName( m_aNamespace ); + aQualifiedName.append( sal_Unicode( ':' ) ); + aQualifiedName.append( ::xmloff::token::GetXMLToken( i_eToken ) ); + return aQualifiedName.makeStringAndClear(); + } + + private: + const ::comphelper::ComponentContext& m_rContext; + const StorageXMLOutputStream& m_rDelegator; + const ::rtl::OUStringBuffer m_aNamespace; + }; + + //-------------------------------------------------------------------- + void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ) + { + m_rDelegator.addAttribute( impl_prefix( i_eName ), i_rValue ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ) + { + m_rDelegator.addAttribute( impl_prefix( i_eName ), ::xmloff::token::GetXMLToken( i_eValue ) ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ) + { + if ( i_bIgnoreWhitespace ) + m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + + m_rDelegator.startElement( impl_prefix( i_eName ) ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::EndElement( const sal_Bool i_bIgnoreWhitespace ) + { + if ( i_bIgnoreWhitespace ) + m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + m_rDelegator.endElement(); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::Characters( const ::rtl::OUString& i_rCharacters ) + { + m_rDelegator.characters( i_rCharacters ); + } + + //-------------------------------------------------------------------- + Reference< XMultiServiceFactory > SettingsExportContext::GetServiceFactory() const + { + return m_rContext.getLegacyServiceFactory(); + } + //==================================================================== //= SubComponentRecovery //==================================================================== - class SubComponentRecovery + class DBACCESS_DLLPRIVATE SubComponentRecovery { public: SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XDatabaseDocumentUI >& i_rController, @@ -441,8 +562,11 @@ namespace dbaccess private: void impl_saveSubDocument_throw( - const Reference< XStorage >& i_rRecoveryStorage, - MapStringToCompDesc& io_mapStorageToCompDesc + const Reference< XStorage >& i_rObjectStorage + ); + + void impl_saveQueryDesign_throw( + const Reference< XStorage >& i_rObjectStorage ); void impl_identifyComponent_throw( @@ -465,11 +589,26 @@ namespace dbaccess // quite fatal, but has already been reported (as assertion) before return; + // open the sub storage for the given kind of components + const ::rtl::OUString& rStorageName( lcl_getComponentsStorageName( m_eType ) ); + const Reference< XStorage > xComponentsStorage( i_rRecoveryStorage->openStorageElement( + rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // find a free sub storage name, and create Yet Another Sub Storage + const ::rtl::OUString& rBaseName( lcl_getComponentStorageBaseName( m_eType ) ); + const ::rtl::OUString sStorName = ::dbtools::createUniqueName( xComponentsStorage.get(), rBaseName, true ); + const Reference< XStorage > xObjectStor( xComponentsStorage->openStorageElement( + sStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + switch ( m_eType ) { case FORM: case REPORT: - impl_saveSubDocument_throw( i_rRecoveryStorage, io_mapCompDescs[ m_eType ] ); + impl_saveSubDocument_throw( xObjectStor ); + break; + + case QUERY: + impl_saveQueryDesign_throw( xObjectStor ); break; default: @@ -477,6 +616,16 @@ namespace dbaccess OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); break; } + + // commit the storage(s) + tools::stor::commitStorageIfWriteable( xObjectStor ); + tools::stor::commitStorageIfWriteable( xComponentsStorage ); + + // remember the relationship from the component name to the storage name + MapStringToCompDesc& rMapCompDescs = io_mapCompDescs[ m_eType ]; + OSL_ENSURE( rMapCompDescs.find( sStorName ) == rMapCompDescs.end(), + "SubComponentRecoverys::saveToRecoveryStorage: object name already used!" ); + rMapCompDescs[ sStorName ] = m_aCompDesc; } //-------------------------------------------------------------------- @@ -534,34 +683,43 @@ namespace dbaccess } //-------------------------------------------------------------------- - void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage, - MapStringToCompDesc& io_mapStorageToCompDesc ) + void SubComponentRecovery::impl_saveQueryDesign_throw( const Reference< XStorage >& i_rObjectStorage ) { - ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); - ENSURE_OR_THROW( i_rRecoveryStorage.is(), "illegal storage" ); + ENSURE_OR_THROW( m_eType == QUERY, "illegal sub component type" ); + ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); - // open the sub storage for the given kind of documents - const ::rtl::OUString& rStorageName( lcl_getComponentsStorageName( m_eType ) ); - const Reference< XStorage > xDocsStor( i_rRecoveryStorage->openStorageElement( - rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + // retrieve the current query design (which might differ from what we can retrieve as ActiveCommand property, since + // the latter is updated only upon successful save of the design) + Reference< XPropertySet > xDesignerProps( m_xComponent, UNO_QUERY_THROW ); + Sequence< PropertyValue > aCurrentQueryDesign; + OSL_VERIFY( xDesignerProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ) ) >>= aCurrentQueryDesign ); - // find a free sub storage name, and create Yet Another Sub Storage - const ::rtl::OUString sBaseName( ::rtl::OUString::createFromAscii( m_eType == FORM ? "form" : "report" ) ); - const ::rtl::OUString sCompStorName = ::dbtools::createUniqueName( xDocsStor.get(), sBaseName, true ); - const Reference< XStorage > xCompStor( xDocsStor->openStorageElement( - sCompStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + // write the query design + StorageXMLOutputStream aDesignOutput( m_rContext, i_rObjectStorage, lcl_getSettingsStreamName() ); + SettingsExportContext aSettingsExportContext( m_rContext, aDesignOutput ); - // store the document into the storage - Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); - xStorageDocument->storeToStorage( xCompStor, Sequence< PropertyValue >() ); + const ::rtl::OUString sWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + + aDesignOutput.startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "office:settings" ) ) ); + aDesignOutput.ignorableWhitespace( sWhitespace ); + + XMLSettingsExportHelper aSettingsExporter( aSettingsExportContext ); + aSettingsExporter.exportAllSettings( aCurrentQueryDesign, lcl_getCurrentQueryDesignName() ); + + aDesignOutput.ignorableWhitespace( sWhitespace ); + aDesignOutput.endElement(); + aDesignOutput.close(); + } - // remember the relationship between the component name to the storage name - OSL_ENSURE( io_mapStorageToCompDesc.find( sCompStorName ) == io_mapStorageToCompDesc.end(), - "SubComponentRecoverys::impl_saveSubDocument_throw: object name already used!" ); - io_mapStorageToCompDesc[ sCompStorName ] = m_aCompDesc; + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rObjectStorage ) + { + ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); + ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); - // commit the storage for the documents collection - tools::stor::commitStorageIfWriteable( xDocsStor ); + // store the document into the storage + Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); + xStorageDocument->storeToStorage( i_rObjectStorage, Sequence< PropertyValue >() ); } //==================================================================== diff --git a/dbaccess/source/core/recovery/makefile.mk b/dbaccess/source/core/recovery/makefile.mk index 2a69495c4044..04f6e44e8e34 100644 --- a/dbaccess/source/core/recovery/makefile.mk +++ b/dbaccess/source/core/recovery/makefile.mk @@ -45,7 +45,10 @@ ENABLE_EXCEPTIONS=TRUE SLOFILES= \ $(SLO)$/dbdocrecovery.obj \ - $(SLO)$/subcomponentloader.obj + $(SLO)$/subcomponentloader.obj \ + $(SLO)$/storagestream.obj \ + $(SLO)$/storagexmlstream.obj \ + $(SLO)$/storagetextstream.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/recovery/storagestream.cxx b/dbaccess/source/core/recovery/storagestream.cxx new file mode 100644 index 000000000000..e8fb99600854 --- /dev/null +++ b/dbaccess/source/core/recovery/storagestream.cxx @@ -0,0 +1,93 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "storagestream.hxx" + +/** === begin UNO includes === **/ +#include +/** === end UNO includes === **/ + +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::io::XStream; + /** === end UNO using === **/ + namespace ElementModes = ::com::sun::star::embed::ElementModes; + + //==================================================================== + //= StorageOutputStream + //==================================================================== + //-------------------------------------------------------------------- + StorageOutputStream::StorageOutputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ) + :m_rContext( i_rContext ) + { + ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" ); + + const Reference< XStream > xStream( + i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + m_xOutputStream.set( xStream->getOutputStream(), UNO_SET_THROW ); + } + + //-------------------------------------------------------------------- + StorageOutputStream::~StorageOutputStream() + { + } + + //-------------------------------------------------------------------- + void StorageOutputStream::close() + { + ENSURE_OR_RETURN_VOID( m_xOutputStream.is(), "already closed" ); + m_xOutputStream->closeOutput(); + m_xOutputStream.clear(); + + // if you add additional functionality here, be aware that there are derived classes which + // (legitimately) do not call this method here. + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/storagestream.hxx b/dbaccess/source/core/recovery/storagestream.hxx new file mode 100644 index 000000000000..a214d3d84d7d --- /dev/null +++ b/dbaccess/source/core/recovery/storagestream.hxx @@ -0,0 +1,79 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef STORAGESTREAM_HXX +#define STORAGESTREAM_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include +/** === end UNO includes === **/ + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= StorageOutputStream + //==================================================================== + /** convenience wrapper around a stream living in a storage + */ + class DBACCESS_DLLPRIVATE StorageOutputStream + { + public: + StorageOutputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + virtual ~StorageOutputStream(); + + /** simply calls closeOutput on our output stream, override to extend/modify this behavior + */ + virtual void close(); + + protected: + const ::comphelper::ComponentContext& getContext() const { return m_rContext; } + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& + getOutputStream() const { return m_xOutputStream; } + + private: + const ::comphelper::ComponentContext& m_rContext; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > + m_xOutputStream; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // STORAGESTREAM_HXX diff --git a/dbaccess/source/core/recovery/storagetextstream.cxx b/dbaccess/source/core/recovery/storagetextstream.cxx new file mode 100644 index 000000000000..af1b832b67b3 --- /dev/null +++ b/dbaccess/source/core/recovery/storagetextstream.cxx @@ -0,0 +1,130 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "storagetextstream.hxx" + +/** === begin UNO includes === **/ +#include +#include +/** === end UNO includes === **/ + +#include +#include + +//...................................................................................................................... +namespace dbaccess +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::io::XTextOutputStream; + using ::com::sun::star::io::XActiveDataSource; + /** === end UNO using === **/ + + //================================================================================================================== + //= StorageTextOutputStream_Data + //================================================================================================================== + struct StorageTextOutputStream_Data + { + Reference< XTextOutputStream > xTextOutput; + }; + + //================================================================================================================== + //= helper + //================================================================================================================== + namespace + { + //-------------------------------------------------------------------------------------------------------------- + static const ::rtl::OUString& lcl_getTextStreamEncodingName() + { + static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); + return s_sMapStreamEncodingName; + } + + //-------------------------------------------------------------------------------------------------------------- + static const ::rtl::OUString& lcl_getLineFeed() + { + static const ::rtl::OUString s_sLineFeed( sal_Unicode( '\n' ) ); + return s_sLineFeed; + } + } + + //================================================================================================================== + //= StorageTextOutputStream + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + StorageTextOutputStream::StorageTextOutputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ) + :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName ) + ,m_pData( new StorageTextOutputStream_Data ) + { + m_pData->xTextOutput.set( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); + m_pData->xTextOutput->setEncoding( lcl_getTextStreamEncodingName() ); + + Reference< XActiveDataSource > xDataSource( m_pData->xTextOutput, UNO_QUERY_THROW ); + xDataSource->setOutputStream( getOutputStream() ); + } + + //------------------------------------------------------------------------------------------------------------------ + StorageTextOutputStream::~StorageTextOutputStream() + { + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageTextOutputStream::writeLine( const ::rtl::OUString& i_rLine ) + { + ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" ); + + m_pData->xTextOutput->writeString( i_rLine ); + m_pData->xTextOutput->writeString( lcl_getLineFeed() ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageTextOutputStream::writeLine() + { + ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" ); + + m_pData->xTextOutput->writeString( lcl_getLineFeed() ); + } + +//...................................................................................................................... +} // namespace dbaccess +//...................................................................................................................... diff --git a/dbaccess/source/core/recovery/storagetextstream.hxx b/dbaccess/source/core/recovery/storagetextstream.hxx new file mode 100644 index 000000000000..08d02008f1a4 --- /dev/null +++ b/dbaccess/source/core/recovery/storagetextstream.hxx @@ -0,0 +1,66 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef STORAGETEXTSTREAM_HXX +#define STORAGETEXTSTREAM_HXX + +#include "storagestream.hxx" + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#include + +//...................................................................................................................... +namespace dbaccess +{ +//...................................................................................................................... + + //================================================================================================================== + //= StorageTextStream + //================================================================================================================== + struct StorageTextOutputStream_Data; + class DBACCESS_DLLPRIVATE StorageTextOutputStream : public StorageOutputStream + { + public: + StorageTextOutputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + ~StorageTextOutputStream(); + + void writeLine( const ::rtl::OUString& i_rLine ); + void writeLine(); + + private: + ::std::auto_ptr< StorageTextOutputStream_Data > m_pData; + }; + +//...................................................................................................................... +} // namespace dbaccess +//...................................................................................................................... + +#endif // STORAGETEXTSTREAM_HXX diff --git a/dbaccess/source/core/recovery/storagexmlstream.cxx b/dbaccess/source/core/recovery/storagexmlstream.cxx new file mode 100644 index 000000000000..10c64cc4141c --- /dev/null +++ b/dbaccess/source/core/recovery/storagexmlstream.cxx @@ -0,0 +1,155 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "storagexmlstream.hxx" + +/** === begin UNO includes === **/ +#include +#include +/** === end UNO includes === **/ + +#include +#include +#include +#include + +#include + +//...................................................................................................................... +namespace dbaccess +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::xml::sax::XDocumentHandler; + using ::com::sun::star::xml::sax::XAttributeList; + using ::com::sun::star::io::XStream; + using ::com::sun::star::io::XOutputStream; + using ::com::sun::star::io::XActiveDataSource; + /** === end UNO using === **/ + + //================================================================================================================== + //= StorageXMLOutputStream_Data + //================================================================================================================== + struct StorageXMLOutputStream_Data + { + Reference< XDocumentHandler > xHandler; + ::std::stack< ::rtl::OUString > aElements; + ::rtl::Reference< SvXMLAttributeList > xAttributes; + }; + + //================================================================================================================== + //= StorageXMLOutputStream + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + StorageXMLOutputStream::StorageXMLOutputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName ) + :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName ) + ,m_pData( new StorageXMLOutputStream_Data ) + { + const Reference< XActiveDataSource > xSaxWriter( i_rContext.createComponent( "com.sun.star.xml.sax.Writer" ), UNO_QUERY_THROW ); + xSaxWriter->setOutputStream( getOutputStream() ); + + m_pData->xHandler.set( xSaxWriter, UNO_QUERY_THROW ); + m_pData->xHandler->startDocument(); + + m_pData->xAttributes = new SvXMLAttributeList; + } + + //------------------------------------------------------------------------------------------------------------------ + StorageXMLOutputStream::~StorageXMLOutputStream() + { + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::close() + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "illegal document handler" ); + m_pData->xHandler->endDocument(); + // do not call the base class, it would call closeOutput on the output stream, which is already done by + // endDocument + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::addAttribute( const ::rtl::OUString& i_rName, const ::rtl::OUString& i_rValue ) const + { + m_pData->xAttributes->AddAttribute( i_rName, i_rValue ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::startElement( const ::rtl::OUString& i_rElementName ) const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + + m_pData->xHandler->startElement( i_rElementName, m_pData->xAttributes.get() ); + m_pData->xAttributes = new SvXMLAttributeList; + m_pData->aElements.push( i_rElementName ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::endElement() const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + ENSURE_OR_RETURN_VOID( !m_pData->aElements.empty(), "no element on the stack" ); + + const ::rtl::OUString sElementName( m_pData->aElements.top() ); + m_pData->xHandler->endElement( sElementName ); + m_pData->aElements.pop(); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::ignorableWhitespace( const ::rtl::OUString& i_rWhitespace ) const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + + m_pData->xHandler->ignorableWhitespace( i_rWhitespace ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::characters( const ::rtl::OUString& i_rCharacters ) const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + + m_pData->xHandler->characters( i_rCharacters ); + } + +//...................................................................................................................... +} // namespace dbaccess +//...................................................................................................................... diff --git a/dbaccess/source/core/recovery/storagexmlstream.hxx b/dbaccess/source/core/recovery/storagexmlstream.hxx new file mode 100644 index 000000000000..504e6b7ccd25 --- /dev/null +++ b/dbaccess/source/core/recovery/storagexmlstream.hxx @@ -0,0 +1,85 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef STORAGEXMLSTREAM_HXX +#define STORAGEXMLSTREAM_HXX + +#include "storagestream.hxx" + +/** === begin UNO includes === **/ +#include +/** === end UNO includes === **/ + +#include + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= StorageXMLOutputStream + //==================================================================== + struct StorageXMLOutputStream_Data; + class DBACCESS_DLLPRIVATE StorageXMLOutputStream : public StorageOutputStream + { + public: + StorageXMLOutputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + ~StorageXMLOutputStream(); + + // StorageOutputStream overridables + virtual void close(); + + void addAttribute( const ::rtl::OUString& i_rName, const ::rtl::OUString& i_rValue ) const; + + void startElement( const ::rtl::OUString& i_rElementName ) const; + void endElement() const; + + void ignorableWhitespace( const ::rtl::OUString& i_rWhitespace ) const; + void characters( const ::rtl::OUString& i_rCharacters ) const; + + private: + StorageXMLOutputStream(); // never implemented + StorageXMLOutputStream( const StorageXMLOutputStream& ); // never implemented + StorageXMLOutputStream& operator=( const StorageXMLOutputStream& ); // never implemented + + private: + ::std::auto_ptr< StorageXMLOutputStream_Data > m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // STORAGEXMLSTREAM_HXX diff --git a/dbaccess/source/inc/stringconstants.hrc b/dbaccess/source/inc/stringconstants.hrc index 384d669226dc..57c4227154cf 100644 --- a/dbaccess/source/inc/stringconstants.hrc +++ b/dbaccess/source/inc/stringconstants.hrc @@ -184,6 +184,7 @@ #define PROPERTY_ID_ENCODING 141 #define PROPERTY_ID_HELP_URL 142 #define PROPERTY_ID_PERSISTENT_PATH 143 +#define PROPERTY_ID_CURRENT_QUERY_DESIGN 144 //============================================================ //= property names diff --git a/dbaccess/source/ui/inc/JoinController.hxx b/dbaccess/source/ui/inc/JoinController.hxx index 88fc32ee8c07..72e61c4bab3d 100644 --- a/dbaccess/source/ui/inc/JoinController.hxx +++ b/dbaccess/source/ui/inc/JoinController.hxx @@ -52,6 +52,11 @@ #endif #include +namespace comphelper +{ + class NamedValueCollection; +} + class VCLXWindow; namespace dbaui { @@ -97,7 +102,7 @@ namespace dbaui @param _rViewProps Contains the new sequence. */ - void saveTableWindows(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps); + void saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const; virtual ~OJoinController(); public: diff --git a/dbaccess/source/ui/inc/TableFieldDescription.hxx b/dbaccess/source/ui/inc/TableFieldDescription.hxx index 9230bef621c3..dd4489821331 100644 --- a/dbaccess/source/ui/inc/TableFieldDescription.hxx +++ b/dbaccess/source/ui/inc/TableFieldDescription.hxx @@ -47,6 +47,11 @@ #include #endif +namespace comphelper +{ + class NamedValueCollection; +} + class Window; namespace dbaui { @@ -142,7 +147,7 @@ namespace dbaui const ::std::vector< ::rtl::OUString>& GetCriteria() const { return m_vecCriteria;} void Load(const ::com::sun::star::beans::PropertyValue& _rProperty); - void Save(::com::sun::star::beans::PropertyValue& _rProperty); + void Save( ::comphelper::NamedValueCollection& o_rSettings ); }; //------------------------------------------------------------------ diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx index 5a1d2b24b82b..eeabaa13192b 100644 --- a/dbaccess/source/ui/inc/querycontroller.hxx +++ b/dbaccess/source/ui/inc/querycontroller.hxx @@ -56,6 +56,11 @@ #include #include +namespace comphelper +{ + class NamedValueCollection; +} + class VCLXWindow; namespace dbaui { @@ -125,7 +130,7 @@ namespace dbaui void executeQuery(); bool doSaveAsDoc(sal_Bool _bSaveAs); - void saveViewSettings( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& o_rViewData ); + void saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includngCriteria ) const; void loadViewSettings( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rViewData ); ::rtl::OUString translateStatement( bool _bFireStatementChange = true ); @@ -204,6 +209,22 @@ namespace dbaui // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + // OPropertySetHelper + virtual sal_Bool SAL_CALL convertFastPropertyValue( + ::com::sun::star::uno::Any& rConvertedValue, + ::com::sun::star::uno::Any& rOldValue, + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) throw (::com::sun::star::lang::IllegalArgumentException); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) throw (::com::sun::star::uno::Exception ); + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, + sal_Int32 nHandle + ) const; + virtual OJoinDesignView* getJoinView(); // ask the user if the design should be saved when it is modified virtual short saveModified(); diff --git a/dbaccess/source/ui/querydesign/JoinController.cxx b/dbaccess/source/ui/querydesign/JoinController.cxx index 0c5367165530..7191bf6252b6 100644 --- a/dbaccess/source/ui/querydesign/JoinController.cxx +++ b/dbaccess/source/ui/querydesign/JoinController.cxx @@ -536,56 +536,31 @@ void OJoinController::loadTableWindow(const Sequence& _rTable) } } // ----------------------------------------------------------------------------- -void OJoinController::saveTableWindows(Sequence& _rViewProps) +void OJoinController::saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const { if ( !m_vTableData.empty() ) { - PropertyValue *pViewIter = _rViewProps.getArray(); - PropertyValue *pEnd = pViewIter + _rViewProps.getLength(); - const static ::rtl::OUString s_sTables(RTL_CONSTASCII_USTRINGPARAM("Tables")); - for (; pViewIter != pEnd && pViewIter->Name != s_sTables; ++pViewIter) - ; + ::comphelper::NamedValueCollection aAllTablesData; - if ( pViewIter == pEnd ) + TTableWindowData::const_iterator aIter = m_vTableData.begin(); + TTableWindowData::const_iterator aEnd = m_vTableData.end(); + for ( sal_Int32 i = 1; aIter != aEnd; ++aIter, ++i ) { - sal_Int32 nLen = _rViewProps.getLength(); - _rViewProps.realloc( nLen + 1 ); - pViewIter = _rViewProps.getArray() + nLen; - pViewIter->Name = s_sTables; + ::comphelper::NamedValueCollection aWindowData; + aWindowData.put( "ComposedName", (*aIter)->GetComposedName() ); + aWindowData.put( "TableName", (*aIter)->GetTableName() ); + aWindowData.put( "WindowName", (*aIter)->GetWinName() ); + aWindowData.put( "WindowTop", (*aIter)->GetPosition().Y() ); + aWindowData.put( "WindowLeft", (*aIter)->GetPosition().X() ); + aWindowData.put( "WindowWidth", (*aIter)->GetSize().Width() ); + aWindowData.put( "WindowHeight", (*aIter)->GetSize().Height() ); + aWindowData.put( "ShowAll", (*aIter)->IsShowAll() ); + + const ::rtl::OUString sTableName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Table" ) ) + ::rtl::OUString::valueOf( i ) ); + aAllTablesData.put( sTableName, aWindowData.getPropertyValues() ); } - Sequence aTables(m_vTableData.size()); - PropertyValue *pIter = aTables.getArray(); - - Sequence aWindow(8); - - TTableWindowData::iterator aIter = m_vTableData.begin(); - TTableWindowData::iterator aEnd = m_vTableData.end(); - for(sal_Int32 i = 1;aIter != aEnd;++aIter,++pIter,++i) - { - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Table")) + ::rtl::OUString::valueOf(i); - - sal_Int32 nPos = 0; - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ComposedName")); - aWindow[nPos++].Value <<= (*aIter)->GetComposedName(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TableName")); - aWindow[nPos++].Value <<= (*aIter)->GetTableName(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowName")); - aWindow[nPos++].Value <<= (*aIter)->GetWinName(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowTop")); - aWindow[nPos++].Value <<= (*aIter)->GetPosition().Y(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowLeft")); - aWindow[nPos++].Value <<= (*aIter)->GetPosition().X(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowWidth")); - aWindow[nPos++].Value <<= (*aIter)->GetSize().Width(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowHeight")); - aWindow[nPos++].Value <<= (*aIter)->GetSize().Height(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowAll")); - aWindow[nPos++].Value <<= (*aIter)->IsShowAll(); - - pIter->Value <<= aWindow; - } - pViewIter->Value <<= aTables; + o_rViewSettings.put( "Tables", aAllTablesData.getPropertyValues() ); } } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx index a00bc3dbd54c..4b053661df1b 100644 --- a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx +++ b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx @@ -40,9 +40,7 @@ #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ #include #endif -#ifndef _COMPHELPER_STREAMSECTION_HXX_ -#include -#endif +#include using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; @@ -207,39 +205,22 @@ void OTableFieldDesc::Load(const ::com::sun::star::beans::PropertyValue& _rPrope } } //------------------------------------------------------------------------------ -void OTableFieldDesc::Save(::com::sun::star::beans::PropertyValue& _rProperty) +void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings ) { DBG_CHKTHIS(OTableFieldDesc,NULL); - - Sequence aFieldDesc(13); - sal_Int32 nPos = 0; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AliasName")); - aFieldDesc[nPos++].Value <<= m_aAliasName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TableName")); - aFieldDesc[nPos++].Value <<= m_aTableName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldName")); - aFieldDesc[nPos++].Value <<= m_aFieldName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldAlias")); - aFieldDesc[nPos++].Value <<= m_aFieldAlias; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FunctionName")); - aFieldDesc[nPos++].Value <<= m_aFunctionName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataType")); - aFieldDesc[nPos++].Value <<= m_eDataType; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FunctionType")); - aFieldDesc[nPos++].Value <<= (sal_Int32)m_eFunctionType; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldType")); - aFieldDesc[nPos++].Value <<= (sal_Int32)m_eFieldType; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OrderDir")); - aFieldDesc[nPos++].Value <<= (sal_Int32)m_eOrderDir; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColWidth")); - aFieldDesc[nPos++].Value <<= m_nColWidth; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GroupBy")); - aFieldDesc[nPos++].Value <<= m_bGroupBy; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Visible")); - aFieldDesc[nPos++].Value <<= m_bVisible; - - _rProperty.Value <<= aFieldDesc; + o_rSettings.put( "AliasName", m_aAliasName ); + o_rSettings.put( "TableName", m_aTableName ); + o_rSettings.put( "FieldName", m_aFieldName ); + o_rSettings.put( "FieldAlias", m_aFieldAlias ); + o_rSettings.put( "FunctionName", m_aFunctionName ); + o_rSettings.put( "DataType", m_eDataType ); + o_rSettings.put( "FunctionType", (sal_Int32)m_eFunctionType ); + o_rSettings.put( "FieldType", (sal_Int32)m_eFieldType ); + o_rSettings.put( "OrderDir", (sal_Int32)m_eOrderDir ); + o_rSettings.put( "ColWidth", m_nColWidth ); + o_rSettings.put( "GroupBy", m_bGroupBy ); + o_rSettings.put( "Visible", m_bVisible ); } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx index e907a9edff2a..aab0703b364c 100644 --- a/dbaccess/source/ui/querydesign/querycontroller.cxx +++ b/dbaccess/source/ui/querydesign/querycontroller.cxx @@ -81,6 +81,7 @@ #include #include +#include #include #include #include @@ -373,6 +374,49 @@ Reference< XPropertySetInfo > SAL_CALL OQueryController::getPropertySetInfo() th return xInfo; } +//------------------------------------------------------------------------- +sal_Bool SAL_CALL OQueryController::convertFastPropertyValue( Any& o_rConvertedValue, Any& o_rOldValue, sal_Int32 i_nHandle, const Any& i_rValue ) throw (IllegalArgumentException) +{ + return OPropertyContainer::convertFastPropertyValue( o_rConvertedValue, o_rOldValue, i_nHandle, i_rValue ); +} + +//------------------------------------------------------------------------- +void SAL_CALL OQueryController::setFastPropertyValue_NoBroadcast( sal_Int32 i_nHandle, const Any& i_rValue ) throw ( Exception ) +{ + OPropertyContainer::setFastPropertyValue_NoBroadcast( i_nHandle, i_rValue ); +} + +//------------------------------------------------------------------------- +void SAL_CALL OQueryController::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const +{ + switch ( i_nHandle ) + { + case PROPERTY_ID_CURRENT_QUERY_DESIGN: + { + ::comphelper::NamedValueCollection aCurrentDesign; + aCurrentDesign.put( "GraphicalDesign", isGraphicalDesign() ); + aCurrentDesign.put( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, m_bEscapeProcessing ); + + if ( isGraphicalDesign() ) + { + getContainer()->SaveUIConfig(); + saveViewSettings( aCurrentDesign, true ); + } + else + { + aCurrentDesign.put( "Statement", getContainer()->getStatement() ); + } + + o_rValue <<= aCurrentDesign.getPropertyValues(); + } + break; + + default: + OPropertyContainer::getFastPropertyValue( o_rValue, i_nHandle ); + break; + } +} + //------------------------------------------------------------------------- ::cppu::IPropertyArrayHelper& OQueryController::getInfoHelper() { @@ -383,7 +427,24 @@ Reference< XPropertySetInfo > SAL_CALL OQueryController::getPropertySetInfo() th ::cppu::IPropertyArrayHelper* OQueryController::createArrayHelper( ) const { Sequence< Property > aProps; - describeProperties(aProps); + describeProperties( aProps ); + + // one additional property: + const sal_Int32 nLength = aProps.getLength(); + aProps.realloc( nLength + 1 ); + aProps[ nLength ] = Property( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ), + PROPERTY_ID_CURRENT_QUERY_DESIGN, + ::cppu::UnoType< Sequence< PropertyValue > >::get(), + PropertyAttribute::READONLY + ); + + ::std::sort( + aProps.getArray(), + aProps.getArray() + aProps.getLength(), + ::comphelper::PropertyCompareByName() + ); + return new ::cppu::OPropertyArrayHelper(aProps); } @@ -1096,42 +1157,53 @@ void OQueryController::reconnect(sal_Bool _bUI) InvalidateAll(); } } + // ----------------------------------------------------------------------------- -void OQueryController::saveViewSettings( Sequence< PropertyValue >& o_rViewData ) +void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includngCriteria ) const { - saveTableWindows( o_rViewData ); + saveTableWindows( o_rViewSettings ); - OTableFields::const_iterator aFieldIter = m_vTableFieldDesc.begin(); - OTableFields::const_iterator aFieldEnd = m_vTableFieldDesc.end(); - sal_Int32 nCount = 0; - for(;aFieldIter != aFieldEnd;++aFieldIter) - { - if(!(*aFieldIter)->IsEmpty()) - ++nCount; - } + OTableFields::const_iterator field = m_vTableFieldDesc.begin(); + OTableFields::const_iterator fieldEnd = m_vTableFieldDesc.end(); - ::comphelper::NamedValueCollection aViewData( o_rViewData ); - if ( nCount != 0 ) + ::comphelper::NamedValueCollection aAllFieldsData; + ::comphelper::NamedValueCollection aFieldData; + for ( sal_Int32 i = 1; field != fieldEnd; ++field, ++i ) { - Sequence aFields(nCount); - PropertyValue *pFieldsIter = aFields.getArray(); - // the fielddata - aFieldIter = m_vTableFieldDesc.begin(); - for(sal_Int32 i = 1;aFieldIter !=aFieldEnd;++aFieldIter,++i) + if ( !(*field)->IsEmpty() ) { - if ( !(*aFieldIter)->IsEmpty() ) + const ::rtl::OUString sFieldSettingName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Field" ) ) + ::rtl::OUString::valueOf( i ); + + aFieldData.clear(); + (*field)->Save( aFieldData ); + + if ( i_includngCriteria ) { - pFieldsIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Field")) + ::rtl::OUString::valueOf(i); - (*aFieldIter)->Save(*pFieldsIter++); + const ::std::vector< ::rtl::OUString >& rCriteria( (*field)->GetCriteria() ); + if ( !rCriteria.empty() ) + { + sal_Int32 c = 0; + ::comphelper::NamedValueCollection aCriteria; + for ( ::std::vector< ::rtl::OUString >::const_iterator crit = rCriteria.begin(); + crit != rCriteria.end(); + ++crit, ++c + ) + { + const ::rtl::OUString sCritName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c ); + aCriteria.put( sCritName, *crit ); + } + + aFieldData.put( "Criteria", aCriteria.getPropertyValues() ); + } } - } - aViewData.put( "Fields", aFields ); + aAllFieldsData.put( sFieldSettingName, aFieldData.getPropertyValues() ); + } } - aViewData.put( "SplitterPosition", m_nSplitPos ); - aViewData.put( "VisibleRows", m_nVisibleRows ); - o_rViewData = aViewData.getPropertyValues(); + o_rViewSettings.put( "Fields", aAllFieldsData.getPropertyValues() ); + o_rViewSettings.put( "SplitterPosition", m_nSplitPos ); + o_rViewSettings.put( "VisibleRows", m_nVisibleRows ); } // ----------------------------------------------------------------------------- void OQueryController::loadViewSettings( const Sequence< PropertyValue >& i_rViewData ) @@ -1758,9 +1830,10 @@ Any SAL_CALL OQueryController::getViewData() throw( RuntimeException ) getContainer()->SaveUIConfig(); - Sequence< PropertyValue > aLayout; - saveViewSettings( aLayout ); - return makeAny( aLayout ); + ::comphelper::NamedValueCollection aViewSettings; + saveViewSettings( aViewSettings, false ); + + return makeAny( aViewSettings.getPropertyValues() ); } // ----------------------------------------------------------------------------- void SAL_CALL OQueryController::restoreViewData(const Any& /*Data*/) throw( RuntimeException ) diff --git a/dbaccess/source/ui/relationdesign/RelationController.cxx b/dbaccess/source/ui/relationdesign/RelationController.cxx index 3f259d867844..d59ef63642e0 100644 --- a/dbaccess/source/ui/relationdesign/RelationController.cxx +++ b/dbaccess/source/ui/relationdesign/RelationController.cxx @@ -189,14 +189,15 @@ void ORelationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue { if ( haveDataSource() && getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) ) { - Sequence aWindows; - saveTableWindows(aWindows); - getDataSource()->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aWindows)); + ::comphelper::NamedValueCollection aWindowsData; + saveTableWindows( aWindowsData ); + getDataSource()->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aWindowsData.getPropertyValues() ) ); setModified(sal_False); } } - catch(Exception&) + catch ( const Exception& ) { + DBG_UNHANDLED_EXCEPTION(); } } } diff --git a/dbaccess/util/makefile.mk b/dbaccess/util/makefile.mk index 622d6355b65d..1426a0178f60 100644 --- a/dbaccess/util/makefile.mk +++ b/dbaccess/util/makefile.mk @@ -72,7 +72,8 @@ SHL1STDLIBS= \ $(SFXLIB) \ $(BASICLIB) \ $(FWELIB) \ - $(SALHELPERLIB) + $(SALHELPERLIB) \ + $(XMLOFFLIB) SHL1DEPN= SHL1IMPLIB=i$(TARGET) -- cgit From 2cf0840f4cc0e8240bc771e1a83edf9631b7d742 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 15 Feb 2010 16:05:58 +0100 Subject: autorecovery: clarified the role of a doc's URL/Location as per agreement with MAV, XModel::getURL and XStorable::getLocation both need to return the logical document URL, even when the document has been recoved from another location. So, the DocFileLocation of the ModelImpl now is for internal purpose only. Consequently, ModelImpl's API has been reworked to better differ between the logical and the "loaded-from" URL of the document. --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 88 ++++++++++++---------- dbaccess/source/core/dataaccess/ModelImpl.hxx | 29 ++++--- .../source/core/dataaccess/databasedocument.cxx | 36 +++++---- .../source/core/dataaccess/databasedocument.hxx | 6 +- dbaccess/source/ui/browser/dataview.cxx | 2 +- 5 files changed, 88 insertions(+), 73 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 26bb425c82d8..1f0d9f337a0b 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -811,37 +811,37 @@ const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormats } return m_xNumberFormatsSupplier; } + // ----------------------------------------------------------------------------- -void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArgs ) +void ODatabaseModelImpl::setDocFileLocation( const ::rtl::OUString& i_rLoadedFrom ) { - ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs ); - ENSURE_OR_THROW( _rURL.getLength(), "invalid URL" ); + ENSURE_OR_THROW( i_rLoadedFrom.getLength(), "invalid URL" ); + m_sDocFileLocation = i_rLoadedFrom; +} - ::rtl::OUString sDocumentLocation( _rURL ); - ::rtl::OUString sDocumentURL( _rURL ); +// ----------------------------------------------------------------------------- +void ODatabaseModelImpl::setResource( const ::rtl::OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs ) +{ + ENSURE_OR_THROW( i_rDocumentURL.getLength(), "invalid URL" ); +#if OSL_DEBUG_LEVEL > 0 + ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs ); if ( aMediaDescriptor.has( "SalvagedFile" ) ) { - const ::rtl::OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) ); - // If SalvagedFile is an empty string, this indicates "the document is being recovered, but _rURL already + ::rtl::OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) ); + // If SalvagedFile is an empty string, this indicates "the document is being recovered, but i_rDocumentURL already // is the real document URL, not the temporary document location" - if ( sSalvagedFile.getLength() ) - { - // otherwise, SalvagedFile is the URL of the document which we should mimic, though we're loaded from - // the file denoted by _rURL. - sDocumentLocation = _rURL; - sDocumentURL = sSalvagedFile; - } - - if ( sSalvagedFile == _rURL ) - // SalvagedFile doesn't carry any information anymore - aMediaDescriptor.remove( "SalvagedFile" ); + if ( !sSalvagedFile.getLength() ) + sSalvagedFile = i_rDocumentURL; + OSL_ENSURE( sSalvagedFile == i_rDocumentURL, "ODatabaseModelImpl::setResource: inconsistency!" ); + // nowadays, setResource should only be called with the logical URL of the document } +#endif m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor ); - switchToURL( sDocumentLocation, sDocumentURL ); + impl_switchToLogicalURL( i_rDocumentURL ); } // ----------------------------------------------------------------------------- @@ -1045,7 +1045,7 @@ Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _b // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper // state, fires all events, and so on. // #i105505# / 2009-10-02 / frank.schoenheit@sun.com - xModel->attachResource( ::rtl::OUString(), m_aMediaDescriptor.getPropertyValues() ); + xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() ); } if ( _bInitialize ) @@ -1340,31 +1340,34 @@ Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Refe } // ----------------------------------------------------------------------------- -void ODatabaseModelImpl::switchToURL( const ::rtl::OUString& _rDocumentLocation, const ::rtl::OUString& _rDocumentURL ) +void ODatabaseModelImpl::impl_switchToLogicalURL( const ::rtl::OUString& i_rDocumentURL ) { - // register at the database context, or change registration - const bool bURLChanged = ( _rDocumentURL != m_sDocumentURL ); + if ( i_rDocumentURL == m_sDocumentURL ) + return; + const ::rtl::OUString sOldURL( m_sDocumentURL ); - if ( bURLChanged ) + // update our name, if necessary + if ( ( m_sName == m_sDocumentURL ) // our name is our old URL + || ( !m_sName.getLength() ) // we do not have a name, yet (i.e. are not registered at the database context) + ) { - if ( ( m_sName == m_sDocumentURL ) // our name is our old URL - || ( !m_sName.getLength() ) // we do not have a name, yet (i.e. are not registered at the database context) - ) + INetURLObject aURL( i_rDocumentURL ); + if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) { - INetURLObject aURL( _rDocumentURL ); - if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) - { - m_sName = _rDocumentURL; - // TODO: our data source must broadcast the change of the Name property - } + m_sName = i_rDocumentURL; + // TODO: our data source must broadcast the change of the Name property } } - // remember both - m_sDocFileLocation = _rDocumentLocation.getLength() ? _rDocumentLocation : _rDocumentURL; - m_sDocumentURL = _rDocumentURL; + // remember URL + m_sDocumentURL = i_rDocumentURL; - if ( bURLChanged && m_pDBContext ) + // update our location, if necessary + if ( m_sDocFileLocation.getLength() == 0 ) + m_sDocFileLocation = m_sDocumentURL; + + // register at the database context, or change registration + if ( m_pDBContext ) { if ( sOldURL.getLength() ) m_pDBContext->databaseDocumentURLChange( sOldURL, m_sDocumentURL ); @@ -1404,10 +1407,13 @@ sal_Bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode ) // ----------------------------------------------------------------------------- ::rtl::OUString ODatabaseModelImpl::getDocumentLocation() const { - // don't return getURL() (or m_sDocumentURL, which is the same). In case we were recovered - // after a previous crash of OOo, m_sDocFileLocation points to the file which were loaded from, - // and this is the one we need for security checks. - return getDocFileLocation(); + return getURL(); + // formerly, we returned getDocFileLocation here, which is the location of the file from which we + // recovered the "real" document. + // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and + // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL* + // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition, + // this folder is considered to be secure. So, the document URL needs to be used to decide about the security. } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx index 8fc7650a9e1a..d74f02506160 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.hxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx @@ -325,9 +325,13 @@ public: const ::comphelper::NamedValueCollection& getMediaDescriptor() const { return m_aMediaDescriptor; } - void attachResource( + void setResource( const ::rtl::OUString& _rURL, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs ); + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs + ); + void setDocFileLocation( + const ::rtl::OUString& i_rLoadedFrom + ); static ::comphelper::NamedValueCollection stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ); @@ -482,19 +486,6 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage ); - /** switches to the given document location/URL - - The document location is the URL of the file from which the document has been loaded. - The document URL is the "intended location" of the document. It differs from the location - if and only if the document was loaded as part of a document recovery process. In this case, - the location points to some temporary file, but the URL is the URL of the file which has been - just recovered. The next store operation would operate on the URL, not the location. - */ - void switchToURL( - const ::rtl::OUString& _rDocumentLocation, - const ::rtl::OUString& _rDocumentURL - ); - /** returns the macro mode imposed by an external instance, which passed it to attachResource */ sal_Int16 getImposedMacroExecMode() const @@ -530,6 +521,14 @@ private: void impl_construct_nothrow(); ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > impl_switchToStorage_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage ); + + /** switches to the given document URL, which denotes the logical URL of the document, not necessariy the + URL where the doc was loaded/recovered from + */ + void impl_switchToLogicalURL( + const ::rtl::OUString& i_rDocumentURL + ); + }; /** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index f779c0fee5e4..61b238d03b69 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -662,6 +662,10 @@ void SAL_CALL ODatabaseDocument::storeToRecoveryFile( const ::rtl::OUString& i_T void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) { DocumentGuard aGuard( *this, DocumentGuard::InitMethod ); + + if ( i_SourceLocation.getLength() == 0 ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + try { // load the document itself, by simply delegating to our "load" method @@ -678,9 +682,12 @@ void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_Sourc // So, everything else is done when the first controller is connected. m_bHasBeenRecovered = true; + // tell the impl that we've been loaded from the given location + m_pImpl->setDocFileLocation( i_SourceLocation ); + // by definition (of XDocumentRecovery), we're responsible for delivering a fully-initialized document, // which includes an attachResource call. - impl_attachResource( i_SourceLocation, aMediaDescriptor.getPropertyValues(), aGuard ); + impl_attachResource( i_SalvagedFile, aMediaDescriptor.getPropertyValues(), aGuard ); // <- SYNCHRONIZED } catch( const Exception& ) @@ -708,10 +715,10 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR } // ----------------------------------------------------------------------------- -sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rURL, const Sequence< PropertyValue >& i_rMediaDescriptor, - DocumentGuard& _rDocGuard ) +sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rLogicalDocumentURL, + const Sequence< PropertyValue >& i_rMediaDescriptor, DocumentGuard& _rDocGuard ) { - if ( ( i_rURL == getURL() ) + if ( ( i_rLogicalDocumentURL == getURL() ) && ( i_rMediaDescriptor.getLength() == 1 ) && ( i_rMediaDescriptor[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 ) ) @@ -722,14 +729,14 @@ sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rURL, // (we do not support macro signatures, so we can ignore this call) } - // if no URL has been provided, the caller was lazy enough to not call our getLocation/getURL - which is allowed ... - ::rtl::OUString sURL( i_rURL ); - if ( !sURL.getLength() ) - sURL = getLocation(); - if ( !sURL.getLength() ) - sURL = getURL(); + // if no URL has been provided, the caller was lazy enough to not call our getURL - which is not allowed anymore, + // now since getURL and getLocation both return the same, so calling one of those should be simple. + ::rtl::OUString sDocumentURL( i_rLogicalDocumentURL ); + OSL_ENSURE( sDocumentURL.getLength(), "ODatabaseDocument::impl_attachResource: invalid URL!" ); + if ( !sDocumentURL.getLength() ) + sDocumentURL = getURL(); - m_pImpl->attachResource( sURL, i_rMediaDescriptor ); + m_pImpl->setResource( sDocumentURL, i_rMediaDescriptor ); if ( impl_isInitializing() ) { // this means we've just been loaded, and this is the attachResource call which follows @@ -918,7 +925,9 @@ sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException) ::rtl::OUString SAL_CALL ODatabaseDocument::getLocation( ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); - return m_pImpl->getDocFileLocation(); + return m_pImpl->getURL(); + // both XStorable::getLocation and XModel::getURL have to return the URL of the document, *not* + // the location of the file which the docunment was possibly recovered from (which would be getDocFileLocation) } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException) @@ -1040,7 +1049,8 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const impl_storeToStorage_throw( xCurrentStorage, aMediaDescriptor, _rGuard ); // success - tell our impl - m_pImpl->attachResource( _rURL, aMediaDescriptor ); + m_pImpl->setDocFileLocation( _rURL ); + m_pImpl->setResource( _rURL, aMediaDescriptor ); // if we are in an initialization process, then this is finished, now that we stored the document if ( bIsInitializationProcess ) diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 8110b9ceee02..51eeefbbbc75 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -613,8 +613,8 @@ private: /** impl-version of attachResource - @param i_rURL - denotes the URL the document was loaded from + @param i_rLogicalDocumentURL + denotes the logical URL of the document, to be reported by getURL/getLocation @param i_rMediaDescriptor denotes additional document parameters @param _rDocGuard @@ -622,7 +622,7 @@ private: */ sal_Bool impl_attachResource( - const ::rtl::OUString& i_rURL, + const ::rtl::OUString& i_rLogicalDocumentURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rMediaDescriptor, DocumentGuard& _rDocGuard ); diff --git a/dbaccess/source/ui/browser/dataview.cxx b/dbaccess/source/ui/browser/dataview.cxx index efeb65adf442..a66f6ec6d11a 100644 --- a/dbaccess/source/ui/browser/dataview.cxx +++ b/dbaccess/source/ui/browser/dataview.cxx @@ -236,7 +236,7 @@ namespace dbaui { ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); aArgs.remove( "Hidden" ); - xModel->attachResource( ::rtl::OUString(), aArgs.getPropertyValues() ); + xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() ); } } catch( const Exception& ) -- cgit From a1c40ed088aeabc90c260d9b8bc7e0db24d1b146 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 08:55:52 +0100 Subject: autorecovery: fixed member initialization order --- dbaccess/source/ui/misc/singledoccontroller.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/misc/singledoccontroller.cxx b/dbaccess/source/ui/misc/singledoccontroller.cxx index 1ff0a7953989..de2acf1d571d 100644 --- a/dbaccess/source/ui/misc/singledoccontroller.cxx +++ b/dbaccess/source/ui/misc/singledoccontroller.cxx @@ -162,8 +162,8 @@ namespace dbaui bool m_bNotAttached; OSingleDocumentControllerImpl( ::osl::Mutex& i_rMutex ) - :m_aModifyListeners( i_rMutex ) - ,m_aDocScriptSupport() + :m_aDocScriptSupport() + ,m_aModifyListeners( i_rMutex ) ,m_nDocStartNumber(0) ,m_bSuspended( sal_False ) ,m_bEditable(sal_True) -- cgit From eb79829c17871ccbad0daf469dfd7bd9c85eb8cc Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 09:43:10 +0100 Subject: autorecovery: outsourced the SubComponentRecovery class into a dedicated file, in preparation of recovering query designs --- dbaccess/source/core/recovery/dbdocrecovery.cxx | 515 +------------------- dbaccess/source/core/recovery/makefile.mk | 3 +- .../source/core/recovery/subcomponentrecovery.cxx | 523 +++++++++++++++++++++ .../source/core/recovery/subcomponentrecovery.hxx | 119 +++++ dbaccess/source/core/recovery/subcomponents.hxx | 88 ++++ 5 files changed, 754 insertions(+), 494 deletions(-) create mode 100644 dbaccess/source/core/recovery/subcomponentrecovery.cxx create mode 100644 dbaccess/source/core/recovery/subcomponentrecovery.hxx create mode 100644 dbaccess/source/core/recovery/subcomponents.hxx (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx index 296f3ba901d5..76a67794ee53 100644 --- a/dbaccess/source/core/recovery/dbdocrecovery.cxx +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -27,38 +27,28 @@ #include "recovery/dbdocrecovery.hxx" #include "sdbcoretools.hxx" -#include "storagexmlstream.hxx" #include "storagetextstream.hxx" -#include "subcomponentloader.hxx" +#include "subcomponentrecovery.hxx" +#include "subcomponents.hxx" #include "dbastrings.hrc" /** === begin UNO includes === **/ #include -#include #include #include #include #include #include #include -#include #include -#include -#include -#include -#include #include /** === end UNO includes === **/ #include #include -#include -#include +#include #include -#include -#include -#include #include //........................................................................ @@ -81,11 +71,9 @@ namespace dbaccess using ::com::sun::star::embed::XStorage; using ::com::sun::star::frame::XController; using ::com::sun::star::sdb::application::XDatabaseDocumentUI; - using ::com::sun::star::frame::XModuleManager; using ::com::sun::star::lang::XComponent; using ::com::sun::star::document::XStorageBasedDocument; using ::com::sun::star::beans::PropertyValue; - using ::com::sun::star::beans::Pair; using ::com::sun::star::io::XStream; using ::com::sun::star::io::XTextOutputStream; using ::com::sun::star::io::XActiveDataSource; @@ -93,57 +81,17 @@ namespace dbaccess using ::com::sun::star::io::XActiveDataSink; using ::com::sun::star::frame::XModel; using ::com::sun::star::util::XModifiable; - using ::com::sun::star::sdb::XFormDocumentsSupplier; - using ::com::sun::star::sdb::XReportDocumentsSupplier; - using ::com::sun::star::ucb::XCommandProcessor; - using ::com::sun::star::container::XHierarchicalNameAccess; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::lang::XMultiServiceFactory; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; - namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; //==================================================================== //= helpers //==================================================================== namespace { - // ......................................................................... - enum SubComponentType - { - TABLE = DatabaseObject::TABLE, - QUERY = DatabaseObject::QUERY, - FORM = DatabaseObject::FORM, - REPORT = DatabaseObject::REPORT, - - RELATION_DESIGN = 1000, - - UNKNOWN = 10001 - }; - - struct DBACCESS_DLLPRIVATE SubComponentDescriptor - { - ::rtl::OUString sName; - bool bForEditing; - - SubComponentDescriptor() - :sName() - ,bForEditing( false ) - { - } - - SubComponentDescriptor( const ::rtl::OUString& i_rName, const bool i_bForEditing ) - :sName( i_rName ) - ,bForEditing( i_bForEditing ) - { - } - }; - - // ......................................................................... - typedef ::std::hash_map< ::rtl::OUString, SubComponentDescriptor, ::rtl::OUStringHash > MapStringToCompDesc; - typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; - // ......................................................................... static void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) { @@ -176,84 +124,12 @@ namespace dbaccess return true; } - // ......................................................................... - static SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) - { - switch ( i_nObjectType ) - { - case DatabaseObject::TABLE: return TABLE; - case DatabaseObject::QUERY: return QUERY; - case DatabaseObject::FORM: return FORM; - case DatabaseObject::REPORT:return REPORT; - default: - break; - } - return UNKNOWN; - } - // ......................................................................... static const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() { static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); return s_sRecDataStorName; } - // ......................................................................... - static const ::rtl::OUString& lcl_getComponentStorageBaseName( const SubComponentType i_eType ) - { - static const ::rtl::OUString s_sFormBaseName( RTL_CONSTASCII_USTRINGPARAM( "form" ) ); - static const ::rtl::OUString s_sReportBaseName( RTL_CONSTASCII_USTRINGPARAM( "report" ) ); - static const ::rtl::OUString s_sTableBaseName( RTL_CONSTASCII_USTRINGPARAM( "table" ) ); - static const ::rtl::OUString s_sQueryBaseName( RTL_CONSTASCII_USTRINGPARAM( "query" ) ); - - switch ( i_eType ) - { - case FORM: - return s_sFormBaseName; - case REPORT: - return s_sReportBaseName; - case TABLE: - return s_sTableBaseName; - case QUERY: - return s_sQueryBaseName; - default: - break; - } - - OSL_ENSURE( false, "lcl_getComponentStorageBaseName: unimplemented case!" ); - static const ::rtl::OUString s_sFallback; - return s_sFallback; - } - - // ......................................................................... - static const ::rtl::OUString& lcl_getComponentsStorageName( const SubComponentType i_eType ) - { - static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); - static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); - static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) ); - static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) ); - static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) ); - - switch ( i_eType ) - { - case FORM: - return s_sFormsStorageName; - case REPORT: - return s_sReportsStorageName; - case TABLE: - return s_sTablesStorageName; - case QUERY: - return s_sQueriesStorageName; - case RELATION_DESIGN: - return s_sRelationsStorageName; - default: - break; - } - - OSL_ENSURE( false, "lcl_getComponentsStorageName: unimplemented case!" ); - static const ::rtl::OUString s_sFallback; - return s_sFallback; - } - // ......................................................................... static const ::rtl::OUString& lcl_getObjectMapStreamName() { @@ -268,20 +144,6 @@ namespace dbaccess return s_sStatementStreamName; } - // ......................................................................... - static const ::rtl::OUString& lcl_getSettingsStreamName() - { - static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "settings.xml" ) ); - return s_sStatementStreamName; - } - - // ......................................................................... - static const ::rtl::OUString& lcl_getCurrentQueryDesignName() - { - static const ::rtl::OUString s_sQuerySettingsName( RTL_CONSTASCII_USTRINGPARAM( "ooo:current-query-design" ) ); - return s_sQuerySettingsName; - } - // ......................................................................... static const ::rtl::OUString& lcl_getMapStreamEncodingName() { @@ -389,23 +251,6 @@ namespace dbaccess } } - // ......................................................................... - static bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) - { - Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); - if ( !xDocument.is() ) - { - Reference< XController > xController( i_rComponent, UNO_QUERY_THROW ); - xDocument = xController->getModel(); - } - - if ( !xDocument.is() ) - return false; - - ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() ); - return aDocArgs.getOrDefault( "ReadOnly", false ); - } - // ......................................................................... static void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) { @@ -418,36 +263,6 @@ namespace dbaccess xModify->setModified( sal_True ); } - - // ......................................................................... - static Reference< XCommandProcessor > lcl_getSubComponentDef_nothrow( const Reference< XController >& i_rAppUI, - SubComponentType i_eType, const ::rtl::OUString& i_rName ) - { - ENSURE_OR_RETURN( i_rAppUI.is(), "lcl_getSubComponentDef_nothrow: illegal controller", NULL ); - ENSURE_OR_RETURN( ( i_eType == FORM ) || ( i_eType == REPORT ), "lcl_getSubComponentDef_nothrow: illegal controller", NULL ); - - Reference< XCommandProcessor > xCommandProcessor; - try - { - Reference< XHierarchicalNameAccess > xDefinitionContainer; - if ( i_eType == FORM ) - { - Reference< XFormDocumentsSupplier > xSuppForms( i_rAppUI->getModel(), UNO_QUERY_THROW ); - xDefinitionContainer.set( xSuppForms->getFormDocuments(), UNO_QUERY_THROW ); - } - else - { - Reference< XReportDocumentsSupplier > xSuppReports( i_rAppUI->getModel(), UNO_QUERY_THROW ); - xDefinitionContainer.set( xSuppReports->getReportDocuments(), UNO_QUERY_THROW ); - } - xCommandProcessor.set( xDefinitionContainer->getByHierarchicalName( i_rName ), UNO_QUERY_THROW ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - return xCommandProcessor; - } } //==================================================================== @@ -463,265 +278,6 @@ namespace dbaccess } }; - //==================================================================== - //= SettingsExportContext - //==================================================================== - class DBACCESS_DLLPRIVATE SettingsExportContext : public ::xmloff::XMLSettingsExportContext - { - public: - SettingsExportContext( const ::comphelper::ComponentContext& i_rContext, const StorageXMLOutputStream& i_rDelegator ) - :m_rContext( i_rContext ) - ,m_rDelegator( i_rDelegator ) - ,m_aNamespace( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_NP_CONFIG ) ) - { - } - - public: - virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ); - virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ); - virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ); - virtual void EndElement ( const sal_Bool i_bIgnoreWhitespace ); - virtual void Characters( const ::rtl::OUString& i_rCharacters ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - GetServiceFactory() const; - - private: - ::rtl::OUString impl_prefix( const ::xmloff::token::XMLTokenEnum i_eToken ) - { - ::rtl::OUStringBuffer aQualifiedName( m_aNamespace ); - aQualifiedName.append( sal_Unicode( ':' ) ); - aQualifiedName.append( ::xmloff::token::GetXMLToken( i_eToken ) ); - return aQualifiedName.makeStringAndClear(); - } - - private: - const ::comphelper::ComponentContext& m_rContext; - const StorageXMLOutputStream& m_rDelegator; - const ::rtl::OUStringBuffer m_aNamespace; - }; - - //-------------------------------------------------------------------- - void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ) - { - m_rDelegator.addAttribute( impl_prefix( i_eName ), i_rValue ); - } - - //-------------------------------------------------------------------- - void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ) - { - m_rDelegator.addAttribute( impl_prefix( i_eName ), ::xmloff::token::GetXMLToken( i_eValue ) ); - } - - //-------------------------------------------------------------------- - void SettingsExportContext::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ) - { - if ( i_bIgnoreWhitespace ) - m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); - - m_rDelegator.startElement( impl_prefix( i_eName ) ); - } - - //-------------------------------------------------------------------- - void SettingsExportContext::EndElement( const sal_Bool i_bIgnoreWhitespace ) - { - if ( i_bIgnoreWhitespace ) - m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); - m_rDelegator.endElement(); - } - - //-------------------------------------------------------------------- - void SettingsExportContext::Characters( const ::rtl::OUString& i_rCharacters ) - { - m_rDelegator.characters( i_rCharacters ); - } - - //-------------------------------------------------------------------- - Reference< XMultiServiceFactory > SettingsExportContext::GetServiceFactory() const - { - return m_rContext.getLegacyServiceFactory(); - } - - //==================================================================== - //= SubComponentRecovery - //==================================================================== - class DBACCESS_DLLPRIVATE SubComponentRecovery - { - public: - SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const Reference< XDatabaseDocumentUI >& i_rController, - const Reference< XComponent >& i_rComponent ) - :m_rContext( i_rContext ) - ,m_xComponent( i_rComponent ) - ,m_eType( UNKNOWN ) - ,m_aCompDesc() - { - impl_identifyComponent_throw( i_rController ); - } - - void saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, MapCompTypeToCompDescs& io_mapCompDescs ); - - private: - void impl_saveSubDocument_throw( - const Reference< XStorage >& i_rObjectStorage - ); - - void impl_saveQueryDesign_throw( - const Reference< XStorage >& i_rObjectStorage - ); - - void impl_identifyComponent_throw( - const Reference< XDatabaseDocumentUI >& i_rController - ); - - private: - const ::comphelper::ComponentContext& m_rContext; - const Reference< XComponent > m_xComponent; - SubComponentType m_eType; - SubComponentDescriptor m_aCompDesc; - }; - - //-------------------------------------------------------------------- - void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, - MapCompTypeToCompDescs& io_mapCompDescs ) - { - - if ( m_eType == UNKNOWN ) - // quite fatal, but has already been reported (as assertion) before - return; - - // open the sub storage for the given kind of components - const ::rtl::OUString& rStorageName( lcl_getComponentsStorageName( m_eType ) ); - const Reference< XStorage > xComponentsStorage( i_rRecoveryStorage->openStorageElement( - rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); - - // find a free sub storage name, and create Yet Another Sub Storage - const ::rtl::OUString& rBaseName( lcl_getComponentStorageBaseName( m_eType ) ); - const ::rtl::OUString sStorName = ::dbtools::createUniqueName( xComponentsStorage.get(), rBaseName, true ); - const Reference< XStorage > xObjectStor( xComponentsStorage->openStorageElement( - sStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); - - switch ( m_eType ) - { - case FORM: - case REPORT: - impl_saveSubDocument_throw( xObjectStor ); - break; - - case QUERY: - impl_saveQueryDesign_throw( xObjectStor ); - break; - - default: - // TODO - OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); - break; - } - - // commit the storage(s) - tools::stor::commitStorageIfWriteable( xObjectStor ); - tools::stor::commitStorageIfWriteable( xComponentsStorage ); - - // remember the relationship from the component name to the storage name - MapStringToCompDesc& rMapCompDescs = io_mapCompDescs[ m_eType ]; - OSL_ENSURE( rMapCompDescs.find( sStorName ) == rMapCompDescs.end(), - "SubComponentRecoverys::saveToRecoveryStorage: object name already used!" ); - rMapCompDescs[ sStorName ] = m_aCompDesc; - } - - //-------------------------------------------------------------------- - void SubComponentRecovery::impl_identifyComponent_throw( const Reference< XDatabaseDocumentUI >& i_rController ) - { - ENSURE_OR_THROW( i_rController.is(), "illegal controller" ); - - // ask the controller - Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = i_rController->identifySubComponent( m_xComponent ); - m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First ); - m_aCompDesc.sName = aComponentIdentity.Second; - - // what the controller didn't give us is the information whether this is in edit mode or not ... - Reference< XModuleManager > xModuleManager( m_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); - const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent ); - - switch ( m_eType ) - { - case TABLE: - m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.TableDesign" ); - break; - - case QUERY: - m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.QueryDesign" ); - break; - - case REPORT: - if ( sModuleIdentifier.equalsAscii( "com.sun.star.report.ReportDefinition" ) ) - { - // it's an SRB report desginer - m_aCompDesc.bForEditing = true; - break; - } - // fall through - - case FORM: - m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent ); - break; - - default: - if ( sModuleIdentifier.equalsAscii( "com.sun.star.sdb.RelationDesign" ) ) - { - m_eType = RELATION_DESIGN; - m_aCompDesc.bForEditing = true; - } - else - { - OSL_ENSURE( false, "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" ); - } - break; - } - - OSL_POSTCOND( m_eType != UNKNOWN, - "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" ); - } - - //-------------------------------------------------------------------- - void SubComponentRecovery::impl_saveQueryDesign_throw( const Reference< XStorage >& i_rObjectStorage ) - { - ENSURE_OR_THROW( m_eType == QUERY, "illegal sub component type" ); - ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); - - // retrieve the current query design (which might differ from what we can retrieve as ActiveCommand property, since - // the latter is updated only upon successful save of the design) - Reference< XPropertySet > xDesignerProps( m_xComponent, UNO_QUERY_THROW ); - Sequence< PropertyValue > aCurrentQueryDesign; - OSL_VERIFY( xDesignerProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ) ) >>= aCurrentQueryDesign ); - - // write the query design - StorageXMLOutputStream aDesignOutput( m_rContext, i_rObjectStorage, lcl_getSettingsStreamName() ); - SettingsExportContext aSettingsExportContext( m_rContext, aDesignOutput ); - - const ::rtl::OUString sWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); - - aDesignOutput.startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "office:settings" ) ) ); - aDesignOutput.ignorableWhitespace( sWhitespace ); - - XMLSettingsExportHelper aSettingsExporter( aSettingsExportContext ); - aSettingsExporter.exportAllSettings( aCurrentQueryDesign, lcl_getCurrentQueryDesignName() ); - - aDesignOutput.ignorableWhitespace( sWhitespace ); - aDesignOutput.endElement(); - aDesignOutput.close(); - } - - //-------------------------------------------------------------------- - void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rObjectStorage ) - { - ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); - ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); - - // store the document into the storage - Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); - xStorageDocument->storeToStorage( i_rObjectStorage, Sequence< PropertyValue >() ); - } - //==================================================================== //= DatabaseDocumentRecovery //==================================================================== @@ -781,7 +337,7 @@ namespace dbaccess ) { Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( map->first ), ElementModes::WRITE | ElementModes::NOCREATE ) ); + SubComponentRecovery::getComponentsStorageName( map->first ), ElementModes::WRITE | ElementModes::NOCREATE ) ); lcl_writeObjectMap_throw( m_pData->aContext, xComponentsStor, map->second ); tools::stor::commitStorageIfWriteable( xComponentsStor ); } @@ -810,11 +366,11 @@ namespace dbaccess SubComponentType aKnownTypes[] = { TABLE, QUERY, FORM, REPORT, RELATION_DESIGN }; for ( size_t i = 0; i < sizeof( aKnownTypes ) / sizeof( aKnownTypes[0] ); ++i ) { - if ( !xRecoveryStorage->hasByName( lcl_getComponentsStorageName( aKnownTypes[i] ) ) ) + if ( !xRecoveryStorage->hasByName( SubComponentRecovery::getComponentsStorageName( aKnownTypes[i] ) ) ) continue; Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( aKnownTypes[i] ), ElementModes::READ ) ); + SubComponentRecovery::getComponentsStorageName( aKnownTypes[i] ), ElementModes::READ ) ); lcl_readObjectMap_throw( m_pData->aContext, xComponentsStor, aMapCompDescs[ aKnownTypes[i] ] ); xComponentsStor->dispose(); } @@ -835,7 +391,7 @@ namespace dbaccess // the storage for all components of the current type Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( - lcl_getComponentsStorageName( eComponentType ), ElementModes::READ ), UNO_QUERY_THROW ); + SubComponentRecovery::getComponentsStorageName( eComponentType ), ElementModes::READ ), UNO_QUERY_THROW ); // loop thru all components of this type for ( MapStringToCompDesc::const_iterator stor = map->second.begin(); @@ -851,7 +407,7 @@ namespace dbaccess message.append( "DatabaseDocumentRecovery::recoverSubDocuments: inconsistent recovery storage: storage '" ); message.append( ::rtl::OUStringToOString( stor->first, RTL_TEXTENCODING_ASCII_US ) ); message.append( "' not found in '" ); - message.append( ::rtl::OUStringToOString( lcl_getComponentsStorageName( eComponentType ), RTL_TEXTENCODING_ASCII_US ) ); + message.append( ::rtl::OUStringToOString( SubComponentRecovery::getComponentsStorageName( eComponentType ), RTL_TEXTENCODING_ASCII_US ) ); message.append( "', but required per map file!" ); OSL_ENSURE( false, message.makeStringAndClear() ); #endif @@ -864,47 +420,8 @@ namespace dbaccess // recover the single component Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); - ::comphelper::NamedValueCollection aLoadArgs; - aLoadArgs.put( "RecoveryStorage", xCompStor ); - - // load/create the sub component hidden. We'll show it when the main app window is shown. - aLoadArgs.put( "Hidden", true ); - - Reference< XComponent > xSubComponent; - Reference< XCommandProcessor > xDocDefinition; - - if ( sComponentName.getLength() ) - { - xDocDefinition = lcl_getSubComponentDef_nothrow( i_rTargetController, eComponentType, sComponentName ); - xSubComponent.set( xDocumentUI->loadComponentWithArguments( - eComponentType, - sComponentName, - stor->second.bForEditing, - aLoadArgs.getPropertyValues() - ), - UNO_SET_THROW - ); - } - else - { - Reference< XComponent > xDocDefComponent; - xSubComponent.set( xDocumentUI->createComponentWithArguments( - eComponentType, - aLoadArgs.getPropertyValues(), - xDocDefComponent - ), - UNO_SET_THROW - ); - - xDocDefinition.set( xDocDefComponent, UNO_QUERY ); - OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" ); - } - - if ( xDocDefinition.is() ) - { - Reference< XInterface > xLoader( *new SubComponentLoader( i_rTargetController, xDocDefinition ) ); - (void)xLoader; - } + SubComponentRecovery aComponentRecovery( m_pData->aContext, xDocumentUI, eComponentType ); + Reference< XComponent > xSubComponent( aComponentRecovery.recoverFromStorage( xCompStor, sComponentName, stor->second.bForEditing ) ); // at the moment, we only store, during session save, sub components which are modified. So, set this // recovered sub component to "modified", too. @@ -913,6 +430,18 @@ namespace dbaccess xComponentsStor->dispose(); } + + xRecoveryStorage->dispose(); + + // now that we successfully recovered, removed the "recovery" sub storage + try + { + i_rDocumentStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } //........................................................................ diff --git a/dbaccess/source/core/recovery/makefile.mk b/dbaccess/source/core/recovery/makefile.mk index 04f6e44e8e34..8679a23dcfec 100644 --- a/dbaccess/source/core/recovery/makefile.mk +++ b/dbaccess/source/core/recovery/makefile.mk @@ -48,7 +48,8 @@ SLOFILES= \ $(SLO)$/subcomponentloader.obj \ $(SLO)$/storagestream.obj \ $(SLO)$/storagexmlstream.obj \ - $(SLO)$/storagetextstream.obj + $(SLO)$/storagetextstream.obj \ + $(SLO)$/subcomponentrecovery.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.cxx b/dbaccess/source/core/recovery/subcomponentrecovery.cxx new file mode 100644 index 000000000000..2331b70d42cc --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentrecovery.cxx @@ -0,0 +1,523 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "subcomponentrecovery.hxx" + +#include "sdbcoretools.hxx" +#include "storagexmlstream.hxx" +#include "subcomponentloader.hxx" + +/** === begin UNO includes === **/ +#include +#include +#include +#include +#include +#include +#include +/** === end UNO includes === **/ + +#include +#include +#include +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::lang::XMultiServiceFactory; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::sdb::application::XDatabaseDocumentUI; + using ::com::sun::star::beans::Pair; + using ::com::sun::star::frame::XModuleManager; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::frame::XController; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::beans::PropertyValue; + using ::com::sun::star::document::XStorageBasedDocument; + using ::com::sun::star::ucb::XCommandProcessor; + using ::com::sun::star::container::XHierarchicalNameAccess; + using ::com::sun::star::sdb::XFormDocumentsSupplier; + using ::com::sun::star::sdb::XReportDocumentsSupplier; + /** === end UNO using === **/ + + namespace ElementModes = ::com::sun::star::embed::ElementModes; + + + //==================================================================== + //= helper + //==================================================================== + namespace + { + // ......................................................................... + static const ::rtl::OUString& lcl_getComponentStorageBaseName( const SubComponentType i_eType ) + { + static const ::rtl::OUString s_sFormBaseName( RTL_CONSTASCII_USTRINGPARAM( "form" ) ); + static const ::rtl::OUString s_sReportBaseName( RTL_CONSTASCII_USTRINGPARAM( "report" ) ); + static const ::rtl::OUString s_sTableBaseName( RTL_CONSTASCII_USTRINGPARAM( "table" ) ); + static const ::rtl::OUString s_sQueryBaseName( RTL_CONSTASCII_USTRINGPARAM( "query" ) ); + + switch ( i_eType ) + { + case FORM: + return s_sFormBaseName; + case REPORT: + return s_sReportBaseName; + case TABLE: + return s_sTableBaseName; + case QUERY: + return s_sQueryBaseName; + default: + break; + } + + OSL_ENSURE( false, "lcl_getComponentStorageBaseName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } + + // ......................................................................... + static SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) + { + switch ( i_nObjectType ) + { + case DatabaseObject::TABLE: return TABLE; + case DatabaseObject::QUERY: return QUERY; + case DatabaseObject::FORM: return FORM; + case DatabaseObject::REPORT:return REPORT; + default: + break; + } + return UNKNOWN; + } + + // ......................................................................... + static bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) + { + Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); + if ( !xDocument.is() ) + { + Reference< XController > xController( i_rComponent, UNO_QUERY_THROW ); + xDocument = xController->getModel(); + } + + if ( !xDocument.is() ) + return false; + + ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() ); + return aDocArgs.getOrDefault( "ReadOnly", false ); + } + + // ......................................................................... + static Reference< XCommandProcessor > lcl_getSubComponentDef_nothrow( const Reference< XDatabaseDocumentUI >& i_rAppUI, + const SubComponentType i_eType, const ::rtl::OUString& i_rName ) + { + Reference< XController > xController( i_rAppUI, UNO_QUERY_THROW ); + ENSURE_OR_RETURN( ( i_eType == FORM ) || ( i_eType == REPORT ), "lcl_getSubComponentDef_nothrow: illegal controller", NULL ); + + Reference< XCommandProcessor > xCommandProcessor; + try + { + Reference< XHierarchicalNameAccess > xDefinitionContainer; + if ( i_eType == FORM ) + { + Reference< XFormDocumentsSupplier > xSuppForms( xController->getModel(), UNO_QUERY_THROW ); + xDefinitionContainer.set( xSuppForms->getFormDocuments(), UNO_QUERY_THROW ); + } + else + { + Reference< XReportDocumentsSupplier > xSuppReports( xController->getModel(), UNO_QUERY_THROW ); + xDefinitionContainer.set( xSuppReports->getReportDocuments(), UNO_QUERY_THROW ); + } + xCommandProcessor.set( xDefinitionContainer->getByHierarchicalName( i_rName ), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return xCommandProcessor; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getSettingsStreamName() + { + static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "settings.xml" ) ); + return s_sStatementStreamName; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getCurrentQueryDesignName() + { + static const ::rtl::OUString s_sQuerySettingsName( RTL_CONSTASCII_USTRINGPARAM( "ooo:current-query-design" ) ); + return s_sQuerySettingsName; + } + } + + //==================================================================== + //= SettingsExportContext + //==================================================================== + class DBACCESS_DLLPRIVATE SettingsExportContext : public ::xmloff::XMLSettingsExportContext + { + public: + SettingsExportContext( const ::comphelper::ComponentContext& i_rContext, const StorageXMLOutputStream& i_rDelegator ) + :m_rContext( i_rContext ) + ,m_rDelegator( i_rDelegator ) + ,m_aNamespace( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_NP_CONFIG ) ) + { + } + + virtual ~SettingsExportContext() + { + } + + public: + virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ); + virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ); + virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ); + virtual void EndElement ( const sal_Bool i_bIgnoreWhitespace ); + virtual void Characters( const ::rtl::OUString& i_rCharacters ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + GetServiceFactory() const; + + private: + ::rtl::OUString impl_prefix( const ::xmloff::token::XMLTokenEnum i_eToken ) + { + ::rtl::OUStringBuffer aQualifiedName( m_aNamespace ); + aQualifiedName.append( sal_Unicode( ':' ) ); + aQualifiedName.append( ::xmloff::token::GetXMLToken( i_eToken ) ); + return aQualifiedName.makeStringAndClear(); + } + + private: + const ::comphelper::ComponentContext& m_rContext; + const StorageXMLOutputStream& m_rDelegator; + const ::rtl::OUStringBuffer m_aNamespace; + }; + + //-------------------------------------------------------------------- + void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ) + { + m_rDelegator.addAttribute( impl_prefix( i_eName ), i_rValue ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ) + { + m_rDelegator.addAttribute( impl_prefix( i_eName ), ::xmloff::token::GetXMLToken( i_eValue ) ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ) + { + if ( i_bIgnoreWhitespace ) + m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + + m_rDelegator.startElement( impl_prefix( i_eName ) ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::EndElement( const sal_Bool i_bIgnoreWhitespace ) + { + if ( i_bIgnoreWhitespace ) + m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + m_rDelegator.endElement(); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::Characters( const ::rtl::OUString& i_rCharacters ) + { + m_rDelegator.characters( i_rCharacters ); + } + + //-------------------------------------------------------------------- + Reference< XMultiServiceFactory > SettingsExportContext::GetServiceFactory() const + { + return m_rContext.getLegacyServiceFactory(); + } + + //==================================================================== + //= SubComponentRecovery + //==================================================================== + //-------------------------------------------------------------------- + const ::rtl::OUString SubComponentRecovery::getComponentsStorageName( const SubComponentType i_eType ) + { + static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); + static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); + static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) ); + static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) ); + static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) ); + + switch ( i_eType ) + { + case FORM: + return s_sFormsStorageName; + case REPORT: + return s_sReportsStorageName; + case TABLE: + return s_sTablesStorageName; + case QUERY: + return s_sQueriesStorageName; + case RELATION_DESIGN: + return s_sRelationsStorageName; + default: + break; + } + + OSL_ENSURE( false, "SubComponentRecovery::getComponentsStorageName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, + MapCompTypeToCompDescs& io_mapCompDescs ) + { + if ( m_eType == UNKNOWN ) + // quite fatal, but has already been reported (as assertion) before + return; + + // open the sub storage for the given kind of components + const ::rtl::OUString& rStorageName( getComponentsStorageName( m_eType ) ); + const Reference< XStorage > xComponentsStorage( i_rRecoveryStorage->openStorageElement( + rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // find a free sub storage name, and create Yet Another Sub Storage + const ::rtl::OUString& rBaseName( lcl_getComponentStorageBaseName( m_eType ) ); + const ::rtl::OUString sStorName = ::dbtools::createUniqueName( xComponentsStorage.get(), rBaseName, true ); + const Reference< XStorage > xObjectStor( xComponentsStorage->openStorageElement( + sStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + switch ( m_eType ) + { + case FORM: + case REPORT: + impl_saveSubDocument_throw( xObjectStor ); + break; + + case QUERY: + impl_saveQueryDesign_throw( xObjectStor ); + break; + + default: + // TODO + OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); + break; + } + + // commit the storage(s) + tools::stor::commitStorageIfWriteable( xObjectStor ); + tools::stor::commitStorageIfWriteable( xComponentsStorage ); + + // remember the relationship from the component name to the storage name + MapStringToCompDesc& rMapCompDescs = io_mapCompDescs[ m_eType ]; + OSL_ENSURE( rMapCompDescs.find( sStorName ) == rMapCompDescs.end(), + "SubComponentRecoverys::saveToRecoveryStorage: object name already used!" ); + rMapCompDescs[ sStorName ] = m_aCompDesc; + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_identifyComponent_throw() + { + // ask the controller + Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = m_xDocumentUI->identifySubComponent( m_xComponent ); + m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First ); + m_aCompDesc.sName = aComponentIdentity.Second; + + // what the controller didn't give us is the information whether this is in edit mode or not ... + Reference< XModuleManager > xModuleManager( m_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); + const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent ); + + switch ( m_eType ) + { + case TABLE: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.TableDesign" ); + break; + + case QUERY: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.QueryDesign" ); + break; + + case REPORT: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.report.ReportDefinition" ) ) + { + // it's an SRB report desginer + m_aCompDesc.bForEditing = true; + break; + } + // fall through + + case FORM: + m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent ); + break; + + default: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.sdb.RelationDesign" ) ) + { + m_eType = RELATION_DESIGN; + m_aCompDesc.bForEditing = true; + } + else + { + OSL_ENSURE( false, "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" ); + } + break; + } + + OSL_POSTCOND( m_eType != UNKNOWN, + "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" ); + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveQueryDesign_throw( const Reference< XStorage >& i_rObjectStorage ) + { + ENSURE_OR_THROW( m_eType == QUERY, "illegal sub component type" ); + ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); + + // retrieve the current query design (which might differ from what we can retrieve as ActiveCommand property, since + // the latter is updated only upon successful save of the design) + Reference< XPropertySet > xDesignerProps( m_xComponent, UNO_QUERY_THROW ); + Sequence< PropertyValue > aCurrentQueryDesign; + OSL_VERIFY( xDesignerProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ) ) >>= aCurrentQueryDesign ); + + // write the query design + StorageXMLOutputStream aDesignOutput( m_rContext, i_rObjectStorage, lcl_getSettingsStreamName() ); + SettingsExportContext aSettingsExportContext( m_rContext, aDesignOutput ); + + const ::rtl::OUString sWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + + aDesignOutput.startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "office:settings" ) ) ); + aDesignOutput.ignorableWhitespace( sWhitespace ); + + XMLSettingsExportHelper aSettingsExporter( aSettingsExportContext ); + aSettingsExporter.exportAllSettings( aCurrentQueryDesign, lcl_getCurrentQueryDesignName() ); + + aDesignOutput.ignorableWhitespace( sWhitespace ); + aDesignOutput.endElement(); + aDesignOutput.close(); + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rObjectStorage ) + { + ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); + ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); + + // store the document into the storage + Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); + xStorageDocument->storeToStorage( i_rObjectStorage, Sequence< PropertyValue >() ); + } + + //-------------------------------------------------------------------- + Reference< XComponent > SubComponentRecovery::impl_recoverSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) + { + Reference< XComponent > xSubComponent; + Reference< XCommandProcessor > xDocDefinition; + + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "RecoveryStorage", i_rRecoveryStorage ); + + // load/create the sub component hidden. We'll show it when the main app window is shown. + aLoadArgs.put( "Hidden", true ); + + if ( i_rComponentName.getLength() ) + { + xDocDefinition = lcl_getSubComponentDef_nothrow( m_xDocumentUI, m_eType, i_rComponentName ); + xSubComponent.set( m_xDocumentUI->loadComponentWithArguments( + m_eType, + i_rComponentName, + i_bForEditing, + aLoadArgs.getPropertyValues() + ), + UNO_SET_THROW + ); + } + else + { + Reference< XComponent > xDocDefComponent; + xSubComponent.set( m_xDocumentUI->createComponentWithArguments( + m_eType, + aLoadArgs.getPropertyValues(), + xDocDefComponent + ), + UNO_SET_THROW + ); + + xDocDefinition.set( xDocDefComponent, UNO_QUERY ); + OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" ); + } + + if ( xDocDefinition.is() ) + { + Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW ); + Reference< XInterface > xLoader( *new SubComponentLoader( xController, xDocDefinition ) ); + (void)xLoader; + } + + return xSubComponent; + } + + //-------------------------------------------------------------------- + Reference< XComponent > SubComponentRecovery::recoverFromStorage( const Reference< XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) + { + Reference< XComponent > xSubComponent; + switch ( m_eType ) + { + case FORM: + case REPORT: + xSubComponent = impl_recoverSubDocument_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing ); + break; + case QUERY: + // TODO + default: + OSL_ENSURE( false, "SubComponentRecovery::recoverFromStorage: unimplemented case!" ); + break; + } + return xSubComponent; + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.hxx b/dbaccess/source/core/recovery/subcomponentrecovery.hxx new file mode 100644 index 000000000000..59a67d802faa --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentrecovery.hxx @@ -0,0 +1,119 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef SUBCOMPONENTRECOVERY_HXX +#define SUBCOMPONENTRECOVERY_HXX + +#include "subcomponents.hxx" + +/** === begin UNO includes === **/ +#include +#include +/** === end UNO includes === **/ + +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= SubComponentRecovery + //==================================================================== + class DBACCESS_DLLPRIVATE SubComponentRecovery + { + public: + SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rController, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rComponent ) + :m_rContext( i_rContext ) + ,m_xDocumentUI( i_rController, ::com::sun::star::uno::UNO_SET_THROW ) + ,m_xComponent( i_rComponent ) + ,m_eType( UNKNOWN ) + ,m_aCompDesc() + { + impl_identifyComponent_throw(); + } + + SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rController, + const SubComponentType i_eType ) + :m_rContext( i_rContext ) + ,m_xDocumentUI( i_rController, ::com::sun::star::uno::UNO_SET_THROW ) + ,m_xComponent() + ,m_eType( i_eType ) + ,m_aCompDesc() + { + } + + // only to be used after being constructed with a component + void saveToRecoveryStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + MapCompTypeToCompDescs& io_mapCompDescs + ); + + // only to be used after being constructed with a type + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + recoverFromStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, + const bool i_bForEditing + ); + + static const ::rtl::OUString getComponentsStorageName( const SubComponentType i_eType ); + + private: + void impl_saveSubDocument_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rObjectStorage + ); + + void impl_saveQueryDesign_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rObjectStorage + ); + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + impl_recoverSubDocument_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, + const bool i_bForEditing + ); + + void impl_identifyComponent_throw(); + + private: + const ::comphelper::ComponentContext& m_rContext; + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI > + m_xDocumentUI; + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + m_xComponent; + SubComponentType m_eType; + SubComponentDescriptor m_aCompDesc; + }; + + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SUBCOMPONENTRECOVERY_HXX diff --git a/dbaccess/source/core/recovery/subcomponents.hxx b/dbaccess/source/core/recovery/subcomponents.hxx new file mode 100644 index 000000000000..d1ba0ccb1966 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponents.hxx @@ -0,0 +1,88 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef SUBCOMPONENTS_HXX +#define SUBCOMPONENTS_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include +/** === end UNO includes === **/ + +#include + +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; + + // ------------------------------------------------------------------- + enum SubComponentType + { + TABLE = DatabaseObject::TABLE, + QUERY = DatabaseObject::QUERY, + FORM = DatabaseObject::FORM, + REPORT = DatabaseObject::REPORT, + + RELATION_DESIGN = 1000, + + UNKNOWN = 10001 + }; + + // ------------------------------------------------------------------- + struct DBACCESS_DLLPRIVATE SubComponentDescriptor + { + ::rtl::OUString sName; + bool bForEditing; + + SubComponentDescriptor() + :sName() + ,bForEditing( false ) + { + } + + SubComponentDescriptor( const ::rtl::OUString& i_rName, const bool i_bForEditing ) + :sName( i_rName ) + ,bForEditing( i_bForEditing ) + { + } + }; + + // ------------------------------------------------------------------- + typedef ::std::hash_map< ::rtl::OUString, SubComponentDescriptor, ::rtl::OUStringHash > MapStringToCompDesc; + typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; + + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SUBCOMPONENTS_HXX -- cgit From cda5b4e3899451f99741472704b325a9d5f9dbd6 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 12:04:36 +0100 Subject: autorecovery: remove unused local static method --- dbaccess/source/core/recovery/dbdocrecovery.cxx | 7 ------- 1 file changed, 7 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx index 296f3ba901d5..8e641601a8ca 100644 --- a/dbaccess/source/core/recovery/dbdocrecovery.cxx +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -261,13 +261,6 @@ namespace dbaccess return s_sObjectMapStreamName; } - // ......................................................................... - static const ::rtl::OUString& lcl_getStatementStreamName() - { - static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "statement.txt" ) ); - return s_sStatementStreamName; - } - // ......................................................................... static const ::rtl::OUString& lcl_getSettingsStreamName() { -- cgit From 44ce7ccd50206e7784130ee418fc6a01bb8aa0cc Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 12:29:05 +0100 Subject: autorecovery: import query design settings (but do not recover the query designer) --- dbaccess/source/core/recovery/dbdocrecovery.cxx | 6 - dbaccess/source/core/recovery/makefile.mk | 3 +- dbaccess/source/core/recovery/settingsimport.cxx | 294 +++++++++++++++++++++ dbaccess/source/core/recovery/settingsimport.hxx | 190 +++++++++++++ dbaccess/source/core/recovery/storagestream.cxx | 33 +++ dbaccess/source/core/recovery/storagestream.hxx | 30 +++ dbaccess/source/core/recovery/storagexmlstream.cxx | 42 +++ dbaccess/source/core/recovery/storagexmlstream.hxx | 28 ++ .../source/core/recovery/subcomponentrecovery.cxx | 149 ++++++++++- .../source/core/recovery/subcomponentrecovery.hxx | 7 + 10 files changed, 774 insertions(+), 8 deletions(-) create mode 100644 dbaccess/source/core/recovery/settingsimport.cxx create mode 100644 dbaccess/source/core/recovery/settingsimport.hxx (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx index 76a67794ee53..4e45dc08d9c4 100644 --- a/dbaccess/source/core/recovery/dbdocrecovery.cxx +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -382,12 +382,6 @@ namespace dbaccess ) { const SubComponentType eComponentType = map->first; - if ( ( eComponentType != FORM ) && ( eComponentType != REPORT ) ) - { - // nobody saves tables/queries/relations at the moment, so encountering those is worth an assertion - OSL_ENSURE( false, "DatabaseDocumentRecovery::recoverSubDocuments: only embedded objects can be recovered currently!" ); - continue; - } // the storage for all components of the current type Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( diff --git a/dbaccess/source/core/recovery/makefile.mk b/dbaccess/source/core/recovery/makefile.mk index 8679a23dcfec..c13334bbc9d9 100644 --- a/dbaccess/source/core/recovery/makefile.mk +++ b/dbaccess/source/core/recovery/makefile.mk @@ -49,7 +49,8 @@ SLOFILES= \ $(SLO)$/storagestream.obj \ $(SLO)$/storagexmlstream.obj \ $(SLO)$/storagetextstream.obj \ - $(SLO)$/subcomponentrecovery.obj + $(SLO)$/subcomponentrecovery.obj \ + $(SLO)$/settingsimport.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/recovery/settingsimport.cxx b/dbaccess/source/core/recovery/settingsimport.cxx new file mode 100644 index 000000000000..566bf42ae847 --- /dev/null +++ b/dbaccess/source/core/recovery/settingsimport.cxx @@ -0,0 +1,294 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "settingsimport.hxx" + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#include +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::xml::sax::XAttributeList; + /** === end UNO using === **/ + + //==================================================================== + //= SettingsImport + //==================================================================== + //-------------------------------------------------------------------- + SettingsImport::SettingsImport() + :m_refCount( 0 ) + { + } + + //-------------------------------------------------------------------- + SettingsImport::~SettingsImport() + { + } + + //-------------------------------------------------------------------- + oslInterlockedCount SAL_CALL SettingsImport::acquire() + { + return osl_incrementInterlockedCount( &m_refCount ); + } + + //-------------------------------------------------------------------- + oslInterlockedCount SAL_CALL SettingsImport::release() + { + oslInterlockedCount newCount = osl_decrementInterlockedCount( &m_refCount ); + if ( newCount == 0 ) + delete this; + return newCount; + } + + //-------------------------------------------------------------------- + void SettingsImport::startElement( const Reference< XAttributeList >& i_rAttributes ) + { + // find the name of the setting + if ( i_rAttributes.is() ) + { + m_sItemName = i_rAttributes->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "config:name" ) ) ); + m_sItemType = i_rAttributes->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "config:type" ) ) ); + } + } + + //-------------------------------------------------------------------- + void SettingsImport::endElement() + { + } + + //-------------------------------------------------------------------- + void SettingsImport::characters( const ::rtl::OUString& i_rCharacters ) + { + m_aCharacters.append( i_rCharacters ); + } + + //-------------------------------------------------------------------- + void SettingsImport::split( const ::rtl::OUString& i_rElementName, ::rtl::OUString& o_rNamespace, ::rtl::OUString& o_rLocalName ) + { + o_rNamespace = ::rtl::OUString(); + o_rLocalName = i_rElementName; + const sal_Int32 nSeparatorPos = i_rElementName.indexOf( ':' ); + if ( nSeparatorPos > -1 ) + { + o_rNamespace = i_rElementName.copy( 0, nSeparatorPos ); + o_rLocalName = i_rElementName.copy( nSeparatorPos + 1 ); + } + + OSL_ENSURE( o_rNamespace.equalsAscii( "config" ), "SettingsImport::split: unexpected namespace!" ); + // our recovery file is kind of hand-made, so there shouldn't be anything else than "config". + // If there is, then just ignore it ... + } + + //==================================================================== + //= IgnoringSettingsImport + //==================================================================== + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > IgnoringSettingsImport::nextState( const ::rtl::OUString& i_rElementName ) + { + (void)i_rElementName; + return this; + } + + //==================================================================== + //= OfficeSettingsImport + //==================================================================== + //-------------------------------------------------------------------- + OfficeSettingsImport::OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings ) + :m_rSettings( o_rSettings ) + { + } + + //-------------------------------------------------------------------- + OfficeSettingsImport::~OfficeSettingsImport() + { + } + + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > OfficeSettingsImport::nextState( const ::rtl::OUString& i_rElementName ) + { + // separate the namespace part from the element name + ::rtl::OUString sNamespace; + ::rtl::OUString sLocalName; + split( i_rElementName, sNamespace, sLocalName ); + + if ( sLocalName.equalsAscii( "config-item-set" ) ) + return new ConfigItemSetImport( m_rSettings ); + +#if OSL_DEBUG_LEVEL > 0 + ::rtl::OString sMessage( "unknown (or unsupported at this place) element name '" ); + sMessage += ::rtl::OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 ); + sMessage += "', ignoring"; + OSL_ENSURE( false, sMessage.getStr() ); +#endif + return new IgnoringSettingsImport; + } + + //==================================================================== + //= ConfigItemImport + //==================================================================== + //-------------------------------------------------------------------- + ConfigItemImport::ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings ) + :m_rSettings( o_rSettings ) + { + } + + //-------------------------------------------------------------------- + ConfigItemImport::~ConfigItemImport() + { + } + + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > ConfigItemImport::nextState( const ::rtl::OUString& i_rElementName ) + { + OSL_ENSURE( false, "ConfigItemImport::nextState: unexpected: this class is responsible for child-less items only!" ); + (void)i_rElementName; + return new IgnoringSettingsImport; + } + + //-------------------------------------------------------------------- + void ConfigItemImport::endElement() + { + SettingsImport::endElement(); + + const ::rtl::OUString sItemName( getItemName() ); + ENSURE_OR_RETURN_VOID( sItemName.getLength(), "no item name -> no item value" ); + Any aValue; + getItemValue( aValue ); + m_rSettings.put( sItemName, aValue ); + } + + //-------------------------------------------------------------------- + void ConfigItemImport::getItemValue( ::com::sun::star::uno::Any& o_rValue ) const + { + o_rValue.clear(); + + // the characters building up th evalue + ::rtl::OUStringBuffer aCharacters( getAccumulatedCharacters() ); + const ::rtl::OUString sValue = aCharacters.makeStringAndClear(); + + const ::rtl::OUString& rItemType( getItemType() ); + ENSURE_OR_RETURN_VOID( rItemType.getLength(), "no item type -> no item value" ); + + if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_INT ) ) + { + sal_Int32 nValue(0); + if ( SvXMLUnitConverter::convertNumber( nValue, sValue ) ) + o_rValue <<= nValue; + else + { + OSL_ENSURE( false, "ConfigItemImport::getItemValue: could not convert an int value!" ); + } + } + else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_BOOLEAN ) ) + { + sal_Bool nValue( sal_False ); + if ( SvXMLUnitConverter::convertBool( nValue, sValue ) ) + o_rValue <<= nValue; + else + { + OSL_ENSURE( false, "ConfigItemImport::getItemValue: could not convert a boolean value!" ); + } + } + else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_STRING ) ) + { + o_rValue <<= sValue; + } +#if OSL_DEBUG_LEVEL > 0 + else + { + ::rtl::OString sMessage( "ConfigItemImport::getItemValue: unsupported item type '" ); + sMessage += ::rtl::OUStringToOString( rItemType, RTL_TEXTENCODING_UTF8 ); + sMessage += "', ignoring"; + OSL_ENSURE( false, sMessage.getStr() ); + } +#endif + } + + //==================================================================== + //= ConfigItemSetImport + //==================================================================== + //-------------------------------------------------------------------- + ConfigItemSetImport::ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings ) + :ConfigItemImport( o_rSettings ) + { + } + + //-------------------------------------------------------------------- + ConfigItemSetImport::~ConfigItemSetImport() + { + } + + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > ConfigItemSetImport::nextState( const ::rtl::OUString& i_rElementName ) + { + // separate the namespace part from the element name + ::rtl::OUString sNamespace; + ::rtl::OUString sLocalName; + split( i_rElementName, sNamespace, sLocalName ); + + if ( sLocalName.equalsAscii( "config-item-set" ) ) + return new ConfigItemSetImport( m_aChildSettings ); + if ( sLocalName.equalsAscii( "config-item" ) ) + return new ConfigItemImport( m_aChildSettings ); + +#if OSL_DEBUG_LEVEL > 0 + ::rtl::OString sMessage( "unknown element name '" ); + sMessage += ::rtl::OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 ); + sMessage += "', ignoring"; + OSL_ENSURE( false, sMessage.getStr() ); +#endif + return new IgnoringSettingsImport; + } + + //-------------------------------------------------------------------- + void ConfigItemSetImport::getItemValue( Any& o_rValue ) const + { + o_rValue <<= m_aChildSettings.getPropertyValues(); + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/settingsimport.hxx b/dbaccess/source/core/recovery/settingsimport.hxx new file mode 100644 index 000000000000..3415092ee93a --- /dev/null +++ b/dbaccess/source/core/recovery/settingsimport.hxx @@ -0,0 +1,190 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +************************************************************************/ + +#ifndef SETTINGSIMPORT_HXX +#define SETTINGSIMPORT_HXX + +/** === begin UNO includes === **/ +#include +/** === end UNO includes === **/ + +#include +#include +#include + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= SettingsImport + //==================================================================== + /** a simplified version of xmloff/DocumentSettingsContext + + It would be nice if the DocumentSettingsContext would not be that tightly interwoven with the SvXMLImport + class, so we could re-use it here ... + */ + class SettingsImport : public ::rtl::IReference + { + public: + SettingsImport(); + + // IReference + virtual oslInterlockedCount SAL_CALL acquire(); + virtual oslInterlockedCount SAL_CALL release(); + + // own overriables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ) = 0; + virtual void startElement( + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& i_rAttributes + ); + virtual void endElement(); + virtual void characters( const ::rtl::OUString& i_rCharacters ); + + protected: + virtual ~SettingsImport(); + + protected: + static void split( const ::rtl::OUString& i_rElementName, ::rtl::OUString& o_rNamespace, ::rtl::OUString& o_rLocalName ); + + protected: + const ::rtl::OUString& getItemName() const { return m_sItemName; } + const ::rtl::OUString& getItemType() const { return m_sItemType; } + const ::rtl::OUStringBuffer& getAccumulatedCharacters() const { return m_aCharacters; } + + private: + oslInterlockedCount m_refCount; + // value of the config:name attribute, if any + ::rtl::OUString m_sItemName; + // value of the config:type attribute, if any + ::rtl::OUString m_sItemType; + // accumulated characters, if any + ::rtl::OUStringBuffer m_aCharacters; + }; + + //==================================================================== + //= IgnoringSettingsImport + //==================================================================== + class IgnoringSettingsImport : public SettingsImport + { + public: + IgnoringSettingsImport() + { + } + + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + + private: + ~IgnoringSettingsImport() + { + } + }; + + //==================================================================== + //= OfficeSettingsImport + //==================================================================== + class OfficeSettingsImport : public SettingsImport + { + public: + OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings ); + + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + + protected: + ~OfficeSettingsImport(); + + private: + // the settings collection to which |this| will contribute a single setting + ::comphelper::NamedValueCollection& m_rSettings; + }; + + //==================================================================== + //= ConfigItemSetImport + //==================================================================== + class ConfigItemImport : public SettingsImport + { + public: + ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings ); + + protected: + ~ConfigItemImport(); + + public: + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + virtual void endElement(); + + protected: + // own overridables + /// retrieves the value represented by the element + virtual void getItemValue( ::com::sun::star::uno::Any& o_rValue ) const; + + private: + // the settings collection to which |this| will contribute a single setting + ::comphelper::NamedValueCollection& m_rSettings; + }; + + //==================================================================== + //= ConfigItemSetImport + //==================================================================== + class ConfigItemSetImport : public ConfigItemImport + { + public: + ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings ); + + protected: + ~ConfigItemSetImport(); + + public: + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + + protected: + // ConfigItemImport overridables + virtual void getItemValue( ::com::sun::star::uno::Any& o_rValue ) const; + + private: + /// the settings represented by our child elements + ::comphelper::NamedValueCollection m_aChildSettings; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SETTINGSIMPORT_HXX diff --git a/dbaccess/source/core/recovery/storagestream.cxx b/dbaccess/source/core/recovery/storagestream.cxx index e8fb99600854..ec6ff49a6098 100644 --- a/dbaccess/source/core/recovery/storagestream.cxx +++ b/dbaccess/source/core/recovery/storagestream.cxx @@ -88,6 +88,39 @@ namespace dbaccess // (legitimately) do not call this method here. } + //==================================================================== + //= StorageInputStream + //==================================================================== + //-------------------------------------------------------------------- + StorageInputStream::StorageInputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ) + :m_rContext( i_rContext ) + { + ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" ); + + const Reference< XStream > xStream( + i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READ ), UNO_QUERY_THROW ); + m_xInputStream.set( xStream->getInputStream(), UNO_SET_THROW ); + } + + //-------------------------------------------------------------------- + StorageInputStream::~StorageInputStream() + { + } + + //-------------------------------------------------------------------- + void StorageInputStream::close() + { + ENSURE_OR_RETURN_VOID( m_xInputStream.is(), "already closed" ); + m_xInputStream->closeInput(); + m_xInputStream.clear(); + + // if you add additional functionality here, be aware that there are derived classes which + // (legitimately) do not call this method here. + } + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/recovery/storagestream.hxx b/dbaccess/source/core/recovery/storagestream.hxx index a214d3d84d7d..2485cfac24cb 100644 --- a/dbaccess/source/core/recovery/storagestream.hxx +++ b/dbaccess/source/core/recovery/storagestream.hxx @@ -72,6 +72,36 @@ namespace dbaccess m_xOutputStream; }; + //==================================================================== + //= StorageInputStream + //==================================================================== + /** convenience wrapper around a stream living in a storage + */ + class DBACCESS_DLLPRIVATE StorageInputStream + { + public: + StorageInputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + virtual ~StorageInputStream(); + + /** simply calls closeInput on our input stream, override to extend/modify this behavior + */ + virtual void close(); + + protected: + const ::comphelper::ComponentContext& getContext() const { return m_rContext; } + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& + getInputStream() const { return m_xInputStream; } + + private: + const ::comphelper::ComponentContext& m_rContext; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > + m_xInputStream; + }; + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/recovery/storagexmlstream.cxx b/dbaccess/source/core/recovery/storagexmlstream.cxx index 10c64cc4141c..8405cce75903 100644 --- a/dbaccess/source/core/recovery/storagexmlstream.cxx +++ b/dbaccess/source/core/recovery/storagexmlstream.cxx @@ -30,9 +30,11 @@ /** === begin UNO includes === **/ #include #include +#include /** === end UNO includes === **/ #include +#include #include #include #include @@ -62,6 +64,8 @@ namespace dbaccess using ::com::sun::star::io::XStream; using ::com::sun::star::io::XOutputStream; using ::com::sun::star::io::XActiveDataSource; + using ::com::sun::star::xml::sax::XParser; + using ::com::sun::star::xml::sax::InputSource; /** === end UNO using === **/ //================================================================================================================== @@ -150,6 +154,44 @@ namespace dbaccess m_pData->xHandler->characters( i_rCharacters ); } + //================================================================================================================== + //= StorageXMLInputStream_Data + //================================================================================================================== + struct StorageXMLInputStream_Data + { + Reference< XParser > xParser; + }; + + //================================================================================================================== + //= StorageXMLInputStream + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + StorageXMLInputStream::StorageXMLInputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName ) + :StorageInputStream( i_rContext, i_rParentStorage, i_rStreamName ) + ,m_pData( new StorageXMLInputStream_Data ) + { + m_pData->xParser.set( i_rContext.createComponent( "com.sun.star.xml.sax.Parser" ), UNO_QUERY_THROW ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLInputStream::import( const Reference< XDocumentHandler >& i_rHandler ) + { + ENSURE_OR_THROW( i_rHandler.is(), "illegal document handler (NULL)" ); + + InputSource aInputSource; + aInputSource.aInputStream = getInputStream(); + + m_pData->xParser->setDocumentHandler( i_rHandler ); + m_pData->xParser->parseStream( aInputSource ); + } + + //------------------------------------------------------------------------------------------------------------------ + StorageXMLInputStream::~StorageXMLInputStream() + { + } + //...................................................................................................................... } // namespace dbaccess //...................................................................................................................... diff --git a/dbaccess/source/core/recovery/storagexmlstream.hxx b/dbaccess/source/core/recovery/storagexmlstream.hxx index 504e6b7ccd25..10a8aaaed5de 100644 --- a/dbaccess/source/core/recovery/storagexmlstream.hxx +++ b/dbaccess/source/core/recovery/storagexmlstream.hxx @@ -30,6 +30,7 @@ /** === begin UNO includes === **/ #include +#include /** === end UNO includes === **/ #include @@ -78,6 +79,33 @@ namespace dbaccess ::std::auto_ptr< StorageXMLOutputStream_Data > m_pData; }; + //==================================================================== + //= StorageXMLInputStream + //==================================================================== + struct StorageXMLInputStream_Data; + class DBACCESS_DLLPRIVATE StorageXMLInputStream : public StorageInputStream + { + public: + StorageXMLInputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + ~StorageXMLInputStream(); + + void import( + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& i_rHandler + ); + + private: + StorageXMLInputStream(); // never implemented + StorageXMLInputStream( const StorageXMLInputStream& ); // never implemented + StorageXMLInputStream& operator=( const StorageXMLInputStream& ); // never implemented + + private: + ::std::auto_ptr< StorageXMLInputStream_Data > m_pData; + }; + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.cxx b/dbaccess/source/core/recovery/subcomponentrecovery.cxx index 2331b70d42cc..4551c83083ee 100644 --- a/dbaccess/source/core/recovery/subcomponentrecovery.cxx +++ b/dbaccess/source/core/recovery/subcomponentrecovery.cxx @@ -30,6 +30,7 @@ #include "sdbcoretools.hxx" #include "storagexmlstream.hxx" #include "subcomponentloader.hxx" +#include "settingsimport.hxx" /** === begin UNO includes === **/ #include @@ -39,6 +40,7 @@ #include #include #include +#include /** === end UNO includes === **/ #include @@ -79,6 +81,10 @@ namespace dbaccess using ::com::sun::star::container::XHierarchicalNameAccess; using ::com::sun::star::sdb::XFormDocumentsSupplier; using ::com::sun::star::sdb::XReportDocumentsSupplier; + using ::com::sun::star::xml::sax::SAXException; + using ::com::sun::star::xml::sax::XLocator; + using ::com::sun::star::xml::sax::XDocumentHandler; + using ::com::sun::star::xml::sax::XAttributeList; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; @@ -276,6 +282,125 @@ namespace dbaccess return m_rContext.getLegacyServiceFactory(); } + //================================================================================================================== + //= SettingsDocumentHandler + //================================================================================================================== + typedef ::cppu::WeakImplHelper1 < XDocumentHandler + > SettingsDocumentHandler_Base; + class DBACCESS_DLLPRIVATE SettingsDocumentHandler : public SettingsDocumentHandler_Base + { + public: + SettingsDocumentHandler() + { + } + + protected: + virtual ~SettingsDocumentHandler() + { + } + + public: + // XDocumentHandler + virtual void SAL_CALL startDocument( ) throw (SAXException, RuntimeException); + virtual void SAL_CALL endDocument( ) throw (SAXException, RuntimeException); + virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const Reference< XAttributeList >& xAttribs ) throw (SAXException, RuntimeException); + virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (SAXException, RuntimeException); + virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (SAXException, RuntimeException); + virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (SAXException, RuntimeException); + virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (SAXException, RuntimeException); + virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) throw (SAXException, RuntimeException); + + const ::comphelper::NamedValueCollection& getSettings() const { return m_aSettings; } + + private: + ::std::stack< ::rtl::Reference< SettingsImport > > m_aStates; + ::comphelper::NamedValueCollection m_aSettings; + }; + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::startDocument( ) throw (SAXException, RuntimeException) + { + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::endDocument( ) throw (SAXException, RuntimeException) + { + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::startElement( const ::rtl::OUString& i_Name, const Reference< XAttributeList >& i_Attribs ) throw (SAXException, RuntimeException) + { + ::rtl::Reference< SettingsImport > pNewState; + + if ( m_aStates.empty() ) + { + if ( i_Name.equalsAscii( "office:settings" ) ) + { + pNewState = new OfficeSettingsImport( m_aSettings ); + } + else + { + OSL_ENSURE( false, "SettingsDocumentHandler::startElement: invalid settings file!" ); + // Yes, that's not correct. Somebody could, in theory, give us a document which starts with "foo:settings", + // where "foo" is mapped to the proper namespace URL. + // However, there's no need to bother with this. The "recovery" sub storage we're recovering from is + // not part of ODF, so we can impose any format restrictions on it ... + } + } + else + { + ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() ); + pNewState = pCurrentState->nextState( i_Name ); + } + + ENSURE_OR_THROW( pNewState.is(), "no new state - aborting import" ); + pNewState->startElement( i_Attribs ); + + m_aStates.push( pNewState ); + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::endElement( const ::rtl::OUString& i_Name ) throw (SAXException, RuntimeException) + { + ENSURE_OR_THROW( !m_aStates.empty(), "no active element" ); + (void)i_Name; + + ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() ); + pCurrentState->endElement(); + m_aStates.pop(); + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::characters( const ::rtl::OUString& i_Chars ) throw (SAXException, RuntimeException) + { + ENSURE_OR_THROW( !m_aStates.empty(), "no active element" ); + + ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() ); + pCurrentState->characters( i_Chars ); + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (SAXException, RuntimeException) + { + // ignore them - that's why they're called "ignorable" + (void)aWhitespaces; + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::processingInstruction( const ::rtl::OUString& i_Target, const ::rtl::OUString& i_Data ) throw (SAXException, RuntimeException) + { + OSL_ENSURE( false, "SettingsDocumentHandler::processingInstruction: unexpected ..." ); + (void)i_Target; + (void)i_Data; + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::setDocumentLocator( const Reference< XLocator >& i_Locator ) throw (SAXException, RuntimeException) + { + // TODO: place your code here + (void)i_Locator; + } + //==================================================================== //= SubComponentRecovery //==================================================================== @@ -498,6 +623,27 @@ namespace dbaccess return xSubComponent; } + //-------------------------------------------------------------------- + Reference< XComponent > SubComponentRecovery::impl_recoverQueryDesign_throw( const Reference< XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) + { + Reference< XComponent > xSubComponent; + + // first read the settings query design settings from the storage + StorageXMLInputStream aDesignInput( m_rContext, i_rRecoveryStorage, lcl_getSettingsStreamName() ); + + ::rtl::Reference< SettingsDocumentHandler > pDocHandler( new SettingsDocumentHandler ); + aDesignInput.import( pDocHandler.get() ); + + const ::comphelper::NamedValueCollection& rSettings( pDocHandler->getSettings() ); + + // TODO + (void)i_rComponentName; + (void)i_bForEditing; + + return xSubComponent; + } + //-------------------------------------------------------------------- Reference< XComponent > SubComponentRecovery::recoverFromStorage( const Reference< XStorage >& i_rRecoveryStorage, const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) @@ -510,7 +656,8 @@ namespace dbaccess xSubComponent = impl_recoverSubDocument_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing ); break; case QUERY: - // TODO + xSubComponent = impl_recoverQueryDesign_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing ); + break; default: OSL_ENSURE( false, "SubComponentRecovery::recoverFromStorage: unimplemented case!" ); break; diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.hxx b/dbaccess/source/core/recovery/subcomponentrecovery.hxx index 59a67d802faa..2cec262937a8 100644 --- a/dbaccess/source/core/recovery/subcomponentrecovery.hxx +++ b/dbaccess/source/core/recovery/subcomponentrecovery.hxx @@ -99,6 +99,13 @@ namespace dbaccess const bool i_bForEditing ); + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + impl_recoverQueryDesign_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, + const bool i_bForEditing + ); + void impl_identifyComponent_throw(); private: -- cgit From 155487cc3f15c1db017e260c77f2e3d9041e0bb4 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 15:21:07 +0100 Subject: autorecovery: recover query designer settings not yet finished: - query designer needs to be loaded hidden, and shown when the main window is shown - recovering table windows is not correct, yet (windows which have been added to the UI, but do not yet add to the "latest known" statement, are not restored (probably) - closing the recovered, and modified, query designer somehow does not ask for saving --- .../source/core/recovery/subcomponentrecovery.cxx | 36 ++++++- dbaccess/source/ui/inc/JoinController.hxx | 6 +- dbaccess/source/ui/inc/QueryDesignView.hxx | 4 + dbaccess/source/ui/inc/QueryViewSwitch.hxx | 5 + dbaccess/source/ui/inc/TableFieldDescription.hxx | 13 +-- dbaccess/source/ui/inc/querycontainerwindow.hxx | 1 + dbaccess/source/ui/inc/querycontroller.hxx | 9 +- dbaccess/source/ui/querydesign/JoinController.cxx | 82 +++++---------- dbaccess/source/ui/querydesign/QueryDesignView.cxx | 25 +++++ dbaccess/source/ui/querydesign/QueryViewSwitch.cxx | 87 +++++++++++---- .../ui/querydesign/TableFieldDescription.cxx | 117 ++++++++++++--------- .../source/ui/querydesign/querycontainerwindow.cxx | 6 ++ dbaccess/source/ui/querydesign/querycontroller.cxx | 102 +++++++++++------- 13 files changed, 312 insertions(+), 181 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.cxx b/dbaccess/source/core/recovery/subcomponentrecovery.cxx index 4551c83083ee..bcfc3131892f 100644 --- a/dbaccess/source/core/recovery/subcomponentrecovery.cxx +++ b/dbaccess/source/core/recovery/subcomponentrecovery.cxx @@ -636,10 +636,40 @@ namespace dbaccess aDesignInput.import( pDocHandler.get() ); const ::comphelper::NamedValueCollection& rSettings( pDocHandler->getSettings() ); + const Any aCurrentQueryDesign = rSettings.get( lcl_getCurrentQueryDesignName() ); +#if OSL_DEBUG_LEVEL > 0 + Sequence< PropertyValue > aQueryDesignLayout; + OSL_VERIFY( aCurrentQueryDesign >>= aQueryDesignLayout ); +#endif - // TODO - (void)i_rComponentName; - (void)i_bForEditing; + // then load the query designer + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "CurrentQueryDesign", aCurrentQueryDesign ); + + // TODO: load the thing hidden, and show when the main doc window is shown + + if ( i_rComponentName.getLength() ) + { + xSubComponent.set( m_xDocumentUI->loadComponentWithArguments( + m_eType, + i_rComponentName, + i_bForEditing, + aLoadArgs.getPropertyValues() + ), + UNO_SET_THROW + ); + } + else + { + Reference< XComponent > xDummy; + xSubComponent.set( m_xDocumentUI->createComponentWithArguments( + m_eType, + aLoadArgs.getPropertyValues(), + xDummy + ), + UNO_SET_THROW + ); + } return xSubComponent; } diff --git a/dbaccess/source/ui/inc/JoinController.hxx b/dbaccess/source/ui/inc/JoinController.hxx index 72e61c4bab3d..6561e7b9f282 100644 --- a/dbaccess/source/ui/inc/JoinController.hxx +++ b/dbaccess/source/ui/inc/JoinController.hxx @@ -87,16 +87,16 @@ namespace dbaui virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); /** loads the information for the windows. - @param _aViewProps + @param i_rViewSettings The properties which comes from the layout information. */ - void loadTableWindows(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aViewProps); + void loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings ); /** loads the information for one window. @param _rTable The properties which comes from the layout information. */ - void loadTableWindow(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rTable); + void loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings ); /** saves the TableWindows structure in a sequence of property values @param _rViewProps diff --git a/dbaccess/source/ui/inc/QueryDesignView.hxx b/dbaccess/source/ui/inc/QueryDesignView.hxx index 6a97719e0c27..cf501441e4ee 100644 --- a/dbaccess/source/ui/inc/QueryDesignView.hxx +++ b/dbaccess/source/ui/inc/QueryDesignView.hxx @@ -167,6 +167,10 @@ namespace dbaui */ bool initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo ); + void initByFieldDescriptions( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rFieldDescriptions + ); + ::connectivity::OSQLParseNode* getPredicateTreeFromEntry( OTableFieldDescRef pEntry, const String& _sCriteria, ::rtl::OUString& _rsErrorMessage, diff --git a/dbaccess/source/ui/inc/QueryViewSwitch.hxx b/dbaccess/source/ui/inc/QueryViewSwitch.hxx index c0692ba48af0..abeccbac4ce2 100644 --- a/dbaccess/source/ui/inc/QueryViewSwitch.hxx +++ b/dbaccess/source/ui/inc/QueryViewSwitch.hxx @@ -78,6 +78,7 @@ namespace dbaui old state) */ bool switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ); + void forceInitialView(); sal_Bool isSlotEnabled(sal_Int32 _nSlotId); void setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable); void setNoneVisbleRow(sal_Int32 _nRows); @@ -96,6 +97,10 @@ namespace dbaui protected: // return the Rectangle where I can paint myself virtual void resizeDocumentView(Rectangle& rRect); + + private: + void impl_forceSQLView(); + bool impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess ); }; } #endif // DBAUI_QUERYVIEWSWITCH_HXX diff --git a/dbaccess/source/ui/inc/TableFieldDescription.hxx b/dbaccess/source/ui/inc/TableFieldDescription.hxx index dd4489821331..64d17909fcce 100644 --- a/dbaccess/source/ui/inc/TableFieldDescription.hxx +++ b/dbaccess/source/ui/inc/TableFieldDescription.hxx @@ -58,7 +58,8 @@ namespace dbaui class OTableFieldDesc : public ::vos::OReference { private: - ::std::vector< ::rtl::OUString> m_vecCriteria; + ::std::vector< ::rtl::OUString > + m_aCriteria; ::rtl::OUString m_aTableName; ::rtl::OUString m_aAliasName; // table range @@ -136,18 +137,18 @@ namespace dbaui sal_Bool HasCriteria() const { - ::std::vector< ::rtl::OUString>::const_iterator aIter = m_vecCriteria.begin(); - ::std::vector< ::rtl::OUString>::const_iterator aEnd = m_vecCriteria.end(); + ::std::vector< ::rtl::OUString>::const_iterator aIter = m_aCriteria.begin(); + ::std::vector< ::rtl::OUString>::const_iterator aEnd = m_aCriteria.end(); for(;aIter != aEnd;++aIter) if(aIter->getLength()) break; return aIter != aEnd; } - const ::std::vector< ::rtl::OUString>& GetCriteria() const { return m_vecCriteria;} + const ::std::vector< ::rtl::OUString>& GetCriteria() const { return m_aCriteria; } - void Load(const ::com::sun::star::beans::PropertyValue& _rProperty); - void Save( ::comphelper::NamedValueCollection& o_rSettings ); + void Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria ); + void Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria ); }; //------------------------------------------------------------------ diff --git a/dbaccess/source/ui/inc/querycontainerwindow.hxx b/dbaccess/source/ui/inc/querycontainerwindow.hxx index 44af65ed2b2a..8d7bb4f7999f 100644 --- a/dbaccess/source/ui/inc/querycontainerwindow.hxx +++ b/dbaccess/source/ui/inc/querycontainerwindow.hxx @@ -118,6 +118,7 @@ namespace dbaui bool reset( ::dbtools::SQLExceptionInfo* _pErrorInfo ) { return m_pViewSwitch->reset( _pErrorInfo ); } bool switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ); + void forceInitialView(); virtual void GetFocus(); diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx index eeabaa13192b..c119095c28bb 100644 --- a/dbaccess/source/ui/inc/querycontroller.hxx +++ b/dbaccess/source/ui/inc/querycontroller.hxx @@ -130,8 +130,8 @@ namespace dbaui void executeQuery(); bool doSaveAsDoc(sal_Bool _bSaveAs); - void saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includngCriteria ) const; - void loadViewSettings( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rViewData ); + void saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includingCriteria ) const; + void loadViewSettings( const ::comphelper::NamedValueCollection& o_rViewSettings ); ::rtl::OUString translateStatement( bool _bFireStatementChange = true ); ::rtl::OUString getDefaultName() const; @@ -175,6 +175,9 @@ namespace dbaui sal_Int32 getColWidth(sal_uInt16 _nColPos) const; + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& + getFieldInformation() const { return m_aFieldInformation; } + ::connectivity::OSQLParser& getParser() { return m_aSqlParser; } ::connectivity::OSQLParseTreeIterator& getParseIterator() { return *m_pSqlIterator; } @@ -231,7 +234,7 @@ namespace dbaui virtual void reset(); virtual void impl_initialize(); - void impl_reset(); + void impl_reset( const bool i_bIgnoreQuerySettings = false ); /// tells the user that we needed to switch to SQL view automatically void impl_showAutoSQLViewError( const ::com::sun::star::uno::Any& _rErrorDetails ); diff --git a/dbaccess/source/ui/querydesign/JoinController.cxx b/dbaccess/source/ui/querydesign/JoinController.cxx index 7191bf6252b6..0582230e0191 100644 --- a/dbaccess/source/ui/querydesign/JoinController.cxx +++ b/dbaccess/source/ui/querydesign/JoinController.cxx @@ -455,73 +455,45 @@ sal_Bool SAL_CALL OJoinController::suspend(sal_Bool _bSuspend) throw( RuntimeExc return bCheck; } // ----------------------------------------------------------------------------- -void OJoinController::loadTableWindows(const Sequence& aViewProps) +void OJoinController::loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings ) { m_vTableData.clear(); - const PropertyValue *pIter = aViewProps.getConstArray(); - const PropertyValue *pEnd = pIter + aViewProps.getLength(); - for (; pIter != pEnd; ++pIter) + m_aMinimumTableViewSize = Point(); + + Sequence< PropertyValue > aWindowData; + aWindowData = i_rViewSettings.getOrDefault( "Tables", aWindowData ); + + const PropertyValue* pTablesIter = aWindowData.getConstArray(); + const PropertyValue* pTablesEnd = pTablesIter + aWindowData.getLength(); + for ( ; pTablesIter != pTablesEnd; ++pTablesIter ) { - if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Tables" ) ) ) - { - m_aMinimumTableViewSize = Point(); - Sequence aWindow; - pIter->Value >>= aWindow; - const PropertyValue *pTablesIter = aWindow.getConstArray(); - const PropertyValue *pTablesEnd = pTablesIter + aWindow.getLength(); - for (; pTablesIter != pTablesEnd; ++pTablesIter) - { - Sequence aTable; - pTablesIter->Value >>= aTable; - loadTableWindow(aTable); - } - if ( m_aMinimumTableViewSize != Point() ) - { - getJoinView()->getScrollHelper()->resetRange(m_aMinimumTableViewSize); - } - break; - } + ::comphelper::NamedValueCollection aSingleTableData( pTablesIter->Value ); + loadTableWindow( aSingleTableData ); + } + if ( m_aMinimumTableViewSize != Point() ) + { + getJoinView()->getScrollHelper()->resetRange( m_aMinimumTableViewSize ); } } + // ----------------------------------------------------------------------------- -void OJoinController::loadTableWindow(const Sequence& _rTable) +void OJoinController::loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings ) { sal_Int32 nX = -1, nY = -1, nHeight = -1, nWidth = -1; ::rtl::OUString sComposedName,sTableName,sWindowName; sal_Bool bShowAll = false; - const PropertyValue *pIter = _rTable.getConstArray(); - const PropertyValue *pEnd = pIter + _rTable.getLength(); - for (; pIter != pEnd; ++pIter) - { - if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ComposedName" ) ) ) - pIter->Value >>= sComposedName; - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "TableName" ) ) ) - pIter->Value >>= sTableName; - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowName" ) ) ) - pIter->Value >>= sWindowName; - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowTop" ) ) ) - { - pIter->Value >>= nY; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowLeft" ) ) ) - { - pIter->Value >>= nX; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowWidth" ) ) ) - { - pIter->Value >>= nWidth; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowHeight" ) ) ) - { - pIter->Value >>= nHeight; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowAll" ) ) ) - { - pIter->Value >>= bShowAll; - } - } + + sComposedName = i_rTableWindowSettings.getOrDefault( "ComposedName", sComposedName ); + sTableName = i_rTableWindowSettings.getOrDefault( "TableName", sTableName ); + sWindowName = i_rTableWindowSettings.getOrDefault( "WindowName", sWindowName ); + nY = i_rTableWindowSettings.getOrDefault( "WindowTop", nY ); + nX = i_rTableWindowSettings.getOrDefault( "WindowLeft", nX ); + nWidth = i_rTableWindowSettings.getOrDefault( "WindowWidth", nWidth ); + nHeight = i_rTableWindowSettings.getOrDefault( "WindowHeight", nHeight ); + bShowAll = i_rTableWindowSettings.getOrDefault( "ShowAll", bShowAll ); + TTableWindowData::value_type pData = createTableWindowData(sComposedName,sTableName,sWindowName); if ( pData ) { diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index 624763306d04..3f927076f4a9 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -1992,6 +1992,7 @@ namespace (*aIter) = NULL; OTableFields().swap( rUnUsedFields ); } + //------------------------------------------------------------------------------ SqlParseError InitFromParseNodeImpl(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw) { @@ -3180,6 +3181,30 @@ void OQueryDesignView::setNoneVisbleRow(sal_Int32 _nRows) { m_pSelectionBox->SetNoneVisbleRow(_nRows); } + +// ----------------------------------------------------------------------------- +void OQueryDesignView::initByFieldDescriptions( const Sequence< PropertyValue >& i_rFieldDescriptions ) +{ + OQueryController& rController = static_cast< OQueryController& >( getController() ); + + m_pSelectionBox->PreFill(); + m_pSelectionBox->SetReadOnly( rController.isReadOnly() ); + m_pSelectionBox->Fill(); + + for ( const PropertyValue* field = i_rFieldDescriptions.getConstArray(); + field != i_rFieldDescriptions.getConstArray() + i_rFieldDescriptions.getLength(); + ++field + ) + { + ::vos::ORef< OTableFieldDesc > pField( new OTableFieldDesc() ); + pField->Load( *field, true ); + InsertField( pField, sal_True, sal_False ); + } + + rController.getUndoMgr()->Clear(); + m_pSelectionBox->Invalidate(); +} + // ----------------------------------------------------------------------------- bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo ) { diff --git a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx index 36b7afe6d727..90ff0685e229 100644 --- a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx +++ b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx @@ -208,37 +208,68 @@ OQueryContainerWindow* OQueryViewSwitch::getContainer() const } // ----------------------------------------------------------------------------- -bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) +void OQueryViewSwitch::impl_forceSQLView() { - sal_Bool bRet = sal_True; - sal_Bool bGraphicalDesign = static_cast(m_pDesignView->getController()).isGraphicalDesign(); - OAddTableDlg* pAddTabDialog( getAddTableDialog() ); - OQueryContainerWindow* pContainer = getContainer(); + // hide the "Add Table" dialog + m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false; + if ( m_bAddTableDialogWasVisible ) + pAddTabDialog->Hide(); + + // tell the views they're in/active + m_pDesignView->stopTimer(); + m_pTextView->getSqlEdit()->startTimer(); + + // set the most recent statement at the text view + m_pTextView->clear(); + m_pTextView->setStatement(static_cast(m_pDesignView->getController()).getStatement()); +} + +// ----------------------------------------------------------------------------- +void OQueryViewSwitch::forceInitialView() +{ + OQueryController& rQueryController( static_cast< OQueryController& >( m_pDesignView->getController() ) ); + const sal_Bool bGraphicalDesign = rQueryController.isGraphicalDesign(); if ( !bGraphicalDesign ) + impl_forceSQLView(); + else { - // hide the "Add Table" dialog - m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false; - if ( m_bAddTableDialogWasVisible ) - pAddTabDialog->Hide(); + // tell the text view it's inactive now + m_pTextView->getSqlEdit()->stopTimer(); + + // update the "Add Table" dialog + OAddTableDlg* pAddTabDialog( getAddTableDialog() ); + if ( pAddTabDialog ) + pAddTabDialog->Update(); - // tell the views they're in/active - m_pDesignView->stopTimer(); - m_pTextView->getSqlEdit()->startTimer(); + // initialize the design view + m_pDesignView->initByFieldDescriptions( rQueryController.getFieldInformation() ); - // set the most recent statement at the text view - m_pTextView->clear(); - m_pTextView->setStatement(static_cast(m_pDesignView->getController()).getStatement()); + // tell the design view it's active now + m_pDesignView->startTimer(); + } + + impl_postViewSwitch( bGraphicalDesign, true ); +} + +// ----------------------------------------------------------------------------- +bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) +{ + sal_Bool bRet = sal_True; + sal_Bool bGraphicalDesign = static_cast(m_pDesignView->getController()).isGraphicalDesign(); + + if ( !bGraphicalDesign ) + { + impl_forceSQLView(); } else { // tell the text view it's inactive now m_pTextView->getSqlEdit()->stopTimer(); - ::rtl::OUString sOldStatement = static_cast(m_pDesignView->getController()).getStatement(); - // update the "Add Table" dialog + OAddTableDlg* pAddTabDialog( getAddTableDialog() ); if ( pAddTabDialog ) pAddTabDialog->Update(); @@ -249,24 +280,34 @@ bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) m_pDesignView->startTimer(); } - if ( bRet ) + return impl_postViewSwitch( bGraphicalDesign, bRet ); +} + +// ----------------------------------------------------------------------------- +bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess ) +{ + if ( i_bSuccess ) { - m_pTextView->Show ( !bGraphicalDesign ); - m_pDesignView->Show ( bGraphicalDesign ); - if ( bGraphicalDesign && m_bAddTableDialogWasVisible && pAddTabDialog ) - pAddTabDialog->Show(); + m_pTextView->Show ( !i_bGraphicalDesign ); + m_pDesignView->Show ( i_bGraphicalDesign ); + OAddTableDlg* pAddTabDialog( getAddTableDialog() ); + if ( pAddTabDialog ) + if ( i_bGraphicalDesign && m_bAddTableDialogWasVisible ) + pAddTabDialog->Show(); GrabFocus(); } + OQueryContainerWindow* pContainer = getContainer(); if ( pContainer ) pContainer->Resize(); m_pDesignView->getController().getUndoMgr()->Clear(); m_pDesignView->getController().InvalidateAll(); - return bRet; + return i_bSuccess; } + // ----------------------------------------------------------------------------- OAddTableDlg* OQueryViewSwitch::getAddTableDialog() { diff --git a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx index 4b053661df1b..577f6a0f48ba 100644 --- a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx +++ b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx @@ -97,7 +97,7 @@ OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS ) if (&rRS == this) return *this; - m_vecCriteria = rRS.m_vecCriteria; + m_aCriteria = rRS.GetCriteria(); m_aTableName = rRS.GetTable(); m_aAliasName = rRS.GetAlias(); // table range m_aFieldName = rRS.GetField(); // column @@ -128,7 +128,7 @@ sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc ) m_aFieldName != rDesc.GetField() || m_aTableName != rDesc.GetTable() || m_bGroupBy != rDesc.IsGroupBy() || - m_vecCriteria != rDesc.GetCriteria() || + m_aCriteria != rDesc.GetCriteria() || m_bVisible != rDesc.IsVisible() ); } @@ -137,13 +137,13 @@ sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc ) void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const ::rtl::OUString& rCrit) { DBG_CHKTHIS(OTableFieldDesc,NULL); - if (nIdx < m_vecCriteria.size()) - m_vecCriteria[nIdx] = rCrit; + if (nIdx < m_aCriteria.size()) + m_aCriteria[nIdx] = rCrit; else { - for(sal_Int32 i=m_vecCriteria.size();i aFieldDesc; - _rProperty.Value >>= aFieldDesc; - //if ( aFieldDesc.getLength() == 12 ) + struct SelectPropertyValueAsString : public ::std::unary_function< PropertyValue, ::rtl::OUString > { - sal_Int32 nCount = aFieldDesc.getLength(); - for (sal_Int32 nPos = 0; nPos < nCount; ++nPos) + ::rtl::OUString operator()( const PropertyValue& i_rPropValue ) const { - if ( aFieldDesc[nPos].Name.equalsAscii("AliasName") ) - aFieldDesc[nPos].Value >>= m_aAliasName; - else if ( aFieldDesc[nPos].Name.equalsAscii("TableName") ) - aFieldDesc[nPos].Value >>= m_aTableName; - else if ( aFieldDesc[nPos].Name.equalsAscii("FieldName") ) - aFieldDesc[nPos].Value >>= m_aFieldName; - else if ( aFieldDesc[nPos].Name.equalsAscii("FieldAlias") ) - aFieldDesc[nPos].Value >>= m_aFieldAlias; - else if ( aFieldDesc[nPos].Name.equalsAscii("FunctionName") ) - aFieldDesc[nPos].Value >>= m_aFunctionName; - else if ( aFieldDesc[nPos].Name.equalsAscii("DataType") ) - aFieldDesc[nPos].Value >>= m_eDataType; - else if ( aFieldDesc[nPos].Name.equalsAscii("FunctionType") ) - aFieldDesc[nPos].Value >>= m_eFunctionType; - else if ( aFieldDesc[nPos].Name.equalsAscii("FieldType") ) - { - sal_Int32 nTemp = 0; - aFieldDesc[nPos].Value >>= nTemp; - m_eFieldType = static_cast(nTemp); - } - else if ( aFieldDesc[nPos].Name.equalsAscii("OrderDir") ) - { - sal_Int32 nTemp = 0; - aFieldDesc[nPos].Value >>= nTemp; - m_eOrderDir = static_cast(nTemp); - } - else if ( aFieldDesc[nPos].Name.equalsAscii("ColWidth") ) - aFieldDesc[nPos].Value >>= m_nColWidth; - else if ( aFieldDesc[nPos].Name.equalsAscii("GroupBy") ) - aFieldDesc[nPos].Value >>= m_bGroupBy; - else if ( aFieldDesc[nPos].Name.equalsAscii("Visible") ) - aFieldDesc[nPos].Value >>= m_bVisible; + ::rtl::OUString sValue; + OSL_VERIFY( i_rPropValue.Value >>= sValue ); + return sValue; } + }; +} + +// ----------------------------------------------------------------------------- +void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria ) +{ + DBG_CHKTHIS(OTableFieldDesc,NULL); + + ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value ); + m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName ); + m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName ); + m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName ); + m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias ); + m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName ); + m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType ); + m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType ); + m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth ); + m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy ); + m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible ); + + m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) ); + m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) ); + + if ( i_bIncludingCriteria ) + { + const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) ); + m_aCriteria.resize( aCriteria.getLength() ); + ::std::transform( + aCriteria.getConstArray(), + aCriteria.getConstArray() + aCriteria.getLength(), + m_aCriteria.begin(), + SelectPropertyValueAsString() + ); } } //------------------------------------------------------------------------------ -void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings ) +void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria ) { DBG_CHKTHIS(OTableFieldDesc,NULL); @@ -221,6 +221,25 @@ void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings ) o_rSettings.put( "ColWidth", m_nColWidth ); o_rSettings.put( "GroupBy", m_bGroupBy ); o_rSettings.put( "Visible", m_bVisible ); + + if ( i_bIncludingCriteria ) + { + if ( !m_aCriteria.empty() ) + { + sal_Int32 c = 0; + Sequence< PropertyValue > aCriteria( m_aCriteria.size() ); + for ( ::std::vector< ::rtl::OUString >::const_iterator crit = m_aCriteria.begin(); + crit != m_aCriteria.end(); + ++crit, ++c + ) + { + aCriteria[c].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c ); + aCriteria[c].Value <<= *crit; + } + + o_rSettings.put( "Criteria", aCriteria ); + } + } } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/querydesign/querycontainerwindow.cxx b/dbaccess/source/ui/querydesign/querycontainerwindow.cxx index 785e29bb9a0c..91e85454a399 100644 --- a/dbaccess/source/ui/querydesign/querycontainerwindow.cxx +++ b/dbaccess/source/ui/querydesign/querycontainerwindow.cxx @@ -125,6 +125,12 @@ namespace dbaui return m_pViewSwitch->switchView( _pErrorInfo ); } + // ----------------------------------------------------------------------------- + void OQueryContainerWindow::forceInitialView() + { + return m_pViewSwitch->forceInitialView(); + } + // ----------------------------------------------------------------------------- void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground ) { diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx index aab0703b364c..05bac818cdee 100644 --- a/dbaccess/source/ui/querydesign/querycontroller.cxx +++ b/dbaccess/source/ui/querydesign/querycontroller.cxx @@ -401,6 +401,7 @@ void SAL_CALL OQueryController::getFastPropertyValue( Any& o_rValue, sal_Int32 i { getContainer()->SaveUIConfig(); saveViewSettings( aCurrentDesign, true ); + aCurrentDesign.put( "Statement", m_sStatement ); } else { @@ -858,6 +859,9 @@ void OQueryController::impl_initialize() ::rtl::OUString sCommand; m_nCommandType = CommandType::QUERY; + // + // reading parameters + // // legacy parameters first (later overwritten by regular parameters) ::rtl::OUString sIndependentSQLCommand; if ( rArguments.get_ensureType( "IndependentSQLCommand", sIndependentSQLCommand ) ) @@ -927,6 +931,37 @@ void OQueryController::impl_initialize() m_bGraphicalDesign = false; } + // ................................................................................................................. + // . initial design + bool bForceInitialDesign = false; + Sequence< PropertyValue > aCurrentQueryDesignProps; + aCurrentQueryDesignProps = rArguments.getOrDefault( "CurrentQueryDesign", aCurrentQueryDesignProps ); + + if ( aCurrentQueryDesignProps.getLength() ) + { + ::comphelper::NamedValueCollection aCurrentQueryDesign( aCurrentQueryDesignProps ); + if ( aCurrentQueryDesign.has( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN ) ) + { + aCurrentQueryDesign.get_ensureType( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, m_bGraphicalDesign ); + } + if ( aCurrentQueryDesign.has( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING ) ) + { + aCurrentQueryDesign.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, m_bEscapeProcessing ); + } + if ( aCurrentQueryDesign.has( "Statement" ) ) + { + ::rtl::OUString sStatement; + aCurrentQueryDesign.get_ensureType( "Statement", sStatement ); + aCurrentQueryDesign.remove( "Statement" ); + setStatement_fireEvent( sStatement ); + } + + loadViewSettings( aCurrentQueryDesign ); + + bForceInitialDesign = true; + } + + // if ( !ensureConnected( sal_False ) ) { // we have no connection so what else should we do m_bGraphicalDesign = sal_False; @@ -981,20 +1016,30 @@ void OQueryController::impl_initialize() try { getContainer()->initialize(); - impl_reset(); + impl_reset( bForceInitialDesign ); - bool bAttemptedGraphicalDesign = m_bGraphicalDesign; SQLExceptionInfo aError; - impl_setViewMode( &aError ); + const bool bAttemptedGraphicalDesign = m_bGraphicalDesign; + + if ( bForceInitialDesign ) + { + getContainer()->forceInitialView(); + } + else + { + impl_setViewMode( &aError ); + } + if ( aError.isValid() && bAttemptedGraphicalDesign && !m_bGraphicalDesign ) { + // we tried initializing the graphical view, this failed, and we were automatically switched to SQL + // view => tell this to the user if ( !editingView() ) { impl_showAutoSQLViewError( aError.get() ); } } - getUndoMgr()->Clear(); if ( ( m_bGraphicalDesign ) @@ -1159,7 +1204,7 @@ void OQueryController::reconnect(sal_Bool _bUI) } // ----------------------------------------------------------------------------- -void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includngCriteria ) const +void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includingCriteria ) const { saveTableWindows( o_rViewSettings ); @@ -1172,31 +1217,10 @@ void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_r { if ( !(*field)->IsEmpty() ) { - const ::rtl::OUString sFieldSettingName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Field" ) ) + ::rtl::OUString::valueOf( i ); - aFieldData.clear(); - (*field)->Save( aFieldData ); - - if ( i_includngCriteria ) - { - const ::std::vector< ::rtl::OUString >& rCriteria( (*field)->GetCriteria() ); - if ( !rCriteria.empty() ) - { - sal_Int32 c = 0; - ::comphelper::NamedValueCollection aCriteria; - for ( ::std::vector< ::rtl::OUString >::const_iterator crit = rCriteria.begin(); - crit != rCriteria.end(); - ++crit, ++c - ) - { - const ::rtl::OUString sCritName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c ); - aCriteria.put( sCritName, *crit ); - } - - aFieldData.put( "Criteria", aCriteria.getPropertyValues() ); - } - } + (*field)->Save( aFieldData, i_includingCriteria ); + const ::rtl::OUString sFieldSettingName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Field" ) ) + ::rtl::OUString::valueOf( i ); aAllFieldsData.put( sFieldSettingName, aFieldData.getPropertyValues() ); } } @@ -1206,12 +1230,13 @@ void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_r o_rViewSettings.put( "VisibleRows", m_nVisibleRows ); } // ----------------------------------------------------------------------------- -void OQueryController::loadViewSettings( const Sequence< PropertyValue >& i_rViewData ) +void OQueryController::loadViewSettings( const ::comphelper::NamedValueCollection& o_rViewSettings ) { - const ::comphelper::NamedValueCollection aViewData( i_rViewData ); - m_nSplitPos = aViewData.getOrDefault( "SplitterPosition", m_nSplitPos ); - m_nVisibleRows = aViewData.getOrDefault( "VisibleRows", m_nVisibleRows ); - m_aFieldInformation = aViewData.getOrDefault( "Fields", m_aFieldInformation ); + loadTableWindows( o_rViewSettings ); + + m_nSplitPos = o_rViewSettings.getOrDefault( "SplitterPosition", m_nSplitPos ); + m_nVisibleRows = o_rViewSettings.getOrDefault( "VisibleRows", m_nVisibleRows ); + m_aFieldInformation = o_rViewSettings.getOrDefault( "Fields", m_aFieldInformation ); } // ----------------------------------------------------------------------------- sal_Int32 OQueryController::getColWidth(sal_uInt16 _nColPos) const @@ -1219,7 +1244,7 @@ sal_Int32 OQueryController::getColWidth(sal_uInt16 _nColPos) const if ( _nColPos < m_aFieldInformation.getLength() ) { ::std::auto_ptr pField( new OTableFieldDesc()); - pField->Load(m_aFieldInformation[_nColPos]); + pField->Load( m_aFieldInformation[ _nColPos ], false ); return pField->GetColWidth(); } return 0; @@ -1639,13 +1664,13 @@ short OQueryController::saveModified() return nRet; } // ----------------------------------------------------------------------------- -void OQueryController::impl_reset() +void OQueryController::impl_reset( const bool i_bIgnoreQuerySettings ) { bool bValid = false; Sequence< PropertyValue > aLayoutInformation; // get command from the query if a query name was supplied - if ( !editingCommand() ) + if ( !i_bIgnoreQuerySettings && !editingCommand() ) { if ( m_sName.getLength() ) { @@ -1695,15 +1720,14 @@ void OQueryController::impl_reset() { try { - // load the layoutInformation - loadTableWindows(aLayoutInformation); - loadViewSettings(aLayoutInformation); + loadViewSettings( aLayoutInformation ); } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } } + if ( m_sStatement.getLength() ) { setQueryComposer(); -- cgit From 110b7db42fa69b3d3ec29c629f2f91b6107fa61c Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 15:31:07 +0100 Subject: autorecovery: do the recovery in setCurrentController, not in connectController - this ensures all knittings, in particular between controller and frame, already happened --- .../source/core/dataaccess/databasedocument.cxx | 46 ++++++++++++---------- .../source/core/dataaccess/databasedocument.hxx | 6 ++- 2 files changed, 30 insertions(+), 22 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 61b238d03b69..5bee9849b175 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -145,7 +145,7 @@ bool ViewMonitor::onControllerConnected( const Reference< XController >& _rxCont } //-------------------------------------------------------------------------- -void ViewMonitor::onSetCurrentController( const Reference< XController >& _rxController ) +bool ViewMonitor::onSetCurrentController( const Reference< XController >& _rxController ) { // we interpret this as "loading the document (including UI) is finished", // if and only if this is the controller which was last connected, and it was the @@ -155,6 +155,8 @@ void ViewMonitor::onSetCurrentController( const Reference< XController >& _rxCon // notify the respective events if ( bLoadFinished ) m_rEventNotifier.notifyDocumentEventAsync( m_bIsNewDocument ? "OnNew" : "OnLoad" ); + + return bLoadFinished; } //============================================================ @@ -795,25 +797,6 @@ void SAL_CALL ODatabaseDocument::connectController( const Reference< XController // check/adjust our macro mode. m_pImpl->checkMacrosOnLoading(); - - // check if there are sub components to recover from our document storage - bool bAttemptRecovery = m_bHasBeenRecovered; - if ( !bAttemptRecovery && m_pImpl->getMediaDescriptor().has( "ForceRecovery" ) ) - // do not use getOrDefault, it will throw for invalid types, which is not desired here - m_pImpl->getMediaDescriptor().get( "ForceRecovery" ) >>= bAttemptRecovery; - - if ( !bAttemptRecovery ) - return; - - try - { - DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext ); - aDocRecovery.recoverSubDocuments( m_pImpl->getRootStorage(), _xController ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } } // ----------------------------------------------------------------------------- @@ -900,8 +883,29 @@ void SAL_CALL ODatabaseDocument::setCurrentController( const Reference< XControl m_xCurrentController = _xController; - m_aViewMonitor.onSetCurrentController( _xController ); + if ( !m_aViewMonitor.onSetCurrentController( _xController ) ) + return; + + // check if there are sub components to recover from our document storage + bool bAttemptRecovery = m_bHasBeenRecovered; + if ( !bAttemptRecovery && m_pImpl->getMediaDescriptor().has( "ForceRecovery" ) ) + // do not use getOrDefault, it will throw for invalid types, which is not desired here + m_pImpl->getMediaDescriptor().get( "ForceRecovery" ) >>= bAttemptRecovery; + + if ( !bAttemptRecovery ) + return; + + try + { + DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext ); + aDocRecovery.recoverSubDocuments( m_pImpl->getRootStorage(), _xController ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } + // ----------------------------------------------------------------------------- Reference< XInterface > SAL_CALL ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException) { diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 51eeefbbbc75..a23e78a6a796 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -125,8 +125,12 @@ public: ); /** to be called when a controller is set as current controller + @return + if and only if the controller connection indicates that loading the document is finished. This + is the case if the given controller has previously been connected, and it was the first controller + ever for which this happened. */ - void onSetCurrentController( + bool onSetCurrentController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); -- cgit From c6b2dff376fa217003808e6b001cd9c3eb113f5f Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 15:43:53 +0100 Subject: autorecovery: recover non-document sub compontns hidden, too --- .../source/core/recovery/subcomponentloader.cxx | 45 +++++++++++++++++++--- .../source/core/recovery/subcomponentloader.hxx | 5 +++ .../source/core/recovery/subcomponentrecovery.cxx | 8 ++-- 3 files changed, 50 insertions(+), 8 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/recovery/subcomponentloader.cxx b/dbaccess/source/core/recovery/subcomponentloader.cxx index 53d27bb93d47..5fd120a5009b 100644 --- a/dbaccess/source/core/recovery/subcomponentloader.cxx +++ b/dbaccess/source/core/recovery/subcomponentloader.cxx @@ -59,6 +59,7 @@ namespace dbaccess using ::com::sun::star::ucb::Command; using ::com::sun::star::ucb::XCommandProcessor; using ::com::sun::star::frame::XController2; + using ::com::sun::star::lang::XComponent; /** === end UNO using === **/ //==================================================================== @@ -67,10 +68,18 @@ namespace dbaccess struct DBACCESS_DLLPRIVATE SubComponentLoader_Data { const Reference< XCommandProcessor > xDocDefCommands; + const Reference< XComponent > xNonDocComponent; Reference< XWindow > xAppComponentWindow; SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition ) :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW ) + ,xNonDocComponent() + { + } + + SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent ) + :xDocDefCommands() + ,xNonDocComponent( i_rNonDocumentComponent, UNO_SET_THROW ) { } }; @@ -85,11 +94,21 @@ namespace dbaccess { try { - Command aCommandOpen; - aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) ); - - const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier(); - i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL ); + if ( i_rData.xDocDefCommands.is() ) + { + Command aCommandOpen; + aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) ); + + const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier(); + i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL ); + } + else + { + const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW ); + const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW ); + const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW ); + xWindow->setVisible( sal_True ); + } } catch( const Exception& ) { @@ -117,6 +136,22 @@ namespace dbaccess osl_decrementInterlockedCount( &m_refCount ); } + //-------------------------------------------------------------------- + SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController, + const Reference< XComponent >& i_rNonDocumentComponent ) + :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) ) + { + // add as window listener to the controller's container window, so we get notified when it is shown + Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW ); + m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW ); + + osl_incrementInterlockedCount( &m_refCount ); + { + m_pData->xAppComponentWindow->addWindowListener( this ); + } + osl_decrementInterlockedCount( &m_refCount ); + } + //-------------------------------------------------------------------- SubComponentLoader::~SubComponentLoader() { diff --git a/dbaccess/source/core/recovery/subcomponentloader.hxx b/dbaccess/source/core/recovery/subcomponentloader.hxx index 7efaea016724..f3bec5b6b39e 100644 --- a/dbaccess/source/core/recovery/subcomponentloader.hxx +++ b/dbaccess/source/core/recovery/subcomponentloader.hxx @@ -59,6 +59,11 @@ namespace dbaccess const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandProcessor >& i_rSubDocumentDefinition ); + SubComponentLoader( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rApplicationController, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rNonDocumentComponent + ); + // XWindowListener virtual void SAL_CALL windowResized( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL windowMoved( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.cxx b/dbaccess/source/core/recovery/subcomponentrecovery.cxx index bcfc3131892f..0ae69402faeb 100644 --- a/dbaccess/source/core/recovery/subcomponentrecovery.cxx +++ b/dbaccess/source/core/recovery/subcomponentrecovery.cxx @@ -397,7 +397,6 @@ namespace dbaccess //-------------------------------------------------------------------- void SAL_CALL SettingsDocumentHandler::setDocumentLocator( const Reference< XLocator >& i_Locator ) throw (SAXException, RuntimeException) { - // TODO: place your code here (void)i_Locator; } @@ -645,8 +644,7 @@ namespace dbaccess // then load the query designer ::comphelper::NamedValueCollection aLoadArgs; aLoadArgs.put( "CurrentQueryDesign", aCurrentQueryDesign ); - - // TODO: load the thing hidden, and show when the main doc window is shown + aLoadArgs.put( "Hidden", true ); if ( i_rComponentName.getLength() ) { @@ -671,6 +669,10 @@ namespace dbaccess ); } + Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW ); + Reference< XInterface > xLoader( *new SubComponentLoader( xController, xSubComponent ) ); + (void)xLoader; + return xSubComponent; } -- cgit From b7caadff93f5b147cfa9f63bc056566256641165 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Feb 2010 15:50:45 +0100 Subject: autorecovery: do not show errors when we're recovering the query designer --- dbaccess/source/ui/querydesign/querycontroller.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx index 05bac818cdee..380c8646c5bf 100644 --- a/dbaccess/source/ui/querydesign/querycontroller.cxx +++ b/dbaccess/source/ui/querydesign/querycontroller.cxx @@ -1664,13 +1664,13 @@ short OQueryController::saveModified() return nRet; } // ----------------------------------------------------------------------------- -void OQueryController::impl_reset( const bool i_bIgnoreQuerySettings ) +void OQueryController::impl_reset( const bool i_bForceCurrentControllerSettings ) { bool bValid = false; Sequence< PropertyValue > aLayoutInformation; // get command from the query if a query name was supplied - if ( !i_bIgnoreQuerySettings && !editingCommand() ) + if ( !i_bForceCurrentControllerSettings && !editingCommand() ) { if ( m_sName.getLength() ) { @@ -1751,7 +1751,7 @@ void OQueryController::impl_reset( const bool i_bIgnoreQuerySettings ) m_pSqlIterator->traverseAll(); if ( m_pSqlIterator->hasErrors() ) { - if ( !editingView() ) + if ( !i_bForceCurrentControllerSettings && !editingView() ) { impl_showAutoSQLViewError( makeAny( m_pSqlIterator->getErrors() ) ); } @@ -1760,7 +1760,7 @@ void OQueryController::impl_reset( const bool i_bIgnoreQuerySettings ) } else { - if ( !editingView() ) + if ( !i_bForceCurrentControllerSettings && !editingView() ) { String aTitle(ModuleRes(STR_SVT_SQL_SYNTAX_ERROR)); OSQLMessageBox aDlg(getView(),aTitle,aErrorMsg); -- cgit From d8015eeea723bb718c1506d49359d72091f1147b Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 18 Feb 2010 11:33:14 +0100 Subject: dba33e: #i108128# catch exception when asking for driver --- dbaccess/source/ui/dlg/dbwizsetup.cxx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index a092109efe80..fa1a6f946eee 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -945,8 +945,15 @@ sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() { ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase(); ::connectivity::DriversConfig aDriverConfig(getORB()); + try + { if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() ) sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); + } + catch(const Exception&) + { + sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); + } return sEmbeddedURL; } -- cgit From c7e9a65998c576d118fd57fee698bf518a698022 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 18 Feb 2010 11:35:32 +0100 Subject: autorecovery: unary_function needs -inlude on Mac --- dbaccess/source/ui/querydesign/TableFieldDescription.cxx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx index 577f6a0f48ba..3ecb836692de 100644 --- a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx +++ b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx @@ -42,6 +42,8 @@ #endif #include +#include + using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -- cgit From 1999b46d0941e5590e17a43498f625ab0b89c29c Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 18 Feb 2010 11:38:26 +0100 Subject: autorecovery: oops, this variable needs to be available in a pro-build, too ... --- dbaccess/source/core/dataaccess/ModelImpl.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 1f0d9f337a0b..ef432d88a46b 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -824,8 +824,8 @@ void ODatabaseModelImpl::setResource( const ::rtl::OUString& i_rDocumentURL, con { ENSURE_OR_THROW( i_rDocumentURL.getLength(), "invalid URL" ); -#if OSL_DEBUG_LEVEL > 0 ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs ); +#if OSL_DEBUG_LEVEL > 0 if ( aMediaDescriptor.has( "SalvagedFile" ) ) { ::rtl::OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) ); -- cgit From 2892b4a7f8d53c0329d52551ff6bb50b38311320 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 19 Feb 2010 10:23:50 +0100 Subject: autorecovery: 'using' directive needed to compile on unxsols4 without warning --- dbaccess/source/ui/inc/querycontroller.hxx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx index c119095c28bb..ad50cb4a7ab0 100644 --- a/dbaccess/source/ui/inc/querycontroller.hxx +++ b/dbaccess/source/ui/inc/querycontroller.hxx @@ -253,6 +253,9 @@ namespace dbaui private: DECL_LINK( OnExecuteAddTable, void* ); + + private: + using OQueryController_PBase::getFastPropertyValue; }; } #endif // DBAUI_QUERYCONTROLLER_HXX -- cgit From f134b69089fb4f37f987b28e08f1b9aa48311926 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 19 Feb 2010 11:18:44 +0100 Subject: autorecovery: 'using' directive needed to compile on unxsols4 without warning --- dbaccess/source/core/dataaccess/documentdefinition.hxx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index f488665bfb2c..65368a23f7f6 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -382,6 +382,8 @@ private: const bool _bActivate, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment ); +private: + using ::cppu::OPropertySetHelper::getFastPropertyValue; }; class NameChangeNotifier -- cgit From d28b920406a67449c4e0d5018aa36c6dcf1162f8 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 22 Feb 2010 10:16:39 +0100 Subject: autorecovery: care for recovering a previously unmodified file (where SalvagedFile is empty) --- dbaccess/source/core/dataaccess/databasedocument.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 5bee9849b175..8b1646862029 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -689,7 +689,8 @@ void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_Sourc // by definition (of XDocumentRecovery), we're responsible for delivering a fully-initialized document, // which includes an attachResource call. - impl_attachResource( i_SalvagedFile, aMediaDescriptor.getPropertyValues(), aGuard ); + const ::rtl::OUString sLogicalDocumentURL( i_SalvagedFile.getLength() ? i_SalvagedFile : i_SourceLocation ); + impl_attachResource( sLogicalDocumentURL, aMediaDescriptor.getPropertyValues(), aGuard ); // <- SYNCHRONIZED } catch( const Exception& ) -- cgit From 8dd0c9c3f9bc8e4d0152edfb00294c4227db4555 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Mon, 22 Feb 2010 10:52:01 +0100 Subject: autorecovery: connect: lock SolarMutex before locking own mutex (makes UISettings complex test case run, again) --- dbaccess/source/ui/app/AppControllerGen.cxx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index 53a4440ee321..6df5b2d8ee63 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -374,6 +374,7 @@ Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() // ----------------------------------------------------------------------------- Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException) { + ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->getSubComponents(); } @@ -394,6 +395,7 @@ Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() // ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeException) { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); ::osl::MutexGuard aGuard( getMutex() ); SQLExceptionInfo aError; @@ -432,6 +434,7 @@ beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL OApplicationController::ide // ----------------------------------------------------------------------------- ::sal_Bool SAL_CALL OApplicationController::closeSubComponents( ) throw (RuntimeException) { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->closeSubComponents(); } -- cgit