update dev300-m58
[ooovba.git] / dbaccess / source / core / misc / DatabaseDataProvider.cxx
blob46d7f929310a1813fa07988aa5acb49348dd4f58
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile$
10 * $Revision$
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 // MARKER(update_precomp.py): autogen include statement, do not remove
31 #include "precompiled_dbaccess.hxx"
33 #include "DatabaseDataProvider.hxx"
34 #include "dbastrings.hrc"
35 #include "cppuhelper/implbase1.hxx"
36 #include <comphelper/types.hxx>
37 #include <connectivity/FValue.hxx>
38 #include <connectivity/dbtools.hxx>
39 #include <rtl/ustrbuf.hxx>
41 #include <com/sun/star/task/XInteractionHandler.hpp>
42 #include <com/sun/star/sdb/XCompletedExecution.hpp>
43 #include <com/sun/star/sdb/CommandType.hpp>
44 #include <com/sun/star/sdbc/XRow.hpp>
45 #include <com/sun/star/sdbc/XResultSet.hpp>
46 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
47 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
48 #include <com/sun/star/beans/NamedValue.hpp>
49 #include <com/sun/star/chart/ChartDataRowSource.hpp>
50 #include <com/sun/star/chart/XChartDataArray.hpp>
52 #include <vector>
53 #include <list>
55 namespace dbaccess
57 using namespace ::com::sun::star;
58 using ::com::sun::star::sdbc::SQLException;
59 using ::com::sun::star::uno::Reference;
60 using ::com::sun::star::uno::RuntimeException;
61 // -----------------------------------------------------------------------------
62 DatabaseDataProvider::DatabaseDataProvider(uno::Reference< uno::XComponentContext > const & context) :
63 TDatabaseDataProvider(m_aMutex),
64 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >(
65 context, static_cast< Implements >(
66 IMPLEMENTS_PROPERTY_SET), uno::Sequence< ::rtl::OUString >()),
67 m_aParameterManager( m_aMutex, uno::Reference< lang::XMultiServiceFactory >(context->getServiceManager(),uno::UNO_QUERY) ),
68 m_aFilterManager( uno::Reference< lang::XMultiServiceFactory >(context->getServiceManager(),uno::UNO_QUERY) ),
69 m_xContext(context),
70 m_CommandType(sdb::CommandType::COMMAND), // #i94114
71 m_RowLimit(0),
72 m_EscapeProcessing(sal_True),
73 m_ApplyFilter(sal_True)
75 m_xInternal.set( m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.chart.InternalDataProvider")),m_xContext ), uno::UNO_QUERY );
76 m_xRangeConversion.set(m_xInternal,uno::UNO_QUERY);
78 osl_incrementInterlockedCount( &m_refCount );
80 m_xRowSet.set( m_xContext->getServiceManager()->createInstanceWithContext(SERVICE_SDB_ROWSET,m_xContext ), uno::UNO_QUERY );
81 m_xAggregate.set(m_xRowSet,uno::UNO_QUERY);
82 m_xAggregateSet.set(m_xRowSet,uno::UNO_QUERY);
83 uno::Reference<beans::XPropertySet> xProp(static_cast< ::cppu::OWeakObject* >( this ),uno::UNO_QUERY);
84 m_aFilterManager.initialize( m_xAggregateSet );
85 m_aParameterManager.initialize( xProp, m_xAggregate );
86 m_xAggregateSet->setPropertyValue(PROPERTY_COMMAND_TYPE,uno::makeAny(m_CommandType));
87 m_xAggregateSet->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,uno::makeAny(m_EscapeProcessing));
89 osl_decrementInterlockedCount( &m_refCount );
91 // -----------------------------------------------------------------------------
92 void SAL_CALL DatabaseDataProvider::disposing()
94 lang::EventObject aEvt(static_cast<XWeak*>(this));
95 m_aParameterManager.disposing( aEvt );
97 m_aParameterManager.dispose(); // (to free any references it may have to me)
98 m_aFilterManager.dispose(); // (dito)
100 m_xParent.clear();
101 m_xAggregateSet.clear();
102 m_xAggregate.clear();
103 m_xRangeConversion.clear();
104 ::comphelper::disposeComponent(m_xRowSet);
105 ::comphelper::disposeComponent(m_xInternal);
106 m_xActiveConnection.clear();
108 // -----------------------------------------------------------------------------
109 uno::Any DatabaseDataProvider::queryInterface(uno::Type const & type) throw (uno::RuntimeException)
111 return TDatabaseDataProvider::queryInterface(type);
113 // -----------------------------------------------------------------------------
115 //------------------------------------------------------------------------------
116 rtl::OUString DatabaseDataProvider::getImplementationName_Static( ) throw(uno::RuntimeException)
118 return rtl::OUString::createFromAscii("com.sun.star.comp.chart2.data.DatabaseDataProvider");
120 // -----------------------------------------------------------------------------
121 // -------------------------------------------------------------------------
122 // XServiceInfo
123 ::rtl::OUString SAL_CALL DatabaseDataProvider::getImplementationName( ) throw(uno::RuntimeException)
125 return getImplementationName_Static();
127 // -----------------------------------------------------------------------------
128 // -------------------------------------------------------------------------
129 sal_Bool SAL_CALL DatabaseDataProvider::supportsService( const ::rtl::OUString& _rServiceName ) throw(uno::RuntimeException)
131 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
133 // -----------------------------------------------------------------------------
134 //------------------------------------------------------------------------------
135 uno::Sequence< ::rtl::OUString > DatabaseDataProvider::getSupportedServiceNames_Static( ) throw (uno::RuntimeException)
137 uno::Sequence< rtl::OUString > aSNS( 1 );
138 aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DatabaseDataProvider"));
139 return aSNS;
141 // -----------------------------------------------------------------------------
142 uno::Sequence< ::rtl::OUString > SAL_CALL DatabaseDataProvider::getSupportedServiceNames( ) throw(uno::RuntimeException)
144 return getSupportedServiceNames_Static();
146 // -----------------------------------------------------------------------------
147 uno::Reference< uno::XInterface > DatabaseDataProvider::Create(uno::Reference< uno::XComponentContext > const & context)
149 return *(new DatabaseDataProvider(context)) ;
151 // -----------------------------------------------------------------------------
152 // lang::XInitialization:
153 void SAL_CALL DatabaseDataProvider::initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception)
155 osl::MutexGuard g(m_aMutex);
156 const uno::Any* pIter = aArguments.getConstArray();
157 const uno::Any* pEnd = pIter + aArguments.getLength();
158 for(;pIter != pEnd;++pIter)
160 if ( !m_xActiveConnection.is() )
161 (*pIter) >>= m_xActiveConnection;
162 else if ( !m_xHandler.is() )
163 (*pIter) >>= m_xHandler;
165 m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, uno::makeAny( m_xActiveConnection ) );
167 // -----------------------------------------------------------------------------
169 // chart2::data::XDataProvider:
170 ::sal_Bool SAL_CALL DatabaseDataProvider::createDataSourcePossible(const uno::Sequence< beans::PropertyValue > & _aArguments) throw (uno::RuntimeException)
172 //::osl::ResettableMutexGuard aClearForNotifies(m_aMutex);
173 const beans::PropertyValue* pArgIter = _aArguments.getConstArray();
174 const beans::PropertyValue* pArgEnd = pArgIter + _aArguments.getLength();
175 for(;pArgIter != pArgEnd;++pArgIter)
177 if ( pArgIter->Name.equalsAscii("DataRowSource") )
179 ::com::sun::star::chart::ChartDataRowSource eRowSource = ::com::sun::star::chart::ChartDataRowSource_COLUMNS;
180 pArgIter->Value >>= eRowSource;
181 if ( eRowSource != ::com::sun::star::chart::ChartDataRowSource_COLUMNS )
182 return sal_False;
183 } // if ( pArgIter->Name.equalsAscii("DataRowSource") )
184 else if ( pArgIter->Name.equalsAscii("CellRangeRepresentation") )
186 ::rtl::OUString sRange;
187 pArgIter->Value >>= sRange;
188 if ( !sRange.equalsAscii("all") )
189 return sal_False;
191 else if ( pArgIter->Name.equalsAscii("FirstCellAsLabel") )
193 sal_Bool bFirstCellAsLabel = sal_True;
194 pArgIter->Value >>= bFirstCellAsLabel;
195 if ( !bFirstCellAsLabel )
196 return sal_False;
199 return sal_True;
201 // -----------------------------------------------------------------------------
202 // -----------------------------------------------------------------------------
203 uno::Reference< chart2::data::XDataSource > SAL_CALL DatabaseDataProvider::createDataSource(const uno::Sequence< beans::PropertyValue > & _aArguments) throw (uno::RuntimeException, lang::IllegalArgumentException)
205 osl::ResettableMutexGuard aClearForNotifies(m_aMutex);
206 if ( createDataSourcePossible(_aArguments) )
208 sal_Bool bHasCategories = sal_True;
209 const beans::PropertyValue* pArgIter = _aArguments.getConstArray();
210 const beans::PropertyValue* pArgEnd = pArgIter + _aArguments.getLength();
211 for(;pArgIter != pArgEnd;++pArgIter)
213 if ( pArgIter->Name.equalsAscii("HasCategories") )
215 pArgIter->Value >>= bHasCategories;
216 break;
219 bool bRet = false;
220 if ( m_Command.getLength() != 0 && m_xActiveConnection.is() )
224 impl_fillRowSet_throw();
225 impl_executeRowSet_throw(aClearForNotifies);
226 impl_fillInternalDataProvider_throw(bHasCategories);
227 bRet = true;
229 catch(const uno::Exception& /*e*/)
233 if ( !bRet ) // no command set or an error occured, use Internal data handler
235 uno::Reference< lang::XInitialization> xIni(m_xInternal,uno::UNO_QUERY);
236 if ( xIni.is() )
238 uno::Sequence< uno::Any > aArgs(1);
239 beans::NamedValue aParam(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CreateDefaultData")),uno::makeAny(sal_True));
240 aArgs[0] <<= aParam;
241 xIni->initialize(aArgs);
246 return m_xInternal->createDataSource(_aArguments);
248 // -----------------------------------------------------------------------------
250 uno::Sequence< beans::PropertyValue > SAL_CALL DatabaseDataProvider::detectArguments(const uno::Reference< chart2::data::XDataSource > & _xDataSource) throw (uno::RuntimeException)
252 uno::Sequence< beans::PropertyValue > aArguments( 4 );
253 aArguments[0] = beans::PropertyValue(
254 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CellRangeRepresentation")), -1, uno::Any(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("all")) ),
255 beans::PropertyState_DIRECT_VALUE );
256 aArguments[1] = beans::PropertyValue(
257 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataRowSource")), -1, uno::makeAny( chart::ChartDataRowSource_COLUMNS ),
258 beans::PropertyState_DIRECT_VALUE );
259 // internal data always contains labels and categories
260 aArguments[2] = beans::PropertyValue(
261 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FirstCellAsLabel")), -1, uno::makeAny( true ), beans::PropertyState_DIRECT_VALUE );
262 sal_Bool bHasCategories = sal_False;
263 if( _xDataSource.is())
265 uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSequences(_xDataSource->getDataSequences());
266 const sal_Int32 nCount( aSequences.getLength());
267 for( sal_Int32 nIdx=0; nIdx<nCount; ++nIdx )
269 if( aSequences[nIdx].is() )
271 uno::Reference< beans::XPropertySet > xSeqProp( aSequences[nIdx]->getValues(), uno::UNO_QUERY );
272 ::rtl::OUString aRole;
273 if( xSeqProp.is() &&
274 (xSeqProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Role"))) >>= aRole) &&
275 aRole.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("categories")) )
277 bHasCategories = sal_True;
278 break;
284 aArguments[3] = beans::PropertyValue(
285 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasCategories")), -1, uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
286 return aArguments;
288 // -----------------------------------------------------------------------------
290 ::sal_Bool SAL_CALL DatabaseDataProvider::createDataSequenceByRangeRepresentationPossible(const ::rtl::OUString & /*aRangeRepresentation*/) throw (uno::RuntimeException)
292 return sal_True;
294 // -----------------------------------------------------------------------------
295 uno::Any DatabaseDataProvider::impl_getNumberFormatKey_nothrow(const ::rtl::OUString & _sRangeRepresentation) const
297 ::std::map< ::rtl::OUString,com::sun::star::uno::Any>::const_iterator aFind = m_aNumberFormats.find(_sRangeRepresentation);
298 if ( aFind != m_aNumberFormats.end() )
299 return aFind->second;
300 return uno::makeAny(sal_Int32(0));
302 // -----------------------------------------------------------------------------
303 uno::Reference< chart2::data::XDataSequence > SAL_CALL DatabaseDataProvider::createDataSequenceByRangeRepresentation(const ::rtl::OUString & _sRangeRepresentation) throw (uno::RuntimeException, lang::IllegalArgumentException)
305 osl::MutexGuard g(m_aMutex);
306 uno::Reference< chart2::data::XDataSequence > xData = m_xInternal->createDataSequenceByRangeRepresentation(_sRangeRepresentation);;
307 uno::Reference<beans::XPropertySet> xProp(xData,uno::UNO_QUERY);
308 const static ::rtl::OUString s_sNumberFormatKey(RTL_CONSTASCII_USTRINGPARAM("NumberFormatKey"));
309 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(s_sNumberFormatKey) )
311 xProp->setPropertyValue(s_sNumberFormatKey,impl_getNumberFormatKey_nothrow(_sRangeRepresentation));
313 return xData;
315 // -----------------------------------------------------------------------------
317 uno::Reference< sheet::XRangeSelection > SAL_CALL DatabaseDataProvider::getRangeSelection() throw (uno::RuntimeException)
319 // TODO: Exchange the default return implementation for "getRangeSelection" !!!
320 // Exchange the default return implementation.
321 // NOTE: Default initialized polymorphic structs can cause problems because of
322 // missing default initialization of primitive types of some C++ compilers or
323 // different Any initialization in Java and C++ polymorphic structs.
324 return uno::Reference< sheet::XRangeSelection >();
326 // -----------------------------------------------------------------------------
327 // chart2::data::XRangeXMLConversion:
328 ::rtl::OUString SAL_CALL DatabaseDataProvider::convertRangeToXML(const ::rtl::OUString & _sRangeRepresentation) throw (uno::RuntimeException, lang::IllegalArgumentException)
330 osl::MutexGuard g(m_aMutex);
331 return m_xRangeConversion->convertRangeToXML(_sRangeRepresentation);
333 // -----------------------------------------------------------------------------
335 ::rtl::OUString SAL_CALL DatabaseDataProvider::convertRangeFromXML(const ::rtl::OUString & _sXMLRange) throw (uno::RuntimeException, lang::IllegalArgumentException)
337 osl::MutexGuard g(m_aMutex);
338 return m_xRangeConversion->convertRangeFromXML(_sXMLRange);
340 // -----------------------------------------------------------------------------
342 // com.sun.star.beans.XPropertySet:
343 uno::Reference< beans::XPropertySetInfo > SAL_CALL DatabaseDataProvider::getPropertySetInfo() throw (uno::RuntimeException)
345 return ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::getPropertySetInfo();
347 // -----------------------------------------------------------------------------
349 void SAL_CALL DatabaseDataProvider::setPropertyValue(const ::rtl::OUString & aPropertyName, const uno::Any & aValue) throw (uno::RuntimeException, beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException)
351 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::setPropertyValue(aPropertyName, aValue);
353 // -----------------------------------------------------------------------------
355 uno::Any SAL_CALL DatabaseDataProvider::getPropertyValue(const ::rtl::OUString & aPropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException)
357 return ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::getPropertyValue(aPropertyName);
359 // -----------------------------------------------------------------------------
361 void SAL_CALL DatabaseDataProvider::addPropertyChangeListener(const ::rtl::OUString & aPropertyName, const uno::Reference< beans::XPropertyChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException)
363 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::addPropertyChangeListener(aPropertyName, xListener);
365 // -----------------------------------------------------------------------------
367 void SAL_CALL DatabaseDataProvider::removePropertyChangeListener(const ::rtl::OUString & aPropertyName, const uno::Reference< beans::XPropertyChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException)
369 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::removePropertyChangeListener(aPropertyName, xListener);
371 // -----------------------------------------------------------------------------
373 void SAL_CALL DatabaseDataProvider::addVetoableChangeListener(const ::rtl::OUString & aPropertyName, const uno::Reference< beans::XVetoableChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException)
375 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::addVetoableChangeListener(aPropertyName, xListener);
377 // -----------------------------------------------------------------------------
379 void SAL_CALL DatabaseDataProvider::removeVetoableChangeListener(const ::rtl::OUString & aPropertyName, const uno::Reference< beans::XVetoableChangeListener > & xListener) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::WrappedTargetException)
381 ::cppu::PropertySetMixin< chart2::data::XDatabaseDataProvider >::removeVetoableChangeListener(aPropertyName, xListener);
383 // -----------------------------------------------------------------------------
385 // chart2::data::XDatabaseDataProvider:
386 uno::Sequence< ::rtl::OUString > SAL_CALL DatabaseDataProvider::getMasterFields() throw (uno::RuntimeException)
388 osl::MutexGuard g(m_aMutex);
389 return m_MasterFields;
391 // -----------------------------------------------------------------------------
393 void SAL_CALL DatabaseDataProvider::setMasterFields(const uno::Sequence< ::rtl::OUString > & the_value) throw (uno::RuntimeException)
395 impl_invalidateParameter_nothrow();
396 set(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MasterFields")),the_value,m_MasterFields);
398 // -----------------------------------------------------------------------------
400 uno::Sequence< ::rtl::OUString > SAL_CALL DatabaseDataProvider::getDetailFields() throw (uno::RuntimeException)
402 osl::MutexGuard g(m_aMutex);
403 return m_DetailFields;
405 // -----------------------------------------------------------------------------
407 void SAL_CALL DatabaseDataProvider::setDetailFields(const uno::Sequence< ::rtl::OUString > & the_value) throw (uno::RuntimeException)
409 set(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DetailFields")),the_value,m_DetailFields);
411 // -----------------------------------------------------------------------------
412 ::rtl::OUString SAL_CALL DatabaseDataProvider::getCommand() throw (uno::RuntimeException)
414 osl::MutexGuard g(m_aMutex);
415 return m_Command;
417 // -----------------------------------------------------------------------------
419 void SAL_CALL DatabaseDataProvider::setCommand(const ::rtl::OUString & the_value) throw (uno::RuntimeException)
422 osl::MutexGuard g(m_aMutex);
423 impl_invalidateParameter_nothrow();
424 m_xAggregateSet->setPropertyValue( PROPERTY_COMMAND, uno::makeAny( the_value ) );
426 set(PROPERTY_COMMAND,the_value,m_Command);
428 // -----------------------------------------------------------------------------
430 ::sal_Int32 SAL_CALL DatabaseDataProvider::getCommandType() throw (uno::RuntimeException)
432 osl::MutexGuard g(m_aMutex);
433 return m_CommandType;
435 // -----------------------------------------------------------------------------
437 void SAL_CALL DatabaseDataProvider::setCommandType(::sal_Int32 the_value) throw (uno::RuntimeException)
440 osl::MutexGuard g(m_aMutex);
441 m_xAggregateSet->setPropertyValue( PROPERTY_COMMAND_TYPE, uno::makeAny( the_value ) );
443 set(PROPERTY_COMMAND_TYPE,the_value,m_CommandType);
445 // -----------------------------------------------------------------------------
447 ::rtl::OUString SAL_CALL DatabaseDataProvider::getFilter() throw (uno::RuntimeException)
449 osl::MutexGuard g(m_aMutex);
450 return m_aFilterManager.getFilterComponent( dbtools::FilterManager::fcPublicFilter );
452 // -----------------------------------------------------------------------------
454 void SAL_CALL DatabaseDataProvider::setFilter(const ::rtl::OUString & the_value) throw (uno::RuntimeException)
457 osl::MutexGuard g(m_aMutex);
458 m_aFilterManager.setFilterComponent( dbtools::FilterManager::fcPublicFilter, the_value );
460 set(PROPERTY_FILTER,the_value,m_Filter);
462 // -----------------------------------------------------------------------------
463 ::sal_Bool SAL_CALL DatabaseDataProvider::getApplyFilter() throw (RuntimeException)
465 osl::MutexGuard g(m_aMutex);
466 return m_ApplyFilter;
468 // -----------------------------------------------------------------------------
469 void SAL_CALL DatabaseDataProvider::setApplyFilter( ::sal_Bool the_value ) throw (RuntimeException)
472 osl::MutexGuard g(m_aMutex);
473 m_xAggregateSet->setPropertyValue( PROPERTY_APPLYFILTER, uno::makeAny( the_value ) );
475 set(PROPERTY_APPLYFILTER,the_value,m_ApplyFilter);
477 // -----------------------------------------------------------------------------
478 ::rtl::OUString SAL_CALL DatabaseDataProvider::getHavingClause() throw (uno::RuntimeException)
480 osl::MutexGuard g(m_aMutex);
481 return m_HavingClause;
483 // -----------------------------------------------------------------------------
484 void SAL_CALL DatabaseDataProvider::setHavingClause( const ::rtl::OUString& the_value ) throw (beans::UnknownPropertyException, uno::RuntimeException)
487 osl::MutexGuard g(m_aMutex);
488 m_xAggregateSet->setPropertyValue( PROPERTY_HAVING_CLAUSE, uno::makeAny( the_value ) );
490 set(PROPERTY_HAVING_CLAUSE,the_value,m_HavingClause);
492 // -----------------------------------------------------------------------------
493 ::rtl::OUString SAL_CALL DatabaseDataProvider::getGroupBy() throw (uno::RuntimeException)
495 osl::MutexGuard g(m_aMutex);
496 return m_GroupBy;
498 // -----------------------------------------------------------------------------
499 void SAL_CALL DatabaseDataProvider::setGroupBy( const ::rtl::OUString& the_value ) throw (beans::UnknownPropertyException, uno::RuntimeException)
502 osl::MutexGuard g(m_aMutex);
503 m_xAggregateSet->setPropertyValue( PROPERTY_GROUP_BY, uno::makeAny( the_value ) );
505 set(PROPERTY_GROUP_BY,the_value,m_GroupBy);
507 // -----------------------------------------------------------------------------
508 ::rtl::OUString SAL_CALL DatabaseDataProvider::getOrder() throw (uno::RuntimeException)
510 osl::MutexGuard g(m_aMutex);
511 return m_Order;
513 // -----------------------------------------------------------------------------
514 void SAL_CALL DatabaseDataProvider::setOrder( const ::rtl::OUString& the_value ) throw (uno::RuntimeException)
517 osl::MutexGuard g(m_aMutex);
518 m_xAggregateSet->setPropertyValue( PROPERTY_ORDER, uno::makeAny( the_value ) );
520 set(PROPERTY_ORDER,the_value,m_Order);
522 // -----------------------------------------------------------------------------
523 ::sal_Bool SAL_CALL DatabaseDataProvider::getEscapeProcessing() throw (uno::RuntimeException)
525 osl::MutexGuard g(m_aMutex);
526 return m_EscapeProcessing;
528 // -----------------------------------------------------------------------------
530 void SAL_CALL DatabaseDataProvider::setEscapeProcessing(::sal_Bool the_value) throw (uno::RuntimeException)
532 set(PROPERTY_ESCAPE_PROCESSING,the_value,m_EscapeProcessing);
534 // -----------------------------------------------------------------------------
535 ::sal_Int32 SAL_CALL DatabaseDataProvider::getRowLimit() throw (uno::RuntimeException)
537 osl::MutexGuard g(m_aMutex);
538 return m_RowLimit;
540 // -----------------------------------------------------------------------------
542 void SAL_CALL DatabaseDataProvider::setRowLimit(::sal_Int32 the_value) throw (uno::RuntimeException)
544 set(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RowLimit")),the_value,m_RowLimit);
546 // -----------------------------------------------------------------------------
547 uno::Reference< sdbc::XConnection > SAL_CALL DatabaseDataProvider::getActiveConnection() throw (uno::RuntimeException)
549 osl::MutexGuard g(m_aMutex);
550 return m_xActiveConnection;
552 // -----------------------------------------------------------------------------
554 void SAL_CALL DatabaseDataProvider::setActiveConnection(const uno::Reference< sdbc::XConnection > & the_value) throw (uno::RuntimeException, lang::IllegalArgumentException)
556 if ( !the_value.is() )
557 throw lang::IllegalArgumentException();
558 set(PROPERTY_ACTIVE_CONNECTION,the_value,m_xActiveConnection);
560 // -----------------------------------------------------------------------------
561 ::rtl::OUString SAL_CALL DatabaseDataProvider::getDataSourceName() throw (uno::RuntimeException)
563 osl::MutexGuard g(m_aMutex);
564 return m_DataSourceName;
566 // -----------------------------------------------------------------------------
568 void SAL_CALL DatabaseDataProvider::setDataSourceName(const ::rtl::OUString& the_value) throw (uno::RuntimeException)
570 set(PROPERTY_DATASOURCENAME,the_value,m_DataSourceName);
572 // -----------------------------------------------------------------------------
573 void DatabaseDataProvider::impl_executeRowSet_throw(::osl::ResettableMutexGuard& _rClearForNotifies)
575 if ( impl_fillParameters_nothrow(_rClearForNotifies) )
576 m_xRowSet->execute();
578 // -----------------------------------------------------------------------------
579 void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCategories)
581 // clear the data before fill the new one
582 uno::Reference< chart::XChartDataArray> xChartData(m_xInternal,uno::UNO_QUERY);
583 if ( xChartData.is() )
585 xChartData->setData(uno::Sequence< uno::Sequence<double> >());
586 xChartData->setColumnDescriptions(uno::Sequence< ::rtl::OUString >());
587 m_xInternal->deleteSequence(0);
590 uno::Sequence< ::rtl::OUString > aColumns;
591 uno::Reference< sdbcx::XColumnsSupplier> xColSup(m_xRowSet,uno::UNO_QUERY_THROW);
592 uno::Reference< container::XNameAccess > xColumns = xColSup->getColumns();
593 if ( xColumns.is() )
594 aColumns = xColumns->getElementNames();
595 // fill the data
596 uno::Reference< sdbc::XResultSet> xRes(m_xRowSet,uno::UNO_QUERY_THROW);
597 uno::Reference< sdbc::XRow> xRow(m_xRowSet,uno::UNO_QUERY_THROW);
598 uno::Reference< sdbc::XResultSetMetaData> xResultSetMetaData = uno::Reference< sdbc::XResultSetMetaDataSupplier>(m_xRowSet,uno::UNO_QUERY)->getMetaData();
600 ::std::vector<sal_Int32> aColumnTypes;
601 uno::Sequence< uno::Any > aLabelArgs(1);
602 const sal_Int32 nCount = aColumns.getLength();
603 if ( nCount )
604 aColumnTypes.push_back(xResultSetMetaData->getColumnType(1));
605 for (sal_Int32 i = 1; i < nCount; ++i)
607 aColumnTypes.push_back(xResultSetMetaData->getColumnType(i+1));
608 } // for (sal_Int32 i = 1; i < nCount; ++i)
610 const ::rtl::OUString* pIter = aColumns.getConstArray();
611 const ::rtl::OUString* pEnd = pIter + aColumns.getLength();
612 for(sal_Int32 k = 0;pIter != pEnd;++pIter,++k)
614 uno::Reference< beans::XPropertySet> xColumn(xColumns->getByName(*pIter),uno::UNO_QUERY);
615 if ( xColumn.is() )
617 m_aNumberFormats.insert( ::std::map< ::rtl::OUString,uno::Any>::value_type(::rtl::OUString::valueOf(k),xColumn->getPropertyValue(PROPERTY_NUMBERFORMAT)));
621 ::std::vector< ::rtl::OUString > aRowLabels;
622 ::std::vector< ::std::vector< double > > aDataValues;
623 sal_Int32 nRowCount = 0;
624 ::connectivity::ORowSetValue aValue;
625 while( xRes->next() && (!m_RowLimit || nRowCount < m_RowLimit) )
627 ++nRowCount;
629 aValue.fill(1,aColumnTypes[0],xRow);
630 aRowLabels.push_back(aValue.getString());
631 ::std::vector< double > aRow;
632 for (sal_Int32 j = _bHasCategories ? 2 : 1,i = 0; j <= nCount; ++j,++i)
634 aValue.fill(j,aColumnTypes[j-1],xRow);
635 aRow.push_back(aValue.getDouble());
636 } // for (sal_Int32 j = 2,i = 0; j <= nCount; ++j,++i)
637 aDataValues.push_back(aRow);
638 } // while( xRes->next() && (!m_RowLimit || nRowCount < m_RowLimit) )
640 // insert default data when no rows exist
641 if ( !nRowCount )
643 nRowCount = 3;
644 const double fDefaultData[ ] =
645 { 9.10, 3.20, 4.54,
646 2.40, 8.80, 9.65,
647 3.10, 1.50, 3.70,
648 4.30, 9.02, 6.20 };
649 for(sal_Int32 h = 0,k = 0; h < nRowCount; ++h,++k )
651 aRowLabels.push_back(::rtl::OUString::valueOf(h+1));
652 ::std::vector< double > aRow;
653 const sal_Int32 nSize = sizeof(fDefaultData)/sizeof(fDefaultData[0]);
654 for (sal_Int32 j = 0; j < (nCount-1); ++j,++k)
656 if ( k >= nSize )
657 k = 0;
658 aRow.push_back(fDefaultData[k]);
659 } // for (sal_Int32 j = 0,k = 0; j < (nCount-1); ++j,++k)
660 aDataValues.push_back(aRow);
662 } // if ( !nRowCount )
664 uno::Reference< chart::XChartDataArray> xData(m_xInternal,uno::UNO_QUERY);
665 xData->setRowDescriptions(uno::Sequence< ::rtl::OUString >(&(*aRowLabels.begin()),aRowLabels.size()));
666 xData->setColumnDescriptions(uno::Sequence< ::rtl::OUString >(aColumns.getArray()+ (_bHasCategories ? 1 : 0),aColumns.getLength() - (_bHasCategories ? 1 : 0) ));
667 uno::Sequence< uno::Sequence< double > > aData(aDataValues.size());
668 uno::Sequence< double >* pDataIter = aData.getArray();
669 uno::Sequence< double >* pDataEnd = pDataIter + aData.getLength();
670 for(sal_Int32 i= 0;pDataIter != pDataEnd; ++pDataIter,++i )
672 if ( !aDataValues[i].empty() )
673 *pDataIter = uno::Sequence< double >(&(*(aDataValues[i]).begin()),(aDataValues[i]).size());
675 xData->setData(aData);
677 // -----------------------------------------------------------------------------
678 void DatabaseDataProvider::impl_fillRowSet_throw()
680 m_xAggregateSet->setPropertyValue( PROPERTY_FILTER, uno::makeAny( getFilter() ) );
681 uno::Reference< sdbc::XParameters> xParam(m_xRowSet,uno::UNO_QUERY_THROW);
682 xParam->clearParameters( );
684 // -----------------------------------------------------------------------------
685 bool DatabaseDataProvider::impl_fillParameters_nothrow( ::osl::ResettableMutexGuard& _rClearForNotifies)
687 // do we have to fill the parameters again?
688 if ( !m_aParameterManager.isUpToDate() )
689 m_aParameterManager.updateParameterInfo( m_aFilterManager );
691 if ( m_aParameterManager.isUpToDate() )
692 return m_aParameterManager.fillParameterValues( m_xHandler, _rClearForNotifies );
694 return true;
696 // com::sun::star::sdbc::XParameters
697 //------------------------------------------------------------------------------
698 void SAL_CALL DatabaseDataProvider::setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) throw( SQLException, RuntimeException )
700 m_aParameterManager.setNull(parameterIndex, sqlType);
703 //------------------------------------------------------------------------------
704 void SAL_CALL DatabaseDataProvider::setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName) throw( SQLException, RuntimeException )
706 m_aParameterManager.setObjectNull(parameterIndex, sqlType, typeName);
709 //------------------------------------------------------------------------------
710 void SAL_CALL DatabaseDataProvider::setBoolean(sal_Int32 parameterIndex, sal_Bool x) throw( SQLException, RuntimeException )
712 m_aParameterManager.setBoolean(parameterIndex, x);
715 //------------------------------------------------------------------------------
716 void SAL_CALL DatabaseDataProvider::setByte(sal_Int32 parameterIndex, sal_Int8 x) throw( SQLException, RuntimeException )
718 m_aParameterManager.setByte(parameterIndex, x);
721 //------------------------------------------------------------------------------
722 void SAL_CALL DatabaseDataProvider::setShort(sal_Int32 parameterIndex, sal_Int16 x) throw( SQLException, RuntimeException )
724 m_aParameterManager.setShort(parameterIndex, x);
727 //------------------------------------------------------------------------------
728 void SAL_CALL DatabaseDataProvider::setInt(sal_Int32 parameterIndex, sal_Int32 x) throw( SQLException, RuntimeException )
730 m_aParameterManager.setInt(parameterIndex, x);
733 //------------------------------------------------------------------------------
734 void SAL_CALL DatabaseDataProvider::setLong(sal_Int32 parameterIndex, sal_Int64 x) throw( SQLException, RuntimeException )
736 m_aParameterManager.setLong(parameterIndex, x);
739 //------------------------------------------------------------------------------
740 void SAL_CALL DatabaseDataProvider::setFloat(sal_Int32 parameterIndex, float x) throw( SQLException, RuntimeException )
742 m_aParameterManager.setFloat(parameterIndex, x);
745 //------------------------------------------------------------------------------
746 void SAL_CALL DatabaseDataProvider::setDouble(sal_Int32 parameterIndex, double x) throw( SQLException, RuntimeException )
748 m_aParameterManager.setDouble(parameterIndex, x);
751 //------------------------------------------------------------------------------
752 void SAL_CALL DatabaseDataProvider::setString(sal_Int32 parameterIndex, const ::rtl::OUString& x) throw( SQLException, RuntimeException )
754 m_aParameterManager.setString(parameterIndex, x);
757 //------------------------------------------------------------------------------
758 void SAL_CALL DatabaseDataProvider::setBytes(sal_Int32 parameterIndex, const uno::Sequence< sal_Int8 >& x) throw( SQLException, RuntimeException )
760 m_aParameterManager.setBytes(parameterIndex, x);
763 //------------------------------------------------------------------------------
764 void SAL_CALL DatabaseDataProvider::setDate(sal_Int32 parameterIndex, const util::Date& x) throw( SQLException, RuntimeException )
766 m_aParameterManager.setDate(parameterIndex, x);
769 //------------------------------------------------------------------------------
770 void SAL_CALL DatabaseDataProvider::setTime(sal_Int32 parameterIndex, const util::Time& x) throw( SQLException, RuntimeException )
772 m_aParameterManager.setTime(parameterIndex, x);
775 //------------------------------------------------------------------------------
776 void SAL_CALL DatabaseDataProvider::setTimestamp(sal_Int32 parameterIndex, const util::DateTime& x) throw( SQLException, RuntimeException )
778 m_aParameterManager.setTimestamp(parameterIndex, x);
781 //------------------------------------------------------------------------------
782 void SAL_CALL DatabaseDataProvider::setBinaryStream(sal_Int32 parameterIndex, const uno::Reference<io::XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException )
784 m_aParameterManager.setBinaryStream(parameterIndex, x, length);
787 //------------------------------------------------------------------------------
788 void SAL_CALL DatabaseDataProvider::setCharacterStream(sal_Int32 parameterIndex, const uno::Reference<io::XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException )
790 m_aParameterManager.setCharacterStream(parameterIndex, x, length);
793 //------------------------------------------------------------------------------
794 void SAL_CALL DatabaseDataProvider::setObjectWithInfo(sal_Int32 parameterIndex, const uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale) throw( SQLException, RuntimeException )
796 m_aParameterManager.setObjectWithInfo(parameterIndex, x, targetSqlType, scale);
799 //------------------------------------------------------------------------------
800 void SAL_CALL DatabaseDataProvider::setObject(sal_Int32 parameterIndex, const uno::Any& x) throw( SQLException, RuntimeException )
802 m_aParameterManager.setObject(parameterIndex, x);
805 //------------------------------------------------------------------------------
806 void SAL_CALL DatabaseDataProvider::setRef(sal_Int32 parameterIndex, const uno::Reference<sdbc::XRef>& x) throw( SQLException, RuntimeException )
808 m_aParameterManager.setRef(parameterIndex, x);
811 //------------------------------------------------------------------------------
812 void SAL_CALL DatabaseDataProvider::setBlob(sal_Int32 parameterIndex, const uno::Reference<sdbc::XBlob>& x) throw( SQLException, RuntimeException )
814 m_aParameterManager.setBlob(parameterIndex, x);
817 //------------------------------------------------------------------------------
818 void SAL_CALL DatabaseDataProvider::setClob(sal_Int32 parameterIndex, const uno::Reference<sdbc::XClob>& x) throw( SQLException, RuntimeException )
820 m_aParameterManager.setClob(parameterIndex, x);
823 //------------------------------------------------------------------------------
824 void SAL_CALL DatabaseDataProvider::setArray(sal_Int32 parameterIndex, const Reference<sdbc::XArray>& x) throw( SQLException, RuntimeException )
826 m_aParameterManager.setArray(parameterIndex, x);
829 //------------------------------------------------------------------------------
830 void SAL_CALL DatabaseDataProvider::clearParameters() throw( SQLException, RuntimeException )
832 m_aParameterManager.clearParameters();
834 //==============================================================================
835 // com::sun::star::sdbc::XRowSet
836 //------------------------------------------------------------------------------
837 void SAL_CALL DatabaseDataProvider::execute() throw( SQLException, RuntimeException )
839 uno::Sequence< beans::PropertyValue > aEmpty;
840 createDataSource(aEmpty);
842 //------------------------------------------------------------------------------
843 void SAL_CALL DatabaseDataProvider::addRowSetListener(const uno::Reference<sdbc::XRowSetListener>& _rListener) throw( RuntimeException )
845 if (m_xRowSet.is())
846 m_xRowSet->addRowSetListener(_rListener);
849 //------------------------------------------------------------------------------
850 void SAL_CALL DatabaseDataProvider::removeRowSetListener(const uno::Reference<sdbc::XRowSetListener>& _rListener) throw( RuntimeException )
852 if (m_xRowSet.is())
853 m_xRowSet->removeRowSetListener(_rListener);
855 //==============================================================================
856 // com::sun::star::sdbc::XResultSet
857 //------------------------------------------------------------------------------
858 sal_Bool SAL_CALL DatabaseDataProvider::next() throw( SQLException, RuntimeException )
860 return m_xRowSet->next();
863 //------------------------------------------------------------------------------
864 sal_Bool SAL_CALL DatabaseDataProvider::isBeforeFirst() throw( SQLException, RuntimeException )
866 return m_xRowSet->isBeforeFirst();
869 //------------------------------------------------------------------------------
870 sal_Bool SAL_CALL DatabaseDataProvider::isAfterLast() throw( SQLException, RuntimeException )
872 return m_xRowSet->isAfterLast();
875 //------------------------------------------------------------------------------
876 sal_Bool SAL_CALL DatabaseDataProvider::isFirst() throw( SQLException, RuntimeException )
878 return m_xRowSet->isFirst();
881 //------------------------------------------------------------------------------
882 sal_Bool SAL_CALL DatabaseDataProvider::isLast() throw( SQLException, RuntimeException )
884 return m_xRowSet->isLast();
887 //------------------------------------------------------------------------------
888 void SAL_CALL DatabaseDataProvider::beforeFirst() throw( SQLException, RuntimeException )
890 m_xRowSet->beforeFirst();
893 //------------------------------------------------------------------------------
894 void SAL_CALL DatabaseDataProvider::afterLast() throw( SQLException, RuntimeException )
896 m_xRowSet->afterLast();
899 //------------------------------------------------------------------------------
900 sal_Bool SAL_CALL DatabaseDataProvider::first() throw( SQLException, RuntimeException )
902 return m_xRowSet->first();
905 //------------------------------------------------------------------------------
906 sal_Bool SAL_CALL DatabaseDataProvider::last() throw( SQLException, RuntimeException )
908 return m_xRowSet->last();
911 //------------------------------------------------------------------------------
912 sal_Int32 SAL_CALL DatabaseDataProvider::getRow() throw( SQLException, RuntimeException )
914 return m_xRowSet->getRow();
917 //------------------------------------------------------------------------------
918 sal_Bool SAL_CALL DatabaseDataProvider::absolute(sal_Int32 row) throw( SQLException, RuntimeException )
920 return m_xRowSet->absolute(row);
923 //------------------------------------------------------------------------------
924 sal_Bool SAL_CALL DatabaseDataProvider::relative(sal_Int32 rows) throw( SQLException, RuntimeException )
926 return m_xRowSet->relative(rows);
929 //------------------------------------------------------------------------------
930 sal_Bool SAL_CALL DatabaseDataProvider::previous() throw( SQLException, RuntimeException )
932 return m_xRowSet->previous();
935 //------------------------------------------------------------------------------
936 void SAL_CALL DatabaseDataProvider::refreshRow() throw( SQLException, RuntimeException )
938 m_xRowSet->refreshRow();
941 //------------------------------------------------------------------------------
942 sal_Bool SAL_CALL DatabaseDataProvider::rowUpdated() throw( SQLException, RuntimeException )
944 return m_xRowSet->rowUpdated();
947 //------------------------------------------------------------------------------
948 sal_Bool SAL_CALL DatabaseDataProvider::rowInserted() throw( SQLException, RuntimeException )
950 return m_xRowSet->rowInserted();
953 //------------------------------------------------------------------------------
954 sal_Bool SAL_CALL DatabaseDataProvider::rowDeleted() throw( SQLException, RuntimeException )
956 return m_xRowSet->rowDeleted();
959 //------------------------------------------------------------------------------
960 uno::Reference< uno::XInterface > SAL_CALL DatabaseDataProvider::getStatement() throw( SQLException, RuntimeException )
962 return m_xRowSet->getStatement();
964 // -----------------------------------------------------------------------------
965 uno::Reference< uno::XInterface > SAL_CALL DatabaseDataProvider::getParent( ) throw (uno::RuntimeException)
967 return m_xParent;
969 // -----------------------------------------------------------------------------
970 void SAL_CALL DatabaseDataProvider::setParent( const uno::Reference< uno::XInterface >& _xParent ) throw (lang::NoSupportException, uno::RuntimeException)
972 osl::MutexGuard g(m_aMutex);
973 m_xParent = _xParent;
975 // -----------------------------------------------------------------------------
976 void DatabaseDataProvider::impl_invalidateParameter_nothrow()
978 osl::MutexGuard g(m_aMutex);
979 m_aParameterManager.clearAllParameterInformation();
981 // -----------------------------------------------------------------------------
982 } // namespace dbaccess