xref: /AOO41X/main/odk/examples/DevelopersGuide/Database/DriverSkeleton/SStatement.hxx (revision 34dd1e2512dbacb6a9a7e4c7f17b9296daa8eff3)
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 
24 #ifndef CONNECTIVITY_SSTATEMENT_HXX
25 #define CONNECTIVITY_SSTATEMENT_HXX
26 
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/sdbc/SQLWarning.hpp>
33 #include <com/sun/star/util/XCancellable.hpp>
34 #include <cppuhelper/compbase5.hxx>
35 #include "SConnection.hxx"
36 #include <list>
37 #include "OSubComponent.hxx"
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 
40 namespace connectivity
41 {
42     namespace skeleton
43     {
44 
45         typedef ::cppu::WeakComponentImplHelper5<   ::com::sun::star::sdbc::XStatement,
46                                                     ::com::sun::star::sdbc::XWarningsSupplier,
47                                                     ::com::sun::star::util::XCancellable,
48                                                     ::com::sun::star::sdbc::XCloseable,
49                                                     ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE;
50 
51         //**************************************************************
52         //************ Class: OStatement_Base
53         // is a base class for the normal statement and for the prepared statement
54         //**************************************************************
55         class OStatement_Base       :   public OBase_Mutex,
56                                         public  OStatement_BASE,
57                                         public  ::cppu::OPropertySetHelper,
58                                         public  OPropertyArrayUsageHelper<OStatement_Base>
59 
60         {
61         ::com::sun::star::sdbc::SQLWarning                            m_aLastWarning;
62         protected:
63             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
64             //  for this Statement
65 
66             ::std::list< ::rtl::OUString>               m_aBatchList;
67 
68             OConnection*                                m_pConnection;  // The owning Connection object
69         protected:
70 
71             void disposeResultSet();
72 
73             // OPropertyArrayUsageHelper
74             virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
75             // OPropertySetHelper
76             virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
77             virtual sal_Bool SAL_CALL convertFastPropertyValue(
78                                                                 ::com::sun::star::uno::Any & rConvertedValue,
79                                                                 ::com::sun::star::uno::Any & rOldValue,
80                                                                 sal_Int32 nHandle,
81                                                                 const ::com::sun::star::uno::Any& rValue )
82                                                             throw (::com::sun::star::lang::IllegalArgumentException);
83             virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
84                                                                 sal_Int32 nHandle,
85                                                                 const ::com::sun::star::uno::Any& rValue)   throw (::com::sun::star::uno::Exception);
86             virtual void SAL_CALL getFastPropertyValue(
87                                                                 ::com::sun::star::uno::Any& rValue,
88                                                                 sal_Int32 nHandle) const;
89             virtual ~OStatement_Base();
90 
91         public:
92             ::cppu::OBroadcastHelper& rBHelper;
93             OStatement_Base(OConnection* _pConnection );
94             using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
95 
96             // OComponentHelper
disposing(void)97             virtual void SAL_CALL disposing(void){OStatement_BASE::disposing();}
98             // XInterface
99             virtual void SAL_CALL release() throw();
100             virtual void SAL_CALL acquire() throw();
101             // XInterface
102             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
103             //XTypeProvider
104             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
105 
106             // XPropertySet
107             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
108             // XStatement
109             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) ;
110             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
111             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
112             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) ;
113             // XWarningsSupplier
114             virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
115             virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
116             // XCancellable
117             virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
118             // XCloseable
119             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
120             // XMultipleResults
121             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);
122             virtual sal_Int32 SAL_CALL getUpdateCount(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
123             virtual sal_Bool SAL_CALL getMoreResults(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
124 
125             // other methods
getOwnConnection() const126             OConnection* getOwnConnection() const { return m_pConnection;}
127         };
128 
129         class OStatement_BASE2  :public OStatement_Base
130                                 ,public OSubComponent<OStatement_BASE2, OStatement_BASE>
131 
132         {
133             friend class OSubComponent<OStatement_BASE2, OStatement_BASE>;
134         public:
OStatement_BASE2(OConnection * _pConnection)135             OStatement_BASE2(OConnection* _pConnection ) :  OStatement_Base(_pConnection ),
136                                     OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){}
137             // OComponentHelper
138             virtual void SAL_CALL disposing(void);
139             // XInterface
140             virtual void SAL_CALL release() throw();
141         };
142 
143         class OStatement :  public OStatement_BASE2,
144                             public ::com::sun::star::sdbc::XBatchExecution,
145                             public ::com::sun::star::lang::XServiceInfo
146         {
147         protected:
~OStatement()148             virtual ~OStatement(){}
149         public:
150             // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
OStatement(OConnection * _pConnection)151             OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
152             DECLARE_SERVICE_INFO();
153 
154             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
155             virtual void SAL_CALL acquire() throw();
156             virtual void SAL_CALL release() throw();
157             // XBatchExecution
158             virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
159             virtual void SAL_CALL clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
160             virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
161         };
162     }
163 }
164 #endif // CONNECTIVITY_SSTATEMENT_HXX
165