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 _CONNECTIVITY_JAVA_SQL_STATEMENT_HXX_ 24 #define _CONNECTIVITY_JAVA_SQL_STATEMENT_HXX_ 25 26 #include "java/lang/Object.hxx" 27 #include <com/sun/star/sdbc/XStatement.hpp> 28 #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 29 #include <com/sun/star/sdbc/XMultipleResults.hpp> 30 #include <com/sun/star/sdbc/XBatchExecution.hpp> 31 #include <com/sun/star/sdbc/XCloseable.hpp> 32 #include <com/sun/star/util/XCancellable.hpp> 33 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp> 34 #include <comphelper/proparrhlp.hxx> 35 #include <cppuhelper/compbase6.hxx> 36 #include <comphelper/uno3.hxx> 37 #include "connectivity/CommonTools.hxx" 38 #include "OSubComponent.hxx" 39 #include <com/sun/star/lang/XServiceInfo.hpp> 40 #include <comphelper/broadcasthelper.hxx> 41 42 #include "java/sql/ConnectionLog.hxx" 43 44 namespace connectivity 45 { 46 47 typedef ::cppu::WeakComponentImplHelper6< ::com::sun::star::sdbc::XStatement, 48 ::com::sun::star::sdbc::XWarningsSupplier, 49 ::com::sun::star::util::XCancellable, 50 ::com::sun::star::sdbc::XCloseable, 51 ::com::sun::star::sdbc::XGeneratedResultSet, 52 ::com::sun::star::sdbc::XMultipleResults> java_sql_Statement_BASE; 53 54 class java_sql_Connection; 55 56 //************************************************************** 57 //************ Class: java.sql.Statement 58 //************************************************************** 59 class java_sql_Statement_Base : public comphelper::OBaseMutex, 60 public java_sql_Statement_BASE, 61 public java_lang_Object, 62 public ::cppu::OPropertySetHelper, 63 public ::comphelper::OPropertyArrayUsageHelper<java_sql_Statement_Base> 64 65 { 66 67 sal_Int32 getQueryTimeOut() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 68 sal_Int32 getMaxFieldSize() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 69 sal_Int32 getMaxRows() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 70 sal_Int32 getResultSetConcurrency() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 71 sal_Int32 getResultSetType() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 72 sal_Int32 getFetchDirection() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 73 sal_Int32 getFetchSize() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 74 ::rtl::OUString getCursorName() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 75 76 void setQueryTimeOut(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 77 void setMaxFieldSize(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 78 void setMaxRows(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 79 void setResultSetConcurrency(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 80 void setResultSetType(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 81 void setFetchDirection(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 82 void setFetchSize(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 83 void setCursorName(const ::rtl::OUString &_par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 84 void setEscapeProcessing(sal_Bool _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 85 86 protected: 87 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement> m_xGeneratedStatement; 88 java_sql_Connection* m_pConnection; 89 java::sql::ConnectionLog m_aLogger; 90 ::rtl::OUString m_sSqlStatement; 91 // Properties 92 sal_Int32 m_nResultSetConcurrency; 93 sal_Int32 m_nResultSetType; 94 sal_Bool m_bEscapeProcessing; 95 ::cppu::OBroadcastHelper& rBHelper; 96 97 98 // statische Daten fuer die Klasse 99 static jclass theClass; 100 101 // OPropertyArrayUsageHelper 102 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 103 // OPropertySetHelper 104 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); 105 106 virtual sal_Bool SAL_CALL convertFastPropertyValue( 107 ::com::sun::star::uno::Any & rConvertedValue, 108 ::com::sun::star::uno::Any & rOldValue, 109 sal_Int32 nHandle, 110 const ::com::sun::star::uno::Any& rValue 111 ) throw (::com::sun::star::lang::IllegalArgumentException); 112 113 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 114 sal_Int32 nHandle, 115 const ::com::sun::star::uno::Any& rValue 116 ) throw (::com::sun::star::uno::Exception); 117 118 virtual void SAL_CALL getFastPropertyValue( 119 ::com::sun::star::uno::Any& rValue, 120 sal_Int32 nHandle 121 ) const; 122 123 virtual void createStatement(JNIEnv* _pEnv) = 0; 124 125 virtual ~java_sql_Statement_Base(); 126 127 sal_Int32 impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID); 128 sal_Int32 impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault); 129 130 public: 131 virtual jclass getMyClass() const; 132 133 // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird: 134 java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon ); 135 getStatementObjectID() const136 sal_Int32 getStatementObjectID() const { return m_aLogger.getObjectID(); } 137 138 // OComponentHelper 139 virtual void SAL_CALL disposing(void); 140 // XInterface 141 virtual void SAL_CALL acquire() throw(); 142 virtual void SAL_CALL release() throw(); 143 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 144 //XTypeProvider 145 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); 146 147 // XPropertySet 148 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 149 // XStatement 150 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) ; 151 virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 152 virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 153 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) ; 154 // XWarningsSupplier 155 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 156 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 157 // XCancellable 158 virtual void SAL_CALL cancel( ) throw(::com::sun::star::uno::RuntimeException); 159 // XCloseable 160 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 161 // XMultipleResults 162 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); 163 virtual sal_Int32 SAL_CALL getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 164 virtual sal_Bool SAL_CALL getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 165 //XGeneratedResultSet 166 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); 167 168 public: 169 using ::cppu::OPropertySetHelper::getFastPropertyValue; 170 }; 171 172 class OStatement_BASE2 :public java_sql_Statement_Base 173 ,public OSubComponent<OStatement_BASE2, java_sql_Statement_BASE> 174 175 { 176 friend class OSubComponent<OStatement_BASE2, java_sql_Statement_BASE>; 177 public: OStatement_BASE2(JNIEnv * pEnv,java_sql_Connection & _rCon)178 OStatement_BASE2(JNIEnv * pEnv, java_sql_Connection& _rCon ) : java_sql_Statement_Base( pEnv, _rCon ), 179 OSubComponent<OStatement_BASE2, java_sql_Statement_BASE>((::cppu::OWeakObject*)(&_rCon), this){} 180 181 // OComponentHelper 182 virtual void SAL_CALL disposing(void); 183 // XInterface 184 virtual void SAL_CALL release() throw(); 185 }; 186 187 class java_sql_Statement : public OStatement_BASE2, 188 public ::com::sun::star::sdbc::XBatchExecution, 189 public ::com::sun::star::lang::XServiceInfo 190 { 191 protected: 192 // statische Daten fuer die Klasse 193 static jclass theClass; 194 195 virtual void createStatement(JNIEnv* _pEnv); 196 197 virtual ~java_sql_Statement(); 198 public: 199 DECLARE_SERVICE_INFO(); 200 virtual jclass getMyClass() const; 201 202 // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird: java_sql_Statement(JNIEnv * pEnv,java_sql_Connection & _rCon)203 java_sql_Statement( JNIEnv * pEnv, java_sql_Connection& _rCon ) : OStatement_BASE2( pEnv, _rCon){}; 204 205 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 206 virtual void SAL_CALL acquire() throw(); 207 virtual void SAL_CALL release() throw(); 208 // XBatchExecution 209 virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 210 virtual void SAL_CALL clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 211 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 212 }; 213 } 214 #endif // _CONNECTIVITY_JAVA_SQL_STATEMENT_HXX_ 215 216