lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / ucbhelper / source / provider / resultsetmetadata.cxx
blob3666fa802f9b1f406380943a81262b98a4b83a47
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 *************************************************************************/
27 #include <osl/diagnose.h>
28 #include <com/sun/star/beans/Property.hpp>
29 #include <com/sun/star/beans/XPropertySetInfo.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/sdbc/ColumnValue.hpp>
33 #include <com/sun/star/sdbc/DataType.hpp>
34 #include <com/sun/star/sdbc/XArray.hpp>
35 #include <com/sun/star/sdbc/XBlob.hpp>
36 #include <com/sun/star/sdbc/XClob.hpp>
37 #include <com/sun/star/sdbc/XRef.hpp>
38 #include <com/sun/star/util/Date.hpp>
39 #include <com/sun/star/util/Time.hpp>
40 #include <com/sun/star/util/DateTime.hpp>
41 #include <com/sun/star/ucb/PropertiesManager.hpp>
42 #include <ucbhelper/macros.hxx>
43 #include <ucbhelper/resultsetmetadata.hxx>
44 #include <cppuhelper/queryinterface.hxx>
46 using namespace com::sun::star::beans;
47 using namespace com::sun::star::io;
48 using namespace com::sun::star::lang;
49 using namespace com::sun::star::sdbc;
50 using namespace com::sun::star::ucb;
51 using namespace com::sun::star::uno;
52 using namespace com::sun::star::util;
55 namespace ucbhelper_impl {
57 struct ResultSetMetaData_Impl
59 osl::Mutex m_aMutex;
60 std::vector< ::ucbhelper::ResultSetColumnData > m_aColumnData;
61 bool m_bObtainedTypes;
63 explicit ResultSetMetaData_Impl( sal_Int32 nSize )
64 : m_aColumnData( nSize ), m_bObtainedTypes( false ) {}
66 explicit ResultSetMetaData_Impl(
67 const std::vector< ::ucbhelper::ResultSetColumnData >& rColumnData )
68 : m_aColumnData( rColumnData ), m_bObtainedTypes( false ) {}
73 using namespace ucbhelper_impl;
75 namespace ucbhelper {
78 // ResultSetMetaData Implementation.
81 ResultSetMetaData::ResultSetMetaData(
82 const Reference< XComponentContext >& rxContext,
83 const Sequence< Property >& rProps )
84 : m_pImpl( new ResultSetMetaData_Impl( rProps.getLength() ) ),
85 m_xContext( rxContext ),
86 m_aProps( rProps )
91 ResultSetMetaData::ResultSetMetaData(
92 const Reference< XComponentContext >& rxContext,
93 const Sequence< Property >& rProps,
94 const std::vector< ResultSetColumnData >& rColumnData )
95 : m_pImpl( new ResultSetMetaData_Impl( rColumnData ) ),
96 m_xContext( rxContext ),
97 m_aProps( rProps )
99 OSL_ENSURE( rColumnData.size() == sal_uInt32( rProps.getLength() ),
100 "ResultSetMetaData ctor - different array sizes!" );
104 // virtual
105 ResultSetMetaData::~ResultSetMetaData()
110 // XInterface methods.
112 void SAL_CALL ResultSetMetaData::acquire()
113 throw()
115 OWeakObject::acquire();
118 void SAL_CALL ResultSetMetaData::release()
119 throw()
121 OWeakObject::release();
124 css::uno::Any SAL_CALL ResultSetMetaData::queryInterface( const css::uno::Type & rType )
126 css::uno::Any aRet = cppu::queryInterface( rType,
127 static_cast< XTypeProvider* >(this),
128 static_cast< XResultSetMetaData* >(this)
130 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
133 // XTypeProvider methods.
136 XTYPEPROVIDER_IMPL_2( ResultSetMetaData,
137 XTypeProvider,
138 XResultSetMetaData );
141 // XResultSetMetaData methods.
144 // virtual
145 sal_Int32 SAL_CALL ResultSetMetaData::getColumnCount()
147 return m_aProps.getLength();
151 // virtual
152 sal_Bool SAL_CALL ResultSetMetaData::isAutoIncrement( sal_Int32 /*column*/ )
155 Checks whether column is automatically numbered, which makes it
156 read-only.
158 return false;
162 // virtual
163 sal_Bool SAL_CALL ResultSetMetaData::isCaseSensitive( sal_Int32 column )
165 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
166 return false;
168 return m_pImpl->m_aColumnData[ column - 1 ].isCaseSensitive;
172 // virtual
173 sal_Bool SAL_CALL ResultSetMetaData::isSearchable( sal_Int32 /*column*/ )
175 return false;
179 // virtual
180 sal_Bool SAL_CALL ResultSetMetaData::isCurrency( sal_Int32 /*column*/ )
182 return false;
186 // virtual
187 sal_Int32 SAL_CALL ResultSetMetaData::isNullable( sal_Int32 /*column*/ )
189 return ColumnValue::NULLABLE;
193 // virtual
194 sal_Bool SAL_CALL ResultSetMetaData::isSigned( sal_Int32 /*column*/ )
196 return false;
200 // virtual
201 sal_Int32 SAL_CALL ResultSetMetaData::getColumnDisplaySize( sal_Int32 /*column*/ )
204 Gets the normal maximum width in characters for column.
206 return 16;
210 // virtual
211 OUString SAL_CALL ResultSetMetaData::getColumnLabel( sal_Int32 column )
214 Gets the suggested column title for column, to be used in print-
215 outs and displays.
218 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
219 return OUString();
221 return m_aProps.getConstArray()[ column - 1 ].Name;
225 // virtual
226 OUString SAL_CALL ResultSetMetaData::getColumnName( sal_Int32 column )
229 Gets the name of column.
232 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
233 return OUString();
235 return m_aProps.getConstArray()[ column - 1 ].Name;
239 // virtual
240 OUString SAL_CALL ResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
243 Gets the schema 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.
248 return OUString();
252 // virtual
253 sal_Int32 SAL_CALL ResultSetMetaData::getPrecision( sal_Int32 /*column*/ )
255 return -1;
259 // virtual
260 sal_Int32 SAL_CALL ResultSetMetaData::getScale( sal_Int32 /*column*/ )
262 return 0;
266 // virtual
267 OUString SAL_CALL ResultSetMetaData::getTableName( sal_Int32 /*column*/ )
270 Gets the name of the table from which column of this result set
271 was derived or "" if there is none (for example, for a join).
272 Because this feature is not widely supported, the return value
273 for many DBMSs will be an empty string.
275 return OUString();
279 // virtual
280 OUString SAL_CALL ResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
283 Gets the catalog name for the table from which column of this
284 result set was derived.
285 Because this feature is not widely supported, the return value
286 for many DBMSs will be an empty string.
288 return OUString();
292 // virtual
293 sal_Int32 SAL_CALL ResultSetMetaData::getColumnType( sal_Int32 column )
296 Gets the JDBC type for the value stored in column. ... The STRUCT
297 and DISTINCT type codes are always returned for structured and
298 distinct types, regardless of whether the value will be mapped
299 according to the standard mapping or be a custom mapping.
302 if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
303 return DataType::SQLNULL;
305 if ( m_aProps.getConstArray()[ column - 1 ].Type
306 == cppu::UnoType<void>::get() )
308 // No type given. Try UCB's Properties Manager...
310 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
312 if ( !m_pImpl->m_bObtainedTypes )
316 Reference< XPropertySetInfo > xInfo = PropertiesManager::create( m_xContext );
317 // Less (remote) calls...
319 Sequence< Property > aProps = xInfo->getProperties();
320 const Property* pProps1 = aProps.getConstArray();
321 sal_Int32 nCount1 = aProps.getLength();
323 sal_Int32 nCount = m_aProps.getLength();
324 Property* pProps = m_aProps.getArray();
325 for ( sal_Int32 n = 0; n < nCount; ++n )
327 Property& rProp = pProps[ n ];
329 for ( sal_Int32 m = 0; m < nCount1; ++m )
331 const Property& rProp1 = pProps1[ m ];
332 if ( rProp.Name == rProp1.Name )
334 // Found...
335 rProp.Type = rProp1.Type;
336 break;
341 catch ( RuntimeException& )
343 throw;
345 catch ( Exception& )
347 // createInstance
350 m_pImpl->m_bObtainedTypes = true;
354 const Type& rType = m_aProps.getConstArray()[ column - 1 ].Type;
355 sal_Int32 nType = DataType::OTHER;
357 if ( rType == cppu::UnoType<OUString>::get() )
358 nType = DataType::VARCHAR; // XRow::getString
359 else if ( rType == cppu::UnoType<bool>::get() )
360 nType = DataType::BIT; // XRow::getBoolean
361 else if ( rType == cppu::UnoType<sal_Int32>::get() )
362 nType = DataType::INTEGER; // XRow::getInt
363 else if ( rType == cppu::UnoType<sal_Int64>::get() )
364 nType = DataType::BIGINT; // XRow::getLong
365 else if ( rType == cppu::UnoType<sal_Int16>::get() )
366 nType = DataType::SMALLINT; // XRow::getShort
367 else if ( rType == cppu::UnoType<sal_Int8>::get() )
368 nType = DataType::TINYINT; // XRow::getByte
369 else if ( rType == cppu::UnoType<float>::get() )
370 nType = DataType::REAL; // XRow::getFloat
371 else if ( rType == cppu::UnoType<double>::get() )
372 nType = DataType::DOUBLE; // XRow::getDouble
373 else if ( rType == cppu::UnoType<Sequence<sal_Int8>>::get() )
374 nType = DataType::VARBINARY;// XRow::getBytes
375 else if ( rType == cppu::UnoType<Date>::get() )
376 nType = DataType::DATE; // XRow::getDate
377 else if ( rType == cppu::UnoType<Time>::get() )
378 nType = DataType::TIME; // XRow::getTime
379 else if ( rType == cppu::UnoType<DateTime>::get() )
380 nType = DataType::TIMESTAMP;// XRow::getTimestamp
381 else if ( rType == cppu::UnoType<XInputStream>::get() )
382 nType = DataType::LONGVARBINARY; // XRow::getBinaryStream
383 // nType = DataType::LONGVARCHAR; // XRow::getCharacterStream
384 else if ( rType == cppu::UnoType<XClob>::get() )
385 nType = DataType::CLOB; // XRow::getClob
386 else if ( rType == cppu::UnoType<XBlob>::get() )
387 nType = DataType::BLOB; // XRow::getBlob
388 else if ( rType == cppu::UnoType<XArray>::get() )
389 nType = DataType::ARRAY;// XRow::getArray
390 else if ( rType == cppu::UnoType<XRef>::get() )
391 nType = DataType::REF;// XRow::getRef
392 else
393 nType = DataType::OBJECT;// XRow::getObject
395 return nType;
399 // virtual
400 OUString SAL_CALL ResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
403 Gets the type name used by this particular data source for the
404 values stored in column. If the type code for the type of value
405 stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
406 returns a fully-qualified SQL type name.
408 return OUString();
412 // virtual
413 sal_Bool SAL_CALL ResultSetMetaData::isReadOnly( sal_Int32 /*column*/ )
415 return true;
419 // virtual
420 sal_Bool SAL_CALL ResultSetMetaData::isWritable( sal_Int32 /*column*/ )
422 return false;
426 // virtual
427 sal_Bool SAL_CALL ResultSetMetaData::isDefinitelyWritable( sal_Int32 /*column*/ )
429 return false;
433 // virtual
434 OUString SAL_CALL ResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
437 Returns the fully-qualified name of the service whose instances
438 are manufactured if XResultSet::getObject is called to retrieve
439 a value from the column.
441 return OUString();
444 } // namespace ucbhelper
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */