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() throw (::com::sun::star::uno::RuntimeException); 104 105 // ::com::sun::star::uno::XInterface 106 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException); 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( ) throw(::com::sun::star::uno::RuntimeException); 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 throw (::com::sun::star::lang::IllegalArgumentException); 128 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 129 sal_Int32 nHandle, 130 const ::com::sun::star::uno::Any& rValue 131 ) 132 throw (::com::sun::star::uno::Exception); 133 virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 134 135 // ::com::sun::star::sdbc::XWarningsSupplier 136 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 137 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 138 139 // ::com::sun::star::util::XCancellable 140 virtual void SAL_CALL cancel( ) throw(::com::sun::star::uno::RuntimeException); 141 142 // ::com::sun::star::sdbc::XCloseable 143 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 144 145 // ::com::sun::star::sdbc::XMultipleResults 146 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); 147 virtual sal_Int32 SAL_CALL getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 148 virtual sal_Bool SAL_CALL getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 149 150 // ::com::sun::star::sdbc::XPreparedBatchExecution 151 virtual void SAL_CALL addBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 152 virtual void SAL_CALL clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 153 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 154 // ::com::sun::star::sdbc::XGeneratedResultSet 155 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); 156 157 // Helper 158 void disposeResultSet(); 159 160 protected: 161 using ::cppu::OPropertySetHelper::getFastPropertyValue; 162 }; 163 164 //************************************************************ 165 // OStatement 166 //************************************************************ 167 typedef ::cppu::ImplHelper3 < ::com::sun::star::sdbc::XStatement 168 , ::com::sun::star::lang::XServiceInfo 169 , ::com::sun::star::sdbc::XBatchExecution 170 > OStatement_IFACE; 171 class OStatement :public OStatementBase 172 ,public OStatement_IFACE 173 { 174 private: 175 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > m_xAggregateStatement; 176 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer > m_xComposer; 177 bool m_bAttemptedComposerCreation; 178 179 public: 180 OStatement(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > & _xConn, 181 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & _xStatement); 182 183 DECLARE_XINTERFACE() 184 DECLARE_XTYPEPROVIDER() 185 186 // ::com::sun::star::lang::XServiceInfo 187 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 188 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 189 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 190 191 // ::com::sun::star::sdbc::XStatement 192 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); 193 virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 194 virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 195 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); 196 197 // OComponentHelper 198 virtual void SAL_CALL disposing(); 199 200 // XBatchExecution 201 virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 202 virtual void SAL_CALL clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 203 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 204 205 using OStatementBase::addBatch; 206 207 private: 208 /** does escape processing for the given SQL command, if the our EscapeProcessing 209 property allows so. 210 */ 211 ::rtl::OUString impl_doEscapeProcessing_nothrow( const ::rtl::OUString& _rSQL ) const; 212 bool impl_ensureComposer_nothrow() const; 213 }; 214 215 #endif // _DBA_COREAPI_STATEMENT_HXX_ 216 217