LibreOffice Module ucbhelper (master) 1
resultsetmetadata.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <osl/diagnose.h>
21#include <com/sun/star/beans/Property.hpp>
22#include <com/sun/star/beans/XPropertySetInfo.hpp>
23#include <com/sun/star/io/XInputStream.hpp>
24#include <com/sun/star/sdbc/ColumnValue.hpp>
25#include <com/sun/star/sdbc/DataType.hpp>
26#include <com/sun/star/sdbc/XArray.hpp>
27#include <com/sun/star/sdbc/XBlob.hpp>
28#include <com/sun/star/sdbc/XClob.hpp>
29#include <com/sun/star/sdbc/XRef.hpp>
30#include <com/sun/star/util/Date.hpp>
31#include <com/sun/star/util/Time.hpp>
32#include <com/sun/star/util/DateTime.hpp>
33#include <com/sun/star/ucb/PropertiesManager.hpp>
35#include <mutex>
36
37using namespace com::sun::star::beans;
38using namespace com::sun::star::io;
39using namespace com::sun::star::lang;
40using namespace com::sun::star::sdbc;
41using namespace com::sun::star::ucb;
42using namespace com::sun::star::uno;
43using namespace com::sun::star::util;
44
45
46namespace ucbhelper_impl {
47
49{
50 std::mutex m_aMutex;
51 std::vector< ::ucbhelper::ResultSetColumnData > m_aColumnData;
53
54 explicit ResultSetMetaData_Impl( sal_Int32 nSize )
55 : m_aColumnData( nSize ), m_bObtainedTypes( false ) {}
56
58 std::vector< ::ucbhelper::ResultSetColumnData >&& rColumnData )
59 : m_aColumnData( std::move(rColumnData) ), m_bObtainedTypes( false ) {}
60};
61
62}
63
64using namespace ucbhelper_impl;
65
66namespace ucbhelper {
67
68
69// ResultSetMetaData Implementation.
70
71
73 const Reference< XComponentContext >& rxContext,
74 const Sequence< Property >& rProps )
75: m_pImpl( new ResultSetMetaData_Impl( rProps.getLength() ) ),
76 m_xContext( rxContext ),
77 m_aProps( rProps )
78{
79}
80
81
82ResultSetMetaData::ResultSetMetaData(
83 const Reference< XComponentContext >& rxContext,
84 const Sequence< Property >& rProps,
85 std::vector< ResultSetColumnData >&& rColumnData )
86: m_pImpl( new ResultSetMetaData_Impl( std::move(rColumnData) ) ),
87 m_xContext( rxContext ),
88 m_aProps( rProps )
89{
90 OSL_ENSURE( m_pImpl->m_aColumnData.size() == sal_uInt32( rProps.getLength() ),
91 "ResultSetMetaData ctor - different array sizes!" );
92}
93
94
95// virtual
96ResultSetMetaData::~ResultSetMetaData()
97{
98}
99
100
101// XResultSetMetaData methods.
102
103
104// virtual
105sal_Int32 SAL_CALL ResultSetMetaData::getColumnCount()
106{
107 return m_aProps.getLength();
108}
109
110
111// virtual
112sal_Bool SAL_CALL ResultSetMetaData::isAutoIncrement( sal_Int32 /*column*/ )
113{
114 /*
115 Checks whether column is automatically numbered, which makes it
116 read-only.
117 */
118 return false;
119}
120
121
122// virtual
123sal_Bool SAL_CALL ResultSetMetaData::isCaseSensitive( sal_Int32 column )
124{
125 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
126 return false;
127
128 return m_pImpl->m_aColumnData[ column - 1 ].isCaseSensitive;
129}
130
131
132// virtual
133sal_Bool SAL_CALL ResultSetMetaData::isSearchable( sal_Int32 /*column*/ )
134{
135 return false;
136}
137
138
139// virtual
140sal_Bool SAL_CALL ResultSetMetaData::isCurrency( sal_Int32 /*column*/ )
141{
142 return false;
143}
144
145
146// virtual
147sal_Int32 SAL_CALL ResultSetMetaData::isNullable( sal_Int32 /*column*/ )
148{
149 return ColumnValue::NULLABLE;
150}
151
152
153// virtual
154sal_Bool SAL_CALL ResultSetMetaData::isSigned( sal_Int32 /*column*/ )
155{
156 return false;
157}
158
159
160// virtual
161sal_Int32 SAL_CALL ResultSetMetaData::getColumnDisplaySize( sal_Int32 /*column*/ )
162{
163 /*
164 Gets the normal maximum width in characters for column.
165 */
166 return 16;
167}
168
169
170// virtual
171OUString SAL_CALL ResultSetMetaData::getColumnLabel( sal_Int32 column )
172{
173 /*
174 Gets the suggested column title for column, to be used in print-
175 outs and displays.
176 */
177
178 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
179 return OUString();
180
181 return m_aProps.getConstArray()[ column - 1 ].Name;
182}
183
184
185// virtual
186OUString SAL_CALL ResultSetMetaData::getColumnName( sal_Int32 column )
187{
188 /*
189 Gets the name of column.
190 */
191
192 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
193 return OUString();
194
195 return m_aProps.getConstArray()[ column - 1 ].Name;
196}
197
198
199// virtual
200OUString SAL_CALL ResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
201{
202 /*
203 Gets the schema name for the table from which column of this
204 result set was derived.
205 Because this feature is not widely supported, the return value
206 for many DBMSs will be an empty string.
207 */
208 return OUString();
209}
210
211
212// virtual
213sal_Int32 SAL_CALL ResultSetMetaData::getPrecision( sal_Int32 /*column*/ )
214{
215 return -1;
216}
217
218
219// virtual
220sal_Int32 SAL_CALL ResultSetMetaData::getScale( sal_Int32 /*column*/ )
221{
222 return 0;
223}
224
225
226// virtual
227OUString SAL_CALL ResultSetMetaData::getTableName( sal_Int32 /*column*/ )
228{
229 /*
230 Gets the name of the table from which column of this result set
231 was derived or "" if there is none (for example, for a join).
232 Because this feature is not widely supported, the return value
233 for many DBMSs will be an empty string.
234 */
235 return OUString();
236}
237
238
239// virtual
240OUString SAL_CALL ResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
241{
242 /*
243 Gets the catalog name for the table from which column of this
244 result set was derived.
245 Because this feature is not widely supported, the return value
246 for many DBMSs will be an empty string.
247 */
248 return OUString();
249}
250
251
252// virtual
253sal_Int32 SAL_CALL ResultSetMetaData::getColumnType( sal_Int32 column )
254{
255 /*
256 Gets the JDBC type for the value stored in column. ... The STRUCT
257 and DISTINCT type codes are always returned for structured and
258 distinct types, regardless of whether the value will be mapped
259 according to the standard mapping or be a custom mapping.
260 */
261
262 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
263 return DataType::SQLNULL;
264
265 if ( m_aProps.getConstArray()[ column - 1 ].Type
267 {
268 // No type given. Try UCB's Properties Manager...
269
270 std::unique_lock aGuard( m_pImpl->m_aMutex );
271
272 if ( !m_pImpl->m_bObtainedTypes )
273 {
274 try
275 {
276 Reference< XPropertySetInfo > xInfo = PropertiesManager::create( m_xContext );
277 // Less (remote) calls...
278
279 const Sequence< Property > aProps = xInfo->getProperties();
280
281 for ( Property& rProp : asNonConstRange(m_aProps) )
282 {
283 auto pProp = std::find_if(aProps.begin(), aProps.end(),
284 [&rProp](const Property& rProp1) { return rProp.Name == rProp1.Name; });
285 if (pProp != aProps.end())
286 {
287 // Found...
288 rProp.Type = pProp->Type;
289 }
290 }
291 }
292 catch ( RuntimeException& )
293 {
294 throw;
295 }
296 catch ( Exception& )
297 {
298 // createInstance
299 }
300
301 m_pImpl->m_bObtainedTypes = true;
302 }
303 }
304
305 const Type& rType = m_aProps.getConstArray()[ column - 1 ].Type;
306 sal_Int32 nType = DataType::OTHER;
307
308 if ( rType == cppu::UnoType<OUString>::get() )
309 nType = DataType::VARCHAR; // XRow::getString
310 else if ( rType == cppu::UnoType<bool>::get() )
311 nType = DataType::BIT; // XRow::getBoolean
312 else if ( rType == cppu::UnoType<sal_Int32>::get() )
313 nType = DataType::INTEGER; // XRow::getInt
314 else if ( rType == cppu::UnoType<sal_Int64>::get() )
315 nType = DataType::BIGINT; // XRow::getLong
316 else if ( rType == cppu::UnoType<sal_Int16>::get() )
317 nType = DataType::SMALLINT; // XRow::getShort
318 else if ( rType == cppu::UnoType<sal_Int8>::get() )
319 nType = DataType::TINYINT; // XRow::getByte
320 else if ( rType == cppu::UnoType<float>::get() )
321 nType = DataType::REAL; // XRow::getFloat
322 else if ( rType == cppu::UnoType<double>::get() )
323 nType = DataType::DOUBLE; // XRow::getDouble
324 else if ( rType == cppu::UnoType<Sequence<sal_Int8>>::get() )
325 nType = DataType::VARBINARY;// XRow::getBytes
326 else if ( rType == cppu::UnoType<Date>::get() )
327 nType = DataType::DATE; // XRow::getDate
328 else if ( rType == cppu::UnoType<Time>::get() )
329 nType = DataType::TIME; // XRow::getTime
330 else if ( rType == cppu::UnoType<DateTime>::get() )
331 nType = DataType::TIMESTAMP;// XRow::getTimestamp
332 else if ( rType == cppu::UnoType<XInputStream>::get() )
333 nType = DataType::LONGVARBINARY; // XRow::getBinaryStream
334// nType = DataType::LONGVARCHAR; // XRow::getCharacterStream
335 else if ( rType == cppu::UnoType<XClob>::get() )
336 nType = DataType::CLOB; // XRow::getClob
337 else if ( rType == cppu::UnoType<XBlob>::get() )
338 nType = DataType::BLOB; // XRow::getBlob
339 else if ( rType == cppu::UnoType<XArray>::get() )
340 nType = DataType::ARRAY;// XRow::getArray
341 else if ( rType == cppu::UnoType<XRef>::get() )
342 nType = DataType::REF;// XRow::getRef
343 else
344 nType = DataType::OBJECT;// XRow::getObject
345
346 return nType;
347}
348
349
350// virtual
351OUString SAL_CALL ResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
352{
353 /*
354 Gets the type name used by this particular data source for the
355 values stored in column. If the type code for the type of value
356 stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
357 returns a fully-qualified SQL type name.
358 */
359 return OUString();
360}
361
362
363// virtual
364sal_Bool SAL_CALL ResultSetMetaData::isReadOnly( sal_Int32 /*column*/ )
365{
366 return true;
367}
368
369
370// virtual
371sal_Bool SAL_CALL ResultSetMetaData::isWritable( sal_Int32 /*column*/ )
372{
373 return false;
374}
375
376
377// virtual
378sal_Bool SAL_CALL ResultSetMetaData::isDefinitelyWritable( sal_Int32 /*column*/ )
379{
380 return false;
381}
382
383
384// virtual
385OUString SAL_CALL ResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
386{
387 /*
388 Returns the fully-qualified name of the service whose instances
389 are manufactured if XResultSet::getObject is called to retrieve
390 a value from the column.
391 */
392 return OUString();
393}
394
395} // namespace ucbhelper
396
397/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
Reference< XComponentContext > m_xContext
ResultSetMetaData(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Sequence< css::beans::Property > &rProps)
Constructor.
double getLength(const B2DPolygon &rCandidate)
@ Exception
Type
QPRO_FUNC_TYPE nType
uno::Sequence< beans::Property > m_aProps
Definition: resultset.cxx:91
ResultSetMetaData_Impl(std::vector< ::ucbhelper::ResultSetColumnData > &&rColumnData)
std::vector< ::ucbhelper::ResultSetColumnData > m_aColumnData
unsigned char sal_Bool