LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - dapidata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 79 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #undef SC_DLLIMPLEMENTATION
      31                 :            : 
      32                 :            : 
      33                 :            : 
      34                 :            : //------------------------------------------------------------------
      35                 :            : 
      36                 :            : #include <vcl/waitobj.hxx>
      37                 :            : #include <comphelper/processfactory.hxx>
      38                 :            : 
      39                 :            : #include <com/sun/star/sheet/DataImportMode.hpp>
      40                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      41                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      42                 :            : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      43                 :            : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      44                 :            : 
      45                 :            : using namespace com::sun::star;
      46                 :            : 
      47                 :            : #include "dapidata.hxx"
      48                 :            : #include "scresid.hxx"
      49                 :            : #include "sc.hrc"
      50                 :            : #include "dapitype.hrc"
      51                 :            : #include "miscuno.hxx"
      52                 :            : #include "dpsdbtab.hxx"         // ScImportSourceDesc
      53                 :            : 
      54                 :            : //-------------------------------------------------------------------------
      55                 :            : 
      56                 :            : #define DP_SERVICE_DBCONTEXT        "com.sun.star.sdb.DatabaseContext"
      57                 :            : #define SC_SERVICE_INTHANDLER       "com.sun.star.task.InteractionHandler"
      58                 :            : 
      59                 :            : //  entries in the "type" ListBox
      60                 :            : #define DP_TYPELIST_TABLE   0
      61                 :            : #define DP_TYPELIST_QUERY   1
      62                 :            : #define DP_TYPELIST_SQL     2
      63                 :            : #define DP_TYPELIST_SQLNAT  3
      64                 :            : 
      65                 :            : //-------------------------------------------------------------------------
      66                 :            : 
      67                 :          0 : ScDataPilotDatabaseDlg::ScDataPilotDatabaseDlg( Window* pParent ) :
      68                 :            :     ModalDialog     ( pParent, ScResId( RID_SCDLG_DAPIDATA ) ),
      69                 :            :     //
      70                 :            :     aFlFrame        ( this, ScResId( FL_FRAME ) ),
      71                 :            :     aFtDatabase     ( this, ScResId( FT_DATABASE ) ),
      72                 :            :     aLbDatabase     ( this, ScResId( LB_DATABASE ) ),
      73                 :            :     aFtObject       ( this, ScResId( FT_OBJECT ) ),
      74                 :            :     aCbObject       ( this, ScResId( CB_OBJECT ) ),
      75                 :            :     aFtType         ( this, ScResId( FT_OBJTYPE ) ),
      76                 :            :     aLbType         ( this, ScResId( LB_OBJTYPE ) ),
      77                 :            :     aBtnOk          ( this, ScResId( BTN_OK ) ),
      78                 :            :     aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
      79                 :          0 :     aBtnHelp        ( this, ScResId( BTN_HELP ) )
      80                 :            : {
      81                 :          0 :     FreeResource();
      82                 :            : 
      83                 :          0 :     WaitObject aWait( this );       // initializing the database service the first time takes a while
      84                 :            : 
      85                 :            :     try
      86                 :            :     {
      87                 :            :         //  get database names
      88                 :            : 
      89                 :            :         uno::Reference<container::XNameAccess> xContext(
      90                 :          0 :                 comphelper::getProcessServiceFactory()->createInstance(
      91                 :          0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( DP_SERVICE_DBCONTEXT )) ),
      92                 :          0 :                 uno::UNO_QUERY);
      93                 :          0 :         if (xContext.is())
      94                 :            :         {
      95                 :          0 :             uno::Sequence<rtl::OUString> aNames = xContext->getElementNames();
      96                 :          0 :             long nCount = aNames.getLength();
      97                 :          0 :             const rtl::OUString* pArray = aNames.getConstArray();
      98                 :          0 :             for (long nPos = 0; nPos < nCount; nPos++)
      99                 :            :             {
     100                 :          0 :                 String aName = pArray[nPos];
     101                 :          0 :                 aLbDatabase.InsertEntry( aName );
     102                 :          0 :             }
     103                 :          0 :         }
     104                 :            :     }
     105                 :          0 :     catch(uno::Exception&)
     106                 :            :     {
     107                 :            :         OSL_FAIL("exception in database");
     108                 :            :     }
     109                 :            : 
     110                 :          0 :     aLbDatabase.SelectEntryPos( 0 );
     111                 :          0 :     aLbType.SelectEntryPos( 0 );
     112                 :            : 
     113                 :          0 :     FillObjects();
     114                 :            : 
     115                 :          0 :     aLbDatabase.SetSelectHdl( LINK( this, ScDataPilotDatabaseDlg, SelectHdl ) );
     116                 :          0 :     aLbType.SetSelectHdl( LINK( this, ScDataPilotDatabaseDlg, SelectHdl ) );
     117                 :          0 : }
     118                 :            : 
     119                 :          0 : ScDataPilotDatabaseDlg::~ScDataPilotDatabaseDlg()
     120                 :            : {
     121                 :          0 : }
     122                 :            : 
     123                 :          0 : void ScDataPilotDatabaseDlg::GetValues( ScImportSourceDesc& rDesc )
     124                 :            : {
     125                 :          0 :     sal_uInt16 nSelect = aLbType.GetSelectEntryPos();
     126                 :            : 
     127                 :          0 :     rDesc.aDBName = aLbDatabase.GetSelectEntry();
     128                 :          0 :     rDesc.aObject = aCbObject.GetText();
     129                 :            : 
     130                 :          0 :     if (rDesc.aDBName.isEmpty() || rDesc.aObject.isEmpty())
     131                 :          0 :         rDesc.nType = sheet::DataImportMode_NONE;
     132                 :          0 :     else if ( nSelect == DP_TYPELIST_TABLE )
     133                 :          0 :         rDesc.nType = sheet::DataImportMode_TABLE;
     134                 :          0 :     else if ( nSelect == DP_TYPELIST_QUERY )
     135                 :          0 :         rDesc.nType = sheet::DataImportMode_QUERY;
     136                 :            :     else
     137                 :          0 :         rDesc.nType = sheet::DataImportMode_SQL;
     138                 :            : 
     139                 :          0 :     rDesc.bNative = ( nSelect == DP_TYPELIST_SQLNAT );
     140                 :          0 : }
     141                 :            : 
     142                 :          0 : IMPL_LINK_NOARG(ScDataPilotDatabaseDlg, SelectHdl)
     143                 :            : {
     144                 :          0 :     FillObjects();
     145                 :          0 :     return 0;
     146                 :            : }
     147                 :            : 
     148                 :          0 : void ScDataPilotDatabaseDlg::FillObjects()
     149                 :            : {
     150                 :          0 :     aCbObject.Clear();
     151                 :            : 
     152                 :          0 :     String aDatabaseName = aLbDatabase.GetSelectEntry();
     153                 :          0 :     if (!aDatabaseName.Len())
     154                 :            :         return;
     155                 :            : 
     156                 :          0 :     sal_uInt16 nSelect = aLbType.GetSelectEntryPos();
     157                 :          0 :     if ( nSelect > DP_TYPELIST_QUERY )
     158                 :            :         return;                                 // only tables and queries
     159                 :            : 
     160                 :            :     try
     161                 :            :     {
     162                 :            :         //  open connection (for tables or queries)
     163                 :            : 
     164                 :            :         uno::Reference<container::XNameAccess> xContext(
     165                 :          0 :                 comphelper::getProcessServiceFactory()->createInstance(
     166                 :          0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( DP_SERVICE_DBCONTEXT )) ),
     167                 :          0 :                 uno::UNO_QUERY);
     168                 :          0 :         if ( !xContext.is() ) return;
     169                 :            : 
     170                 :          0 :         uno::Any aSourceAny = xContext->getByName( aDatabaseName );
     171                 :            :         uno::Reference<sdb::XCompletedConnection> xSource(
     172                 :          0 :                 ScUnoHelpFunctions::AnyToInterface( aSourceAny ), uno::UNO_QUERY );
     173                 :          0 :         if ( !xSource.is() ) return;
     174                 :            : 
     175                 :            :         uno::Reference<task::XInteractionHandler> xHandler(
     176                 :          0 :                 comphelper::getProcessServiceFactory()->createInstance(
     177                 :          0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_SERVICE_INTHANDLER )) ),
     178                 :          0 :                 uno::UNO_QUERY);
     179                 :            : 
     180                 :          0 :         uno::Reference<sdbc::XConnection> xConnection = xSource->connectWithCompletion( xHandler );
     181                 :            : 
     182                 :          0 :         uno::Sequence<rtl::OUString> aNames;
     183                 :          0 :         if ( nSelect == DP_TYPELIST_TABLE )
     184                 :            :         {
     185                 :            :             //  get all tables
     186                 :            : 
     187                 :          0 :             uno::Reference<sdbcx::XTablesSupplier> xTablesSupp( xConnection, uno::UNO_QUERY );
     188                 :          0 :             if ( !xTablesSupp.is() ) return;
     189                 :            : 
     190                 :          0 :             uno::Reference<container::XNameAccess> xTables = xTablesSupp->getTables();
     191                 :          0 :             if ( !xTables.is() ) return;
     192                 :            : 
     193                 :          0 :             aNames = xTables->getElementNames();
     194                 :            :         }
     195                 :            :         else
     196                 :            :         {
     197                 :            :             //  get all queries
     198                 :            : 
     199                 :          0 :             uno::Reference<sdb::XQueriesSupplier> xQueriesSupp( xConnection, uno::UNO_QUERY );
     200                 :          0 :             if ( !xQueriesSupp.is() ) return;
     201                 :            : 
     202                 :          0 :             uno::Reference<container::XNameAccess> xQueries = xQueriesSupp->getQueries();
     203                 :          0 :             if ( !xQueries.is() ) return;
     204                 :            : 
     205                 :          0 :             aNames = xQueries->getElementNames();
     206                 :            :         }
     207                 :            : 
     208                 :            :         //  fill list
     209                 :            : 
     210                 :          0 :         long nCount = aNames.getLength();
     211                 :          0 :         const rtl::OUString* pArray = aNames.getConstArray();
     212                 :          0 :         for( long nPos=0; nPos<nCount; nPos++ )
     213                 :            :         {
     214                 :          0 :             String aName = pArray[nPos];
     215                 :          0 :             aCbObject.InsertEntry( aName );
     216                 :          0 :         }
     217                 :            :     }
     218                 :          0 :     catch(uno::Exception&)
     219                 :            :     {
     220                 :            :         //  this may happen if an invalid database is selected -> no DBG_ERROR
     221                 :            :         OSL_FAIL("exception in database");
     222                 :          0 :     }
     223                 :          0 : }
     224                 :            : 
     225                 :            : 
     226                 :            : 
     227                 :            : 
     228                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10