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

Generated by: LCOV version 1.10