Tag: cws_src680_dba201b
User: fs      
Date: 05/07/20 03:11:04

Modified:
 /dba/dbaccess/source/ui/browser/
  unodatbr.cxx

Log:
 #i51255# XConnection replaced with SharedConnection

File Changes:

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

File [changed]: unodatbr.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/browser/unodatbr.cxx?r1=1.170.20.2&r2=1.170.20.3
Delta lines:  +152 -162
-----------------------
--- unodatbr.cxx        15 Jul 2005 06:06:56 -0000      1.170.20.2
+++ unodatbr.cxx        20 Jul 2005 10:11:01 -0000      1.170.20.3
@@ -2,9 +2,9 @@
  *
  *     $RCSfile: unodatbr.cxx,v $
  *
- *  $Revision: 1.170.20.2 $
+ *  $Revision: 1.170.20.3 $
  *
- *  last change: $Author: oj $ $Date: 2005/07/15 06:06:56 $
+ *  last change: $Author: fs $ $Date: 2005/07/20 10:11:01 $
  *
  *     The Contents of this file are made available subject to the terms of
  *     either of the following licenses
@@ -110,6 +110,9 @@
 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_
 #include <com/sun/star/sdbcx/XRename.hpp>
 #endif
+#ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
+#include <com/sun/star/sdb/XDocumentDataSource.hpp>
+#endif
 #ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
 #include <com/sun/star/frame/XLayoutManager.hpp>
 #endif
@@ -425,7 +428,6 @@
        ,m_nBorder(1)
     ,m_aTableCopyHelper(this)
     ,m_nAsyncDrop(0)
-       ,m_bOwnConnection(sal_True)
 {
        DBG_CTOR(SbaTableQueryBrowser,NULL);
 }
@@ -599,33 +601,32 @@
                Sequence< Any> aValues(3);
 
                DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
-               OSL_ENSURE(pData,"No user data set at the currently displayed 
entry!");
-               Reference<XPropertySet> xTableProp(pData->xObject,UNO_QUERY);
-               OSL_ENSURE(xTableProp.is(),"No table available!");
+        OSL_ENSURE( pData, "SbaTableQueryBrowser::InitializeForm: No user data 
set at the currently displayed entry!" );
+        OSL_ENSURE( pData->xObjectProperties.is(), 
"SbaTableQueryBrowser::InitializeForm: No table available!" );
 
-               if ( xTableProp.is() )
+               if ( pData->xObjectProperties.is() )
                {
                        sal_Int32 nPos = 0;
                        // is the filter intially applied ?
                        aProperties.getArray()[nPos]    = PROPERTY_APPLYFILTER;
-                       aValues.getArray()[nPos++]              = 
xTableProp->getPropertyValue(PROPERTY_APPLYFILTER);
+                       aValues.getArray()[nPos++]              = 
pData->xObjectProperties->getPropertyValue(PROPERTY_APPLYFILTER);
 
                        // the initial filter
                        aProperties.getArray()[nPos]    = PROPERTY_FILTER;
-                       aValues.getArray()[nPos++]              = 
xTableProp->getPropertyValue(PROPERTY_FILTER);
+                       aValues.getArray()[nPos++]              = 
pData->xObjectProperties->getPropertyValue(PROPERTY_FILTER);
 
-                       if ( 
xTableProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_HAVING_CLAUSE) )
+                       if ( 
pData->xObjectProperties->getPropertySetInfo()->hasPropertyByName(PROPERTY_HAVING_CLAUSE)
 )
                        {
                                aProperties.realloc(aProperties.getLength()+1);
                                aValues.realloc(aValues.getLength()+1);
                                // the initial having clause
                                aProperties.getArray()[nPos]    = 
PROPERTY_HAVING_CLAUSE;
-                               aValues.getArray()[nPos++]              = 
xTableProp->getPropertyValue(PROPERTY_HAVING_CLAUSE);
+                               aValues.getArray()[nPos++]              = 
pData->xObjectProperties->getPropertyValue(PROPERTY_HAVING_CLAUSE);
                        }
 
                        // the initial ordering
                        aProperties.getArray()[nPos]    = PROPERTY_ORDER;
-                       aValues.getArray()[nPos++]              = 
xTableProp->getPropertyValue(PROPERTY_ORDER);
+                       aValues.getArray()[nPos++]              = 
pData->xObjectProperties->getPropertyValue(PROPERTY_ORDER);
 
                        Reference< XMultiPropertySet >  xFormMultiSet(_rxForm, 
UNO_QUERY);
                        xFormMultiSet->setPropertyValues(aProperties, aValues);
@@ -682,8 +683,7 @@
                                Sequence< Any> aValues(7 + ( m_bPreview ? 5 : 0 
));
 
                                DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
-                               Reference<XPropertySet> 
xTableProp(pData->xObject,UNO_QUERY);
-                               
OSL_ENSURE(xTableProp.is(),"SbaTableQueryBrowser::InitializeGridModel: No table 
available!");
+                               OSL_ENSURE( pData->xObjectProperties.is(), 
"SbaTableQueryBrowser::InitializeGridModel: No table available!" );
 
                                ::rtl::OUString* pStringIter = 
aProperties.getArray();
                                Any* pValueIter = aValues.getArray();
@@ -696,11 +696,11 @@
                                }
 
                                *pStringIter++  = PROPERTY_FONT;
-                               *pValueIter++   = 
xTableProp->getPropertyValue(PROPERTY_FONT);
+                               *pValueIter++   = 
pData->xObjectProperties->getPropertyValue(PROPERTY_FONT);
                                *pStringIter++  = PROPERTY_TEXTEMPHASIS;
-                               *pValueIter++   = 
xTableProp->getPropertyValue(PROPERTY_TEXTEMPHASIS);
+                               *pValueIter++   = 
pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTEMPHASIS);
                                *pStringIter++  = PROPERTY_TEXTRELIEF;
-                               *pValueIter++   = 
xTableProp->getPropertyValue(PROPERTY_TEXTRELIEF);
+                               *pValueIter++   = 
pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTRELIEF);
                                if ( m_bPreview )
                                {
                                        *pStringIter++  = 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
@@ -709,16 +709,16 @@
                                        *pValueIter++           <<= sal_False;
                                }
                                *pStringIter++  = PROPERTY_ROW_HEIGHT;
-                               *pValueIter++   = 
xTableProp->getPropertyValue(PROPERTY_ROW_HEIGHT);
+                               *pValueIter++   = 
pData->xObjectProperties->getPropertyValue(PROPERTY_ROW_HEIGHT);
                                if ( m_bPreview )
                                {
                                        *pStringIter++  = 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
                                        *pValueIter++           <<= sal_False;
                                }
                                *pStringIter++  = PROPERTY_TEXTCOLOR;
-                               *pValueIter++   = 
xTableProp->getPropertyValue(PROPERTY_TEXTCOLOR);
+                               *pValueIter++   = 
pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTCOLOR);
                                *pStringIter++  = PROPERTY_TEXTLINECOLOR;
-                               *pValueIter++   = 
xTableProp->getPropertyValue(PROPERTY_TEXTLINECOLOR);
+                               *pValueIter++   = 
pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTLINECOLOR);
 
                                Reference< XMultiPropertySet >  
xFormMultiSet(xGrid, UNO_QUERY);
                                xFormMultiSet->setPropertyValues(aProperties, 
aValues);
@@ -730,7 +730,7 @@
 
                        Reference<XConnection> xConnection;
                        Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
-                       
::cppu::extractInterface(xConnection,xProp->getPropertyValue(PROPERTY_ACTIVECONNECTION));
+            xProp->getPropertyValue( PROPERTY_ACTIVECONNECTION ) >>= 
xConnection;
                        OSL_ENSURE(xConnection.is(),"A ActiveConnection should 
normaly exists!");
 
                        Reference<XChild> xChild(xConnection,UNO_QUERY);
@@ -859,7 +859,7 @@
        if(_pCurrentlyDisplayed)
        {
                DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(_pCurrentlyDisplayed->GetUserData());
-               Reference<XColumnsSupplier> 
xColumnsSup(pData->xObject,UNO_QUERY);
+               Reference<XColumnsSupplier> 
xColumnsSup(pData->xObjectProperties,UNO_QUERY);
                Reference<XNameAccess> xNames = xColumnsSup->getColumns();
                ::rtl::OUString aName;
                _rxSource->getPropertyValue(PROPERTY_NAME) >>= aName;
@@ -875,7 +875,7 @@
        if(m_pCurrentlyDisplayed)
        {
                DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
-               Reference< XPropertySet > xProp(pData->xObject, UNO_QUERY);
+               Reference< XPropertySet > xProp(pData->xObjectProperties, 
UNO_QUERY);
                
OSL_ENSURE(xProp.is(),"SbaTableQueryBrowser::transferChangedControlProperty: no 
table/query object!");
                if (xProp.is())
                        xProp->setPropertyValue(_rProperty, _rNewValue);
@@ -960,14 +960,13 @@
                        if(m_pCurrentlyDisplayed)
                        {
                                DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
-                               Reference<XPropertySet> 
xProp(pData->xObject,UNO_QUERY);
-                               OSL_ENSURE(xProp.is(),"No table available!");
+                               OSL_ENSURE( pData->xObjectProperties.is(), "No 
table available!" );
 
                                sal_Bool bDefault = !evt.NewValue.hasValue();
                                if (bDefault)
-                                       
xProp->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny((sal_Int32)45));
+                                       
pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny((sal_Int32)45));
                                else
-                                       
xProp->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue);
+                                       
pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue);
                        }
                }
 
@@ -1064,7 +1063,7 @@
 {
        SvLBoxEntry* pDataSourceEntry = NULL;
        SvLBoxEntry* pContainerEntry = NULL;
-       SvLBoxEntry* pObjectEntry = getObjectEntry(m_aDocumentDataSource, 
&pDataSourceEntry, &pContainerEntry, sal_False);
+       SvLBoxEntry* pObjectEntry = getObjectEntry( m_aDocumentDataSource, 
&pDataSourceEntry, &pContainerEntry, sal_False );
        sal_Bool bKnownDocDataSource = (NULL != pObjectEntry);
        if (!bKnownDocDataSource)
        {
@@ -1158,9 +1157,8 @@
 
 // -------------------------------------------------------------------------
 SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& 
_rDataSource, const ::rtl::OUString& _rCommand, sal_Int32 _nCommandType,
-               SvLBoxEntry** _ppDataSourceEntry, SvLBoxEntry** 
_ppContainerEntry,
-               sal_Bool _bExpandAncestors
-               ,const Reference<XConnection>& _rxConnection)
+               SvLBoxEntry** _ppDataSourceEntry, SvLBoxEntry** 
_ppContainerEntry, sal_Bool _bExpandAncestors,
+        const SharedConnection& _rxConnection )
 {
        if (_ppDataSourceEntry)
                *_ppDataSourceEntry = NULL;
@@ -1186,7 +1184,7 @@
                        // add new entries to the list box model
                                Image a, b, c;  // not interested in  reusing 
them
                                String e, f;
-                               implAddDatasource( _rDataSource, a, e, b, f, c 
,_rxConnection);
+                               implAddDatasource( _rDataSource, a, e, b, f, c, 
_rxConnection );
                                pDataSource = 
m_pTreeView->getListBox()->GetEntryPosByName( sDisplayName, NULL, &aFilter );
                 DBG_ASSERT( pDataSource, 
"SbaTableQueryBrowser::getObjectEntry: hmm - did not find it again!" );
                        }
@@ -1243,7 +1241,7 @@
        sal_Bool bEscapeProcessing = sal_True;
        extractDescriptorProps(_rDescriptor, sDataSource, sCommand, 
nCommandType, bEscapeProcessing);
 
-       return getObjectEntry(sDataSource, sCommand, nCommandType, 
_ppDataSourceEntry, _ppContainerEntry, _bExpandAncestors);
+       return getObjectEntry( sDataSource, sCommand, nCommandType, 
_ppDataSourceEntry, _ppContainerEntry, _bExpandAncestors, SharedConnection() );
 }
 
 // -------------------------------------------------------------------------
@@ -1379,10 +1377,10 @@
                                while (pDSLoop)
                                {
                                        DBTreeListModel::DBTreeListUserData* 
pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pDSLoop->GetUserData());
-                                       if(pData && pData->xObject == xCon)
+                                       if ( pData && pData->xConnection == 
xCon )
                                        {
                                                // we set the conenction to 
null to avoid a second disposing of the connection
-                                               pData->xObject = NULL;
+                                               pData->xConnection.clear();
                                                
closeConnection(pDSLoop,sal_False);
                                                break;
                                        }
@@ -2003,8 +2001,8 @@
 }
 // -------------------------------------------------------------------------
 void SbaTableQueryBrowser::implAddDatasource(const String& _rDbName, Image& 
_rDbImage,
-               String& _rQueryName, Image& _rQueryImage, String& _rTableName, 
Image& _rTableImage
-               ,const Reference<XConnection>& _rxConnection)
+               String& _rQueryName, Image& _rQueryImage, String& _rTableName, 
Image& _rTableImage,
+        const SharedConnection& _rxConnection)
 {
        vos::OGuard aGuard( Application::GetSolarMutex() );
        // initialize the names/images if necessary
@@ -2031,7 +2029,9 @@
        DBTreeListModel::DBTreeListUserData* pDSData = new 
DBTreeListModel::DBTreeListUserData;
        pDSData->eType = etDatasource;
     pDSData->sAccessor = sDataSourceId;
-       pDSData->xObject = _rxConnection;
+       pDSData->xConnection = _rxConnection;
+    if ( _rxConnection.is() )
+        pDSData->aController.swap( ModelControllerConnector( 
impl_nf_getDBDocumentForConnection( _rxConnection ), this ) );
        pDatasourceEntry->SetUserData(pDSData);
 
        // the child for the queries container
@@ -2064,7 +2064,7 @@
                const ::rtl::OUString* pIter    = aDatasources.getConstArray();
                const ::rtl::OUString* pEnd     = pIter + 
aDatasources.getLength();
                for (; pIter != pEnd; ++pIter)
-                       implAddDatasource(*pIter, aDBImage, sQueriesName, 
aQueriesImage, sTablesName, aTablesImage,NULL);
+                       implAddDatasource( *pIter, aDBImage, sQueriesName, 
aQueriesImage, sTablesName, aTablesImage, SharedConnection() );
        }
 }
 // -------------------------------------------------------------------------
@@ -2074,7 +2074,7 @@
 {
        DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(_pParent->GetUserData());
        if(pData) // don't ask if the nameaccess is already set see 
OnExpandEntry views and tables
-               pData->xObject = _xNameAccess;
+               pData->xContainer = _xNameAccess;
 
        ModuleRes 
aResId(DBTreeListModel::getImageResId(_rEntryType,isHiContrast()));
        Image aImage(aResId);
@@ -2123,7 +2123,7 @@
                WaitObject aWaitCursor(getBrowserView());
 
                // it could be that we already have a connection
-               Reference<XConnection> xConnection;
+        SharedConnection xConnection;
                ensureConnection( pFirstParent, xConnection );
 
                if ( xConnection.is() )
@@ -2195,8 +2195,9 @@
        {       // we have to expand the queries or bookmarks
                if (ensureEntryObject(_pParent))
                {
-                       Reference< XNameAccess > xCollection(static_cast< 
DBTreeListModel::DBTreeListUserData* >(_pParent->GetUserData())->xObject, 
UNO_QUERY);
-                       populateTree(xCollection, _pParent, etQuery );
+            DBTreeListModel::DBTreeListUserData* pData = static_cast< 
DBTreeListModel::DBTreeListUserData* >( _pParent->GetUserData() );
+                       Reference< XNameAccess > xCollection( 
pData->xContainer, UNO_QUERY );
+                       populateTree( xCollection, _pParent, etQuery );
                }
        }
        return 1L;
@@ -2215,15 +2216,19 @@
        DBTreeListModel::DBTreeListUserData* pEntryData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(_pEntry->GetUserData());
        OSL_ENSURE(pEntryData,"ensureEntryObject: user data should already be 
set!");
 
-       if (pEntryData->xObject.is())
-               // nothing to do
-               return sal_True;
-
        SvLBoxEntry* pDataSourceEntry = 
m_pTreeView->getListBox()->GetRootLevelParent(_pEntry);
+
+    sal_Bool bSuccess = sal_False;
        switch (eType)
        {
                case etQueryContainer:
+               if ( pEntryData->xContainer.is() )
                {
+                       // nothing to do
+                bSuccess = sal_True;
+                break;
+            }
+
                        try
                        {
                                Reference< XQueryDefinitionsSupplier > 
xQuerySup;
@@ -2236,7 +2241,8 @@
                                                // add as listener to get 
notified if elements are inserted or removed
                                                
xCont->addContainerListener(this);
 
-                                       pEntryData->xObject = xQueryDefs;
+                                       pEntryData->xContainer = xQueryDefs;
+                    bSuccess = pEntryData->xContainer.is();
                                }
                                else
                                        
DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no 
XQueryDefinitionsSupplier interface!");
@@ -2245,7 +2251,6 @@
                        {
                                
DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: caught an exception while 
retrieving the queries container!");
                        }
-               }
                break;
 
                default:
@@ -2254,7 +2259,7 @@
                        break;
        }
 
-       return pEntryData->xObject.is();
+       return bSuccess;
 }
 
//------------------------------------------------------------------------------
 IMPL_LINK(SbaTableQueryBrowser, OnEntryDoubleClicked, SvLBoxEntry*, _pEntry)
@@ -2280,12 +2285,12 @@
        extractDescriptorProps(_rDescriptor, sDataSource, sCommand, 
nCommandType, bEscapeProcessing);
 
        // select it
-       return implSelect(sDataSource, sCommand, nCommandType, 
bEscapeProcessing,NULL,_bSelectDirect);
+       return implSelect( sDataSource, sCommand, nCommandType, 
bEscapeProcessing, SharedConnection(), _bSelectDirect );
 }
 
 
//------------------------------------------------------------------------------
 sal_Bool SbaTableQueryBrowser::implLoadAnything(const ::rtl::OUString& 
_rDataSourceName, const ::rtl::OUString& _rCommand,
-       const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing, const 
Reference< XConnection>& _rxConnection)
+       const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing, const 
SharedConnection& _rxConnection)
 {
        Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
        if(xProp.is())
@@ -2296,7 +2301,7 @@
                        // the values allowing the RowSet to re-execute
                        xProp->setPropertyValue(PROPERTY_DATASOURCENAME, 
makeAny(_rDataSourceName));
                        if(_rxConnection.is())
-                               
xProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,makeAny(_rxConnection));
+                               xProp->setPropertyValue( 
PROPERTY_ACTIVECONNECTION, makeAny( _rxConnection.getTyped() ) );
 
                                // set this _before_ setting the connection, 
else the rowset would rebuild it ...
                        xProp->setPropertyValue(PROPERTY_COMMANDTYPE, 
makeAny(_nCommandType));
@@ -2365,14 +2370,14 @@
 
//------------------------------------------------------------------------------
 sal_Bool SbaTableQueryBrowser::implSelect(const ::rtl::OUString& 
_rDataSourceName, const ::rtl::OUString& _rCommand,
                                                                          const 
sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing,
-                                                                         const 
Reference<XConnection>& _rxConnection
+                                                                         const 
SharedConnection& _rxConnection
                                                                          
,sal_Bool _bSelectDirect)
 {
        if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != 
_nCommandType))
        {
                SvLBoxEntry* pDataSource = NULL;
                SvLBoxEntry* pCommandType = NULL;
-               SvLBoxEntry* pCommand = getObjectEntry(_rDataSourceName, 
_rCommand, _nCommandType, &pDataSource, &pCommandType, sal_True,_rxConnection);
+               SvLBoxEntry* pCommand = getObjectEntry( _rDataSourceName, 
_rCommand, _nCommandType, &pDataSource, &pCommandType, sal_True, _rxConnection 
);
 
                //      if (pDataSource) // OJ change for the new app
                {
@@ -2444,13 +2449,14 @@
        OSL_ENSURE(pString,"There must be a string item!");
        ::rtl::OUString aName(pString->GetText().GetBuffer());
 
-       Reference<XConnection> xConnection(pConData->xObject,UNO_QUERY);
        sal_Int32 nCommandType =        ( etTableContainer == 
pContainerData->eType)
                                                        ?       
CommandType::TABLE
                                                        :       
CommandType::QUERY;
 
        // check if need to rebuild the rowset
-       sal_Bool bRebuild = xOldConnection != xConnection || nOldType != 
nCommandType || aName != aOldName;
+       sal_Bool bRebuild = ( xOldConnection != pConData->xConnection )
+                     || ( nOldType != nCommandType )
+                     || ( aName != aOldName );
 
        Reference< ::com::sun::star::form::XLoadable >  xLoadable = 
getLoadable();
        bRebuild |= !xLoadable->isLoaded();
@@ -2470,9 +2476,9 @@
                        selectPath(m_pCurrentlyDisplayed, sal_True);
 
                        // get the name of the data source currently selected
-                       ensureConnection( m_pCurrentlyDisplayed, xConnection );
+                       ensureConnection( m_pCurrentlyDisplayed, 
pConData->xConnection );
 
-                       if(!xConnection.is())
+                       if ( !pConData->xConnection.is() )
                        {
                                unloadAndCleanup(sal_False,sal_False);
                                return 0L;
@@ -2484,21 +2490,21 @@
                                case CommandType::TABLE:
                                        {
                                                // only for tables
-                                               
if(!pContainerData->xObject.is())
+                                               if ( 
!pContainerData->xContainer.is() )
                                                {
-                                                       
Reference<XTablesSupplier> xSup(xConnection,UNO_QUERY);
+                                                       
Reference<XTablesSupplier> xSup( pConData->xConnection, UNO_QUERY );
                                                        if(xSup.is())
                                                                xNameAccess = 
xSup->getTables();
 
-                                                       pContainerData->xObject 
= xNameAccess;
+                                                       
pContainerData->xContainer = xNameAccess;
                                                }
                                                else
-                                                       
xNameAccess.set(pContainerData->xObject,UNO_QUERY);
+                                                       xNameAccess.set( 
pContainerData->xContainer, UNO_QUERY );
                                        }
                                        break;
                                case CommandType::QUERY:
                                        {
-                                               Reference<XQueriesSupplier> 
xSup(xConnection,UNO_QUERY);
+                                               Reference<XQueriesSupplier> 
xSup( pConData->xConnection, UNO_QUERY );
                                                if(xSup.is())
                                                        xNameAccess = 
xSup->getQueries();
                                        }
@@ -2511,19 +2517,19 @@
                        if(xNameAccess.is() && xNameAccess->hasByName(aName))
                        {
                                DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(_pEntry->GetUserData());
-                               if(!pData->xObject.is())
+                               if ( !pData->xObjectProperties.is() )
                                {
                                        Reference<XInterface> xObject;
                                        if(xNameAccess->getByName(aName) >>= 
xObject) // remember the table or query object
                                        {
-                                               pData->xObject = xObject;
+                                               pData->xObjectProperties = 
pData->xObjectProperties.query( xObject );
                                                // if the query contains a 
parameterized statement and preview is enabled we won't get any data.
                                                if ( m_bPreview && nCommandType 
== CommandType::QUERY && xObject.is() )
                                                {
                                                        ::rtl::OUString sSql;
                                                        Reference<XPropertySet> 
xProp(xObject,UNO_QUERY);
                                                        
xProp->getPropertyValue(PROPERTY_COMMAND) >>= sSql;
-                                                       Reference< 
XMultiServiceFactory >  xFactory(xConnection, UNO_QUERY);
+                                                       Reference< 
XMultiServiceFactory >  xFactory( pConData->xConnection, UNO_QUERY );
                                                        if (xFactory.is())
                                                        {
                                                                try
@@ -2557,7 +2563,7 @@
                        }
 
                        String sDataSourceName( getDataSourceAcessor( 
pConnection ) );
-                       if ( implLoadAnything( sDataSourceName, aName, 
nCommandType, sal_True, xConnection ) )
+                       if ( implLoadAnything( sDataSourceName, aName, 
nCommandType, sal_True, pConData->xConnection ) )
                                // set the title of the beamer
                                updateTitle();
                        else
@@ -2605,12 +2611,12 @@
                {
                        pContainer      = pListBox->GetEntry(pDSLoop, 
CONTAINER_QUERIES);
                        DBTreeListModel::DBTreeListUserData* pQueriesData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pContainer->GetUserData());
-                       if(pQueriesData && pQueriesData->xObject.get() == 
_rxNameAccess.get())
+                       if ( pQueriesData && pQueriesData->xContainer == 
_rxNameAccess )
                                break;
 
                        pContainer      = pListBox->GetEntry(pDSLoop, 
CONTAINER_TABLES);
                        DBTreeListModel::DBTreeListUserData* pTablesData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pContainer->GetUserData());
-                       if(pTablesData && pTablesData->xObject.get() == 
_rxNameAccess.get())
+                       if ( pTablesData && pTablesData->xContainer == 
_rxNameAccess )
                                break;
 
                        pDSLoop         = pListBox->NextSibling(pDSLoop);
@@ -2642,12 +2648,11 @@
                        // only insert userdata when we have a table because 
the query is only a commanddefinition object and not a query
                        DBTreeListModel::DBTreeListUserData* pNewData = new 
DBTreeListModel::DBTreeListUserData;
 
-                       _rEvent.Element >>= pNewData->xObject;// remember the 
new element
+                       _rEvent.Element >>= pNewData->xObjectProperties;// 
remember the new element
                        // now we have to check which type we have here
-                       Reference<XPropertySet> 
xProp(pNewData->xObject,UNO_QUERY);
                        ::rtl::OUString sType;
-                       
if(xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_TYPE))
-                               xProp->getPropertyValue(PROPERTY_TYPE) >>= 
sType;
+                       if ( 
pNewData->xObjectProperties->getPropertySetInfo()->hasPropertyByName( 
PROPERTY_TYPE ) )
+                               
pNewData->xObjectProperties->getPropertyValue(PROPERTY_TYPE) >>= sType;
                        if(sType.getLength() && sType == 
::rtl::OUString::createFromAscii("VIEW"))
                                pNewData->eType = etView;
                        else
@@ -2675,7 +2680,7 @@
                        else
                        {
                                DBTreeListModel::DBTreeListUserData* pNewData = 
new DBTreeListModel::DBTreeListUserData;
-                               //      _rEvent.Element >>= 
pNewData->xObject;// remember the new element
+                               //      _rEvent.Element >>= 
pNewData->xObjectProperties;// remember the new element
                                pNewData->eType = etQuery;
 
                                sal_uInt16 nImageResId = 
DBTreeListModel::getImageResId(pNewData->eType,isHiContrast());
@@ -2699,7 +2704,7 @@
                // add new entries to the list box model
                Image a, b, c;  // not interested in  reusing them
                String e, f;
-               implAddDatasource(sNewDS, a, e, b, f, c,NULL);
+               implAddDatasource( sNewDS, a, e, b, f, c, SharedConnection() );
        }
        else
                SbaXDataBrowserController::elementInserted(_rEvent);
@@ -2845,7 +2850,7 @@
                        {
                                if (etTable == pData->eType || etView == 
pData->eType)
                                { // only insert userdata when we have a table 
because the query is only a commanddefinition object and not a query
-                                        _rEvent.Element >>= pData->xObject;// 
remember the new element
+                                        _rEvent.Element >>= 
pData->xObjectProperties;  // remember the new element
                                }
                                else
                                {
@@ -2867,7 +2872,7 @@
                                        {
                                                if (etTable == pData->eType || 
etView == pData->eType)
                                                { // only insert userdata when 
we have a table because the query is only a commanddefinition object and not a 
query
-                                                       _rEvent.Element >>= 
pData->xObject;// remember the new element
+                                                       _rEvent.Element >>= 
pData->xObjectProperties;   // remember the new element
                                                }
                                                else
                                                {
@@ -2898,15 +2903,15 @@
 void SbaTableQueryBrowser::disposeConnection( SvLBoxEntry* _pDSEntry )
 {
        DBG_ASSERT( _pDSEntry, "SbaTableQueryBrowser::disposeConnection: 
invalid entry (NULL)!" );
-       OSL_ENSURE( m_pTreeView->getListBox()->GetRootLevelParent( _pDSEntry ) 
== _pDSEntry, "SbaTableQueryBrowser::disposeConnection: invalid entry (not 
top-level)!" );
+       DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), 
"SbaTableQueryBrowser::disposeConnection: invalid entry (not top-level)!" );
 
        if ( _pDSEntry )
        {
-               DBTreeListModel::DBTreeListUserData* pData = static_cast< 
DBTreeListModel::DBTreeListUserData* >( _pDSEntry->GetUserData() );
-               if ( pData )
+               DBTreeListModel::DBTreeListUserData* pTreeListData = 
static_cast< DBTreeListModel::DBTreeListUserData* >( _pDSEntry->GetUserData() );
+               if ( pTreeListData )
                {
                        // remove as event listener
-                       Reference< XComponent > xComponent( pData->xObject, 
UNO_QUERY );
+                       Reference< XComponent > xComponent( 
pTreeListData->xConnection, UNO_QUERY );
                        if ( xComponent.is() )
                        {
                                Reference< XEventListener > xListener( 
static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY );
@@ -2914,13 +2919,16 @@
                        }
 
                        // dispose
-            Reference< XModel > 
xModel(getDataSourceOrModel(::dbtools::findDataSource(pData->xObject)),UNO_QUERY);
-                       ::comphelper::disposeComponent( pData->xObject );
-            if ( xModel.is() )
-                xModel->disconnectController(this);
+            pTreeListData->xConnection.clear();
+                // will implicitly dispose, since xConnection is a 
SharedConnection
+
+            // release the model-controller-connection
+            DBG_ASSERT( !pTreeListData->aController.empty(),
+                "SbaTableQueryBrowser::disposeConnection: there's a 
connection, but we didn't register ourself as controller at the model?!" );
+            pTreeListData->aController.swap( ModelControllerConnector() );
 
                        // clear
-                       pData->xObject.clear();
+                       pTreeListData->xConnection.clear();
                }
        }
 }
@@ -2929,7 +2937,7 @@
 void SbaTableQueryBrowser::closeConnection(SvLBoxEntry* _pDSEntry,sal_Bool 
_bDisposeConnection)
 {
        DBG_ASSERT(_pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid 
entry (NULL)!");
-       OSL_ENSURE(m_pTreeView->getListBox()->GetRootLevelParent(_pDSEntry) == 
_pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid entry (not 
top-level)!");
+       OSL_ENSURE( impl_isDataSourceEntry( _pDSEntry ), 
"SbaTableQueryBrowser::closeConnection: invalid entry (not top-level)!");
 
        // if one of the entries of the given DS is displayed currently, unload 
the form
        if (m_pCurrentlyDisplayed && 
(m_pTreeView->getListBox()->GetRootLevelParent(m_pCurrentlyDisplayed) == 
_pDSEntry))
@@ -3033,7 +3041,7 @@
        // first initialize the parent
        SbaXDataBrowserController::impl_initialize( aArguments );
 
-       Reference<XConnection> xConnection;
+       Reference<XConnection> xForeignConnection;
        Reference< XFrame > xFrame;
 
        PropertyValue aValue;
@@ -3070,7 +3078,7 @@
         }
                else if (0 == 
aValue.Name.compareToAscii(PROPERTY_ACTIVECONNECTION))
         {
-            if ( !(aValue.Value >>= xConnection) )
+            if ( !(aValue.Value >>= xForeignConnection) )
                 throw 
Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid argument type 
for ActiveConnection.")),*this);
         }
                else if (0 == 
aValue.Name.compareToAscii(PROPERTY_UPDATE_CATALOGNAME))
@@ -3189,13 +3197,12 @@
                Reference<XFramesSupplier> xSup = xFrame->getCreator();
                Reference<XController> xCont = xSup.is() ? 
xSup->getController() : Reference<XController>();
 
-        bSubFrameOfEmbeddedDocument = xCont.is() && 
::dbtools::isEmbeddedInDatabase( xCont->getModel(), xConnection );
+        bSubFrameOfEmbeddedDocument = xCont.is() && 
::dbtools::isEmbeddedInDatabase( xCont->getModel(), xForeignConnection );
        }
 
     // if we have a connection at this point, it was either passed from 
outside, our
     // determined from a outer DB document. In both cases, do not dispose it 
later on.
-    if ( xConnection.is() )
-        m_bOwnConnection = sal_False;
+    SharedConnection xConnection( xForeignConnection, !xForeignConnection.is() 
);
 
     // should we display all registered databases in the left hand side tree?
     // or only *one* special?
@@ -3237,13 +3244,15 @@
         Image aDBImage, aQueriesImage, aTablesImage;
                String sQueriesName, sTablesName;
 
-               implAddDatasource( sInitialDataSourceName, aDBImage, 
sQueriesName, aQueriesImage, sTablesName, aTablesImage, xConnection );
+               implAddDatasource( sInitialDataSourceName,
+            aDBImage, sQueriesName, aQueriesImage, sTablesName, aTablesImage, 
xConnection
+        );
                m_pTreeView->getListBox()->Expand( 
m_pTreeView->getListBox()->First() );
     }
     else
                initializeTreeModel();
 
-       if ( implSelect(sInitialDataSourceName, sInitialCommand, 
nInitialDisplayCommandType, bEsacpeProcessing,xConnection,sal_True) )
+       if ( implSelect( sInitialDataSourceName, sInitialCommand, 
nInitialDisplayCommandType, bEsacpeProcessing, xConnection, sal_True ) )
        {
                try
                {
@@ -3305,7 +3314,7 @@
 }
 
 // 
-----------------------------------------------------------------------------
-sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pAnyEntry, 
Reference< XConnection>& _xConnection)
+sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pAnyEntry, 
SharedConnection& _rConnection)
 {
        SvLBoxEntry* pDSEntry = 
m_pTreeView->getListBox()->GetRootLevelParent(_pAnyEntry);
        DBTreeListModel::DBTreeListUserData* pDSData =
@@ -3313,21 +3322,45 @@
                        ?       
static_cast<DBTreeListModel::DBTreeListUserData*>(pDSEntry->GetUserData())
                        :       NULL;
 
-       return ensureConnection( pDSEntry, pDSData, _xConnection);
+       return ensureConnection( pDSEntry, pDSData, _rConnection );
+}
+
+// 
-----------------------------------------------------------------------------
+bool SbaTableQueryBrowser::impl_isDataSourceEntry( SvLBoxEntry* _pEntry ) const
+{
+    return m_pTreeModel->GetRootLevelParent( _pEntry ) == _pEntry;
+}
+
+// -------------------------------------------------------------------------
+Reference< XModel > SbaTableQueryBrowser::impl_nf_getDBDocumentForConnection( 
const Reference< XConnection >& _rxConnection )
+{
+    Reference< XModel > xModel;
+    try
+    {
+           Reference< XChild > xChild( _rxConnection, UNO_QUERY_THROW );
+        Reference< XDocumentDataSource > xDS( xChild->getParent(), 
UNO_QUERY_THROW );
+        xModel = Reference< XModel >( xDS->getDatabaseDocument(), 
UNO_QUERY_THROW );
+    }
+    catch( const Exception& )
+    {
+       OSL_ENSURE( sal_False, 
"SbaTableQueryBrowser::impl_nf_getDBDocumentForConnection: caught an 
exception!" );
+    }
+    return xModel;
 }
 
 // 
-----------------------------------------------------------------------------
-sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pDSEntry, void* 
pDSData, Reference<XConnection>& _xConnection)
+sal_Bool SbaTableQueryBrowser::ensureConnection( SvLBoxEntry* _pDSEntry, void* 
pDSData, SharedConnection& _rConnection )
 {
+    DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), 
"SbaTableQueryBrowser::ensureConnection: this entry does not denote a data 
source!" );
        if(_pDSEntry)
        {
-               DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pDSData);
+               DBTreeListModel::DBTreeListUserData* pTreeListData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pDSData);
                ::rtl::OUString aDSName = GetEntryText(_pDSEntry);
 
-               if (pData)
-                       _xConnection.set(pData->xObject,UNO_QUERY);
+               if ( pTreeListData )
+                       _rConnection = pTreeListData->xConnection;
 
-               if (!_xConnection.is() && pData)
+               if ( !_rConnection.is() && pTreeListData )
                {
                        // show the "connecting to ..." status
                        String 
sConnecting(ModuleRes(STR_CONNECTING_DATASOURCE));
@@ -3339,20 +3372,24 @@
                        sConnectingContext.SearchAndReplaceAscii("$name$", 
aDSName);
 
                        // connect
-            _xConnection = connect( getDataSourceAcessor( _pDSEntry ), 
sConnectingContext, rtl::OUString(), sal_True);
-                       if ( m_bOwnConnection = _xConnection.is() )
+            _rConnection = SharedConnection(
+                connect( getDataSourceAcessor( _pDSEntry ), 
sConnectingContext, rtl::OUString(), sal_True),
+                true    /* take ownership */
+            );
+                       if ( _rConnection.is() )
             {
-                Reference< XModel > 
xModel(getDataSourceOrModel(::dbtools::findDataSource(_xConnection)),UNO_QUERY);
-                if ( xModel.is() )
-                    xModel->connectController(this);
+                DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), 
"SbaTableQueryBrowser::ensureConnection: this is no data source entry!" );
+                    // if this fails, we can't expect 
pTreeListData->aController to point to a valid
+                    // instance, since those instances are only filled for 
data source entries
+                pTreeListData->aController.swap( ModelControllerConnector( 
impl_nf_getDBDocumentForConnection( _rConnection ), this ) );
             }
 
                        // remember the connection
-                       static_cast< DBTreeListModel::DBTreeListUserData* >( 
pData )->xObject = _xConnection;
+                       pTreeListData->xConnection = _rConnection;
                }
        }
 
-       return _xConnection.is();
+       return _rConnection.is();
 }
 
 // 
-----------------------------------------------------------------------------
@@ -3419,7 +3456,7 @@
 {
        try
        {
-               Reference<XConnection> xConnection;
+               SharedConnection xConnection;
                if(!ensureConnection(_pApplyTo, xConnection))
                        return;
 
@@ -3550,7 +3587,7 @@
        PopupMenu* pDynamicSubMenu = NULL;
 
        // enable menu entries
-       if (!pDSData || !pDSData->xObject.is())
+       if (!pDSData || !pDSData->xConnection.is())
        {       // no -> disable the connection-related menu entries
                aContextMenu.EnableItem(ID_TREE_CLOSE_CONN, sal_False);
                aContextMenu.EnableItem(ID_TREE_REBUILD_CONN, sal_False);
@@ -3701,53 +3738,6 @@
 
        return sal_False;
 }
-// 
-----------------------------------------------------------------------------
-void SbaTableQueryBrowser::ensureObjectExists(SvLBoxEntry* _pApplyTo)
-{
-       // get the name of the object
-       DBTreeListModel::DBTreeListUserData* pData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(_pApplyTo->GetUserData());
-       if(!pData->xObject.is())
-       {
-               // the object has not been accessed before -> create it's user 
data
-               SvLBoxEntry* pEntryParent       = 
m_pTreeView->getListBox()->GetParent(_pApplyTo);
-               DBTreeListModel::DBTreeListUserData* pParentData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pEntryParent->GetUserData());
-               if(pParentData && pParentData->xObject.is())
-               {
-                       Reference<XNameAccess> xNameAccess;
-                       if(pParentData->eType == etQueryContainer)
-                       {// special handling for queries because otherwise we 
got commanddefinition instead of query object
-
-                               // connect to the data source
-                               SvLBoxEntry* pRootEntry = 
m_pTreeView->getListBox()->GetRootLevelParent( _pApplyTo );
-                               Reference< XConnection > xConnection;
-                               ensureConnection( pRootEntry, xConnection );
-
-                               // get the queries
-                               Reference< XQueriesSupplier > xSup( 
xConnection, UNO_QUERY );
-                               if ( xSup.is() )
-                                       xNameAccess = xSup->getQueries();
-                                       // TODO: this seems to be a hack ... 
this relies on the fact that the query is create when we call
-                                       // getQueries ....
-                                       // [EMAIL PROTECTED] - 24.01.2002
-                       }
-                       else
-                               xNameAccess.set(pParentData->xObject,UNO_QUERY);
-
-                       ::rtl::OUString sCurrentObject;
-                       SvLBoxItem* pTextItem = 
_pApplyTo->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
-                       if (pTextItem)
-                               sCurrentObject = 
static_cast<SvLBoxString*>(pTextItem)->GetText();
-                       try
-                       {
-                               if(xNameAccess.is() && 
xNameAccess->hasByName(sCurrentObject))  // remember the table or query object
-                                       xNameAccess->getByName(sCurrentObject) 
>>= pData->xObject;
-                       }
-                       catch(Exception&)
-                       {
-                       }
-               }
-       }
-}
 
//------------------------------------------------------------------------------
 void SbaTableQueryBrowser::frameAction(const 
::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
 {
@@ -3848,7 +3838,7 @@
                {
                        SvLBoxEntry* pDataSource = NULL;
                        SvLBoxEntry* pCommandType = NULL;
-                       m_pCurrentlyDisplayed = getObjectEntry(sDataSource, 
sCommand, nCommandType, &pDataSource, &pCommandType, sal_True,NULL);
+                       m_pCurrentlyDisplayed = getObjectEntry( sDataSource, 
sCommand, nCommandType, &pDataSource, &pCommandType, sal_True, 
SharedConnection() );
                        bIni = sal_True;
                }
        }




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

Reply via email to