Tag: cws_src680_oj14
User: oj      
Date: 06/01/03 05:18:08

Modified:
 /dba/dbaccess/source/ui/app/
  AppController.cxx

Log:
 RESYNC: (1.22-1.25); FILE MERGED

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.4.1&r2=1.22.4.2
Delta lines:  +91 -138
----------------------
--- AppController.cxx   3 Jan 2006 07:48:56 -0000       1.22.4.1
+++ AppController.cxx   3 Jan 2006 13:18:05 -0000       1.22.4.2
@@ -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
@@ -99,15 +97,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
@@ -234,12 +234,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
@@ -359,31 +359,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()
 {
@@ -401,7 +407,7 @@
                m_pClipbordNotifier = NULL;
        }
 
-       clearConnections();
+       disconnect();
        try
        {
                Reference < XFrame > xFrame;
@@ -503,18 +509,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();
                        }
                }
        }
@@ -691,7 +695,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;
@@ -774,13 +778,13 @@
                                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() )
                                {
                                        DATASOURCE_TYPE eType = 
m_aTypeCollection.getType(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
-                                       aReturn.bEnabled = DST_EMBEDDED != 
eType && DST_MOZILLA != eType && DST_EVOLUTION != eType && DST_OUTLOOK != eType 
&& DST_OUTLOOKEXP != eType;
+                                       aReturn.bEnabled = DST_EMBEDDED != 
eType && DST_MOZILLA != eType && DST_EVOLUTION != eType && DST_KAB != eType && 
DST_OUTLOOK != eType && DST_OUTLOOKEXP != eType;
                                }
                                break;
                        case SID_DB_APP_DSCONNECTION_TYPE:
@@ -794,7 +798,7 @@
                                if ( aReturn.bEnabled = m_xDataSource.is() )
                                {
                                        DATASOURCE_TYPE eType = 
m_aTypeCollection.getType(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
-                                       aReturn.bEnabled = DST_EMBEDDED != 
eType && DST_LDAP != eType && DST_CALC != eType && DST_MOZILLA != eType && 
DST_THUNDERBIRD != eType && DST_EVOLUTION != eType && DST_OUTLOOK != eType && 
DST_OUTLOOKEXP != eType;
+                                       aReturn.bEnabled = DST_EMBEDDED != 
eType && DST_LDAP != eType && DST_CALC != eType && DST_MOZILLA != eType && 
DST_THUNDERBIRD != eType && DST_EVOLUTION != eType && DST_KAB != eType && 
DST_OUTLOOK != eType && DST_OUTLOOKEXP != eType;
                                }
                                break;
                        case SID_DB_APP_CONVERTTOVIEW:
@@ -805,8 +809,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();
                                        }
                                }
@@ -958,15 +961,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) )
@@ -1179,8 +1174,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 );
@@ -1226,20 +1220,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")));
                                }
@@ -1265,8 +1257,7 @@
                                break;
                        case ID_DIRECT_SQL:
                                {
-                                       Reference<XConnection> xConnection;
-                                       ensureConnection(xConnection);
+                                       SharedConnection xConnection( 
ensureConnection() );
                                        if ( xConnection.is() )
                                                openDirectSQLDialog();
                                }
@@ -1449,13 +1440,12 @@
                {
                        ::rtl::OUString sName;
                        _rEvent.Accessor >>= sName;
-                       Reference<XConnection> xConnection;
                        ElementType eType = getElementType(xContainer);
 
                        switch( eType )
                        {
                                case E_TABLE:
-                                       ensureConnection(xConnection);
+                                       ensureConnection();
                                        break;
                                case E_FORM:
                                case E_REPORT:
@@ -1466,7 +1456,7 @@
                                        }
                                        break;
                        }
-                       
getContainer()->elementAdded(eType,sName,_rEvent.Element,xConnection);
+                       
getContainer()->elementAdded(eType,sName,_rEvent.Element,getConnection());
                }
        }
 }
@@ -1482,12 +1472,11 @@
                OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
                ::rtl::OUString sName;
                _rEvent.Accessor >>= sName;
-               Reference<XConnection> xConnection;
                ElementType eType = getElementType(xContainer);
                switch( eType )
                {
                        case E_TABLE:
-                               ensureConnection(xConnection);
+                               ensureConnection();
                                break;
                        case E_FORM:
                        case E_REPORT:
@@ -1500,7 +1489,7 @@
                                }
                                break;
                }
-               getContainer()->elementRemoved(eType,sName,xConnection);
+               getContainer()->elementRemoved(eType,sName,getConnection());
        }
 }
 // 
-----------------------------------------------------------------------------
@@ -1525,10 +1514,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:
@@ -1591,9 +1582,7 @@
                {
                        try
                        {
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection);
-
+                               SharedConnection xConnection( 
ensureConnection() );
                                if ( xConnection.is() && 
getContainer()->getDetailView() )
                                {
                                        
getContainer()->getDetailView()->createTablesPage(xConnection);
@@ -1642,28 +1631,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&)
                {
@@ -1697,8 +1667,7 @@
                case E_TABLE:
                        {
                                ::std::auto_ptr< ODesignAccess> pDispatcher;
-                               Reference<XConnection> xConnection;
-                               ensureConnection(xConnection);
+                               SharedConnection xConnection( 
ensureConnection() );
                                if ( xConnection.is() )
                                {
                                        Sequence < PropertyValue > aArgs;
@@ -1741,7 +1710,7 @@
 // 
-----------------------------------------------------------------------------
 IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
 {
-    ElementType eType = (ElementType)reinterpret_cast< int >( _pType );
+    ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
     newElementWithPilot( eType );
     return 0L;
 }
@@ -1768,16 +1737,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)
@@ -1840,8 +1800,8 @@
                
                        {
                                ::std::auto_ptr< ODesignAccess> pDispatcher;
-                               Reference<XConnection> xConnection;
-                               if ( ensureConnection( xConnection ) )
+                               SharedConnection xConnection( 
ensureConnection() );
+                               if ( xConnection.is() )
                                {
                                        if ( _eType == E_TABLE )
                                        {
@@ -1902,7 +1862,6 @@
        {
                if ( xContainer.is() )
                {
-                       Reference<XConnection> xConnection = 
getActiveConnection();
             ::std::auto_ptr<OSaveAsDlg> aDlg;
                        Reference<XRename> xRename;
                        ElementType eType = getContainer()->getElementType();
@@ -1944,7 +1903,8 @@
                                        }
                                        break;
                                case E_TABLE:
-                    if ( !ensureConnection( xConnection, sal_True ) )
+                    ensureConnection();
+                    if ( !getConnection().is() )
                         break;
                     // NO break
                                case E_QUERY:
@@ -1952,10 +1912,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;
                        }
@@ -1977,7 +1937,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();
@@ -1994,8 +1954,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;
                                                }
@@ -2065,8 +2025,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);
                             }
@@ -2075,8 +2034,7 @@
                         break;
                                        case E_TABLE:
                                                {
-                                                       Reference<XConnection> 
xConnection;
-                                                       
ensureConnection(xConnection);
+                            SharedConnection xConnection( ensureConnection() );
                                                        if ( xConnection.is() )
                                                        {
                                                                ::rtl::OUString 
sName = pView->getQualifiedName( _pEntry,xConnection->getMetaData());
@@ -2346,13 +2304,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));




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

Reply via email to