LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/relationdesign - RelationController.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 257 0.0 %
Date: 2012-12-27 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dbu_reghelper.hxx"
      21             : #include <sfx2/sfxsids.hrc>
      22             : #include "dbu_rel.hrc"
      23             : #include <vcl/svapp.hxx>
      24             : #include "browserids.hxx"
      25             : #include <comphelper/types.hxx>
      26             : #include "dbustrings.hrc"
      27             : #include <connectivity/dbtools.hxx>
      28             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      29             : #include <comphelper/extract.hxx>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <com/sun/star/container/XChild.hpp>
      32             : #include <com/sun/star/container/XNameContainer.hpp>
      33             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      34             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      35             : #include <com/sun/star/sdbcx/KeyType.hpp>
      36             : #include <com/sun/star/sdbcx/XDrop.hpp>
      37             : #include <com/sun/star/sdbcx/XAlterTable.hpp>
      38             : #include <com/sun/star/sdbcx/XAppend.hpp>
      39             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      40             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      41             : #include <com/sun/star/sdb/SQLContext.hpp>
      42             : #include <com/sun/star/sdbc/SQLWarning.hpp>
      43             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      44             : #include <com/sun/star/sdbc/XRow.hpp>
      45             : #include <connectivity/dbexception.hxx>
      46             : #include <connectivity/dbmetadata.hxx>
      47             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      48             : #include <comphelper/streamsection.hxx>
      49             : #include <comphelper/basicio.hxx>
      50             : #include <comphelper/seqstream.hxx>
      51             : #include <com/sun/star/io/XActiveDataSource.hpp>
      52             : #include <com/sun/star/io/XActiveDataSink.hpp>
      53             : #include "sqlmessage.hxx"
      54             : #include "RelationController.hxx"
      55             : #include <vcl/msgbox.hxx>
      56             : #include "TableWindowData.hxx"
      57             : #include "UITools.hxx"
      58             : #include "RTableConnectionData.hxx"
      59             : #include "RelationTableView.hxx"
      60             : #include "RelationDesignView.hxx"
      61             : #include <tools/debug.hxx>
      62             : #include <tools/diagnose_ex.h>
      63             : #include <vcl/waitobj.hxx>
      64             : #include <osl/thread.hxx>
      65             : #include <osl/mutex.hxx>
      66             : 
      67             : 
      68             : #define MAX_THREADS 10
      69             : 
      70           0 : extern "C" void SAL_CALL createRegistryInfo_ORelationControl()
      71             : {
      72           0 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::ORelationController > aAutoRegistration;
      73           0 : }
      74             : 
      75             : 
      76             : using namespace ::com::sun::star::uno;
      77             : using namespace ::com::sun::star::io;
      78             : using namespace ::com::sun::star::beans;
      79             : using namespace ::com::sun::star::frame;
      80             : using namespace ::com::sun::star::util;
      81             : using namespace ::com::sun::star::lang;
      82             : using namespace ::com::sun::star::container;
      83             : using namespace ::com::sun::star::sdbcx;
      84             : using namespace ::com::sun::star::sdbc;
      85             : using namespace ::com::sun::star::sdb;
      86             : using namespace ::com::sun::star::ui::dialogs;
      87             : using namespace ::com::sun::star::util;
      88             : using namespace ::dbtools;
      89             : using namespace ::dbaui;
      90             : using namespace ::comphelper;
      91             : using namespace ::osl;
      92             : 
      93             : //------------------------------------------------------------------------------
      94           0 : ::rtl::OUString SAL_CALL ORelationController::getImplementationName() throw( RuntimeException )
      95             : {
      96           0 :     return getImplementationName_Static();
      97             : }
      98             : 
      99             : //------------------------------------------------------------------------------
     100           0 : ::rtl::OUString ORelationController::getImplementationName_Static() throw( RuntimeException )
     101             : {
     102           0 :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.ORelationDesign"));
     103             : }
     104             : //------------------------------------------------------------------------------
     105           0 : Sequence< ::rtl::OUString> ORelationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
     106             : {
     107           0 :     Sequence< ::rtl::OUString> aSupported(1);
     108           0 :     aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.RelationDesign"));
     109           0 :     return aSupported;
     110             : }
     111             : //-------------------------------------------------------------------------
     112           0 : Sequence< ::rtl::OUString> SAL_CALL ORelationController::getSupportedServiceNames() throw(RuntimeException)
     113             : {
     114           0 :     return getSupportedServiceNames_Static();
     115             : }
     116             : // -------------------------------------------------------------------------
     117           0 : Reference< XInterface > SAL_CALL ORelationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
     118             : {
     119           0 :     return *(new ORelationController(_rxFactory));
     120             : }
     121             : DBG_NAME(ORelationController);
     122             : // -----------------------------------------------------------------------------
     123           0 : ORelationController::ORelationController(const Reference< XMultiServiceFactory >& _rM)
     124             :     : OJoinController(_rM)
     125             :     ,m_nThreadEvent(0)
     126           0 :     ,m_bRelationsPossible(sal_True)
     127             : {
     128             :     DBG_CTOR(ORelationController,NULL);
     129           0 :     InvalidateAll();
     130           0 : }
     131             : // -----------------------------------------------------------------------------
     132           0 : ORelationController::~ORelationController()
     133             : {
     134             :     DBG_DTOR(ORelationController,NULL);
     135           0 : }
     136             : // -----------------------------------------------------------------------------
     137           0 : FeatureState ORelationController::GetState(sal_uInt16 _nId) const
     138             : {
     139           0 :     FeatureState aReturn;
     140           0 :     aReturn.bEnabled = m_bRelationsPossible;
     141           0 :     switch (_nId)
     142             :     {
     143             :         case SID_RELATION_ADD_RELATION:
     144           0 :             aReturn.bEnabled = !m_vTableData.empty() && isConnected() && isEditable();
     145           0 :             aReturn.bChecked = false;
     146           0 :             break;
     147             :         case ID_BROWSER_SAVEDOC:
     148           0 :             aReturn.bEnabled = haveDataSource() && impl_isModified();
     149           0 :             break;
     150             :         default:
     151           0 :             aReturn = OJoinController::GetState(_nId);
     152           0 :             break;
     153             :     }
     154           0 :     return aReturn;
     155             : }
     156             : // -----------------------------------------------------------------------------
     157           0 : void ORelationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
     158             : {
     159           0 :     switch(_nId)
     160             :     {
     161             :         case ID_BROWSER_SAVEDOC:
     162             :             {
     163             :                 OSL_ENSURE(isEditable(),"Slot ID_BROWSER_SAVEDOC should not be enabled!");
     164           0 :                 if(!::dbaui::checkDataSourceAvailable(::comphelper::getString(getDataSource()->getPropertyValue(PROPERTY_NAME)), comphelper::getComponentContext(getORB())))
     165             :                 {
     166           0 :                     String aMessage(ModuleRes(STR_DATASOURCE_DELETED));
     167           0 :                     OSQLWarningBox( getView(), aMessage ).Execute();
     168             :                 }
     169             :                 else
     170             :                 {
     171             :                     // now we save the layout information
     172             :                     //  create the output stream
     173             :                     try
     174             :                     {
     175           0 :                         if ( haveDataSource() && getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) )
     176             :                         {
     177           0 :                             ::comphelper::NamedValueCollection aWindowsData;
     178           0 :                             saveTableWindows( aWindowsData );
     179           0 :                             getDataSource()->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aWindowsData.getPropertyValues() ) );
     180           0 :                             setModified(sal_False);
     181             :                         }
     182             :                     }
     183           0 :                     catch ( const Exception& )
     184             :                     {
     185             :                         DBG_UNHANDLED_EXCEPTION();
     186             :                     }
     187             :                 }
     188             :             }
     189           0 :             break;
     190             :         case SID_RELATION_ADD_RELATION:
     191           0 :             static_cast<ORelationTableView*>(static_cast<ORelationDesignView*>( getView() )->getTableView())->AddNewRelation();
     192           0 :             break;
     193             :         default:
     194           0 :             OJoinController::Execute(_nId,aArgs);
     195           0 :             return;
     196             :     }
     197           0 :     InvalidateFeature(_nId);
     198             : }
     199             : // -----------------------------------------------------------------------------
     200           0 : void ORelationController::impl_initialize()
     201             : {
     202           0 :     OJoinController::impl_initialize();
     203             : 
     204           0 :     if( !getSdbMetaData().supportsRelations() )
     205             :     {// check if this database supports relations
     206             : 
     207           0 :         setEditable(sal_False);
     208           0 :         m_bRelationsPossible    = sal_False;
     209             :         {
     210           0 :             String sTitle(ModuleRes(STR_RELATIONDESIGN));
     211           0 :             sTitle.Erase(0,3);
     212           0 :             OSQLMessageBox aDlg(NULL,sTitle,ModuleRes(STR_RELATIONDESIGN_NOT_AVAILABLE));
     213           0 :             aDlg.Execute();
     214             :         }
     215           0 :         disconnect();
     216           0 :         throw SQLException();
     217             :     }
     218             : 
     219           0 :     if(!m_bRelationsPossible)
     220           0 :         InvalidateAll();
     221             : 
     222             :     // we need a datasource
     223             :     OSL_ENSURE(haveDataSource(),"ORelationController::initialize: need a datasource!");
     224             : 
     225           0 :     Reference<XTablesSupplier> xSup(getConnection(),UNO_QUERY);
     226             :     OSL_ENSURE(xSup.is(),"Connection isn't a XTablesSupplier!");
     227           0 :     if(xSup.is())
     228           0 :         m_xTables = xSup->getTables();
     229             :     // load the layoutInformation
     230           0 :     loadLayoutInformation();
     231             :     try
     232             :     {
     233           0 :         loadData();
     234           0 :         if ( !m_nThreadEvent )
     235           0 :             Application::PostUserEvent(LINK(this, ORelationController, OnThreadFinished));
     236             :     }
     237           0 :     catch( const Exception& )
     238             :     {
     239             :         DBG_UNHANDLED_EXCEPTION();
     240           0 :     }
     241             : 
     242           0 : }
     243             : // -----------------------------------------------------------------------------
     244           0 : ::rtl::OUString ORelationController::getPrivateTitle( ) const
     245             : {
     246           0 :     ::rtl::OUString sName = getDataSourceName();
     247           0 :     return ::dbaui::getStrippedDatabaseName(getDataSource(),sName);
     248             : }
     249             : // -----------------------------------------------------------------------------
     250           0 : sal_Bool ORelationController::Construct(Window* pParent)
     251             : {
     252           0 :     setView( * new ORelationDesignView( pParent, *this, comphelper::getComponentContext(getORB()) ) );
     253           0 :     OJoinController::Construct(pParent);
     254           0 :     return sal_True;
     255             : }
     256             : // -----------------------------------------------------------------------------
     257           0 : short ORelationController::saveModified()
     258             : {
     259           0 :     short nSaved = RET_YES;
     260           0 :     if(haveDataSource() && isModified())
     261             :     {
     262           0 :         QueryBox aQry(getView(), ModuleRes(RELATION_DESIGN_SAVEMODIFIED));
     263           0 :         nSaved = aQry.Execute();
     264           0 :         if(nSaved == RET_YES)
     265           0 :             Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
     266             :     }
     267           0 :     return nSaved;
     268             : }
     269             : // -----------------------------------------------------------------------------
     270           0 : void ORelationController::describeSupportedFeatures()
     271             : {
     272           0 :     OJoinController::describeSupportedFeatures();
     273           0 :     implDescribeSupportedFeature( ".uno:DBAddRelation", SID_RELATION_ADD_RELATION, CommandGroup::EDIT );
     274           0 : }
     275             : namespace
     276             : {
     277             :     class RelationLoader : public ::osl::Thread
     278             :     {
     279             :         DECLARE_STL_MAP(::rtl::OUString,::boost::shared_ptr<OTableWindowData>,::comphelper::UStringMixLess,TTableDataHelper);
     280             :         TTableDataHelper                    m_aTableData;
     281             :         TTableConnectionData                m_vTableConnectionData;
     282             :         const Sequence< ::rtl::OUString>    m_aTableList;
     283             :         ORelationController*                m_pParent;
     284             :         const Reference< XDatabaseMetaData> m_xMetaData;
     285             :         const Reference< XNameAccess >      m_xTables;
     286             :         const sal_Int32                     m_nStartIndex;
     287             :         const sal_Int32                     m_nEndIndex;
     288             : 
     289             :     public:
     290           0 :         RelationLoader(ORelationController* _pParent
     291             :                         ,const Reference< XDatabaseMetaData>& _xMetaData
     292             :                         ,const Reference< XNameAccess >& _xTables
     293             :                         ,const Sequence< ::rtl::OUString>& _aTableList
     294             :                         ,const sal_Int32 _nStartIndex
     295             :                         ,const sal_Int32 _nEndIndex)
     296           0 :             :m_aTableData(_xMetaData.is() && _xMetaData->supportsMixedCaseQuotedIdentifiers())
     297             :             ,m_aTableList(_aTableList)
     298             :             ,m_pParent(_pParent)
     299             :             ,m_xMetaData(_xMetaData)
     300             :             ,m_xTables(_xTables)
     301             :             ,m_nStartIndex(_nStartIndex)
     302           0 :             ,m_nEndIndex(_nEndIndex)
     303             :         {
     304           0 :         }
     305             : 
     306             :         /// Working method which should be overridden.
     307             :         virtual void SAL_CALL run();
     308             :         virtual void SAL_CALL onTerminated();
     309             :     protected:
     310           0 :         virtual ~RelationLoader(){}
     311             : 
     312             :         void loadTableData(const Any& _aTable);
     313             :     };
     314             : 
     315           0 :     void SAL_CALL RelationLoader::run()
     316             :     {
     317           0 :         const ::rtl::OUString* pIter = m_aTableList.getConstArray() + m_nStartIndex;
     318           0 :         for(sal_Int32 i = m_nStartIndex; i < m_nEndIndex;++i,++pIter)
     319             :         {
     320           0 :             ::rtl::OUString sCatalog,sSchema,sTable;
     321             :             ::dbtools::qualifiedNameComponents(m_xMetaData,
     322             :                                                 *pIter,
     323             :                                                 sCatalog,
     324             :                                                 sSchema,
     325             :                                                 sTable,
     326           0 :                                                 ::dbtools::eInDataManipulation);
     327           0 :             Any aCatalog;
     328           0 :             if ( !sCatalog.isEmpty() )
     329           0 :                 aCatalog <<= sCatalog;
     330             : 
     331             :             try
     332             :             {
     333           0 :                 Reference< XResultSet > xResult = m_xMetaData->getImportedKeys(aCatalog, sSchema,sTable);
     334           0 :                 if ( xResult.is() && xResult->next() )
     335             :                 {
     336           0 :                     ::comphelper::disposeComponent(xResult);
     337           0 :                     loadTableData(m_xTables->getByName(*pIter));
     338           0 :                 }
     339             :             }
     340           0 :             catch( const Exception& )
     341             :             {
     342             :                 DBG_UNHANDLED_EXCEPTION();
     343             :             }
     344           0 :         }
     345           0 :     }
     346           0 :     void SAL_CALL RelationLoader::onTerminated()
     347             :     {
     348           0 :         m_pParent->mergeData(m_vTableConnectionData);
     349           0 :         delete this;
     350           0 :     }
     351             : 
     352           0 :     void RelationLoader::loadTableData(const Any& _aTable)
     353             :     {
     354           0 :         Reference<XPropertySet> xTableProp(_aTable,UNO_QUERY);
     355           0 :         const ::rtl::OUString sSourceName = ::dbtools::composeTableName( m_xMetaData, xTableProp, ::dbtools::eInTableDefinitions, false, false, false );
     356           0 :         TTableDataHelper::iterator aFind = m_aTableData.find(sSourceName);
     357           0 :         if ( aFind == m_aTableData.end() )
     358             :         {
     359           0 :             aFind = m_aTableData.insert(TTableDataHelper::value_type(sSourceName,::boost::shared_ptr<OTableWindowData>(new OTableWindowData(xTableProp,sSourceName, sSourceName)))).first;
     360           0 :             aFind->second->ShowAll(sal_False);
     361             :         }
     362           0 :         TTableWindowData::value_type pReferencingTable = aFind->second;
     363           0 :         Reference<XIndexAccess> xKeys = pReferencingTable->getKeys();
     364           0 :         const Reference<XKeysSupplier> xKeySup(xTableProp,UNO_QUERY);
     365             : 
     366           0 :         if ( !xKeys.is() && xKeySup.is() )
     367             :         {
     368           0 :             xKeys = xKeySup->getKeys();
     369             :         }
     370             : 
     371           0 :         if ( xKeys.is() )
     372             :         {
     373           0 :             Reference<XPropertySet> xKey;
     374           0 :             const sal_Int32 nCount = xKeys->getCount();
     375           0 :             for(sal_Int32 i = 0 ; i < nCount ; ++i)
     376             :             {
     377           0 :                 xKeys->getByIndex(i) >>= xKey;
     378           0 :                 sal_Int32 nKeyType = 0;
     379           0 :                 xKey->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
     380           0 :                 if ( KeyType::FOREIGN == nKeyType )
     381             :                 {
     382           0 :                     ::rtl::OUString sReferencedTable;
     383           0 :                     xKey->getPropertyValue(PROPERTY_REFERENCEDTABLE) >>= sReferencedTable;
     384             :                     //////////////////////////////////////////////////////////////////////
     385             :                     // insert windows
     386           0 :                     TTableDataHelper::iterator aRefFind = m_aTableData.find(sReferencedTable);
     387           0 :                     if ( aRefFind == m_aTableData.end() )
     388             :                     {
     389           0 :                         if ( m_xTables->hasByName(sReferencedTable) )
     390             :                         {
     391           0 :                             Reference<XPropertySet>  xReferencedTable(m_xTables->getByName(sReferencedTable),UNO_QUERY);
     392           0 :                             aRefFind = m_aTableData.insert(TTableDataHelper::value_type(sReferencedTable,::boost::shared_ptr<OTableWindowData>(new OTableWindowData(xReferencedTable,sReferencedTable, sReferencedTable)))).first;
     393           0 :                             aRefFind->second->ShowAll(sal_False);
     394             :                         }
     395             :                         else
     396           0 :                             continue; // table name could not be found so we do not show this table releation
     397             :                     }
     398           0 :                     TTableWindowData::value_type pReferencedTable = aRefFind->second;
     399             : 
     400           0 :                     ::rtl::OUString sKeyName;
     401           0 :                     xKey->getPropertyValue(PROPERTY_NAME) >>= sKeyName;
     402             :                     //////////////////////////////////////////////////////////////////////
     403             :                     // insert connection
     404           0 :                     ORelationTableConnectionData* pTabConnData = new ORelationTableConnectionData( pReferencingTable, pReferencedTable, sKeyName );
     405           0 :                     m_vTableConnectionData.push_back(TTableConnectionData::value_type(pTabConnData));
     406             :                     //////////////////////////////////////////////////////////////////////
     407             :                     // insert columns
     408           0 :                     const Reference<XColumnsSupplier> xColsSup(xKey,UNO_QUERY);
     409             :                     OSL_ENSURE(xColsSup.is(),"Key is no XColumnsSupplier!");
     410           0 :                     const Reference<XNameAccess> xColumns       = xColsSup->getColumns();
     411           0 :                     const Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
     412           0 :                     const ::rtl::OUString* pIter    = aNames.getConstArray();
     413           0 :                     const ::rtl::OUString* pEnd     = pIter + aNames.getLength();
     414           0 :                     ::rtl::OUString sColumnName,sRelatedName;
     415           0 :                     for(sal_uInt16 j=0;pIter != pEnd;++pIter,++j)
     416             :                     {
     417           0 :                         const Reference<XPropertySet> xPropSet(xColumns->getByName(*pIter),UNO_QUERY);
     418             :                         OSL_ENSURE(xPropSet.is(),"Invalid column found in KeyColumns!");
     419           0 :                         if ( xPropSet.is() )
     420             :                         {
     421           0 :                             xPropSet->getPropertyValue(PROPERTY_NAME)           >>= sColumnName;
     422           0 :                             xPropSet->getPropertyValue(PROPERTY_RELATEDCOLUMN)  >>= sRelatedName;
     423             :                         }
     424           0 :                         pTabConnData->SetConnLine( j, sColumnName, sRelatedName );
     425           0 :                     }
     426             :                     //////////////////////////////////////////////////////////////////////
     427             :                     // Update/Del-Flags setzen
     428           0 :                     sal_Int32   nUpdateRule = 0;
     429           0 :                     sal_Int32   nDeleteRule = 0;
     430           0 :                     xKey->getPropertyValue(PROPERTY_UPDATERULE) >>= nUpdateRule;
     431           0 :                     xKey->getPropertyValue(PROPERTY_DELETERULE) >>= nDeleteRule;
     432             : 
     433           0 :                     pTabConnData->SetUpdateRules( nUpdateRule );
     434           0 :                     pTabConnData->SetDeleteRules( nDeleteRule );
     435             : 
     436             :                     //////////////////////////////////////////////////////////////////////
     437             :                     // Kardinalitaet setzen
     438           0 :                     pTabConnData->SetCardinality();
     439             :                 }
     440           0 :             }
     441           0 :         }
     442           0 :     }
     443             : }
     444             : 
     445           0 : void ORelationController::mergeData(const TTableConnectionData& _aConnectionData)
     446             : {
     447           0 :     ::osl::MutexGuard aGuard( getMutex() );
     448             : 
     449           0 :     ::std::copy( _aConnectionData.begin(), _aConnectionData.end(), ::std::back_inserter( m_vTableConnectionData ));
     450             :     //const Reference< XDatabaseMetaData> xMetaData = getConnection()->getMetaData();
     451           0 :     const sal_Bool bCase = sal_True;//xMetaData.is() && xMetaData->supportsMixedCaseQuotedIdentifiers();
     452             :     // here we are finished, so we can collect the table from connection data
     453           0 :     TTableConnectionData::iterator aConnDataIter = m_vTableConnectionData.begin();
     454           0 :     TTableConnectionData::iterator aConnDataEnd = m_vTableConnectionData.end();
     455           0 :     for(;aConnDataIter != aConnDataEnd;++aConnDataIter)
     456             :     {
     457           0 :         if ( !existsTable((*aConnDataIter)->getReferencingTable()->GetComposedName(),bCase) )
     458             :         {
     459           0 :             m_vTableData.push_back((*aConnDataIter)->getReferencingTable());
     460             :         }
     461           0 :         if ( !existsTable((*aConnDataIter)->getReferencedTable()->GetComposedName(),bCase) )
     462             :         {
     463           0 :             m_vTableData.push_back((*aConnDataIter)->getReferencedTable());
     464             :         }
     465             :     }
     466           0 :     if ( m_nThreadEvent )
     467             :     {
     468           0 :         --m_nThreadEvent;
     469           0 :         if ( !m_nThreadEvent )
     470           0 :             Application::PostUserEvent(LINK(this, ORelationController, OnThreadFinished));
     471           0 :     }
     472           0 : }
     473             : // -----------------------------------------------------------------------------
     474           0 : IMPL_LINK( ORelationController, OnThreadFinished, void*, /*NOTINTERESTEDIN*/ )
     475             : {
     476           0 :     ::SolarMutexGuard aSolarGuard;
     477           0 :     ::osl::MutexGuard aGuard( getMutex() );
     478             :     try
     479             :     {
     480           0 :         getView()->initialize();    // show the windows and fill with our informations
     481           0 :         getView()->Invalidate(INVALIDATE_NOERASE);
     482           0 :         ClearUndoManager();
     483           0 :         setModified(sal_False);     // and we are not modified yet
     484             : 
     485           0 :         if(m_vTableData.empty())
     486           0 :             Execute(ID_BROWSER_ADDTABLE,Sequence<PropertyValue>());
     487             :     }
     488           0 :     catch( const Exception& )
     489             :     {
     490             :         DBG_UNHANDLED_EXCEPTION();
     491             :     }
     492           0 :     m_pWaitObject.reset();
     493           0 :     return 0L;
     494             : }
     495             : // -----------------------------------------------------------------------------
     496           0 : void ORelationController::loadData()
     497             : {
     498           0 :     m_pWaitObject.reset( new WaitObject(getView()) );
     499             :     try
     500             :     {
     501           0 :         if ( !m_xTables.is() )
     502           0 :             return;
     503           0 :         DatabaseMetaData aMeta(getConnection());
     504             :         // this may take some time
     505           0 :         const Reference< XDatabaseMetaData> xMetaData = getConnection()->getMetaData();
     506           0 :         const Sequence< ::rtl::OUString> aNames = m_xTables->getElementNames();
     507           0 :         const sal_Int32 nCount = aNames.getLength();
     508           0 :         if ( aMeta.supportsThreads() )
     509             :         {
     510           0 :             const sal_Int32 nMaxElements = (nCount / MAX_THREADS) +1;
     511           0 :             sal_Int32 nStart = 0,nEnd = ::std::min(nMaxElements,nCount);
     512           0 :             while(nStart != nEnd)
     513             :             {
     514           0 :                 ++m_nThreadEvent;
     515           0 :                 RelationLoader* pThread = new RelationLoader(this,xMetaData,m_xTables,aNames,nStart,nEnd);
     516           0 :                 pThread->createSuspended();
     517           0 :                 pThread->setPriority(osl_Thread_PriorityBelowNormal);
     518           0 :                 pThread->resume();
     519           0 :                 nStart = nEnd;
     520           0 :                 nEnd += nMaxElements;
     521           0 :                 nEnd = ::std::min(nEnd,nCount);
     522             :             }
     523             :         }
     524             :         else
     525             :         {
     526           0 :             RelationLoader* pThread = new RelationLoader(this,xMetaData,m_xTables,aNames,0,nCount);
     527           0 :             pThread->run();
     528           0 :             pThread->onTerminated();
     529           0 :         }
     530             :     }
     531           0 :     catch(SQLException& e)
     532             :     {
     533           0 :         showError(SQLExceptionInfo(e));
     534             :     }
     535           0 :     catch(const Exception&)
     536             :     {
     537             :         DBG_UNHANDLED_EXCEPTION();
     538             :     }
     539             : }
     540             : // -----------------------------------------------------------------------------
     541           0 : TTableWindowData::value_type ORelationController::existsTable(const ::rtl::OUString& _rComposedTableName,sal_Bool _bCase)  const
     542             : {
     543           0 :     ::comphelper::UStringMixEqual bCase(_bCase);
     544           0 :     TTableWindowData::const_iterator aIter = m_vTableData.begin();
     545           0 :     TTableWindowData::const_iterator aEnd = m_vTableData.end();
     546           0 :     for(;aIter != aEnd;++aIter)
     547             :     {
     548           0 :         if(bCase((*aIter)->GetComposedName(),_rComposedTableName))
     549           0 :             break;
     550             :     }
     551           0 :     return ( aIter != aEnd) ? *aIter : TTableWindowData::value_type();
     552             : }
     553             : // -----------------------------------------------------------------------------
     554           0 : void ORelationController::loadLayoutInformation()
     555             : {
     556             :     try
     557             :     {
     558             :         OSL_ENSURE(haveDataSource(),"We need a datasource from our connection!");
     559           0 :         if ( haveDataSource() )
     560             :         {
     561           0 :             if ( getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) )
     562             :             {
     563           0 :                 Sequence<PropertyValue> aWindows;
     564           0 :                 getDataSource()->getPropertyValue(PROPERTY_LAYOUTINFORMATION) >>= aWindows;
     565           0 :                 loadTableWindows(aWindows);
     566             :             }
     567             :         }
     568             :     }
     569           0 :     catch(Exception&)
     570             :     {
     571             :     }
     572           0 : }
     573             : // -----------------------------------------------------------------------------
     574           0 : void ORelationController::reset()
     575             : {
     576           0 :     loadLayoutInformation();
     577           0 :     ODataView* pView = getView();
     578             :     OSL_ENSURE(pView,"No current view!");
     579           0 :     if(pView)
     580             :     {
     581           0 :         pView->initialize();
     582           0 :         pView->Invalidate(INVALIDATE_NOERASE);
     583             :     }
     584           0 : }
     585             : 
     586             : // -----------------------------------------------------------------------------
     587           0 : bool ORelationController::allowViews() const
     588             : {
     589           0 :     return false;
     590             : }
     591             : 
     592             : // -----------------------------------------------------------------------------
     593           0 : bool ORelationController::allowQueries() const
     594             : {
     595           0 :     return false;
     596             : }
     597             : 
     598             : // -----------------------------------------------------------------------------
     599             : 
     600             : 
     601             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10