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