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