Tag: cws_src680_dba201d
User: fs      
Date: 05/10/05 03:22:18

Modified:
 /dba/dbaccess/source/ui/app/
  AppController.cxx, AppController.hxx, AppControllerDnD.cxx,
  AppControllerGen.cxx

Log:
 #i55493# flush the connection before disconnecting, if possible / no code 
multiple connections anymore (dead code)

File Changes:

Directory: /dba/dbaccess/source/ui/app/
=======================================

File [changed]: AppController.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppController.cxx?r1=1.22&r2=1.22.2.1
Delta lines:  +86 -131
----------------------
--- AppController.cxx   23 Sep 2005 12:14:21 -0000      1.22
+++ AppController.cxx   5 Oct 2005 10:22:11 -0000       1.22.2.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: AppController.cxx,v $
  *
- *  $Revision: 1.22 $
+ *  $Revision: 1.22.2.1 $
  *
- *  last change: $Author: hr $ $Date: 2005/09/23 12:14:21 $
+ *  last change: $Author: fs $ $Date: 2005/10/05 10:22:11 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -36,12 +36,10 @@
 #ifndef DBAUI_APPCONTROLLER_HXX
 #include "AppController.hxx"
 #endif
-#ifndef _COMPHELPER_SEQUENCE_HXX_
-#include <comphelper/sequence.hxx>
-#endif
 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
 #include "dbustrings.hrc"
 #endif
+/** === begin UNO includes === **/
 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
 #include <com/sun/star/container/XNameContainer.hpp>
 #endif
@@ -97,15 +95,17 @@
 #ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_
 #include <com/sun/star/util/XModifiable.hpp>
 #endif
-#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
-#include <com/sun/star/util/XCloseable.hpp>
-#endif
-#ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
-#include <com/sun/star/sdbcx/XDrop.hpp>
-#endif
 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
 #include <com/sun/star/frame/XStorable.hpp>
 #endif
+#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
+#include <com/sun/star/util/XFlushable.hpp>
+#endif
+/** === end UNO includes === **/
+
 #ifndef _TOOLS_DEBUG_HXX
 #include <tools/debug.hxx>
 #endif
@@ -232,12 +232,12 @@
 #ifndef INCLUDED_SVTOOLS_HISTORYOPTIONS_HXX
 #include <svtools/historyoptions.hxx>
 #endif
-#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
-#include <com/sun/star/frame/FrameSearchFlag.hpp>
-#endif
 #ifndef SVTOOLS_FILENOTATION_HXX_
 #include <svtools/filenotation.hxx>
 #endif
+#ifndef _COMPHELPER_SEQUENCE_HXX_
+#include <comphelper/sequence.hxx>
+#endif
 #ifndef _DBACCESS_SLOTID_HRC_
 #include "dbaccess_slotid.hrc"
 #endif
@@ -353,31 +353,37 @@
 //--------------------------------------------------------------------
 
IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
 
IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
-//-------------------------------------------------------------------------
-void OApplicationController::disconnect(Reference< XConnection >& _xConnection)
-{
-       ::comphelper::disposeComponent( _xConnection );
-       stopConnectionListening(_xConnection);
-
-       InvalidateAll();
-}
 // 
-----------------------------------------------------------------------------
-void OApplicationController::clearConnections()
+void OApplicationController::disconnect()
 {
+    if ( m_xDataSourceConnection.is() )
+           stopConnectionListening( m_xDataSourceConnection );
+
        try
        {
-               TDataSourceConnections::iterator aIter = 
m_aDataSourceConnections.begin();
-               TDataSourceConnections::iterator aEnd = 
m_aDataSourceConnections.end();
-               for (; aIter != aEnd; ++aIter)
-               {
-                       stopConnectionListening(aIter->second);
-                       ::comphelper::disposeComponent(aIter->second);
-               }
+        // temporary (hopefully!) hack for #i55274#
+        Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
+        if ( xFlush.is() )
+            xFlush->flush();
+    }
+    catch( const Exception& e )
+    {
+    #if OSL_DEBUG_LEVEL > 0
+        ::rtl::OString sMessage( "OApplicationController::disconnect: caught 
an exception!\n" );
+        sMessage += "message:\n";
+        sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), 
osl_getThreadTextEncoding() );
+        OSL_ENSURE( false, sMessage );
+    #else
+        e; // make compiler happy
+    #endif
        }
-       catch(Exception)
-       {}
-       m_aDataSourceConnections.clear();
+
+    m_xDataSourceConnection.clear();
+    m_xMetaData.clear();
+
+       InvalidateAll();
 }
+
 //--------------------------------------------------------------------
 void SAL_CALL OApplicationController::disposing()
 {
@@ -395,7 +401,7 @@
                m_pClipbordNotifier = NULL;
        }
 
-       clearConnections();
+       disconnect();
        try
        {
                Reference < XFrame > xFrame;
@@ -497,18 +503,16 @@
        Reference<XConnection> 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?" );
+
                if ( getContainer() && getContainer()->getElementType() == 
E_TABLE )
                {
-                       TDataSourceConnections::iterator aIter = 
m_aDataSourceConnections.begin();
-                       TDataSourceConnections::iterator aEnd = 
m_aDataSourceConnections.end();
-                       for (;aIter != aEnd ; ++aIter)
-                       {
-                               if ( aIter->second.is() && aIter->second == 
xCon )
+            if ( m_xDataSourceConnection == xCon )
                                {
                                        getContainer()->clearPages();
-                    m_aDataSourceConnections.erase(aIter);
-                                       break;
-                               }
+                m_xDataSourceConnection.clear();
+                m_xMetaData.clear();
                        }
                }
        }
@@ -684,7 +688,7 @@
                                aReturn.bEnabled = !isDataSourceReadOnly() && 
!isConnectionReadOnly();
                                if ( aReturn.bEnabled )
                                {
-                                       Reference<XViewsSupplier> 
xViewsSup(getActiveConnection(),UNO_QUERY);
+                                       Reference<XViewsSupplier> xViewsSup( 
getConnection(), UNO_QUERY );
                                        aReturn.bEnabled = xViewsSup.is();
                                }
                                break;
@@ -767,7 +771,7 @@
                                aReturn.bEnabled = !isDataSourceReadOnly();
                                break;
                        case SID_DB_APP_REFRESH_TABLES:
-                               aReturn.bEnabled = 
getContainer()->getElementType() == E_TABLE && getActiveConnection().is();
+                               aReturn.bEnabled = 
getContainer()->getElementType() == E_TABLE && isConnected();
                                break;
                        case SID_DB_APP_DSPROPS:
                                if ( aReturn.bEnabled = m_xDataSource.is() )
@@ -798,8 +802,7 @@
                                        aReturn.bEnabled = eType == E_QUERY && 
getContainer()->getSelectionCount() > 0;
                                        if ( aReturn.bEnabled )
                                        {
-                                               Reference<XConnection> 
xConnection = getActiveConnection();
-                                               Reference<XViewsSupplier> 
xViewSup(xConnection,UNO_QUERY);
+                                               Reference<XViewsSupplier> 
xViewSup( getConnection(), UNO_QUERY );
                                                aReturn.bEnabled = 
xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
                                        }
                                }
@@ -951,15 +954,7 @@
                                        switch( eType )
                                        {
                                                case E_TABLE:
-                            {
-                                Reference<XConnection> xDestConnection;
-                                           ensureConnection(xDestConnection);
-
-                                SharedConnection xConnection( xDestConnection, 
SharedConnection::NoTakeOwnership );
-                                // TODO: migrate ensureConnection to the 
SharedConnection-API
-
-                                m_aTableCopyHelper.pasteTable( aTransferData , 
getDatabaseName(), xConnection );
-                            }
+                            m_aTableCopyHelper.pasteTable( aTransferData , 
getDatabaseName(), ensureConnection() );
                                                        break;
                                                case E_QUERY:
                             if ( 
getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
@@ -1169,8 +1164,7 @@
                        case ID_NEW_VIEW_DESIGN:
                        case SID_DB_NEW_VIEW_SQL:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                    SharedConnection xConnection( ensureConnection() );
                                        if ( xConnection.is() )
                                        {
                                                OQueryDesignAccess 
aHelper(getORB(),sal_True,SID_DB_NEW_VIEW_SQL == _nId );
@@ -1216,20 +1210,18 @@
                                break;
                        case SID_DB_APP_DSRELDESIGN:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                        {
                                                ORelationDesignAccess 
aHelper(getORB());
-                                               Reference< XComponent > 
xComponent(aHelper.create(Reference<XDataSource>(m_xDataSource,UNO_QUERY), 
getActiveConnection()),UNO_QUERY);
+                                               Reference< XComponent > 
xComponent(aHelper.create(Reference<XDataSource>(m_xDataSource,UNO_QUERY), 
xConnection),UNO_QUERY);
                                                
addDocumentListener(xComponent,NULL);
                                        }
                                }
                                break;
                        case SID_DB_APP_DSUSERADMIN:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                                
openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog")));
                                }
@@ -1255,8 +1247,7 @@
                                break;
                        case ID_DIRECT_SQL:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                                openDirectSQLDialog();
                                }
@@ -1444,7 +1435,7 @@
                        switch( eType )
                        {
                                case E_TABLE:
-                                       ensureConnection(xConnection);
+                                       ensureConnection();
                                        break;
                                case E_FORM:
                                case E_REPORT:
@@ -1476,7 +1467,7 @@
                switch( eType )
                {
                        case E_TABLE:
-                               ensureConnection(xConnection);
+                               ensureConnection();
                                break;
                        case E_FORM:
                        case E_REPORT:
@@ -1514,10 +1505,12 @@
                        switch( eType )
                        {
                                case E_TABLE:
-                                       ensureConnection(xConnection);
-                                       if ( xProp.is() && xConnection.is() )
                                        {
-                                               sNewName = 
::dbaui::composeTableName(xConnection->getMetaData(),xProp,sal_False,::dbtools::eInDataManipulation);
+                                       ensureConnection();
+                                       if ( xProp.is() && m_xMetaData.is() )
+                                       {
+                                               sNewName = 
::dbaui::composeTableName(m_xMetaData,xProp,sal_False,::dbtools::eInDataManipulation);
+                                       }
                                        }
                                        break;
                                case E_FORM:
@@ -1580,9 +1573,7 @@
                {
                        try
                        {
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection);
-
+                               SharedConnection xConnection( 
ensureConnection() );
                                if ( xConnection.is() && 
getContainer()->getDetailView() )
                                {
                                        
getContainer()->getDetailView()->createTablesPage(xConnection);
@@ -1631,28 +1622,9 @@
        OSL_ENSURE(_pTree != NULL,"Who called me without a svtreelsiboc! ->GPF 
");
        if ( getContainer() && getContainer()->isLeaf(_pTree->GetHdlEntry()) )
        {
-               ElementType eType = getContainer()->getElementType();
-
-               Reference<XConnection> xConnection;
-               Reference<XDatabaseMetaData> xMetaData;
-               if ( eType == E_TABLE )
-               {
-                       ensureConnection(xConnection);
-                       if ( xConnection.is() )
-                       {
                                try
                                {
-                                       xMetaData = xConnection->getMetaData();
-                               }
-                               catch(const Exception&)
-                               {
-                                       OSL_ENSURE(0,"Exception catched!");
-                               }
-                       }
-               }
-               try
-               {
-                       
openElement(getContainer()->getQualifiedName(_pTree->GetHdlEntry(),xMetaData),eType);
+                       openElement( getContainer()->getQualifiedName( 
_pTree->GetHdlEntry(), m_xMetaData ), getContainer()->getElementType() );
                }
                catch(const Exception&)
                {
@@ -1685,8 +1657,7 @@
                case E_TABLE:
                        {
                                ::std::auto_ptr< ODesignAccess> pDispatcher;
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection);
+                               SharedConnection xConnection( 
ensureConnection() );
                                if ( xConnection.is() )
                                {
                                        Sequence < PropertyValue > aArgs;
@@ -1752,16 +1723,7 @@
                            {
                                    try
                                    {
-                                           Reference< XDatabaseMetaData> 
xMetaData;
-                                           if ( CommandType::TABLE == 
nCommandType )
-                                           {
-                                                   
ensureConnection(xConnection,sal_False);
-
-                                                   if ( xConnection.is() )
-                                                           xMetaData = 
xConnection->getMetaData();
-                                           }
-
-                                           sName = 
getContainer()->getQualifiedName(NULL,xMetaData);
+                                           sName = 
getContainer()->getQualifiedName( NULL, m_xMetaData );
                         OSL_ENSURE( sName.getLength(), 
"OApplicationController::newElementWithPilot: no name given!" );
                                    }
                                    catch(Exception)
@@ -1819,8 +1781,8 @@
                case E_TABLE:
                        {
                                ::std::auto_ptr< ODesignAccess> pDispatcher;
-                               Reference<XConnection> xConnection;
-                               if ( ensureConnection( xConnection ) )
+                               SharedConnection xConnection( 
ensureConnection() );
+                               if ( xConnection.is() )
                                {
                                        if ( _eType == E_TABLE )
                                        {
@@ -1878,7 +1840,6 @@
        {
                if ( xContainer.is() )
                {
-                       Reference<XConnection> xConnection = 
getActiveConnection();
             ::std::auto_ptr<OSaveAsDlg> aDlg;
                        Reference<XRename> xRename;
                        ElementType eType = getContainer()->getElementType();
@@ -1920,7 +1881,8 @@
                                        }
                                        break;
                                case E_TABLE:
-                    if ( !ensureConnection( xConnection, sal_True ) )
+                    ensureConnection();
+                    if ( !getConnection().is() )
                         break;
                     // NO break
                                case E_QUERY:
@@ -1928,10 +1890,10 @@
                                        {
                                                
xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
                         sal_Int32 nCommandType = eType == E_QUERY ? 
CommandType::QUERY : CommandType::TABLE;
+
                                            aDlg.reset( new OSaveAsDlg(
                             getView(), nCommandType, xContainer,
-                            xConnection.is() ? xConnection->getMetaData() : 
Reference< XDatabaseMetaData >(),
-                            xConnection, *aList.begin(), SAD_TITLE_RENAME) );
+                            m_xMetaData, getConnection(), *aList.begin(), 
SAD_TITLE_RENAME) );
                                        }
                                        break;
                        }
@@ -1953,7 +1915,7 @@
                                                                ::rtl::OUString 
sCatalog = aDlg->getCatalog();
                                                                ::rtl::OUString 
sSchema  = aDlg->getSchema();
 
-                                                               
::dbtools::composeTableName(xConnection->getMetaData(),sCatalog,sSchema,sName,sNewName,sal_False,::dbtools::eInTableDefinitions);
+                                                               
::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, sNewName, 
sal_False, ::dbtools::eInTableDefinitions );
                                                        }
                                                        else
                                                                sNewName = 
aDlg->getName();
@@ -1970,8 +1932,8 @@
 
                                                        
xRename->rename(sNewName);
 
-                                                       if ( ! Reference< 
XNameAccess >(xRename,UNO_QUERY).is() )
-                                                               
getContainer()->elementReplaced(getContainer()->getElementType(),sOldName,sNewName,xConnection);
+                                                       if ( !Reference< 
XNameAccess >( xRename, UNO_QUERY ).is() )
+                                                               
getContainer()->elementReplaced( getContainer()->getElementType(), sOldName, 
sNewName, getConnection() );
 
                                                        bTryAgain = sal_False;
                                                }
@@ -2041,8 +2003,7 @@
                             ::rtl::OUString sName = pView->getQualifiedName( 
_pEntry,NULL);
                             if ( pView->isPreviewEnabled() )
                             {
-                                Reference<XConnection> xConnection;
-                                                           
ensureConnection(xConnection);
+                                SharedConnection xConnection( 
ensureConnection() );
                                                            if ( 
xConnection.is() )
                                                                
pView->showPreview(getDatabaseName(),xConnection,sName,sal_False);
                             }
@@ -2051,8 +2012,7 @@
                         break;
                                        case E_TABLE:
                                                {
-                                                       Reference<XConnection> 
xConnection;
-                                                       
ensureConnection(xConnection);
+                            SharedConnection xConnection( ensureConnection() );
                                                        if ( xConnection.is() )
                                                        {
                                                                ::rtl::OUString 
sName = pView->getQualifiedName( _pEntry,xConnection->getMetaData());
@@ -2322,13 +2282,8 @@
        }
        else
        {
-        Reference<XConnection> xDestConnection;         // supports the 
service sdb::connection
-           ensureConnection( xDestConnection);
-
-        SharedConnection xConnection( xDestConnection, 
SharedConnection::NoTakeOwnership );
-        // TODO: migrate ensureConnection to the SharedConnection-API
-
-        if ( xDestConnection.is() && m_aTableCopyHelper.copyTagTable( 
aDroppedData, m_aAsyncDrop, xConnection ) )
+        SharedConnection xConnection( ensureConnection() );
+        if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( 
aDroppedData, m_aAsyncDrop, xConnection ) )
         {
                        // asyncron because we some dialogs and we aren't 
allowed to show them while in D&D
                        m_nAsyncDrop = Application::PostUserEvent(LINK(this, 
OApplicationController, OnAsyncDrop));

File [changed]: AppController.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppController.hxx?r1=1.12&r2=1.12.2.1
Delta lines:  +22 -30
---------------------
--- AppController.hxx   23 Sep 2005 12:14:43 -0000      1.12
+++ AppController.hxx   5 Oct 2005 10:22:12 -0000       1.12.2.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: AppController.hxx,v $
  *
- *  $Revision: 1.12 $
+ *  $Revision: 1.12.2.1 $
  *
- *  last change: $Author: hr $ $Date: 2005/09/23 12:14:43 $
+ *  last change: $Author: fs $ $Date: 2005/10/05 10:22:12 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -87,6 +87,9 @@
 #ifndef DBACCESS_SOURCE_UI_INC_DOCUMENTCONTROLLER_HXX
 #include "documentcontroller.hxx"
 #endif
+#ifndef _DBAUI_COMMON_TYPES_HXX_
+#include "commontypes.hxx"
+#endif
 
 #include <memory>
 
@@ -135,10 +138,12 @@
 
        private:
 
-               DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XConnection >,TDataSourceConnections);
-
         OTableCopyHelper::DropDescriptor                       m_aAsyncDrop;
-               TDataSourceConnections  m_aDataSourceConnections;
+
+        SharedConnection        m_xDataSourceConnection;
+        ::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XDatabaseMetaData >
+                                m_xMetaData;
+
                TransferableDataHelper  m_aSystemClipboard;             // 
content of the clipboard
                ::com::sun::star::uno::Reference< 
::com::sun::star::beans::XPropertySet >   m_xDataSource;
         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
@@ -385,10 +390,6 @@
                */
                sal_Bool suspendDocuments(sal_Bool bSuspend);
 
-               /** disposes all created connections
-               */
-               void clearConnections();
-
                /** add event listener and remember the document
                        @param  _xDocument
                                the new document, may be <NULL/>
@@ -489,31 +490,24 @@
                // XPropertyChangeListener
                virtual void SAL_CALL propertyChange( const 
::com::sun::star::beans::PropertyChangeEvent& evt ) throw 
(::com::sun::star::uno::RuntimeException);
 
-               /** ensures that a connection for the selected data source 
exists
-                       @param  _xConnection
-                               The new connection
-                       @param  _bCreate
-                               If set to <TRUE/> than the connection will be 
created if it doesn't exist.
-            @return
-                <TRUE/> if and only if the conneciton could be established
+               /** retrieves the current connection, creates it if necessary
                */
-               bool ensureConnection(::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XConnection >& _xConnection,sal_Bool _bCreate = 
sal_True);
+               const SharedConnection& ensureConnection();
 
-               /** returns the connection for the currently active data source
-                       @return
-                               The connection for the currently active data 
source
+               /** retrieves the current connection
                */
-               ::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XConnection > getActiveConnection() const;
+        const SharedConnection& getConnection() const { return 
m_xDataSourceConnection; }
+
+        /// determines whether we're currently connected to the database
+        bool isConnected() const { return m_xDataSourceConnection.is(); }
 
+        const ::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XDatabaseMetaData >&
+            getConnectionMetaData() const { return m_xMetaData; }
 
                /** refreshes the tables
                */
                void refreshTables();
 
-               /** closes the connection of the select data source
-               */
-               void closeConnection();
-
                /// @see 
<method>IApplicationElementNotification::onEntryDoubleClick</method>
                virtual void onEntryDoubleClick(SvTreeListBox* _pTree);
                /// @see 
<method>IApplicationElementNotification::onCreationClick</method>
@@ -545,11 +539,9 @@
                virtual void previewChanged( sal_Int32 _nMode);
        protected:
 
-               /** the connection will be disposed and set to NULL
-                       @param  _xConnection
-                               the connection to be disposed
+               /** disconnects from our XConnection, and cleans up this 
connection
                */
-               virtual void            
disconnect(::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XConnection >& _xConnection);
+               virtual void            disconnect();
 
                // late construction
                virtual sal_Bool        Construct(Window* pParent);

File [changed]: AppControllerDnD.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppControllerDnD.cxx?r1=1.12&r2=1.12.2.1
Delta lines:  +32 -66
---------------------
--- AppControllerDnD.cxx        23 Sep 2005 12:14:58 -0000      1.12
+++ AppControllerDnD.cxx        5 Oct 2005 10:22:14 -0000       1.12.2.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: AppControllerDnD.cxx,v $
  *
- *  $Revision: 1.12 $
+ *  $Revision: 1.12.2.1 $
  *
- *  last change: $Author: hr $ $Date: 2005/09/23 12:14:58 $
+ *  last change: $Author: fs $ $Date: 2005/10/05 10:22:14 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -228,8 +228,7 @@
 // 
-----------------------------------------------------------------------------
 void OApplicationController::deleteTables(const ::std::vector< 
::rtl::OUString>& _rList)
 {
-       Reference<XConnection> xConnection;
-       ensureConnection(xConnection);
+    SharedConnection xConnection( ensureConnection() );
 
        Reference<XTablesSupplier> xSup(xConnection,UNO_QUERY);
        OSL_ENSURE(xSup.is(),"OApplicationController::deleteTable: no 
XTablesSuppier!");
@@ -451,43 +450,26 @@
        }
 }
 // 
-----------------------------------------------------------------------------
-Reference<XConnection> OApplicationController::getActiveConnection() const
-{
-       Reference<XConnection> xConnection;
-       if ( getContainer() )
-       {
-               ::rtl::OUString sDataSourceName = getDatabaseName();
-               TDataSourceConnections::const_iterator aFind = 
m_aDataSourceConnections.find(sDataSourceName);
-               if ( aFind != m_aDataSourceConnections.end() )
-                       xConnection = aFind->second;
-       }
-
-       return xConnection;
-}
-// 
-----------------------------------------------------------------------------
-bool OApplicationController::ensureConnection(Reference<XConnection>& 
_xConnection,sal_Bool _bCreate)
+const SharedConnection& OApplicationController::ensureConnection()
 {
        ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
        ::osl::MutexGuard aGuard(m_aMutex);
 
-       ::rtl::OUString sDataSourceName = getDatabaseName();
-       TDataSourceConnections::iterator aFind = 
m_aDataSourceConnections.find(sDataSourceName);
-       if ( aFind == m_aDataSourceConnections.end() )
-               aFind = 
m_aDataSourceConnections.insert(TDataSourceConnections::value_type(sDataSourceName,Reference<XConnection>())).first;
-
-       if ( !aFind->second.is() && _bCreate )
+    if ( !m_xDataSourceConnection.is() )
        {
                WaitObject aWO(getView());
                String sConnectingContext( ModuleRes( 
STR_COULDNOTCONNECT_DATASOURCE ) );
                sConnectingContext.SearchAndReplaceAscii("$name$", 
getStrippedDatabaseName());
 
-               aFind->second = connect(sDataSourceName, sConnectingContext, 
rtl::OUString(), sal_True);
+               m_xDataSourceConnection.reset( connect( getDatabaseName(), 
sConnectingContext, rtl::OUString(), sal_True ) );
+        if ( m_xDataSourceConnection.is() )
+            m_xMetaData = m_xDataSourceConnection->getMetaData();
+
                // otherwise we got a loop when connecting to db throws an error
-//             if ( !aFind->second.is() )
+//             if ( !m_xDataSourceConnection.is() )
 //                     getContainer()->clearSelection();
        }
-       _xConnection = aFind->second;
-    return _xConnection.is();
+    return m_xDataSourceConnection;
 }
 // 
-----------------------------------------------------------------------------
 sal_Bool OApplicationController::isDataSourceReadOnly() const
@@ -499,13 +481,11 @@
 sal_Bool OApplicationController::isConnectionReadOnly() const
 {
        sal_Bool bIsConnectionReadOnly = sal_True;
-       Reference<XConnection> xConnection = getActiveConnection();
-
-       if ( xConnection.is() )
+       if ( m_xMetaData.is() )
        {
                try
                {
-                       bIsConnectionReadOnly = 
xConnection->getMetaData()->isReadOnly();
+                       bIsConnectionReadOnly = m_xMetaData->isReadOnly();
                }
                catch(SQLException&)
                {
@@ -554,11 +534,9 @@
                                break;
                        case E_TABLE:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection,sal_False);
-                                       if ( xConnection.is() )
+                    if ( m_xDataSourceConnection.is() )
                                        {
-                                               Reference<XTablesSupplier> 
xSup(xConnection,UNO_QUERY);
+                                               Reference< XTablesSupplier > 
xSup( getConnection(), UNO_QUERY );
                                                
OSL_ENSURE(xSup.is(),"OApplicationController::getElements: no XTablesSuppier!");
                                                if ( xSup.is() )
                                                        xElements = 
xSup->getTables();
@@ -620,10 +598,8 @@
        Reference< XDatabaseMetaData> xMetaData;
        if ( getContainer()->getElementType() == E_TABLE )
        {
-               Reference<XConnection> xConnection;
-               ensureConnection(xConnection,sal_False);
-               if ( xConnection.is() )
-                       xMetaData = xConnection->getMetaData();
+               if ( m_xDataSourceConnection.is() )
+                       xMetaData = m_xDataSourceConnection->getMetaData();
        }
 
        getContainer()->getSelectionElementNames(_rNames,xMetaData);
@@ -666,16 +642,17 @@
 
        }
 
-       Reference<XConnection> xConnection;
+    SharedConnection xConnection;
     try
     {
-           ensureConnection(xConnection);
+           xConnection = ensureConnection();
     }
        catch(SQLContext& e) { showError(SQLExceptionInfo(e)); }
        catch(SQLWarning& e) { showError(SQLExceptionInfo(e)); }
        catch(SQLException& e) { showError(SQLExceptionInfo(e)); }
        OSL_ENSURE(xNameAccess.is(),"Data source doesn't return a name access 
-> GPF");
-       return ::std::auto_ptr<OLinkedDocumentsAccess>( new 
OLinkedDocumentsAccess(getView(), getORB(), 
xNameAccess,xConnection,getDatabaseName()));
+       return ::std::auto_ptr<OLinkedDocumentsAccess>(
+        new OLinkedDocumentsAccess( getView(), getORB(), xNameAccess, 
xConnection, getDatabaseName() ) );
 }
 // 
-----------------------------------------------------------------------------
 TransferableHelper* OApplicationController::copyObject()
@@ -692,11 +669,9 @@
                        case E_TABLE:
                        case E_QUERY:
                        {
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection,sal_False);
                                Reference< XDatabaseMetaData> xMetaData;
-                               if ( xConnection.is() )
-                                       xMetaData = xConnection->getMetaData();
+                               if ( m_xDataSourceConnection.is() )
+                                       xMetaData = 
m_xDataSourceConnection->getMetaData();
 
                                ::rtl::OUString sName = 
getContainer()->getQualifiedName(NULL,xMetaData);
                 if ( sName.getLength() )
@@ -705,11 +680,11 @@
 
                                    if ( eType == E_TABLE )
                                    {
-                                           pData = new 
ODataClipboard(sDataSource, CommandType::TABLE, sName, xConnection, 
getNumberFormatter(xConnection,getORB()), getORB());
+                                           pData = new 
ODataClipboard(sDataSource, CommandType::TABLE, sName, m_xDataSourceConnection, 
getNumberFormatter(m_xDataSourceConnection,getORB()), getORB());
                                    }
                                    else
                                    {
-                                           pData = new 
ODataClipboard(sDataSource, CommandType::QUERY, sName, 
getNumberFormatter(xConnection,getORB()), getORB());
+                                           pData = new 
ODataClipboard(sDataSource, CommandType::QUERY, sName, 
getNumberFormatter(m_xDataSourceConnection,getORB()), getORB());
                                    }
                 }
                        }
@@ -931,14 +906,10 @@
        // first get the dest connection
        ::osl::MutexGuard aGuard(m_aMutex);
 
-       Reference<XConnection> xDestConnection;  // supports the service 
sdb::connection
-       ensureConnection( xDestConnection);
-       if ( !xDestConnection.is() )
+    SharedConnection xConnection( ensureConnection() );
+       if ( !xConnection.is() )
                return sal_False;
 
-    SharedConnection xConnection( xDestConnection, 
SharedConnection::NoTakeOwnership );
-    // TODO: migrate ensureConnection to the SharedConnection-API
-
     return m_aTableCopyHelper.copyTagTable( _rDesc, _bCheck, xConnection );
 }
 // 
-----------------------------------------------------------------------------
@@ -951,13 +922,8 @@
 
        if ( m_aAsyncDrop.nType == E_TABLE )
        {
-        Reference<XConnection> xDestConnection;         // supports the 
service sdb::connection
-           ensureConnection( xDestConnection);
-
-        SharedConnection xConnection( xDestConnection, 
SharedConnection::NoTakeOwnership );
-        // TODO: migrate ensureConnection to the SharedConnection-API
-
-        if ( xDestConnection.is() )
+        SharedConnection xConnection( ensureConnection() );
+        if ( xConnection.is() )
                    m_aTableCopyHelper.asyncCopyTagTable( m_aAsyncDrop, 
getDatabaseName(), xConnection );
        }
        else

File [changed]: AppControllerGen.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppControllerGen.cxx?r1=1.14&r2=1.14.2.1
Delta lines:  +9 -27
--------------------
--- AppControllerGen.cxx        23 Sep 2005 12:15:14 -0000      1.14
+++ AppControllerGen.cxx        5 Oct 2005 10:22:15 -0000       1.14.2.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: AppControllerGen.cxx,v $
  *
- *  $Revision: 1.14 $
+ *  $Revision: 1.14.2.1 $
  *
- *  last change: $Author: hr $ $Date: 2005/09/23 12:15:14 $
+ *  last change: $Author: fs $ $Date: 2005/10/05 10:22:15 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -155,7 +155,7 @@
 {
        try
        {
-               Reference<XConnection> xConnection = getActiveConnection();
+               SharedConnection xConnection( getConnection() );
                Reference<XQueriesSupplier> xSup(xConnection,UNO_QUERY);
                if ( xSup.is() )
                {
@@ -214,13 +214,7 @@
                        ElementType eType = getContainer()->getElementType();
                        if ( eType == E_TABLE )
             {
-                Reference<XConnection> xDestConnection;
-                ensureConnection(xDestConnection);
-
-                SharedConnection xConnection( xDestConnection, 
SharedConnection::NoTakeOwnership );
-                // TODO: migrate ensureConnection to the SharedConnection-API
-
-                m_aTableCopyHelper.pasteTable( _nFormatId, rClipboard, 
getDatabaseName(), xConnection);
+                m_aTableCopyHelper.pasteTable( _nFormatId, rClipboard, 
getDatabaseName(), ensureConnection() );
             }
                        else
                                paste( 
eType,ODataAccessObjectTransferable::extractObjectDescriptor(rClipboard) );
@@ -246,7 +240,7 @@
                ::osl::MutexGuard aGuard(m_aMutex);
                WaitObject aWO(getView());
 
-        Reference<XConnection> xConnection = getActiveConnection();
+        SharedConnection xConnection( getConnection() );
                Sequence< Any > aArgs(xConnection.is() ? 3 : 2);
 
                Reference< ::com::sun::star::awt::XWindow> xWindow = 
getTopMostContainerWindow();
@@ -272,7 +266,7 @@
                if ( xConnection.is() )
                        aArgs[2] <<= PropertyValue(
                                PROPERTY_ACTIVECONNECTION, 0,
-                               makeAny(xConnection), 
PropertyState_DIRECT_VALUE);
+                               makeAny( xConnection ), 
PropertyState_DIRECT_VALUE);
 
                // create the dialog
                Reference< XExecutableDialog > xAdminDialog;
@@ -294,16 +288,6 @@
        
openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.TableFilterDialog")));
 }
 // 
-----------------------------------------------------------------------------
-void OApplicationController::closeConnection()
-{
-       if ( getContainer() )
-       {
-               TDataSourceConnections::iterator aFind = 
m_aDataSourceConnections.find(getDatabaseName());
-               if ( aFind != m_aDataSourceConnections.end() )
-                       disconnect(aFind->second);
-       }
-}
-// 
-----------------------------------------------------------------------------
 void OApplicationController::refreshTables()
 {
        if ( getContainer() && getContainer()->getDetailView() )
@@ -322,9 +306,7 @@
                }
 
                getContainer()->getDetailView()->clearPages(sal_False);
-               Reference<XConnection> xConnection;
-               ensureConnection(xConnection);
-               getContainer()->getDetailView()->createTablesPage(xConnection);
+               getContainer()->getDetailView()->createTablesPage( 
ensureConnection() );
        }
 }
 // 
-----------------------------------------------------------------------------
@@ -432,7 +414,7 @@
                if ( bClear )
                {
                        ElementType eType = getContainer()->getElementType();
-                       clearConnections();
+                       disconnect();
                        getContainer()->getDetailView()->clearPages(sal_False);
                        getContainer()->changeContainer(E_NONE); // invalidate 
the old selection
                        getContainer()->changeContainer(eType); // reselect the 
current one again




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to