LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/abpilot - datasourcehandling.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 207 0.0 %
Date: 2012-12-27 Functions: 0 39 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             : 
      21             : #include "abpresid.hrc"
      22             : #include "abptypes.hxx"
      23             : #include "componentmodule.hxx"
      24             : #include "datasourcehandling.hxx"
      25             : 
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/frame/XStorable.hpp>
      29             : #include <com/sun/star/lang/XComponent.hpp>
      30             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      31             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      32             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      33             : #include <com/sun/star/sdb/SQLContext.hpp>
      34             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      35             : #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
      36             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      37             : #include <com/sun/star/sdbc/XConnection.hpp>
      38             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      39             : #include <com/sun/star/task/InteractionHandler.hpp>
      40             : #include <com/sun/star/uno/XNamingService.hpp>
      41             : 
      42             : #include <comphelper/interaction.hxx>
      43             : #include <comphelper/processfactory.hxx>
      44             : #include <tools/debug.hxx>
      45             : #include <tools/diagnose_ex.h>
      46             : #include <unotools/confignode.hxx>
      47             : #include <unotools/sharedunocomponent.hxx>
      48             : #include <vcl/stdtext.hxx>
      49             : 
      50             : //.........................................................................
      51             : namespace abp
      52             : {
      53             : //.........................................................................
      54             : 
      55             :     using namespace ::utl;
      56             :     using namespace ::comphelper;
      57             :     using namespace ::com::sun::star::uno;
      58             :     using namespace ::com::sun::star::lang;
      59             :     using namespace ::com::sun::star::sdb;
      60             :     using namespace ::com::sun::star::sdbc;
      61             :     using namespace ::com::sun::star::task;
      62             :     using namespace ::com::sun::star::beans;
      63             :     using namespace ::com::sun::star::sdbcx;
      64             :     using namespace ::com::sun::star::container;
      65             :     using namespace ::com::sun::star::frame;
      66             : 
      67             :     //=====================================================================
      68             :     struct PackageAccessControl { };
      69             : 
      70             :     //=====================================================================
      71             :     //---------------------------------------------------------------------
      72           0 :     static Reference< XDatabaseContext > lcl_getDataSourceContext( const Reference< XComponentContext >& _rxContext ) SAL_THROW (( Exception ))
      73             :     {
      74           0 :         Reference<XDatabaseContext> xContext = DatabaseContext::create(_rxContext);
      75           0 :         return xContext;
      76             :     }
      77             : 
      78             :     //---------------------------------------------------------------------
      79             :     /// creates a new data source and inserts it into the context
      80           0 :     static void lcl_implCreateAndInsert(
      81             :         const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rName,
      82             :         Reference< XPropertySet >& /* [out] */ _rxNewDataSource ) SAL_THROW (( ::com::sun::star::uno::Exception ))
      83             :     {
      84             :         //.............................................................
      85             :         // get the data source context
      86           0 :         Reference< XDatabaseContext > xContext = lcl_getDataSourceContext( _rxContext );
      87             : 
      88             :         DBG_ASSERT( !xContext->hasByName( _rName ), "lcl_implCreateAndInsert: name already used!" );
      89             :         (void)_rName;
      90             : 
      91             :         //.............................................................
      92             :         // create a new data source
      93           0 :         Reference< XSingleServiceFactory > xFactory( xContext, UNO_QUERY );
      94           0 :         Reference< XPropertySet > xNewDataSource;
      95           0 :         if (xFactory.is())
      96           0 :             xNewDataSource = Reference< XPropertySet >( xFactory->createInstance(), UNO_QUERY );
      97             :         DBG_ASSERT( xNewDataSource.is(), "lcl_implCreateAndInsert: could not create a new data source!" );
      98             : 
      99             :         //.............................................................
     100             :         // insert the data source into the context
     101           0 :         Reference< XNamingService > xDynamicContext( xContext, UNO_QUERY );
     102             :         DBG_ASSERT( xDynamicContext.is(), "lcl_implCreateAndInsert: missing an interface on the context (XNamingService)!" );
     103           0 :         if (xDynamicContext.is())
     104             :         {
     105             :             //  xDynamicContext->registerObject( _rName, xNewDataSource );
     106           0 :             _rxNewDataSource = xNewDataSource;
     107           0 :         }
     108           0 :     }
     109             : 
     110             :     //---------------------------------------------------------------------
     111             :     /// creates and inserts a data source, and sets it's URL property to the string given
     112           0 :     static ODataSource lcl_implCreateAndSetURL(
     113             :         const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rName,
     114             :         const sal_Char* _pInitialAsciiURL ) SAL_THROW (( ))
     115             :     {
     116           0 :         ODataSource aReturn( _rxORB );
     117             :         try
     118             :         {
     119             :             // create the new data source
     120           0 :             Reference< XPropertySet > xNewDataSource;
     121           0 :             lcl_implCreateAndInsert( comphelper::getComponentContext(_rxORB), _rName, xNewDataSource );
     122             : 
     123             :             //.............................................................
     124             :             // set the URL property
     125           0 :             if (xNewDataSource.is())
     126             :             {
     127           0 :                 xNewDataSource->setPropertyValue(
     128             :                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "URL" )),
     129             :                     makeAny( ::rtl::OUString::createFromAscii( _pInitialAsciiURL ) )
     130           0 :                 );
     131             :             }
     132             : 
     133           0 :             aReturn.setDataSource( xNewDataSource, _rName,PackageAccessControl() );
     134             :         }
     135           0 :         catch(const Exception&)
     136             :         {
     137             :             OSL_FAIL( "lcl_implCreateAndSetURL: caught an exception while creating the data source!" );
     138             :         }
     139             : 
     140           0 :         return aReturn;
     141             :     }
     142             :     //---------------------------------------------------------------------
     143           0 :     void lcl_registerDataSource(
     144             :         const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _sName,
     145             :         const ::rtl::OUString& _sURL ) SAL_THROW (( ::com::sun::star::uno::Exception ))
     146             :     {
     147             :         OSL_ENSURE( !_sName.isEmpty(), "lcl_registerDataSource: invalid name!" );
     148             :         OSL_ENSURE( !_sURL.isEmpty(), "lcl_registerDataSource: invalid URL!" );
     149             :         try
     150             :         {
     151             :             Reference< XDatabaseContext > xRegistrations(
     152             :                 DatabaseContext::create(
     153           0 :                     comphelper::getComponentContext(_rxORB)));
     154           0 :             if ( xRegistrations->hasRegisteredDatabase( _sName ) )
     155           0 :                 xRegistrations->changeDatabaseLocation( _sName, _sURL );
     156             :             else
     157           0 :                 xRegistrations->registerDatabaseLocation( _sName, _sURL );
     158             :         }
     159           0 :         catch( const Exception& )
     160             :         {
     161             :             DBG_UNHANDLED_EXCEPTION();
     162             :         }
     163           0 :     }
     164             : 
     165             :     //=====================================================================
     166             :     //= ODataSourceContextImpl
     167             :     //=====================================================================
     168             :     struct ODataSourceContextImpl
     169             :     {
     170             :         Reference< XMultiServiceFactory >   xORB;
     171             :         Reference< XNameAccess >            xContext;           /// the UNO data source context
     172             :         StringBag                           aDataSourceNames;   /// for quicker name checks (without the UNO overhead)
     173             : 
     174           0 :         ODataSourceContextImpl( const Reference< XMultiServiceFactory >& _rxORB ) : xORB( _rxORB ) { }
     175             :         ODataSourceContextImpl( const ODataSourceContextImpl& _rSource )
     176             :             :xORB       ( _rSource.xORB )
     177             :             ,xContext   ( _rSource.xContext )
     178             :         {
     179             :         }
     180             :     };
     181             : 
     182             :     //=====================================================================
     183             :     //= ODataSourceContext
     184             :     //=====================================================================
     185             :     //---------------------------------------------------------------------
     186           0 :     ODataSourceContext::ODataSourceContext(const Reference< XMultiServiceFactory >& _rxORB)
     187           0 :         :m_pImpl( new ODataSourceContextImpl( _rxORB ) )
     188             :     {
     189             :         try
     190             :         {
     191             :             // create the UNO context
     192             :             m_pImpl->xContext = Reference<XNameAccess>(
     193             :                       lcl_getDataSourceContext( comphelper::getComponentContext(_rxORB) ),
     194           0 :                       UNO_QUERY_THROW);
     195             : 
     196           0 :             if (m_pImpl->xContext.is())
     197             :             {
     198             :                 // collect the data source names
     199           0 :                 Sequence< ::rtl::OUString > aDSNames = m_pImpl->xContext->getElementNames();
     200           0 :                 const ::rtl::OUString* pDSNames = aDSNames.getConstArray();
     201           0 :                 const ::rtl::OUString* pDSNamesEnd = pDSNames + aDSNames.getLength();
     202             : 
     203           0 :                 for ( ;pDSNames != pDSNamesEnd; ++pDSNames )
     204           0 :                     m_pImpl->aDataSourceNames.insert( *pDSNames );
     205             :             }
     206             :         }
     207           0 :         catch( const Exception& )
     208             :         {
     209             :             OSL_FAIL( "ODataSourceContext::ODataSourceContext: caught an exception!" );
     210             :         }
     211           0 :     }
     212             : 
     213             :     //---------------------------------------------------------------------
     214           0 :     ::rtl::OUString& ODataSourceContext::disambiguate(::rtl::OUString& _rDataSourceName)
     215             :     {
     216           0 :         ::rtl::OUString sCheck( _rDataSourceName );
     217           0 :         ConstStringBagIterator aPos = m_pImpl->aDataSourceNames.find( sCheck );
     218             : 
     219           0 :         sal_Int32 nPostFix = 1;
     220           0 :         while ( ( m_pImpl->aDataSourceNames.end() != aPos ) && ( nPostFix < 65535 ) )
     221             :         {   // there already is a data source with this name
     222           0 :             sCheck = _rDataSourceName;
     223           0 :             sCheck += ::rtl::OUString::valueOf( nPostFix++ );
     224             : 
     225           0 :             aPos = m_pImpl->aDataSourceNames.find( sCheck );
     226             :         }
     227             : 
     228           0 :         _rDataSourceName = sCheck;
     229           0 :         return _rDataSourceName;
     230             :     }
     231             : 
     232             :     //---------------------------------------------------------------------
     233           0 :     void ODataSourceContext::getDataSourceNames( StringBag& _rNames ) const SAL_THROW (( ))
     234             :     {
     235           0 :         _rNames = m_pImpl->aDataSourceNames;
     236           0 :     }
     237             : 
     238             :     //---------------------------------------------------------------------
     239           0 :     ODataSource ODataSourceContext::createNewLDAP( const ::rtl::OUString& _rName) SAL_THROW (( ))
     240             :     {
     241           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:ldap:" );
     242             :     }
     243             : 
     244             :     //---------------------------------------------------------------------
     245           0 :     ODataSource ODataSourceContext::createNewMORK( const ::rtl::OUString& _rName) SAL_THROW (( ))
     246             :     {
     247           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:mozilla" );
     248             :     }
     249             : 
     250             :     //---------------------------------------------------------------------
     251           0 :     ODataSource ODataSourceContext::createNewThunderbird( const ::rtl::OUString& _rName ) SAL_THROW (( ))
     252             :     {
     253           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:thunderbird" );
     254             :     }
     255             : 
     256             :     //---------------------------------------------------------------------
     257           0 :     ODataSource ODataSourceContext::createNewEvolutionLdap( const ::rtl::OUString& _rName) SAL_THROW (( ))
     258             :     {
     259           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:evolution:ldap" );
     260             :     }
     261             :     //---------------------------------------------------------------------
     262           0 :     ODataSource ODataSourceContext::createNewEvolutionGroupwise( const ::rtl::OUString& _rName) SAL_THROW (( ))
     263             :     {
     264           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:evolution:groupwise" );
     265             :     }
     266             :     //---------------------------------------------------------------------
     267           0 :     ODataSource ODataSourceContext::createNewEvolution( const ::rtl::OUString& _rName) SAL_THROW (( ))
     268             :     {
     269           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:evolution:local" );
     270             :     }
     271             : 
     272             :     //---------------------------------------------------------------------
     273           0 :     ODataSource ODataSourceContext::createNewKab( const ::rtl::OUString& _rName) SAL_THROW (( ))
     274             :     {
     275           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:kab" );
     276             :     }
     277             : 
     278             :     //---------------------------------------------------------------------
     279           0 :     ODataSource ODataSourceContext::createNewMacab( const ::rtl::OUString& _rName) SAL_THROW (( ))
     280             :     {
     281           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:macab" );
     282             :     }
     283             : 
     284             :     //---------------------------------------------------------------------
     285           0 :     ODataSource ODataSourceContext::createNewOutlook( const ::rtl::OUString& _rName) SAL_THROW (( ))
     286             :     {
     287           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:outlook" );
     288             :     }
     289             : 
     290             :     //---------------------------------------------------------------------
     291           0 :     ODataSource ODataSourceContext::createNewOE( const ::rtl::OUString& _rName) SAL_THROW (( ))
     292             :     {
     293           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:address:outlookexp" );
     294             :     }
     295             : 
     296             :     //---------------------------------------------------------------------
     297           0 :     ODataSource ODataSourceContext::createNewDBase( const ::rtl::OUString& _rName) SAL_THROW (( ))
     298             :     {
     299           0 :         return lcl_implCreateAndSetURL( m_pImpl->xORB, _rName, "sdbc:dbase:" );
     300             :     }
     301             : 
     302             :     //=====================================================================
     303             :     //= ODataSourceImpl
     304             :     //=====================================================================
     305           0 :     struct ODataSourceImpl
     306             :     {
     307             :     public:
     308             :         Reference< XMultiServiceFactory >       xORB;               /// the service factory
     309             :         Reference< XPropertySet >               xDataSource;        /// the UNO data source
     310             :         ::utl::SharedUNOComponent< XConnection >
     311             :                                                 xConnection;
     312             :         StringBag                               aTables;            // the cached table names
     313             :         ::rtl::OUString                         sName;
     314             :         sal_Bool                                bTablesUpToDate;    // table name cache up-to-date?
     315             : 
     316           0 :         ODataSourceImpl( const Reference< XMultiServiceFactory >& _rxORB )
     317             :             :xORB( _rxORB )
     318           0 :             ,bTablesUpToDate( sal_False )
     319             :         {
     320           0 :         }
     321             : 
     322             :         ODataSourceImpl( const ODataSourceImpl& _rSource );
     323             :     };
     324             : 
     325             :     //---------------------------------------------------------------------
     326           0 :     ODataSourceImpl::ODataSourceImpl( const ODataSourceImpl& _rSource )
     327             :         :xORB( _rSource.xORB )
     328             :         ,xDataSource( _rSource.xDataSource )
     329             :         ,xConnection( _rSource.xConnection )
     330             :         ,aTables( _rSource.aTables )
     331             :         ,sName( _rSource.sName )
     332           0 :         ,bTablesUpToDate( _rSource.bTablesUpToDate )
     333             :     {
     334           0 :     }
     335             : 
     336             :     //=====================================================================
     337             :     //= ODataSource
     338             :     //=====================================================================
     339             :     //---------------------------------------------------------------------
     340           0 :     ODataSource::ODataSource( const ODataSource& _rSource )
     341           0 :         :m_pImpl( NULL )
     342             :     {
     343           0 :         *this = _rSource;
     344           0 :     }
     345             : 
     346             :     //---------------------------------------------------------------------
     347           0 :     ODataSource& ODataSource::operator=( const ODataSource& _rSource )
     348             :     {
     349           0 :         if( this != &_rSource )
     350             :         {
     351           0 :             delete m_pImpl;
     352           0 :             m_pImpl = new ODataSourceImpl( *_rSource.m_pImpl );
     353             :         }
     354           0 :         return *this;
     355             :     }
     356             : 
     357             :     //---------------------------------------------------------------------
     358           0 :     ODataSource::ODataSource( const Reference< XMultiServiceFactory >& _rxORB )
     359           0 :         :m_pImpl(new ODataSourceImpl(_rxORB))
     360             :     {
     361           0 :     }
     362             : 
     363             :     //---------------------------------------------------------------------
     364           0 :     ODataSource::~ODataSource( )
     365             :     {
     366           0 :         delete m_pImpl;
     367           0 :     }
     368             : 
     369             :     //---------------------------------------------------------------------
     370           0 :     void ODataSource::store() SAL_THROW (( ))
     371             :     {
     372           0 :         if (!isValid())
     373             :             // nothing to do
     374           0 :             return;
     375             :         try
     376             :         {
     377           0 :             Reference< XDocumentDataSource > xDocAccess( m_pImpl->xDataSource, UNO_QUERY );
     378           0 :             Reference< XStorable > xStorable;
     379           0 :             if ( xDocAccess.is() )
     380           0 :                 xStorable = xStorable.query( xDocAccess->getDatabaseDocument() );
     381             :             OSL_ENSURE( xStorable.is(),"DataSource is no XStorable!" );
     382           0 :             if ( xStorable.is() )
     383           0 :                 xStorable->storeAsURL(m_pImpl->sName,Sequence<PropertyValue>());
     384             :         }
     385           0 :         catch(const Exception&)
     386             :         {
     387             :             OSL_FAIL( "ODataSource::registerDataSource: caught an exception while creating the data source!" );
     388             :         }
     389             :     }
     390             :     //---------------------------------------------------------------------
     391           0 :     void ODataSource::registerDataSource( const ::rtl::OUString& _sRegisteredDataSourceName) SAL_THROW (( ))
     392             :     {
     393           0 :         if (!isValid())
     394             :             // nothing to do
     395           0 :             return;
     396             : 
     397             :         try
     398             :         {
     399             :             // invalidate ourself
     400           0 :             lcl_registerDataSource(m_pImpl->xORB,_sRegisteredDataSourceName,m_pImpl->sName);
     401             :         }
     402           0 :         catch(const Exception&)
     403             :         {
     404             :             OSL_FAIL( "ODataSource::registerDataSource: caught an exception while creating the data source!" );
     405             :         }
     406             :     }
     407             : 
     408             :     //---------------------------------------------------------------------
     409           0 :     void ODataSource::setDataSource( const Reference< XPropertySet >& _rxDS,const ::rtl::OUString& _sName, PackageAccessControl )
     410             :     {
     411           0 :         if (m_pImpl->xDataSource.get() == _rxDS.get())
     412             :             // nothing to do
     413           0 :             return;
     414             : 
     415           0 :         if ( isConnected() )
     416           0 :             disconnect();
     417             : 
     418           0 :         m_pImpl->sName = _sName;
     419           0 :         m_pImpl->xDataSource = _rxDS;
     420             :     }
     421             : 
     422             :     //---------------------------------------------------------------------
     423           0 :     void ODataSource::remove() SAL_THROW (( ))
     424             :     {
     425           0 :         if (!isValid())
     426             :             // nothing to do
     427           0 :             return;
     428             : 
     429             :         try
     430             :         {
     431             :             // invalidate ourself
     432           0 :             m_pImpl->xDataSource.clear();
     433             :         }
     434           0 :         catch(const Exception&)
     435             :         {
     436             :             OSL_FAIL( "ODataSource::remove: caught an exception while creating the data source!" );
     437             :         }
     438             :     }
     439             : 
     440             :     //---------------------------------------------------------------------
     441           0 :     sal_Bool ODataSource::rename( const ::rtl::OUString& _rName ) SAL_THROW (( ))
     442             :     {
     443           0 :         if (!isValid())
     444             :             // nothing to do
     445           0 :             return sal_False;
     446             : 
     447           0 :         m_pImpl->sName = _rName;
     448           0 :         return sal_True;
     449             :     }
     450             : 
     451             :     //---------------------------------------------------------------------
     452           0 :     ::rtl::OUString ODataSource::getName() const SAL_THROW (( ))
     453             :     {
     454           0 :         if ( !isValid() )
     455           0 :             return ::rtl::OUString();
     456           0 :         return m_pImpl->sName;
     457             :     }
     458             : 
     459             :     //---------------------------------------------------------------------
     460           0 :     bool ODataSource::hasTable( const ::rtl::OUString& _rTableName ) const
     461             :     {
     462           0 :         if ( !isConnected() )
     463           0 :             return false;
     464             : 
     465           0 :         const StringBag& aTables( getTableNames() );
     466           0 :         return aTables.find( _rTableName ) != aTables.end();
     467             :     }
     468             : 
     469             :     //---------------------------------------------------------------------
     470           0 :     const StringBag& ODataSource::getTableNames() const SAL_THROW (( ))
     471             :     {
     472           0 :         m_pImpl->aTables.clear();
     473           0 :         if ( !isConnected() )
     474             :         {
     475             :             OSL_FAIL( "ODataSource::getTableNames: not connected!" );
     476             :         }
     477             :         else
     478             :         {
     479             :             try
     480             :             {
     481             :                 // get the tables container from the connection
     482           0 :                 Reference< XTablesSupplier > xSuppTables( m_pImpl->xConnection.getTyped(), UNO_QUERY );
     483           0 :                 Reference< XNameAccess > xTables;
     484           0 :                 if ( xSuppTables.is( ) )
     485           0 :                     xTables = xSuppTables->getTables();
     486             :                 DBG_ASSERT( xTables.is(), "ODataSource::getTableNames: could not retrieve the tables container!" );
     487             : 
     488             :                 // get the names
     489           0 :                 Sequence< ::rtl::OUString > aTableNames;
     490           0 :                 if ( xTables.is( ) )
     491           0 :                     aTableNames = xTables->getElementNames( );
     492             : 
     493             :                 // copy the names
     494           0 :                 const ::rtl::OUString* pTableNames = aTableNames.getConstArray();
     495           0 :                 const ::rtl::OUString* pTableNamesEnd = pTableNames + aTableNames.getLength();
     496           0 :                 for (;pTableNames < pTableNamesEnd; ++pTableNames)
     497           0 :                     m_pImpl->aTables.insert( *pTableNames );
     498             :             }
     499           0 :             catch(const Exception&)
     500             :             {
     501             :             }
     502             :         }
     503             : 
     504             :         // now the table cache is up-to-date
     505           0 :         m_pImpl->bTablesUpToDate = sal_True;
     506           0 :         return m_pImpl->aTables;
     507             :     }
     508             : 
     509             :     //---------------------------------------------------------------------
     510           0 :     sal_Bool ODataSource::connect( Window* _pMessageParent ) SAL_THROW (( ))
     511             :     {
     512           0 :         if ( isConnected( ) )
     513             :             // nothing to do
     514           0 :             return sal_True;
     515             : 
     516             :         // ................................................................
     517             :         // create the interaction handler (needed for authentication and error handling)
     518           0 :         Reference< XInteractionHandler > xInteractions;
     519             :         try
     520             :         {
     521             :             xInteractions.set(
     522             :                 InteractionHandler::createWithParent(comphelper::getComponentContext(m_pImpl->xORB), 0),
     523           0 :                 UNO_QUERY);
     524             :         }
     525           0 :         catch(const Exception&)
     526             :         {
     527             :         }
     528             : 
     529             :         // ................................................................
     530             :         // failure to create the interaction handler is a serious issue ...
     531           0 :         if (!xInteractions.is())
     532             :         {
     533           0 :             ::rtl::OUString s_sInteractionHandlerServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler"));
     534           0 :             if ( _pMessageParent )
     535           0 :                 ShowServiceNotAvailableError( _pMessageParent, s_sInteractionHandlerServiceName, sal_True );
     536           0 :             return sal_False;
     537             :         }
     538             : 
     539             :         // ................................................................
     540             :         // open the connection
     541           0 :         Any aError;
     542           0 :         Reference< XConnection > xConnection;
     543             :         try
     544             :         {
     545           0 :             Reference< XCompletedConnection > xComplConn( m_pImpl->xDataSource, UNO_QUERY );
     546             :             DBG_ASSERT( xComplConn.is(), "ODataSource::connect: missing the XCompletedConnection interface on the data source!" );
     547           0 :             if ( xComplConn.is() )
     548           0 :                 xConnection = xComplConn->connectWithCompletion( xInteractions );
     549             :         }
     550           0 :         catch( const SQLContext& e ) { aError <<= e; }
     551           0 :         catch( const SQLWarning& e ) { aError <<= e; }
     552           0 :         catch( const SQLException& e ) { aError <<= e; }
     553           0 :         catch( const Exception& )
     554             :         {
     555             :             OSL_FAIL( "ODataSource::connect: caught a generic exception!" );
     556             :         }
     557             : 
     558             :         // ................................................................
     559             :         // handle errors
     560           0 :         if ( aError.hasValue() && _pMessageParent )
     561             :         {
     562             :             try
     563             :             {
     564           0 :                 SQLException aException;
     565           0 :                   aError >>= aException;
     566           0 :                   if ( aException.Message.isEmpty() )
     567             :                   {
     568             :                     // prepend some context info
     569           0 :                     SQLContext aDetailedError;
     570           0 :                     aDetailedError.Message = String( ModuleRes( RID_STR_NOCONNECTION ) );
     571           0 :                     aDetailedError.Details = String( ModuleRes( RID_STR_PLEASECHECKSETTINGS ) );
     572           0 :                     aDetailedError.NextException = aError;
     573             :                     // handle (aka display) the new context info
     574           0 :                     xInteractions->handle( new OInteractionRequest( makeAny( aDetailedError ) ) );
     575             :                   }
     576             :                   else
     577             :                   {
     578             :                       // handle (aka display) the original error
     579           0 :                     xInteractions->handle( new OInteractionRequest( makeAny( aException ) ) );
     580           0 :                 }
     581             :             }
     582           0 :             catch( const Exception& )
     583             :             {
     584             :                 OSL_FAIL( "ODataSource::connect: caught an exception while trying to display the error!" );
     585             :             }
     586             :         }
     587             : 
     588           0 :         if ( !xConnection.is() )
     589           0 :             return sal_False;
     590             : 
     591             :         // ................................................................
     592             :         // success
     593           0 :         m_pImpl->xConnection.reset( xConnection );
     594           0 :         m_pImpl->aTables.clear();
     595           0 :         m_pImpl->bTablesUpToDate = sal_False;
     596             : 
     597           0 :         return sal_True;
     598             :     }
     599             : 
     600             :     //---------------------------------------------------------------------
     601           0 :     void ODataSource::disconnect( ) SAL_THROW (( ))
     602             :     {
     603           0 :         m_pImpl->xConnection.clear();
     604           0 :         m_pImpl->aTables.clear();
     605           0 :         m_pImpl->bTablesUpToDate = sal_False;
     606           0 :     }
     607             : 
     608             :     //---------------------------------------------------------------------
     609           0 :     sal_Bool ODataSource::isConnected( ) const SAL_THROW (( ))
     610             :     {
     611           0 :         return m_pImpl->xConnection.is();
     612             :     }
     613             : 
     614             :     //---------------------------------------------------------------------
     615           0 :     sal_Bool ODataSource::isValid() const SAL_THROW (( ))
     616             :     {
     617           0 :         return m_pImpl && m_pImpl->xDataSource.is();
     618             :     }
     619             :     //---------------------------------------------------------------------
     620           0 :     Reference< XPropertySet > ODataSource::getDataSource() const SAL_THROW (( ))
     621             :     {
     622           0 :         return m_pImpl ? m_pImpl->xDataSource : Reference< XPropertySet >();
     623             :     }
     624             : 
     625             : //.........................................................................
     626             : }   // namespace abp
     627             : //.........................................................................
     628             : 
     629             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10