Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / evoab2 / NStatement.hxx
blobb89973efa75149a96be03d20ea7e05f59c11375c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NStatement.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONNECTIVITY_EVOAB_STATEMENT_HXX_
32 #define _CONNECTIVITY_EVOAB_STATEMENT_HXX_
34 #include <com/sun/star/sdbc/XStatement.hpp>
35 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
36 #include <com/sun/star/sdbc/XMultipleResults.hpp>
37 #include <com/sun/star/sdbc/XCloseable.hpp>
38 #include <com/sun/star/sdbc/SQLWarning.hpp>
39 #include <comphelper/proparrhlp.hxx>
40 #include <cppuhelper/compbase2.hxx>
41 #include <comphelper/uno3.hxx>
42 #include "connectivity/CommonTools.hxx"
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <comphelper/broadcasthelper.hxx>
45 #include "connectivity/sqliterator.hxx"
46 #include "connectivity/sqlparse.hxx"
47 #include <connectivity/FValue.hxx>
48 #include "OSubComponent.hxx"
49 #include <com/sun/star/util/XCancellable.hpp>
50 #include <cppuhelper/compbase5.hxx>
51 #include <comphelper/propertycontainer.hxx>
52 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #include "EApi.h"
56 #include <list>
58 namespace connectivity
60 namespace evoab
62 class OEvoabResultSet;
63 class OEvoabConnection;
64 typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::sdbc::XWarningsSupplier
65 , ::com::sun::star::sdbc::XCloseable
66 > OCommonStatement_IBase;
68 struct FieldSort
70 sal_Int32 nField;
71 bool bAscending;
73 FieldSort() : nField(0), bAscending( true ) { }
74 FieldSort( const sal_Int32 _nField, const bool _bAscending ) : nField( _nField ), bAscending( _bAscending ) { }
76 typedef ::std::vector< FieldSort > SortDescriptor;
78 enum QueryFilterType
80 eFilterAlwaysFalse,
81 eFilterNone,
82 eFilterOther
85 struct QueryData
87 private:
88 EBookQuery* pQuery;
90 public:
91 ::rtl::OUString sTable;
92 QueryFilterType eFilterType;
93 ::vos::ORef< ::connectivity::OSQLColumns > xSelectColumns;
94 SortDescriptor aSortOrder;
96 QueryData()
97 :pQuery( NULL )
98 ,sTable()
99 ,eFilterType( eFilterOther )
100 ,xSelectColumns()
101 ,aSortOrder()
105 QueryData( const QueryData& _rhs )
106 :pQuery( NULL )
107 ,sTable()
108 ,eFilterType( eFilterType )
109 ,xSelectColumns()
110 ,aSortOrder()
112 *this = _rhs;
115 QueryData& operator=( const QueryData& _rhs )
117 if ( this == &_rhs )
118 return *this;
120 setQuery( _rhs.pQuery );
121 sTable = _rhs.sTable;
122 eFilterType = _rhs.eFilterType;
123 xSelectColumns = _rhs.xSelectColumns;
124 aSortOrder = _rhs.aSortOrder;
126 return *this;
129 ~QueryData()
131 setQuery( NULL );
134 EBookQuery* getQuery() const { return pQuery; }
136 void setQuery( EBookQuery* _pQuery )
138 if ( pQuery )
139 e_book_query_unref( pQuery );
140 pQuery = _pQuery;
141 if ( pQuery )
142 e_book_query_ref( pQuery );
146 //**************************************************************
147 //************ Class: OCommonStatement
148 // is a base class for the normal statement and for the prepared statement
149 //**************************************************************
150 class OCommonStatement;
151 typedef OSubComponent< OCommonStatement, OCommonStatement_IBase > OStatement_CBase;
153 class OCommonStatement :public comphelper::OBaseMutex
154 ,public OCommonStatement_IBase
155 ,public ::comphelper::OPropertyContainer
156 ,public ::comphelper::OPropertyArrayUsageHelper< OCommonStatement >
157 ,public OStatement_CBase
159 friend class OSubComponent< OCommonStatement, OCommonStatement_IBase >;
161 private:
162 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet> m_xResultSet; // The last ResultSet created
163 OEvoabResultSet *m_pResultSet;
164 OEvoabConnection *m_pConnection;
165 connectivity::OSQLParser m_aParser;
166 connectivity::OSQLParseTreeIterator m_aSQLIterator;
167 connectivity::OSQLParseNode *m_pParseTree;
169 // <properties>
170 ::rtl::OUString m_aCursorName;
171 sal_Int32 m_nMaxFieldSize;
172 sal_Int32 m_nMaxRows;
173 sal_Int32 m_nQueryTimeOut;
174 sal_Int32 m_nFetchSize;
175 sal_Int32 m_nResultSetType;
176 sal_Int32 m_nFetchDirection;
177 sal_Int32 m_nResultSetConcurrency;
178 sal_Bool m_bEscapeProcessing;
179 // </properties>
181 ::cppu::OBroadcastHelper& rBHelper;
183 protected:
185 void disposeResultSet();
187 // OPropertyArrayUsageHelper
188 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
189 // OPropertySetHelper
190 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
192 virtual ~OCommonStatement();
194 protected:
195 void reset () throw( ::com::sun::star::sdbc::SQLException);
196 void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException);
197 void parseSql( const ::rtl::OUString& sql, QueryData& _out_rQueryData );
198 EBookQuery *whereAnalysis( const OSQLParseNode* parseTree );
199 void orderByAnalysis( const OSQLParseNode* _pOrderByClause, SortDescriptor& _out_rSort );
200 rtl::OUString getTableName();
201 EBookQuery *createTrue();
202 EBookQuery *createTest( const ::rtl::OUString &aColumnName,
203 EBookQueryTest eTest,
204 const ::rtl::OUString &aMatch );
206 public:
208 // other methods
209 OEvoabConnection* getOwnConnection() const { return m_pConnection;}
211 using OCommonStatement_IBase::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
213 protected:
214 OCommonStatement( OEvoabConnection* _pConnection );
216 // OComponentHelper
217 virtual void SAL_CALL disposing(void);
218 // XInterface
219 virtual void SAL_CALL release() throw();
220 virtual void SAL_CALL acquire() throw();
221 // XInterface
222 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
223 //XTypeProvider
224 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException);
226 // XPropertySet
227 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
229 // XWarningsSupplier
230 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
231 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
233 // XCloseable
234 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
236 protected:
237 /** will return the EBookQuery representing the stamement's WHERE condition, or throw
239 Also, all statement dependent members (such as the parser/iterator) will be inited afterwards.
241 QueryData
242 impl_getEBookQuery_throw( const ::rtl::OUString& _rSql );
244 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >
245 impl_executeQuery_throw( const ::rtl::OUString& _rSql );
247 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >
248 impl_executeQuery_throw( const QueryData& _rData );
250 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
251 impl_getConnection() { return ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >( (::com::sun::star::sdbc::XConnection*)m_pConnection ); }
253 ::rtl::OUString
254 impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode& _rColumnRef );
257 typedef ::cppu::ImplHelper2 < ::com::sun::star::lang::XServiceInfo
258 , ::com::sun::star::sdbc::XStatement
259 > OStatement_IBase;
260 class OStatement :public OCommonStatement
261 ,public OStatement_IBase
263 protected:
264 virtual ~OStatement(){}
266 public:
267 OStatement( OEvoabConnection* _pConnection)
268 :OCommonStatement( _pConnection)
272 // XInterface
273 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
274 virtual void SAL_CALL acquire() throw();
275 virtual void SAL_CALL release() throw();
277 // XTypeProvider
278 DECLARE_XTYPEPROVIDER()
280 // XServiceInfo
281 DECLARE_SERVICE_INFO();
283 // XStatement
284 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) ;
285 virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
286 virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
287 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) ;
291 #endif // CONNECTIVITY_SSTATEMENT_HXX