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