1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 #ifndef CONNECTIVITY_SSTATEMENT_HXX
36 #define CONNECTIVITY_SSTATEMENT_HXX
37 
38 #include <com/sun/star/sdbc/XStatement.hpp>
39 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
40 #include <com/sun/star/sdbc/XMultipleResults.hpp>
41 #include <com/sun/star/sdbc/XBatchExecution.hpp>
42 #include <com/sun/star/sdbc/XCloseable.hpp>
43 #include <com/sun/star/sdbc/SQLWarning.hpp>
44 #include <com/sun/star/util/XCancellable.hpp>
45 #include <cppuhelper/compbase5.hxx>
46 #include "SConnection.hxx"
47 #include <list>
48 #include "OSubComponent.hxx"
49 #include <com/sun/star/lang/XServiceInfo.hpp>
50 
51 namespace connectivity
52 {
53 	namespace skeleton
54 	{
55 
56         typedef ::cppu::WeakComponentImplHelper5<	::com::sun::star::sdbc::XStatement,
57                                                     ::com::sun::star::sdbc::XWarningsSupplier,
58                                                     ::com::sun::star::util::XCancellable,
59                                                     ::com::sun::star::sdbc::XCloseable,
60                                                     ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE;
61 
62 		//**************************************************************
63 		//************ Class: OStatement_Base
64 		// is a base class for the normal statement and for the prepared statement
65 		//**************************************************************
66 		class OStatement_Base		:	public OBase_Mutex,
67 										public	OStatement_BASE,
68 										public	::cppu::OPropertySetHelper,
69 										public	OPropertyArrayUsageHelper<OStatement_Base>
70 
71 		{
72         ::com::sun::star::sdbc::SQLWarning                            m_aLastWarning;
73 		protected:
74 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
75 			//  for this Statement
76 
77 			::std::list< ::rtl::OUString>				m_aBatchList;
78 
79 			OConnection*								m_pConnection;	// The owning Connection object
80 		protected:
81 
82 			void disposeResultSet();
83 
84 			// OPropertyArrayUsageHelper
85 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
86 			// OPropertySetHelper
87 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
88 			virtual sal_Bool SAL_CALL convertFastPropertyValue(
89 																::com::sun::star::uno::Any & rConvertedValue,
90 																::com::sun::star::uno::Any & rOldValue,
91 																sal_Int32 nHandle,
92 																const ::com::sun::star::uno::Any& rValue )
93 															throw (::com::sun::star::lang::IllegalArgumentException);
94 			virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
95 																sal_Int32 nHandle,
96 																const ::com::sun::star::uno::Any& rValue)	throw (::com::sun::star::uno::Exception);
97 			virtual void SAL_CALL getFastPropertyValue(
98 																::com::sun::star::uno::Any& rValue,
99 																sal_Int32 nHandle) const;
100 			virtual ~OStatement_Base();
101 
102 		public:
103 			::cppu::OBroadcastHelper& rBHelper;
104 			OStatement_Base(OConnection* _pConnection );
105 			using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
106 
107 			// OComponentHelper
108 			virtual void SAL_CALL disposing(void){OStatement_BASE::disposing();}
109 			// XInterface
110             virtual void SAL_CALL release() throw();
111 			virtual void SAL_CALL acquire() throw();
112 			// XInterface
113             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
114 			//XTypeProvider
115             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
116 
117 			// XPropertySet
118             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
119 			// XStatement
120             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) ;
121             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
122             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
123             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) ;
124 			// XWarningsSupplier
125 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
126 			virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
127 			// XCancellable
128 			virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
129 			// XCloseable
130             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
131 			// XMultipleResults
132             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);
133             virtual sal_Int32 SAL_CALL getUpdateCount(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134             virtual sal_Bool SAL_CALL getMoreResults(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135 
136 			// other methods
137 			OConnection* getOwnConnection() const { return m_pConnection;}
138 		};
139 
140 		class OStatement_BASE2	:public OStatement_Base
141 								,public OSubComponent<OStatement_BASE2, OStatement_BASE>
142 
143 		{
144 			friend class OSubComponent<OStatement_BASE2, OStatement_BASE>;
145 		public:
146 			OStatement_BASE2(OConnection* _pConnection ) :  OStatement_Base(_pConnection ),
147 									OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){}
148 			// OComponentHelper
149 			virtual void SAL_CALL disposing(void);
150 			// XInterface
151             virtual void SAL_CALL release() throw();
152 		};
153 
154 		class OStatement :	public OStatement_BASE2,
155                             public ::com::sun::star::sdbc::XBatchExecution,
156                             public ::com::sun::star::lang::XServiceInfo
157 		{
158 		protected:
159 			virtual ~OStatement(){}
160 		public:
161 			// ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
162 			OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
163 			DECLARE_SERVICE_INFO();
164 
165             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
166 			virtual void SAL_CALL acquire() throw();
167             virtual void SAL_CALL release() throw();
168 			// XBatchExecution
169             virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
170             virtual void SAL_CALL clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
171             virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
172 		};
173 	}
174 }
175 #endif // CONNECTIVITY_SSTATEMENT_HXX
176