1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_MACAB_STATEMENT_HXX_
29*cdf0e10cSrcweir #define _CONNECTIVITY_MACAB_STATEMENT_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "MacabConnection.hxx"
32*cdf0e10cSrcweir #include "MacabHeader.hxx"
33*cdf0e10cSrcweir #include <list>
34*cdf0e10cSrcweir #include "connectivity/sqliterator.hxx"
35*cdf0e10cSrcweir #ifndef _CONNECTIVITY_PARSE_SQLPARSE_HXX_
36*cdf0e10cSrcweir #include "connectivity/sqlparse.hxx"
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #include <com/sun/star/sdbc/XStatement.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/util/XCancellable.hpp>
40*cdf0e10cSrcweir #include <cppuhelper/compbase4.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
42*cdf0e10cSrcweir #include <comphelper/proparrhlp.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace connectivity
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 	namespace macab
47*cdf0e10cSrcweir 	{
48*cdf0e10cSrcweir 		typedef ::cppu::WeakComponentImplHelper4<	::com::sun::star::sdbc::XStatement,
49*cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XWarningsSupplier,
50*cdf0e10cSrcweir                                                     ::com::sun::star::util::XCancellable,
51*cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XCloseable> MacabCommonStatement_BASE;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 		//**************************************************************
54*cdf0e10cSrcweir 		// Class MacabCommonStatement
55*cdf0e10cSrcweir 		// is a base class for the normal statement and for the prepared statement
56*cdf0e10cSrcweir 		//**************************************************************
57*cdf0e10cSrcweir 		class MacabCommonStatement :	public comphelper::OBaseMutex,
58*cdf0e10cSrcweir 						public	MacabCommonStatement_BASE,
59*cdf0e10cSrcweir 						public	::cppu::OPropertySetHelper,
60*cdf0e10cSrcweir 						public	comphelper::OPropertyArrayUsageHelper<MacabCommonStatement>
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 		{
63*cdf0e10cSrcweir 			::com::sun::star::sdbc::SQLWarning	m_aLastWarning;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 		protected:
66*cdf0e10cSrcweir 			::std::list< ::rtl::OUString>		m_aBatchList;
67*cdf0e10cSrcweir 			connectivity::OSQLParser			m_aParser;
68*cdf0e10cSrcweir 			connectivity::OSQLParseTreeIterator	m_aSQLIterator;
69*cdf0e10cSrcweir 			connectivity::OSQLParseNode*		m_pParseTree;
70*cdf0e10cSrcweir 			MacabConnection*						m_pConnection;	// The owning Connection object
71*cdf0e10cSrcweir 			MacabHeader*							m_pHeader;	// The header of the address book on which to run queries (provided by m_pConnection)
72*cdf0e10cSrcweir 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 		protected:
76*cdf0e10cSrcweir 			class MacabCondition *analyseWhereClause(
77*cdf0e10cSrcweir 				const OSQLParseNode *pParseNode) const throw(::com::sun::star::sdbc::SQLException);
78*cdf0e10cSrcweir 			class MacabOrder *analyseOrderByClause(
79*cdf0e10cSrcweir 				const OSQLParseNode *pParseNode) const throw(::com::sun::star::sdbc::SQLException);
80*cdf0e10cSrcweir 			::rtl::OUString getTableName( ) const;
81*cdf0e10cSrcweir 			void setMacabFields(class MacabResultSet *pResult) const throw(::com::sun::star::sdbc::SQLException);
82*cdf0e10cSrcweir 			void selectRecords(MacabResultSet *pResult) const throw(::com::sun::star::sdbc::SQLException);
83*cdf0e10cSrcweir 			void sortRecords(MacabResultSet *pResult) const throw(::com::sun::star::sdbc::SQLException);
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 			// OPropertyArrayUsageHelper
86*cdf0e10cSrcweir 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 			// OPropertySetHelper
89*cdf0e10cSrcweir 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
90*cdf0e10cSrcweir 			virtual sal_Bool SAL_CALL convertFastPropertyValue(
91*cdf0e10cSrcweir 					::com::sun::star::uno::Any & rConvertedValue,
92*cdf0e10cSrcweir 					::com::sun::star::uno::Any & rOldValue,
93*cdf0e10cSrcweir 					sal_Int32 nHandle,
94*cdf0e10cSrcweir 					const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::lang::IllegalArgumentException);
95*cdf0e10cSrcweir 			virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
96*cdf0e10cSrcweir 					sal_Int32 nHandle,
97*cdf0e10cSrcweir 					const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception);
98*cdf0e10cSrcweir 			virtual void SAL_CALL getFastPropertyValue(
99*cdf0e10cSrcweir 					::com::sun::star::uno::Any& rValue,
100*cdf0e10cSrcweir 					sal_Int32 nHandle) const;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			virtual void resetParameters() const throw(::com::sun::star::sdbc::SQLException);
103*cdf0e10cSrcweir 			virtual void getNextParameter(::rtl::OUString &rParameter) const throw(::com::sun::star::sdbc::SQLException);
104*cdf0e10cSrcweir 			virtual ~MacabCommonStatement();
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 		public:
107*cdf0e10cSrcweir 			::cppu::OBroadcastHelper& rBHelper;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 			MacabCommonStatement(MacabConnection *_pConnection);
110*cdf0e10cSrcweir 			using MacabCommonStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 			// OComponentHelper
113*cdf0e10cSrcweir 			virtual void SAL_CALL disposing();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 			// XInterface
116*cdf0e10cSrcweir 			virtual void SAL_CALL release() throw();
117*cdf0e10cSrcweir 			virtual void SAL_CALL acquire() throw();
118*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
119*cdf0e10cSrcweir 					const ::com::sun::star::uno::Type & rType
120*cdf0e10cSrcweir 					) throw(::com::sun::star::uno::RuntimeException);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 			// XTypeProvider
123*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(
124*cdf0e10cSrcweir 					) throw(::com::sun::star::uno::RuntimeException);
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 			// XPropertySet
127*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(
128*cdf0e10cSrcweir 					) throw(::com::sun::star::uno::RuntimeException);
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 			// XStatement
131*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery(
132*cdf0e10cSrcweir 					const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133*cdf0e10cSrcweir 			virtual sal_Int32 SAL_CALL executeUpdate(
134*cdf0e10cSrcweir 					 const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135*cdf0e10cSrcweir 			virtual sal_Bool SAL_CALL execute(
136*cdf0e10cSrcweir 					const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(
138*cdf0e10cSrcweir 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 			// XWarningsSupplier
141*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(
142*cdf0e10cSrcweir 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
143*cdf0e10cSrcweir 			virtual void SAL_CALL clearWarnings(
144*cdf0e10cSrcweir 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 			// XCancellable
147*cdf0e10cSrcweir 			virtual void SAL_CALL cancel(
148*cdf0e10cSrcweir 					) throw(::com::sun::star::uno::RuntimeException);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 			// XCloseable
151*cdf0e10cSrcweir 			virtual void SAL_CALL close(
152*cdf0e10cSrcweir 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 			// other methods
155*cdf0e10cSrcweir 			inline MacabConnection* getOwnConnection() const { return m_pConnection; }
156*cdf0e10cSrcweir 		};
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 		//**************************************************************
159*cdf0e10cSrcweir 		// Class MacabStatement
160*cdf0e10cSrcweir 		//**************************************************************
161*cdf0e10cSrcweir 		typedef ::cppu::ImplInheritanceHelper1<
162*cdf0e10cSrcweir 				MacabCommonStatement, ::com::sun::star::lang::XServiceInfo > MacabStatement_BASE;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 		class MacabStatement : public MacabStatement_BASE
165*cdf0e10cSrcweir 		{
166*cdf0e10cSrcweir 		protected:
167*cdf0e10cSrcweir 			virtual ~MacabStatement() { }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 		public:
170*cdf0e10cSrcweir 			MacabStatement(MacabConnection* _pConnection);
171*cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
172*cdf0e10cSrcweir 		};
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir #endif // _CONNECTIVITY_MACAB_STATEMENT_HXX_
177