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 
28 #ifndef _CONNECTIVITY_MACAB_STATEMENT_HXX_
29 #define _CONNECTIVITY_MACAB_STATEMENT_HXX_
30 
31 #include "MacabConnection.hxx"
32 #include "MacabHeader.hxx"
33 #include <list>
34 #include "connectivity/sqliterator.hxx"
35 #ifndef _CONNECTIVITY_PARSE_SQLPARSE_HXX_
36 #include "connectivity/sqlparse.hxx"
37 #endif
38 #include <com/sun/star/sdbc/XStatement.hpp>
39 #include <com/sun/star/util/XCancellable.hpp>
40 #include <cppuhelper/compbase4.hxx>
41 #include <cppuhelper/implbase1.hxx>
42 #include <comphelper/proparrhlp.hxx>
43 
44 namespace connectivity
45 {
46 	namespace macab
47 	{
48 		typedef ::cppu::WeakComponentImplHelper4<	::com::sun::star::sdbc::XStatement,
49                                                     ::com::sun::star::sdbc::XWarningsSupplier,
50                                                     ::com::sun::star::util::XCancellable,
51                                                     ::com::sun::star::sdbc::XCloseable> MacabCommonStatement_BASE;
52 
53 		//**************************************************************
54 		// Class MacabCommonStatement
55 		// is a base class for the normal statement and for the prepared statement
56 		//**************************************************************
57 		class MacabCommonStatement :	public comphelper::OBaseMutex,
58 						public	MacabCommonStatement_BASE,
59 						public	::cppu::OPropertySetHelper,
60 						public	comphelper::OPropertyArrayUsageHelper<MacabCommonStatement>
61 
62 		{
63 			::com::sun::star::sdbc::SQLWarning	m_aLastWarning;
64 
65 		protected:
66 			::std::list< ::rtl::OUString>		m_aBatchList;
67 			connectivity::OSQLParser			m_aParser;
68 			connectivity::OSQLParseTreeIterator	m_aSQLIterator;
69 			connectivity::OSQLParseNode*		m_pParseTree;
70 			MacabConnection*						m_pConnection;	// The owning Connection object
71 			MacabHeader*							m_pHeader;	// The header of the address book on which to run queries (provided by m_pConnection)
72 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
73 
74 
75 		protected:
76 			class MacabCondition *analyseWhereClause(
77 				const OSQLParseNode *pParseNode) const throw(::com::sun::star::sdbc::SQLException);
78 			class MacabOrder *analyseOrderByClause(
79 				const OSQLParseNode *pParseNode) const throw(::com::sun::star::sdbc::SQLException);
80 			::rtl::OUString getTableName( ) const;
81 			void setMacabFields(class MacabResultSet *pResult) const throw(::com::sun::star::sdbc::SQLException);
82 			void selectRecords(MacabResultSet *pResult) const throw(::com::sun::star::sdbc::SQLException);
83 			void sortRecords(MacabResultSet *pResult) const throw(::com::sun::star::sdbc::SQLException);
84 
85 			// OPropertyArrayUsageHelper
86 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
87 
88 			// OPropertySetHelper
89 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
90 			virtual sal_Bool SAL_CALL convertFastPropertyValue(
91 					::com::sun::star::uno::Any & rConvertedValue,
92 					::com::sun::star::uno::Any & rOldValue,
93 					sal_Int32 nHandle,
94 					const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::lang::IllegalArgumentException);
95 			virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
96 					sal_Int32 nHandle,
97 					const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception);
98 			virtual void SAL_CALL getFastPropertyValue(
99 					::com::sun::star::uno::Any& rValue,
100 					sal_Int32 nHandle) const;
101 
102 			virtual void resetParameters() const throw(::com::sun::star::sdbc::SQLException);
103 			virtual void getNextParameter(::rtl::OUString &rParameter) const throw(::com::sun::star::sdbc::SQLException);
104 			virtual ~MacabCommonStatement();
105 
106 		public:
107 			::cppu::OBroadcastHelper& rBHelper;
108 
109 			MacabCommonStatement(MacabConnection *_pConnection);
110 			using MacabCommonStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
111 
112 			// OComponentHelper
113 			virtual void SAL_CALL disposing();
114 
115 			// XInterface
116 			virtual void SAL_CALL release() throw();
117 			virtual void SAL_CALL acquire() throw();
118 			virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
119 					const ::com::sun::star::uno::Type & rType
120 					) throw(::com::sun::star::uno::RuntimeException);
121 
122 			// XTypeProvider
123 			virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(
124 					) throw(::com::sun::star::uno::RuntimeException);
125 
126 			// XPropertySet
127 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(
128 					) throw(::com::sun::star::uno::RuntimeException);
129 
130 			// XStatement
131 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery(
132 					const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133 			virtual sal_Int32 SAL_CALL executeUpdate(
134 					 const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135 			virtual sal_Bool SAL_CALL execute(
136 					const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(
138 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
139 
140 			// XWarningsSupplier
141 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(
142 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
143 			virtual void SAL_CALL clearWarnings(
144 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
145 
146 			// XCancellable
147 			virtual void SAL_CALL cancel(
148 					) throw(::com::sun::star::uno::RuntimeException);
149 
150 			// XCloseable
151 			virtual void SAL_CALL close(
152 					) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
153 
154 			// other methods
155 			inline MacabConnection* getOwnConnection() const { return m_pConnection; }
156 		};
157 
158 		//**************************************************************
159 		// Class MacabStatement
160 		//**************************************************************
161 		typedef ::cppu::ImplInheritanceHelper1<
162 				MacabCommonStatement, ::com::sun::star::lang::XServiceInfo > MacabStatement_BASE;
163 
164 		class MacabStatement : public MacabStatement_BASE
165 		{
166 		protected:
167 			virtual ~MacabStatement() { }
168 
169 		public:
170 			MacabStatement(MacabConnection* _pConnection);
171 			DECLARE_SERVICE_INFO();
172 		};
173 	}
174 }
175 
176 #endif // _CONNECTIVITY_MACAB_STATEMENT_HXX_
177