LCOV - code coverage report
Current view: top level - dbaccess/source/ui/uno - copytablewizard.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 9 562 1.6 %
Date: 2014-11-03 Functions: 5 65 7.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dbu_reghelper.hxx"
      21             : #include "dbu_resource.hrc"
      22             : #include "dbu_uno.hrc"
      23             : #include "dbustrings.hrc"
      24             : #include "moduledbu.hxx"
      25             : #include "sqlmessage.hxx"
      26             : #include "uiservices.hxx"
      27             : #include "WCopyTable.hxx"
      28             : 
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/sdb/application/XCopyTableWizard.hpp>
      31             : #include <com/sun/star/sdb/application/CopyTableContinuation.hpp>
      32             : #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
      33             : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
      34             : #include <com/sun/star/lang/NotInitializedException.hpp>
      35             : #include <com/sun/star/sdbc/XDataSource.hpp>
      36             : #include <com/sun/star/sdbc/DataType.hpp>
      37             : #include <com/sun/star/container/XNameAccess.hpp>
      38             : #include <com/sun/star/container/XChild.hpp>
      39             : #include <com/sun/star/task/InteractionHandler.hpp>
      40             : #include <com/sun/star/frame/XModel.hpp>
      41             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      42             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      43             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      44             : #include <com/sun/star/sdb/CommandType.hpp>
      45             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      46             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      47             : #include <com/sun/star/lang/DisposedException.hpp>
      48             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      49             : #include <com/sun/star/sdbc/XParameters.hpp>
      50             : #include <com/sun/star/sdbc/XRow.hpp>
      51             : #include <com/sun/star/sdbc/XBlob.hpp>
      52             : #include <com/sun/star/sdbc/XClob.hpp>
      53             : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      54             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      55             : #include <com/sun/star/sdb/SQLContext.hpp>
      56             : #include <com/sun/star/sdbc/DriverManager.hpp>
      57             : #include <com/sun/star/sdbc/ConnectionPool.hpp>
      58             : 
      59             : #include <comphelper/processfactory.hxx>
      60             : #include <comphelper/interaction.hxx>
      61             : #include <comphelper/namedvaluecollection.hxx>
      62             : #include <comphelper/proparrhlp.hxx>
      63             : #include <connectivity/dbexception.hxx>
      64             : #include <connectivity/dbtools.hxx>
      65             : #include <cppuhelper/exc_hlp.hxx>
      66             : #include <cppuhelper/implbase1.hxx>
      67             : #include <rtl/ustrbuf.hxx>
      68             : #include <svtools/genericunodialog.hxx>
      69             : #include <tools/diagnose_ex.h>
      70             : #include <unotools/sharedunocomponent.hxx>
      71             : #include <vcl/msgbox.hxx>
      72             : #include <vcl/waitobj.hxx>
      73             : 
      74             : namespace dbaui
      75             : {
      76             : 
      77             :     using ::com::sun::star::uno::Reference;
      78             :     using ::com::sun::star::uno::XInterface;
      79             :     using ::com::sun::star::uno::UNO_QUERY;
      80             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      81             :     using ::com::sun::star::uno::UNO_SET_THROW;
      82             :     using ::com::sun::star::uno::Exception;
      83             :     using ::com::sun::star::uno::RuntimeException;
      84             :     using ::com::sun::star::uno::Any;
      85             :     using ::com::sun::star::uno::makeAny;
      86             :     using ::com::sun::star::uno::Sequence;
      87             :     using ::com::sun::star::uno::XComponentContext;
      88             :     using ::com::sun::star::beans::XPropertySetInfo;
      89             :     using ::com::sun::star::lang::XMultiServiceFactory;
      90             :     using ::com::sun::star::beans::Property;
      91             :     using ::com::sun::star::sdb::application::XCopyTableWizard;
      92             :     using ::com::sun::star::sdb::application::XCopyTableListener;
      93             :     using ::com::sun::star::sdb::application::CopyTableRowEvent;
      94             :     using ::com::sun::star::beans::Optional;
      95             :     using ::com::sun::star::lang::IllegalArgumentException;
      96             :     using ::com::sun::star::ucb::AlreadyInitializedException;
      97             :     using ::com::sun::star::beans::XPropertySet;
      98             :     using ::com::sun::star::lang::NotInitializedException;
      99             :     using ::com::sun::star::lang::XServiceInfo;
     100             :     using ::com::sun::star::sdbc::XConnection;
     101             :     using ::com::sun::star::sdbc::XDataSource;
     102             :     using ::com::sun::star::container::XNameAccess;
     103             :     using ::com::sun::star::container::XChild;
     104             :     using ::com::sun::star::task::InteractionHandler;
     105             :     using ::com::sun::star::task::XInteractionHandler;
     106             :     using ::com::sun::star::frame::XModel;
     107             :     using ::com::sun::star::sdb::DatabaseContext;
     108             :     using ::com::sun::star::sdb::XDatabaseContext;
     109             :     using ::com::sun::star::sdb::XDocumentDataSource;
     110             :     using ::com::sun::star::sdb::XCompletedConnection;
     111             :     using ::com::sun::star::lang::WrappedTargetException;
     112             :     using ::com::sun::star::sdbcx::XTablesSupplier;
     113             :     using ::com::sun::star::sdb::XQueriesSupplier;
     114             :     using ::com::sun::star::lang::DisposedException;
     115             :     using ::com::sun::star::sdbc::XPreparedStatement;
     116             :     using ::com::sun::star::sdb::XSingleSelectQueryComposer;
     117             :     using ::com::sun::star::sdbc::XDatabaseMetaData;
     118             :     using ::com::sun::star::sdbcx::XColumnsSupplier;
     119             :     using ::com::sun::star::sdbc::XParameters;
     120             :     using ::com::sun::star::sdbc::XResultSet;
     121             :     using ::com::sun::star::sdbc::XRow;
     122             :     using ::com::sun::star::sdbc::XBlob;
     123             :     using ::com::sun::star::sdbc::XClob;
     124             :     using ::com::sun::star::sdbcx::XRowLocate;
     125             :     using ::com::sun::star::sdbc::XResultSetMetaDataSupplier;
     126             :     using ::com::sun::star::sdbc::XResultSetMetaData;
     127             :     using ::com::sun::star::sdbc::SQLException;
     128             :     using ::com::sun::star::sdb::SQLContext;
     129             :     using ::com::sun::star::sdbc::ConnectionPool;
     130             :     using ::com::sun::star::sdbc::XConnectionPool;
     131             :     using ::com::sun::star::sdbc::XDriverManager;
     132             :     using ::com::sun::star::sdbc::DriverManager;
     133             :     using ::com::sun::star::beans::PropertyValue;
     134             : 
     135             :     namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
     136             :     namespace CopyTableContinuation = ::com::sun::star::sdb::application::CopyTableContinuation;
     137             :     namespace CommandType = ::com::sun::star::sdb::CommandType;
     138             :     namespace DataType = ::com::sun::star::sdbc::DataType;
     139             : 
     140             :     typedef ::utl::SharedUNOComponent< XConnection >    SharedConnection;
     141             : 
     142             :     // CopyTableWizard
     143             :     typedef ::svt::OGenericUnoDialog        CopyTableWizard_DialogBase;
     144             :     typedef ::cppu::ImplInheritanceHelper1  <   CopyTableWizard_DialogBase
     145             :                                             ,   XCopyTableWizard
     146             :                                             >   CopyTableWizard_Base;
     147             :     class CopyTableWizard
     148             :             :public CopyTableWizard_Base
     149             :             ,public ::comphelper::OPropertyArrayUsageHelper< CopyTableWizard >
     150             :     {
     151             :     public:
     152             :         // XServiceInfo
     153             :         virtual OUString SAL_CALL getImplementationName() throw(RuntimeException, std::exception) SAL_OVERRIDE;
     154             :         virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(RuntimeException, std::exception) SAL_OVERRIDE;
     155             : 
     156             :         // XServiceInfo - static methods
     157             :         static Sequence< OUString >  getSupportedServiceNames_Static(void) throw( RuntimeException );
     158             :         static OUString              getImplementationName_Static(void) throw( RuntimeException );
     159             :         static Reference< XInterface >      Create( const Reference< XMultiServiceFactory >& );
     160             : 
     161             :         // XCopyTableWizard
     162             :         virtual ::sal_Int16 SAL_CALL getOperation() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     163             :         virtual void SAL_CALL setOperation( ::sal_Int16 _operation ) throw (IllegalArgumentException, RuntimeException, std::exception) SAL_OVERRIDE;
     164             :         virtual OUString SAL_CALL getDestinationTableName() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     165             :         virtual void SAL_CALL setDestinationTableName( const OUString& _destinationTableName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     166             :         virtual Optional< OUString > SAL_CALL getCreatePrimaryKey() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     167             :         virtual void SAL_CALL setCreatePrimaryKey( const Optional< OUString >& _newPrimaryKey ) throw (IllegalArgumentException, SQLException, RuntimeException, std::exception) SAL_OVERRIDE;
     168             :         virtual sal_Bool SAL_CALL getUseHeaderLineAsColumnNames() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     169             :         virtual void SAL_CALL setUseHeaderLineAsColumnNames( sal_Bool _bUseHeaderLineAsColumnNames ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     170             :         virtual void SAL_CALL addCopyTableListener( const Reference< XCopyTableListener >& Listener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     171             :         virtual void SAL_CALL removeCopyTableListener( const Reference< XCopyTableListener >& Listener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     172             : 
     173             :         // XCopyTableWizard::XExecutableDialog
     174             :         virtual void SAL_CALL setTitle( const OUString& aTitle ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     175             :         virtual ::sal_Int16 SAL_CALL execute(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     176             : 
     177             :         // XInitialization
     178             :         virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException, std::exception) SAL_OVERRIDE;
     179             : 
     180             :         // XPropertySet
     181             :         virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException, std::exception) SAL_OVERRIDE;
     182             :         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
     183             : 
     184             :         // OPropertyArrayUsageHelper
     185             :         virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE;
     186             : 
     187             :     public:
     188           0 :         ::osl::Mutex&   getMutex() { return m_aMutex; }
     189           0 :         bool            isInitialized() const { return m_xSourceConnection.is() && m_pSourceObject.get() && m_xDestConnection.is(); }
     190             : 
     191             :     protected:
     192             :         CopyTableWizard( const Reference< XComponentContext >& _rxORB );
     193             :         virtual ~CopyTableWizard();
     194             : 
     195             :         // OGenericUnoDialog overridables
     196             :         virtual Dialog* createDialog( vcl::Window* _pParent ) SAL_OVERRIDE;
     197             :         virtual void executedDialog( sal_Int16 _nExecutionResult ) SAL_OVERRIDE;
     198             : 
     199             :     private:
     200             :         /// ensures our current attribute values are reflected in the dialog
     201             :         void    impl_attributesToDialog_nothrow( OCopyTableWizard& _rDialog ) const;
     202             : 
     203             :         /// ensures the current dialog settings are reflected in our attributes
     204             :         void    impl_dialogToAttributes_nothrow( const OCopyTableWizard& _rDialog );
     205             : 
     206             :         /** returns our typed dialog
     207             : 
     208             :             @throws ::com::sun::star::uno::RuntimeException
     209             :                 if we don't have a dialog at the moment the method is called
     210             :         */
     211             :         OCopyTableWizard&
     212             :                 impl_getDialog_throw();
     213             : 
     214             :         /** ensures the given argument sequence contains a valid data access descriptor at the given position
     215             :             @param _rAllArgs
     216             :                 the arguments as passed to ->initialize
     217             :             @param _nArgPos
     218             :                 the position within ->_rAllArgs which contains the data access descriptor
     219             :             @param _out_rxConnection
     220             :                 will, upon successful return, contain the connection for the data source
     221             :             @param _out_rxDocInteractionHandler
     222             :                 will, upon successful return, contain the interaction handler which could
     223             :                 be deduced from database document described by the descriptor, if any.
     224             :                 (It is possible that the descriptor does not allow to deduce a database document,
     225             :                 in which case <code>_out_rxDocInteractionHandler</code> will be <NULL/>.)
     226             :             @return the data access descriptor
     227             :         */
     228             :         Reference< XPropertySet >
     229             :                 impl_ensureDataAccessDescriptor_throw(
     230             :                     const Sequence< Any >& _rAllArgs,
     231             :                     const sal_Int16 _nArgPos,
     232             :                     SharedConnection& _out_rxConnection,
     233             :                     Reference< XInteractionHandler >& _out_rxDocInteractionHandler
     234             :                 ) const;
     235             : 
     236             :         /** extracts the source object (table or query) described by the given descriptor,
     237             :             relative to m_xSourceConnection
     238             :         */
     239             :         ::std::unique_ptr< ICopyTableSourceObject >
     240             :                 impl_extractSourceObject_throw(
     241             :                     const Reference< XPropertySet >& _rxDescriptor,
     242             :                     sal_Int32& _out_rCommandType
     243             :                 ) const;
     244             : 
     245             :         /** extracts the result set to copy records from, and the selection-related aspects, if any.
     246             : 
     247             :             Effectively, this method extracts m_xSourceResultSet, m_aSourceSelection, and m_bSourceSelectionBookmarks.
     248             : 
     249             :             If an inconsistent/insufficent sub set of those properties is present in the descriptor, and exception
     250             :             is thrown.
     251             :         */
     252             :         void    impl_extractSourceResultSet_throw(
     253             :                     const Reference< XPropertySet >& i_rDescriptor
     254             :                 );
     255             : 
     256             :         /** checks whether the given copy source descriptor contains settings which are not
     257             :             supported (yet)
     258             : 
     259             :             Throws an IllegalArgumentException if the descriptor contains a valid setting, which is
     260             :             not yet supported.
     261             :         */
     262             :         void    impl_checkForUnsupportedSettings_throw(
     263             :             const Reference< XPropertySet >& _rxSourceDescriptor ) const;
     264             : 
     265             :         /** obtaines the connection described by the given data access descriptor
     266             : 
     267             :             If needed and possible, the method will ask the user, using the interaction
     268             :             handler associated with the database described by the descriptor.
     269             : 
     270             :             All errors are handled with the InteractionHandler associated with the data source,
     271             :             if there is one. Else, they will be silenced (but asserted in non-product builds).
     272             : 
     273             :             @param _rxDataSourceDescriptor
     274             :                 the data access descriptor describing the data source whose connection
     275             :                 should be obtained. Must not be <NULL/>.
     276             :             @param _out_rxDocInteractionHandler
     277             :                 the interaction handler which could be deduced from the descriptor
     278             : 
     279             :             @throws RuntimeException
     280             :                 if anything goes seriously wrong.
     281             :         */
     282             :         SharedConnection
     283             :                 impl_extractConnection_throw(
     284             :                     const Reference< XPropertySet >& _rxDataSourceDescriptor,
     285             :                     Reference< XInteractionHandler >& _out_rxDocInteractionHandler
     286             :                 ) const;
     287             : 
     288             :         /** actually copies the table
     289             : 
     290             :             This method is called after the dialog has been successfully executed.
     291             :         */
     292             :         void    impl_doCopy_nothrow();
     293             : 
     294             :         /** creates the INSERT INTO statement
     295             :             @param  _xTable The destination table.
     296             :         */
     297             :         OUString impl_getServerSideCopyStatement_throw( const Reference< XPropertySet >& _xTable );
     298             : 
     299             :         /** creates the statement which, when executed, will produce the source data to copy
     300             : 
     301             :             If the source object refers to a query which contains parameters, those parameters
     302             :             are filled in, using an interaction handler.
     303             :         */
     304             :         ::utl::SharedUNOComponent< XPreparedStatement >
     305             :                 impl_createSourceStatement_throw() const;
     306             : 
     307             :         /** copies the data rows from the given source result set to the given destination table
     308             :         */
     309             :         void    impl_copyRows_throw(
     310             :                     const Reference< XResultSet >& _rxSourceResultSet,
     311             :                     const Reference< XPropertySet >& _rxDestTable
     312             :                 );
     313             : 
     314             :         /** processes an error which occurred during copying
     315             : 
     316             :             First, all listeners are ask. If a listener tells to cancel or continue copying, this is reported to the
     317             :             method's caller. If a listener tells to ask the user, this is done, and the user's decision is
     318             :             reported to the method's caller.
     319             : 
     320             :             @return
     321             :                 <TRUE/> if and only if copying should be continued.
     322             :         */
     323             :         bool    impl_processCopyError_nothrow(
     324             :                     const CopyTableRowEvent& _rEvent );
     325             : 
     326             : private:
     327             :         Reference<XComponentContext>    m_xContext;
     328             : 
     329             :         // attributes
     330             :         sal_Int16                       m_nOperation;
     331             :         OUString                        m_sDestinationTable;
     332             :         Optional< OUString >            m_aPrimaryKeyName;
     333             :         bool                        m_bUseHeaderLineAsColumnNames;
     334             : 
     335             :         // source
     336             :         SharedConnection                m_xSourceConnection;
     337             :         sal_Int32                       m_nCommandType;
     338             :         ::std::unique_ptr< ICopyTableSourceObject >
     339             :                                         m_pSourceObject;
     340             :         Reference< XResultSet >         m_xSourceResultSet;
     341             :         Sequence< Any >                 m_aSourceSelection;
     342             :         bool                        m_bSourceSelectionBookmarks;
     343             : 
     344             :         // destination
     345             :         SharedConnection                m_xDestConnection;
     346             : 
     347             :         // other
     348             :         Reference< XInteractionHandler > m_xInteractionHandler;
     349             :         ::cppu::OInterfaceContainerHelper
     350             :                                         m_aCopyTableListeners;
     351             :         sal_Int16                       m_nOverrideExecutionResult;
     352             :     };
     353             : 
     354             : // MethodGuard
     355             : class CopyTableAccessGuard
     356             : {
     357             : public:
     358           0 :     CopyTableAccessGuard( CopyTableWizard& _rWizard )
     359           0 :         :m_rWizard( _rWizard )
     360             :     {
     361           0 :         m_rWizard.getMutex().acquire();
     362           0 :         if ( !m_rWizard.isInitialized() )
     363           0 :             throw NotInitializedException();
     364           0 :     }
     365             : 
     366           0 :     ~CopyTableAccessGuard()
     367             :     {
     368           0 :         m_rWizard.getMutex().release();
     369           0 :     }
     370             : 
     371             : private:
     372             :     CopyTableWizard&    m_rWizard;
     373             : };
     374             : 
     375           0 : CopyTableWizard::CopyTableWizard( const Reference< XComponentContext >& _rxORB )
     376             :     :CopyTableWizard_Base( _rxORB )
     377             :     ,m_xContext( _rxORB )
     378             :     ,m_nOperation( CopyTableOperation::CopyDefinitionAndData )
     379             :     ,m_sDestinationTable()
     380             :     ,m_aPrimaryKeyName( sal_False,  "ID" )
     381             :     ,m_bUseHeaderLineAsColumnNames( true )
     382             :     ,m_xSourceConnection()
     383             :     ,m_nCommandType( CommandType::COMMAND )
     384             :     ,m_pSourceObject()
     385             :     ,m_xSourceResultSet()
     386             :     ,m_aSourceSelection()
     387             :     ,m_bSourceSelectionBookmarks( true )
     388             :     ,m_xDestConnection()
     389             :     ,m_aCopyTableListeners( m_aMutex )
     390           0 :     ,m_nOverrideExecutionResult( -1 )
     391             : {
     392           0 : }
     393             : 
     394           0 : CopyTableWizard::~CopyTableWizard()
     395             : {
     396           0 :     acquire();
     397             : 
     398             :     // protect some members whose dtor might potentially throw
     399           0 :     try { m_xSourceConnection.clear();  }
     400           0 :     catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     401           0 :     try { m_xDestConnection.clear();  }
     402           0 :     catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     403             : 
     404             :     // TODO: shouldn't we have explicit disposal support? If a listener is registered
     405             :     // at our instance, and perhaps holds this our instance by a hard ref, then we'll never
     406             :     // be destroyed.
     407             :     // However, adding XComponent support to the GenericUNODialog probably requires
     408             :     // some thinking - would it break existing clients which do not call a dispose, then?
     409           0 : }
     410             : 
     411           0 : Reference< XInterface > CopyTableWizard::Create( const Reference< XMultiServiceFactory >& _rxFactory )
     412             : {
     413           0 :     return *( new CopyTableWizard( comphelper::getComponentContext(_rxFactory) ) );
     414             : }
     415             : 
     416           0 : OUString SAL_CALL CopyTableWizard::getImplementationName() throw(RuntimeException, std::exception)
     417             : {
     418           0 :     return getImplementationName_Static();
     419             : }
     420             : 
     421          48 : OUString CopyTableWizard::getImplementationName_Static() throw(RuntimeException)
     422             : {
     423          48 :     return OUString( "org.openoffice.comp.dbu.CopyTableWizard" );
     424             : }
     425             : 
     426           0 : ::comphelper::StringSequence SAL_CALL CopyTableWizard::getSupportedServiceNames() throw(RuntimeException, std::exception)
     427             : {
     428           0 :     return getSupportedServiceNames_Static();
     429             : }
     430             : 
     431          24 : ::comphelper::StringSequence CopyTableWizard::getSupportedServiceNames_Static() throw(RuntimeException)
     432             : {
     433          24 :     ::comphelper::StringSequence aSupported(1);
     434          24 :     aSupported.getArray()[0] = "com.sun.star.sdb.application.CopyTableWizard";
     435          24 :     return aSupported;
     436             : }
     437             : 
     438           0 : Reference< XPropertySetInfo > SAL_CALL CopyTableWizard::getPropertySetInfo() throw(RuntimeException, std::exception)
     439             : {
     440           0 :     Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     441           0 :     return xInfo;
     442             : }
     443             : 
     444           0 : ::sal_Int16 SAL_CALL CopyTableWizard::getOperation() throw (RuntimeException, std::exception)
     445             : {
     446           0 :     CopyTableAccessGuard aGuard( *this );
     447           0 :     return m_nOperation;
     448             : }
     449             : 
     450           0 : void SAL_CALL CopyTableWizard::setOperation( ::sal_Int16 _operation ) throw (IllegalArgumentException, RuntimeException, std::exception)
     451             : {
     452           0 :     CopyTableAccessGuard aGuard( *this );
     453             : 
     454           0 :     if  (   ( _operation != CopyTableOperation::CopyDefinitionAndData )
     455           0 :         &&  ( _operation != CopyTableOperation::CopyDefinitionOnly )
     456           0 :         &&  ( _operation != CopyTableOperation::CreateAsView )
     457           0 :         &&  ( _operation != CopyTableOperation::AppendData )
     458             :         )
     459           0 :         throw IllegalArgumentException( OUString(), *this, 1 );
     460             : 
     461           0 :     if  (   ( _operation == CopyTableOperation::CreateAsView )
     462           0 :         &&  !OCopyTableWizard::supportsViews( m_xDestConnection )
     463             :         )
     464             :         throw IllegalArgumentException(
     465             :             OUString( ModuleRes( STR_CTW_NO_VIEWS_SUPPORT ) ),
     466             :             *this,
     467             :             1
     468           0 :         );
     469             : 
     470           0 :     m_nOperation = _operation;
     471           0 : }
     472             : 
     473           0 : OUString SAL_CALL CopyTableWizard::getDestinationTableName() throw (RuntimeException, std::exception)
     474             : {
     475           0 :     CopyTableAccessGuard aGuard( *this );
     476           0 :     return m_sDestinationTable;
     477             : }
     478             : 
     479           0 : void SAL_CALL CopyTableWizard::setDestinationTableName( const OUString& _destinationTableName ) throw (RuntimeException, std::exception)
     480             : {
     481           0 :     CopyTableAccessGuard aGuard( *this );
     482           0 :     m_sDestinationTable = _destinationTableName;
     483           0 : }
     484             : 
     485           0 : Optional< OUString > SAL_CALL CopyTableWizard::getCreatePrimaryKey() throw (RuntimeException, std::exception)
     486             : {
     487           0 :     CopyTableAccessGuard aGuard( *this );
     488           0 :     return m_aPrimaryKeyName;
     489             : }
     490             : 
     491           0 : void SAL_CALL CopyTableWizard::setCreatePrimaryKey( const Optional< OUString >& _newPrimaryKey ) throw (IllegalArgumentException, SQLException, RuntimeException, std::exception)
     492             : {
     493           0 :     CopyTableAccessGuard aGuard( *this );
     494             : 
     495           0 :     if ( _newPrimaryKey.IsPresent && !OCopyTableWizard::supportsPrimaryKey( m_xDestConnection ) )
     496             :         throw IllegalArgumentException(
     497             :                 OUString( ModuleRes( STR_CTW_NO_PRIMARY_KEY_SUPPORT ) ),
     498             :             *this,
     499             :             1
     500           0 :         );
     501             : 
     502           0 :     m_aPrimaryKeyName = _newPrimaryKey;
     503           0 : }
     504             : 
     505           0 : sal_Bool SAL_CALL CopyTableWizard::getUseHeaderLineAsColumnNames() throw (RuntimeException, std::exception)
     506             : {
     507           0 :     CopyTableAccessGuard aGuard( *this );
     508           0 :     return m_bUseHeaderLineAsColumnNames;
     509             : }
     510             : 
     511           0 : void SAL_CALL CopyTableWizard::setUseHeaderLineAsColumnNames( sal_Bool _bUseHeaderLineAsColumnNames ) throw (RuntimeException, std::exception)
     512             : {
     513           0 :     CopyTableAccessGuard aGuard( *this );
     514           0 :     m_bUseHeaderLineAsColumnNames = _bUseHeaderLineAsColumnNames;
     515           0 : }
     516             : 
     517           0 : void SAL_CALL CopyTableWizard::addCopyTableListener( const Reference< XCopyTableListener >& _rxListener ) throw (RuntimeException, std::exception)
     518             : {
     519           0 :     CopyTableAccessGuard aGuard( *this );
     520           0 :     if ( _rxListener.is() )
     521           0 :         m_aCopyTableListeners.addInterface( _rxListener );
     522           0 : }
     523             : 
     524           0 : void SAL_CALL CopyTableWizard::removeCopyTableListener( const Reference< XCopyTableListener >& _rxListener ) throw (RuntimeException, std::exception)
     525             : {
     526           0 :     CopyTableAccessGuard aGuard( *this );
     527           0 :     if ( _rxListener.is() )
     528           0 :         m_aCopyTableListeners.removeInterface( _rxListener );
     529           0 : }
     530             : 
     531           0 : void SAL_CALL CopyTableWizard::setTitle( const OUString& _rTitle ) throw (RuntimeException, std::exception)
     532             : {
     533           0 :     CopyTableAccessGuard aGuard( *this );
     534           0 :     CopyTableWizard_DialogBase::setTitle( _rTitle );
     535           0 : }
     536             : 
     537           0 : ::sal_Int16 SAL_CALL CopyTableWizard::execute(  ) throw (RuntimeException, std::exception)
     538             : {
     539           0 :     CopyTableAccessGuard aGuard( *this );
     540             : 
     541           0 :     m_nOverrideExecutionResult = -1;
     542           0 :     sal_Int16 nExecutionResult = CopyTableWizard_DialogBase::execute();
     543           0 :     if ( m_nOverrideExecutionResult )
     544           0 :         nExecutionResult = m_nOverrideExecutionResult;
     545             : 
     546           0 :     return nExecutionResult;
     547             : }
     548             : 
     549           0 : OCopyTableWizard& CopyTableWizard::impl_getDialog_throw()
     550             : {
     551           0 :     OCopyTableWizard* pWizard = dynamic_cast< OCopyTableWizard* >( m_pDialog );
     552           0 :     if ( !pWizard )
     553           0 :         throw DisposedException( OUString(), *this );
     554           0 :     return *pWizard;
     555             : }
     556             : 
     557           0 : void CopyTableWizard::impl_attributesToDialog_nothrow( OCopyTableWizard& _rDialog ) const
     558             : {
     559             :     // primary key column
     560           0 :     _rDialog.setCreatePrimaryKey( m_aPrimaryKeyName.IsPresent, m_aPrimaryKeyName.Value );
     561           0 :     _rDialog.setUseHeaderLine(m_bUseHeaderLineAsColumnNames);
     562             : 
     563             :     // everything else was passed at construction time already
     564           0 : }
     565             : 
     566           0 : void CopyTableWizard::impl_dialogToAttributes_nothrow( const OCopyTableWizard& _rDialog )
     567             : {
     568           0 :     m_aPrimaryKeyName.IsPresent = _rDialog.shouldCreatePrimaryKey();
     569           0 :     if ( m_aPrimaryKeyName.IsPresent )
     570           0 :         m_aPrimaryKeyName.Value = _rDialog.getPrimaryKeyName();
     571             :     else
     572           0 :         m_aPrimaryKeyName.Value = OUString();
     573             : 
     574           0 :     m_sDestinationTable = _rDialog.getName();
     575             : 
     576           0 :     m_nOperation = _rDialog.getOperation();
     577           0 :     m_bUseHeaderLineAsColumnNames = _rDialog.UseHeaderLine();
     578           0 : }
     579             : 
     580             : namespace
     581             : {
     582             :     /** tries to obtain the InteractionHandler associated with a given data source
     583             : 
     584             :         If the data source is a sdb-level data source, it will have a DatabaseDocument associated
     585             :         with it. This doocument may have an InteractionHandler used while loading it.
     586             : 
     587             :         @throws RuntimeException
     588             :             if it occurs during invoking any of the data source's methods, or if any of the involved
     589             :             components violates its contract by not providing the required interfaces
     590             :     */
     591           0 :     Reference< XInteractionHandler > lcl_getInteractionHandler_throw( const Reference< XDataSource >& _rxDataSource, const Reference< XInteractionHandler >& _rFallback )
     592             :     {
     593           0 :         Reference< XInteractionHandler > xHandler( _rFallback );
     594             : 
     595             :         // try to obtain the document model
     596           0 :         Reference< XModel > xDocumentModel;
     597           0 :         Reference< XDocumentDataSource > xDocDataSource( _rxDataSource, UNO_QUERY );
     598           0 :         if ( xDocDataSource.is() )
     599           0 :             xDocumentModel.set( xDocDataSource->getDatabaseDocument(), UNO_QUERY_THROW );
     600             : 
     601             :         // see whether the document model can provide a handler
     602           0 :         if ( xDocumentModel.is() )
     603             :         {
     604           0 :             ::comphelper::NamedValueCollection aModelArgs( xDocumentModel->getArgs() );
     605           0 :             xHandler = aModelArgs.getOrDefault( "InteractionHandler", xHandler );
     606             :         }
     607             : 
     608           0 :         return xHandler;
     609             :     }
     610             :     /** tries to obtain the InteractionHandler associated with a given connection
     611             : 
     612             :         If the connection belongs to a sdb-level data source, then this data source
     613             :         is examined for an interaction handler. Else, <NULL/> is returned.
     614             : 
     615             :         @throws RuntimeException
     616             :             if it occurs during invoking any of the data source's methods, or if any of the involved
     617             :             components violates its contract by not providing the required interfaces
     618             :     */
     619           0 :     Reference< XInteractionHandler > lcl_getInteractionHandler_throw( const Reference< XConnection >& _rxConnection, const Reference< XInteractionHandler >& _rFallback )
     620             :     {
     621             :         // try whether there is a data source which the connection belongs to
     622           0 :         Reference< XDataSource > xDataSource;
     623           0 :         Reference< XChild > xAsChild( _rxConnection, UNO_QUERY );
     624           0 :         if ( xAsChild.is() )
     625           0 :             xDataSource.set(xAsChild->getParent(), css::uno::UNO_QUERY);
     626             : 
     627           0 :         if ( xDataSource.is() )
     628           0 :             return lcl_getInteractionHandler_throw( xDataSource, _rFallback );
     629             : 
     630           0 :         return _rFallback;
     631             :     }
     632             : }
     633             : 
     634           0 : Reference< XPropertySet > CopyTableWizard::impl_ensureDataAccessDescriptor_throw(
     635             :     const Sequence< Any >& _rAllArgs, const sal_Int16 _nArgPos, SharedConnection& _out_rxConnection,
     636             :     Reference< XInteractionHandler >& _out_rxDocInteractionHandler ) const
     637             : {
     638           0 :     Reference< XPropertySet > xDescriptor;
     639           0 :     _rAllArgs[ _nArgPos ] >>= xDescriptor;
     640             : 
     641             :     // the descriptor must be non-NULL, of course
     642           0 :     bool bIsValid = xDescriptor.is();
     643             : 
     644             :     // it must support the proper service
     645           0 :     if ( bIsValid )
     646             :     {
     647           0 :         Reference< XServiceInfo > xSI( xDescriptor, UNO_QUERY );
     648           0 :         bIsValid =  (   xSI.is()
     649           0 :                     &&  xSI->supportsService( "com.sun.star.sdb.DataAccessDescriptor" ) );
     650             :     }
     651             : 
     652             :     // it must be able to provide a connection
     653           0 :     if ( bIsValid )
     654             :     {
     655           0 :         _out_rxConnection = impl_extractConnection_throw( xDescriptor, _out_rxDocInteractionHandler );
     656           0 :         bIsValid = _out_rxConnection.is();
     657             :     }
     658             : 
     659           0 :     if ( !bIsValid )
     660             :     {
     661             :         throw IllegalArgumentException(
     662             :             OUString( ModuleRes( STR_CTW_INVALID_DATA_ACCESS_DESCRIPTOR ) ),
     663             :             *const_cast< CopyTableWizard* >( this ),
     664             :             _nArgPos + 1
     665           0 :         );
     666             :     }
     667             : 
     668           0 :     return xDescriptor;
     669             : }
     670             : 
     671             : namespace
     672             : {
     673           0 :     bool lcl_hasNonEmptyStringValue_throw( const Reference< XPropertySet >& _rxDescriptor,
     674             :         const Reference< XPropertySetInfo > _rxPSI, const OUString& _rPropertyName )
     675             :     {
     676           0 :         OUString sValue;
     677           0 :         if ( _rxPSI->hasPropertyByName( _rPropertyName ) )
     678             :         {
     679           0 :             OSL_VERIFY( _rxDescriptor->getPropertyValue( _rPropertyName ) >>= sValue );
     680             :         }
     681           0 :         return !sValue.isEmpty();
     682             :     }
     683             : }
     684             : 
     685           0 : void CopyTableWizard::impl_checkForUnsupportedSettings_throw( const Reference< XPropertySet >& _rxSourceDescriptor ) const
     686             : {
     687             :     OSL_PRECOND( _rxSourceDescriptor.is(), "CopyTableWizard::impl_checkForUnsupportedSettings_throw: illegal argument!" );
     688           0 :     Reference< XPropertySetInfo > xPSI( _rxSourceDescriptor->getPropertySetInfo(), UNO_SET_THROW );
     689           0 :     OUString sUnsupportedSetting;
     690             : 
     691             :     const OUString aSettings[] = {
     692             :         OUString(PROPERTY_FILTER), OUString(PROPERTY_ORDER), OUString(PROPERTY_HAVING_CLAUSE), OUString(PROPERTY_GROUP_BY)
     693           0 :     };
     694           0 :     for ( size_t i=0; i < sizeof( aSettings ) / sizeof( aSettings[0] ); ++i )
     695             :     {
     696           0 :         if ( lcl_hasNonEmptyStringValue_throw( _rxSourceDescriptor, xPSI, aSettings[i] ) )
     697             :         {
     698           0 :             sUnsupportedSetting = aSettings[i];
     699           0 :             break;
     700             :         }
     701             :     }
     702             : 
     703           0 :     if ( !sUnsupportedSetting.isEmpty() )
     704             :     {
     705             :         OUString sMessage(
     706             :             OUString(ModuleRes(STR_CTW_ERROR_UNSUPPORTED_SETTING)).
     707           0 :             replaceFirst("$name$", sUnsupportedSetting));
     708             :         throw IllegalArgumentException(
     709             :             sMessage,
     710             :             *const_cast< CopyTableWizard* >( this ),
     711             :             1
     712           0 :         );
     713           0 :     }
     714             : 
     715           0 : }
     716             : 
     717           0 : ::std::unique_ptr< ICopyTableSourceObject > CopyTableWizard::impl_extractSourceObject_throw( const Reference< XPropertySet >& _rxDescriptor, sal_Int32& _out_rCommandType ) const
     718             : {
     719             :     OSL_PRECOND( _rxDescriptor.is() && m_xSourceConnection.is(), "CopyTableWizard::impl_extractSourceObject_throw: illegal arguments!" );
     720             : 
     721           0 :     Reference< XPropertySetInfo > xPSI( _rxDescriptor->getPropertySetInfo(), UNO_SET_THROW );
     722           0 :     if  (   !xPSI->hasPropertyByName( PROPERTY_COMMAND )
     723           0 :         ||  !xPSI->hasPropertyByName( PROPERTY_COMMAND_TYPE )
     724             :         )
     725             :         throw IllegalArgumentException("Expecting a table or query specification.",
     726             :                                        // TODO: resource
     727           0 :                                        *const_cast< CopyTableWizard* >( this ), 1);
     728             : 
     729           0 :     OUString sCommand;
     730           0 :     _out_rCommandType = CommandType::COMMAND;
     731           0 :     OSL_VERIFY( _rxDescriptor->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
     732           0 :     OSL_VERIFY( _rxDescriptor->getPropertyValue( PROPERTY_COMMAND_TYPE ) >>= _out_rCommandType );
     733             : 
     734           0 :     ::std::unique_ptr< ICopyTableSourceObject > pSourceObject;
     735           0 :     Reference< XNameAccess > xContainer;
     736           0 :     switch ( _out_rCommandType )
     737             :     {
     738             :     case CommandType::TABLE:
     739             :     {
     740           0 :         Reference< XTablesSupplier > xSuppTables( m_xSourceConnection.getTyped(), UNO_QUERY );
     741           0 :         if ( xSuppTables.is() )
     742           0 :             xContainer.set( xSuppTables->getTables(), UNO_SET_THROW );
     743             :     }
     744           0 :     break;
     745             :     case CommandType::QUERY:
     746             :     {
     747           0 :         Reference< XQueriesSupplier > xSuppQueries( m_xSourceConnection.getTyped(), UNO_QUERY );
     748           0 :         if ( xSuppQueries.is() )
     749           0 :             xContainer.set( xSuppQueries->getQueries(), UNO_SET_THROW );
     750             :     }
     751           0 :     break;
     752             :     default:
     753             :         throw IllegalArgumentException(
     754             :             OUString( ModuleRes( STR_CTW_ONLY_TABLES_AND_QUERIES_SUPPORT ) ),
     755             :             *const_cast< CopyTableWizard* >( this ),
     756             :             1
     757           0 :         );
     758             :     }
     759             : 
     760           0 :     if ( xContainer.is() )
     761             :     {
     762             :         pSourceObject.reset( new ObjectCopySource( m_xSourceConnection,
     763           0 :             Reference< XPropertySet >( xContainer->getByName( sCommand ), UNO_QUERY_THROW ) ) );
     764             :     }
     765             :     else
     766             :     {
     767             :         // our source connection is an SDBC level connection only, not a SDBCX level one
     768             :         // Which means it cannot provide the to-be-copied object as component.
     769             : 
     770           0 :         if ( _out_rCommandType == CommandType::QUERY )
     771             :             // we cannot copy a query if the connection cannot provide it ...
     772             :             throw IllegalArgumentException(
     773             :                 OUString(ModuleRes( STR_CTW_ERROR_NO_QUERY )),
     774             :                 *const_cast< CopyTableWizard* >( this ),
     775             :                 1
     776           0 :             );
     777           0 :         pSourceObject.reset( new NamedTableCopySource( m_xSourceConnection, sCommand ) );
     778             :     }
     779             : 
     780           0 :     return pSourceObject;
     781             : }
     782             : 
     783           0 : void CopyTableWizard::impl_extractSourceResultSet_throw( const Reference< XPropertySet >& i_rDescriptor )
     784             : {
     785           0 :     Reference< XPropertySetInfo > xPSI( i_rDescriptor->getPropertySetInfo(), UNO_SET_THROW );
     786             : 
     787             :     // extract relevant settings
     788           0 :     if ( xPSI->hasPropertyByName( PROPERTY_RESULT_SET ) )
     789           0 :         m_xSourceResultSet.set( i_rDescriptor->getPropertyValue( PROPERTY_RESULT_SET ), UNO_QUERY );
     790             : 
     791           0 :     if ( xPSI->hasPropertyByName( PROPERTY_SELECTION ) )
     792           0 :         OSL_VERIFY( i_rDescriptor->getPropertyValue( PROPERTY_SELECTION ) >>= m_aSourceSelection );
     793             : 
     794           0 :     if ( xPSI->hasPropertyByName( PROPERTY_BOOKMARK_SELECTION ) )
     795           0 :         OSL_VERIFY( i_rDescriptor->getPropertyValue( PROPERTY_BOOKMARK_SELECTION ) >>= m_bSourceSelectionBookmarks );
     796             : 
     797             :     // sanity checks
     798           0 :     const bool bHasResultSet = m_xSourceResultSet.is();
     799           0 :     const bool bHasSelection = ( m_aSourceSelection.getLength() != 0 );
     800           0 :     if ( bHasSelection && !bHasResultSet )
     801             :         throw IllegalArgumentException("A result set is needed when specifying a selection to copy.",
     802             :                                        // TODO: resource
     803           0 :                                        *this, 1);
     804             : 
     805           0 :     if ( bHasSelection && m_bSourceSelectionBookmarks )
     806             :     {
     807           0 :         Reference< XRowLocate > xRowLocate( m_xSourceResultSet, UNO_QUERY );
     808           0 :         if ( !xRowLocate.is() )
     809             :         {
     810             :             ::dbtools::throwGenericSQLException(
     811             :                 OUString( ModuleRes( STR_CTW_COPY_SOURCE_NEEDS_BOOKMARKS ) ),
     812             :                 *this
     813           0 :             );
     814           0 :         }
     815           0 :     }
     816           0 : }
     817             : 
     818           0 : SharedConnection CopyTableWizard::impl_extractConnection_throw( const Reference< XPropertySet >& _rxDataSourceDescriptor,
     819             :     Reference< XInteractionHandler >& _out_rxDocInteractionHandler ) const
     820             : {
     821           0 :     SharedConnection xConnection;
     822             : 
     823             :     OSL_PRECOND( _rxDataSourceDescriptor.is(), "CopyTableWizard::impl_extractConnection_throw: no descriptor!" );
     824           0 :     if ( !_rxDataSourceDescriptor.is() )
     825           0 :         return xConnection;
     826             : 
     827           0 :     Reference< XInteractionHandler > xInteractionHandler;
     828             : 
     829             :     do
     830             :     {
     831           0 :     Reference< XPropertySetInfo > xPSI( _rxDataSourceDescriptor->getPropertySetInfo(), UNO_SET_THROW );
     832             : 
     833             :     // if there's an ActiveConnection, use it
     834           0 :     if ( xPSI->hasPropertyByName( PROPERTY_ACTIVE_CONNECTION ) )
     835             :     {
     836           0 :         Reference< XConnection > xPure;
     837           0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xPure );
     838           0 :         xConnection.reset( xPure, SharedConnection::NoTakeOwnership );
     839             :     }
     840           0 :     if ( xConnection.is() )
     841             :     {
     842           0 :         xInteractionHandler = lcl_getInteractionHandler_throw( xConnection.getTyped(), m_xInteractionHandler );
     843             :         SAL_WARN_IF( !xInteractionHandler.is(), "dbaccess.ui", "CopyTableWizard::impl_extractConnection_throw: lcl_getInteractionHandler_throw returned nonsense!" );
     844           0 :         break;
     845             :     }
     846             : 
     847             :     // there could be a DataSourceName or a DatabaseLocation, describing the css.sdb.DataSource
     848           0 :     OUString sDataSource, sDatabaseLocation;
     849           0 :     if ( xPSI->hasPropertyByName( PROPERTY_DATASOURCENAME ) )
     850           0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_DATASOURCENAME ) >>= sDataSource );
     851           0 :     if ( xPSI->hasPropertyByName( PROPERTY_DATABASE_LOCATION ) )
     852           0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_DATABASE_LOCATION ) >>= sDatabaseLocation );
     853             : 
     854             :     // need a DatabaseContext for loading the data source
     855           0 :     Reference< XDatabaseContext > xDatabaseContext = DatabaseContext::create( m_xContext );
     856           0 :     Reference< XDataSource > xDataSource;
     857           0 :     if ( !sDataSource.isEmpty() )
     858           0 :         xDataSource.set( xDatabaseContext->getByName( sDataSource ), UNO_QUERY_THROW );
     859           0 :     if ( !xDataSource.is() && !sDatabaseLocation.isEmpty() )
     860           0 :         xDataSource.set( xDatabaseContext->getByName( sDatabaseLocation ), UNO_QUERY_THROW );
     861             : 
     862           0 :     if ( xDataSource.is() )
     863             :     {
     864             :         // first, try connecting with completion
     865           0 :         xInteractionHandler = lcl_getInteractionHandler_throw( xDataSource, m_xInteractionHandler );
     866             :         SAL_WARN_IF( !xInteractionHandler.is(), "dbaccess.ui", "CopyTableWizard::impl_extractConnection_throw: lcl_getInteractionHandler_throw returned nonsense!" );
     867           0 :         if ( xInteractionHandler.is() )
     868             :         {
     869           0 :             Reference< XCompletedConnection > xInteractiveConnection( xDataSource, UNO_QUERY );
     870           0 :             if ( xInteractiveConnection.is() )
     871           0 :                 xConnection.reset( xInteractiveConnection->connectWithCompletion( xInteractionHandler ), SharedConnection::TakeOwnership );
     872             :         }
     873             : 
     874             :         // interactively connecting was not successful or possible -> connect without interaction
     875           0 :         if ( !xConnection.is() )
     876             :         {
     877           0 :             xConnection.reset( xDataSource->getConnection( OUString(), OUString() ), SharedConnection::TakeOwnership );
     878             :         }
     879             :     }
     880             : 
     881           0 :     if ( xConnection.is() )
     882           0 :         break;
     883             : 
     884             :     // finally, there could be a ConnectionResource/ConnectionInfo
     885           0 :     OUString sConnectionResource;
     886           0 :     Sequence< PropertyValue > aConnectionInfo;
     887           0 :     if ( xPSI->hasPropertyByName( PROPERTY_CONNECTION_RESOURCE ) )
     888           0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_CONNECTION_RESOURCE ) >>= sConnectionResource );
     889           0 :     if ( xPSI->hasPropertyByName( PROPERTY_CONNECTION_INFO ) )
     890           0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_CONNECTION_INFO ) >>= aConnectionInfo );
     891             : 
     892           0 :     Reference< XDriverManager > xDriverManager;
     893             :     try {
     894           0 :         xDriverManager.set( ConnectionPool::create( m_xContext ), UNO_QUERY_THROW );
     895           0 :     } catch( const Exception& ) {  }
     896           0 :     if ( !xDriverManager.is() )
     897             :         // no connection pool installed
     898           0 :         xDriverManager.set( DriverManager::create( m_xContext ), UNO_QUERY_THROW );
     899             : 
     900           0 :     if ( aConnectionInfo.getLength() )
     901           0 :         xConnection.set( xDriverManager->getConnectionWithInfo( sConnectionResource, aConnectionInfo ), UNO_SET_THROW );
     902             :     else
     903           0 :         xConnection.set( xDriverManager->getConnection( sConnectionResource ), UNO_SET_THROW );
     904             :     }
     905             :     while ( false );
     906             : 
     907           0 :     if ( xInteractionHandler != m_xInteractionHandler )
     908           0 :         _out_rxDocInteractionHandler = xInteractionHandler;
     909             : 
     910           0 :     return xConnection;
     911             : }
     912             : 
     913           0 : ::utl::SharedUNOComponent< XPreparedStatement > CopyTableWizard::impl_createSourceStatement_throw() const
     914             : {
     915             :     OSL_PRECOND( m_xSourceConnection.is(), "CopyTableWizard::impl_createSourceStatement_throw: illegal call!" );
     916           0 :     if ( !m_xSourceConnection.is() )
     917           0 :         throw RuntimeException( "CopyTableWizard::impl_createSourceStatement_throw: illegal call!", *const_cast< CopyTableWizard* >( this ));
     918             : 
     919           0 :     ::utl::SharedUNOComponent< XPreparedStatement > xStatement;
     920           0 :     switch ( m_nCommandType )
     921             :     {
     922             :     case CommandType::TABLE:
     923           0 :         xStatement.set( m_pSourceObject->getPreparedSelectStatement(), UNO_SET_THROW );
     924           0 :         break;
     925             : 
     926             :     case CommandType::QUERY:
     927             :     {
     928           0 :         OUString sQueryCommand( m_pSourceObject->getSelectStatement() );
     929           0 :         xStatement.set( m_pSourceObject->getPreparedSelectStatement(), UNO_SET_THROW );
     930             : 
     931             :         // check whether we have to fill in parameter values
     932             :         // create and fill a composer
     933             : 
     934           0 :         Reference< XMultiServiceFactory > xFactory( m_xSourceConnection, UNO_QUERY );
     935           0 :         ::utl::SharedUNOComponent< XSingleSelectQueryComposer > xComposer;
     936           0 :         if ( xFactory.is() )
     937             :             // note: connections below the sdb-level are allowed to not support the XMultiServiceFactory interface
     938           0 :             xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY );
     939             : 
     940           0 :         if ( xComposer.is() )
     941             :         {
     942           0 :             xComposer->setQuery( sQueryCommand );
     943             : 
     944           0 :             Reference< XParameters > xStatementParams( xStatement, UNO_QUERY );
     945             :             OSL_ENSURE( xStatementParams.is(), "CopyTableWizard::impl_createSourceStatement_throw: no access to the statement's parameters!" );
     946             :                 // the statement should be a css.sdbc.PreparedStatement (this is what
     947             :                 // we created), and a prepared statement is required to support XParameters
     948           0 :             if ( xStatementParams.is() )
     949             :             {
     950             :                 OSL_ENSURE( m_xInteractionHandler.is(),
     951             :                    "CopyTableWizard::impl_createSourceStatement_throw: no interaction handler for the parameters request!" );
     952             :                 // we should always have an interaction handler - as last fallback, we create an own one in ::initialize
     953             : 
     954           0 :                 if ( m_xInteractionHandler.is() )
     955           0 :                     ::dbtools::askForParameters( xComposer, xStatementParams, m_xSourceConnection, m_xInteractionHandler );
     956           0 :             }
     957           0 :         }
     958             :     }
     959           0 :     break;
     960             : 
     961             :     default:
     962             :         // this should not have survived initialization phase
     963           0 :         throw RuntimeException("No case matched, this should not have survived the initialization phase", *const_cast< CopyTableWizard* >( this ));
     964             :     }
     965             : 
     966           0 :     return xStatement;
     967             : }
     968             : 
     969             : namespace
     970             : {
     971           0 :     class ValueTransfer
     972             :     {
     973             :     public:
     974           0 :         ValueTransfer( const sal_Int32& _rSourcePos, const sal_Int32& _rDestPos, const ::std::vector< sal_Int32 >& _rColTypes,
     975             :             const Reference< XRow >& _rxSource, const Reference< XParameters >& _rxDest )
     976             :             :m_rSourcePos( _rSourcePos )
     977             :             ,m_rDestPos( _rDestPos )
     978             :             ,m_rColTypes( _rColTypes )
     979             :             ,m_xSource( _rxSource )
     980           0 :             ,m_xDest( _rxDest )
     981             :         {
     982           0 :         }
     983             : 
     984             :     template< typename VALUE_TYPE >
     985           0 :     void transferValue( VALUE_TYPE ( SAL_CALL XRow::*_pGetter )( sal_Int32 ),
     986             :         void (SAL_CALL XParameters::*_pSetter)( sal_Int32, VALUE_TYPE ) )
     987             :     {
     988           0 :         VALUE_TYPE value( (m_xSource.get()->*_pGetter)( m_rSourcePos ) );
     989           0 :         if ( m_xSource->wasNull() )
     990           0 :             m_xDest->setNull( m_rDestPos, m_rColTypes[ m_rSourcePos ] );
     991             :         else
     992           0 :             (m_xDest.get()->*_pSetter)( m_rDestPos, value );
     993           0 :     }
     994             :  template< typename VALUE_TYPE >
     995           0 :     void transferComplexValue( VALUE_TYPE ( SAL_CALL XRow::*_pGetter )( sal_Int32 ),
     996             :         void (SAL_CALL XParameters::*_pSetter)( sal_Int32, const VALUE_TYPE& ) )
     997             :     {
     998           0 :         const VALUE_TYPE value( (m_xSource.get()->*_pGetter)( m_rSourcePos ) );
     999             :                {
    1000           0 :         if ( m_xSource->wasNull() )
    1001           0 :             m_xDest->setNull( m_rDestPos, m_rColTypes[ m_rSourcePos ] );
    1002             :         else
    1003           0 :             (m_xDest.get()->*_pSetter)( m_rDestPos, value );
    1004           0 :                }
    1005           0 :     }
    1006             :     private:
    1007             :         const sal_Int32&                    m_rSourcePos;
    1008             :         const sal_Int32&                    m_rDestPos;
    1009             :         const ::std::vector< sal_Int32 >    m_rColTypes;
    1010             :         const Reference< XRow >             m_xSource;
    1011             :         const Reference< XParameters >      m_xDest;
    1012             :     };
    1013             : }
    1014             : 
    1015           0 : bool CopyTableWizard::impl_processCopyError_nothrow( const CopyTableRowEvent& _rEvent )
    1016             : {
    1017           0 :     Reference< XCopyTableListener > xListener;
    1018             :     try
    1019             :     {
    1020           0 :         ::cppu::OInterfaceIteratorHelper aIter( m_aCopyTableListeners );
    1021           0 :         while ( aIter.hasMoreElements() )
    1022             :         {
    1023           0 :             xListener.set( aIter.next(), UNO_QUERY_THROW );
    1024           0 :             sal_Int16 nListenerChoice = xListener->copyRowError( _rEvent );
    1025           0 :             switch ( nListenerChoice )
    1026             :             {
    1027           0 :             case CopyTableContinuation::Proceed:            return true;    // continue copying
    1028           0 :             case CopyTableContinuation::CallNextHandler:    continue;       // continue the loop, ask next listener
    1029           0 :             case CopyTableContinuation::Cancel:             return false;   // cancel copying
    1030           0 :             case CopyTableContinuation::AskUser:            break;          // stop asking the listeners, ask the user
    1031             : 
    1032             :             default:
    1033             :                 SAL_WARN("dbaccess.ui", "CopyTableWizard::impl_processCopyError_nothrow: invalid listener response!" );
    1034             :                 // ask next listener
    1035           0 :                 continue;
    1036             :             }
    1037           0 :         }
    1038             :     }
    1039           0 :     catch( const Exception& )
    1040             :     {
    1041             :         DBG_UNHANDLED_EXCEPTION();
    1042             :     }
    1043             : 
    1044             :     // no listener felt responsible for the error, or a listener told to ask the user
    1045             : 
    1046             :     try
    1047             :     {
    1048           0 :         SQLContext aError;
    1049           0 :         aError.Context = *this;
    1050           0 :         aError.Message = OUString( ModuleRes( STR_ERROR_OCCURRED_WHILE_COPYING ) );
    1051             : 
    1052           0 :         ::dbtools::SQLExceptionInfo aInfo( _rEvent.Error );
    1053           0 :         if ( aInfo.isValid() )
    1054           0 :             aError.NextException = _rEvent.Error;
    1055             :         else
    1056             :         {
    1057             :             // a non-SQL exception happened
    1058           0 :             Exception aException;
    1059           0 :             OSL_VERIFY( _rEvent.Error >>= aException );
    1060           0 :             SQLContext aContext;
    1061           0 :             aContext.Context = aException.Context;
    1062           0 :             aContext.Message = aException.Message;
    1063           0 :             aContext.Details = _rEvent.Error.getValueTypeName();
    1064           0 :             aError.NextException <<= aContext;
    1065             :         }
    1066             : 
    1067           0 :         ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( makeAny( aError ) ) );
    1068             : 
    1069           0 :         ::rtl::Reference< ::comphelper::OInteractionApprove > xYes = new ::comphelper::OInteractionApprove;
    1070           0 :         xRequest->addContinuation( xYes.get() );
    1071           0 :         xRequest->addContinuation( new ::comphelper::OInteractionDisapprove );
    1072             : 
    1073             :         OSL_ENSURE( m_xInteractionHandler.is(),
    1074             :             "CopyTableWizard::impl_processCopyError_nothrow: we always should have an interaction handler!" );
    1075           0 :         if ( m_xInteractionHandler.is() )
    1076           0 :             m_xInteractionHandler->handle( xRequest.get() );
    1077             : 
    1078           0 :         if ( xYes->wasSelected() )
    1079             :             // continue copying
    1080           0 :             return true;
    1081             :     }
    1082           0 :     catch( const Exception& )
    1083             :     {
    1084             :         DBG_UNHANDLED_EXCEPTION();
    1085             :     }
    1086             : 
    1087             :     // cancel copying
    1088           0 :     return false;
    1089             : }
    1090             : 
    1091           0 : void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSourceResultSet,
    1092             :     const Reference< XPropertySet >& _rxDestTable )
    1093             : {
    1094             :     OSL_PRECOND( m_xDestConnection.is(), "CopyTableWizard::impl_copyRows_throw: illegal call!" );
    1095           0 :     if ( !m_xDestConnection.is() )
    1096           0 :         throw RuntimeException( "m_xDestConnection is set to null, CopyTableWizard::impl_copyRows_throw: illegal call!", *this );
    1097             : 
    1098           0 :     Reference< XDatabaseMetaData > xDestMetaData( m_xDestConnection->getMetaData(), UNO_QUERY_THROW );
    1099             : 
    1100           0 :     const OCopyTableWizard& rWizard             = impl_getDialog_throw();
    1101           0 :     ODatabaseExport::TPositions aColumnMapping  = rWizard.GetColumnPositions();
    1102           0 :     bool bAutoIncrement                         = rWizard.shouldCreatePrimaryKey();
    1103             : 
    1104           0 :     Reference< XRow > xRow              ( _rxSourceResultSet, UNO_QUERY_THROW );
    1105           0 :     Reference< XRowLocate > xRowLocate  ( _rxSourceResultSet, UNO_QUERY_THROW );
    1106             : 
    1107           0 :     Reference< XResultSetMetaDataSupplier > xSuppResMeta( _rxSourceResultSet, UNO_QUERY_THROW );
    1108           0 :     Reference< XResultSetMetaData> xMeta( xSuppResMeta->getMetaData() );
    1109             : 
    1110             :     // we need a vector which all types
    1111           0 :     sal_Int32 nCount = xMeta->getColumnCount();
    1112           0 :     ::std::vector< sal_Int32 > aSourceColTypes;
    1113           0 :     aSourceColTypes.reserve( nCount + 1 );
    1114           0 :     aSourceColTypes.push_back( -1 ); // just to avoid a every time i-1 call
    1115             : 
    1116           0 :     ::std::vector< sal_Int32 > aSourcePrec;
    1117           0 :     aSourcePrec.reserve( nCount + 1 );
    1118           0 :     aSourcePrec.push_back( -1 ); // just to avoid a every time i-1 call
    1119             : 
    1120           0 :     for ( sal_Int32 k=1; k <= nCount; ++k )
    1121             :     {
    1122           0 :         aSourceColTypes.push_back( xMeta->getColumnType( k ) );
    1123           0 :         aSourcePrec.push_back( xMeta->getPrecision( k ) );
    1124             :     }
    1125             : 
    1126             :     // now create, fill and execute the prepared statement
    1127           0 :     Reference< XPreparedStatement > xStatement( ODatabaseExport::createPreparedStatment( xDestMetaData, _rxDestTable, aColumnMapping ), UNO_SET_THROW );
    1128           0 :     Reference< XParameters > xStatementParams( xStatement, UNO_QUERY_THROW );
    1129             : 
    1130           0 :     const bool bSelectedRecordsOnly = m_aSourceSelection.getLength() != 0;
    1131           0 :     const Any* pSelectedRow         = m_aSourceSelection.getConstArray();
    1132           0 :     const Any* pSelEnd              = pSelectedRow + m_aSourceSelection.getLength();
    1133             : 
    1134           0 :     sal_Int32 nRowCount = 0;
    1135           0 :     bool bContinue = false;
    1136             : 
    1137           0 :     CopyTableRowEvent aCopyEvent;
    1138           0 :     aCopyEvent.Source = *this;
    1139           0 :     aCopyEvent.SourceData = _rxSourceResultSet;
    1140             : 
    1141           0 :     do // loop as long as there are more rows or the selection ends
    1142             :     {
    1143           0 :         bContinue = false;
    1144           0 :         if ( bSelectedRecordsOnly )
    1145             :         {
    1146           0 :             if ( pSelectedRow != pSelEnd )
    1147             :             {
    1148           0 :                 if ( m_bSourceSelectionBookmarks )
    1149             :                 {
    1150           0 :                     bContinue = xRowLocate->moveToBookmark( *pSelectedRow );
    1151             :                 }
    1152             :                 else
    1153             :                 {
    1154           0 :                     sal_Int32 nPos = 0;
    1155           0 :                     OSL_VERIFY( *pSelectedRow >>= nPos );
    1156           0 :                     bContinue = _rxSourceResultSet->absolute( nPos );
    1157             :                 }
    1158           0 :                 ++pSelectedRow;
    1159             :             }
    1160             :         }
    1161             :         else
    1162           0 :             bContinue = _rxSourceResultSet->next();
    1163             : 
    1164           0 :         if ( !bContinue )
    1165             :         {
    1166           0 :             break;
    1167             :         }
    1168             : 
    1169           0 :         ++nRowCount;
    1170           0 :         bool bInsertAutoIncrement = true;
    1171           0 :         ODatabaseExport::TPositions::const_iterator aPosIter = aColumnMapping.begin();
    1172           0 :         ODatabaseExport::TPositions::const_iterator aPosEnd = aColumnMapping.end();
    1173             : 
    1174           0 :         aCopyEvent.Error.clear();
    1175             :         try
    1176             :         {
    1177             :             // notify listeners
    1178           0 :             m_aCopyTableListeners.notifyEach( &XCopyTableListener::copyingRow, aCopyEvent );
    1179             : 
    1180           0 :             sal_Int32 nDestColumn( 0 );
    1181           0 :             sal_Int32 nSourceColumn( 1 );
    1182           0 :             ValueTransfer aTransfer( nSourceColumn, nDestColumn, aSourceColTypes, xRow, xStatementParams );
    1183             : 
    1184           0 :             for ( ; aPosIter != aPosEnd; ++aPosIter )
    1185             :             {
    1186           0 :                 nDestColumn = aPosIter->first;
    1187           0 :                 if ( nDestColumn == COLUMN_POSITION_NOT_FOUND )
    1188             :                 {
    1189           0 :                     ++nSourceColumn;
    1190             :                     // otherwise we don't get the correct value when only the 2nd source column was selected
    1191           0 :                     continue;
    1192             :                 }
    1193             : 
    1194           0 :                 if ( bAutoIncrement && bInsertAutoIncrement )
    1195             :                 {
    1196           0 :                     xStatementParams->setInt( 1, nRowCount );
    1197           0 :                     bInsertAutoIncrement = false;
    1198           0 :                     continue;
    1199             :                 }
    1200             : 
    1201           0 :                 if ( ( nSourceColumn < 1 ) || ( nSourceColumn >= (sal_Int32)aSourceColTypes.size() ) )
    1202             :                 {   // ( we have to check here against 1 because the parameters are 1 based)
    1203             :                     ::dbtools::throwSQLException("Internal error: invalid column type index.",
    1204           0 :                                                  ::dbtools::SQL_INVALID_DESCRIPTOR_INDEX, *this);
    1205             :                 }
    1206             : 
    1207           0 :                 switch ( aSourceColTypes[ nSourceColumn ] )
    1208             :                 {
    1209             :                     case DataType::DOUBLE:
    1210             :                     case DataType::REAL:
    1211           0 :                         aTransfer.transferValue( &XRow::getDouble, &XParameters::setDouble );
    1212           0 :                         break;
    1213             : 
    1214             :                     case DataType::CHAR:
    1215             :                     case DataType::VARCHAR:
    1216             :                     case DataType::LONGVARCHAR:
    1217             :                     case DataType::DECIMAL:
    1218             :                     case DataType::NUMERIC:
    1219           0 :                         aTransfer.transferComplexValue( &XRow::getString, &XParameters::setString );
    1220           0 :                         break;
    1221             : 
    1222             :                     case DataType::BIGINT:
    1223           0 :                         aTransfer.transferValue( &XRow::getLong, &XParameters::setLong );
    1224           0 :                         break;
    1225             : 
    1226             :                     case DataType::FLOAT:
    1227           0 :                         aTransfer.transferValue( &XRow::getFloat, &XParameters::setFloat );
    1228           0 :                         break;
    1229             : 
    1230             :                     case DataType::LONGVARBINARY:
    1231             :                     case DataType::BINARY:
    1232             :                     case DataType::VARBINARY:
    1233           0 :                         aTransfer.transferComplexValue( &XRow::getBytes, &XParameters::setBytes );
    1234           0 :                         break;
    1235             : 
    1236             :                     case DataType::DATE:
    1237           0 :                         aTransfer.transferComplexValue( &XRow::getDate, &XParameters::setDate );
    1238           0 :                         break;
    1239             : 
    1240             :                     case DataType::TIME:
    1241           0 :                         aTransfer.transferComplexValue( &XRow::getTime, &XParameters::setTime );
    1242           0 :                         break;
    1243             : 
    1244             :                     case DataType::TIMESTAMP:
    1245           0 :                         aTransfer.transferComplexValue( &XRow::getTimestamp, &XParameters::setTimestamp );
    1246           0 :                         break;
    1247             : 
    1248             :                     case DataType::BIT:
    1249           0 :                         if ( aSourcePrec[nSourceColumn] > 1 )
    1250             :                         {
    1251           0 :                             aTransfer.transferComplexValue( &XRow::getBytes, &XParameters::setBytes );
    1252           0 :                             break;
    1253             :                         }
    1254             :                         // run through
    1255             :                     case DataType::BOOLEAN:
    1256           0 :                         aTransfer.transferValue( &XRow::getBoolean, &XParameters::setBoolean );
    1257           0 :                         break;
    1258             : 
    1259             :                     case DataType::TINYINT:
    1260           0 :                         aTransfer.transferValue( &XRow::getByte, &XParameters::setByte );
    1261           0 :                         break;
    1262             : 
    1263             :                     case DataType::SMALLINT:
    1264           0 :                         aTransfer.transferValue( &XRow::getShort, &XParameters::setShort );
    1265           0 :                         break;
    1266             : 
    1267             :                     case DataType::INTEGER:
    1268           0 :                         aTransfer.transferValue( &XRow::getInt, &XParameters::setInt );
    1269           0 :                         break;
    1270             : 
    1271             :                     case DataType::BLOB:
    1272           0 :                         aTransfer.transferComplexValue( &XRow::getBlob, &XParameters::setBlob );
    1273           0 :                         break;
    1274             : 
    1275             :                     case DataType::CLOB:
    1276           0 :                         aTransfer.transferComplexValue( &XRow::getClob, &XParameters::setClob );
    1277           0 :                         break;
    1278             : 
    1279             :                     default:
    1280             :                     {
    1281           0 :                         OUString aMessage( ModuleRes( STR_CTW_UNSUPPORTED_COLUMN_TYPE ) );
    1282             : 
    1283           0 :                         aMessage = aMessage.replaceFirst( "$type$", OUString::number( aSourceColTypes[ nSourceColumn ] ) );
    1284           0 :                         aMessage = aMessage.replaceFirst( "$pos$", OUString::number( nSourceColumn ) );
    1285             : 
    1286             :                         ::dbtools::throwSQLException(
    1287             :                             aMessage,
    1288             :                             ::dbtools::SQL_INVALID_SQL_DATA_TYPE,
    1289             :                             *this
    1290           0 :                         );
    1291             :                     }
    1292             :                 }
    1293           0 :                 ++nSourceColumn;
    1294             :             }
    1295           0 :             xStatement->executeUpdate();
    1296             : 
    1297             :             // notify listeners
    1298           0 :             m_aCopyTableListeners.notifyEach( &XCopyTableListener::copiedRow, aCopyEvent );
    1299             :         }
    1300           0 :         catch( const Exception& )
    1301             :         {
    1302           0 :             aCopyEvent.Error = ::cppu::getCaughtException();
    1303             :         }
    1304             : 
    1305           0 :         if ( aCopyEvent.Error.hasValue() )
    1306           0 :             bContinue = impl_processCopyError_nothrow( aCopyEvent );
    1307             :     }
    1308           0 :     while( bContinue );
    1309           0 : }
    1310             : 
    1311           0 : void CopyTableWizard::impl_doCopy_nothrow()
    1312             : {
    1313           0 :     Any aError;
    1314             : 
    1315             :     try
    1316             :     {
    1317           0 :         OCopyTableWizard& rWizard( impl_getDialog_throw() );
    1318             : 
    1319           0 :         WaitObject aWO( rWizard.GetParent() );
    1320           0 :         Reference< XPropertySet > xTable;
    1321             : 
    1322           0 :         switch ( rWizard.getOperation() )
    1323             :         {
    1324             :             case CopyTableOperation::CopyDefinitionOnly:
    1325             :             case CopyTableOperation::CopyDefinitionAndData:
    1326             :             {
    1327           0 :                 xTable = rWizard.createTable();
    1328             : 
    1329           0 :                 if( !xTable.is() )
    1330             :                 {
    1331             :                     SAL_WARN("dbaccess.ui", "CopyTableWizard::impl_doCopy_nothrow: createTable should throw here, shouldn't it?" );
    1332           0 :                     break;
    1333             :                 }
    1334             : 
    1335           0 :                 if( CopyTableOperation::CopyDefinitionOnly == rWizard.getOperation() )
    1336           0 :                     break;
    1337             :             }
    1338             :             // run through
    1339             : 
    1340             :             case CopyTableOperation::AppendData:
    1341             :             {
    1342             : 
    1343           0 :                 if ( !xTable.is() )
    1344             :                 {
    1345           0 :                     xTable = rWizard.createTable();
    1346           0 :                     if ( !xTable.is() )
    1347             :                     {
    1348             :                         SAL_WARN("dbaccess.ui", "CopyTableWizard::impl_doCopy_nothrow: createTable should throw here, shouldn't it?" );
    1349           0 :                         break;
    1350             :                     }
    1351             :                 }
    1352             : 
    1353           0 :                 ::utl::SharedUNOComponent< XPreparedStatement > xSourceStatement;
    1354           0 :                 ::utl::SharedUNOComponent< XResultSet > xSourceResultSet;
    1355             : 
    1356           0 :                 if ( m_xSourceResultSet.is() )
    1357             :                 {
    1358           0 :                     xSourceResultSet.reset( m_xSourceResultSet, ::utl::SharedUNOComponent< XResultSet >::NoTakeOwnership );
    1359             :                 }
    1360             :                 else
    1361             :                 {
    1362           0 :                     const bool bIsSameConnection = ( m_xSourceConnection.getTyped() == m_xDestConnection.getTyped() );
    1363           0 :                     const bool bIsTable = ( CommandType::TABLE == m_nCommandType );
    1364           0 :                     bool bDone = false;
    1365           0 :                     if ( bIsSameConnection && bIsTable )
    1366             :                     {
    1367             :                         // try whether the server supports copying via SQL
    1368             :                         try
    1369             :                         {
    1370           0 :                             m_xDestConnection->createStatement()->executeUpdate( impl_getServerSideCopyStatement_throw(xTable) );
    1371           0 :                             bDone = true;
    1372             :                         }
    1373           0 :                         catch( const Exception& )
    1374             :                         {
    1375             :                             // this is allowed.
    1376             :                         }
    1377             :                     }
    1378             : 
    1379           0 :                     if ( !bDone )
    1380             :                     {
    1381           0 :                         xSourceStatement.set( impl_createSourceStatement_throw(), UNO_SET_THROW );
    1382           0 :                         xSourceResultSet.set( xSourceStatement->executeQuery(), UNO_SET_THROW );
    1383             :                     }
    1384             :                 }
    1385             : 
    1386           0 :                 if ( xSourceResultSet.is() )
    1387           0 :                     impl_copyRows_throw( xSourceResultSet, xTable );
    1388             :             }
    1389           0 :             break;
    1390             : 
    1391             :             case CopyTableOperation::CreateAsView:
    1392           0 :                 rWizard.createView();
    1393           0 :                 break;
    1394             : 
    1395             :             default:
    1396             :                 SAL_WARN("dbaccess.ui", "CopyTableWizard::impl_doCopy_nothrow: What operation, please?" );
    1397           0 :                 break;
    1398           0 :         }
    1399             :     }
    1400           0 :     catch( const Exception& )
    1401             :     {
    1402           0 :         aError = ::cppu::getCaughtException();
    1403             : 
    1404             :         // silence the error of the user cancelling the parameter's dialog
    1405           0 :         SQLException aSQLError;
    1406           0 :         if ( ( aError >>= aSQLError ) && ( aSQLError.ErrorCode == ::dbtools::ParameterInteractionCancelled ) )
    1407             :         {
    1408           0 :             aError.clear();
    1409           0 :             m_nOverrideExecutionResult = RET_CANCEL;
    1410           0 :         }
    1411             :     }
    1412             : 
    1413           0 :     if ( aError.hasValue() && m_xInteractionHandler.is() )
    1414             :     {
    1415             :         try
    1416             :         {
    1417           0 :             ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( aError ) );
    1418           0 :             m_xInteractionHandler->handle( xRequest.get() );
    1419             :         }
    1420           0 :         catch( const Exception& )
    1421             :         {
    1422             :             DBG_UNHANDLED_EXCEPTION();
    1423             :         }
    1424           0 :     }
    1425           0 : }
    1426             : 
    1427           0 : OUString CopyTableWizard::impl_getServerSideCopyStatement_throw(const Reference< XPropertySet >& _xTable)
    1428             : {
    1429           0 :     const Reference<XColumnsSupplier> xDestColsSup(_xTable,UNO_QUERY_THROW);
    1430           0 :     const Sequence< OUString> aDestColumnNames = xDestColsSup->getColumns()->getElementNames();
    1431           0 :     const Reference< XDatabaseMetaData > xDestMetaData( m_xDestConnection->getMetaData(), UNO_QUERY_THROW );
    1432           0 :     const OUString sQuote = xDestMetaData->getIdentifierQuoteString();
    1433           0 :     OUStringBuffer sColumns;
    1434             :     // 1st check if the columns matching
    1435           0 :     const OCopyTableWizard& rWizard             = impl_getDialog_throw();
    1436           0 :     ODatabaseExport::TPositions aColumnMapping  = rWizard.GetColumnPositions();
    1437           0 :     ODatabaseExport::TPositions::const_iterator aPosIter = aColumnMapping.begin();
    1438           0 :     for ( sal_Int32 i = 0; aPosIter != aColumnMapping.end() ; ++aPosIter,++i )
    1439             :     {
    1440           0 :         if ( COLUMN_POSITION_NOT_FOUND != aPosIter->second )
    1441             :         {
    1442           0 :             if ( !sColumns.isEmpty() )
    1443           0 :                 sColumns.append(",");
    1444           0 :             sColumns.append(sQuote + aDestColumnNames[aPosIter->second - 1] + sQuote);
    1445             :         }
    1446             :     }
    1447           0 :     const OUString sComposedTableName = ::dbtools::composeTableName( xDestMetaData, _xTable, ::dbtools::eInDataManipulation, false, false, true );
    1448           0 :     OUString sSql("INSERT INTO " + sComposedTableName + " ( " + sColumns.makeStringAndClear() + " ) ( " + m_pSourceObject->getSelectStatement() + " )");
    1449             : 
    1450           0 :     return sSql;
    1451             : }
    1452             : 
    1453           0 : void SAL_CALL CopyTableWizard::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException, std::exception)
    1454             : {
    1455           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1456           0 :     if ( isInitialized() )
    1457           0 :         throw AlreadyInitializedException( OUString(), *this );
    1458             : 
    1459           0 :     sal_Int32 nArgCount( _rArguments.getLength() );
    1460           0 :     if ( ( nArgCount != 2 ) && ( nArgCount != 3 ) )
    1461             :         throw IllegalArgumentException(
    1462             :             OUString( ModuleRes( STR_CTW_ILLEGAL_PARAMETER_COUNT ) ),
    1463             :             *this,
    1464             :             1
    1465           0 :         );
    1466             : 
    1467             :     try
    1468             :     {
    1469           0 :         if ( nArgCount == 3 )
    1470             :         {   // ->createWithInteractionHandler
    1471           0 :             if ( !( _rArguments[2] >>= m_xInteractionHandler ) )
    1472             :                 throw IllegalArgumentException(
    1473             :                     OUString(ModuleRes( STR_CTW_ERROR_INVALID_INTERACTIONHANDLER )),
    1474             :                     *this,
    1475             :                     3
    1476           0 :                 );
    1477             :         }
    1478           0 :         if ( !m_xInteractionHandler.is() )
    1479           0 :             m_xInteractionHandler.set( InteractionHandler::createWithParent(m_xContext, 0), UNO_QUERY );
    1480             : 
    1481           0 :         Reference< XInteractionHandler > xSourceDocHandler;
    1482           0 :         Reference< XPropertySet > xSourceDescriptor( impl_ensureDataAccessDescriptor_throw( _rArguments, 0, m_xSourceConnection, xSourceDocHandler ) );
    1483           0 :         impl_checkForUnsupportedSettings_throw( xSourceDescriptor );
    1484           0 :         m_pSourceObject = impl_extractSourceObject_throw( xSourceDescriptor, m_nCommandType );
    1485           0 :         impl_extractSourceResultSet_throw( xSourceDescriptor );
    1486             : 
    1487           0 :         Reference< XInteractionHandler > xDestDocHandler;
    1488           0 :         impl_ensureDataAccessDescriptor_throw( _rArguments, 1, m_xDestConnection, xDestDocHandler );
    1489             : 
    1490           0 :         if ( xDestDocHandler.is() && !m_xInteractionHandler.is() )
    1491           0 :             m_xInteractionHandler = xDestDocHandler;
    1492             :     }
    1493           0 :     catch( const RuntimeException& ) { throw; }
    1494           0 :     catch( const SQLException& ) { throw; }
    1495           0 :     catch( const Exception& )
    1496             :     {
    1497             :         throw WrappedTargetException(
    1498             :             OUString( ModuleRes( STR_CTW_ERROR_DURING_INITIALIZATION ) ),
    1499             :             *this,
    1500             :             ::cppu::getCaughtException()
    1501           0 :         );
    1502           0 :     }
    1503           0 : }
    1504             : 
    1505           0 : ::cppu::IPropertyArrayHelper& CopyTableWizard::getInfoHelper()
    1506             : {
    1507           0 :     return *getArrayHelper();
    1508             : }
    1509             : 
    1510           0 : ::cppu::IPropertyArrayHelper* CopyTableWizard::createArrayHelper( ) const
    1511             : {
    1512           0 :     Sequence< Property > aProps;
    1513           0 :     describeProperties( aProps );
    1514           0 :     return new ::cppu::OPropertyArrayHelper( aProps );
    1515             : }
    1516             : 
    1517           0 : Dialog* CopyTableWizard::createDialog( vcl::Window* _pParent )
    1518             : {
    1519             :     OSL_PRECOND( isInitialized(), "CopyTableWizard::createDialog: not initialized!" );
    1520             :         // this should have been prevented in ::execute already
    1521             : 
    1522             :     OCopyTableWizard* pWizard = new OCopyTableWizard(
    1523             :         _pParent,
    1524             :         m_sDestinationTable,
    1525             :         m_nOperation,
    1526           0 :         *m_pSourceObject,
    1527           0 :         m_xSourceConnection.getTyped(),
    1528           0 :         m_xDestConnection.getTyped(),
    1529             :         m_xContext,
    1530             :         m_xInteractionHandler
    1531           0 :     );
    1532             : 
    1533           0 :     impl_attributesToDialog_nothrow( *pWizard );
    1534             : 
    1535           0 :     return pWizard;
    1536             : }
    1537             : 
    1538           0 : void CopyTableWizard::executedDialog( sal_Int16 _nExecutionResult )
    1539             : {
    1540           0 :     CopyTableWizard_DialogBase::executedDialog( _nExecutionResult );
    1541             : 
    1542           0 :     if ( _nExecutionResult == RET_OK )
    1543           0 :         impl_doCopy_nothrow();
    1544             : 
    1545             :     // do this after impl_doCopy_nothrow: The attributes may change during copying, for instance
    1546             :     // if the user entered an unqualified table name
    1547           0 :     impl_dialogToAttributes_nothrow( impl_getDialog_throw() );
    1548           0 : }
    1549             : 
    1550             : } // namespace dbaui
    1551             : 
    1552          24 : extern "C" void SAL_CALL createRegistryInfo_CopyTableWizard()
    1553             : {
    1554          24 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::CopyTableWizard > aAutoRegistration;
    1555          96 : }
    1556             : 
    1557             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10