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 #ifndef MYSQLC_STATEMENT_HXX 22 #define MYSQLC_STATEMENT_HXX 23 24 #include "mysqlc_connection.hxx" 25 #include "mysqlc_subcomponent.hxx" 26 27 #include <com/sun/star/lang/XServiceInfo.hpp> 28 #include <com/sun/star/sdbc/SQLWarning.hpp> 29 #include <com/sun/star/sdbc/XBatchExecution.hpp> 30 #include <com/sun/star/sdbc/XCloseable.hpp> 31 #include <com/sun/star/sdbc/XMultipleResults.hpp> 32 #include <com/sun/star/sdbc/XStatement.hpp> 33 #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 34 #include <com/sun/star/util/XCancellable.hpp> 35 36 #include <preextstl.h> 37 #include <cppconn/statement.h> 38 #include <postextstl.h> 39 #include <cppuhelper/compbase5.hxx> 40 #include <list> 41 42 namespace connectivity 43 { 44 namespace mysqlc 45 { 46 using ::com::sun::star::sdbc::SQLWarning; 47 using ::com::sun::star::sdbc::SQLException; 48 using ::com::sun::star::uno::Any; 49 using ::com::sun::star::uno::RuntimeException; 50 using ::rtl::OUString; 51 52 typedef ::cppu::WeakComponentImplHelper5< ::com::sun::star::sdbc::XStatement, 53 ::com::sun::star::sdbc::XWarningsSupplier, 54 ::com::sun::star::util::XCancellable, 55 ::com::sun::star::sdbc::XCloseable, 56 ::com::sun::star::sdbc::XMultipleResults> OCommonStatement_IBase; 57 58 class OCommonStatement; 59 typedef OSubComponent< OCommonStatement, OCommonStatement_IBase > OStatement_CBase; 60 61 //************************************************************** 62 //************ Class: OCommonStatement 63 // is a base class for the normal statement and for the prepared statement 64 //************************************************************** 65 class OCommonStatement :public OBase_Mutex 66 ,public OCommonStatement_IBase 67 ,public ::cppu::OPropertySetHelper 68 ,public OPropertyArrayUsageHelper<OCommonStatement> 69 ,public OStatement_CBase 70 71 { 72 friend class OSubComponent< OCommonStatement, OCommonStatement_IBase >; 73 74 private: 75 SQLWarning m_aLastWarning; 76 77 protected: 78 ::std::list< OUString> m_aBatchList; 79 80 OConnection* m_pConnection; // The owning Connection object 81 82 sql::Statement *cppStatement; 83 84 protected: 85 void disposeResultSet(); 86 87 // OPropertyArrayUsageHelper 88 ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 89 90 // OPropertySetHelper 91 ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); 92 sal_Bool SAL_CALL convertFastPropertyValue(Any & rConvertedValue, Any & rOldValue, 93 sal_Int32 nHandle, const Any& rValue) 94 throw (::com::sun::star::lang::IllegalArgumentException); 95 96 void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) 97 throw(::com::sun::star::uno::Exception); 98 99 void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const; 100 virtual ~OCommonStatement(); 101 102 protected: 103 OCommonStatement(OConnection* _pConnection, sql::Statement *_cppStatement); 104 105 public: 106 ::cppu::OBroadcastHelper& rBHelper; 107 using OCommonStatement_IBase::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >; 108 109 // OComponentHelper 110 void SAL_CALL disposing(void); 111 112 // XInterface 113 void SAL_CALL release() throw(); 114 115 void SAL_CALL acquire() throw(); 116 117 // XInterface 118 Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & rType) 119 throw(RuntimeException); 120 121 //XTypeProvider 122 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() 123 throw(RuntimeException); 124 125 // XPropertySet 126 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() 127 throw(RuntimeException); 128 129 // XStatement 130 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery(const OUString& sql) 131 throw(SQLException, RuntimeException); 132 133 sal_Int32 SAL_CALL executeUpdate(const OUString& sql) 134 throw(SQLException, RuntimeException); 135 136 sal_Bool SAL_CALL execute( const OUString& sql ) 137 throw(SQLException, RuntimeException); 138 139 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection() 140 throw(SQLException, RuntimeException); 141 142 // XWarningsSupplier 143 Any SAL_CALL getWarnings() throw(SQLException, RuntimeException); 144 145 void SAL_CALL clearWarnings() throw(SQLException, RuntimeException); 146 147 // XCancellable 148 void SAL_CALL cancel() throw(RuntimeException); 149 150 // XCloseable 151 void SAL_CALL close() throw(SQLException, RuntimeException); 152 153 // XMultipleResults 154 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet() 155 throw(SQLException, RuntimeException); 156 157 sal_Int32 SAL_CALL getUpdateCount() throw(SQLException, RuntimeException); 158 159 sal_Bool SAL_CALL getMoreResults() throw(SQLException, RuntimeException); 160 161 // other methods getOwnConnection() const162 OConnection* getOwnConnection() const { return m_pConnection;} 163 164 private: 165 using ::cppu::OPropertySetHelper::getFastPropertyValue; 166 }; 167 168 169 class OStatement : public OCommonStatement, 170 public ::com::sun::star::sdbc::XBatchExecution, 171 public ::com::sun::star::lang::XServiceInfo 172 173 { 174 protected: ~OStatement()175 virtual ~OStatement(){} 176 177 public: 178 // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird: OStatement(OConnection * _pConnection,sql::Statement * _cppStatement)179 OStatement(OConnection* _pConnection, sql::Statement *_cppStatement) : OCommonStatement(_pConnection, _cppStatement) {} 180 DECLARE_SERVICE_INFO(); 181 182 Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) 183 throw(RuntimeException); 184 185 void SAL_CALL acquire() throw(); 186 void SAL_CALL release() throw(); 187 188 // XBatchExecution 189 void SAL_CALL addBatch(const OUString& sql) 190 throw(SQLException, RuntimeException); 191 192 void SAL_CALL clearBatch() throw(SQLException, RuntimeException); 193 194 ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch() 195 throw(SQLException, RuntimeException); 196 197 }; 198 } 199 } 200 #endif // MYSQLC_STATEMENT_HXX 201 202 /* 203 * Local variables: 204 * tab-width: 4 205 * c-basic-offset: 4 206 * End: 207 * vim600: noet sw=4 ts=4 fdm=marker 208 * vim<600: noet sw=4 ts=4 209 */ 210