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 _UCBHELPER_RESULTSETMETADATA_HXX
25 #define _UCBHELPER_RESULTSETMETADATA_HXX
26 
27 #include <vector>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/lang/XTypeProvider.hpp>
31 #include <com/sun/star/sdbc/ColumnValue.hpp>
32 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
33 #include <cppuhelper/weak.hxx>
34 #include <ucbhelper/macros.hxx>
35 #include "ucbhelper/ucbhelperdllapi.h"
36 
37 namespace com { namespace sun { namespace star {
38 	namespace lang	{ class XMultiServiceFactory; }
39 	namespace beans { struct Property; }
40 } } }
41 
42 namespace ucbhelper_impl {
43     struct ResultSetMetaData_Impl;
44 }
45 
46 namespace ucbhelper
47 {
48 
49 //=========================================================================
50 
51 /**
52  * This is a structure that holds additional meta data for one column
53  * of a resultset. The default values set in the constructor should be a
54  * good guess for many UCB use cases.
55  */
56 struct ResultSetColumnData
57 {
58 	/** @see ResultSetMetaData::isAutoIncrement */
59 	sal_Bool        isAutoIncrement;
60 
61 	/** @see ResultSetMetaData::isCaseSensitive */
62 	sal_Bool        isCaseSensitive;
63 
64 	/** @see ResultSetMetaData::isSearchable */
65 	sal_Bool        isSearchable;
66 
67 	/** @see ResultSetMetaData::isCurrency */
68 	sal_Bool        isCurrency;
69 
70 	/** @see ResultSetMetaData::isNullable */
71 	sal_Int32       isNullable;
72 
73 	/** @see ResultSetMetaData::isSigned */
74 	sal_Bool        isSigned;
75 
76 	/** @see ResultSetMetaData::getColumnDisplaySize */
77 	sal_Int32       columnDisplaySize;
78 
79 	/** @see ResultSetMetaData::getColumnLabel */
80 	::rtl::OUString columnLabel;
81 
82 	/** @see ResultSetMetaData::getSchemaName */
83 	::rtl::OUString schemaName;
84 
85 	/** @see ResultSetMetaData::getPrecision */
86 	sal_Int32 		precision;
87 
88 	/** @see ResultSetMetaData::getScale */
89 	sal_Int32 		scale;
90 
91 	/** @see ResultSetMetaData::getTableName */
92 	::rtl::OUString tableName;
93 
94 	/** @see ResultSetMetaData::getCatalogName */
95 	::rtl::OUString catalogName;
96 
97 	/** @see ResultSetMetaData::getColumnTypeName */
98 	::rtl::OUString columnTypeName;
99 
100 	/** @see ResultSetMetaData::isReadOnly */
101 	sal_Bool 		isReadOnly;
102 
103 	/** @see ResultSetMetaData::isWritable */
104 	sal_Bool 		isWritable;
105 
106 	/** @see ResultSetMetaData::isDefinitelyWritable */
107 	sal_Bool 		isDefinitelyWritable;
108 
109 	/** @see ResultSetMetaData::getColumnServiceName */
110 	::rtl::OUString columnServiceName;
111 
112 	inline ResultSetColumnData();
113 };
114 
115 // Note: Never change the initial values! Implementations using this struct
116 //       may havily depend on the behaviour of the default constructor.
117 
ResultSetColumnData()118 ResultSetColumnData::ResultSetColumnData()
119 : isAutoIncrement( sal_False ),
120   isCaseSensitive( sal_True ),
121   isSearchable( sal_False ),
122   isCurrency( sal_False ),
123   isNullable( ::com::sun::star::sdbc::ColumnValue::NULLABLE ),
124   isSigned( sal_False ),
125   columnDisplaySize( 16 ),
126   precision( -1 ),
127   scale( 0 ),
128   isReadOnly( sal_True ),
129   isWritable( sal_False ),
130   isDefinitelyWritable( sal_False )
131 {
132 }
133 
134 //=========================================================================
135 
136 /**
137  * This is an implementation of the interface XResultSetMetaData. It can be
138  * used to implement the interface
139  * com::sun::star::sdbc::XResultSetMetaDataSupplier, which is required for
140  * implementations of service com.sun.star.ucb.ContentResultSet.
141  */
142 class UCBHELPER_DLLPUBLIC ResultSetMetaData :
143 				public ::cppu::OWeakObject,
144 				public ::com::sun::star::lang::XTypeProvider,
145 				public ::com::sun::star::sdbc::XResultSetMetaData
146 {
147 private:
148 	ucbhelper_impl::ResultSetMetaData_Impl* m_pImpl;
149 
150 protected:
151 	::com::sun::star::uno::Reference<
152 		::com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
153 	::com::sun::star::uno::Sequence<
154 		::com::sun::star::beans::Property > 		   m_aProps;
155 	sal_Bool m_bReadOnly;
156 
157 public:
158 
159 	/**
160 	  *	Constructor.
161 	  *
162 	  *	@param rxSMgr is a Servive Manager.
163 	  *	@param rProps is a sequence of properties (partially) describing the
164 	  *        columns of a resultset.
165 	  * @param bReadOnly is used to specify whether the whole(!) resultset
166 	  *        is read-only.
167 	  */
168 	ResultSetMetaData(
169 			const ::com::sun::star::uno::Reference<
170 				::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
171 			const ::com::sun::star::uno::Sequence<
172 				::com::sun::star::beans::Property >& rProps,
173 			sal_Bool bReadOnly = sal_True );
174 
175 	/**
176 	  *	Constructor.
177 	  *
178 	  *	@param rxSMgr is a Servive Manager.
179 	  *	@param rProps is a sequence of properties (partially) describing the
180 	  *        columns of a resultset.
181 	  *	@param rColumnData contains additional meta data for the columns of
182 	  *	       a resultset, which override the default values returned by the
183 	  *		   appropriate methods of this class. The length of rColumnData
184 	  *		   must be the same as length of rProps.
185 	  *		   rColumnData[ 0 ] corresponds to data in rProps[ 0 ],
186 	  *		   rColumnData[ 1 ] corresponds to data in rProps[ 1 ], ...
187 	  */
188 	ResultSetMetaData(
189 			const ::com::sun::star::uno::Reference<
190 				::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
191 			const ::com::sun::star::uno::Sequence<
192 				::com::sun::star::beans::Property >& rProps,
193 			const std::vector< ResultSetColumnData >& rColumnData );
194 
195 	/**
196 	  *	Destructor.
197 	  */
198 	virtual ~ResultSetMetaData();
199 
200 	// XInterface
201 	XINTERFACE_DECL()
202 
203 	// XTypeProvider
204 	XTYPEPROVIDER_DECL()
205 
206 	// XResultSetMetaData
207 
208 	/**
209 	  * Returns the number of columns of the resultset.
210 	  *
211 	  *	@return the length of the property sequence.
212 	  */
213     virtual sal_Int32 SAL_CALL
214 	getColumnCount()
215 		throw( ::com::sun::star::sdbc::SQLException,
216 			   ::com::sun::star::uno::RuntimeException );
217 	/**
218 	  *	Checks whether column is automatically numbered, which makes it
219 	  *	read-only.
220 	  *
221 	  * @param  column is the number of the column for that a value shall
222 	  *         be returned. The first column is 1, the second is 2, ...
223 	  *	@return true, if column is automatically numbered.
224 	  */
225     virtual sal_Bool SAL_CALL
226 	isAutoIncrement( sal_Int32 column )
227 		throw( ::com::sun::star::sdbc::SQLException,
228 			   ::com::sun::star::uno::RuntimeException );
229 	/**
230 	  *	Checks whether column is case sensitive.
231 	  *
232 	  * @param  column is the number of the column for that a value shall
233 	  *         be returned. The first column is 1, the second is 2, ...
234 	  *	@return true, if column is case sensitive.
235 	  */
236     virtual sal_Bool SAL_CALL
237 	isCaseSensitive( sal_Int32 column )
238 		throw( ::com::sun::star::sdbc::SQLException,
239 			   ::com::sun::star::uno::RuntimeException );
240 	/**
241 	  * Checks whether the value stored in column can be used in a
242 	  *	WHERE clause.
243 	  *
244 	  * @param  column is the number of the column for that a value shall
245 	  *         be returned. The first column is 1, the second is 2, ...
246 	  *	@return true, if the column is searchable.
247 	  */
248     virtual sal_Bool SAL_CALL
249 	isSearchable( sal_Int32 column )
250 		throw( ::com::sun::star::sdbc::SQLException,
251 			   ::com::sun::star::uno::RuntimeException );
252 	/**
253 	  *	Checks whether column is a cash value.
254 	  *
255 	  * @param  column is the number of the column for that a value shall
256 	  *         be returned. The first column is 1, the second is 2, ...
257 	  *	@return true, if the column is a cash value.
258 	  */
259     virtual sal_Bool SAL_CALL
260 	isCurrency( sal_Int32 column )
261 		throw( ::com::sun::star::sdbc::SQLException,
262 			   ::com::sun::star::uno::RuntimeException );
263 	/**
264 	  *	Checks whether a NULL can be stored in column.
265 	  *
266 	  *	@see com::sun::star::sdbc::ColumnValue
267 	  *
268 	  * @param  column is the number of the column for that a value shall
269 	  *         be returned. The first column is 1, the second is 2, ...
270 	  *	@return ::com::sun::star::sdbc::ColumnValue::NULLABLE, if a NULL
271 	  *         can be stored in the column.
272 	  */
273     virtual sal_Int32 SAL_CALL
274 	isNullable( sal_Int32 column )
275 		throw( ::com::sun::star::sdbc::SQLException,
276 			   ::com::sun::star::uno::RuntimeException );
277 	/**
278 	  *	Checks whether the value stored in column is a signed number.
279 	  *
280 	  * @param  column is the number of the column for that a value shall
281 	  *         be returned. The first column is 1, the second is 2, ...
282 	  *	@return true, if the value stored in column is a signed number.
283 	  */
284     virtual sal_Bool SAL_CALL
285 	isSigned( sal_Int32 column )
286 		throw( ::com::sun::star::sdbc::SQLException,
287 			   ::com::sun::star::uno::RuntimeException );
288 	/**
289 	  *	Gets the normal maximum width in characters for column.
290 	  *
291 	  * @param  column is the number of the column for that a value shall
292 	  *         be returned. The first column is 1, the second is 2, ...
293 	  *	@return the normal maximum width in characters for column.
294 	  */
295     virtual sal_Int32 SAL_CALL
296 	getColumnDisplaySize( sal_Int32 column )
297 		throw( ::com::sun::star::sdbc::SQLException,
298 			   ::com::sun::star::uno::RuntimeException );
299 	/**
300 	  *	Gets the suggested column title for column, to be used in print-
301 	  *	outs and displays.
302 	  *
303 	  * @param  column is the number of the column for that a value shall
304 	  *         be returned. The first column is 1, the second is 2, ...
305 	  *	@return the column label.
306 	  */
307     virtual ::rtl::OUString SAL_CALL
308 	getColumnLabel( sal_Int32 column )
309 		throw( ::com::sun::star::sdbc::SQLException,
310 			   ::com::sun::star::uno::RuntimeException );
311 	/**
312 	  *	Gets the name of column.
313 	  *
314 	  * @param  column is the number of the column for that a value shall
315 	  *         be returned. The first column is 1, the second is 2, ...
316 	  *	@return the name of the property that corresponds to column.
317 	  */
318     virtual ::rtl::OUString SAL_CALL
319 	getColumnName( sal_Int32 column )
320 		throw( ::com::sun::star::sdbc::SQLException,
321 			   ::com::sun::star::uno::RuntimeException );
322 	/**
323 	  *	Gets the schema name for the table from which column of this
324 	  *	result set was derived.
325 	  *	Because this feature is not widely supported, the return value
326 	  *	for many DBMSs will be an empty string.
327 	  *
328 	  * @param  column is the number of the column for that a value shall
329 	  *         be returned. The first column is 1, the second is 2, ...
330 	  *	@return the schema name of column or an empty string.
331 	  */
332     virtual ::rtl::OUString SAL_CALL
333 	getSchemaName( sal_Int32 column )
334 		throw( ::com::sun::star::sdbc::SQLException,
335 			   ::com::sun::star::uno::RuntimeException );
336 	/**
337 	  *	For number types, getprecision gets the number of decimal digits
338 	  *	in column.
339 	  *	For character types, it gets the maximum length in characters for
340 	  *	column.
341 	  *	For binary types, it gets the maximum length in bytes for column.
342 	  *
343 	  * @param  column is the number of the column for that a value shall
344 	  *         be returned. The first column is 1, the second is 2, ...
345 	  *	@return the precision for the column.
346 	  */
347     virtual sal_Int32 SAL_CALL
348 	getPrecision( sal_Int32 column )
349 		throw( ::com::sun::star::sdbc::SQLException,
350 			   ::com::sun::star::uno::RuntimeException );
351 	/**
352 	  *	Gets the number of digits to the right of the decimal point for
353 	  *	values in column.
354 	  *
355 	  * @param  column is the number of the column for that a value shall
356 	  *         be returned. The first column is 1, the second is 2, ...
357 	  *	@return the scale of the column.
358 	  */
359     virtual sal_Int32 SAL_CALL
360 	getScale( sal_Int32 column )
361 		throw( ::com::sun::star::sdbc::SQLException,
362 			   ::com::sun::star::uno::RuntimeException );
363 	/**
364 	  *	Gets the name of the table from which column of this result set
365 	  *	was derived or "" if there is none (for example, for a join).
366 	  *	Because this feature is not widely supported, the return value
367 	  *	for many DBMSs will be an empty string.
368 	  *
369 	  * @param  column is the number of the column for that a value shall
370 	  *         be returned. The first column is 1, the second is 2, ...
371 	  *	@return the table name for column or an empty string.
372 	  */
373     virtual ::rtl::OUString SAL_CALL
374 	getTableName( sal_Int32 column )
375 		throw( ::com::sun::star::sdbc::SQLException,
376 			   ::com::sun::star::uno::RuntimeException );
377     virtual ::rtl::OUString SAL_CALL
378 	/**
379 	  *	Gets the catalog name for the table from which column of this
380 	  *	result set was derived.
381 	  *	Because this feature is not widely supported, the return value
382 	  *	for many DBMSs will be an empty string.
383 	  *
384 	  * @param  column is the number of the column for that a value shall
385 	  *         be returned. The first column is 1, the second is 2, ...
386 	  *	@return the catalog name for column or an empty string.
387 	  */
388 	getCatalogName( sal_Int32 column )
389 		throw( ::com::sun::star::sdbc::SQLException,
390 			   ::com::sun::star::uno::RuntimeException );
391 	/**
392 	  *	Gets the JDBC type for the value stored in column. ... The STRUCT
393 	  *	and DISTINCT type codes are always returned for structured and
394 	  *	distinct types, regardless of whether the value will be mapped
395 	  *	according to the standard mapping or be a custom mapping.
396 	  *
397 	  * @param  column is the number of the column for that a value shall
398 	  *         be returned. The first column is 1, the second is 2, ...
399 	  *	@return the type of the property that corresponds to column - mapped
400 	  *         from UNO-Type to SQL-Type.
401 	  */
402     virtual sal_Int32 SAL_CALL
403 	getColumnType( sal_Int32 column )
404 		throw( ::com::sun::star::sdbc::SQLException,
405 			   ::com::sun::star::uno::RuntimeException );
406 	/**
407 	  *	Gets the type name used by this particular data source for the
408 	  *	values stored in column. If the type code for the type of value
409 	  *	stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
410 	  *	returns a fully-qualified SQL type name.
411 	  *
412 	  * @param  column is the number of the column for that a value shall
413 	  *         be returned. The first column is 1, the second is 2, ...
414 	  *	@return the column type name.
415 	  */
416     virtual ::rtl::OUString SAL_CALL
417 	getColumnTypeName( sal_Int32 column )
418 		throw( ::com::sun::star::sdbc::SQLException,
419 			   ::com::sun::star::uno::RuntimeException );
420 	/**
421 	  * Indicates whether a column is definitely not writable.
422 	  *
423 	  * @param  column is the number of the column for that a value shall
424 	  *         be returned. The first column is 1, the second is 2, ...
425 	  *	@return true, if the column is definetely not writable.
426 	  */
427     virtual sal_Bool SAL_CALL
428 	isReadOnly( sal_Int32 column )
429 		throw( ::com::sun::star::sdbc::SQLException,
430 			   ::com::sun::star::uno::RuntimeException );
431 	/**
432 	  * Indicates whether it is possible for a write on the column to succeed.
433 	  *
434 	  * @param  column is the number of the column for that a value shall
435 	  *         be returned. The first column is 1, the second is 2, ...
436 	  *	@return true, if it is possible for a write to succeed.
437 	  */
438     virtual sal_Bool SAL_CALL
439 	isWritable( sal_Int32 column )
440 		throw( ::com::sun::star::sdbc::SQLException,
441 			   ::com::sun::star::uno::RuntimeException );
442 	/**
443 	  * Indicates whether a write on the column will definitely succeed.
444 	  *
445 	  * @param  column is the number of the column for that a value shall
446 	  *         be returned. The first column is 1, the second is 2, ...
447 	  *	@return true, if a write on the column will definetely succeed.
448 	  */
449     virtual sal_Bool SAL_CALL
450 	isDefinitelyWritable( sal_Int32 column )
451 		throw( ::com::sun::star::sdbc::SQLException,
452 			   ::com::sun::star::uno::RuntimeException );
453 	/**
454 	  * Returns the fully-qualified name of the service whose instances
455 	  *	are manufactured if the method
456 	  * com::sun::star::sdbc::ResultSet::getObject is called to retrieve a
457 	  * value from the column.
458 	  *
459 	  * @param  column is the number of the column for that a value shall
460 	  *         be returned. The first column is 1, the second is 2, ...
461 	  *	@return the service name for column or an empty string, if no service
462 	  *         is applicable.
463 	  */
464     virtual ::rtl::OUString SAL_CALL
465 	getColumnServiceName( sal_Int32 column )
466 		throw( ::com::sun::star::sdbc::SQLException,
467 			   ::com::sun::star::uno::RuntimeException );
468 };
469 
470 } // namespace ucbhelper
471 
472 #endif /* !_UCBHELPER_RESULTSETMETADATA_HXX */
473