build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / misc / DatabaseDataProvider.cxx
blob3fd1ba2cb75161c000ae0372322bef72c6cc1e1e
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 .
20 #include "DatabaseDataProvider.hxx"
21 #include "dbastrings.hrc"
22 #include "cppuhelper/implbase1.hxx"
23 #include <cppuhelper/supportsservice.hxx>
24 #include <comphelper/types.hxx>
25 #include <comphelper/namedvaluecollection.hxx>
26 #include <connectivity/FValue.hxx>
27 #include <connectivity/dbtools.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <rtl/math.hxx>
30 #include <sal/macros.h>
31 #include <tools/diagnose_ex.h>
33 #include <com/sun/star/task/XInteractionHandler.hpp>
34 #include <com/sun/star/sdb/XCompletedExecution.hpp>
35 #include <com/sun/star/sdb/CommandType.hpp>
36 #include <com/sun/star/sdbc/DataType.hpp>
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/sdbc/XResultSet.hpp>
39 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
40 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
41 #include <com/sun/star/sdbc/XColumnLocate.hpp>
42 #include <com/sun/star/beans/NamedValue.hpp>
43 #include <com/sun/star/chart/ChartDataRowSource.hpp>
44 #include <com/sun/star/chart/XChartDataArray.hpp>
45 #include <com/sun/star/chart/XDateCategories.hpp>
47 #include <vector>
48 #include <list>
50 namespace dbaccess
52 using namespace ::com::sun::star;
53 using ::com::sun::star::sdbc::SQLException;
54 using ::com::sun::star::uno::Reference;
55 using ::com::sun::star::uno::RuntimeException;
57 DatabaseDataProvider::DatabaseDataProvider(uno::Reference< uno::XComponentContext > const & context) :
58 TDatabaseDataProvider(m_aMutex),
59 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >(
60 context, static_cast< Implements >(
61 IMPLEMENTS_PROPERTY_SET), uno::Sequence< OUString >()),
62 m_aParameterManager( m_aMutex, context ),
63 m_aFilterManager(),
64 m_xContext(context),
65 m_CommandType(sdb::CommandType::COMMAND), // #i94114
66 m_RowLimit(0),
67 m_EscapeProcessing(true),
68 m_ApplyFilter(true)
70 m_xInternal.set( m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.chart.InternalDataProvider",m_xContext ), uno::UNO_QUERY );
71 m_xRangeConversion.set(m_xInternal,uno::UNO_QUERY);
72 m_xComplexDescriptionAccess.set(m_xInternal,uno::UNO_QUERY);
74 osl_atomic_increment( &m_refCount );
76 m_xRowSet.set( m_xContext->getServiceManager()->createInstanceWithContext(SERVICE_SDB_ROWSET,m_xContext ), uno::UNO_QUERY );
77 m_xAggregate.set(m_xRowSet,uno::UNO_QUERY);
78 m_xAggregateSet.set(m_xRowSet,uno::UNO_QUERY);
79 uno::Reference<beans::XPropertySet> xProp(static_cast< ::cppu::OWeakObject* >( this ),uno::UNO_QUERY);
80 m_aFilterManager.initialize( m_xAggregateSet );
81 m_aParameterManager.initialize( xProp, m_xAggregate );
82 m_xAggregateSet->setPropertyValue(PROPERTY_COMMAND_TYPE,uno::makeAny(m_CommandType));
83 m_xAggregateSet->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,uno::makeAny(m_EscapeProcessing));
85 osl_atomic_decrement( &m_refCount );
88 void SAL_CALL DatabaseDataProvider::disposing()
90 lang::EventObject aEvt(static_cast<XWeak*>(this));
92 m_aParameterManager.dispose(); // (to free any references it may have to me)
93 m_aFilterManager.dispose(); // (dito)
95 m_xParent.clear();
96 m_xAggregateSet.clear();
97 m_xAggregate.clear();
98 m_xRangeConversion.clear();
99 ::comphelper::disposeComponent(m_xRowSet);
100 ::comphelper::disposeComponent(m_xInternal);
101 m_xActiveConnection.clear();
104 uno::Any DatabaseDataProvider::queryInterface(uno::Type const & type) throw (uno::RuntimeException, std::exception)
106 return TDatabaseDataProvider::queryInterface(type);
109 OUString DatabaseDataProvider::getImplementationName_Static( ) throw(uno::RuntimeException)
111 return OUString("com.sun.star.comp.dbaccess.DatabaseDataProvider");
114 // XServiceInfo
115 OUString SAL_CALL DatabaseDataProvider::getImplementationName( ) throw(uno::RuntimeException, std::exception)
117 return getImplementationName_Static();
120 sal_Bool SAL_CALL DatabaseDataProvider::supportsService( const OUString& _rServiceName ) throw(uno::RuntimeException, std::exception)
122 return cppu::supportsService(this, _rServiceName);
125 uno::Sequence< OUString > DatabaseDataProvider::getSupportedServiceNames_Static( ) throw (uno::RuntimeException)
127 uno::Sequence<OUString> aSNS { "com.sun.star.chart2.data.DatabaseDataProvider" };
128 return aSNS;
131 uno::Sequence< OUString > SAL_CALL DatabaseDataProvider::getSupportedServiceNames( ) throw(uno::RuntimeException, std::exception)
133 return getSupportedServiceNames_Static();
136 uno::Reference< uno::XInterface > DatabaseDataProvider::Create(uno::Reference< uno::XComponentContext > const & context)
138 return *(new DatabaseDataProvider(context)) ;
141 // lang::XInitialization:
142 void SAL_CALL DatabaseDataProvider::initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception, std::exception)
144 osl::MutexGuard g(m_aMutex);
145 const uno::Any* pIter = aArguments.getConstArray();
146 const uno::Any* pEnd = pIter + aArguments.getLength();
147 for(;pIter != pEnd;++pIter)
149 if ( !m_xActiveConnection.is() )
150 (*pIter) >>= m_xActiveConnection;
151 else if ( !m_xHandler.is() )
152 (*pIter) >>= m_xHandler;
154 m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, uno::makeAny( m_xActiveConnection ) );
157 // chart2::data::XDataProvider:
158 sal_Bool SAL_CALL DatabaseDataProvider::createDataSourcePossible(const uno::Sequence< beans::PropertyValue > & _aArguments) throw (uno::RuntimeException, std::exception)
160 const beans::PropertyValue* pArgIter = _aArguments.getConstArray();
161 const beans::PropertyValue* pArgEnd = pArgIter + _aArguments.getLength();
162 for(;pArgIter != pArgEnd;++pArgIter)
164 if ( pArgIter->Name == "DataRowSource" )
166 css::chart::ChartDataRowSource eRowSource = css::chart::ChartDataRowSource_COLUMNS;
167 pArgIter->Value >>= eRowSource;
168 if ( eRowSource != css::chart::ChartDataRowSource_COLUMNS )
169 return false;
171 else if ( pArgIter->Name == "CellRangeRepresentation" )
173 OUString sRange;
174 pArgIter->Value >>= sRange;
175 if ( sRange != "all" )
176 return false;
178 else if ( pArgIter->Name == "FirstCellAsLabel" )
180 bool bFirstCellAsLabel = true;
181 pArgIter->Value >>= bFirstCellAsLabel;
182 if ( !bFirstCellAsLabel )
183 return false;
186 return true;
189 uno::Reference< chart2::data::XDataSource > SAL_CALL DatabaseDataProvider::createDataSource(const uno::Sequence< beans::PropertyValue > & _aArguments) throw (uno::RuntimeException, lang::IllegalArgumentException, std::exception)
191 osl::ResettableMutexGuard aClearForNotifies(m_aMutex);
192 if ( createDataSourcePossible(_aArguments) )
196 uno::Reference< chart::XChartDataArray> xChartData( m_xInternal, uno::UNO_QUERY_THROW );
197 xChartData->setData( uno::Sequence< uno::Sequence< double > >() );
198 xChartData->setColumnDescriptions( uno::Sequence< OUString >() );
199 if ( m_xInternal->hasDataByRangeRepresentation( OUString::number( 0 ) ) )
200 m_xInternal->deleteSequence(0);
202 catch( const uno::Exception& )
204 DBG_UNHANDLED_EXCEPTION();
207 ::comphelper::NamedValueCollection aArgs( _aArguments );
208 const bool bHasCategories = aArgs.getOrDefault( "HasCategories", true );
209 uno::Sequence< OUString > aColumnNames =
210 aArgs.getOrDefault( "ColumnDescriptions", uno::Sequence< OUString >() );
212 bool bRet = false;
213 if ( !m_Command.isEmpty() && m_xActiveConnection.is() )
217 impl_fillRowSet_throw();
218 if ( impl_fillParameters_nothrow(aClearForNotifies) )
219 m_xRowSet->execute();
220 impl_fillInternalDataProvider_throw(bHasCategories,aColumnNames);
221 bRet = true;
223 catch(const uno::Exception& /*e*/)
227 if ( !bRet ) // no command set or an error occurred, use Internal data handler
229 uno::Reference< lang::XInitialization> xIni(m_xInternal,uno::UNO_QUERY);
230 if ( xIni.is() )
232 uno::Sequence< uno::Any > aInitArgs(1);
233 beans::NamedValue aParam("CreateDefaultData",uno::makeAny(true));
234 aInitArgs[0] <<= aParam;
235 xIni->initialize(aInitArgs);
240 return m_xInternal->createDataSource(_aArguments);
243 uno::Sequence< beans::PropertyValue > SAL_CALL DatabaseDataProvider::detectArguments(const uno::Reference< chart2::data::XDataSource > & _xDataSource) throw (uno::RuntimeException, std::exception)
245 ::comphelper::NamedValueCollection aArguments;
246 aArguments.put( "CellRangeRepresentation", uno::Any( OUString( "all" ) ) );
247 aArguments.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS ) );
248 // internal data always contains labels
249 aArguments.put( "FirstCellAsLabel", uno::makeAny( true ) );
251 bool bHasCategories = false;
252 if( _xDataSource.is())
254 uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSequences(_xDataSource->getDataSequences());
255 const sal_Int32 nCount( aSequences.getLength());
256 for( sal_Int32 nIdx=0; nIdx<nCount; ++nIdx )
258 if( aSequences[nIdx].is() )
260 uno::Reference< beans::XPropertySet > xSeqProp( aSequences[nIdx]->getValues(), uno::UNO_QUERY );
261 OUString aRole;
262 if ( xSeqProp.is()
263 && ( xSeqProp->getPropertyValue( "Role" ) >>= aRole )
264 && aRole == "categories"
267 bHasCategories = true;
268 break;
273 aArguments.put( "HasCategories", uno::makeAny( bHasCategories ) );
274 return aArguments.getPropertyValues();
277 sal_Bool SAL_CALL DatabaseDataProvider::createDataSequenceByRangeRepresentationPossible(const OUString & /*aRangeRepresentation*/) throw (uno::RuntimeException, std::exception)
279 return true;
282 uno::Any DatabaseDataProvider::impl_getNumberFormatKey_nothrow(const OUString & _sRangeRepresentation) const
284 ::std::map< OUString,css::uno::Any>::const_iterator aFind = m_aNumberFormats.find(_sRangeRepresentation);
285 if ( aFind != m_aNumberFormats.end() )
286 return aFind->second;
287 return uno::makeAny(sal_Int32(0));
290 uno::Reference< chart2::data::XDataSequence > SAL_CALL DatabaseDataProvider::createDataSequenceByRangeRepresentation(const OUString & _sRangeRepresentation) throw (uno::RuntimeException, lang::IllegalArgumentException, std::exception)
292 osl::MutexGuard g(m_aMutex);
293 uno::Reference< chart2::data::XDataSequence > xData = m_xInternal->createDataSequenceByRangeRepresentation(_sRangeRepresentation);
294 uno::Reference<beans::XPropertySet> xProp(xData,uno::UNO_QUERY);
295 static const char s_sNumberFormatKey[] = "NumberFormatKey";
296 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(s_sNumberFormatKey) )
298 xProp->setPropertyValue(s_sNumberFormatKey,impl_getNumberFormatKey_nothrow(_sRangeRepresentation));
300 return xData;
303 uno::Reference<chart2::data::XDataSequence>
304 SAL_CALL DatabaseDataProvider::createDataSequenceByValueArray(
305 const OUString& /*aRole*/, const OUString& /*aRangeRepresentation*/ )
306 throw (uno::RuntimeException, lang::IllegalArgumentException, std::exception)
308 return uno::Reference<chart2::data::XDataSequence>();
311 uno::Sequence< uno::Sequence< OUString > > SAL_CALL DatabaseDataProvider::getComplexRowDescriptions() throw (uno::RuntimeException, std::exception)
313 return m_xComplexDescriptionAccess->getComplexRowDescriptions();
316 void SAL_CALL DatabaseDataProvider::setComplexRowDescriptions( const uno::Sequence< uno::Sequence< OUString > >& aRowDescriptions ) throw (uno::RuntimeException, std::exception)
318 m_xComplexDescriptionAccess->setComplexRowDescriptions(aRowDescriptions);
321 uno::Sequence< uno::Sequence< OUString > > SAL_CALL DatabaseDataProvider::getComplexColumnDescriptions() throw (uno::RuntimeException, std::exception)
323 return m_xComplexDescriptionAccess->getComplexColumnDescriptions();
326 void SAL_CALL DatabaseDataProvider::setComplexColumnDescriptions( const uno::Sequence< uno::Sequence< OUString > >& aColumnDescriptions ) throw (uno::RuntimeException, std::exception)
328 m_xComplexDescriptionAccess->setComplexColumnDescriptions(aColumnDescriptions);
331 // ____ XChartDataArray ____
332 uno::Sequence< uno::Sequence< double > > SAL_CALL DatabaseDataProvider::getData() throw (uno::RuntimeException, std::exception)
334 return m_xComplexDescriptionAccess->getData();
337 void SAL_CALL DatabaseDataProvider::setData( const uno::Sequence< uno::Sequence< double > >& rDataInRows ) throw (uno::RuntimeException, std::exception)
339 m_xComplexDescriptionAccess->setData(rDataInRows);
342 void SAL_CALL DatabaseDataProvider::setRowDescriptions( const uno::Sequence< OUString >& aRowDescriptions ) throw (uno::RuntimeException, std::exception)
344 m_xComplexDescriptionAccess->setRowDescriptions(aRowDescriptions);
347 void SAL_CALL DatabaseDataProvider::setColumnDescriptions( const uno::Sequence< OUString >& aColumnDescriptions ) throw (uno::RuntimeException, std::exception)
349 m_xComplexDescriptionAccess->setColumnDescriptions(aColumnDescriptions);
352 uno::Sequence< OUString > SAL_CALL DatabaseDataProvider::getRowDescriptions() throw (uno::RuntimeException, std::exception)
354 return m_xComplexDescriptionAccess->getRowDescriptions();
357 uno::Sequence< OUString > SAL_CALL DatabaseDataProvider::getColumnDescriptions() throw (uno::RuntimeException, std::exception)
359 return m_xComplexDescriptionAccess->getColumnDescriptions();
362 // ____ XChartData (base of XChartDataArray) ____
363 void SAL_CALL DatabaseDataProvider::addChartDataChangeEventListener(const uno::Reference< css::chart::XChartDataChangeEventListener >& x) throw (uno::RuntimeException, std::exception)
365 m_xComplexDescriptionAccess->addChartDataChangeEventListener(x);
368 void SAL_CALL DatabaseDataProvider::removeChartDataChangeEventListener(const uno::Reference< css::chart::XChartDataChangeEventListener >& x) throw (uno::RuntimeException, std::exception)
370 m_xComplexDescriptionAccess->removeChartDataChangeEventListener(x);
373 double SAL_CALL DatabaseDataProvider::getNotANumber() throw (uno::RuntimeException, std::exception)
375 return m_xComplexDescriptionAccess->getNotANumber();
378 sal_Bool SAL_CALL DatabaseDataProvider::isNotANumber( double nNumber ) throw (uno::RuntimeException, std::exception)
380 return m_xComplexDescriptionAccess->isNotANumber(nNumber);
383 uno::Reference< sheet::XRangeSelection > SAL_CALL DatabaseDataProvider::getRangeSelection() throw (uno::RuntimeException, std::exception)
385 // TODO: Exchange the default return implementation for "getRangeSelection" !!!
386 // Exchange the default return implementation.
387 // NOTE: Default initialized polymorphic structs can cause problems because of
388 // missing default initialization of primitive types of some C++ compilers or
389 // different Any initialization in Java and C++ polymorphic structs.
390 return uno::Reference< sheet::XRangeSelection >();
393 // chart2::data::XRangeXMLConversion:
394 OUString SAL_CALL DatabaseDataProvider::convertRangeToXML(const OUString & _sRangeRepresentation) throw (uno::RuntimeException, lang::IllegalArgumentException, std::exception)
396 osl::MutexGuard g(m_aMutex);
397 return m_xRangeConversion->convertRangeToXML(_sRangeRepresentation);
400 OUString SAL_CALL DatabaseDataProvider::convertRangeFromXML(const OUString & _sXMLRange) throw (uno::RuntimeException, lang::IllegalArgumentException, std::exception)
402 osl::MutexGuard g(m_aMutex);
403 return m_xRangeConversion->convertRangeFromXML(_sXMLRange);
406 // com.sun.star.beans.XPropertySet:
407 uno::Reference< beans::XPropertySetInfo > SAL_CALL DatabaseDataProvider::getPropertySetInfo() throw (uno::RuntimeException, std::exception)
409 return ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::getPropertySetInfo();
412 void SAL_CALL DatabaseDataProvider::setPropertyValue(const OUString & aPropertyName, const uno::Any & aValue) throw (uno::RuntimeException, beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, std::exception)
414 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::setPropertyValue(aPropertyName, aValue);
417 uno::Any SAL_CALL DatabaseDataProvider::getPropertyValue(const OUString & aPropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException, std::exception)
419 return ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::getPropertyValue(aPropertyName);
422 void SAL_CALL DatabaseDataProvider::addPropertyChangeListener(const OUString & aPropertyName, const uno::Reference< beans::XPropertyChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException, std::exception)
424 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::addPropertyChangeListener(aPropertyName, xListener);
427 void SAL_CALL DatabaseDataProvider::removePropertyChangeListener(const OUString & aPropertyName, const uno::Reference< beans::XPropertyChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException, std::exception)
429 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::removePropertyChangeListener(aPropertyName, xListener);
432 void SAL_CALL DatabaseDataProvider::addVetoableChangeListener(const OUString & aPropertyName, const uno::Reference< beans::XVetoableChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException, std::exception)
434 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::addVetoableChangeListener(aPropertyName, xListener);
437 void SAL_CALL DatabaseDataProvider::removeVetoableChangeListener(const OUString & aPropertyName, const uno::Reference< beans::XVetoableChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException, std::exception)
439 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::removeVetoableChangeListener(aPropertyName, xListener);
442 // chart2::data::XDatabaseDataProvider:
443 uno::Sequence< OUString > SAL_CALL DatabaseDataProvider::getMasterFields() throw (uno::RuntimeException, std::exception)
445 osl::MutexGuard g(m_aMutex);
446 return m_MasterFields;
449 void SAL_CALL DatabaseDataProvider::setMasterFields(const uno::Sequence< OUString > & the_value) throw (uno::RuntimeException, std::exception)
451 impl_invalidateParameter_nothrow();
452 set("MasterFields",the_value,m_MasterFields);
455 uno::Sequence< OUString > SAL_CALL DatabaseDataProvider::getDetailFields() throw (uno::RuntimeException, std::exception)
457 osl::MutexGuard g(m_aMutex);
458 return m_DetailFields;
461 void SAL_CALL DatabaseDataProvider::setDetailFields(const uno::Sequence< OUString > & the_value) throw (uno::RuntimeException, std::exception)
463 set("DetailFields",the_value,m_DetailFields);
466 OUString SAL_CALL DatabaseDataProvider::getCommand() throw (uno::RuntimeException, std::exception)
468 osl::MutexGuard g(m_aMutex);
469 return m_Command;
472 void SAL_CALL DatabaseDataProvider::setCommand(const OUString & the_value) throw (uno::RuntimeException, std::exception)
475 osl::MutexGuard g(m_aMutex);
476 impl_invalidateParameter_nothrow();
477 m_xAggregateSet->setPropertyValue( PROPERTY_COMMAND, uno::makeAny( the_value ) );
479 set(PROPERTY_COMMAND,the_value,m_Command);
482 ::sal_Int32 SAL_CALL DatabaseDataProvider::getCommandType() throw (uno::RuntimeException, std::exception)
484 osl::MutexGuard g(m_aMutex);
485 return m_CommandType;
488 void SAL_CALL DatabaseDataProvider::setCommandType(::sal_Int32 the_value) throw (uno::RuntimeException, std::exception)
491 osl::MutexGuard g(m_aMutex);
492 m_xAggregateSet->setPropertyValue( PROPERTY_COMMAND_TYPE, uno::makeAny( the_value ) );
494 set(PROPERTY_COMMAND_TYPE,the_value,m_CommandType);
497 OUString SAL_CALL DatabaseDataProvider::getFilter() throw (uno::RuntimeException, std::exception)
499 osl::MutexGuard g(m_aMutex);
500 return m_aFilterManager.getFilterComponent( dbtools::FilterManager::FilterComponent::PublicFilter );
503 void SAL_CALL DatabaseDataProvider::setFilter(const OUString & the_value) throw (uno::RuntimeException, std::exception)
506 osl::MutexGuard g(m_aMutex);
507 m_aFilterManager.setFilterComponent( dbtools::FilterManager::FilterComponent::PublicFilter, the_value );
509 set(PROPERTY_FILTER,the_value,m_Filter);
512 sal_Bool SAL_CALL DatabaseDataProvider::getApplyFilter() throw (RuntimeException, std::exception)
514 osl::MutexGuard g(m_aMutex);
515 return m_ApplyFilter;
518 void SAL_CALL DatabaseDataProvider::setApplyFilter( sal_Bool the_value ) throw (RuntimeException, std::exception)
521 osl::MutexGuard g(m_aMutex);
522 m_xAggregateSet->setPropertyValue( PROPERTY_APPLYFILTER, uno::makeAny( the_value ) );
524 set(PROPERTY_APPLYFILTER,(bool)the_value,m_ApplyFilter);
527 OUString SAL_CALL DatabaseDataProvider::getHavingClause() throw (uno::RuntimeException, std::exception)
529 osl::MutexGuard g(m_aMutex);
530 return m_HavingClause;
533 void SAL_CALL DatabaseDataProvider::setHavingClause( const OUString& the_value ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
536 osl::MutexGuard g(m_aMutex);
537 m_xAggregateSet->setPropertyValue( PROPERTY_HAVING_CLAUSE, uno::makeAny( the_value ) );
539 set(PROPERTY_HAVING_CLAUSE,the_value,m_HavingClause);
542 OUString SAL_CALL DatabaseDataProvider::getGroupBy() throw (uno::RuntimeException, std::exception)
544 osl::MutexGuard g(m_aMutex);
545 return m_GroupBy;
548 void SAL_CALL DatabaseDataProvider::setGroupBy( const OUString& the_value ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
551 osl::MutexGuard g(m_aMutex);
552 m_xAggregateSet->setPropertyValue( PROPERTY_GROUP_BY, uno::makeAny( the_value ) );
554 set(PROPERTY_GROUP_BY,the_value,m_GroupBy);
557 OUString SAL_CALL DatabaseDataProvider::getOrder() throw (uno::RuntimeException, std::exception)
559 osl::MutexGuard g(m_aMutex);
560 return m_Order;
563 void SAL_CALL DatabaseDataProvider::setOrder( const OUString& the_value ) throw (uno::RuntimeException, std::exception)
566 osl::MutexGuard g(m_aMutex);
567 m_xAggregateSet->setPropertyValue( PROPERTY_ORDER, uno::makeAny( the_value ) );
569 set(PROPERTY_ORDER,the_value,m_Order);
572 sal_Bool SAL_CALL DatabaseDataProvider::getEscapeProcessing() throw (uno::RuntimeException, std::exception)
574 osl::MutexGuard g(m_aMutex);
575 return m_EscapeProcessing;
578 void SAL_CALL DatabaseDataProvider::setEscapeProcessing(sal_Bool the_value) throw (uno::RuntimeException, std::exception)
580 set(PROPERTY_ESCAPE_PROCESSING,(bool)the_value,m_EscapeProcessing);
583 ::sal_Int32 SAL_CALL DatabaseDataProvider::getRowLimit() throw (uno::RuntimeException, std::exception)
585 osl::MutexGuard g(m_aMutex);
586 return m_RowLimit;
589 void SAL_CALL DatabaseDataProvider::setRowLimit(::sal_Int32 the_value) throw (uno::RuntimeException, std::exception)
591 set("RowLimit",the_value,m_RowLimit);
594 uno::Reference< sdbc::XConnection > SAL_CALL DatabaseDataProvider::getActiveConnection() throw (uno::RuntimeException, std::exception)
596 osl::MutexGuard g(m_aMutex);
597 return m_xActiveConnection;
600 void SAL_CALL DatabaseDataProvider::setActiveConnection(const uno::Reference< sdbc::XConnection > & the_value) throw (uno::RuntimeException, lang::IllegalArgumentException, std::exception)
602 if ( !the_value.is() )
603 throw lang::IllegalArgumentException();
604 set(PROPERTY_ACTIVE_CONNECTION,the_value,m_xActiveConnection);
607 OUString SAL_CALL DatabaseDataProvider::getDataSourceName() throw (uno::RuntimeException, std::exception)
609 osl::MutexGuard g(m_aMutex);
610 return m_DataSourceName;
613 void SAL_CALL DatabaseDataProvider::setDataSourceName(const OUString& the_value) throw (uno::RuntimeException, std::exception)
615 set(PROPERTY_DATASOURCENAME,the_value,m_DataSourceName);
618 namespace
620 struct ColumnDescription
622 OUString sName;
623 sal_Int32 nResultSetPosition;
624 sal_Int32 nDataType;
626 ColumnDescription()
627 :sName()
628 ,nResultSetPosition( 0 )
629 ,nDataType( sdbc::DataType::VARCHAR )
632 explicit ColumnDescription( const OUString& i_rName )
633 :sName( i_rName )
634 ,nResultSetPosition( 0 )
635 ,nDataType( sdbc::DataType::VARCHAR )
640 struct CreateColumnDescription : public ::std::unary_function< OUString, ColumnDescription >
642 ColumnDescription operator()( const OUString& i_rName )
644 return ColumnDescription( i_rName );
648 struct SelectColumnName : public ::std::unary_function< ColumnDescription, OUString >
650 const OUString& operator()( const ColumnDescription& i_rColumn )
652 return i_rColumn.sName;
657 void DatabaseDataProvider::impl_fillInternalDataProvider_throw(bool _bHasCategories,const uno::Sequence< OUString >& i_aColumnNames)
659 // clear the data before fill the new one
660 uno::Reference< sdbcx::XColumnsSupplier > xColSup(m_xRowSet,uno::UNO_QUERY_THROW);
661 uno::Reference< container::XNameAccess > xColumns( xColSup->getColumns(), uno::UNO_SET_THROW );
662 const uno::Sequence< OUString > aRowSetColumnNames( xColumns->getElementNames() );
664 typedef ::std::vector< ColumnDescription > ColumnDescriptions;
665 ColumnDescriptions aColumns;
666 bool bFirstColumnIsCategory = _bHasCategories;
667 if ( i_aColumnNames.getLength() )
669 // some normalizations ...
670 uno::Sequence< OUString > aImposedColumnNames( i_aColumnNames );
672 // strangely, there exist documents where the ColumnDescriptions end with a number of empty strings. /me
673 // thinks they're generated when you have a chart based on a result set with n columns, but remove some
674 // of those columns from the chart - it looks like a bug in the report XML export to me.
675 // So, get rid of the "trailing" empty columns
676 sal_Int32 nLastNonEmptyColName = aImposedColumnNames.getLength() - 1;
677 for ( ; nLastNonEmptyColName >= 0; --nLastNonEmptyColName )
679 if ( !aImposedColumnNames[ nLastNonEmptyColName ].isEmpty() )
680 break;
682 aImposedColumnNames.realloc( nLastNonEmptyColName + 1 );
684 // second, for X-Y-charts the ColumnDescriptions exported by chart miss the name of the first (non-category)
685 // column. This, this results in a ColumnDescriptions array like <"", "col2", "col3">, where you'd expect
686 // <"col1", "col2", "col3">.
687 // Fix this with some heuristics:
688 if ( ( aImposedColumnNames.getLength() > 0 ) && ( !aImposedColumnNames[0].isEmpty() ) )
690 const sal_Int32 nAssumedRowSetColumnIndex = _bHasCategories ? 1 : 0;
691 if ( nAssumedRowSetColumnIndex < aRowSetColumnNames.getLength() )
692 aImposedColumnNames[0] = aRowSetColumnNames[ nAssumedRowSetColumnIndex ];
695 const sal_Int32 nCount = aImposedColumnNames.getLength();
696 for ( sal_Int32 i = 0 ; i < nCount; ++i )
698 const OUString sColumnName( aImposedColumnNames[i] );
699 if ( !xColumns->hasByName( sColumnName ) )
700 continue;
702 if ( _bHasCategories && aColumns.empty() )
704 if ( aRowSetColumnNames.getLength() )
705 aColumns.push_back( ColumnDescription( aRowSetColumnNames[0] ) );
706 else
707 aColumns.push_back( ColumnDescription( sColumnName ) );
708 bFirstColumnIsCategory = true;
710 aColumns.push_back( ColumnDescription( sColumnName ) );
713 if ( aColumns.empty() )
715 aColumns.resize( aRowSetColumnNames.getLength() );
716 ::std::transform(
717 aRowSetColumnNames.getConstArray(),
718 aRowSetColumnNames.getConstArray() + aRowSetColumnNames.getLength(),
719 aColumns.begin(),
720 CreateColumnDescription()
724 // fill the data
725 uno::Reference< sdbc::XResultSet> xRes( m_xRowSet, uno::UNO_QUERY_THROW );
726 uno::Reference< sdbc::XRow> xRow( m_xRowSet,uno::UNO_QUERY_THROW );
727 uno::Reference< sdbc::XResultSetMetaDataSupplier > xSuppMeta( m_xRowSet,uno::UNO_QUERY_THROW );
728 uno::Reference< sdbc::XResultSetMetaData > xResultSetMetaData( xSuppMeta->getMetaData(), uno::UNO_SET_THROW );
729 uno::Reference< sdbc::XColumnLocate > xColumnLocate( m_xRowSet, uno::UNO_QUERY_THROW );
731 for ( ColumnDescriptions::iterator col = aColumns.begin();
732 col != aColumns.end();
733 ++col
736 col->nResultSetPosition = xColumnLocate->findColumn( col->sName );
738 const uno::Reference< beans::XPropertySet > xColumn( xColumns->getByName( col->sName ), uno::UNO_QUERY_THROW );
739 const uno::Any aNumberFormat( xColumn->getPropertyValue( PROPERTY_NUMBERFORMAT ) );
740 OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_TYPE ) >>= col->nDataType );
742 const sal_Int32 columnIndex = col - aColumns.begin();
743 const OUString sRangeName = OUString::number( columnIndex );
744 m_aNumberFormats.insert( ::std::map< OUString, uno::Any >::value_type( sRangeName, aNumberFormat ) );
747 ::std::vector< OUString > aRowLabels;
748 ::std::vector< ::std::vector< double > > aDataValues;
749 sal_Int32 nRowCount = 0;
750 ::connectivity::ORowSetValue aValue;
751 while( xRes->next() && (!m_RowLimit || nRowCount < m_RowLimit) )
753 ++nRowCount;
755 aValue.fill( aColumns[0].nResultSetPosition, aColumns[0].nDataType, xRow );
756 aRowLabels.push_back( aValue.getString() );
758 ::std::vector< double > aRow;
759 for ( ColumnDescriptions::const_iterator col = aColumns.begin();
760 col != aColumns.end();
761 ++col
764 if ( bFirstColumnIsCategory && ( col == aColumns.begin() ) )
765 continue;
767 aValue.fill( col->nResultSetPosition, col->nDataType, xRow );
768 if ( aValue.isNull() )
770 double nValue;
771 ::rtl::math::setNan( &nValue );
772 aRow.push_back( nValue );
774 else
775 aRow.push_back( aValue.getDouble() );
778 aDataValues.push_back( aRow );
781 // insert default data when no rows exist
782 if ( !nRowCount )
784 nRowCount = 3;
785 static const double fDefaultData[ ] =
786 { 9.10, 3.20, 4.54,
787 2.40, 8.80, 9.65,
788 3.10, 1.50, 3.70,
789 4.30, 9.02, 6.20 };
790 for(sal_Int32 h = 0,k = 0; h < nRowCount; ++h,++k )
792 aRowLabels.push_back(OUString::number(h+1));
793 ::std::vector< double > aRow;
794 const sal_Int32 nSize = SAL_N_ELEMENTS(fDefaultData);
795 for (size_t j = 0; j < (aColumns.size()-1); ++j,++k)
797 if ( k >= nSize )
798 k = 0;
799 aRow.push_back(fDefaultData[k]);
801 aDataValues.push_back(aRow);
805 uno::Reference< chart::XChartDataArray> xData(m_xInternal,uno::UNO_QUERY);
806 xData->setRowDescriptions(uno::Sequence< OUString >(&(*aRowLabels.begin()),aRowLabels.size()));
808 const size_t nOffset = bFirstColumnIsCategory ? 1 : 0;
809 uno::Sequence< OUString > aColumnDescriptions( aColumns.size() - nOffset );
810 ::std::transform(
811 aColumns.begin() + nOffset,
812 aColumns.end(),
813 aColumnDescriptions.getArray(),
814 SelectColumnName()
816 xData->setColumnDescriptions( aColumnDescriptions );
818 uno::Sequence< uno::Sequence< double > > aData(aDataValues.size());
819 uno::Sequence< double >* pDataIter = aData.getArray();
820 uno::Sequence< double >* pDataEnd = pDataIter + aData.getLength();
821 for(sal_Int32 i= 0;pDataIter != pDataEnd; ++pDataIter,++i )
823 if ( !aDataValues[i].empty() )
824 *pDataIter = uno::Sequence< double >(&(*(aDataValues[i]).begin()),(aDataValues[i]).size());
826 xData->setData(aData);
829 void DatabaseDataProvider::impl_fillRowSet_throw()
831 m_xAggregateSet->setPropertyValue( PROPERTY_FILTER, uno::makeAny( getFilter() ) );
832 uno::Reference< sdbc::XParameters> xParam(m_xRowSet,uno::UNO_QUERY_THROW);
833 xParam->clearParameters( );
836 bool DatabaseDataProvider::impl_fillParameters_nothrow( ::osl::ResettableMutexGuard& _rClearForNotifies)
838 // do we have to fill the parameters again?
839 if ( !m_aParameterManager.isUpToDate() )
840 m_aParameterManager.updateParameterInfo( m_aFilterManager );
842 if ( m_aParameterManager.isUpToDate() )
843 return m_aParameterManager.fillParameterValues( m_xHandler, _rClearForNotifies );
845 return true;
848 // css::sdbc::XParameters
849 void SAL_CALL DatabaseDataProvider::setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) throw( SQLException, RuntimeException, std::exception )
851 m_aParameterManager.setNull(parameterIndex, sqlType);
854 void SAL_CALL DatabaseDataProvider::setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName) throw( SQLException, RuntimeException, std::exception )
856 m_aParameterManager.setObjectNull(parameterIndex, sqlType, typeName);
859 void SAL_CALL DatabaseDataProvider::setBoolean(sal_Int32 parameterIndex, sal_Bool x) throw( SQLException, RuntimeException, std::exception )
861 m_aParameterManager.setBoolean(parameterIndex, x);
864 void SAL_CALL DatabaseDataProvider::setByte(sal_Int32 parameterIndex, sal_Int8 x) throw( SQLException, RuntimeException, std::exception )
866 m_aParameterManager.setByte(parameterIndex, x);
869 void SAL_CALL DatabaseDataProvider::setShort(sal_Int32 parameterIndex, sal_Int16 x) throw( SQLException, RuntimeException, std::exception )
871 m_aParameterManager.setShort(parameterIndex, x);
874 void SAL_CALL DatabaseDataProvider::setInt(sal_Int32 parameterIndex, sal_Int32 x) throw( SQLException, RuntimeException, std::exception )
876 m_aParameterManager.setInt(parameterIndex, x);
879 void SAL_CALL DatabaseDataProvider::setLong(sal_Int32 parameterIndex, sal_Int64 x) throw( SQLException, RuntimeException, std::exception )
881 m_aParameterManager.setLong(parameterIndex, x);
884 void SAL_CALL DatabaseDataProvider::setFloat(sal_Int32 parameterIndex, float x) throw( SQLException, RuntimeException, std::exception )
886 m_aParameterManager.setFloat(parameterIndex, x);
889 void SAL_CALL DatabaseDataProvider::setDouble(sal_Int32 parameterIndex, double x) throw( SQLException, RuntimeException, std::exception )
891 m_aParameterManager.setDouble(parameterIndex, x);
894 void SAL_CALL DatabaseDataProvider::setString(sal_Int32 parameterIndex, const OUString& x) throw( SQLException, RuntimeException, std::exception )
896 m_aParameterManager.setString(parameterIndex, x);
899 void SAL_CALL DatabaseDataProvider::setBytes(sal_Int32 parameterIndex, const uno::Sequence< sal_Int8 >& x) throw( SQLException, RuntimeException, std::exception )
901 m_aParameterManager.setBytes(parameterIndex, x);
904 void SAL_CALL DatabaseDataProvider::setDate(sal_Int32 parameterIndex, const util::Date& x) throw( SQLException, RuntimeException, std::exception )
906 m_aParameterManager.setDate(parameterIndex, x);
909 void SAL_CALL DatabaseDataProvider::setTime(sal_Int32 parameterIndex, const util::Time& x) throw( SQLException, RuntimeException, std::exception )
911 m_aParameterManager.setTime(parameterIndex, x);
914 void SAL_CALL DatabaseDataProvider::setTimestamp(sal_Int32 parameterIndex, const util::DateTime& x) throw( SQLException, RuntimeException, std::exception )
916 m_aParameterManager.setTimestamp(parameterIndex, x);
919 void SAL_CALL DatabaseDataProvider::setBinaryStream(sal_Int32 parameterIndex, const uno::Reference<io::XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException, std::exception )
921 m_aParameterManager.setBinaryStream(parameterIndex, x, length);
924 void SAL_CALL DatabaseDataProvider::setCharacterStream(sal_Int32 parameterIndex, const uno::Reference<io::XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException, std::exception )
926 m_aParameterManager.setCharacterStream(parameterIndex, x, length);
929 void SAL_CALL DatabaseDataProvider::setObjectWithInfo(sal_Int32 parameterIndex, const uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale) throw( SQLException, RuntimeException, std::exception )
931 m_aParameterManager.setObjectWithInfo(parameterIndex, x, targetSqlType, scale);
934 void SAL_CALL DatabaseDataProvider::setObject(sal_Int32 parameterIndex, const uno::Any& x) throw( SQLException, RuntimeException, std::exception )
936 m_aParameterManager.setObject(parameterIndex, x);
939 void SAL_CALL DatabaseDataProvider::setRef(sal_Int32 parameterIndex, const uno::Reference<sdbc::XRef>& x) throw( SQLException, RuntimeException, std::exception )
941 m_aParameterManager.setRef(parameterIndex, x);
944 void SAL_CALL DatabaseDataProvider::setBlob(sal_Int32 parameterIndex, const uno::Reference<sdbc::XBlob>& x) throw( SQLException, RuntimeException, std::exception )
946 m_aParameterManager.setBlob(parameterIndex, x);
949 void SAL_CALL DatabaseDataProvider::setClob(sal_Int32 parameterIndex, const uno::Reference<sdbc::XClob>& x) throw( SQLException, RuntimeException, std::exception )
951 m_aParameterManager.setClob(parameterIndex, x);
954 void SAL_CALL DatabaseDataProvider::setArray(sal_Int32 parameterIndex, const Reference<sdbc::XArray>& x) throw( SQLException, RuntimeException, std::exception )
956 m_aParameterManager.setArray(parameterIndex, x);
959 void SAL_CALL DatabaseDataProvider::clearParameters() throw( SQLException, RuntimeException, std::exception )
961 m_aParameterManager.clearParameters();
964 // css::sdbc::XRowSet
965 void SAL_CALL DatabaseDataProvider::execute() throw( SQLException, RuntimeException, std::exception )
967 uno::Sequence< beans::PropertyValue > aEmpty;
968 createDataSource(aEmpty);
971 void SAL_CALL DatabaseDataProvider::addRowSetListener(const uno::Reference<sdbc::XRowSetListener>& _rListener) throw( RuntimeException, std::exception )
973 if (m_xRowSet.is())
974 m_xRowSet->addRowSetListener(_rListener);
977 void SAL_CALL DatabaseDataProvider::removeRowSetListener(const uno::Reference<sdbc::XRowSetListener>& _rListener) throw( RuntimeException, std::exception )
979 if (m_xRowSet.is())
980 m_xRowSet->removeRowSetListener(_rListener);
983 // css::sdbc::XResultSet
984 sal_Bool SAL_CALL DatabaseDataProvider::next() throw( SQLException, RuntimeException, std::exception )
986 return m_xRowSet->next();
989 sal_Bool SAL_CALL DatabaseDataProvider::isBeforeFirst() throw( SQLException, RuntimeException, std::exception )
991 return m_xRowSet->isBeforeFirst();
994 sal_Bool SAL_CALL DatabaseDataProvider::isAfterLast() throw( SQLException, RuntimeException, std::exception )
996 return m_xRowSet->isAfterLast();
999 sal_Bool SAL_CALL DatabaseDataProvider::isFirst() throw( SQLException, RuntimeException, std::exception )
1001 return m_xRowSet->isFirst();
1004 sal_Bool SAL_CALL DatabaseDataProvider::isLast() throw( SQLException, RuntimeException, std::exception )
1006 return m_xRowSet->isLast();
1009 void SAL_CALL DatabaseDataProvider::beforeFirst() throw( SQLException, RuntimeException, std::exception )
1011 m_xRowSet->beforeFirst();
1014 void SAL_CALL DatabaseDataProvider::afterLast() throw( SQLException, RuntimeException, std::exception )
1016 m_xRowSet->afterLast();
1019 sal_Bool SAL_CALL DatabaseDataProvider::first() throw( SQLException, RuntimeException, std::exception )
1021 return m_xRowSet->first();
1024 sal_Bool SAL_CALL DatabaseDataProvider::last() throw( SQLException, RuntimeException, std::exception )
1026 return m_xRowSet->last();
1029 sal_Int32 SAL_CALL DatabaseDataProvider::getRow() throw( SQLException, RuntimeException, std::exception )
1031 return m_xRowSet->getRow();
1034 sal_Bool SAL_CALL DatabaseDataProvider::absolute(sal_Int32 row) throw( SQLException, RuntimeException, std::exception )
1036 return m_xRowSet->absolute(row);
1039 sal_Bool SAL_CALL DatabaseDataProvider::relative(sal_Int32 rows) throw( SQLException, RuntimeException, std::exception )
1041 return m_xRowSet->relative(rows);
1044 sal_Bool SAL_CALL DatabaseDataProvider::previous() throw( SQLException, RuntimeException, std::exception )
1046 return m_xRowSet->previous();
1049 void SAL_CALL DatabaseDataProvider::refreshRow() throw( SQLException, RuntimeException, std::exception )
1051 m_xRowSet->refreshRow();
1054 sal_Bool SAL_CALL DatabaseDataProvider::rowUpdated() throw( SQLException, RuntimeException, std::exception )
1056 return m_xRowSet->rowUpdated();
1059 sal_Bool SAL_CALL DatabaseDataProvider::rowInserted() throw( SQLException, RuntimeException, std::exception )
1061 return m_xRowSet->rowInserted();
1064 sal_Bool SAL_CALL DatabaseDataProvider::rowDeleted() throw( SQLException, RuntimeException, std::exception )
1066 return m_xRowSet->rowDeleted();
1069 uno::Reference< uno::XInterface > SAL_CALL DatabaseDataProvider::getStatement() throw( SQLException, RuntimeException, std::exception )
1071 return m_xRowSet->getStatement();
1074 uno::Reference< uno::XInterface > SAL_CALL DatabaseDataProvider::getParent( ) throw (uno::RuntimeException, std::exception)
1076 return m_xParent;
1079 void SAL_CALL DatabaseDataProvider::setParent( const uno::Reference< uno::XInterface >& _xParent ) throw (lang::NoSupportException, uno::RuntimeException, std::exception)
1081 osl::MutexGuard g(m_aMutex);
1082 m_xParent = _xParent;
1085 void DatabaseDataProvider::impl_invalidateParameter_nothrow()
1087 osl::MutexGuard g(m_aMutex);
1088 m_aParameterManager.clearAllParameterInformation();
1091 } // namespace dbaccess
1093 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */