xref: /trunk/main/dbaccess/source/core/inc/statement.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _DBA_COREAPI_STATEMENT_HXX_
24 #define _DBA_COREAPI_STATEMENT_HXX_
25 
26 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #endif
29 #ifndef _COM_SUN_STAR_SDBC_XSTATEMENT_HPP_
30 #include <com/sun/star/sdbc/XStatement.hpp>
31 #endif
32 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
33 #include <com/sun/star/sdbc/XConnection.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_UTIL_XCANCELLABLE_HPP_
36 #include <com/sun/star/util/XCancellable.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
39 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
40 #endif
41 #ifndef _COM_SUN_STAR_SDBC_XCLOSEABLE_HPP_
42 #include <com/sun/star/sdbc/XCloseable.hpp>
43 #endif
44 #ifndef _COM_SUN_STAR_SDBC_XMULTIPLERESULTS_HDL_
45 #include <com/sun/star/sdbc/XMultipleResults.hpp>
46 #endif
47 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDBATCHEXECUTION_HDL_
48 #include <com/sun/star/sdbc/XPreparedBatchExecution.hpp>
49 #endif
50 #include <com/sun/star/sdbc/XBatchExecution.hpp>
51 #ifndef _COM_SUN_STAR_SDBC_XGENERATEDRESULTSET_HPP_
52 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
55 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
56 #endif
57 #ifndef _CPPUHELPER_PROPSHLP_HXX
58 #include <cppuhelper/propshlp.hxx>
59 #endif
60 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
61 #include <comphelper/proparrhlp.hxx>
62 #endif
63 #ifndef _DBASHARED_APITOOLS_HXX_
64 #include "apitools.hxx"
65 #endif
66 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_
67 #include <comphelper/broadcasthelper.hxx>
68 #endif
69 
70 #include <cppuhelper/implbase3.hxx>
71 
72 //************************************************************
73 //  OStatementBase
74 //************************************************************
75 class OStatementBase :  public comphelper::OBaseMutex,
76                         public OSubComponent,
77                         public ::cppu::OPropertySetHelper,
78                         public ::comphelper::OPropertyArrayUsageHelper < OStatementBase >,
79                         public ::com::sun::star::util::XCancellable,
80                         public ::com::sun::star::sdbc::XWarningsSupplier,
81                         public ::com::sun::star::sdbc::XPreparedBatchExecution,
82                         public ::com::sun::star::sdbc::XMultipleResults,
83                         public ::com::sun::star::sdbc::XCloseable,
84                         public ::com::sun::star::sdbc::XGeneratedResultSet
85 {
86 protected:
87     ::osl::Mutex            m_aCancelMutex;
88 
89     ::com::sun::star::uno::WeakReferenceHelper  m_aResultSet;
90     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xAggregateAsSet;
91     ::com::sun::star::uno::Reference< ::com::sun::star::util::XCancellable > m_xAggregateAsCancellable;
92     sal_Bool                m_bUseBookmarks;
93     sal_Bool                m_bEscapeProcessing;
94 
95     virtual ~OStatementBase();
96 
97 public:
98     OStatementBase(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > & _xConn,
99                    const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & _xStatement);
100 
101 
102 // ::com::sun::star::lang::XTypeProvider
103     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes();
104 
105 // ::com::sun::star::uno::XInterface
106     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType );
107     virtual void SAL_CALL acquire() throw();
108     virtual void SAL_CALL release() throw();
109 
110 // OComponentHelper
111     virtual void SAL_CALL disposing(void);
112 
113 // com::sun::star::beans::XPropertySet
114     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  );
115 
116 // comphelper::OPropertyArrayUsageHelper
117     virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
118 
119 // cppu::OPropertySetHelper
120     virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
121 
122     virtual sal_Bool SAL_CALL convertFastPropertyValue(
123                             ::com::sun::star::uno::Any & rConvertedValue,
124                             ::com::sun::star::uno::Any & rOldValue,
125                             sal_Int32 nHandle,
126                             const ::com::sun::star::uno::Any& rValue );
127     virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
128                                 sal_Int32 nHandle,
129                                 const ::com::sun::star::uno::Any& rValue
130                                                  );
131     virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
132 
133 // ::com::sun::star::sdbc::XWarningsSupplier
134     virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  );
135     virtual void SAL_CALL clearWarnings(  );
136 
137 // ::com::sun::star::util::XCancellable
138     virtual void SAL_CALL cancel(  );
139 
140 // ::com::sun::star::sdbc::XCloseable
141     virtual void SAL_CALL close(  );
142 
143 // ::com::sun::star::sdbc::XMultipleResults
144     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet(  );
145     virtual sal_Int32 SAL_CALL getUpdateCount(  );
146     virtual sal_Bool SAL_CALL getMoreResults(  );
147 
148 // ::com::sun::star::sdbc::XPreparedBatchExecution
149     virtual void SAL_CALL addBatch(  );
150     virtual void SAL_CALL clearBatch(  );
151     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  );
152 // ::com::sun::star::sdbc::XGeneratedResultSet
153     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getGeneratedValues(  );
154 
155 // Helper
156     void disposeResultSet();
157 
158 protected:
159     using ::cppu::OPropertySetHelper::getFastPropertyValue;
160 };
161 
162 //************************************************************
163 //  OStatement
164 //************************************************************
165 typedef ::cppu::ImplHelper3 <   ::com::sun::star::sdbc::XStatement
166                             ,   ::com::sun::star::lang::XServiceInfo
167                             ,   ::com::sun::star::sdbc::XBatchExecution
168                             >   OStatement_IFACE;
169 class OStatement    :public OStatementBase
170                     ,public OStatement_IFACE
171 {
172 private:
173     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement >                  m_xAggregateStatement;
174     ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >   m_xComposer;
175     bool                                                                                    m_bAttemptedComposerCreation;
176 
177 public:
178     OStatement(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > & _xConn,
179                const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & _xStatement);
180 
181     DECLARE_XINTERFACE()
182     DECLARE_XTYPEPROVIDER()
183 
184 // ::com::sun::star::lang::XServiceInfo
185     virtual ::rtl::OUString SAL_CALL getImplementationName(  );
186     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
187     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
188 
189 // ::com::sun::star::sdbc::XStatement
190     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql );
191     virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql );
192     virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql );
193     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  );
194 
195     // OComponentHelper
196     virtual void SAL_CALL disposing();
197 
198     // XBatchExecution
199     virtual void SAL_CALL addBatch( const ::rtl::OUString& sql );
200     virtual void SAL_CALL clearBatch(  );
201     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  );
202 
203     using OStatementBase::addBatch;
204 
205 private:
206     /** does escape processing for the given SQL command, if the our EscapeProcessing
207         property allows so.
208     */
209     ::rtl::OUString impl_doEscapeProcessing_nothrow( const ::rtl::OUString& _rSQL ) const;
210     bool            impl_ensureComposer_nothrow() const;
211 };
212 
213 #endif // _DBA_COREAPI_STATEMENT_HXX_
214