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