LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - querycomposer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 127 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <string.h>
      21             : #include <com/sun/star/lang/DisposedException.hpp>
      22             : #include <com/sun/star/util/XNumberFormatter.hpp>
      23             : #include <com/sun/star/sdbc/ColumnSearch.hpp>
      24             : #include <com/sun/star/sdbc/DataType.hpp>
      25             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      26             : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
      27             : #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
      28             : #include <comphelper/sequence.hxx>
      29             : #include <com/sun/star/uno/XAggregation.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include "dbastrings.hrc"
      32             : #include <cppuhelper/supportsservice.hxx>
      33             : #include <cppuhelper/typeprovider.hxx>
      34             : #include <unotools/configmgr.hxx>
      35             : #include <comphelper/types.hxx>
      36             : #include <tools/debug.hxx>
      37             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      38             : #include <com/sun/star/i18n/XLocaleData.hpp>
      39             : #include <unotools/syslocale.hxx>
      40             : #include <com/sun/star/container/XChild.hpp>
      41             : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
      42             : #include "querycomposer.hxx"
      43             : #include "HelperCollections.hxx"
      44             : #include "composertools.hxx"
      45             : #include <algorithm>
      46             : 
      47             : using namespace dbaccess;
      48             : using namespace dbtools;
      49             : using namespace comphelper;
      50             : using namespace connectivity;
      51             : using namespace ::com::sun::star::uno;
      52             : using namespace ::com::sun::star::beans;
      53             : using namespace ::com::sun::star::sdbc;
      54             : using namespace ::com::sun::star::sdb;
      55             : using namespace ::com::sun::star::sdbcx;
      56             : using namespace ::com::sun::star::container;
      57             : using namespace ::com::sun::star::i18n;
      58             : using namespace ::com::sun::star::lang;
      59             : using namespace ::com::sun::star::script;
      60             : using namespace ::cppu;
      61             : using namespace ::osl;
      62             : using namespace ::utl;
      63             : 
      64             : 
      65             : 
      66           0 : OQueryComposer::OQueryComposer(const Reference< XConnection>& _xConnection)
      67           0 :  : OSubComponent(m_aMutex,_xConnection)
      68             : {
      69             :     OSL_ENSURE(_xConnection.is()," Connection can't be null!");
      70             : 
      71           0 :     Reference<XMultiServiceFactory> xFac( _xConnection, UNO_QUERY_THROW );
      72           0 :     m_xComposer.set( xFac->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
      73           0 :     m_xComposerHelper.set( xFac->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
      74           0 : }
      75             : 
      76           0 : OQueryComposer::~OQueryComposer()
      77             : {
      78           0 : }
      79             : 
      80           0 : void SAL_CALL OQueryComposer::disposing()
      81             : {
      82           0 :     ::comphelper::disposeComponent(m_xComposerHelper);
      83           0 :     ::comphelper::disposeComponent(m_xComposer);
      84           0 : }
      85             : 
      86             : // ::com::sun::star::lang::XTypeProvider
      87           0 : Sequence< Type > SAL_CALL OQueryComposer::getTypes() throw (RuntimeException, std::exception)
      88             : {
      89           0 :     return ::comphelper::concatSequences(OSubComponent::getTypes(),OQueryComposer_BASE::getTypes());
      90             : }
      91             : 
      92           0 : Sequence< sal_Int8 > SAL_CALL OQueryComposer::getImplementationId() throw (RuntimeException, std::exception)
      93             : {
      94           0 :     return css::uno::Sequence<sal_Int8>();
      95             : }
      96             : 
      97           0 : Any SAL_CALL OQueryComposer::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
      98             : {
      99           0 :     Any aRet = OSubComponent::queryInterface(rType);
     100           0 :     if(!aRet.hasValue())
     101           0 :         aRet = OQueryComposer_BASE::queryInterface(rType);
     102           0 :     return aRet;
     103             : }
     104             : 
     105             : // XServiceInfo
     106           0 : OUString OQueryComposer::getImplementationName(  ) throw(RuntimeException, std::exception)
     107             : {
     108           0 :     return OUString("com.sun.star.sdb.dbaccess.OQueryComposer");
     109             : }
     110             : 
     111           0 : sal_Bool OQueryComposer::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
     112             : {
     113           0 :     return cppu::supportsService(this, _rServiceName);
     114             : }
     115             : 
     116           0 : Sequence< OUString > OQueryComposer::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     117             : {
     118           0 :     Sequence< OUString > aSNS( 1 );
     119           0 :     aSNS[0] = SERVICE_SDB_SQLQUERYCOMPOSER;
     120           0 :     return aSNS;
     121             : }
     122             : 
     123             : // XSQLQueryComposer
     124           0 : OUString SAL_CALL OQueryComposer::getQuery(  ) throw(RuntimeException, std::exception)
     125             : {
     126           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     127             : 
     128           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     129           0 :     Reference<XPropertySet> xProp(m_xComposer,UNO_QUERY);
     130           0 :     OUString sQuery;
     131           0 :     if ( xProp.is() )
     132           0 :         xProp->getPropertyValue(PROPERTY_ORIGINAL) >>= sQuery;
     133           0 :     return sQuery;
     134             : }
     135             : 
     136           0 : void SAL_CALL OQueryComposer::setQuery( const OUString& command ) throw(SQLException, RuntimeException, std::exception)
     137             : {
     138           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     139             : 
     140           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     141           0 :     m_aFilters.clear();
     142           0 :     m_xComposer->setQuery(command);
     143           0 :     m_sOrgFilter = m_xComposer->getFilter();
     144           0 :     m_sOrgOrder = m_xComposer->getOrder();
     145           0 : }
     146             : 
     147           0 : OUString SAL_CALL OQueryComposer::getComposedQuery(  ) throw(RuntimeException, std::exception)
     148             : {
     149           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     150             : 
     151           0 :     MutexGuard aGuard(m_aMutex);
     152             : 
     153           0 :     return m_xComposer->getQuery();
     154             : }
     155             : 
     156           0 : OUString SAL_CALL OQueryComposer::getFilter(  ) throw(RuntimeException, std::exception)
     157             : {
     158           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     159           0 :     MutexGuard aGuard(m_aMutex);
     160           0 :     FilterCreator aFilterCreator;
     161           0 :     aFilterCreator = ::std::for_each(m_aFilters.begin(),m_aFilters.end(),aFilterCreator);
     162           0 :     return aFilterCreator.getComposedAndClear();
     163             : }
     164             : 
     165           0 : Sequence< Sequence< PropertyValue > > SAL_CALL OQueryComposer::getStructuredFilter(  ) throw(RuntimeException, std::exception)
     166             : {
     167           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     168             : 
     169           0 :     MutexGuard aGuard(m_aMutex);
     170           0 :     return m_xComposer->getStructuredFilter();
     171             : }
     172             : 
     173           0 : OUString SAL_CALL OQueryComposer::getOrder(  ) throw(RuntimeException, std::exception)
     174             : {
     175           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     176             : 
     177           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     178           0 :     OrderCreator aOrderCreator;
     179           0 :     aOrderCreator = ::std::for_each(m_aOrders.begin(),m_aOrders.end(),aOrderCreator);
     180           0 :     return aOrderCreator.getComposedAndClear();
     181             : }
     182             : 
     183           0 : void SAL_CALL OQueryComposer::appendFilterByColumn( const Reference< XPropertySet >& column ) throw(SQLException, RuntimeException, std::exception)
     184             : {
     185           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     186           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     187             : 
     188           0 :     m_xComposerHelper->setQuery(getQuery());
     189           0 :     m_xComposerHelper->setFilter(OUString());
     190           0 :     m_xComposerHelper->appendFilterByColumn(column, sal_True, SQLFilterOperator::EQUAL);
     191             : 
     192           0 :     FilterCreator aFilterCreator;
     193           0 :     aFilterCreator.append(getFilter());
     194           0 :     aFilterCreator.append(m_xComposerHelper->getFilter());
     195             : 
     196           0 :     setFilter( aFilterCreator.getComposedAndClear() );
     197           0 : }
     198             : 
     199           0 : void SAL_CALL OQueryComposer::appendOrderByColumn( const Reference< XPropertySet >& column, sal_Bool ascending ) throw(SQLException, RuntimeException, std::exception)
     200             : {
     201           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     202           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     203             : 
     204           0 :     m_xComposerHelper->setQuery(getQuery());
     205           0 :     m_xComposerHelper->setOrder(OUString());
     206           0 :     m_xComposerHelper->appendOrderByColumn(column,ascending);
     207             : 
     208           0 :     OrderCreator aOrderCreator;
     209           0 :     aOrderCreator.append(getOrder());
     210           0 :     aOrderCreator.append(m_xComposerHelper->getOrder());
     211             : 
     212           0 :     setOrder(aOrderCreator.getComposedAndClear());
     213           0 : }
     214             : 
     215           0 : void SAL_CALL OQueryComposer::setFilter( const OUString& filter ) throw(SQLException, RuntimeException, std::exception)
     216             : {
     217           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     218             : 
     219           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     220           0 :     FilterCreator aFilterCreator;
     221           0 :     aFilterCreator.append(m_sOrgFilter);
     222           0 :     aFilterCreator.append(filter);
     223             : 
     224           0 :     m_aFilters.clear();
     225           0 :     if ( !filter.isEmpty() )
     226           0 :         m_aFilters.push_back(filter);
     227             : 
     228           0 :     m_xComposer->setFilter( aFilterCreator.getComposedAndClear() );
     229           0 : }
     230             : 
     231           0 : void SAL_CALL OQueryComposer::setOrder( const OUString& order ) throw(SQLException, RuntimeException, std::exception)
     232             : {
     233           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     234             : 
     235           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     236             : 
     237           0 :     OrderCreator aOrderCreator;
     238           0 :     aOrderCreator.append(m_sOrgOrder);
     239           0 :     aOrderCreator.append(order);
     240             : 
     241           0 :     m_aOrders.clear();
     242           0 :     if ( !order.isEmpty() )
     243           0 :         m_aOrders.push_back(order);
     244             : 
     245           0 :     m_xComposer->setOrder(aOrderCreator.getComposedAndClear());
     246           0 : }
     247             : 
     248             : // XTablesSupplier
     249           0 : Reference< XNameAccess > SAL_CALL OQueryComposer::getTables(  ) throw(RuntimeException, std::exception)
     250             : {
     251           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     252             : 
     253           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     254           0 :     return Reference<XTablesSupplier>(m_xComposer,UNO_QUERY)->getTables();
     255             : }
     256             : 
     257             : // XColumnsSupplier
     258           0 : Reference< XNameAccess > SAL_CALL OQueryComposer::getColumns(  ) throw(RuntimeException, std::exception)
     259             : {
     260           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     261             : 
     262           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     263           0 :     return Reference<XColumnsSupplier>(m_xComposer,UNO_QUERY)->getColumns();
     264             : }
     265             : 
     266           0 : Reference< XIndexAccess > SAL_CALL OQueryComposer::getParameters(  ) throw(RuntimeException, std::exception)
     267             : {
     268           0 :     ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
     269             : 
     270           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     271           0 :     return Reference<XParametersSupplier>(m_xComposer,UNO_QUERY)->getParameters();
     272             : }
     273             : 
     274           0 : void SAL_CALL OQueryComposer::acquire() throw()
     275             : {
     276           0 :     OSubComponent::acquire();
     277           0 : }
     278             : 
     279           0 : void SAL_CALL OQueryComposer::release() throw()
     280             : {
     281           0 :     OSubComponent::release();
     282           0 : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11