1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _DBA_COREAPI_STATEMENT_HXX_
28 #define _DBA_COREAPI_STATEMENT_HXX_
29 
30 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_SDBC_XSTATEMENT_HPP_
34 #include <com/sun/star/sdbc/XStatement.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
37 #include <com/sun/star/sdbc/XConnection.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_UTIL_XCANCELLABLE_HPP_
40 #include <com/sun/star/util/XCancellable.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
43 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_XCLOSEABLE_HPP_
46 #include <com/sun/star/sdbc/XCloseable.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SDBC_XMULTIPLERESULTS_HDL_
49 #include <com/sun/star/sdbc/XMultipleResults.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDBATCHEXECUTION_HDL_
52 #include <com/sun/star/sdbc/XPreparedBatchExecution.hpp>
53 #endif
54 #include <com/sun/star/sdbc/XBatchExecution.hpp>
55 #ifndef _COM_SUN_STAR_SDBC_XGENERATEDRESULTSET_HPP_
56 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
59 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
60 #endif
61 #ifndef _CPPUHELPER_PROPSHLP_HXX
62 #include <cppuhelper/propshlp.hxx>
63 #endif
64 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
65 #include <comphelper/proparrhlp.hxx>
66 #endif
67 #ifndef _DBASHARED_APITOOLS_HXX_
68 #include "apitools.hxx"
69 #endif
70 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_
71 #include <comphelper/broadcasthelper.hxx>
72 #endif
73 
74 #include <cppuhelper/implbase3.hxx>
75 
76 //************************************************************
77 //  OStatementBase
78 //************************************************************
79 class OStatementBase :	public comphelper::OBaseMutex,
80 						public OSubComponent,
81 						public ::cppu::OPropertySetHelper,
82 						public ::comphelper::OPropertyArrayUsageHelper < OStatementBase >,
83 						public ::com::sun::star::util::XCancellable,
84 						public ::com::sun::star::sdbc::XWarningsSupplier,
85 						public ::com::sun::star::sdbc::XPreparedBatchExecution,
86 						public ::com::sun::star::sdbc::XMultipleResults,
87 						public ::com::sun::star::sdbc::XCloseable,
88 						public ::com::sun::star::sdbc::XGeneratedResultSet
89 {
90 protected:
91 	::osl::Mutex			m_aCancelMutex;
92 
93 	::com::sun::star::uno::WeakReferenceHelper	m_aResultSet;
94 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xAggregateAsSet;
95 	::com::sun::star::uno::Reference< ::com::sun::star::util::XCancellable > m_xAggregateAsCancellable;
96 	sal_Bool				m_bUseBookmarks;
97     sal_Bool                m_bEscapeProcessing;
98 
99 	virtual ~OStatementBase();
100 
101 public:
102 	OStatementBase(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > & _xConn,
103 				   const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & _xStatement);
104 
105 
106 // ::com::sun::star::lang::XTypeProvider
107 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
108 
109 // ::com::sun::star::uno::XInterface
110 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException);
111 	virtual void SAL_CALL acquire() throw();
112     virtual void SAL_CALL release() throw();
113 
114 // OComponentHelper
115 	virtual void SAL_CALL disposing(void);
116 
117 // com::sun::star::beans::XPropertySet
118 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
119 
120 // comphelper::OPropertyArrayUsageHelper
121 	virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
122 
123 // cppu::OPropertySetHelper
124 	virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
125 
126 	virtual sal_Bool SAL_CALL convertFastPropertyValue(
127 							::com::sun::star::uno::Any & rConvertedValue,
128 							::com::sun::star::uno::Any & rOldValue,
129 							sal_Int32 nHandle,
130 							const ::com::sun::star::uno::Any& rValue )
131 								throw (::com::sun::star::lang::IllegalArgumentException);
132 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
133 								sal_Int32 nHandle,
134 								const ::com::sun::star::uno::Any& rValue
135 												 )
136 												 throw (::com::sun::star::uno::Exception);
137 	virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
138 
139 // ::com::sun::star::sdbc::XWarningsSupplier
140     virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
141     virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
142 
143 // ::com::sun::star::util::XCancellable
144 	virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
145 
146 // ::com::sun::star::sdbc::XCloseable
147 	virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
148 
149 // ::com::sun::star::sdbc::XMultipleResults
150     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
151     virtual sal_Int32 SAL_CALL getUpdateCount(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
152     virtual sal_Bool SAL_CALL getMoreResults(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
153 
154 // ::com::sun::star::sdbc::XPreparedBatchExecution
155     virtual void SAL_CALL addBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
156     virtual void SAL_CALL clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
157     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
158 // ::com::sun::star::sdbc::XGeneratedResultSet
159 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getGeneratedValues(  ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
160 
161 // Helper
162 	void disposeResultSet();
163 
164 protected:
165     using ::cppu::OPropertySetHelper::getFastPropertyValue;
166 };
167 
168 //************************************************************
169 //  OStatement
170 //************************************************************
171 typedef ::cppu::ImplHelper3 <   ::com::sun::star::sdbc::XStatement
172                             ,   ::com::sun::star::lang::XServiceInfo
173                             ,   ::com::sun::star::sdbc::XBatchExecution
174                             >   OStatement_IFACE;
175 class OStatement    :public OStatementBase
176                     ,public OStatement_IFACE
177 {
178 private:
179 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement >                  m_xAggregateStatement;
180     ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >   m_xComposer;
181     bool                                                                                    m_bAttemptedComposerCreation;
182 
183 public:
184 	OStatement(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > & _xConn,
185 			   const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & _xStatement);
186 
187     DECLARE_XINTERFACE()
188     DECLARE_XTYPEPROVIDER()
189 
190 // ::com::sun::star::lang::XServiceInfo
191     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
192     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
193     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
194 
195 // ::com::sun::star::sdbc::XStatement
196     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
197     virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
198     virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
199     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
200 
201     // OComponentHelper
202 	virtual void SAL_CALL disposing();
203 
204     // XBatchExecution
205 	virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
206 	virtual void SAL_CALL clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
207 	virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
208 
209     using OStatementBase::addBatch;
210 
211 private:
212     /** does escape processing for the given SQL command, if the our EscapeProcessing
213         property allows so.
214     */
215     ::rtl::OUString impl_doEscapeProcessing_nothrow( const ::rtl::OUString& _rSQL ) const;
216     bool            impl_ensureComposer_nothrow() const;
217 };
218 
219 #endif // _DBA_COREAPI_STATEMENT_HXX_
220 
221