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_FDATABASEMETADATARESULTSET_HXX_
29 #define _CONNECTIVITY_FDATABASEMETADATARESULTSET_HXX_
30 
31 #include <com/sun/star/sdbc/XResultSet.hpp>
32 #include <com/sun/star/sdbc/XRow.hpp>
33 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
34 #include <com/sun/star/sdbc/XCloseable.hpp>
35 #include <com/sun/star/sdbc/XColumnLocate.hpp>
36 #include <com/sun/star/util/XCancellable.hpp>
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
40 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
41 #include <com/sun/star/sdbc/XRowUpdate.hpp>
42 #include <cppuhelper/compbase9.hxx>
43 #include <comphelper/proparrhlp.hxx>
44 #include "connectivity/CommonTools.hxx"
45 #include <comphelper/propertycontainer.hxx>
46 #include "connectivity/FValue.hxx"
47 #include "connectivity/dbtoolsdllapi.hxx"
48 #include <comphelper/broadcasthelper.hxx>
49 #include <vos/refernce.hxx>
50 
51 namespace connectivity
52 {
53 	class ODatabaseMetaDataResultSetMetaData;
54     typedef ::cppu::WeakComponentImplHelper9<   ::com::sun::star::sdbc::XResultSet,
55 												::com::sun::star::sdbc::XRow,
56 												::com::sun::star::sdbc::XResultSetMetaDataSupplier,
57 												::com::sun::star::util::XCancellable,
58 												::com::sun::star::sdbc::XWarningsSupplier,
59 												::com::sun::star::sdbc::XCloseable,
60                                                 ::com::sun::star::lang::XInitialization,
61                                                 ::com::sun::star::lang::XServiceInfo,
62 												::com::sun::star::sdbc::XColumnLocate> ODatabaseMetaDataResultSet_BASE;
63 
64 	//	typedef ORefVector<ORowSetValue>	ORow;
65 	//	typedef ORefVector<ORow>			ORows;
66 
67 	class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataResultSet :
68                                         public comphelper::OBaseMutex,
69 										public	ODatabaseMetaDataResultSet_BASE,
70 										public	::comphelper::OPropertyContainer,
71 										public	::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet>
72 	{
73 
74 	public:
75 		DECLARE_STL_VECTOR(ORowSetValueDecoratorRef,ORow);
76 		DECLARE_STL_VECTOR(ORow, ORows);
77 
78         enum MetaDataResultSetType
79         {
80             /// describes a result set as expected by XDatabaseMetaData::getCatalogs
81             eCatalogs = 0,
82             /// describes a result set as expected by XDatabaseMetaData::getSchemas
83             eSchemas = 1,
84             /// describes a result set as expected by XDatabaseMetaData::getColumnPrivileges
85             eColumnPrivileges = 2,
86             /// describes a result set as expected by XDatabaseMetaData::getColumns
87             eColumns = 3,
88             /// describes a result set as expected by XDatabaseMetaData::getTables
89             eTables = 4,
90             /// describes a result set as expected by XDatabaseMetaData::getTableTypes
91             eTableTypes = 5,
92             /// describes a result set as expected by XDatabaseMetaData::getProcedureColumns
93             eProcedureColumns = 6,
94             /// describes a result set as expected by XDatabaseMetaData::getProcedures
95             eProcedures = 7,
96             /// describes a result set as expected by XDatabaseMetaData::getExportedKeys
97             eExportedKeys = 8,
98             /// describes a result set as expected by XDatabaseMetaData::getImportedKeys
99             eImportedKeys = 9,
100             /// describes a result set as expected by XDatabaseMetaData::getPrimaryKeys
101             ePrimaryKeys = 10,
102             /// describes a result set as expected by XDatabaseMetaData::getIndexInfo
103             eIndexInfo = 11,
104             /// describes a result set as expected by XDatabaseMetaData::getTablePrivileges
105             eTablePrivileges = 12,
106             /// describes a result set as expected by XDatabaseMetaData::getCrossReference
107             eCrossReference = 13,
108             /// describes a result set as expected by XDatabaseMetaData::getTypeInfo
109             eTypeInfo = 14,
110             /// describes a result set as expected by XDatabaseMetaData::getBestRowIdentifier
111             eBestRowIdentifier = 15,
112             /// describes a result set as expected by XDatabaseMetaData::getVersionColumns
113             eVersionColumns = 16
114         };
115 
116 	private:
117 		ORowSetValue					m_aEmptyValue;
118         ::com::sun::star::uno::WeakReferenceHelper    m_aStatement;
119         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData>        m_xMetaData;
120 		sal_Int32						m_nColPos;
121 
122 		sal_Int32						m_nFetchSize;
123 		sal_Int32						m_nResultSetType;
124 		sal_Int32						m_nFetchDirection;
125 		sal_Int32						m_nResultSetConcurrency;
126 
127 		void construct();
128 		void checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException);
129         void setType(MetaDataResultSetType _eType);
130 
131 	protected:
132 		ORows							m_aRows;
133 		ORows::iterator					m_aRowsIter;
134 		sal_Bool						m_bBOF;
135         sal_Bool                        m_bEOF;
136 
137 		virtual const ORowSetValue& getValue(sal_Int32 columnIndex);
138 
139 		// OPropertyArrayUsageHelper
140 		virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
141 		// OPropertySetHelper
142 		virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
143 
144 		virtual ~ODatabaseMetaDataResultSet();
145 	public:
146 
147 		virtual void	SAL_CALL acquire() throw();
148 		virtual void	SAL_CALL release() throw();
149 
150         /// default construction
151 		ODatabaseMetaDataResultSet();
152         /// construction of a pre-defined result set type
153         ODatabaseMetaDataResultSet( MetaDataResultSetType _eType );
154 
155 		void setRows(const ORows& _rRows);
156 
157         // XServiceInfo
158 
159 		static ::rtl::OUString getImplementationName_Static(  ) throw(::com::sun::star::uno::RuntimeException);
160         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw (::com::sun::star::uno::RuntimeException);
161 
162     protected:
163         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
164         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
165         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
166 		// ::cppu::OComponentHelper
167 		virtual void SAL_CALL disposing(void);
168 		// XInterface
169         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
170 		//XTypeProvider
171         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
172 		// XPropertySet
173         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
174 		// XResultSet
175         virtual sal_Bool SAL_CALL next(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176         virtual sal_Bool SAL_CALL isBeforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
177         virtual sal_Bool SAL_CALL isAfterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
178         virtual sal_Bool SAL_CALL isFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
179         virtual sal_Bool SAL_CALL isLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
180         virtual void SAL_CALL beforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
181         virtual void SAL_CALL afterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
182         virtual sal_Bool SAL_CALL first(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
183         virtual sal_Bool SAL_CALL last(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
184         virtual sal_Int32 SAL_CALL getRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
185         virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
186         virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
187         virtual sal_Bool SAL_CALL previous(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
188         virtual void SAL_CALL refreshRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
189         virtual sal_Bool SAL_CALL rowUpdated(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
190         virtual sal_Bool SAL_CALL rowInserted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
191         virtual sal_Bool SAL_CALL rowDeleted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
192         virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getStatement(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
193 		// XRow
194         virtual sal_Bool SAL_CALL wasNull(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
195         virtual ::rtl::OUString SAL_CALL getString( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
196         virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
197         virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
198         virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
199         virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
200         virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
201         virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
202         virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
203         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
204         virtual ::com::sun::star::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
205         virtual ::com::sun::star::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
206         virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
207         virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
208         virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
209         virtual ::com::sun::star::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
210         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
211         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
212         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
213         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
214 		// XResultSetMetaDataSupplier
215         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL getMetaData(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
216 		// XCancellable
217         virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
218 		// XCloseable
219         virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
220 		// XWarningsSupplier
221         virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
222         virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
223 		// XColumnLocate
224         virtual sal_Int32 SAL_CALL findColumn( const ::rtl::OUString& columnName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
225 
226         // XInitialization
227         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
228 
229 		void setCatalogsMap();
230 		void setSchemasMap();
231 		void setColumnPrivilegesMap();
232 		void setColumnsMap();
233 		void setTablesMap();
234 		void setTableTypes();
235 		void setProcedureColumnsMap();
236 		void setProceduresMap();
237 		void setExportedKeysMap();
238 		void setImportedKeysMap();
239 		void setPrimaryKeysMap();
240 		void setIndexInfoMap();
241 		void setTablePrivilegesMap();
242 		void setCrossReferenceMap();
243 		void setTypeInfoMap();
244 		void setBestRowIdentifierMap();
245 		void setVersionColumnsMap();
246     public:
247 		// some methods to get already defined ORowSetValues
248 		// this increase the reuse of ORowSetValues
249 		/// return an empty ORowSetValueDecorator
250 		static ORowSetValueDecoratorRef getEmptyValue();
251 		/// return an ORowSetValueDecorator with 0 as value
252 		static ORowSetValueDecoratorRef get0Value();
253 		/// return an ORowSetValueDecorator with 1 as value
254 		static ORowSetValueDecoratorRef get1Value();
255 		/// return an ORowSetValueDecorator with ColumnSearch::BASIC as value
256 		static ORowSetValueDecoratorRef getBasicValue();
257 		/// return an ORowSetValueDecorator with string SELECT as value
258 		static ORowSetValueDecoratorRef getSelectValue();
259 		/// return an ORowSetValueDecorator with string INSERT as value
260 		static ORowSetValueDecoratorRef getInsertValue();
261 		/// return an ORowSetValueDecorator with string DELETE as value
262 		static ORowSetValueDecoratorRef getDeleteValue();
263 		/// return an ORowSetValueDecorator with string UPDATE as value
264 		static ORowSetValueDecoratorRef getUpdateValue();
265 		/// return an ORowSetValueDecorator with string CREATE as value
266 		static ORowSetValueDecoratorRef getCreateValue();
267 		/// return an ORowSetValueDecorator with string READ as value
268 		static ORowSetValueDecoratorRef getReadValue();
269 		/// return an ORowSetValueDecorator with string ALTER as value
270 		static ORowSetValueDecoratorRef getAlterValue();
271 		/// return an ORowSetValueDecorator with string DROP as value
272 		static ORowSetValueDecoratorRef getDropValue();
273 		/// return an ORowSetValueDecorator with string ' as value
274 		static ORowSetValueDecoratorRef getQuoteValue();
275 
276 	};
277 }
278 #endif // _CONNECTIVITY_FDATABASEMETADATARESULTSET_HXX_
279 
280