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